Documentation

CslibFrontier.Algorithms.WordRAM.AKS.CongruenceLoop

Step 5 of the AKS algorithm on the word RAM #

Step 5 of the AKS algorithm Agrawal, Kayal, Saxena, Section 4 tests the congruence (X + a)^n ≡ X^n + a (mod X^r - 1, n) for a = 1, …, A. The program runs the test for one a (Cslib.Algorithms.WordRAM.AKS.Congruence.program) for each a in turn and clears a flag when one fails.

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.

@[reducible, inline]

The tested value a, which is also the loop index.

@[reducible, inline]

The answer of one test.

@[reducible, inline]

The last tested value A, preserved.

@[reducible, inline]

The loop end A + 1.

@[reducible, inline]

1 while every test so far has passed.

@[reducible, inline]

Constant one.

The test for one a runs on the first 25 registers.

theorem Cslib.Algorithms.WordRAM.AKS.CongruenceLoop.exec {w : ℕ} (x : WordRAM.Data 29) {a b t r n A₀ : ℕ} (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) (hA : x.regs A = A₀) (hr0 : 0 < r) (hn0 : 0 < n) (hab : a + r ≤ b ∨ b + r ≤ a) (hta : t + r ≤ a ∨ a + r ≤ t) (htb : t + r ≤ b ∨ b + r ≤ t) (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)) (hfA : WordRAM.Fits w (A₀ + 1)) :
∃ (y : WordRAM.Data 29), WordRAM.ExecWithin w program x y (time r n A₀) ∧ y.regs ok ≤ 1 ∧ (y.regs ok = 1 ↔ ∀ (v : ℕ), 1 ≤ v → v ≤ A₀ → AKS.Congruence n r v) ∧ y.regs R = a ∧ y.regs B = b ∧ y.regs T = t ∧ y.regs rr = r ∧ y.regs nn = n

Step 5. For r ≥ 1 and n ≥ 1, with the three blocks pairwise disjoint and the word size holding the block ends, 2 r, n² + n and A + 1, the program leaves 1 in ok exactly when (X + a)^n ≡ X^n + a (mod X^r - 1, n) for every 1 ≤ a ≤ A, within time r n A instructions.