# Finite Fields Package

A field is an algebraic structure obeying the rules of ordinary arithmetic. In particular, a field has binary operations of addition and multiplication, both of which are commutative and associative. A field has two special elements, the additive identity 0 and the multiplicative identity 1. This package adds rules to Plus, Times, and Power so that arithmetic on field elements will be defined properly. It also provides low‐level utilities for working with finite fields and for formatting finite field elements.

For any finite field there is a fixed prime number , called the characteristic of the field, such that the sum of of the 1 field elements gives the 0 field element. A finite field of characteristic has elements for some positive integer , which is loosely called the extension degree. This package represents field elements as polynomials in a single variable. The polynomials have degree at most and their coefficients are integers reduced mod .

The internal form of a finite field element is GF[p,ilist][elist] where GF stands for *Galois field*, is the prime characteristic of the field, ilist is the coefficient list of the irreducible polynomial which defines multiplication in the field, and elist is the coefficient list of the polynomial representing the particular element. Because this form can be a bit clumsy, the package provides several shortcuts for entering finite field elements.

GF[p][{k}] | the integer k in the field of integers mod p |

GF[p,1][{k}] | another way of expressing the integer k in the field of integers mod p |

GF[p,{0,1}][{k}] | the full form of the integer k in the field of integers mod p |

GF[p,d] | a field that is a degree d extension of a prime field isomorphic to (the integers mod p); an irreducible polynomial is selected automatically |

GF[p,ilist][elist] | the full form of a finite field element, where ilist is a list of integers of length representing the coefficients of an irreducible polynomial, and elist is a list of integers of length d giving the coefficients of the polynomial representation of the element |

Ways to enter finite field elements.

In[1]:= |

In[2]:= |

Out[2]= |

In[3]:= |

Out[3]//FullForm= | |

In[4]:= |

Out[4]= |

In[5]:= |

Out[5]= |

In[6]:= |

Out[6]= |

In[7]:= |

Out[7]= |

In[8]:= |

Out[8]= |

Zero is special. This package makes the assumption that zero is zero, regardless of the field it is in. The main consequence of this is that a field zero is simplified to the integer 0 automatically. Many functions in the Wolfram Language work better with this assumption. The assumption is not rigorously correct, but will not produce nonsensical output unless nonsensical input is given.

In[9]:= |

Out[9]= |

In[10]:= |

Out[10]= |

SetFieldFormat[f,FormatType->Subscripted] | set the field f to have a Subscripted output (default) |

SetFieldFormat[f,FormatType->FullForm] | set the field f to have a FullForm output |

SetFieldFormat[f,FormatType->FunctionOfCoefficients[g]] | set the field f to input and output a field element using g as the function name, with the arguments given by the coefficients of the polynomial representation of the field element |

SetFieldFormat[f,FormatType->FunctionOfCode[g]] | set the field f to input and output a field element using g as the function name, with the argument given by the integer code specifying the field element |

You may always input or output the FullForm of a finite field element; however, the package provides some shortcuts. The elements of a prime field may be written GF[p][{k}] or GF[p,1][{k}], both of which are interpreted as GF[p,{0,1}][{k}]. In general, if with prime and a positive integer, then GF[s] is interpreted as GF[p,d]. The expression GF[3, 4] stands for a degree 4 extension of the integers mod 3, that is, a field with 81 elements. When this form is used, the package automatically selects an irreducible polynomial, with coefficients given by ilist and with the property that GF[p,ilist][{0,1}] is a *primitive element* of the field. It is possible to provide your own irreducible polynomial by giving it explicitly, as in GF[3,{1,1,1,1,2,1}].

The default OutputForm of a finite field element is a list of integers subscripted by the characteristic of the field. The length of the list is the degree of the field extension over the prime field. If you are working with only one representation of any field, then this will be sufficient to distinguish which field contains a given element.

Since it is possible to have fields of the same size using different irreducible polynomials, it is useful to be able to distinguish elements from these fields. It is also convenient to have a more compact way to type finite field elements. The function SetFieldFormat establishes the input and output formats of field elements. You may always input field elements in the ways already described, or ask explicitly for the FullForm of the output.

Note that a field head, such as GF[2,3] may be assigned to a symbol. The assignment f8=GF[2,3] allows you to refer to a specific field element using .

In[11]:= |

In[12]:= |

Out[12]= |

In[13]:= |

In[14]:= |

Out[14]= |

In[15]:= |

Characteristic[f] | give the characteristic of field f |

ExtensionDegree[f] | give the degree of the extension of field f over its base field |

FieldSize[f] | give the number of elements in field f |

FieldIrreducible[f,s] | give the irreducible polynomial which defines multiplication in the field f, expressed in terms of the symbol s |

IrreduciblePolynomial[s,p,d] | find an irreducible polynomial of degree d over the integers mod prime p, expressed in terms of the symbol s |

The functions Characteristic, ExtensionDegree, FieldSize, FieldIrreducible, and IrreduciblePolynomial give important parameters about a finite field.

In[16]:= |

Out[16]= |

In[17]:= |

Out[17]= |

In[18]:= |

Out[18]= |

In[19]:= |

Out[19]= |

In[20]:= |

Out[20]= |

Successor[elem] | give the next element in a canonical ordering of the field elements (this function does not wrap, so the largest element has no successor) |

ReduceElement[elem] | give a field element in reduced form |

ToElementCode[elem] | give a non-negative integer less than the field size that encodes the field element |

FromElementCode[f,code] | give the field element of f corresponding to code, a non-negative integer less than the field size |

PolynomialToElement[f,poly] | give the field element of f corresponding to poly, a polynomial in one variable with integer‐valued coefficients |

ElementToPolynomial[elem,s] | give a polynomial in the symbol s corresponding to the field element elem |

Field element manipulation functions.

The functions Successor, ReduceElement, ToElementCode, FromElementCode, PolynomialToElement, and ElementToPolynomial are for working with finite field elements.

In[21]:= |

Out[21]= |

PowerListQ[f] | give True if a list representing the powers of a primitive element of the field is used to do field arithmetic, False otherwise |

FieldExp[f,n] | give the value of the discrete exponential function associated with the field f for integer n |

FieldInd[elem] | give the value of the discrete logarithm function associated with the field for element elem |

PowerList[f] | give a list of the data parts of the nonzero elements of the field f, generated by raising a primitive element of the field to integer powers 0, 1, 2, …, FieldSize[f]-1 |

PowerListToField[list] | give the field associated with the specified list of element data parts, where the elements are generated by successive powers of a primitive element |

Functions to support fast multiplication and division.

A finite field must have a prime power number of elements. If it has elements, where is a prime, then it is isomorphic to the integers mod . In this case the package does addition, subtraction, multiplication, and positive powers as usual over the integers and reduces the results using Mod. For negative powers the package uses PowerMod.

If the field has elements, where , then it is isomorphic to the set of polynomials in some variable having degree less than and with coefficients in the integers mod . Addition is polynomial addition except that the coefficients are reduced modulo . For multiplication the product is also reduced modulo an irreducible (nonfactorable) polynomial over the integers modulo .

Taking multiplicative inverses is equivalent to finding the extended greatest common divisor modulo with the irreducible polynomial. In other words, given the field element elem and the field's irreducible polynomial irred, find polynomials and such that PolynomialGCD[elem,irred,Modulus->p] equals PolynomialMod[a elem + b irred,p]. If the result of PolynomialGCD is unity, then is the inverse of elem.

There is a faster way to do multiplication and compute inverses, based on the fact that the multiplicative group of any finite field is cyclic. If you have a generator of the group along with a list of the positive powers of the generator in sequence, then multiplication and division can be reduced to adding and subtracting indices of the elements in the list.

The package supports this method of arithmetic by allowing you to either generate a field object from a list representing the powers of a primitive element (PowerListToField), or generate a list representing the powers of a primitive element from a field object (PowerList). Setting PowerListQ to True causes field arithmetic to use a list of primitive element powers, by defining the discrete exponential function FieldExp and the discrete logarithm function FieldInd. The FieldInd function is often called the index function for the field. The list of powers will depend on the choice of primitive element and on which irreducible polynomial is used for the field representation. Any element of the field for which FieldInd[elem] is relatively prime to FieldSize[f]-1 is also a primitive element of the field.

Field arithmetic using a list of primitive element powers has two disadvantages. It takes time to enter or compute the list, and the list can take considerable memory. In general, if you are doing only a few arithmetic operations, or if you are working in a large field, it is better not to create the list. Note that setting PowerListQ to False disables this method of doing arithmetic in a particular field, but it does not destroy the computed values of FieldExp and FieldInd.

In[22]:= |

Out[22]= |

In[23]:= |

In[24]:= |

Out[24]= |

In[25]:= |

Out[25]= |

In[26]:= |

Out[26]= |

Some books contain tables equivalent to the list given by PowerList. The function PowerListToField allows such a list to be used to define a field. The argument of PowerListToField is a list of ‐tuples of integers. The first ‐tuple is assumed to give the coefficients of the polynomial representation of the element of the field. This is used to determine whether the coefficients are listed constant‐term‐first or constant‐term‐last. The second ‐tuple is assumed to represent a primitive element of the field. The succeeding ‐tuples are assumed to represent successive powers of the second element. PowerListToField does some elementary error checking to verify that the input list is valid. If so, PowerListToField computes parameters of the field such as the characteristic and the irreducible polynomial.

In[27]:= |

Out[27]= |

In[28]:= |

Out[28]= |

In[29]:= |

Out[29]= |

In[30]:= |

Out[30]= |

In[31]:= |

Out[31]= |

### Compatibility with Other Wolfram Language Functions

Most Wolfram Language functions are not, indeed cannot be, designed to work over arbitrary fields. For instance, it is nonsensical to integrate an expression containing a finite field object. At best, such functions will not do anything when given such an expression.

You can generally expect these functions to treat the field object as an unknown symbol. Before using a function on an expression with finite field objects, it is wise to try some test cases first. The types of functions that might reasonably be expected to work are linear algebra and polynomial functions.

In[32]:= |

In[33]:= |

Out[33]= |

In[34]:= |

Out[34]= |

In[35]:= |

Out[35]= |

In[36]:= |

In[37]:= |

Out[37]= |

In[38]:= |

Out[38]= |

In[39]:= |

Out[39]= |

In[40]:= |

Out[40]= |

In[41]:= |

Out[41]= |