Documentation

Complexitylib.Models.RandomAccessMachine.Simulation.RegisterStore

Sparse RAM register stores on Turing tapes #

This module exposes the representation boundary used by the RAM-to-Turing- machine simulation. A canonical finite list of nonzero address/value pairs decodes to the RAM model's total register file. Functional reads and writes are exact, every finite-support register file has a canonical representation, and the self-delimiting binary snapshot codec round-trips.

The concrete length theorem is the first resource bridge for the reverse simulation: if the program counter, entry count, addresses, and values all have bit-width at most w, a snapshot with m entries occupies at most (m + 1) * (4 * w + 2) tape cells.

theorem Complexity.RAM.RegisterStore.read_write (store : Store) (hstore : AddressesNodup store) (address value target : ) :
read (write store address value) target = Function.update (read store) address value target

Sparse writing implements functional update exactly when addresses are unique.

theorem Complexity.RAM.RegisterStore.write_canonical (store : Store) (hstore : Canonical store) (address value : ) :
Canonical (write store address value)

Sparse writing preserves unique addresses and omission of zero values.

theorem Complexity.RAM.RegisterStore.decode_write (store : Store) (hstore : AddressesNodup store) (address value : ) :
decode (write store address value) = Function.update (decode store) address value

Decoding after a sparse write is exactly functional update.

theorem Complexity.RAM.RegisterStore.ofRegs_represents (regs : ) (hfinite : (Function.support regs).Finite) :
Represents (ofRegs regs hfinite) regs

Materializing any finite-support register file gives a canonical exact representation.

The canonical public-input store has at most one entry per initialized register.

A canonical word code parses to its value and leaves any suffix untouched.

One self-delimiting word occupies twice its bit-width plus one cell.

A canonical address/value code parses exactly and leaves its suffix.

theorem Complexity.RAM.RegisterStore.Entry.encode_length (entry : Entry) :
entry.encode.length = 2 * bitlen entry.1 + 2 * bitlen entry.2 + 2

An encoded entry charges twice the address width, twice the value width, and two separators.

theorem Complexity.RAM.RegisterStore.encodedStoreLength_write_le (store : Store) (address value : ) :
encodedStoreLength (write store address value) encodedStoreLength store + (Entry.encode (address, value)).length

One sparse write increases the actual encoded store by at most the code of the address/value pair being written. Replacement and deletion can only make this estimate smaller.

The explicit finite public-input snapshot decodes to RAM.initCfg.

The public-input snapshot's intrinsic width is at most the width of |input| + 1.

Materializing a finite-support RAM configuration gives a canonical exact snapshot.

theorem Complexity.RAM.RegisterStore.Snapshot.stepInstr_canonical (instruction : Instr) (snapshot : Snapshot) (hcanonical : Canonical snapshot.store) :
Canonical (stepInstr instruction snapshot).store

One sparse interpreter instruction preserves canonicality.

theorem Complexity.RAM.RegisterStore.Snapshot.decode_stepInstr (instruction : Instr) (snapshot : Snapshot) (hcanonical : Canonical snapshot.store) :
(stepInstr instruction snapshot).decode = RAM.stepInstr instruction snapshot.decode

Decoding commutes exactly with one sparse interpreter instruction.

theorem Complexity.RAM.RegisterStore.Snapshot.step_canonical (program : Program) (snapshot : Snapshot) (hcanonical : Canonical snapshot.store) :
Canonical (step program snapshot).store

The selected sparse step preserves canonicality.

theorem Complexity.RAM.RegisterStore.Snapshot.decode_step (program : Program) (snapshot : Snapshot) (hcanonical : Canonical snapshot.store) :
(step program snapshot).decode = RAM.step program snapshot.decode

Decoding commutes exactly with the selected RAM step.

theorem Complexity.RAM.RegisterStore.Snapshot.width_stepInstr_le (instruction : Instr) (snapshot : Snapshot) :
(stepInstr instruction snapshot).width stepWidthBound instruction snapshot

One sparse interpreter instruction grows the intrinsic width only to the maximum of the old width plus one, its fixed literal width, and its charged logarithmic runtime width.

theorem Complexity.RAM.RegisterStore.Snapshot.width_step_le (program : Program) (snapshot : Snapshot) :
(step program snapshot).width max (snapshot.width + 1) (max (programStaticWidth program) (stepLogCost program snapshot.decode))

A selected sparse step is bounded by the fixed program's literal width and the RAM step's logarithmic charge.

theorem Complexity.RAM.RegisterStore.Snapshot.run_canonical (program : Program) (fuel : ) (snapshot : Snapshot) (hcanonical : Canonical snapshot.store) :
Canonical (run program fuel snapshot).store

Every finite sparse run preserves canonicality.

theorem Complexity.RAM.RegisterStore.Snapshot.decode_run (program : Program) (fuel : ) (snapshot : Snapshot) (hcanonical : Canonical snapshot.store) :
(run program fuel snapshot).decode = RAM.run program fuel snapshot.decode

The complete sparse interpreter run decodes to the executable RAM run.

theorem Complexity.RAM.RegisterStore.Snapshot.length_run_le (program : Program) (fuel : ) (snapshot : Snapshot) :
Canonical snapshot.storeList.length (run program fuel snapshot).store List.length snapshot.store + unitTimeUpto program fuel snapshot.decode

Each RAM instruction materializes at most one additional sparse entry.

theorem Complexity.RAM.RegisterStore.Snapshot.width_run_le (program : Program) (fuel : ) (snapshot : Snapshot) (hcanonical : Canonical snapshot.store) :
(run program fuel snapshot).width snapshot.width + unitTimeUpto program fuel snapshot.decode * (programStaticWidth program + 1) + logTimeUpto program fuel snapshot.decode

Along a canonical sparse run, width grows linearly with executed fuel, the fixed program literal width, and accumulated logarithmic RAM time.

theorem Complexity.RAM.RegisterStore.Snapshot.encodedStoreLength_run_le (program : Program) (fuel : ) (snapshot : Snapshot) (hcanonical : Canonical snapshot.store) :
encodedStoreLength (run program fuel snapshot).store encodedStoreLength snapshot.store + 4 * (unitTimeUpto program fuel snapshot.decode * (programStaticWidth program + 1) + logTimeUpto program fuel snapshot.decode)

The live sparse-store code has amortized growth controlled by the resources actually charged by the RAM run. In particular, this avoids the spurious product of the number of entries and the maximum entry width: each executed instruction pays once for its fixed destination width and for the operand/result bits in its logarithmic cost.

Canonical snapshot serialization round-trips exactly.

theorem Complexity.RAM.RegisterStore.Snapshot.encode_length_le (snapshot : Snapshot) (width : ) (hpc : bitlen snapshot.pc width) (hcount : bitlen (List.length snapshot.store) width) (hstore : entrysnapshot.store, bitlen entry.1 width bitlen entry.2 width) :
snapshot.encode.length (List.length snapshot.store + 1) * (4 * width + 2)

A width-w, m-entry RAM snapshot occupies at most (m + 1) * (4 * w + 2) Turing-tape cells.

Every canonical snapshot code satisfies its intrinsic concrete tape-cell envelope, without external side conditions.

A snapshot code is bounded by its actual live-entry encoding plus the two header words. This is the width-sensitive alternative to the product envelope Snapshot.sizeBound.

theorem Complexity.RAM.RegisterStore.Snapshot.encode_run_length_le_amortized (program : Program) (fuel : ) (snapshot : Snapshot) (hcanonical : Canonical snapshot.store) :
(run program fuel snapshot).encode.length encodedStoreLength snapshot.store + 4 * snapshot.width + 8 * (unitTimeUpto program fuel snapshot.decode * (programStaticWidth program + 1) + logTimeUpto program fuel snapshot.decode) + 2

Combining the actual live-store charge with the width invariant gives a linear-in-accumulated-cost representation bound for every canonical sparse run, relative to the initial sparse encoding.

The materialized public-input store occupies at most one fixed-width entry per initialized register. This records the current ABI's explicit O(n log n) initialization term.

theorem Complexity.RAM.RegisterStore.Snapshot.encode_initial_run_length_le_amortized (program : Program) (fuel : ) (input : List Bool) :
(run program fuel (initial input)).encode.length (input.length + 1) * (4 * bitlen (input.length + 1) + 2) + 4 * bitlen (input.length + 1) + 8 * (logTimeUpto program fuel (initCfg input) * (programStaticWidth program + 2)) + 2

Public-input specialization of the amortized live-representation bound. The accumulated part is linear in charged RAM time; the separate n * bitlen n term comes from eagerly materializing all nonzero input registers in the current snapshot ABI.

theorem Complexity.RAM.RegisterStore.Snapshot.encode_run_length_le (program : Program) (fuel : ) (snapshot : Snapshot) (hcanonical : Canonical snapshot.store) :
(run program fuel snapshot).encode.length (List.length snapshot.store + unitTimeUpto program fuel snapshot.decode + 1) * (4 * (snapshot.width + unitTimeUpto program fuel snapshot.decode * (programStaticWidth program + 1) + logTimeUpto program fuel snapshot.decode) + 2)

The canonical code of every reachable snapshot has an explicit product bound: entry count grows by at most one per step, while width grows only with fixed program literals and charged logarithmic RAM time.

theorem Complexity.RAM.RegisterStore.Snapshot.encode_run_length_le_logTime (program : Program) (fuel : ) (snapshot : Snapshot) (hcanonical : Canonical snapshot.store) :
(run program fuel snapshot).encode.length (List.length snapshot.store + logTimeUpto program fuel snapshot.decode + 1) * (4 * (snapshot.width + logTimeUpto program fuel snapshot.decode * (programStaticWidth program + 1) + logTimeUpto program fuel snapshot.decode) + 2)

Eliminating actual step count via unitTimeUpto ≤ logTimeUpto gives a pure logarithmic-time tape-size envelope. This is the quadratic representation bound needed by the RAM-to-TM simulation.

theorem Complexity.RAM.RegisterStore.Snapshot.encode_initial_run_length_le_logTime (program : Program) (fuel : ) (input : List Bool) :
(run program fuel (initial input)).encode.length (input.length + 1 + logTimeUpto program fuel (initCfg input) + 1) * (4 * (bitlen (input.length + 1) + logTimeUpto program fuel (initCfg input) * (programStaticWidth program + 1) + logTimeUpto program fuel (initCfg input)) + 2)

From the public RAM ABI, every reachable snapshot code has an explicit quadratic envelope in input length, logarithmic RAM time, and one fixed program constant.