# How can I reduce the coefficients modulo a certain integer in a matrix of polynomials?

For eg, if I have a 2x1 matrix of polynomials,

A = matrix([[25x^3+50x^2+1],[18x+11]])


how do I reduce all the coefficients modulo 2 so that I have the matrix,

A = matrix([[x^3+1],[1]])

edit retag close merge delete

Sort by ยป oldest newest most voted

Starting from an already defined matrix, use its change_ring method to produce a matrix over a different ring.

Suppose we have defined our initial matrix:

sage: A = matrix([[25*x^3 + 50*x^2 + 1], [18*x + 11]])
sage: A
[25*x^3 + 50*x^2 + 1]
[          18*x + 11]


Consider it over the polynomial ring over integers modulo two:

sage: B = A.change_ring(GF(2)['x'])
sage: B
[x^3 + 1]
[      1]


If needed, move entries from there to polynomials over the integers:

sage: C = B.change_ring(ZZ['x'])
sage: C
[x^3 + 1]
[      1]


One of them behaves modulo two, the other does not:

sage: 3 * B
[x^3 + 1]
[      1]

sage: 3 * C
[3*x^3 + 3]
[        3]

more

You just have to define your polynomials as elements of the polynomial ring $\mathbb{F}_2[x]$ as follows:

sage: R.<x> = GF(2)[]
sage: x.parent()
Univariate Polynomial Ring in x over Finite Field of size 2 (using GF2X)
sage: A = matrix([[25*x^3+50*x^2+1],[18*x+11]])
sage: A
[x^3 + 1]
[      1]

more