I created a Python package galois that extends NumPy arrays over finite fields. It also supports NumPy linear algebra routines in np.linalg
.
Here is an example solving a linear system Ax = b
for x
in GF(2)
.
In [1]: import numpy as np
In [2]: import galois
In [3]: GF = galois.GF(2)
In [4]: A = GF.Random((4,4)); A
Out[4]:
GF([[0, 1, 0, 0],
[0, 0, 1, 1],
[0, 0, 0, 1],
[1, 1, 0, 0]], order=2)
In [5]: x_truth = GF([1,0,1,1]); x_truth
Out[5]: GF([1, 0, 1, 1], order=2)
In [6]: b = A @ x_truth; b
Out[6]: GF([0, 0, 1, 1], order=2)
# Solve Ax = b for x
In [7]: x = np.linalg.solve(A, b); x
Out[7]: GF([1, 0, 1, 1], order=2)
# Verify that x is x_truth
In [8]: np.array_equal(x, x_truth)
Out[8]: True