> 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 <[email protected]> wrote: > 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 to Integral. > > Aaron Meruer > > On Thu, Mar 26, 2015 at 6:54 PM, Francesco Bonazzi > <[email protected]> wrote: > > 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 <[email protected] > > > >> 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 [email protected]. > >>> To post to this group, send email to [email protected]. > >>> 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 > . > >>> > >>> 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 [email protected]. > > To post to this group, send email to [email protected]. > > 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. > > -- > 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 [email protected]. > To post to this group, send email to [email protected]. > 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/CAKgW%3D6LbcosAeX6FeM0y%2Bb%3D50yrpDUK%3DiVpKhsNqKEh7A46W5A%40mail.gmail.com > . > 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 [email protected]. To post to this group, send email to [email protected]. 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/CAJ8oX-GLuWwuPVf67SgHB3m7gdGa%3D%3DNUgRTqsV%2BMNSmA_g8qnA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
