Ask Your Question
1

Using vector with variables over a finite field

asked 2023-08-11 00:21:04 +0100

Saar gravatar image

updated 2023-08-11 08:19:55 +0100

FrédéricC gravatar image

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 flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2023-08-11 06:40:41 +0100

rburing gravatar image

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.

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

Stats

Asked: 2023-08-11 00:21:04 +0100

Seen: 150 times

Last updated: Aug 11 '23