Pseudo Division of Polynomials

This code is for Maxima Computer algebra System. It helps in calculating pseudo remainder and pseudo quotient of two polynomials.
pseudo_poly_div(uu,vv,x):=block([r,v,d,dr,dv,l,n,t,p:0,i:0],
v:expand(vv),dv:hipow(v,x),r:expand(uu),dr:hipow(r,x),
if(dv<=dr) then (
    l:coeff(v,x,dv),
    if(dv=0) then v:0 else v:subst(0,x^dv,v))
else l:1,
d:dr-dv+1,
while(r#0 and dv<=dr) do( i:i+1,
    t:expand(x^(dr-dv)*coeff(r,x,dr)),
    if(dr=0) then r:0 else r:subst(0,x^dr,r),
    r:expand(l*r)-expand(t*v),
    p:expand(l*p)+expand(t),
    dr:hipow(r,x)),
r:l^(d-i)*r,
m:l^d,
q:l^(d-i)*p,
map(ratsimp,[r,m,q]))$ 
Usage:
pseudo_poly_div(x^4-7*x+7,3*x^2-7,x); 
=> [336-189*x,27,9*x^2+21]
where  for m*f=g*q+r
r = 336-189*x, m = 27, q = 9*x^2+21

No comments:

Post a Comment

Disqus for http://programathing.blogspot.in/