Sparse RAM register stores on Turing tapes: definitions #
This file defines the auditable representation boundary for simulating a RAM
with a Turing machine. A finite register file is represented by a list of
address/value pairs. Zero-valued registers are omitted. Words use a
self-delimiting binary code consisting of a unary width, a zero separator, and
exactly that many binary payload bits. Thus a word of bit-width w occupies
2 * w + 1 tape cells.
Snapshot adds the program counter to a finite store. Its bit encoding begins
with the program counter and entry count, followed by the address and value of
each entry. The corresponding decoders are total Option-valued functions.
Proofs that the store operations implement functional register reads/writes and that every codec round-trips live in the internal module.
Maximum bit-width of an instruction's hardwired register indices,
immediate, and jump target. These literals are fixed with the program and are
therefore not charged as runtime indirect addresses by Instr.logCost.
Equations
- One or more equations did not get rendered due to their size.
- Complexity.RAM.RegisterStore.Instr.staticWidth (Complexity.RAM.Instr.imm destination value) = max (Complexity.RAM.bitlen destination) (Complexity.RAM.bitlen value)
- Complexity.RAM.RegisterStore.Instr.staticWidth (Complexity.RAM.Instr.load destination addressRegister) = max (Complexity.RAM.bitlen destination) (Complexity.RAM.bitlen addressRegister)
- Complexity.RAM.RegisterStore.Instr.staticWidth (Complexity.RAM.Instr.store destination addressRegister) = max (Complexity.RAM.bitlen destination) (Complexity.RAM.bitlen addressRegister)
- Complexity.RAM.RegisterStore.Instr.staticWidth (Complexity.RAM.Instr.jz source target) = max (Complexity.RAM.bitlen source) (Complexity.RAM.bitlen target)
- Complexity.RAM.RegisterStore.Instr.staticWidth (Complexity.RAM.Instr.jmp target) = Complexity.RAM.bitlen target
- Complexity.RAM.RegisterStore.Instr.staticWidth Complexity.RAM.Instr.halt = 0
Instances For
Maximum hardwired literal width appearing in a fixed RAM program.
Equations
- Complexity.RAM.RegisterStore.programStaticWidth [] = 0
- Complexity.RAM.RegisterStore.programStaticWidth (instruction :: rest) = max (Complexity.RAM.RegisterStore.Instr.staticWidth instruction) (Complexity.RAM.RegisterStore.programStaticWidth rest)
Instances For
One sparse register entry: an address paired with its nonzero value.
Equations
Instances For
A finite sparse register file.
Instances For
Read an address from a sparse store, defaulting to zero.
Equations
- Complexity.RAM.RegisterStore.read [] x✝ = 0
- Complexity.RAM.RegisterStore.read ((storedAddress, value) :: rest) x✝ = if x✝ = storedAddress then value else Complexity.RAM.RegisterStore.read rest x✝
Instances For
Write one address in a sparse store. Writing zero removes the entry; writing a nonzero value replaces the first matching entry or appends a fresh entry when the address is absent.
Equations
Instances For
No address occurs twice in a sparse store.
Equations
- Complexity.RAM.RegisterStore.AddressesNodup store = (List.map Prod.fst store).Nodup
Instances For
Every materialized entry carries a nonzero value.
Equations
- Complexity.RAM.RegisterStore.ValuesNonzero store = ∀ entry ∈ store, entry.2 ≠ 0
Instances For
A canonical sparse store has unique addresses and omits zero values.
Equations
Instances For
Decode a sparse store into the RAM model's total register file.
Equations
Instances For
A finite sparse store represents a total RAM register file exactly.
Equations
- Complexity.RAM.RegisterStore.Represents store regs = (Complexity.RAM.RegisterStore.Canonical store ∧ Complexity.RAM.RegisterStore.decode store = regs)
Instances For
Maximum address/value bit-width materialized in a sparse store.
Equations
- Complexity.RAM.RegisterStore.maxWidth [] = 0
- Complexity.RAM.RegisterStore.maxWidth (entry :: rest) = max (Complexity.RAM.bitlen entry.1) (max (Complexity.RAM.bitlen entry.2) (Complexity.RAM.RegisterStore.maxWidth rest))
Instances For
Materialize the finite support of a total register file as a sparse store.
Equations
Instances For
Nonzero public-input registers, selected from the known finite input range.
Equations
- Complexity.RAM.RegisterStore.initialAddresses input = {address ∈ Finset.range (input.length + 1) | Complexity.RAM.initRegs input address ≠ 0}
Instances For
Canonical sparse materialization of the RAM public-input register file.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Self-delimiting binary words #
Encode a natural as unary bit-width, a zero separator, and fixed-width little-endian payload bits. The payload convention matches the library's canonical binary-arithmetic work tapes.
Equations
- Complexity.RAM.RegisterStore.WordCode.encode value = List.replicate (Complexity.RAM.bitlen value) true ++ false :: (Complexity.RAM.bitlen value).toBitsLE value
Instances For
Parse the unary-width prefix, then consume exactly that many payload bits.
Equations
- Complexity.RAM.RegisterStore.WordCode.decodeAux? [] x✝ = none
- Complexity.RAM.RegisterStore.WordCode.decodeAux? (true :: rest) x✝ = Complexity.RAM.RegisterStore.WordCode.decodeAux? rest (x✝ + 1)
- Complexity.RAM.RegisterStore.WordCode.decodeAux? (false :: rest) x✝ = if x✝ ≤ rest.length then some (Nat.fromBitsLE (List.take x✝ rest), List.drop x✝ rest) else none
Instances For
Parse one self-delimiting binary word and return the unconsumed suffix.
Equations
Instances For
Serialize an address/value entry as two self-delimiting words.
Equations
- entry.encode = Complexity.RAM.RegisterStore.WordCode.encode entry.1 ++ Complexity.RAM.RegisterStore.WordCode.encode entry.2
Instances For
Number of tape cells occupied by the concatenated self-delimiting codes of
the live sparse-store entries. Unlike Snapshot.sizeBound, this charges the
actual width of every entry instead of multiplying the entry count by one
run-wide maximum width.
Equations
Instances For
Parse exactly count sparse entries and return the unconsumed suffix.
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Serialize a snapshot as program counter, entry count, and entries.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A canonical snapshot represents a RAM configuration exactly.
Equations
- snapshot.Represents cfg = (Complexity.RAM.RegisterStore.Canonical snapshot.store ∧ snapshot.decode = cfg)
Instances For
One width envelope for the program counter, entry count, addresses, and values of a finite snapshot.
Equations
- snapshot.width = max (Complexity.RAM.bitlen snapshot.pc) (max (Complexity.RAM.bitlen (List.length snapshot.store)) (Complexity.RAM.RegisterStore.maxWidth snapshot.store))
Instances For
One-step width envelope: old width plus one, or a width explicitly exposed by the instruction literal or its logarithmic runtime charge.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Materialize a RAM configuration whose register support is finite.
Equations
- Complexity.RAM.RegisterStore.Snapshot.ofCfg cfg hfinite = { pc := cfg.pc, store := Complexity.RAM.RegisterStore.ofRegs cfg.regs hfinite }
Instances For
Canonical finite snapshot of the RAM public-input configuration.
Equations
- Complexity.RAM.RegisterStore.Snapshot.initial input = { pc := 0, store := Complexity.RAM.RegisterStore.initialStore input }
Instances For
The instruction selected by a finite snapshot.
Equations
- Complexity.RAM.RegisterStore.Snapshot.curInstr program snapshot = program[snapshot.pc]?.getD Complexity.RAM.Instr.halt
Instances For
Execute one RAM instruction directly on the sparse finite store.
Equations
- One or more equations did not get rendered due to their size.
- Complexity.RAM.RegisterStore.Snapshot.stepInstr (Complexity.RAM.Instr.imm destination value) x✝ = { pc := x✝.pc + 1, store := Complexity.RAM.RegisterStore.write x✝.store destination value }
- Complexity.RAM.RegisterStore.Snapshot.stepInstr (Complexity.RAM.Instr.jmp target) x✝ = { pc := target, store := x✝.store }
- Complexity.RAM.RegisterStore.Snapshot.stepInstr Complexity.RAM.Instr.halt x✝ = x✝
Instances For
Execute the selected RAM instruction on a sparse snapshot.
Equations
- Complexity.RAM.RegisterStore.Snapshot.step program snapshot = Complexity.RAM.RegisterStore.Snapshot.stepInstr (Complexity.RAM.RegisterStore.Snapshot.curInstr program snapshot) snapshot
Instances For
A sparse snapshot is halted exactly when its selected instruction is halt.
Equations
- Complexity.RAM.RegisterStore.Snapshot.Halted program snapshot = (Complexity.RAM.RegisterStore.Snapshot.curInstr program snapshot = Complexity.RAM.Instr.halt)
Instances For
Equations
- Complexity.RAM.RegisterStore.Snapshot.instDecidableHalted program snapshot = id inferInstance
Fuel-bounded sparse execution, stopping at the first halted snapshot.
Equations
- One or more equations did not get rendered due to their size.
- Complexity.RAM.RegisterStore.Snapshot.run program 0 x✝ = x✝