Ask Your Question
1

Apply modulus to polynomial coefficients

asked 2020-11-17 22:46:09 +0100

BurnsBA gravatar image

I want to apply mod operator to a polynomial and get the expanded result. For example

$$ (x+1)^4 \bmod 6 $$ should give $$ x^4 + 4 x^3 + 4 x + 1 $$

What I've tried:

sage: ZP.<x> = ZZ[]
sage: ( (x+1)^4 ).factor_mod(6)
ValueError: p must be prime

sage: Mod( (x+1)^4 , 6)
TypeError: not a constant polynomial

and

a,b,c=var('a,b,c')
sage: ((a+b+c)^3).expand()
a^3 + 3*a^2*b + 3*a*b^2 + b^3 + 3*a^2*c + 6*a*b*c + 3*b^2*c + 3*a*c^2 + 3*b*c^2 + c^3
sage: (a+b+c)^3 % 3
TypeError: unsupported operand parent(s) for %: 'Symbolic Ring' and 'Symbolic Ring'
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2020-11-18 10:09:12 +0100

slelievre gravatar image

updated 2020-11-18 10:10:52 +0100

There are several ways to go depending whether the result should be a polynomial with coefficients in $\mathbb{Z}$ or a polynomial with coefficients in $\mathbb{Z}/6\mathbb{Z}$.

Here is an illustration for both options.

Define a polynomial ring and a polynomial:

sage: ZP.<x> = ZZ[]
sage: p = (x+1)^4
sage: p
x^4 + 4*x^3 + 6*x^2 + 4*x + 1
sage: p.parent()
Univariate Polynomial Ring in x over Integer Ring

Mod out by 6, keeping coefficients in the integers:

sage: q = p % 6
sage: q
x^4 + 4*x^3 + 4*x + 1
sage: q.parent()
Univariate Polynomial Ring in x over Integer Ring

Move to coefficients in modular integers:

sage: r = p.change_ring(Zmod(6))
sage: r
x^4 + 4*x^3 + 4*x + 1
sage: r.parent()
Univariate Polynomial Ring in x over Ring of integers modulo 6

The difference is apparent when you keep working with the modded out polynomial. Compare:

sage: 3 * q
3*x^4 + 12*x^3 + 12*x + 3

sage: 3 * r
3*x^4 + 3
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-11-17 22:45:17 +0100

Seen: 815 times

Last updated: Nov 18 '20