Explicit-budget certificates for register-word glue #
This module certifies finite, memory-independent glue in the existing WordRAM.Code language.
An emitter takes possibly repeated input registers and a disjoint fresh scratch bank. Its code
and instruction budget are chosen before the input values and word width. This follows the
emit-and-frame pattern of Multiword.Circuit, specialized to physical words; it does not use
that compiler's standard-basis wide-arithmetic semantics for exact-basis operations.
The admissible-input predicate and one envelope for executed values remain explicit. In particular, increasing the width does not justify exact subtraction below zero or a zero divisor. Selection runs only its chosen alternative. Width reads, memory instructions, loops and random sampling are excluded. This is the word-glue component of realization, not a compiler for memory clients or algorithms. The certificate asserts successful execution on its stated domain; it does not assert a converse about executions outside that domain.
Inputs are already in the supplied registers. Their installation, scratch reservation and a
final halt are not charged here; the surrounding realization must charge them. Constants,
copies, ALU instructions and branch overhead inside the emitted code are charged normally.
The interface and closure results are original; the underlying model is WordRAM.Structured.
Main definitions #
Code.IsGlue: the memory-independent, width-independent finite fragment of existing code.GlueComputes: a framed scalar computation with an explicit uniform instruction budget.GlueComputable: the same contract with only the instruction budget existentially hidden.GlueComputes.Witness: retain specified scalar scratch and code under that same contract.
Main results #
GlueComputes.proj,GlueComputes.const: register projections and constants.GlueComputes.binary,GlueComputes.comp_many,GlueComputes.select: compositional emission.GlueComputes.realize: instantiate the emitter with a concrete finite register layout.GlueComputes.mono: explicit weakening of the value envelope and instruction budget.
The register-only finite fragment of Code. Conditions may select a branch, but no loop,
memory access, random choice or word-width read is permitted. This is a predicate on the
existing language, not a second program syntax.
Instances For
Register glue does not read the word width, so existing execution monotonicity applies.
The uniform native contract shared by existential and retained scalar certificates. Inputs may alias; only the scratch bank is fresh and injective. No whole-state boundedness premise is added to the scalar interface.
Instances For
A scalar register function has a fixed emitter and instruction budget. bound is one
top-level value envelope, and P is the fixed admissibility predicate. The scratch bank is
fresh and injectively placed; input registers may repeat. Output is in scratch slot zero,
memory is unchanged, and registers outside scratch retain their initial contents. Neither the
emitter nor the budget may depend on run-time values or the word width.
Instances For
Syntax-directed automation hides only the uniform budget and emitter witness. The basis, admissibility predicate, scalar function and value envelope remain visible parameters.
Instances For
A specified scalar emitter with the same contract as GlueComputes. The envelope,
scratch and code are retained as data before every runtime value, width and register layout.
- scratchSize : ℕ
Auxiliary slots, in addition to the scalar result slot.
The uniform scalar emitter.
The original visible value envelope.
- code_spec : Spec B P f bound time self.scratchSize fun {r : ℕ} => self.code
The original native execution and memory/register-frame contract.
Instances For
Existential-only fallback. The selected scratch and code need not equal those of any
particular derivation; use a supplied Witness when their identities matter.
Instances For
A checked explicit budget supplies the automation facade.
A canonical finite register layout puts inputs first and fresh scratch after them. The same code and register count work for every valid input and width, and every initial memory is framed. The budget excludes a final halt; a later flat-program export must charge it.
Weaken the envelope and instruction budget explicitly, outside syntax-directed search.
Apply a basis operation to two computed words. The operation may repeat or ignore either word in its argument vector. Its interpretation and domain are checked explicitly, at every width; no totalization of a partial basis operation is used. Intermediate executions share the same envelope, and their instruction costs are added without bound search.
Instances For
Binary composition retains the two disjoint operand banks and one result slot.
Compose existential certificates using their choice-selected scalar witnesses. For
specified scratch and code, use Witness.binary directly.
Substitute a register map, including a map with repeated inputs. The emitter accepts arbitrary input layouts, so this substitution needs no staging copies or injectivity premise.
Substitute any finite vector of computed arguments into a routine. All component emitters, scratch banks and budgets are fixed before runtime inputs or widths. The forest runs in index order, preserving inputs and earlier results, and then runs the outer routine in its own bank. The one common envelope covers all components and dominates the outer envelope.
Compose two scalar computations, passing the first result as the second computation's single input. Each stage keeps its own explicit domain and envelope; the caller proves the domain implication and envelope domination once.
Select between two computations by an existing register condition. Only the selected branch must satisfy its domain; the inactive branch may fault if executed.
Standard binary operations use the basis's documented total natural-number semantics.
Retain exact binary code and scratch. Definedness of the partial operation on the fixed domain is still required separately from output fit.
Instances For
Exact binary witnesses retain the original operand-bank accounting without requiring clients to unfold the basis-dependent emitter.
Exact binary operations require their interpretation to be defined on the fixed domain. Output fit alone cannot discharge underflow or a zero divisor.