using expression Ok in two places but raised error in third [closed]
I am new to Sagemath. I am writing code to divide univariate polynomials (I know Sagemath has quo_rem and other ways but want the steps) `
def div1(f,f1): # returns qoutient and remainder of dividing f by f1
R.<x>=QQ['x']
g=R(f)
f1=R(f1)
q=R(0)
n=g.degree()
l=g.lt()
print(g,g.parent()," degree =",g.degree()," leading term =",g.lt())
while g.degree()>0:
if g.degree()>f1.degree():
tt=(g.lt()/f1.lt())
g=g-tt*f1
q=q+tt
print(g,"\t<<>>\t",q)
return [q,g]
The first two uses of g.degree() were OK but the one in the while loop raised an error AttributeError: 'sage.rings.fraction_field_element.FractionFieldElement_1poly_field' object has no attribute 'degree' I don't understand why. I would greatly appreciate any guidance Thanks
use exact division
//
to remain in the ring of polynomial, instead of division/
that land in the fraction field