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 give *Integral( ... , (x, -oo, -1)) + Integral( ... , (x, 1, oo)) *instead of *Integral( ... , (x, Union(Interval(-oo, -1), Interval(1, oo))))*. On the other hand, this alternative notation may be useful. Unfortunately it would require some algorithmic changes and I am a bit wary about a substantial edit of the integration algorithm. On Thursday, March 26, 2015 at 9:12:37 PM UTC+1, Matthew wrote: > > 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 <franz....@gmail.com > <javascript:>> wrote: > >> >> 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, ∞) >> ⌠ >> ⎮ 2 >> ⎮ -(z - μ) >> ⎮ ────────── >> ⎮ 2 >> ⎮ ___ 2⋅σ >> ⎮ ╲╱ 2 ⋅ℯ >> ⎮ ───────────────── dz >> ⎮ ___ >> ⎮ 2⋅╲╱ π ⋅σ >> ⌡ >> >> >> In [7]: srepr(P(N**2>1, evaluate=False)) >> Out[7]: "Integral(Mul(Rational(1, 2), Pow(Integer(2), Rational(1, 2)), >> Pow(pi, Rational(-1, 2)), Pow(Symbol('sigma'), Integer(-1)), >> exp(Mul(Integer(-1), Rational(1, 2), Pow(Symbol('sigma'), Integer(-2)), >> Pow(Add(Dummy('z'), Mul(Integer(-1), Symbol('mu'))), Integer(2))))), >> Tuple(Dummy('z'), Union(Interval(-oo, Integer(-1), S.true, S.true), >> Interval(Integer(1), oo, S.true, S.true))))" >> >> >> Apart the fact that such an integral looks wrong to me, i.e. there is no >> account for the random variable being squared (or am I missing something?), >> it looks like SymPy is OK with intervals, but not with unions of intervals: >> >> >> https://github.com/sympy/sympy/blob/9242d31f6d31a1d9c3464264a5a6e61eab8acfb8/sympy/concrete/expr_with_limits.py#L37 >> >> That's the point where an Interval gets parsed by the integration >> algorithm. >> >> I think it's an easy fix to add the processing for unions of intervals. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "sympy" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to sympy+un...@googlegroups.com <javascript:>. >> To post to this group, send email to sy...@googlegroups.com <javascript:> >> . >> Visit this group at http://groups.google.com/group/sympy. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/sympy/230fe8c3-a834-4074-920d-435a2687be36%40googlegroups.com >> >> <https://groups.google.com/d/msgid/sympy/230fe8c3-a834-4074-920d-435a2687be36%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> >> For more options, visit https://groups.google.com/d/optout. >> > > -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sympy+unsubscr...@googlegroups.com. To post to this group, send email to sympy@googlegroups.com. Visit this group at http://groups.google.com/group/sympy. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/c3701c8c-3577-45a0-afdd-2a000bcd32d8%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.