Documentation

CslibFrontier.Computability.PolyTime.GaloisRingArithmetic

Arithmetic modulo 2 ^ p and a monic polynomial, on coefficient lists #

The coefficient rings of the contraction algorithm of [OAI26k] (Appendix D.4.1, p. 57) are A_p = (ℤ / 2 ^ p)[U] / (f) for a monic f ∈ ℤ[U] of degree e. An element is represented in the basis 1, U, …, U ^ (e - 1) by its list of coordinates, each an integer residue modulo 2 ^ p. The monic polynomial is given by the list fl of its coefficients below the leading one (GaloisRingArith.monicOf), so e is the length of fl. With f irreducible modulo 2, A_p is the Galois ring (ℤ / 2 ^ p)[U] / (f); nothing here needs irreducibility.

The value of a coefficient list c is ∑ i < e, c i U ^ i in A_p (GaloisRingArith.val).

Each operation is correct (GaloisRingArith.val_add, GaloisRingArith.val_mulX, GaloisRingArith.val_mul) and polynomial-time, with the precision p in unary and the coordinates and the coefficients of f in binary (GaloisRingArith.computableInPolyTime_add, GaloisRingArith.computableInPolyTime_mul). Their outputs are reduced, with e coordinates below 2 ^ p (GaloisRingArith.length_mul, GaloisRingArith.lt_of_mem_mul). These are the polynomial-time arithmetic claims of Appendix D.4.1 for addition and multiplication, in the case ℓ = 1 of the source, where A = O has no V-coordinates, together with the inversion of units by inversion modulo two and Newton lifting that the source names (Appendix D.4.1, p. 58).

Main definitions #

Main results #

References #

The monic polynomial U ^ e + ∑ i < e, fl i U ^ i of degree e = fl.length.

monicOf fl is monic, of degree fl.length.

@[reducible, inline]

The ring A_p = (ℤ / 2 ^ p)[U] / (f) for f = monicOf fl.

noncomputable def Cslib.GaloisRingArith.val (p : ℕ) (fl c : List ℕ) :
Ring p fl

The value ∑ i < e, c i U ^ i of a coefficient list in A_p, with e = fl.length. Coordinates past e are ignored and missing ones are zero.

Coordinatewise sum modulo 2 ^ p.

def Cslib.GaloisRingArith.addSmul (p : ℕ) (fl c : List ℕ) (k : ℕ) (d : List ℕ) :

Add k times d to c, coordinatewise modulo 2 ^ p.

Multiplication by U: shift the coordinates up and subtract the top coordinate times the lower coefficients of f, modulo 2 ^ p.

The zero element, with e coordinates.

One step of shift-and-add multiplication by c: from (U ^ i d, ∑ j < i, c j U ^ j d), add c i U ^ i d to the accumulator and multiply the current power by U.

Multiplication by shift-and-add.

The unit element 1, with e coordinates.

def Cslib.GaloisRingArith.pow (p : ℕ) (fl c : List ℕ) (k : ℕ) :

Powers c ^ k, by k multiplications; the exponent is read in unary.

Negation, coordinatewise modulo 2 ^ p.

Subtraction.

One step of the seed of inversion: from (x ^ 2 ^ j, x ^ (2 ^ (j + 1) - 2)), square the power and multiply it in.

The seed x ^ (2 ^ e - 2) = x ^ 2 x ^ 4 ⋯ x ^ (2 ^ (e - 1)) of inversion, by e - 1 squarings. In a Galois ring it inverts x modulo 2, since the residue field has 2 ^ e elements.

One Newton step y (2 - x y) towards the inverse of x.

Inversion: p Newton steps from the seed. It is the inverse of x whenever the seed inverts x modulo 2 (val_mul_inv), in particular for every unit of a Galois ring.

Correctness #

theorem Cslib.GaloisRingArith.natCast_two_pow {p : ℕ} {fl : List ℕ} :
↑(2 ^ p) = 0
theorem Cslib.GaloisRingArith.natCast_mod_two_pow {p : ℕ} {fl : List ℕ} (x : ℕ) :
↑(x % 2 ^ p) = ↑x

The root satisfies U ^ e = -∑ i < e, fl i U ^ i.

@[simp]
theorem Cslib.GaloisRingArith.val_zero {p : ℕ} {fl : List ℕ} :
val p fl (zero fl) = 0
theorem Cslib.GaloisRingArith.val_add {p : ℕ} {fl : List ℕ} (c d : List ℕ) :
val p fl (add p fl c d) = val p fl c + val p fl d

Addition is correct.

theorem Cslib.GaloisRingArith.val_addSmul {p : ℕ} {fl : List ℕ} (c : List ℕ) (k : ℕ) (d : List ℕ) :
val p fl (addSmul p fl c k d) = val p fl c + ↑k * val p fl d

Adding a multiple is correct.

theorem Cslib.GaloisRingArith.val_mulX {p : ℕ} {fl : List ℕ} (c : List ℕ) :
val p fl (mulX p fl c) = AdjoinRoot.root (Polynomial.map (Int.castRingHom (ZMod (2 ^ p))) (monicOf fl)) * val p fl c

Multiplication by U is correct.

theorem Cslib.GaloisRingArith.val_mul {p : ℕ} {fl : List ℕ} (c d : List ℕ) :
val p fl (mul p fl c d) = val p fl c * val p fl d

Multiplication is correct.

@[simp]
theorem Cslib.GaloisRingArith.val_one {p : ℕ} {fl : List ℕ} :
val p fl (one fl) = 1

The unit is correct.

theorem Cslib.GaloisRingArith.val_pow {p : ℕ} {fl : List ℕ} (c : List ℕ) (k : ℕ) :
val p fl (pow p fl c k) = val p fl c ^ k

Powers are correct.

theorem Cslib.GaloisRingArith.val_neg {p : ℕ} {fl : List ℕ} (c : List ℕ) :
val p fl (neg p fl c) = -val p fl c

Negation is correct.

theorem Cslib.GaloisRingArith.val_sub {p : ℕ} {fl : List ℕ} (c d : List ℕ) :
val p fl (sub p fl c d) = val p fl c - val p fl d

Subtraction is correct.

theorem Cslib.GaloisRingArith.val_seed {p : ℕ} {fl : List ℕ} (x : List ℕ) :
val p fl (seed p fl x) = val p fl x ^ (2 ^ fl.length - 2)

The seed is the power x ^ (2 ^ e - 2).

theorem Cslib.GaloisRingArith.val_mul_newton {p : ℕ} {fl : List ℕ} (x y : List ℕ) {m : ℕ} {w : Ring p fl} (h : val p fl x * val p fl y = 1 + 2 ^ m * w) :
val p fl x * val p fl (newton p fl x y) = 1 + 2 ^ (2 * m) * -w ^ 2

Newton's step squares the defect: if x y = 1 + 2 ^ m w then x (y (2 - x y)) = 1 + 2 ^ (2 m) (-w ^ 2).

theorem Cslib.GaloisRingArith.val_mul_inv {p : ℕ} {fl : List ℕ} (x : List ℕ) {w : Ring p fl} (h : val p fl x * val p fl x ^ (2 ^ fl.length - 2) = 1 + 2 * w) :
val p fl x * val p fl (inv p fl x) = 1

Inversion is correct when the seed inverts x modulo 2.

Reduced outputs #

@[simp]
theorem Cslib.GaloisRingArith.length_add (p : ℕ) (fl c d : List ℕ) :
(add p fl c d).length = fl.length
@[simp]
theorem Cslib.GaloisRingArith.length_addSmul (p : ℕ) (fl c : List ℕ) (k : ℕ) (d : List ℕ) :
(addSmul p fl c k d).length = fl.length
@[simp]
theorem Cslib.GaloisRingArith.length_mulX (p : ℕ) (fl c : List ℕ) :
(mulX p fl c).length = fl.length
theorem Cslib.GaloisRingArith.lt_of_mem_add {p : ℕ} {fl c d : List ℕ} {x : ℕ} (hx : x ∈ add p fl c d) :
x < 2 ^ p
theorem Cslib.GaloisRingArith.lt_of_mem_addSmul {p : ℕ} {fl c : List ℕ} {k : ℕ} {d : List ℕ} {x : ℕ} (hx : x ∈ addSmul p fl c k d) :
x < 2 ^ p
theorem Cslib.GaloisRingArith.lt_of_mem_mulX {p : ℕ} {fl c : List ℕ} {x : ℕ} (hx : x ∈ mulX p fl c) :
x < 2 ^ p
theorem Cslib.GaloisRingArith.length_mul (p : ℕ) (fl c d : List ℕ) :
(mul p fl c d).length = fl.length
theorem Cslib.GaloisRingArith.lt_of_mem_mul {p : ℕ} {fl c d : List ℕ} {x : ℕ} (hx : x ∈ mul p fl c d) :
x < 2 ^ p

Polynomial time #

theorem Cslib.GaloisRingArith.length_encList_le {p e : ℕ} {c : List ℕ} (hlen : c.length = e) (hlt : ∀ x ∈ c, x < 2 ^ p) :

A reduced coefficient list, with e coordinates below 2 ^ p, is at most e (2 p + 1) long in binary.

The length e (2 p + 1) of a reduced coefficient list is polynomially bounded.

Multiplication is polynomial-time, with the precision in unary. Every intermediate pair is reduced after its first step, so its length is bounded by the precision and the degree.