Verified byte tables for tiny binary formats #
An operation on a format with at most eight stored bits can be compiled into a dense ByteArray.
Generation uses the shared Tabulation constructors in Generic.Construction. Unlike a bijective
Encoding, this interface accepts any radix; the lookup theorems therefore carry explicit input
and result bounds.
Public low-bit kernels keep generated arrays in Lean runtime Thunk cells. Module initialization
creates the cells without generating a table; the first lookup computes and memoizes the bytes.
The defining Thunk.get equation keeps this startup optimization inside the proved boundary. See
Lean Init.Core.Thunk:
https://github.com/leanprover/lean4/blob/v4.34.0/src/Init/Core.lean#L109-L153.
Build the row-major byte table of a total binary operation.
Public arithmetic operations are total, so the table stores exactly one encoded result per input pair. Generating it directly avoids a sentinel encoding for an unused partial-operation case.
Instances For
Build the dense byte table of a total unary operation.
Instances For
Build the row-major byte table of a total ternary operation.
Instances For
Delay a total binary table until its first lookup, then retain the generated bytes.
Lean's runtime implements Thunk as a thread-safe call-by-need cell. The logical equation below
is definitional, so laziness changes initialization cost without changing the proof boundary.
See Init.Core.Thunk in Lean:
https://github.com/leanprover/lean4/blob/v4.34.0/src/Init/Core.lean#L109-L153.
Instances For
Forcing a delayed binary table returns exactly its logical generator.
Delay and memoize a total unary byte table.
Instances For
Forcing a delayed unary table returns exactly its logical generator.
Delay and memoize a total ternary byte table.
Instances For
Forcing a delayed ternary table returns exactly its logical generator.
Native binary-table lookup returns the same code generated by the logical operation.
This is the refinement bridge used by direct UInt8 carriers. The index arithmetic is native at
runtime; all range and no-overflow arguments are proof-only.
Native unary-table lookup returns the same code generated by the logical operation.
The byte-to-USize conversion is unboxed and the bound argument is erased.
Native ternary-table lookup returns the code generated by the logical operation.
The quotient and remainder equations reconstruct the three input coordinates from the native row-major index. All arithmetic side conditions are proof-only.
Two in-range words select an in-range row-major entry of a total-operation table.
Three in-range words select an in-range row-major entry of a ternary table.
Reading a total-operation table returns the logical operation result.
The result bound is explicit because the table stores one byte. The input bound reconstructs the two operands from their row-major index.
Reading a total unary-operation table returns the logical operation result.
Reading a total ternary-operation table returns the logical operation result.
Read a lazily memoized binary table through the ordinary Model carrier.
The table equation is an explicit argument so concrete format modules never need to unfold a large generator while elaborating either the implementation or its refinement theorem.
Instances For
A lazy binary-table read returns the operation used to generate the table.
Read a lazily memoized unary table through the ordinary Model carrier.
Instances For
A lazy unary-table read returns the operation used to generate the table.
Read a lazily memoized ternary table through the ordinary Model carrier.
Instances For
A lazy ternary-table read returns the operation used to generate the table.