Problems with integrating ln(x-y) wrt. y

26 views
Skip to first unread message

Filip

unread,
Oct 22, 2015, 9:56:35 AM10/22/15
to sympy
I'm trying to integrate ln(x-y) dy, but the result I get from SymPy is very different from Maple's answer.
Here is what I get when I integrate in SymPy:
In [2]:
integrate(ln(x-y), y)
Out[2]:
-x*log(-x + y) + y*log(x - y) - y

When I try to differentiate this, i get something very different from ln(x-y):
In [3]:
diff(-x*log(-x + y) + y*log(x - y) - y, y)
Out[3]:
-x/(-x + y) - y/(x - y) + log(x - y) - 1

Is this a bug in SymPy, or a user error?

When i differentiate the answer I get when I integrate using Maple, i get the expected result ln(x-y)
In [4]:
diff(-ln(x-y)*(x-y)+x-y, y)
Out[4]:
log(x - y)

An IPython Notebook with an example can be found here: http://nbviewer.ipython.org/gist/FSund/d3b3f7f590db0e72e2e2

I'm using Python 3.4.3 (Anaconda 2.3.0 (64-bit)), and IPython 4.0.0.

Kalevi Suominen

unread,
Oct 22, 2015, 11:32:34 AM10/22/15
to sympy


Use cancel to simplify the result. SymPy does not do that automatically.

Speed

unread,
Oct 22, 2015, 1:07:14 PM10/22/15
to sympy
Use simplify(diff(-x*log(-x + y) + y*log(x - y) - y,y)) instead of only diff(-x*log(-x + y) + y*log(x - y) - y,y)

as mentioned by Kalevi sympy does not do the simplification part autometically.

and in sympy during integration sometimes the constants make a difference.
Hope it helps.
Reply all
Reply to author
Forward
0 new messages