Hi,

Limit values like -oo should not be directly substituted into complicated 
expressions. Instead of `g.subs(x, -oo)`, one should compute `limit(g, x, 
-oo)` (which is -1/2).

Kalevi Suominen

On Saturday, October 12, 2019 at 5:25:03 PM UTC+3, Rainer Dorsch wrote:
>
> Hi,
>
> I have to admit I am new to sympy and deeply impressed what sympy can do.
>
> When experimenting with integrating a Gaussian distribution, I got a 
> backtrace. Just wondering if I did something wrong.
>
> My experiment:
>
> import sympy as sp
>> sp.init_printing()
>>
>> # Define Gaussian distribution
>> sigma=sp.Symbol('sigma', positive=True)
>> mu=sp.Symbol('mu',domain=sp.S.Reals)
>> x=sp.Symbol('x')
>> f=1/sp.sqrt(2*sp.pi*sigma**2)*sp.exp(-(x-mu)**2/(2*sigma**2))
>>
>> # Integrate
>> g=sp.integrate(f,x)
>> h=g-g.subs(x,-sp.oo)
>> h
>>
>> # Simplify full Intervall - 1 is expected
>> sp.simplify(h.subs(x,sp.oo))
>>
>> The output I got
>>
>  
> rd@h370:~/tmp.nobackup$ python3 sympy-test.py 
> Traceback (most recent call last):
>   File "sympy-test.py", line 16, in <module>
>     sp.simplify(h.subs(x,sp.oo))
>   File "/usr/lib/python3/dist-packages/sympy/simplify/simplify.py", line 
> 566, in simplify
>     expr1 = shorter(_e, _mexpand(_e).cancel())  # issue 6829
>   File "/usr/lib/python3/dist-packages/sympy/core/expr.py", line 3245, in 
> cancel
>     return cancel(self, *gens, **args)
>   File "/usr/lib/python3/dist-packages/sympy/polys/polytools.py", line 
> 6583, in cancel
>     f = factor_terms(f, radical=True)
>   File "/usr/lib/python3/dist-packages/sympy/core/exprtools.py", line 1202
> , in factor_terms
>     return do(expr)
>   File "/usr/lib/python3/dist-packages/sympy/core/exprtools.py", line 1177
> , in do
>     list_args = [do(a) for a in Add.make_args(p)]
>   File "/usr/lib/python3/dist-packages/sympy/core/exprtools.py", line 1177
> , in <listcomp>
>     list_args = [do(a) for a in Add.make_args(p)]
>   File "/usr/lib/python3/dist-packages/sympy/core/exprtools.py", line 1198
> , in do
>     *[do(a) for a in p.args])
>   File "/usr/lib/python3/dist-packages/sympy/core/exprtools.py", line 1198
> , in <listcomp>
>     *[do(a) for a in p.args])
>   File "/usr/lib/python3/dist-packages/sympy/core/exprtools.py", line 1167
> , in do
>     newargs = tuple([do(i) for i in args])
>   File "/usr/lib/python3/dist-packages/sympy/core/exprtools.py", line 1167
> , in <listcomp>
>     newargs = tuple([do(i) for i in args])
>   File "/usr/lib/python3/dist-packages/sympy/core/exprtools.py", line 1199
> , in do
>     rv = _keep_coeff(cont, p, clear=clear, sign=sign)
>   File "/usr/lib/python3/dist-packages/sympy/core/mul.py", line 1793, in 
> _keep_coeff
>     if r == int(r):
>   File "/usr/lib/python3/dist-packages/sympy/core/expr.py", line 229, in 
> __int__
>     raise TypeError("can't convert %s to int" % r)
> TypeError: can't convert -oo to int
> rd@h370:~/tmp.nobackup$ 
>
> sp.simplify(h.subs(x,sp.oo).subs(mu,0))
>
> works well and returns 1 as expected.
>
> Do I need to restrict mu further or did I hit a sympy issue? Or something 
> completely different?
>
> Any feedback is welcome.
>
>
> Thanks
> Rainer
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/e5f0c229-0227-4570-9a23-b432ad0f1c6b%40googlegroups.com.

Reply via email to