The AKS tests with integer thresholds #
The AKS algorithm Agrawal, Kayal, Saxena, Section 4 compares the multiplicative order
of n modulo r with log₂² n (step 2) and tests the congruence for a ≤ ⌊√φ(r) log₂ n⌋
(step 5). A program decides these comparisons more easily with the integer threshold
c = ⌈log₂ n⌉ in place of log₂ n: step 2 asks for ord_r(n) > c², and step 5 tests
a ≤ ⌊√φ(r) · c⌋ = ⌊√(φ(r) c²)⌋. This is a standard integer variant. It is still correct, by
Theorem 4.1 of the paper (Cslib.AKS.prime_iff_passes): c² ≥ log₂² n, so the order condition
is stronger than the paper's, and every prime passes the congruence for every a, so testing more
values of a loses nothing.
Cslib.AKS.PassesUpTo n r A states the tests with the congruence checked for 1 ≤ a ≤ A; the
paper's Cslib.AKS.Passes n r is its case A = ⌊√φ(r) log₂ n⌋. For n ≥ 2, ord_r(n) > c² and
A ≥ ⌊√φ(r) log₂ n⌋, it holds exactly when n is prime
(Cslib.AKS.prime_iff_passesUpTo). The order condition is decided by small powers: for r ≥ 2,
ord_r(n) > L exactly when n is coprime to r and no n^k with 1 ≤ k ≤ L is 1 modulo r
(Cslib.AKS.lt_orderOf_iff).
Main definitions #
Cslib.AKS.numTestsNat: the integer bound⌊√(φ(r) ⌈log₂ n⌉²)⌋of step 5.
Main results #
Cslib.AKS.logb_le_clog:log₂ n ≤ ⌈log₂ n⌉.Cslib.AKS.numTests_le_numTestsNat: the integer bound tests at least the paper's values.Cslib.AKS.lt_orderOf_iff: the order condition by small powers.Cslib.AKS.prime_iff_passesUpTo: the tests with integer thresholds characterize the primes.
References #
The integer bound ⌊√(φ(r) c²)⌋ = ⌊√φ(r) · c⌋ of step 5, with c = ⌈log₂ n⌉.
The integer bound tests at least the paper's values: ⌊√φ(r) log₂ n⌋ ≤ ⌊√(φ(r) c²)⌋.
The order condition by small powers: for r ≥ 2, the multiplicative order of n modulo
r exceeds L exactly when n is coprime to r and no n^k with 1 ≤ k ≤ L is 1 modulo
r.
The tests with integer thresholds characterize the primes: for n ≥ 2, r such that the
order of n modulo r exceeds ⌈log₂ n⌉², and A ≥ ⌊√φ(r) log₂ n⌋, n passes the tests up to
A exactly when it is prime. This is Agrawal, Kayal, Saxena, Theorem 4.1 with integer
thresholds.