The search for r in the AKS algorithm on the word RAM #
Step 2 of the AKS algorithm Agrawal, Kayal, Saxena, Section 4 finds the least r such
that the multiplicative order of n modulo r exceeds a bound L. As in the proof of their
Theorem 5.1, the program tries r = 2, 3, … in turn. It accepts r when gcd(n, r) = 1 and
n^k mod r ≠ 1 for every 1 ≤ k ≤ L; for r ≥ 2 this is the order condition
(Cslib.AKS.lt_orderOf_iff). The powers are computed by one multiplication modulo r each, and
the gcd by Euclid's algorithm (Cslib.Algorithms.WordRAM.NatGcd.program). Given any r₀ ≥ 2
satisfying the condition, the search stops at some 2 ≤ r ≤ r₀ satisfying it, within a number of
instructions polynomial in r₀ and L.
Main definitions #
Cslib.Algorithms.WordRAM.AKS.OrderSearch.Good: the condition tested for oner.Cslib.Algorithms.WordRAM.AKS.OrderSearch.program: the search.Cslib.Algorithms.WordRAM.AKS.OrderSearch.time: its instruction bound.
Main results #
Cslib.Algorithms.WordRAM.AKS.OrderSearch.exec: the search stops at anr ≤ r₀satisfying the condition, withintime L r₀instructions.
References #
The number n, preserved.
The bound L on the order, preserved.
The candidate r, and the output.
1 once a candidate is accepted.
The power n^k mod r.
First argument of the gcd, and its result.
Second argument of the gcd.
Test one candidate.
Try r = 2, 3, … until one is accepted.
The instruction bound of program.
The search for r. If some r₀ ≥ 2 satisfies Good n L r₀, and the word size holds
n, r₀² and L + 1, the search stops within time L r₀ instructions at some 2 ≤ r ≤ r₀
satisfying Good n L r, preserving n and L.