Documentation

CslibFrontier.Algorithms.WordRAM.AKS.PolyPow

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

Raising a polynomial modulo X^r - 1 and n to the power e by repeated squaring: with a result block R, a base block B and a scratch block T, each round multiplies R by B into T and copies it back when e is odd, squares B into T and copies it back, and halves e. The class of R · B^e is invariant, so when e reaches 0 the result block holds the class of R · B^e for the original R, B and e. The loop makes Nat.size e rounds, each of O(r²) instructions (Cslib.Algorithms.WordRAM.AKS.PolyMul.program and Cslib.WordRAM.ArrayCopy.program). This is the polynomial arithmetic of step 5 of the AKS algorithm Agrawal, Kayal, Saxena, Section 4.

Main definitions #

Main results #

References #

@[reducible, inline]

Base address of the result block.

@[reducible, inline]

Base address of the base block.

@[reducible, inline]

Base address of the scratch block.

@[reducible, inline]

The number r of coefficients.

@[reducible, inline]

The modulus n of the coefficients.

@[reducible, inline]

The exponent, halved every round.

@[reducible, inline]

The parity of the exponent.

@[reducible, inline]

Constant two.

@[reducible, inline]

Constant zero, for the loop test.

@[reducible, inline]

First argument of the multiplication, and source of the copy.

@[reducible, inline]

Second argument of the multiplication, and destination of the copy.

@[reducible, inline]

Product block of the multiplication.

The multiplication runs on pa, pb, pt, rr, nn and the scratch registers 12, …, 20.

The copy runs from pa to pb over rr words, with scratch among 12, …, 20.

Multiply the blocks at x and y into T, then copy T into the block at d.

One round: multiply R by B if e is odd, square B, and halve e.

Repeated squaring while the exponent is positive.

The instruction bound of one multiplication followed by a copy.

The instruction bound of program: Nat.size e rounds of two multiplications.

Halving a positive number shortens its binary representation.

theorem Cslib.Algorithms.WordRAM.AKS.PolyPow.exec {w : ℕ} (x : WordRAM.Data 21) {a b t r n : ℕ} (ha : x.regs R = a) (hb : x.regs B = b) (ht : x.regs T = t) (hr : x.regs rr = r) (hn : x.regs nn = n) (hn0 : 0 < n) (hab : a + r ≤ b ∨ b + r ≤ a) (hta : t + r ≤ a ∨ a + r ≤ t) (htb : t + r ≤ b ∨ b + r ≤ t) (hpa : ∀ i < r, x.mem (a + i) < n) (hpb : ∀ i < r, x.mem (b + i) < 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)) (hfe : WordRAM.Fits w (x.regs e)) :
∃ (y : WordRAM.Data 21), WordRAM.ExecWithin w program x y (time r (x.regs e)) ∧ (AKS.toQuot n r fun (i : ℕ) => y.mem (a + i)) = (AKS.toQuot n r fun (i : ℕ) => x.mem (a + i)) * (AKS.toQuot n r fun (i : ℕ) => x.mem (b + i)) ^ x.regs e ∧ (∀ i < r, y.mem (a + i) < n) ∧ y.regs R = a ∧ y.regs B = b ∧ y.regs T = t ∧ y.regs rr = r ∧ y.regs nn = n

Powers modulo X^r - 1 and n. If the result, base and scratch blocks [a, a + r), [b, b + r) and [t, t + r) are pairwise disjoint, the result and base coefficients are below n ≥ 1, and the word size holds the block ends, 2 r, n² + n and the exponent e, then within time r e instructions the result block receives reduced coefficients whose class is that of R · B^e.