Solving a linear system of matrix equations in GF(2) using Sage

663 Views Asked by At

I am trying to solve a system of two equations of the form:

$$ \left\{ \begin{matrix} K_1XC + K_2YC & = V_1 \\ K_3XC + K_4YC & = V_2 \\ \end{matrix} \right. $$

where the $K_i$ and $V_i$ are constants, $C$ a "counting" vector filled with 1, and $X, Y$ diagonal matrices with the unknowns on the diagonal. All matrices coefficients are in $GF(2)$.

I tried to implement them using Sage like this:

R = PolynomialRing(GF(2), 64, "x")

X = diagonal_matrix(R.gens()[:32])
Y = diagonal_matrix(R.gens()[32:])

K1 = matrix.zero(R, 32)
# filling K1...
# same for K2, K3, K4

C = matrix.ones(R, 32, 1)

At this point, printing $K_1XC + K_2YC$ give me a huge column vector containing the equations I want. However, I am failing to find how to solve them.

sol = solve([K1*X*C + K2*Y*C == V1, K3*X*C + K4*Y*C == V2], [variables?])

throws me an error message no matter what I try, mostly TypeError: x0 is not a valid variable. and the likes.

This link advised to declare my 64 variables in the symbolic ring SR, which give me a TypeError: unsupported operand parent(s) for *: 'Finite Field of size 2' and 'Symbolic Ring'. It also explains that the resolution of such a system needs ideals and term orders, which I never heard of and seem above my math level.

How should I proceed to solve my system?