x=Symbol('x')
M=Matrix([[1,x],[x^2,x^3]])
s=M.det()
f=lambdify(x,s)
我需要知道 f(2)=? 在 GF(2^8) 中,计算规则服从 GF(2^8)
x=Symbol('x')
M=Matrix([[1,x],[x^2,x^3]])
s=M.det()
f=lambdify(x,s)
我需要知道 f(2)=? 在 GF(2^8) 中,计算规则服从 GF(2^8)
目前尚不清楚您要做什么,但这里有一些工具可以提供帮助。我创建了一个 Python 包galois,它在 Galois 字段上扩展了 NumPy 数组。支持所有有限域GF(p^m)
。还支持线性代数和多项式等。
这是一个计算您提到的矩阵行列式和多项式评估的示例。
In [1]: import numpy as np
In [2]: import galois
# Create a Galois field class
In [3]: GF = galois.GF(2**8)
# The irreducible polynomial is the one you specified in your comment
In [4]: print(GF.properties)
GF(2^8):
characteristic: 2
degree: 8
order: 256
irreducible_poly: x^8 + x^4 + x^3 + x^2 + 1
is_primitive_poly: True
primitive_element: x
# Create an array from its polynomials over GF(2) with degree < 8
In [5]: M = GF([[1, "x"], ["x^2", "x^3"]]); M
Out[5]:
GF([[1, 2],
[4, 8]], order=2^8)
# Compute the determinant of the matrix
In [6]: np.linalg.det(M)
Out[6]: GF(0, order=2^8)
# Construct the polynomial x^2 + x as you mentioned in your comment
In [7]: f = galois.Poly([1, 1, 0], field=GF); f
Out[7]: Poly(x^2 + x, GF(2^8))
# Evaluate the polynomial at x = 2
In [8]: f(2)
Out[8]: GF(6, order=2^8)
在 GF(2^8) 中,元素通常表示为 7 次的形式多项式,它们是一元单项式的和。例如 x² + x,可以写成紧致形式 00000110(这不能当作普通的二进制数)。
在某个 x 处评估多项式是没有意义的,而且是不成立的,尤其是当 x 不应该是 0 或 1 时。(你可能想说 0²+0=0 和 1²+1=0,但这是无关紧要。)