Repository navigation
refactor(WordRAM): one Karger amplification-loop law, one multiword clear, one ExactTriangle copy step - #4992
Merged
Conversation
`ampLoop_law` (KargerMinCut) and `fastCutAmpLoop_law` (KargerStein) were the same 25-line induction over the remaining trials, differing only in the trial body, its invariant and its answer law. It is now the generic `Karger.minRunsLoop_law` in `Karger/OutputLaw`, next to the shared `minUpdate_exec`: any `while trial < trials do body` whose trials fold a fresh answer of law `μ` into `best` observes `Lean.Karger.minRuns`. Both loop laws (statements unchanged) are now a three-line application to their body law. OutputLaw gains a public import of `Algorithms/Lean/Karger/Contraction`, which defines `minRuns`/`minStep`; both clients already depend on it. Refs #3725.
`Arithmetic`'s private `exec_clear_framed` re-proved Schoolbook's `exec_clear` (same code, same induction) with a different register frame, but its only caller used just the memory part; the register frame there comes from `preserves_truncatingProgram`. Make `Schoolbook.exec_clear` public (documented) and use it; delete the copy. `exec_row` now composes its cell and tail frames with the existing `frame_trans`/`frame_mono`, as `Sub.exec_digits` and `Shift` already do. Refs #3725.
`exec_adapt` made the same copy call three times (one per source square), each followed by the same fourteen lines deriving the destination, length, running total, register frame, memory and below-base facts from `exec_copy`. They are now one private `exec_copyStep`, which also absorbs the local `sum_eq` rewriting of the original word sum. Statement unchanged. Refs #3725.
Collaborator
Author
|
Agent review claim: coordinator |
SamuelSchlesinger
left a comment
Collaborator
Author
There was a problem hiding this comment.
Coordinator review (coordinator agy-634bba4c, session 634bba4c-9d3c-4f80-8d5b-6097f495b913) of head 671b925cd41ef8da51a0fe34218fdaefcc195403: APPROVE.
Verified:
Cslib.Algorithms.WordRAM.Karger.minRunsLoop_law(Algorithms/WordRAM/Karger/OutputLaw.lean) cleanly separates the per-trial body boundTfrom the charged loop budgetS(T + 2 ≤ S), accommodating both exact step accounting inKargerMinCut.ampLoop_lawand slack upper bounds inKargerStein.fastCutAmpLoop_lawwithout changing either caller's public theorem statement. Itspublic importofLean.Karger.Contractionadds zero transitive fan-out sinceKargerMinCutandKargerSteinare the sole importers and already import it viaKarger.Contract.- Exposing
Schoolbook.exec_clear(Multiword/Mul.lean) removes the duplicate 27-lineArithmetic.exec_clear_framed(Multiword/Arithmetic.lean) and alignsMul.exec_row's frame composition withSub.exec_digitsviaframe_trans/frame_mono. exec_copyStep(ExactTriangle/CallableFixedPrime/Adapt.lean) soundly discharges all fourexec_copypreconditions and register/memory frames across all three edge-list copies (ab,bc,ac).- All four "left as is" notes in the PR description were checked against source and are genuine structural differences rather than missed extractions. Local
check_hygiene.py --check-simp,check_projection_chains.py,check_encoding_readability.py, andcheck_operator_manual.pyall pass.
Non-blocking nit: Schoolbook.exec_clear's docstring says "changing only them and the carry workspace", whereas Workspace.Frame permits both total and carry to vary. Holding queue placement until ci-checks finishes and its advisory notices are checked.
This is agent review, not human review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #3725 (repeated proof machinery). Author: Jetski worker sessions
025a212a(delegating) and4702ea05(implementation), branchproofs/wordram-algorithm-twins. This PR is its own task record.Three Word-RAM algorithm refactors, one commit each:
ampLoop_law(KargerMinCut) andfastCutAmpLoop_law(KargerStein) repeated the same 25-line induction over the remaining trials. The new publicKarger.minRunsLoop_lawinAlgorithms/WordRAM/Karger/OutputLaw.leansits next tominUpdate_exec, whose module docstring already describes the shared best-cut update, and is listed in Main results. It covers anywhile trial < trials do bodywith invariantInv i, givenR ≥ 1,T + 2 ≤ Sand a body lawμ.map (if i = 0 then v else min v best), and concludes theminRuns/minSteplaw. Both client statements are unchanged, and each proof is now an unfold plus oneexact. OutputLaw publicly importsLean/Karger/Contractionbecause the statement namesminRuns/minStep; both clients already depended on it.Arithmetic's privateexec_clear_framedre-provedMul'sSchoolbook.exec_clear(same code, same induction), and its only caller used only the memory part.exec_clearis now public with a docstring, and the copy is deleted.exec_rowalso composes its frames with the existingframe_trans/frame_mono, asSub.exec_digitsalready does.exec_adapt. The three per-square copy calls shared about 14 lines of fact plumbing each. They now use one privateexec_copyStep.No existing public statement or name changes. New public API:
minRunsLoop_law, plusexec_clearmade public. Net −44 lines (+98/−142).proof_copies.pyreports no repeated block in the touched files.Left as is, with reasons:
exec_row(multiply-add with carry) vsexec_digits(subtract with borrow): the cell semantics, invariants and value equations differ, so a generic digit loop would abstract all three.fastCutStep_stage0/1_law: different branch nesting.Instanceslayout preambles: fixing them would mean a representation redesign with named layouts.MatrixReadbackp/q branches: these differ in their residue arguments.This is refactoring only, with no new mathematics.
Validation:
lake build --wfail --iofailof OutputLaw, KargerMinCut, KargerStein, Mul, Arithmetic, Bank, BankArithmetic, FusionTree Compress, Adapt, CallableFixedPrime.Exec and the testsWordRAMKargerMinCut,WordRAMKargerStein,WordRAMMultiword.scripts/check.sh --quickpassed (73 affected targets, lint, hygiene, ratchets,mk_all). Single-file elaboration (warmlake env lean, min, before → after): OutputLaw 5.3 → 5.2 s, KargerMinCut 10.9 → 8.3 s, KargerStein 40.7 → 32.2 s, Mul 18.3 → 18.0 s, Arithmetic 5.6 → 4.6 s, Adapt 5.4 → 4.6 s. CI does the full run.Manuals:
manual/.../probabilistic-workflows.mdcites OutputLaw only forprogram_of_law, and neither manual describes these proofs, so neither needs an edit.AI assistance: prepared by AI agents (Jetski). Not reviewed by a human.