Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect Simplification in SymPy of Powers to Logarithms #26006

Closed
georgepittock opened this issue Dec 20, 2023 · 2 comments
Closed

Incorrect Simplification in SymPy of Powers to Logarithms #26006

georgepittock opened this issue Dec 20, 2023 · 2 comments

Comments

@georgepittock
Copy link
Contributor

Problem Description:

There is a further simplification that should be done when simplifying expressions in cases involving logarithmic powers. When attempting to simplify expressions like $(b^x)^\frac{\log(a)} {\log(b)}$, the expected result should be $a^x$.

Code Snippet:

>>> from sympy import symbols, log, simplify, pprint
>>> a, b, x = symbols("a b x")
>>> expr = (b**x)**(log(a,b))
>>> pprint(simplify(expr), use_unicode=False)
    log(a)
    ------
    log(b)
/ x\
\b /
@oscarbenjamin
Copy link
Collaborator

You need to set some assumptions on the symbols:

In [53]: a, b = symbols('a, b', positive=True)

In [54]: x = symbols('x', real=True)

In [55]: e = (b**x)**(log(a,b))

In [56]: e
Out[56]: 
 xlog(a)
        

In [57]: simplify(e)
Out[57]: 
 x
a 

(This is still not valid for b=1.)

Otherwise you can have:

In [58]: N(expr.subs({a:2, x:2, b:-2}))
Out[58]: 1.02142647003754 - 0.306662540131076

@georgepittock
Copy link
Contributor Author

I see - thank you, thanks for clarifying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants