Pure-register Word-RAM logarithm and iterated logarithm routines #
This module provides zero-memory-cost (memoryCost = 0) Word-RAM programs computing Nat.log 2 x
and Nat.iterLog k x via pure register arithmetic (boundedWhile and iterate), certified with
both Memory.FramedTriple (cost = 0, S = ∅) and Realizes .exact.
Main definitions #
natLog2Prog: compute⌊log₂ x⌋using register right-shifts with zero memory accesses.iterLogProg: compute thek-fold iterated floor logarithmNat.iterLog k xwith zero memory accesses.
Main results #
natLog2Prog_spec,realizes_natLog2Prog:Memory.FramedTriple(cost = 0) andRealizes .exact(work = Nat.log 2 x + 2) certificates fornatLog2Prog.iterLogProg_spec,realizes_iterLogProg:Memory.FramedTriple(cost = 0) andRealizes .exact(work = k * (Nat.log 2 x + 3)) certificates foriterLogProg.
Compute ⌊log₂ x⌋ using register shifts with zero memory accesses (memoryCost = 0).
Framed specification for natLog2Prog: returns Nat.log 2 x in memoryCost = 0 and leaves
memory unchanged (s' = s).
Uniform Realizes .exact certificate for natLog2Prog with zero memory accesses and
O(Nat.log 2 x + 1) local register work.
Compute the iterated base-2 floor logarithm Nat.iterLog k x with zero memory accesses
(memoryCost = 0).
Framed specification for iterLogProg: returns Nat.iterLog k x in memoryCost = 0 and
leaves memory unchanged (s' = s).
Uniform Realizes .exact certificate for iterLogProg with zero memory accesses and
O(k * (Nat.log 2 x + 3)) local register work.