Rational with symbol as numerator not working?
Hello,
I'm testing out the library and tried to create a rational with a symbol as the numerator:
import symengine
A = symengine.Symbol("A")
B = symengine.Rational(A,10)
However, when I try this, I get the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "symengine_wrapper.pyx", line 1586, in symengine.lib.symengine_wrapper.Rational.__new__
File "symengine_wrapper.pyx", line 1642, in symengine.lib.symengine_wrapper.Integer.__new__
File "symengine_wrapper.pyx", line 1078, in symengine.lib.symengine_wrapper.Basic.__int__
File "symengine_wrapper.pyx", line 1072, in symengine.lib.symengine_wrapper.Basic.__float__
File "symengine_wrapper.pyx", line 921, in symengine.lib.symengine_wrapper.Basic.n
File "symengine_wrapper.pyx", line 4033, in symengine.lib.symengine_wrapper.evalf
RuntimeError: Symbol cannot be evaluated.
II noticed in this issue that evalf for rationals with symbols has been excluded and thatthe error above runs evalf.
So is something like x/1 intentionally restricted from this library?
However, I'm able to create a rational if the symbol is the denominator:
B = symengine.Rational(10,A)
I always thought Rational is meant for just numbers. You can create x/1 directly using the division / operator.
Oh great, thats good to know!
Give this works in sympy, should it not also work in symengine?
Changing https://github.com/symengine/symengine.py/blob/740b26fb5832e155d8e1f6d289863a17763b3523/symengine/lib/symengine_wrapper.pyx#L1592 to _sympify(p)/q should work.
@isuruf should we submit a PR?
Sure. If someone can send a PR, I'll review.
@eric-wieser do you want to send a PR for this?