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

asked 2023-01-08 11:40:16 +0100

IvanaGyro gravatar image

updated 2024-04-16 21:16:14 +0100

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()
edit retag flag offensive close merge delete

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+\frac{3}{4x}$, 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.

$$ \frac{4 \, x + 3}{4 \, x} = \frac{3}{4} \, {\sum_{p=0}^{+\infty} {\left(-x + 1\right)}^{p}} + 1 $$

valid for $x\in\left(0\ 1\right)$.

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

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2023-01-08 13:10:54 +0100 )edit

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

IvanaGyro gravatar imageIvanaGyro ( 2023-01-08 13:21:38 +0100 )edit

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 ( 2023-01-08 14:43:11 +0100 )edit