[sympy] Integrate over Union of Interval's

2015-03-25 Thread Francesco Bonazzi
I opened this issue a few days ago: https://github.com/sympy/sympy/issues/9189 I bumped into this problem because it was raised by the stats module. Apparently the integration algorithm is unable to cope with unions of intervals. I was wondering, is it correct to pass a union of intervals to th

Re: [sympy] Integrate over Union of Interval's

2015-03-25 Thread Aaron Meurer
Wow, I didn't know integrate supported Intervals. If we are going to support sets, we might as well support all of them (at least unevaluated). A union of intervals is easy if the values are computable (i.e., if you can determine if the union is disjoint). Otherwise, it's complicated. Integrate(1,

Re: [sympy] Integrate over Union of Interval's

2015-03-25 Thread Francesco Bonazzi
On Wednesday, March 25, 2015 at 5:29:18 PM UTC+1, Aaron Meurer wrote: > > Wow, I didn't know integrate supported Intervals. I had a look at the code, I think that behaviour is unintended. The point is, the stats module apparently calls *integrate* with intervals to determine probabilities. I

Re: [sympy] Integrate over Union of Interval's

2015-03-25 Thread Aaron Meurer
On Wed, Mar 25, 2015 at 1:21 PM, Francesco Bonazzi wrote: > > > On Wednesday, March 25, 2015 at 5:29:18 PM UTC+1, Aaron Meurer wrote: >> >> Wow, I didn't know integrate supported Intervals. > > > I had a look at the code, I think that behaviour is unintended. > > The point is, the stats module app

Re: [sympy] Integrate over Union of Interval's

2015-03-26 Thread Francesco Bonazzi
Well, I was a bit surprised too, but the stats module apparently does so, as shown in this example: In [1]: from sympy.stats import * In [2]: var('sigma', positive=True) Out[2]: σ In [3]: N = Normal('X', mu, sigma) In [6]: P(N**2>1, evaluate=False) Out[6]: (-∞, -1) ∪ (1, ∞)

Re: [sympy] Integrate over Union of Interval's

2015-03-26 Thread Matthew Rocklin
You don't need to square the random variable to compute the result. You just need to integrate the pdf over x < -1 and x > 1 On Thu, Mar 26, 2015 at 5:42 AM, Francesco Bonazzi wrote: > > Well, I was a bit surprised too, but the stats module apparently does so, > as shown in this example: > > In

Re: [sympy] Integrate over Union of Interval's

2015-03-26 Thread Francesco Bonazzi
Matthew... what do you think of the union of intervals as an alternative to the usual ranges in integrate/Integral? I suppose that you wrote the code outputting that integral, which currently does not work, and I want to make it work. I am undecided on whether to edit sympy.stats in order to gi

Re: [sympy] Integrate over Union of Interval's

2015-03-26 Thread Aaron Meurer
I think integrating over sets is a useful thing to allow, but we definitely need to be more careful about symbolic intervals. And given that, it probably means that sympy.stats should just do normal integrals, since it can make assumptions about symbolic intervals that won't be present when passed

Re: [sympy] Integrate over Union of Interval's

2015-03-27 Thread Matthew Rocklin
> Matthew... what do you think of the union of intervals as an alternative to the usual ranges in integrate/Integral? Seems like a decent plan. I haven't been actively working on stats in a while so I don't have strong opinions here. On Thu, Mar 26, 2015 at 6:50 PM, Aaron Meurer wrote: > I t