# Polynomial Long Division with Variable Coefficients

This post is a wiki. Anyone with karma >750 is welcome to improve it.

I want to divide the following polynomial (in terms of $t$) with coefficients in terms of $\lambda$.

$$(\lambda^6 - 5\lambda^4 + 6\lambda^2 - 1)t^5 + (\lambda^5 - 4\lambda^3 + 3\lambda^2)t^6$$

by $$\lambda t^2 -\lambda^2 t + \lambda$$

The resulting quotient will include a fractional component (the numerator's degree will be strictly less than the denominator's degree).

This is what a quotient and remainder, added together, might look like:

$$t(\frac{2\lambda^8 - 9 \lambda^6 + 2 \lambda^5 + 6 \lambda^4 - 4\lambda^2}{\lambda}) + t^3(\frac{2\lambda^6 - 9\lambda^4 + 3\lambda^3 + 6\lambda^2 -1 }{\lambda}) + \frac{t(\lambda^4 - 2\lambda) + (\lambda^3 - 4\lambda^2)}{\lambda t^2 - \lambda^2 t + \lambda}$$

I have tried the following thus far Any suggestions? The code below "does not work", because it outputs a quotient whose degree is greater than the degree of the dividend. Here $y$ takes the place of $\lambda$ and $x$ takes the place of $t$.

The quotient is:

-2*x^8 - x^4*y^4 + 2.0*x^6 - 3.0*x^5 - 1.0*x^4 - (2*x^5 + x^3)*y^3 + (-2*x^6 + 2.0*x^4 - x^2)*y^2 + (-2*x^7 +
4.0*x^5 + 1.0*x^3 - x)*y - 1
The remainder is:

-x^5 + (2*x^10 + 3.0*x^7 - 1.0*x^6 + 3.0*x^5 + 1.0*x^4 + x^2 + 1)*y


The code:

from sympy import Function, rsolve_poly, Symbol, rsolve, rsolve_hyper, oo
from sympy.abc import n

x = var('x')
y = var('y')
P.<x,y> = PolynomialRing(CC)
f = (y**5 - 4*y**3 + 3*y**2)*x**6 + (y**6 - 5*y**4 + 6*y**2 - 1)*x**5
g = y*x**2 - y**2*x + y

def division(dividend, divisor):
return (dividend._maxima_().divide(divisor).sage())

a = division(f,g)
print("The quotient is: \n")
print(a[0])
print("The remainder is: \n")
print(a[1])

edit retag close merge delete

Sort by » oldest newest most voted

Your polynomials are not polynomials with two indeterminates lambda and t. They are polynomial in t with coefficients in function field in lambda, so the definition of the rings you are working in should reflect that. Here is a possiblity:

sage: R.<l> = FunctionField(QQ) ; R
Rational function field in l over Rational Field
sage: S.<t> = R[] ; S
Univariate Polynomial Ring in t over Rational function field in l over Rational Field
sage: P = (l^6-5*l^4+6*l^2-1)*t^5 + (l^5-4*l^3+3*l^2)*t^6
sage: Q = l*t^2 - l^2*t + l
sage: a,b = P.quo_rem(Q)
sage: a
(l^4 - 4*l^2 + 3*l)*t^4 + ((2*l^6 - 9*l^4 + 3*l^3 + 6*l^2 - 1)/l)*t^3 + (2*l^6 - 10*l^4 + 3*l^3 + 10*l^2 - 3*l - 1)*t^2 + ((2*l^8 - 12*l^6 + 3*l^5 + 19*l^4 - 6*l^3 - 7*l^2 + 1)/l)*t + 2*l^8 - 14*l^6 + 3*l^5 + 29*l^4 - 9*l^3 - 17*l^2 + 3*l + 2
sage: b
(2*l^10 - 16*l^8 + 3*l^7 + 41*l^6 - 12*l^5 - 36*l^4 + 9*l^3 + 9*l^2 - 1)*t - 2*l^9 + 14*l^7 - 3*l^6 - 29*l^5 + 9*l^4 + 17*l^3 - 3*l^2 - 2*l
sage: a*Q+b == P
True
sage: a.degree()
4
sage: b.degree()
1

more