integrate Heaviside give not correct answer

42 views
Skip to first unread message

chaowen guo

unread,
Apr 28, 2017, 12:41:47 AM4/28/17
to sympy
Hi:

import sympy
x=sympy.symbols('x',real=True)
sympy.integrate(sympy.Heaviside(x-1)*(x-1)+1,(x,0,2))

the output is 2, which is wrong, the correct answer is 5/2

I try the following Mathematica code:

Integrate[HeavisideTheta[x - 1]*(x - 1) + 1, {x, 0, 2}] which gives me 5/2

also the following piecewise function:

sympy.integrate(sympy.Piecewise((1,x<1),(x,x>1)),(x,0,2)) which gives me the correct answer

So I want to ask whether it is a bug in Heaviside function or there are some special explanations in sympy?

Kalevi Suominen

unread,
Apr 28, 2017, 7:48:59 AM4/28/17
to sympy

The indefinite integral involves a Meijer G-function that SymPy is unable to evaluate.
 >>> integrate(Heaviside(x-1)*(x-1) + 1, x)
x + Piecewise((0, Abs(x) < 1), (meijerg(((3, 1), ()), ((), (1, 0)), x), True))

 Manual integration will give the correct answer:
>>> integrate(Heaviside(x-1)*(x-1) + 1, (x, 0, 2), manual=True)
5/2

So the bug is in the evaluation of the indefinite integral.

Kalevi Suominen

Chris Smith

unread,
May 4, 2017, 11:15:38 AM5/4/17
to sympy
This *might* work in the PR that I am struggling with that upgrades Piecewise. #12587
Reply all
Reply to author
Forward
0 new messages