Split off the factors of two: oddSplitAux fuel m = (s, d) with
m = 2 ^ s * d and d odd, provided the fuel bounds the number of factors
of two.
Equations
Instances For
Split m as 2 ^ s * d with d odd, returning (s, d);
oddSplit 0 = (0, 0).
Equations
- Hex.Nat.oddSplit m = Hex.Nat.oddSplitAux (m.log2 + 1) m
Instances For
The squaring loop of the strong test: starting from
x = a ^ (2 ^ 1 * d) % n, true iff some square in the next i steps hits
n - 1.
Equations
- Hex.Nat.mrWitnessLoop n x✝ 0 = false
- Hex.Nat.mrWitnessLoop n x✝ i.succ = if x✝ = n - 1 then true else Hex.Nat.mrWitnessLoop n (x✝ * x✝ % n) i
Instances For
The Miller-Rabin test at base a. false is a proof of compositeness;
true is evidence and nothing more. The branch list is part of the
specification: in particular the a % n = 0 branch returns true
(inconclusive; such a base carries no information), which is what makes the
compositeness theorem true at small n.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Run millerRabin over a base list. true proves nothing about n; it
is consumed only as a filter ahead of certificate construction.
Equations
- Hex.Nat.isProbablePrime n bases = bases.all (Hex.Nat.millerRabin n)
Instances For
A prime passes the Miller-Rabin test at every base: the contrapositive of the compositeness theorem, proved branch by branch.
A Miller-Rabin witness proves compositeness. This is the theorem the whole test exists for; there is deliberately no converse.