Step 3 of the AKS algorithm and Euler's totient on the word RAM #
Step 3 of the AKS algorithm Agrawal, Kayal, Saxena, Section 4 outputs COMPOSITE if
1 < gcd(a, n) < n for some a ≤ r, and step 5 needs φ(r). One loop over 0 ≤ a ≤ r does
both, with two runs of Euclid's algorithm (Cslib.Algorithms.WordRAM.NatGcd.program) per a: it
clears a flag when gcd(n, a) is neither 1 nor n, and counts the a with gcd(r, a) = 1.
The index a = 0 is harmless (gcd(n, 0) = n), and for r ≥ 2 neither 0 nor r is coprime
to r, so the count is φ(r).
Main definitions #
Cslib.Algorithms.WordRAM.AKS.GcdTotient.program: the loop.Cslib.Algorithms.WordRAM.AKS.GcdTotient.time: its instruction bound.
Main results #
Cslib.Algorithms.WordRAM.AKS.GcdTotient.exec: the flag records step 3 and the count isφ(r), withintime rinstructions.
References #
The number n, preserved.
The modulus r, preserved.
The loop end r + 1.
1 while every gcd(n, a) seen is 1 or n.
The number of a seen with gcd(r, a) = 1.
First argument of the gcd, and its result.
Second argument of the gcd.
Test gcd(n, a), count gcd(r, a) = 1, and advance a.
Step 3 and the totient. For r ≥ 2, with the word size holding n and r + 1, within
time r instructions the flag ok is 1 exactly when every 1 ≤ a ≤ r has gcd(a, n) = 1 or
gcd(a, n) = n, and phi is φ(r). For n ≥ 1 the flag condition says that no 1 ≤ a ≤ r has
1 < gcd(a, n) < n; for n = 0 it is stronger, since gcd(a, 0) = a.