While this submission is a draft, it cannot be used by other submissions.

A word RAM with signed addresses

Lax350013.WordRAM · concepts/Lax350013/WordRAM.lean · lax-350013

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.

    Natural Language Statement

    Definition

    A deterministic random-access machine with WW-bit words, signed integer addresses, modular addition, subtraction and multiplication, indirect loads and stores, a negative-word branch, and acceptance or rejection. Every instruction costs one step. The initial memory contains the input followed by zeros; all negative addresses initially contain zero. The only literal instruction writes the constant 11.

    Concept map
    1 concept; 18 descendants hidden
    100%
    Proven claimDefinitionThis conceptRelated conceptA → B: B builds on A

    Lean source view on GitHub

    1/-
    2Copyright (c) 2026 Anthropic, PBC. All rights reserved.
    3Released under Apache 2.0 license as described in the file LICENSE.
    4SPDX-License-Identifier: Apache-2.0
    5-/
    6/-
    7Modified for the independent Lax packaging by Édouard Bonnet, 2026.
    8Derived from 3sum-apsp/EndStatement.lean / PaperStatements.lean at upstream commit e1a4e6508154ea59f030480661590a9fe3018011.
    9Changes: Lax module/namespace layout, separated concepts and proofs, archive
    10annotations, and compatibility with the archive Lean/mathlib environment.
    11See NOTICE and README.md in the submission root for provenance and scope.
    12-/
    13
    14
    15/-!
    16---
    17title: A word RAM with signed addresses
    18type: definition
    19---
    20A deterministic random-access machine with WW-bit words, signed integer addresses, modular addition, subtraction and multiplication, indirect loads and stores, a negative-word branch, and acceptance or rejection. Every instruction costs one step. The initial memory contains the input followed by zeros; all negative addresses initially contain zero. The only literal instruction writes the constant 11.
    21-/
    22
    23namespace Lax350013.WordRAM
    24
    25
    26/-- `i j k` name cells, `l` a position in the program, `[i]` is the word in cell `i`. The only constant is 1. -/
    27inductive Instr where
    28 | one (i : Int) -- [i] := 1
    29 | add (i j k : Int) -- [i] := [j] + [k]
    30 | sub (i j k : Int) -- [i] := [j] - [k]
    31 | mul (i j k : Int) -- [i] := [j] * [k]
    32 | load (i j : Int) -- [i] := [[j]]
    33 | store (i j : Int) -- [[i]] := [j]
    34 | bltz (i : Int) (l : Nat) -- if [i] < 0, go to position l
    35 | accept
    36 | reject
    37
    38/-- The verdict and the final memory, if `P`, run from position `pc` on memory `m`, halts within `t` steps, the halting
    39step counted; past its end `P` rejects. Addresses are read signed; `bltz` jumps on a negative word; `write` runs on. -/
    40def exec {W : Nat} (P : List Instr) : (t pc : Nat) → (m : Int → BitVec W) → Option (Bool × (Int → BitVec W))
    41 | 0, _, _ => none
    42 | t + 1, pc, m =>
    43 let write (i : Int) (v : BitVec W) := exec P t (pc + 1) fun x => if x = i then v else m x
    44 match P.getD pc .reject with
    45 | .one i => write i 1
    46 | .add i j k => write i (m j + m k)
    47 | .sub i j k => write i (m j - m k)
    48 | .mul i j k => write i (m j * m k)
    49 | .load i j => write i (m (m j).toInt)
    50 | .store i j => write (m i).toInt (m j)
    51 | .bltz i l => exec P t (if (m i).toInt < 0 then l else pc + 1) m
    52 | .accept => some (true, m)
    53 | .reject => some (false, m)
    54
    55/-- The memory at the start: `ws` in cells 0, 1, 2, …, and 0 in every other cell. -/
    56def loadWords (W : Nat) (ws : List Int) : Int → BitVec W :=
    57 fun a => if a < 0 then 0 else BitVec.ofInt W (ws.getD a.toNat 0)
    58
    59end Lax350013.WordRAM
    60
    Builds on

    none

    Used by
    From Mathlib

    none

    Discussion

    Ask a question or add context. Endorsements and structured flags are kept in the review panel above.

    Loading discussion…