Compiling additive word RAMs to logarithmic-cost RAMs #
The additive fragment of Cslib.WordRAM uses constants, copying, addition, truncated
subtraction, indirect memory, comparisons and control flow. Its compiler uses the existing
natural-number Cslib.RAM with logarithmic instruction costs. This is a forward simulation
of successful, bounded-word executions; it does not reflect overflow faults or simulate the
word-width instruction, multiplication, division, bitwise operations or shifts.
Source registers occupy target registers 1, …, r. Register 0 is zero until the final
output is copied to it. Four further registers hold 1, the fixed memory offset, and two
scratch values. Source memory address a occupies target register r + 5 + a, so indirect
stores cannot alias the source registers or compiler scratch space. Every source instruction
occupies eight target instruction slots; jumps skip unused slots.
The source machine is adapted from the lean-trominoes formalization
MIT–ULB CompGeom Group. The target is the natural-number RAM adaptation of
Cook and Reckhow documented in Cslib.RAM, not literally their original
integer/I/O model. Neither this compiler nor its cost bound is a Turing-machine simulation.
Main definitions #
Cslib.WordRAM.Instr.IsAdditive: the supported instruction fragment.Cslib.WordRAM.ToRAM.compile,Cslib.WordRAM.ToRAM.compileAdditive: fixed-block compilation, with explicit code placement.Cslib.WordRAM.ToRAM.paddedProgram,Cslib.WordRAM.ToRAM.paddedProgramAdditive: complete compiled programs usingpaddedInput.Cslib.WordRAM.ToRAM.Represents: the register and memory layout.
Main results #
Cslib.WordRAM.Fits.bitLength_le: a fitting word hasRAM.bitLengthat mostw + 1.Cslib.WordRAM.Program.mapOp_additiveHomStandard_isAdditive: every program translated fromBasis.additivebelongs to the additive fragment.Cslib.WordRAM.ToRAM.executes_compile,Cslib.WordRAM.ToRAM.executes_compileAdditive: a successful bounded-word run is simulated by the actual compiled code with logarithmic cost at most8 t (bitLength (r + 5) + w + 1).Cslib.WordRAM.ToRAM.haltsWithResultInTime_padded,Cslib.WordRAM.ToRAM.haltsWithResultInTime_padded_additive: the complete target program, including its register initialization, uses logarithmic cost at most8 (bitLength (r + 5) + 1) (t + 1) (w + 1)on the stated padded input convention.
References #
A word fitting w bits has logarithmic RAM bit-length at most w + 1.
The fragment compiled to the logarithmic-cost natural-number RAM.
Instances For
Every instruction belongs to the additive-memory fragment.
Instances For
Every instruction translated from Basis.additive belongs to the additive fragment.
Every program translated from Basis.additive belongs to the additive fragment.
Assembling a structured program over Basis.additive and translating to Basis.standard
produces an additive-fragment program.
The first target register used to represent source memory.
Instances For
Target register holding the memory offset.
Instances For
Scratch register holding a translated indirect address.
Instances For
Scratch register holding a truncated difference for a comparison.
Instances For
The target instruction corresponding to a source program counter.
Instances For
One slot in the eight-instruction block for a source instruction.
Instances For
Compile into blocks of eight instructions. base is the position where the result will
be inserted in the target program; jump targets are absolute. The unsupported instructions
have no correctness specification. The compiler is independent of word size and input.
Instances For
The register/memory representation at source instruction boundaries. Scratch registers are deliberately unconstrained: each is overwritten before the compiler reads it.
Register zero remains zero until the final output copy.
A permanent positive register implements unconditional jumps.
The memory base is available for indirect addressing.
The finite source register file is disjoint from the other regions.
The source memory occupies the remaining target registers.
Instances For
Successful bounded-word execution is simulated by the compiled code, wherever it is
placed after pre. The initial target state represents the source state and starts at its
compiled instruction; execution of pre is not included in this statement. The final
output copy and jump past the end of the target program are included in the cost.
The padded target input convention: zero working registers, followed by the source input length and words. Installing this list is uncharged; the compiler's two initialization instructions and all subsequent instructions are charged.
Instances For
Initialize the two permanent compiler registers.
Instances For
A complete compiled program using paddedInput.
Instances For
Start the compiled simulation after an arbitrary already-executed prefix, from the supplied padded register layout. The prefix itself is not charged by this theorem; the two-instruction prologue, compiled source execution and final output are charged. This is the composition interface for a separately certified input-preparation program.
The padded-input logarithmic-cost simulation. The compiler and constant depend only on the source program (in fact, the constant depends only on its number of named registers). The input convention explicitly supplies the length and zero workspace; construction of that convention is not a reduction certified by this theorem.
Compile a program over Basis.additive directly to RAM.Program.
Instances For
Successful bounded-word execution of a program over Basis.additive is simulated by
compileAdditive, without a separate IsAdditive side condition.
A complete compiled program over Basis.additive using paddedInput.
Instances For
Start the compiled simulation of a Basis.additive program after an arbitrary
already-executed prefix, from the supplied padded register layout.
The padded-input logarithmic-cost simulation for programs over Basis.additive.