# Integration error #7383

Open
opened this Issue Apr 8, 2014 · 0 comments

Projects
None yet
1 participant
Member

### asmeurer commented Apr 8, 2014

From the mailing list:

Hello,

I was double-checking an integral with sympy, and noticed that the software comes up with the wrong answer. The integrand has five terms, which can be collected into three groups. Two of the groups -- Ec1 and Ec2 -- cancel after integrating over z. Strangely, sympy gets the answer right if you ask it to integrate the groups separately.

``````x, z, R, a = symbols('x z R a')
r = sqrt(x**2 + z**2)
u = erf(a*r/sqrt(2))/r
Ec = diff(u, z, z).subs([(x, sqrt(R*R-z*z))])
``````
##### compare
``````>>> simplify(integrate(Ec, (z, -R, R)))
-2*sqrt(2)*a*(R**2*a**2 + 3*R**2 - 3)*exp(-R**2*a**2/2)/(3*sqrt(pi)*R**3)
``````
``````-2*sqrt(2)*R*a**3*exp(-R**2*a**2/2)/(3*sqrt(pi))
``````
##### in particular, `Ec = Ec1 + Ec2 + Ec3`, where
``````Ec1 = sympify('3*z**2*erf(sqrt(2)*a*sqrt(R**2)/2)/(R**2)**(5/2) - erf(sqrt(2)*a*sqrt(R**2)/2)/(R**2)**(3/2)')
Ec2 = sympify('+ sqrt(2)*a*exp(-R**2*a**2/2)/(sqrt(pi)*R**2) - 3*sqrt(2)*a*z**2*exp(-R**2*a**2/2)/(sqrt(pi)*R**4)')
Ec3 = Ec - Ec1 - Ec2 # -sqrt(2)*a**3*z**2*exp(-R**2*a**2/2)/(sqrt(pi)*R**2)

simplify(integrate(Ec1, (z, -R, R))) # -> 0
simplify(integrate(Ec2, (z, -R, R))) # -> 0

integrate(Ec3, (z, -R, R))
``````

### skirpichev added a commit to diofant/diofant that referenced this issue Dec 28, 2015

``` Add regression test for sympy/sympy#7383 (fixed by above commits) ```
`Closes sympy/sympy#7383`
``` 0658b7b ```