Skip to content

feat(WordRAM): simulate local-address RAM on a pointer machine - #8942

Open
slef wants to merge 2 commits into
mainfrom
slef/local-address-ram-simulation
Open

slef wants to merge 2 commits into
mainfrom
slef/local-address-ram-simulation

Conversation

@slef

@slef slef commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

This formalizes a typed local-address RAM whose address registers move by one cell in either direction. Each cell of a prepared finite interval is represented by one doubly linked record. The compiler maps local moves to link traversals and preserves structured execution costs exactly. For matching randomized scalar primitives it also preserves the joint distribution of outputs and instruction counts.

Schönhage describes real-time equivalence between storage modification machines and successor RAMs. This PR verifies the one-way simulation for a typed finite interval, with exact instruction counts and a randomized version under matching scalar primitives. Schönhage, Storage Modification Machines (1980)

The simulation assumes the linked representation is supplied at entry. The theorem covers the typed fragment with address equality and separate scalar operations. The stacked quicksort PR uses the compiler to transfer a full sorting and expected-cost proof.

Randomized flat execution uses the program counter in PointerMachine.State. The standalone local-address RAM test checks interval endpoints, execution through a null reference on an empty interval, and preservation of two distinct path costs for a randomized branch. The test passes with --wfail --iofail, and source hygiene and the import aggregate check pass.

Tracks #8941. Ready for coordinator review.

AI assistance: Codex helped develop and check the formalization.

@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator

CLAIM review head=4632284df423b924f6fd197065ab67c3624f1544 by=reviewer-agy-8942 until=2026-11-27T08:34Z

@SamuelSchlesinger SamuelSchlesinger left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REQUEST_CHANGES at 4632284 by reviewer-agy-8942

Independent non-authoring agent review (reviewer-agy-8942, not human review or platform approval) of PR #8942 at 4632284df423b924f6fd197065ab67c3624f1544 against origin/main (66957ec822).

What was verified

  • Headlines, scope, and citation: Verified [Schonhage1980] (Storage Modification Machines, SIAM J. Comput. 9(3):490–508, 1980, doi:10.1137/0209036) and checked all public statements (exec_compile, executes_compile, execRand_compile, runRand_compile) against their docstrings and the PR description. None overclaims Schönhage's general unbounded SMM/successor-RAM real-time equivalence: the module states a one-way simulation from a typed finite-interval local-address RAM on a supplied doubly linked representation, with exact instruction counts derived from Cslib.Program and Cslib.PointerMachine semantics (no TimeM or hand-charged cost monad).
  • Mergeability, hygiene, and CI notices: Clean merge-tree with origin/main, valid import_key placement in CslibFrontier.lean, sorted references.bib key, passing ci-checks on 4632284df423b924f6fd197065ab67c3624f1544, and empty Parallel-definition (26 declarations) and Duplicate-statement (16 theorems) notices.

Changes requested

  1. Make the flat randomized pointer-machine semantics transparent on PointerMachine.State and place it in Cslib.PointerMachine (Local.lean lines 335–340, 444–522).

    • randomizedFlatMachine and evalPointerRand sit in a public section without @[expose], and pointerRandStep is private. Under module, in every downstream importer (including stacked #8943), (randomizedFlatMachine kernel).Config, .running, and .step are opaque: external readers and callers cannot see how .step behaves at halt, out-of-bounds labels, or instructions, cannot project the program counter or State out of Config, and cannot prove that .running is injective (so in #8943's pointerSort_exec, ∃ y, cfg = R.running c.size y ∧ ... does not let a caller deduce the postcondition for z from R.running c.size z ∈ (R.run ...).support).
    • In addition, Config := ℕ × State M (layout p d) duplicates the program counter alongside State.pc (leaving (encode z.1).pc = 0 while .1 is (compile c).size), whereas PointerMachine.step, Executes, and executes_compile operate directly on State M L ({ encode y with pc := (compile c).size }); and nothing in evalPointerRand, pointerRandStep, or randomizedFlatMachine depends on Local.layout p d.
    • Please extract transparent (@[expose]) Op.evalRand, stepRand, and runRand on State M L for general (M : Model) (L : Layout) into Cslib.PointerMachine (for example CslibFrontier/Computability/PointerMachine/Randomized.lean, keeping the Program.RandomizedFlatMachine adapter private as in Computability/WordRAM/Randomized/Structured.lean), remove Local.evalPointerRand and Local.randomizedFlatMachine, and state Local.runRand_compile directly in terms of PointerMachine.runRand reaching { encode z.1 with pc := (compile c).size }.
  2. Add a standalone module test file in CslibFrontierTests/ and complete the module interface of instructionSet, encode, and compile (CONTRIBUTING.md#public-surface-under-the-module-system, policy/statements.md).

    • This PR adds no test in CslibFrontierTests/, leaving Local.lean without an ordinary module client on main.
    • Checking the public surface for external module callers exposes three small interface omissions:
      • instructionSet lacks a Decidable instance for its test relation (compare PointerMachine/Structured.lean lines 155–173), which Program.Code.eval requires;
      • encode is non-@[expose] and lacks @[simp] theorem encode_pc (x : Data M n p d) : (encode x).pc = 0 := rfl, which callers need in order to apply PointerMachine.ExecWithin.executes;
      • compile is non-@[expose] and lacks @[simp] theorem size_compile (c : Program.Code (Op M p d) (Test M p d)) : (compile c).size = c.size, needed to relate (compile c).size and (compile c).program.length to c.size.
    • Please add those interface declarations and a module test file under CslibFrontierTests/ exercising concrete deterministic and randomized executions via ordinary imports, including interval-endpoint boundaries (Direction.next at n - 1, Direction.prev at 0, operations through none, and n = 0) and a branching randomized program whose paths take distinct instruction counts.
  3. Factor the repeated List.ofFn modification proof in op_correct (Local.lean lines 222–266; CI Repeated-proof-block notice).

    • The storeAddr and storeData branches of op_correct duplicate a 16-line List.ext_getElem / List.getElem_modify / List.getElem_ofFn argument. Please extract a short private lemma (such as (List.ofFn f).modify a.val g = List.ofFn (Function.update f a (g (f a))) or encode_modify) and use it in both branches.
  4. Module docstring (Local.lean lines 13–36; policy/build-and-files.md#file-rules).

    • Add a ## Main definitions section listing the public model and compiler declarations (Data, Direction, Op, Test, instructionSet, layout, encode, compile, evalRand) alongside ## Main results, and include a section locator ([Schonhage1980], §4) where Schönhage's SMM / successor-RAM equivalence is cited for context.

Limits of review

  • Reviewed source diff, surrounding PointerMachine and Program modules, representative caller PR #8943, bibliography metadata (via web search, without reading the full paywalled 1980 article text), and hosted CI logs/notices on 4632284df423b924f6fd197065ab67c3624f1544. This is an independent agent review, not human review.

Extract the generic randomized pointer semantics, simplify heap updates, and exercise deterministic and randomized local RAM compilation through the public module interface. Strict LocalAddressRAM build, source hygiene and import aggregate checks passed.

slef commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

Fixed in 17669670c4. PointerMachine.Randomized exposes the flat run on State, with a private assembly adapter. The local compiler now has the missing instance and size and entry-label lemmas, one shared heap-update proof, and a standalone client covering the requested boundary and randomized cases. The Schönhage citation points to the publisher abstract, where the equivalence is stated. Strict local build, hygiene, and import checks passed. Please review this delta.

@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator

CLAIM review head=17669670c40f08d7505f40850f68729c1d4eb905 by=reviewer-agy-8942 until=2026-11-27T09:05Z

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants