A charged native ceiling binary logarithm #
Main definitions #
NatClog.program: successive ceiling division by two.
Main results #
NatClog.exec: the ceiling logarithm with a logarithmic charged instruction bound.
@[reducible, inline]
Quotient, initially the input.
@[reducible, inline]
Ceiling logarithm output.
Divide the quotient by two and increment the answer.
Fixed code for Nat.clog 2, including its value zero at input zero.
Ceiling logarithm, initialized constants and unchanged memory; the quotient is consumed.
theorem Cslib.Algorithms.WordRAM.NatClog.exec {w : ℕ} (x : WordRAM.Data 4) (h2 : WordRAM.Fits w 2) (hn : WordRAM.Fits w (x.regs arg + 1)) (hout : WordRAM.Fits w (Nat.clog 2 (x.regs arg) + 1)) :
∃ (y : WordRAM.Data 4), WordRAM.ExecWithin w program x y (5 * Nat.clog 2 (x.regs arg) + 5) ∧ Post x y
Compute the ceiling binary logarithm in at most 5 ⌈log₂ n⌉ + 5 instructions.
Memory is untouched and the input quotient is consumed.
theorem Cslib.Algorithms.WordRAM.NatClog.exec_rename {r w : ℕ} (f : Fin 4 → Fin r) (hf : Function.Injective f) (x : WordRAM.Data r) (h2 : WordRAM.Fits w 2) (hn : WordRAM.Fits w (x.regs (f arg) + 1)) (hout : WordRAM.Fits w (Nat.clog 2 (x.regs (f arg)) + 1)) :
Run the routine on any injectively chosen registers.