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
> <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 [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-GTu35YvjPBpApeokZ6fued9iBHYzD7o9vB1YUSmDryJA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to