1 | initial version |
Fixed by casting m into the base ring, m=R(m) I guess this is some sloppy patch I would like to know if there is some smarter way to make this algorithm.
The code:
x=var('x')
R.<x>=PolynomialRing(QQ)
def div(p,q):
if q==0:
return("NaN")
elif q!=0:
l=0
r=p
while r!=0 and q.degree()<=r.degree():
t=r.leading_coefficient()/q.leading_coefficient()
m=x^r.degree()/x^q.degree()
m=R(m)
l=l+t*m
r=r-(t*m*q)
print(l,r)
return(l,r)