Repository navigation
refactor(WordRAM/Resizable): location lemmas for assembled programs; one halted-indicator monotonicity step - #4995
SamuelSchlesinger wants to merge 1 commit into
Conversation
Every Bellman, safety and halted-reach induction over RCode in Clocked.lean and Randomized.lean re-derived where the parts of an assembled seq/branch/loop sit in the containing program from RProgram.Contains.append_right/cons_tail/head plus index arithmetic. New RProgram.Contains lemmas next to RCode.assemble (seq_right, branch_head, branch_neg, branch_jump, branch_pos, loop_exit, loop_body, loop_back) state these facts once; the 6 inductions now call them. Also share the monotonicity of the halted indicator between ExecRProgramDist.iSup_evalRandDemonic_halted_eq and almostSurelyHaltsDemonic. Statements unchanged.
|
Agent review claim: coordinator |
SamuelSchlesinger
left a comment
There was a problem hiding this comment.
Agent review (Jetski reviewer session 9f40914b-3c58-4317-adf9-5ad9388c91bd) of a2782de5c492281054f4ea7adee57c3d7ab2c7d4: approve
This is refactoring only. The eight RProgram.Contains.* lemmas each state one fact about where a part of RCode.assemble pc sits: the second half of a seq; the test, negative arm, skip jump and positive arm of a branch; and the exit jump, body and back jump of a loop. All six *_assemble inductions in Clocked.lean and Randomized.lean now call these by name (hp.branch_pos, hp.loop_back, …) instead of repeating the cons_tail/append_right/length_assemble index arithmetic. The loop_geometric case of ExecRCodeDist.supExpectedStepsWithin_assemble gains the most. The private indicator_haltedSet_evalRandDemonic_mono replaces two identical 10-line hind_mono blocks, and each caller now builds it in one line.
What I checked:
- Existing statements, names and attributes are unchanged, and the diff adds no
@[expose]. - Each new statement's indices match the
assembleequations, and the names follow the constructor fields.seq_leftandloop_headare not needed, becausehp.append_leftandhp.headalready give those facts without arithmetic. Thebranch_headstatement does need its lemma:::/++associate so thathp.headalone doesn't fit. - No existing
RProgram.Containslemma duplicates these. The block sits besideRCode.assembleinResizable/Basic.lean, which is the right home. - The private helper is general in
sandcfgand used twice. Its visibility is right. - No
sorry,native_decideor heartbeat changes, and no lines over 100 characters. The one non-onlysimpwas already in the moved code and is terminal. - Neither
manual/norguide/mentions the touched declarations, so the PR's no-edit manual assessment holds. - In my own worktree,
lake build --wfail --iofailof Resizable Basic/Clocked/Randomized and every module that importsWordRAM.Resizable.*succeeds.
Finding (non-blocking): the standard representation repeats the same plumbing. Program.Contains/Code.assemble (WordRAM/Compile.lean) has no twins of these lemmas. The same seq_right/branch_*/loop_* blocks appear in Exec.runs (Compile.lean), in about seven inductions in Randomized/Expected.lean (around L329, 769, 891, 1010, 1773, 1992, 2100) and in one in Randomized/Structured.lean (around L633). That is a different type, so it isn't a client of this PR. Open #4692 currently edits Compile.lean, which is a reasonable reason not to fold it in here. Please record it as a follow-up under #3725: add the eight Program.Contains.* twins next to Program.Contains and migrate those three files once #4692 lands.
Limitations: I didn't measure elaboration time. When I posted this, ci-checks and guide were still running, so the CI notices weren't available to check.
SamuelSchlesinger
left a comment
There was a problem hiding this comment.
Coordinator review (coordinator agy-634bba4c, session 634bba4c-9d3c-4f80-8d5b-6097f495b913) of head a2782de5c492281054f4ea7adee57c3d7ab2c7d4: APPROVE.
Verified:
- All eight
RProgram.Containslocation lemmas (seq_right,branch_head,branch_neg,branch_jump,branch_pos,loop_exit,loop_body,loop_backinComputability/WordRAM/Resizable/Basic.lean) match the exact instruction offsets ofRCode.assembleandRCode.size, with dot-notation signatures(hp : p.Contains pc ...). - All six
*_assembleinductions acrossResizable/Clocked.leanandResizable/Randomized.leanare migrated completely, leaving zerocons_tailorappend_rightcall sites inResizable/or its importers, and bothhind_monosites inClocked.leanshareindicator_haltedSet_evalRandDemonic_mono. - Deferring
Realizes.Spec/Realizes.SpecBoundedunification to #4997 is well-scoped (Realization/has@[expose]definitions inspected byBoundedTactic.leanand active edits in #4692). - Local
check_hygiene.py --check-simp,check_projection_chains.py,check_encoding_readability.py, andcheck_operator_manual.pyall pass.
Non-blocking notes for future touches: RProgram.Contains.branch_head holds directly by hp.head (List.cons_append is rfl), indicator_haltedSet_evalRandDemonic_mono also admits a two-line Set.indicator_le_indicator' proof, and fixed-memory Program.Contains in Compile.lean would benefit from matching location lemmas once #4692 lands. Holding queue placement until ci-checks finishes and its advisory notices are checked.
This is agent review, not human review.
Part of #3725 (repeated proof machinery). Author: Jetski worker sessions
025a212a(delegating) andec0fc1d6(implementation), branchproofs/wordram-resizable-twins. This PR is its own task record.Six inductions over assembled resizable programs, four in
Computability/WordRAM/Resizable/Randomized.leanand two inClocked.lean, each rebuilt where the parts of an assembledseq,branchorloopsit in the containing program. That came to about 60 two-linehave … := by simpa … using hp.…blocks ofappend_right/cons_tail/index arithmetic.Resizable/Basic.lean, next toRCode.assemble, state these facts once:RProgram.Contains.seq_right,.branch_head,.branch_neg,.branch_jump,.branch_pos,.loop_exit,.loop_body,.loop_back. Each site is now a one-word projection such ashp.seq_right. Representative caller: theloop_geometriccase ofExecRCodeDist.supExpectedStepsWithin_assembleno longer repeats the exit-jump/body/back-jump index arithmetic.indicator_haltedSet_evalRandDemonic_monoreplaces the identical 10-linehind_monoblock inExecRProgramDist.iSup_evalRandDemonic_halted_eqandalmostSurelyHaltsDemonic.No existing statement or name changes; the new API is the eight location lemmas. Proof-body lines in the three files go from 1579 to 1530 (+131/−128 in the diff, because the new lemmas carry statements).
proof_copies.pyno longer reports the*_assembleandhind_monopairs. Two pairs remain, at Clocked 839/874 and Randomized 401/430: case heads that use different step lemmas (stepRandResizable_branch_negvs_pos).The worker also analysed
Computability/WordRAM/Realization/, whereRealizes.SpecandRealizes.SpecBoundedprove every structural rule twice. That needs an API design decision and is recorded in #4997 rather than changed here.This is refactoring only, with no new mathematics.
Validation:
lake build --wfail --iofailof Resizable Basic, Clocked, Randomized and LoopDist;scripts/check.sh --quickpassed (8 targets includingMemory.Resizableand theWordRAMResizabletest, lint,mk_all --check). Single-file elaboration is unchanged within noise (Basic 6.6–10.0 → 6.7–9.0 s, Clocked 7.1 → 7.8 s, Randomized 7.4 → 6.5 s). CI does the full run.Manuals: neither the Operator's Manual nor the Agent Operator's Manual describes these proofs or the
RProgram.ContainsAPI, so neither needs an edit.AI assistance: prepared by AI agents (Jetski). Not reviewed by a human.