Documentation

CslibFrontier.Algorithms.WordRAM.PrimeTrial

Charged native trial division #

This is a finite instruction program, not an invocation of Lean's primality decision procedure. The Chan–He prime table will call it only on candidates at least two.

Main definitions #

Main results #

@[reducible, inline]

Candidate, preserved.

@[reducible, inline]

Current trial divisor.

@[reducible, inline]

Primality flag.

@[reducible, inline]

Remainder scratch.

@[reducible, inline]

Constant one.

@[reducible, inline]

Constant zero.

Test one trial divisor and advance. The conditional also charges its control instructions.

Initialize and test every divisor strictly between one and the candidate.

theorem Cslib.Algorithms.WordRAM.PrimeTrial.exec {w : ℕ} (x : WordRAM.Data 6) (hp : 2 ≤ x.regs arg) (hfit : WordRAM.Fits w (x.regs arg + 2)) :
∃ (y : WordRAM.Data 6), WordRAM.ExecWithin w program x y (7 * (x.regs arg - 2) + 6) ∧ (y.regs flag = if Nat.Prime (x.regs arg) then 1 else 0) ∧ y.regs arg = x.regs arg ∧ y.mem = x.mem

Test a candidate at least two in at most 7(p-2)+6 native instructions. All divisors are actual register values; the native remainder instruction is charged.