sympy / sympy

A computer algebra system written in pure Python
https://sympy.org/
Other
12.77k stars 4.38k forks source link

Incorrect LaTeX Representation for Logarithms #26897

Open thuongvovan opened 1 month ago

thuongvovan commented 1 month ago

When converting logarithmic expressions to LaTeX using SymPy's latex function, the output for log(b, a) is incorrectly represented as \frac{\log{a}}{\log{b}}. This should instead be rendered as \log_{a}(b). Natural logarithm should default as \ln(a) \ln(b)

There is a fix here but it seems like the latest version isn't there yet? https://github.com/sympy/sympy/pull/19396/commits/7227e21411a48e46add398a78bc8415c7a6bf05b#diff-2a60b6b9791931a1418810380aae96f630bc05e34e3fb4b073f2a3a19f66dfa4

oscarbenjamin commented 1 month ago

It is not the LaTeX representation that does this but rather the evaluation code:

In [13]: log(x, y)
Out[13]: 
log(x)
──────
log(y)

In [14]: latex(log(x, y))
Out[14]: '\\frac{\\log{\\left(x \\right)}}{\\log{\\left(y \\right)}}'

In [15]: log(x, y, evaluate=False)
Out[15]: log(x, y)

In [16]: latex(log(x, y, evaluate=False))
Out[16]: '\\log{\\left(x \\right)}'
oscarbenjamin commented 1 month ago
In [16]: latex(log(x, y, evaluate=False))
Out[16]: '\\log{\\left(x \\right)}'

This looks like a bug.

thuongvovan commented 1 month ago

Thanks for considering. I hope this error will be fixed soon.