Fields

Conway polynomials

There is one field with pnp^n elements, but many ways to write it down, one for each irreducible polynomial of degree nn mod pp. Conway polynomials are an agreed choice, made so that the fields for different nn fit inside one another in a fixed way. Computer algebra systems share tables of them; here they are computed from the definition.

The problem they solve

GF(pn)\mathrm{GF}(p^n) is built as GF(p)[x]/(f)\mathrm{GF}(p)[x]/(f) for an irreducible ff of degree nn. Two people choosing different ff get isomorphic fields, but an element such as x2+1x^2 + 1 means different things to each, and there are nn isomorphisms to choose from. Worse, GF(pm)\mathrm{GF}(p^m) sits inside GF(pn)\mathrm{GF}(p^n) whenever mm divides nn, and working with several fields at once needs those inclusions to agree with each other.

The definition

The Conway polynomial Cp,nC_{p,n} is the monic polynomial of degree nn over GF(p)\mathrm{GF}(p) that is

  1. primitive: its root aa generates the multiplicative group, so every non-zero element is a power of aa;
  2. compatible: for every mm dividing nn, the power a(pn−1)/(pm−1)a^{(p^n - 1)/(p^m - 1)} is a root of Cp,mC_{p,m};
  3. first among all such, in a particular order: write f=xn−cn−1xn−1+cn−2xn−2−…f = x^n - c_{n-1}x^{n-1} + c_{n-2}x^{n-2} - \dots with alternating signs and compare the words cn−1cn−2…c0c_{n-1} c_{n-2} \dots c_0, digits 0<1<⋯<p−10 < 1 < \dots < p - 1, as in a dictionary.

Condition 2 is what makes the embeddings fit: the standard generator of the small field is a fixed power of the standard generator of the big one. The alternating signs make Cp,1=x−gC_{p,1} = x - g with gg the smallest primitive root mod pp. The definition is recursive, and nothing shortcuts it: the search walks through candidates in order, testing primitivity (by the prime factors of pn−1p^n - 1) and compatibility. That is quick for the fields one meets in practice and hopeless for large ones, which is why the published tables stop where they do.

import { conwayPolynomial, conwayField } from "@ratmath/structures";

conwayPolynomial(2, 8);          // [1n, 0n, 1n, 1n, 1n, 0n, 0n, 0n, 1n], constant first: x⁸ + x⁴ + x³ + x² + 1
conwayPolynomial(3, 4);          // x⁴ + 2x³ + 2
conwayPolynomial(5, 1);          // x + 3, that is x − 2: 2 is the smallest primitive root mod 5

The polynomial for GF(28)\mathrm{GF}(2^8) is not the one in the AES cipher (x8+x4+x3+x+1x^8 + x^4 + x^3 + x + 1, which is irreducible but not primitive). The search reproduces the published values for every case tried in the tests, 23 of them.

The standard fields

conwayField(p, n) is the field built on that polynomial: the same kind of object as galoisField gives, plus its standard generator and the embeddings of the subfields.

const F = conwayField(2, 4);     // GF(16) = GF(2)[a]/(a⁴ + a + 1)
F.text;                          // "x⁴ + x + 1"
F.order(F.gen);                  // 15n: a generates the whole multiplicative group

const e = F.embed(2);            // GF(4) inside GF(16)
e.exponent;                      // 5: the generator of GF(4) is a⁵
F.format(e.image);               // "a² + a", a root of x² + x + 1 = C(2,2)

Because every non-zero element is a power of aa, multiplication can be done by adding exponents, and F.log gives the exponent: the discrete logarithm, by table for fields this small.

Try itEdit the code and run it with @ratmath/structures and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.
Ctrl/⌘ + Enter runs