A charged native binary logarithm #
Main definitions #
NatLog.program: successive division by two.
Main results #
NatLog.exec: the floor logarithm with a logarithmic charged instruction bound.
@[reducible, inline]
Quotient, initially the input.
Instances For
@[reducible, inline]
Floor logarithm output.
Instances For
@[reducible, inline]
Constant one.
Instances For
@[reducible, inline]
Constant two.
Instances For
Divide the quotient by two and increment the answer.
Instances For
Fixed code for Nat.log 2, including its value zero at input zero.
Instances For
theorem Cslib.Algorithms.WordRAM.NatLog.exec {w : ℕ} (x : WordRAM.Data 4) (h2 : WordRAM.Fits w 2) (hn : WordRAM.Fits w (x.regs arg)) (hout : WordRAM.Fits w (Nat.log 2 (x.regs arg) + 1)) :
Compute the floor binary logarithm in at most 4 log₂ n + 5 instructions.
Memory is untouched and the input quotient is consumed.
theorem Cslib.Algorithms.WordRAM.NatLog.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))) (hout : WordRAM.Fits w (Nat.log 2 (x.regs (f arg)) + 1)) :
Run the routine on any injectively chosen registers.