我写了一个 python 包,它在 Galois 字段上实现了 numpy 数组。除了普通的数组算术,它还支持线性代数。https://github.com/mhostetter/galois
这是一个执行您所要求的示例的示例。
In [1]: import numpy as np
In [2]: import galois
In [3]: GF = galois.GF(2**3)
In [4]: print(GF.properties)
GF(2^3):
characteristic: 2
degree: 3
order: 8
irreducible_poly: Poly(x^3 + x + 1, GF(2))
is_primitive_poly: True
primitive_element: GF(2, order=2^3)
In [5]: A = GF([[6,2,1],[7,0,4],[1,7,3]]); A
Out[5]:
GF([[6, 2, 1],
[7, 0, 4],
[1, 7, 3]], order=2^3)
In [6]: np.linalg.inv(A)
Out[6]:
GF([[5, 5, 4],
[3, 0, 1],
[4, 3, 7]], order=2^3)
In [7]: np.linalg.inv(A) @ A
Out[7]:
GF([[1, 0, 0],
[0, 1, 0],
[0, 0, 1]], order=2^3)