使用 python 求解 F(2) 域上的线性方程组

MRm*_*MRm 6 python numpy linear-algebra finite-field

有没有一种方法可以使用 python 求解域 F2 上的线性方程组(即加法和乘法模 2 - 二进制域)?我已经尝试寻找有用的软件包有一段时间了,但没有找到任何结果......

谢谢,

小智 2

我创建了一个 Python 包galois,它将 NumPy 数组扩展到有限域上。它还支持np.linalg.

Ax = b下面是求解in线性系统x的示例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
Run Code Online (Sandbox Code Playgroud)