Draft — mutable and not usable as a dependency; its citation marks the draft state.

Lax489179.WordPrograms

Word-RAM programs with optional fair coins

concepts/Lax489179/WordPrograms.lean · lax-489179

definition

Loading review…

Sign in with ORCID

Community review

Flags

Each flag is tied to a public ORCID identity and explains why this concept may be incorrect.

No flags have been submitted.

    Community review

    Flag this concept

    State precisely what appears incorrect. This explanation will be public under your ORCID name.

    No source line selected.

    Concept map

    Proven claimDefinitionThis conceptRelated conceptA → B: B builds on A

    Definition

    We use the finite word-RAM instruction set of lax-67 and add one instruction writing a fresh fair bit to a specified cell. In deterministic mode this instruction is forbidden. All arithmetic, indirect addressing, input access and output use lax-67's word semantics. Input is a read-only array, writable memory starts at zero, and output is append-only.

    Each fetched instruction costs one step, including a coin or a halt. Detecting an out-of-range program counter also costs one step in this wrapper. Halted configurations are unchanged by further padding steps. The bound thus includes the full output and termination. A random word can be assembled from fair bits using the ordinary instructions. The probability space is the uniform distribution on the finite bit strings supplied to these transitions; it does not provide random advice.

    Lean source view on GitHub

    1import Lax67.Ram
    2import Lax489179.Algorithms
    3
    4/-!
    5---
    6title: Word-RAM programs with optional fair coins
    7type: definition
    8---
    9We use the finite word-RAM instruction set of lax-67 and add one
    10instruction writing a fresh fair bit to a specified cell. In deterministic
    11mode this instruction is forbidden. All arithmetic, indirect addressing,
    12input access and output use lax-67's word semantics. Input is a read-only
    13array, writable memory starts at zero, and output is append-only.
    14
    15Each fetched instruction costs one step, including a coin or a halt.
    16Detecting an out-of-range program counter also costs one step in this
    17wrapper. Halted configurations are unchanged by further padding steps.
    18The bound thus includes the full output and termination. A random word
    19can be assembled from fair bits using the ordinary instructions.
    20The probability space is the uniform distribution on the finite bit
    21strings supplied to these transitions; it does not provide random advice.
    22-/
    23
    24namespace Lax489179.WordPrograms
    25
    26open Lax67.Ram
    27
    28inductive Instruction
    29 | ordinary (instruction : Instr)
    30 | coin (destination : ℕ)
    31
    32abbrev Program := List Instruction
    33
    34structure Config where
    35 state : State
    36 halted : Bool
    37
    38def init (input : List ℕ) : Config := ⟨initState input, false
    39
    40def step (w : ℕ) (p : Program) (bit : Bool) (c : Config) : Config :=
    41 if c.halted then c else
    42 match p[c.state.pc]? with
    43 | none => { c with halted := true }
    44 | some (.ordinary instruction) =>
    45 match instruction.effect w c.state with
    46 | none => { c with halted := true }
    47 | some s => ⟨s, false
    48 | some (.coin a) =>
    49 ⟨{ c.state with
    50 pc := c.state.pc + 1
    51 mem := setCell w c.state.mem a bit.toNat }, false
    52
    53def run (w : ℕ) (p : Program) : (t : ℕ) → (Fin t → Bool) → ConfigConfig
    54 | 0, _, c => c
    55 | t + 1, r, c => run w p t (fun i => r i.succ) (step w p (r 0) c)
    56
    57def output (c : Config) : Option (List ℕ) :=
    58 if c.halted then some c.state.out else none
    59
    60def Deterministic (p : Program) : Prop :=
    61 ∀ a, Instruction.coin a ∉ p
    62
    63def ComputesWithin (w : ℕ) (p : Program) (input : List ℕ)
    64 (correct : List ℕ → Prop) (t : ℕ) : Prop :=
    65 Algorithms.CorrectWithin t (fun r => output (run w p t r (init input))) correct
    66
    67end Lax489179.WordPrograms
    68

    Community review

    Discussion

    Ask a question or add context. Endorsements and structured flags are kept in the review panel above; your ORCID profile must share a public name.

    0 comments

    Loading discussion…