Documentation

CslibFrontier.Computability.WordRAM.Realization.NatLog

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 #

Main results #

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).

theorem Cslib.WordRAM.Realization.realizes_iterLogProg :
Realizes Basis.exact (fun (x : ℕ × ℕ) => match x with | (k, x) => iterLogProg k x) WordEncoding.encode WordEncoding.encode (fun (w : ℕ) (x : ℕ × ℕ) (x_1 : DataStructure.Memory.State) => Fits w 1) fun (x : ℕ × ℕ) (x_1 : DataStructure.Memory.State) => match x with | (k, x) => k * (Nat.log 2 x + 3)

Uniform Realizes .exact certificate for iterLogProg with zero memory accesses and O(k * (Nat.log 2 x + 3)) local register work.