ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 06 Jul 2017 00:12:28 -0500Polynomial Long Division with Variable Coefficientshttp://ask.sagemath.org/question/38187/polynomial-long-division-with-variable-coefficients/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])MunoThu, 06 Jul 2017 00:12:28 -0500http://ask.sagemath.org/question/38187/Division algorithm in a polynomial ring with variable coefficientshttp://ask.sagemath.org/question/37098/division-algorithm-in-a-polynomial-ring-with-variable-coefficients/ I am working on an algorithm to divide a polynomial `f` by a list of polynomials `[g1, g2, ..., gm]`. The following is my algorithm:
def div(f,g): # Division algorithm on Page 11 of Using AG by Cox;
# f is the dividend;
# g is a list of ordered divisors;
# The output consists of a list of coefficients for g and the remainder;
# p is the intermediate dividend;
n = len(g)
p, r, q = f, 0, [0 for x in range(0,n)]
while p != 0:
i, divisionoccured = 0, False
print(p,r,q);
while i < n and divisionoccured == False:
if g[i].lt().divides(p.lt()):
q[i] = q[i] + p.lt()//g[i].lt()
p = p - (p.lt()//g[i].lt())*g[i]
divisionoccured = True
else:
i = i + 1
if divisionoccured == False:
r = r + p.lt()
p = p - p.lt()
return q, r
Here is an example of implementing the algorithm:
K.<a,b> = FractionField(PolynomialRing(QQ,'a, b'))
P.<x,y,z> = PolynomialRing(K,order='lex')
f=a*x^2*y^3+x*y+2*b
g1=a^2*x+2
g2=x*y-b
div(f,[g1,g2])
Here is the result:
(a*x^2*y^3 + x*y + 2*b, 0, [0, 0])
(((-2)/a)*x*y^3 + x*y + 2*b, 0, [1/a*x*y^3, 0])
(x*y + 4/a^3*y^3 + 2*b, 0, [1/a*x*y^3 + ((-2)/a^3)*y^3, 0])
(4/a^3*y^3 + ((-2)/a^2)*y + 2*b, 0, [1/a*x*y^3 + ((-2)/a^3)*y^3 + 1/a^2*y, 0])
(((-2)/a^2)*y + 2*b, 4/a^3*y^3, [1/a*x*y^3 + ((-2)/a^3)*y^3 + 1/a^2*y, 0])
(2*b, 4/a^3*y^3 + ((-2)/a^2)*y, [1/a*x*y^3 + ((-2)/a^3)*y^3 + 1/a^2*y, 0])
Error in lines 6-6
Traceback (most recent call last):
and some other error messages.
We can see that it worked well until the leading term is `2b`. it does not recognize the `2b` as a term. I tried:
(x).lt().divides(1)
It gives the answer `False`. But I tried
(x).lt().divides(a)
It gives error message. Is there a way to solve this? Thank you for your help!
KittyLMon, 27 Mar 2017 14:26:48 -0500http://ask.sagemath.org/question/37098/