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

simplify produces wrong answer with non-commuting symbols #25590

Closed
jtmacair opened this issue Aug 24, 2023 · 1 comment · Fixed by #25595
Closed

simplify produces wrong answer with non-commuting symbols #25590

jtmacair opened this issue Aug 24, 2023 · 1 comment · Fixed by #25595
Labels

Comments

@jtmacair
Copy link

I'm not sure why #25572 was closed. A misreading of the expressions maybe? Let me try one more time.

To see the problem, please look at the term that contains the non-commuting symbols A and B in the original expression and compare it with the corresponding term in the output. Simplify has incorrectly reversed the order from BA to AB within the same term. (The other terms are just part of the context in which the problem occurs.)

from sympy import *
x = symbols('x')
A, B = symbols('A B', commutative=False)
expr = 2*cos(x)*sin(x)*B*A + cos(x)**2
print(expr.simplify())

Output

sin(2*x)*A*B + cos(2*x)/2 + 1/2
@sylee957
Copy link
Member

sylee957 commented Aug 24, 2023

I confirm that the issue is valid
having the cos(x)**2 triggers the changes of the wrong result

expr = 2*cos(x)*sin(x)*B*A
print(expr.simplify())

sin(2*x)*B*A

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

Successfully merging a pull request may close this issue.

2 participants