Documentation

CslibFrontier.Algorithms.WordRAM.AKS.PolyMul

Multiplication modulo X^r - 1 and n on the word RAM #

Polynomials modulo X^r - 1 with coefficients modulo n are stored as arrays of r words. The program clears the destination array and then, for every pair i, j < r, adds p i * q j into cell (i + j) mod r, reducing modulo n after each addition: schoolbook multiplication, with O(r²) instructions. Every product and sum stays below n² + n. The result has the coefficients Cslib.AKS.mulCoeff n r p q, so its class is the product of the classes of the factors (Cslib.AKS.toQuot_mulCoeff). The factors may coincide, which is how a polynomial is squared; the destination must be disjoint from both.

Main definitions #

Main results #

References #

@[reducible, inline]

Base address of the first factor.

@[reducible, inline]

Base address of the second factor.

@[reducible, inline]

Base address of the product.

@[reducible, inline]

The number r of coefficients.

@[reducible, inline]

The modulus n of the coefficients.

@[reducible, inline]

Index into the first factor.

@[reducible, inline]

Index into the second factor.

@[reducible, inline]

Index (i + j) mod r into the product.

@[reducible, inline]

Address scratch.

@[reducible, inline]

The coefficient p i.

@[reducible, inline]

The product p i * q j.

@[reducible, inline]

The updated product coefficient.

@[reducible, inline]

Constant one.

@[reducible, inline]

Constant zero.

Add the product into its cell, reducing modulo n, and advance j.

Add p i * q j into cell (i + j) mod r of the product.

Add the products of p i with every coefficient of q.

Clear the product, then accumulate every pair of coefficients.

theorem Cslib.Algorithms.WordRAM.AKS.PolyMul.exec {w : ℕ} (x : WordRAM.Data 14) {a b t r n : ℕ} (ha : x.regs pa = a) (hb : x.regs pb = b) (ht : x.regs pt = t) (hr : x.regs rr = r) (hn : x.regs nn = n) (hn0 : 0 < n) (hta : t + r ≤ a ∨ a + r ≤ t) (htb : t + r ≤ b ∨ b + r ≤ t) (hpa : ∀ i' < r, x.mem (a + i') < n) (hpb : ∀ j' < r, x.mem (b + j') < n) (hfa : WordRAM.Fits w (a + r)) (hfb : WordRAM.Fits w (b + r)) (hft : WordRAM.Fits w (t + r)) (hf2 : WordRAM.Fits w (2 * r)) (hfn : WordRAM.Fits w (n * n + n)) :
∃ (y : WordRAM.Data 14), WordRAM.ExecWithin w program x y (14 * (r + 1) * (r + 1)) ∧ (∀ k' < r, y.mem (t + k') = AKS.mulCoeff n r (fun (i' : ℕ) => x.mem (a + i')) (fun (j' : ℕ) => x.mem (b + j')) k') ∧ (∀ (a' : ℕ), ¬(t ≤ a' ∧ a' < t + r) → y.mem a' = x.mem a') ∧ y.regs pa = a ∧ y.regs pb = b ∧ y.regs pt = t ∧ y.regs rr = r ∧ y.regs nn = n

Multiplication modulo X^r - 1 and n. If the product block [t, t + r) is disjoint from both factor blocks, the factors' coefficients are below n ≥ 1, and the word size holds the block ends, 2 r and n² + n, then the product block receives the coefficients Cslib.AKS.mulCoeff n r p q within 14 (r + 1)² instructions, and no other cell changes.