integrate in sympy

60 views
Skip to first unread message

Andreas Söll

unread,
Jun 24, 2025, 6:38:45 AMJun 24
to sympy
What am I doing wrong?

>>> from sympy import *       # Version 1.13.2
>>> x = symbols("x")
>>> f = x / (x+1)
>>> f
x/(x + 1)
>>> integrate(diff(f,x),x)    # should be x/(x+1)
-1/(x + 1)

diff seems correct - what about integrate?

Can anyone help?

Oscar Benjamin

unread,
Jun 24, 2025, 6:43:47 AMJun 24
to sy...@googlegroups.com
Antiderivatives are not unique.

Generally
diff(integrate(f(x), x), x) == f(x)
but we don't necessarily have
integrate(diff(f(x), x), x) == f(x)
because they can differ by a constant of integration:

>>> cancel(f - integrate(diff(f, x), x))
1
>>> cancel(f - diff(integrate(f, x), x))
0

--
Oscar

Andreas Söll

unread,
Jun 25, 2025, 5:56:00 AMJun 25
to sympy
Thank you very much for your quick help.
At first I was hesitant and tried a few things.
Your answer has now convinced me.

Best regards, Andreas

Donaldson Tan

unread,
Jul 19, 2025, 3:15:55 AMJul 19
to sympy
 integrate(diff(f,x),x) actually yields you -1/(x + 1) + constant C

when u set C = 1, it becomes x/(x + 1)
Reply all
Reply to author
Forward
0 new messages