-2
x=Symbol('x')

M=Matrix([[1,x],[x^2,x^3]])

s=M.det()

f=lambdify(x,s)

I need to know f(2)=? in GF(2^8),the caculate rules obey the GF(2^8)

Tobi208
  • 1,306
  • 10
  • 17
Marat
  • 1
  • The code snippet you give is of no use. What is `f` ? –  Feb 09 '22 at 10:19
  • 1
    Hi Marat, welcome to Stack Overflow. it's not very clear to me what you mean by `GF(2^8)`, which seems to be an important concept for your question. Can you elaborate on what that notation means? It doesn't match any of the code you've given. If the `2^8` part is supposed to do exponentiation (e.g. it means 2 to the 8th power), then you want `2 ** 8` for that part. But I have no idea what the `GF` means, so I can't help with that part. – Blckknght Feb 09 '22 at 10:19
  • @Blckknght: GF stands for Galois Field and this request is most probably related to error correction. But the question is very very poor. –  Feb 09 '22 at 10:21
  • Does this answer your question? [How to work with polynomials over Galois fields in SymPy](https://stackoverflow.com/questions/50194135/how-to-work-with-polynomials-over-galois-fields-in-sympy) – anatolyg Feb 09 '22 at 10:22
  • @anatolyg: as the link says, SymPy does not support fields of order p^m. –  Feb 09 '22 at 10:24
  • @Yves Daoust: f make no sense. Since the type of s is not a function, f make s become a function. For example, I know x=2, then I need to know x**2+x=? in GF(2^8). – Marat Feb 09 '22 at 10:32
  • What is the generator polynomial ? And what is 2 in GF(2^8) ? –  Feb 09 '22 at 10:36
  • @YvesDaoust the generator polynomilal is x^8+x^4+x^3+x^2+1,and the 2=0000 0010 – Marat Feb 10 '22 at 01:57
  • 00000010 corresponds to the monomial x. That's all there is to say, unless you have other operations to perform. It makes no sense to write x=2. –  Feb 10 '22 at 08:42

2 Answers2

2

It's not exactly clear what you're asking to do, but here are some tools to assist. I created a Python package galois that extends NumPy arrays over Galois fields. All finite fields GF(p^m) are supported. Linear algebra and polynomials, among much more, are also supported.

Here is an example computing the matrix determinant and polynomial evaluation you alluded to.

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)
Matt Hostetter
  • 360
  • 1
  • 10
0

In GF(2^8), the elements are usually represented as formal polynomials of degree 7, which are sums of monic monomials. E.g. x² + x, which can be written in the compact form 00000110 (this is not to be taken as an ordinary binary number).

Evaluating the polynomial at some x does not make sense and is not made, especially as x should not be other than 0 or 1. (You might be tempted to say that 0²+0=0 and 1²+1=0, but this is irrelevant.)