sympy_gamma icon indicating copy to clipboard operation
sympy_gamma copied to clipboard

log(e) terms could be cancelled to 1

Open bl0ckeduser opened this issue 11 years ago • 3 comments

Hi,

for example for the input: "diff(sin(cos(x^3)^2 + log(e^x)) / (3x^2 + x), x)"

the result contains a log(e) term.

I suspect this could easily be canceled to a 1.

Screenshot:

Anecdotally, for the same input, Maxima is also giving a log(e) term, but when I spell it as "%e", it happily cancels it down.

It's a detail, but then I guess fixing this would make the software ever-so-slightly better than it was before. My feelings about software development is that this the most that can be done on any given day.

Anyway, best regards and congrats on having what seems at a quick glance like a pretty readable and well-organized codebase :)

bl0ckeduser avatar Jun 14 '14 21:06 bl0ckeduser

In your expression, the e is a symbol and does not have any value associated with it. So log(e) will remain non evaluated. However, it can be attained by doing this.

In [1]: from sympy import *

In [2]: log(exp(1))
Out[2]: 1

debugger22 avatar Jun 14 '14 22:06 debugger22

@debugger22 is correct (and this is probably confusing) about that to Gamma e is a variable named e while E is the constant. See http://www.sympygamma.com/input/?i=e vs http://www.sympygamma.com/input/?i=E. It would probably make sense to alias e to E though (or perhaps add a "Did you mean?" result). However SymPy still won't automatically simplify the log(exp(x)) as this identity is only true when x is real: https://github.com/sympy/sympy/issues/5143.

In SymPy you can assume that x is real:

...
>>> log(exp(x))
   ⎛ x⎞
log⎝ℯ ⎠
>>> simplify(log(exp(x)))
   ⎛ x⎞
log⎝ℯ ⎠
>>> x = Symbol('x', real=True)
>>> log(exp(x))
x

and then it simplifies as you would expect.

lidavidm avatar Jun 15 '14 16:06 lidavidm

Long term we may need the ability to have "let e be: symbol, Euler's constant" at the top (wolfram alpha does this sort of thing all the time)

asmeurer avatar Jun 15 '14 16:06 asmeurer