Error: "fraction must have unit denominator" when converting symbolic expression into Univariate Polynomial Ring

asked 2 years ago

IvanaGyro gravatar image

updated 1 year ago

FrédéricC gravatar image

I want to convert a symbolic expression into (fractional) polynomials over RealField.

ploy_real = RealField()['E']
(E_real,) = ploy_real._first_ngens(1)
E = SR.var('E')
f = -1/4*(4*E + 3)/E
f.polynomial(base_ring=RealField())

However, I got this error. How to solve this error? Hasn't f already had a denominator E?

/usr/lib/python3/dist-packages/sage/rings/fraction_field.py in _call_(self, x, check)
   1242             # However, too much existing code is expecting this to throw a
   1243             # TypeError, so we decided to keep it for the time being.
-> 1244             raise TypeError("fraction must have unit denominator")
   1245         return num * den.inverse_of_unit()
Preview: (hide)

Comments

Your expression cannot be a polynomial. Consider :

sage: f=1/4*(4*x+3)/x ; f
1/4*(4*x + 3)/x
sage: f.expand()
3/4/x + 1

i. e. 1+34x, which is not a (finite) polynomial. You may try :

sage: with assuming(x>0,x<1): f==f.expand().subs((sum(x^p, p, 0, oo)==sum(x^p, p, 0, oo, hold=True)).subs(x==1-x))
1/4*(4*x + 3)/x == 3/4*sum((-x + 1)^p, p, 0, +Infinity) + 1

i. e.

4x+34x=34+p=0(x+1)p+1

valid for x(0 1).

But this "polynomial" has an infinite number of terms...

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2 years ago )

I see. I found what I want is f.fraction(RealField()) Thank you.

IvanaGyro gravatar imageIvanaGyro ( 2 years ago )

I see. BTW, ypu can get that more easily, along the lines of :

sage: f
1/4*(4*x + 3)/x
sage: f.laurent_polynomial(SR)
3/4*x^-1 + 1

HTH,

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2 years ago )