# Constructing Galois field array classes¶

The main idea of the galois package is that it constructs “Galois field array classes” using GF = galois.GF(p**m). Galois field array classes, e.g. GF, are subclasses of numpy.ndarray and their constructors a = GF(array_like) mimic the numpy.array() function. Galois field arrays, e.g. a, can be operated on like any other numpy array. For example: a + b, np.reshape(a, new_shape), np.multiply.reduce(a, axis=0), etc.

Galois field array classes are subclasses of galois.FieldArray with metaclass galois.FieldClass. The metaclass provides useful methods and attributes related to the finite field.

The Galois field $$\mathrm{GF}(2)$$ is already constructed in galois. It can be accessed by galois.GF2.

In [1]: GF2 = galois.GF2

In [2]: print(GF2)
<class 'numpy.ndarray over GF(2)'>

In [3]: issubclass(GF2, np.ndarray)
Out[3]: True

In [4]: issubclass(GF2, galois.FieldArray)
Out[4]: True

In [5]: issubclass(type(GF2), galois.FieldClass)
Out[5]: True

In [6]: print(GF2.properties)
GF(2):
characteristic: 2
degree: 1
order: 2
irreducible_poly: x + 1
is_primitive_poly: True
primitive_element: 1


$$\mathrm{GF}(2^m)$$ fields, where $$m$$ is a positive integer, can be constructed using the class factory galois.GF().

In [7]: GF8 = galois.GF(2**3)

In [8]: print(GF8)
<class 'numpy.ndarray over GF(2^3)'>

In [9]: issubclass(GF8, np.ndarray)
Out[9]: True

In [10]: issubclass(GF8, galois.FieldArray)
Out[10]: True

In [11]: issubclass(type(GF8), galois.FieldClass)
Out[11]: True

In [12]: print(GF8.properties)
GF(2^3):
characteristic: 2
degree: 3
order: 8
irreducible_poly: x^3 + x + 1
is_primitive_poly: True
primitive_element: x


$$\mathrm{GF}(p)$$ fields, where $$p$$ is prime, can be constructed using the class factory galois.GF().

In [13]: GF7 = galois.GF(7)

In [14]: print(GF7)
<class 'numpy.ndarray over GF(7)'>

In [15]: issubclass(GF7, np.ndarray)
Out[15]: True

In [16]: issubclass(GF7, galois.FieldArray)
Out[16]: True

In [17]: issubclass(type(GF7), galois.FieldClass)
Out[17]: True

In [18]: print(GF7.properties)
GF(7):
characteristic: 7
degree: 1
order: 7
irreducible_poly: x + 4
is_primitive_poly: True
primitive_element: 3