Logcombine

28 views
Skip to first unread message

Paul Royik

unread,
Oct 19, 2015, 1:12:46 AM10/19/15
to sympy
Hello.
I noticed that simplify moves coefficient of logarithm under logarithm: 2*log(5)=log(5**2)=log(25).

How is it possible to avoid this issue and revert if this happened?

Francesco Bonazzi

unread,
Oct 19, 2015, 3:33:13 AM10/19/15
to sympy
In [1]: Mul(2, log(5), evaluate=False)
Out[1]: 2*log(5)

Francesco Bonazzi

unread,
Oct 19, 2015, 3:35:45 AM10/19/15
to sympy


On Monday, 19 October 2015 07:12:46 UTC+2, Paul Royik wrote:
Hello.
I noticed that simplify moves coefficient of logarithm under logarithm: 2*log(5)=log(5**2)=log(25).


Are you sure it does?

I get this:

In [2]: 2*log(5)
Out[2]: 2*log(5)

In [5]: log(25)
Out[5]: log(25)



Paul Royik

unread,
Oct 19, 2015, 5:32:34 AM10/19/15
to sympy
simplify(2log(5)) returns log(25)
How to revert this?

Francesco Bonazzi

unread,
Oct 19, 2015, 8:05:20 AM10/19/15
to sympy
Try factor( )

In [1]: log(25)
Out[1]: log(25)

In [2]: factor(log(25))
Out[2]: 2*log(5)



To apply it only to logarithm expressions:

In [6]: l = log(25)

In [7]: l.replace(lambda expr: isinstance(expr, log), lambda expr: factor(expr))
Out[7]: 2*log(5)

Paul Royik

unread,
Oct 19, 2015, 12:40:11 PM10/19/15
to sympy
Thank you very much.
It works!
Reply all
Reply to author
Forward
0 new messages