Delaying evaluation until after simplification

65 views
Skip to first unread message

Ian Bell

unread,
Feb 13, 2015, 4:42:31 PM2/13/15
to sy...@googlegroups.com
I am trying to do an integration like this:



Ultimately the result I should be able to get is -log(1-z)

Manual integration shows that you can integrate(1/(1-z),z) -> -log(z-1), evaluation at the limits yields -log(z-1) - (-log(-1)) which you can simplify to -log(1-z).  How can I tell sympy to delay evaluation until after it has done the simplification?  I guess that it first does log(-1), which it isn't happy about...

Ian

Aaron Meurer

unread,
Feb 13, 2015, 6:11:54 PM2/13/15
to sy...@googlegroups.com
On Fri, Feb 13, 2015 at 3:42 PM, Ian Bell <ian.h...@gmail.com> wrote:
I am trying to do an integration like this:

Was there supposed to be something here? It's just showing up as empty space for me.

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 http://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/fdbada4e-6ba0-4de5-835f-5121aaa022ce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ian Bell

unread,
Feb 13, 2015, 7:37:56 PM2/13/15
to sy...@googlegroups.com
There was an embedded image, but clearly that didn't work.

>> integrate(1/(1-z),(z,0,z))

was the command.  I used a picture to show that you get an imaginary term as part of the return value

Chris Smith

unread,
Feb 13, 2015, 9:15:01 PM2/13/15
to sy...@googlegroups.com
You can do a little manual simplification like this:

>>> integrate(1/(1-z),(z,0,z))
-log(z - 1) + I*pi
>>> exp(_)
-1/(z - 1)
>>> 1/(-1/_/-1)  # the badger-face inversion :-)
1/(-z + 1)
>>> log(_)
log(1/(-z + 1))

But that can't simplify to -log(1-z) because that is not valid unless 1-z is positive.

>>> expand_log(log(1/Dummy(positive=True)))
-log(_Dummy_85)
>>> expand_log(log(1/Dummy(nonnegative=True)))
log(1/_Dummy_86)
>>> expand_log(log(1/Dummy(negative=True)))
log(1/_Dummy_107)

Aaron Meurer

unread,
Feb 14, 2015, 12:33:18 AM2/14/15
to sy...@googlegroups.com
Just compute the definite integral, and evaluate at the limits manually. That is, use integrate(1/(1-z), z). 

However you're going to have problems because as Chris notes, log(1 - z) = log(-1) + log(z - 1) is not always valid (I think it may be true if z < 1, if I remember the rule correctly).  The issue is that for real values, the integral of 1/x should be log(abs(x)) (this isn't true in the complex case, which is why SymPy doesn't return that value). 

I believe the result you get with the I*pi is mathematically correct. That is, if you plug in any real value for z, you'll get the same result as from -log(abs(z - 1)).

Aaron Meurer

Chris Smith

unread,
Feb 14, 2015, 12:48:53 AM2/14/15
to sy...@googlegroups.com
You can also just use the "manual" hint:

>>> integrate(1/((1-z)),z,manual=True)
-log(-z + 1)
Reply all
Reply to author
Forward
0 new messages