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

Equality of two expressions similar to sympy #496

Open
dominikgeissler opened this issue Oct 8, 2024 · 1 comment
Open

Equality of two expressions similar to sympy #496

dominikgeissler opened this issue Oct 8, 2024 · 1 comment

Comments

@dominikgeissler
Copy link

Hello!
When trying to check the equality for two expressions I want to utilize a method similar to the .equals() method in sympy (see example below)

import sympy as sp
import symengine as se

# In Symengine
expr1: se.Expr = se.S("(y + 1)**10/1024")
expr2: se.Expr = se.S("((1/2 + (1/2)*y)**10)")
print(expr1 == expr2)                       # False
print(expr1.expand() == expr2.expand())     # True

# In Sympy
expr1: sp.Expr = sp.S("(y + 1)**10/1024")
expr2: sp.Expr = sp.S("((1/2 + (1/2)*y)**10)")
print(expr1 == expr2)                       # False
print(expr1.expand() == expr2.expand())     # True
# 👇 behaviour I want to have
print(expr1.equals(expr2))                  # True

Is there a way to do this in symengine without calling additional methods (as .expand()) or using sympy?

Thanks in advance!

@rikardn
Copy link
Contributor

rikardn commented Oct 9, 2024

The closest in symengine is to use the is_zero property for the difference of the expressions. It is currently quite weak and will not be able to handle this expression.

I think in the end the only feasible way of comparing two polynomials for equality is to first expand them so the underlying function would need to do this. Doing it without expanding is a hard problem in general (see https://en.wikipedia.org/wiki/Polynomial_identity_testing).

The implementation is here https://github.com/symengine/symengine/blob/master/symengine/test_visitors.cpp if you'd like to take a look. Perhaps adding an is_equal function would be also be of value.

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