# Generate a Matrix over a Finite Field with symbolic variables

Hi everyone,

I am currently trying to generate a matrix over a finite field of 2 using symbolic variables a,b,c,and d instead of integers. The current problem I am having is that sage tries to convert these variables into integers and do not allow me to generate the matrix.

Inputting: var('a, b, c, d') m = matrix(GF(2), [[a,b], [e,f]]) gives me the error: TypeError: unable to convert a to an integer

edit retag close merge delete

Sort by » oldest newest most voted

A classical trick is not to work in the symbolic ring, but to see your variables as polynomial indeterminates:

sage: R.<a,b,c,d,e,f> = PolynomialRing(GF(2)) ; R
Multivariate Polynomial Ring in a, b, c, d, e, f over Finite Field of size 2
sage: m = matrix(R, [[a,b], [e,f]]) ; m
[a b]
[e f]
sage: m^3
[                  a^3 + b*e*f a^2*b + b^2*e + a*b*f + b*f^2]
[a^2*e + b*e^2 + a*e*f + e*f^2                   a*b*e + f^3]


Alternatively, if you want not only to have 2=0 as before, but also x^2=x for your indeterminates:

sage: R.<a,b,c,d,e,f> = BooleanPolynomialRing() ; R
Boolean PolynomialRing in a, b, c, d, e, f
sage: m = matrix(R, [[a,b], [e,f]]) ; m
[a b]
[e f]
sage: m^3
[              a + b*e*f a*b*f + a*b + b*e + b*f]
[a*e*f + a*e + b*e + e*f               a*b*e + f]

more