Elementary integration fails

55 views
Skip to first unread message

qm

unread,
Nov 10, 2016, 6:22:51 PM11/10/16
to sympy
Why do these identical elementary integrations lead to differing results?
In the 1st version the parameters y,G are kept arbitrary before doing the integration.
In the 2nd version the parameters are set before the integration.
The integrand is completely harmless, both with respect to the variable and the parameters.
The results differ. Why?

x,y,G=sp.symbols('x y G')

c = lambda x: G/(x**2+G**2)

u=sp.integrate(c(x)*c(x-y),x)

d = (c(x)*c(x-y)).subs({y:sp.Integer(2),G:sp.Integer(1)})

v=sp.integrate(d,x)


print (u.subs({x:sp.Integer(1),y:sp.Integer(2),G:sp.Integer(1)})).evalf()

print (v.subs({x:sp.Integer(1)})).evalf()


-0.392699081698724 + 0.e-21*I

0



Aaron Meurer

unread,
Nov 10, 2016, 6:51:56 PM11/10/16
to sy...@googlegroups.com
Keep in mind that indefinite integrals are only defined up to a
constant. simplify(u.diff(x) - c(x)*c(x-y)) gives 0, which
demonstrates that the integral is correct.

As to why they are different, for some reason, integrate isn't giving
arctangents in the former case. This could be considered a bug
(integrate() should avoid introducing complex numbers whenever
possible).

Aaron Meurer
> --
> 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.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/ef11d5e4-a7c2-434c-b9c9-8236bec34468%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

qm

unread,
Nov 11, 2016, 4:55:49 AM11/11/16
to sympy
Keep in mind that indefinite integrals are only defined up to a
constant.
 
My math teacher just reminded me to definitely not disagree on that ;)

Let me pls. follow up in a different way. We can do

a,b = sp.symbols('a b')

r1=u.subs({x:a,y:sp.Integer(2),G:sp.Integer(1)}) - u.subs({x:b,y:sp.Integer(2),G:sp.Integer(1)})

r2=v.subs({x:a})-v.subs({x:b})


With u and v defined as in my original post.

Mathematically r1 and r2 are the same.

Do you know what kind of simplification I would have to apply to either of the two expressions r1,r2, to make SymPy actually also tell me that?


qm

unread,
Nov 11, 2016, 8:44:41 AM11/11/16
to sympy
Am Freitag, 11. November 2016 10:55:49 UTC+1 schrieb qm:
Do you know what kind of simplification I would have to apply to either of the two expressions r1,r2, to make SymPy actually also tell me that?

by 'simplification' I don't mean that I would have to substitute things like log(a+1j) = log(1+a**2) + 1j*atan(1/a) by hand, but if there is a builtin function to do that?

Aaron Meurer

unread,
Nov 11, 2016, 3:41:41 PM11/11/16
to sy...@googlegroups.com
I don't know if there's any easy way to do it. Really it should be
happening in the integration routine (that's why I said that this can
be considered a bug). In the integration routine it has enough
information to easily give an arctangent instead of a logarithm, but
after the fact it's more difficult.

Aaron Meurer
> --
> 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.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/de5d5398-f440-4b39-bf0b-67201d873f49%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages