### 11.8.18 Construction of a Galois field

A Galois field is a finite field. A Galois field has the characteristic p for some prime number p, and its order is pn for some integer n. Any Galois field of order pn is isomorphic to ℤ/pℤ[X]/I, where I is the ideal generated by an irreducible polynomial P(X) in ℤ/pℤ[X]

The GF command creates Galois fields.

- GF takes two mandatory arguments and one optional argument:
  - p, a prime number.
  - n, an integer greater than 1 (or an irreducible polynomial over ℤ/pℤ[X]).

    If n is an integer, the first two arguments can be combined and entered as a prime power pn.

  - Optionally vars, either the name of a variable or a list of two or three variables. These variables must be symbolic, so you should purge them if necessary.
- GF(p,n ⟨,vars ⟩) returns a Galois field of characteristic p having pn elements. The output will look like GF(p,P(k),[k,K,g],undef) where:
  - p is the characteristic.
  - P(k) is an irreducible polynomial generating an ideal I in ℤ/pℤ[X], the Galois field being the quotient of ℤ/pℤ[X] by I.
  - k is the name of the polynomial variable.
  - K is the name of the Galois field (which will be given to a free variable).
  - g is a generator of the multiplicative group K∗. You can build elements of the field with polynomials in g.
  If the optional argument vars is given:
  - vars consists of a variable name, then g is that variable name.
  - If vars consists of a pair of variable names, then k will be the first variable and K will be the second variable.

    In this case, there is no generator given and the elements of K must be given by K(P(k)) for a polynomial P(k).

  - If vars consists of three variable names, then k will be the first variable, K will be the second variable and g will be the third variable.
- The elements of the field will be 0,g,g2,…,gpn−2.
- Once a Galois field is created in Xcas, use elements of the field to create polynomials and matrices, and use the usual operators on them, such as +, -, *, /, ^, inv, sqrt, quo, rem, quorem, diff, factor, gcd, egcd, etc.
- Note that there are still some limitations due to an incomplete implementation of some algorithms, such as multivariate factorization when the polynomial is not unitary.

#### Examples

To create a Galois field with parameters p=2 and n=8, input:

GF(2,8)

GF(2,k8+k4+k3+k2+1, | ⎡ ⎣ | k,K,g | ⎤ ⎦ | ,undef)

The field K has 28=256 elements and g generates the multiplicative group of this field ({1,g,g2,…,g254}). The elements of this field can be written as polynomials in g or as K(P(k)), where P(k) is a polynomial in k.

g^9

or:

K(k^9)

(g5+g4+g3+g) |  |  |  |  |  |  |  |  |  |

Indeed, g8=g4+g3+g2+1 and therefore g9=g5+g4+g3+g.

Compute the inverse of a matrix in a Galois field:

GF(3,5,b):; A:=[[1,b],[b,1]]:; inv(A)

⎡ ⎢ ⎣ |
(b3+b2−b) | (−b4−b3+b2)
(−b4−b3+b2) | (b3+b2−b)
| ⎤ ⎥ ⎦

Factor a polynomial over a Galois field:

GF(5,3,c):; p:=x^2-c-1:; factor(p)

| ⎛ ⎝ | ⎛ ⎝ | 1%5 | ⎞ ⎠ | x+ | ⎛ ⎝ | (−2 c2+2 c) | ⎞ ⎠ | ⎞ ⎠ | ⎛ ⎝ | ⎛ ⎝ | 1%5 | ⎞ ⎠ | x+ | ⎛ ⎝ | (2 c2−2 c) | ⎞ ⎠ | ⎞ ⎠

As one can see in the these examples, the output contains many times the same information that you would prefer not to see if you work many times with the same field. For this reason, the definition of a Galois field may have an optional argument, a variable name which will be used thereafter to represent elements of the field. Since you will also most likely want to modify the name of the indeterminate, the field name is grouped with the variable name in a list passed as third argument to GF. Note that these two variable names must be quoted.

G:=GF(2,2,['w','G']):; G(w^2)

Done,G | ⎛ ⎝ | w+1 | ⎞ ⎠

G(w^3)

G(1) |  |  |  |  |  |  |  |  |  |

Hence, the elements of GF(2,2) are G(0), G(1), G(w) and G(w^2)=G(w+1).

We may also impose the irreducible primitive polynomial that we wish to use, by putting it as second argument (instead of n), for example:

G:=GF(2,w^8+w^6+w^3+w^2+1,['w','G'])

If the polynomial is not primitive, Xcas will replace it automatically by a primitive polynomial, for example:

G:=GF(2,w^8+w^7+w^5+w+1,['w','G'])

GF | ⎛ ⎝ | 2,w8+w7+w5+w+1, | ⎡ ⎣ | w,G | ⎤ ⎦ | ,undef | ⎞ ⎠