symengine / symengine.py

Python wrappers for SymEngine
MIT License
165 stars 65 forks source link

Checking whether a given expression is polynomial #492

Open dominikgeissler opened 3 weeks ago

dominikgeissler commented 3 weeks ago

Hey! Using symengine, I was trying to check whether a given expression is polynomial.

In the C++ documentation there exists a method is_polynomial() which would be exactly what I was looking for. This method however does not seem to exist in the python bindings (as of version 0.11.0).

Using the given is_finite propery sadly doesn't work and produces some interesting result when compared to SymPy

import symengine as se
import sympy as sp

expr = se.zoo

# 👇 Is this the way it should behave? If yes, why?
print(se.S(expr).is_finite)         # None
print(sp.S(expr).is_finite)         # False

expr = "x ** 5"

# As expected...
print(se.S(expr).is_finite)         # None
print(sp.S(expr).is_finite)         # None

# However, this behavior is what I want
print(sp.S(expr).is_polynomial())   # True

Are there any plans of making the function accessible? Is there a workaround (without simply using SymPy)?

Thanks in advance!

bjodah commented 3 weeks ago

Assumptions are not yet implemented in SymEngine. So almost all .is_xxxxx methods will return None (which signifies "indeterminate").

Looks like is_polynomial would be useful in the python bindings. I think it's just a matter of someone finding the time / having the need to write a pull request.