polynomial division

317 views
Skip to first unread message

Michael Beeson

unread,
Apr 22, 2012, 4:23:53 PM4/22/12
to sage-s...@googlegroups.com
Sage version 4.6.1  (I know it's old, new one is downloading now, but I don't think this is a version problem.)
Given:  polynomial f in x  with some letters for the coefficients,  and polynomial psi  of lower degree in x with constant coefficients.
Wanted:  remainder of f  on division by psi  as polynomials in x,  with coefficients involving the letters in f.  
Problem:  Sage treats f as a polynomial in many variables and I can't convince it to treat it as a polynomial in x only and perform the division (or pseudo division).
Example:

sage: R.<x,N,p,r,m,l> = PolynomialRing(QQ,6)
sage: a = x - x^-1
sage: b = x^4-x^-4
sage: c = x^9 - x^-9
sage: f = N*a*b*c - (p*a+r*c)*(m*a + l *c)
sage: t = x^2  - x^-2
sage: f = x^20*(N*a*b*c - (p*a+r*c)*(m*a + l *c)*t)
sage: f 
-x^40*r*l + x^36*r*l + x^34*N - x^32*r*m - x^32*p*l - x^32*N 
+ x^30*r*m + x^30*p*l + x^28*r*m + x^28*p*l - x^26*r*m - x^26*p*l
 - x^26*N - x^24*p*m + x^24*N + 2*x^22*p*m + 2*x^22*r*l - 2*x^18*p*m 
 - 2*x^18*r*l + x^16*p*m - x^16*N + x^14*r*m + x^14*p*l + x^14*N 
 - x^12*r*m - x^12*p*l - x^10*r*m - x^10*p*l + x^8*r*m + x^8*p*l 
 + x^8*N - x^6*N - x^4*r*l + r*l

Now psi should be the 28-th cyclotomic polynomial  x^12-x^10+x^8...;  so in a multivariate polynomial I can't compute that directly, 
first sign of trouble.  So I typed it in, and then  f.quo_rem(psi)  does not yield the desired answer, because as polynomials in  6 variables, psi does not divide f.

Justin C. Walker

unread,
Apr 22, 2012, 4:53:45 PM4/22/12
to sage-s...@googlegroups.com

On Apr 22, 2012, at 13:23 , Michael Beeson wrote:

> Sage version 4.6.1 (I know it's old, new one is downloading now, but I
> don't think this is a version problem.)
> Given: polynomial f in x with some letters for the coefficients, and
> polynomial psi of lower degree in x with constant coefficients.
> Wanted: remainder of f on division by psi as polynomials in x, with
> coefficients involving the letters in f.
> Problem: Sage treats f as a polynomial in many variables and I can't
> convince it to treat it as a polynomial in x only and perform the division
> (or pseudo division).

You might try starting with this (unverified):

R.<N,p,r,m,l> = PolynomialRing(QQ)
K=R.fraction_field()
S.<x>=PolynomialRing(K)

HTH

Justin

--
Justin C. Walker, Curmudgeon at Large
Institute for the Absorption of Federal Funds
-----------
My wife 'n kids 'n dogs are gone,
I can't get Jesus on the phone,
But Ol' Milwaukee's Best is my best friend.
-----------


Volker Braun

unread,
Apr 22, 2012, 6:24:02 PM4/22/12
to sage-s...@googlegroups.com
Because you divided by x in your computation, the polynomial f was coerced into the fraction field. In the fraction field, quotient is always possible without reminder:

sage: f.parent()
Fraction Field of Multivariate Polynomial Ring in x, N, p, r, m, l over Rational Field

You want to convert f back into the polynomial ring:

sage: f = R(f)
sage: f.parent()
Multivariate Polynomial Ring in x, N, p, r, m, l over Rational Field

sage: f.quo_rem(psi) # works now 

Michael Beeson

unread,
Jan 5, 2013, 8:26:06 PM1/5/13
to sage-s...@googlegroups.com

I want to take, for example,  x^2 + 1  mod  a*x  and get quotient (1/a)*x  and remainder 1.    It doesn't work if I work in PolynomialRing  because then you can't have 1/a.  
It doesn't work in the quotient field because then you always get remainder 0.    To have  f.quo_rem(g)  work,  I must anticipate all denominators that might occur in the 
coefficients and multiply f by them to begin with, as shown in the following example.   But I'd rather have sage treat x as a polynomial variable and the others, like a, as rational variables.
Can that be done?

----------------------------------------------------------------------
| Sage Version 4.8, Release Date: 2012-01-20                         |
| Type notebook() for the GUI, and license() for information.        |
----------------------------------------------------------------------
sage: R.<a,x> = PolynomialRing(QQ,2)
sage: f = x^2 + 1
sage: g = a*x
sage: f.quo_rem(g)
(0, x^2 + 1)
sage: f.parent()
Multivariate Polynomial Ring in a, x over Rational Field
sage: f = a*(x^2+1)
sage: f.quo_rem(g)
(x, a)
 

John Cremona

unread,
Jan 6, 2013, 12:54:41 PM1/6/13
to sage-s...@googlegroups.com
Easy, you just need to define the ring Q(a)[x] like this:

sage: K.<a> = FractionField(PolynomialRing(QQ,'a'))
sage: R.<x> = K[]
sage: f = x^2+1
sage: g = a*x
sage: f.quo_rem(g)
(1/a*x, 1)
Reply all
Reply to author
Forward
0 new messages