Documentation

CslibFrontier.Algorithms.WordRAM.AKS.Congruence

The AKS congruence for one a on the word RAM #

Step 5 of the AKS algorithm Agrawal, Kayal, Saxena, Section 4 tests (X + a)^n ≡ X^n + a (mod X^r - 1, n). The program writes the coefficients of X + a into a base block B and those of 1 into a result block R, raises by repeated squaring (Cslib.Algorithms.WordRAM.AKS.PolyPow.program) so that R holds (X + a)^n, writes the coefficients of X^n + a into the scratch block T, and compares R with T. Both blocks are reduced, so they agree exactly when the classes agree (Cslib.AKS.toQuot_eq_toQuot_iff), which is the congruence (Cslib.AKS.congruence_iff_toQuot).

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, which is also the exponent.

@[reducible, inline]

The exponent of the power.

@[reducible, inline]

Block argument of the subroutines.

@[reducible, inline]

Second block argument of the comparison.

@[reducible, inline]

Constant one.

@[reducible, inline]

The tested value a, preserved.

@[reducible, inline]

The exponent residue for Fill.

@[reducible, inline]

The constant term for Fill.

@[reducible, inline]

The answer: 1 when the congruence holds.

The power runs on the first 21 registers.

Fill writes the block at pa, with scratch shared with the power.

Compare compares the blocks at pa and pb.

Write X + a into B and 1 into R, raise to the power n, write X^n + a into T, and compare R with T.

The registers that every subroutine call preserves.

Instances For
    theorem Cslib.Algorithms.WordRAM.AKS.Congruence.exec {w : ℕ} (x : WordRAM.Data 25) {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 av = 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) :
    ∃ (y : WordRAM.Data 25), WordRAM.ExecWithin w program x y (time r n) ∧ y.regs flag ≤ 1 ∧ (y.regs flag = 1 ↔ AKS.Congruence n r A) ∧ ∀ (j : Fin 25), Keep j → y.regs j = x.regs j

    The AKS congruence for one a. For r ≥ 1 and n ≥ 1, with the result, base and scratch blocks [a, a + r), [b, b + r) and [t, t + r) pairwise disjoint, and the word size holding the block ends, 2 r, n² + n and the tested value A, the program leaves 1 in flag if (X + A)^n ≡ X^n + A (mod X^r - 1, n) and 0 otherwise, within time r n instructions.