A charged native integer square root #
Main definitions #
NatSqrt.program: successive squares.
Main results #
NatSqrt.exec: integer square root in a square-root number of native instructions.
@[reducible, inline]
Input integer, preserved.
Instances For
@[reducible, inline]
Current root and output.
Instances For
@[reducible, inline]
Successor of the current root.
Instances For
@[reducible, inline]
Square of the successor.
Instances For
@[reducible, inline]
Constant one.
Instances For
@[reducible, inline]
Input plus one.
Instances For
Advance the root and compute the next square.
Instances For
A fixed program for the integer square root, with all square computations charged.
Instances For
theorem Cslib.Algorithms.WordRAM.NatSqrt.exec {w : ℕ} (x : WordRAM.Data 6) (hfit : WordRAM.Fits w (4 * x.regs arg + 4)) :
Compute Nat.sqrt n in at most 5 sqrt(n) + 7 instructions, preserving input and memory.
The linear bound 4n + 4 covers the final unsuccessful square as well as all counters.
theorem Cslib.Algorithms.WordRAM.NatSqrt.exec_rename {r w : ℕ} (f : Fin 6 → Fin r) (hf : Function.Injective f) (x : WordRAM.Data r) (hfit : WordRAM.Fits w (4 * x.regs (f arg) + 4)) :
Run successive squares on any injectively chosen registers.