Using vector with variables over a finite field

I'm trying to write a code that does some manipulation on a vector of variables and then checks something for each of their assignments. The manipulation includes multiplying the vector by a matrix. Everything is over GF(2) so for $n$ variables there are $2^n$ options which is fine with me.

I've seen that the following code works for declaring a vector with variables

 x, y, z = var('x y z')

vector([x, y, z]) 

My problem is that these variables aren't from GF(2), and so when I try multiplying it by a matrix which is indeed declared over GF(2), it throws an exception.

The specific exception is TypeError: positive characteristic not allowed in symbolic computations.

Is there any workaround for still doing the manipulation?

edit retag close merge delete

Sort by » oldest newest most voted

Instead of symbolic variables you can use the generators of a polynomial ring:

sage: R.<x,y,z> = PolynomialRing(GF(2))
sage: v = vector([x, y, z])
sage: M = matrix(GF(2), [[0, 1, 0], [0, 0, 1], [1, 0, 0]])
sage: M*v
(y, z, x)


Like symbolic expressions, polynomials allow substitution/evaluation with the subs method.

more