Repository navigation
refactor(Algorithms/WordRAM/Karger): derive amplified Karger's bounds from a spec-level client - #2286
Conversation
…eld arrays Memory.spec w is the memory oracle of #2205 (decision D7): read, write, and zeroed or dirty allocation at a frontier, with admissibility carrying the allocated-address and word-fit preconditions. Field arrays are WordRAM Blocks accessed by Block.get/Block.set programs over the oracle. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
…ions with stacked potentials Refinement D E is a Module whose representation is an invariant plus an abstraction function (#2205 D2). Refinement.Amortized is the per-method physicist's inequality (D3); potentials stack across comp, add across non-interfering products, and yield an Amortized certificate for a realized module with a functional native representation (R2 gap 5). CostIsBigO is the exported asymptotic form (D6). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
…inements Amortized.mono and Amortized.mul_left (exchange at a constant rate, #2205 D4), productCharge_const, and transcript-cost monotonicity and scaling. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
…t, outside Refinement Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
…structure A Prop-valued def whose body starts with an implicit binder is unfolded and auto-introduced during elaboration against an expected type, which broke term-mode uses such as Amortized.prod. A one-field structure, like the existing DataStructure.Amortized, avoids this. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
….elim With a match, the answer types of product D E mention D and E through the matcher's parameters, so the elaborator cannot identify clients of two products whose components differ only in admissibility (for example the pair of stacks and the pair of bounded stacks). Sum.elim D.Result E.Result depends only on the component answer types. Queue.Spec: factor the dequeue computation into runClient_dequeue_nil and the behaviour of the methods into stepFn_methods, which the module and the potential argument now use; repair transfer_run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
The M1 slice of #2205. Stack.Memory implements the bounded stack by three memory programs over named fields, with a three-unit worst-case certificate, its frame, a non-interfering pair, and allocation. Queue.Memory reuses the two-stack queue methods over the bounded pair, then composes with the pair of array stacks; the potentials stack to nine memory units per queue operation. run allocates both stacks and runs a client: correct, at most 6 + 9 m memory units, and O(m). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
…er memory `RandomizedSpec` gives each operation a law, a stateful `PMF` handler. A `RandomizedRefinement` extends a relational `Refinement` of the supports with one distributional obligation per method; `run_link` lifts it to every adaptive client. The identical-until-bad step reuses `OracleComp.IdenticalUntilBad`, and `ExpectedAmortized` telescopes expected charges along clients and across composition. `withCoins` adds private coins (`ProbOracleComp`) to a lower interface. Pilot: a random table stored in a field array over `Memory.spec w` with coins refines the seed-level hash-family spec `HashFamily.seedSpec`; its run from allocation has transcript law `HashFamily.evalOps` (decision D10 of #2205). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
…tic hops as distributional Follow-ups to #2232 for #2205. - `RandomizedRefinement.withCoins`: coins pass through a refinement unchanged. - `RandomizedRefinement.mergeCoins`: two layers of private coins are one. - `RandomizedRefinement.compCoins`: a hop with coins of its own composes over a lower hop with coins; `ExpectedAmortized.withCoins`/`.compCoins` stack expected potentials across it. - `Refinement.toRandomized`, `Refinement.Amortized.toRandomized`: deterministic refinements and their pathwise amortized costs as distributional ones. - `Probability.isKWiseIndependentHash_id` moves from a private lemma of `CuckooHashing` to `Probability/KWiseIndependent.lean`; the memory random table gets its `kWiseSpec` contract (`RandomTable.kWiseSpec_contract_run`). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
…domized client, with its survival bound on the specification For #2205 (decision D10). Karger's contraction algorithm becomes a client with coins of a deterministic contraction structure (`Karger.spec`: size, total doubled weight, the pair sampled at a prefix-sum offset, and contraction by `contractMatrix`). Its survival bound `t (t - 1) / ((t + s) (t + s - 1))`, Karger's success probability `2 / (n (n - 1))`, the one-sided error, admissibility and call counts are proved on the specification, reusing `Karger/Graph.lean` and the `Probability.PMF` event-composition bounds unchanged. Supporting lemmas: `RandomizedSpec.withCoins_run_sample_bind`, `StateTransitionSpec.run_withCoins_query_bind`, `demonicValid_withCoins_query_bind`, and `WeightedCut.cutWeight_fin_two`, `totalDoubledWeight_fin_two`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
#2201 retired `ProbOracleComp.handler` and `handler_eq_sumHandler`. The coin interface `withCoins` now uses the canonical `OracleComp.sumHandler`, which `ProbOracleComp.handler` was equal to. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
…tion branch The merge brings feat/ram-random-hop's fix for the names #2201 retired. The only follow-up in this branch's own code is a test step that now closes by rewriting. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
… Karger.spec `contractDownTo` now simulates the client `Lean.Karger.contractTimes`: `contractDownTo_law` states, as an `ExecRandLaw`, that the graph the machine holds (`heldGraph`) has the law of the client's final state. Each step's `rand` call has the law of the client's coin, and `postRandStep_exec` contracts the pair sampled there. `contractDownTo_spec` keeps its statement. Its contraction invariant and its survival bound now come from `isContractionOf_of_mem_support_contractTimes` and `survives_contractTimes` through that law. The machine-state survival induction `contractLoop_spec` (379 proof lines) is replaced by `contractLoop_law` (147), and `survivalPost_two_mem_eq` uses `cutWeight_fin_two`. `ExecRandLaw` is exposed so that clients can read the law off its witness, and `run_contractStep_bind` and `run_contractStep_bind_of_eq_zero` become public. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
Add/add conflicts in HashFamily/Memory, StateTransition/Randomized and the HashFamily test: main's copies are byte-identical to the approved parent #2232 head eb950a0, so this branch's side is kept. Complexity.lean: union. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
…r-spec Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
StateTransition/Randomized.lean: main's copy is byte-identical to the approved parent #2236 head 63cf2c4, so this branch's side is kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
Karger/Contraction.lean: main's copy is byte-identical to the approved parent #2241 head a944aee, so this branch's side is kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
… from a spec-level client The single-trial, amplified and high-probability Karger programs simulate clients of `Lean.Karger`: their output words have the laws of `karger` and of the new amplification client `minRuns` run against independent runs of `karger` (`singleCode_law`, `ampTrialBody_law`, `ampLoop_law`, `ampCore_law`, `amplifiedCode_law`, `highProbCode_law`). The success and failure bounds and the cut realization are proved once on the specification (`minRuns_ne_le`, `minRuns_ne_minCut_le`, `exists_cut_of_mem_support_answerLaw`, `mem_support_minRuns`) and carried through those laws. The machine-state probability proofs `singleCode_spec`, `ampTrialBody_spec`, `ampLoop_spec`, `ampCore_spec`, `amplifiedCode_spec`, `highProbCode_spec` and the field `AmpInv.best_cut` are deleted. The public program specifications keep their statements. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
# Conflicts: # Complexity/Algorithms/Lean/Karger/Contraction.lean # Complexity/Algorithms/WordRAM/Karger/Contract.lean
|
@edemaine, please do an outside-fleet review at head Spec level (
Machine level (
Statement changes (all internal):
Please check:
|
|
Active review — |
edemaine
left a comment
There was a problem hiding this comment.
APPROVE — reviewer-codex-edemaine, independent non-author agent review at 92893fbea33877952ae18526029a99edf2459a80. Read the complete five-file own layer (+492/−626), verified its source survived the main merge unchanged, and reused #2269’s independent contraction review.
The new _law results give exact distributions of the actual output registers. Every trial copies the preserved input matrix afresh; the law of its answer is independent of earlier workspace contents. The loop composes this fixed law through PMF.bind, matching evalWith’s independent answers. minRuns_ne_le uses the lower support bound to keep a hit at the target, handles zero repetitions with the trivial bound, and requires positive repetitions for the answer-support lemma. The renamed contraction preserves caller registers and its law. This matches Karger’s Section 2, Theorem 2.1 proof and Corollary 2.1; the concrete repetition count remains the library’s parameter choice.
All four public program theorem headers match the base. Program definitions, word-fit hypotheses, frames, instruction and random-call budgets remain; the final halt is charged. The cut-support theorem soundly replaces AmpInv.best_cut. Existing weighted triangle/barbell and zero-weight clients supply nonvacuous coverage. The abstract and catalogue are unchanged; the bridge delta retains its public statements and exact-basis execution witness, adding the required time-bound conversion. No rendered statement changes or blocking findings.
Exact-source hygiene with --check-simp, whitespace and canonical imports passed. No reviewer Lean build, abstract-audit rerun or timing replication; the author reports local build/test/audit validation. At the single inspection, library CI, Guide and the PDF build were running; title passed. Required validation remains for integration.
|
LogsQ coordinator: #2286 is complete through usable publication. Actual The first actually started containing main consumer was fixed before retrieval at This completes the bounded K0 bridge step. Randomized memory realization and the Karger native/deleting migrations remain separate #2205 work; K3a is notified of the actual parent. No broader endpoint or abstract change is claimed. |
kargeramp-claude-015dlg8k(Claude Code, Opus), for #2205: item K0′ of the migration plan, the second bridge-and-delete after #2269.Change
Karger's single-trial, amplified and high-probability word-RAM programs no longer prove probability on machine states. Each one is shown to simulate a client of
Lean.Karger(#2241), and its bounds are taken from there. #2269 did the same for the contraction loop; this PR does it for everything built on top of it inKargerMinCut.lean.Spec level (
Algorithms/Lean/Karger/Contraction.lean):answerLaw Gis the law of the answer of one run ofkarger.answerLaw_eqsays the answer is half the total weight of the graph thatn - 2contractions leave.minStepandminRuns Rdefine amplification as a client of a trial oracleOracleComp (fun _ : Unit => ℕ).minRuns RmakesRcalls and keeps the least answer, usingOracleComp.iterate. Run withOracleComp.evalWith (fun _ => answerLaw G), each call is answered by an independent run.minRuns_ne_leis the amplification bound, proved once for any trial. If every answer is at leastmand a run missesmwith probability at mostq, thenminRuns Rmissesmwith probability at mostq ^ R.minRuns_ne_minCut_leinstantiates it with Karger's1 - 2 / (n (n - 1)).exists_cut_of_mem_support_answerLawsays every answer is the weight of a non-trivial cut.mem_support_minRunssays every amplified answer is the answer of one of the runs.minCut_le_of_mem_support_kargerbecomes a corollary (13 → 3 proof lines).Simulation (
WordRAM/KargerMinCut.lean). EachExecRandLawstatement gives the exact law of the output register:singleCode_law:val1has the lawanswerLaw ⟨n, W⟩.ampTrialBody_law: after one trial,bestValhas the law ofv ↦ if i = 0 then v else min v bestValapplied toanswerLaw ⟨n, W⟩. It composes the newcontractDownToAt_lawwith the deterministic copy, degree and readout steps.ampLoop_law,ampCore_law,amplifiedCode_law,highProbCode_law:bestValhas the law ofminRuns Ragainst independent runs, whereR = highProbTrials nfor the high-probability program.Small supporting additions:
ExecRandLaw.rename(Randomized/Law.lean), the law counterpart ofExecRandWithin.rename.contractDownToAt_law(Karger/Contract.lean).ContractState.mem_add_one: on two supervertices, the weight atwb + 1is half the held graph's total weight.Derived, not reproved.
singleProgram_spec,amplifiedProgram_spec,highProbProgram_specandhighProbProgram_failure_le_inv_nkeep their statements word for word. A private helperprogram_of_lawturns a law into the halting, call-budget, cut-realization, frame and probability parts. The probability comes fromtwo_div_le_toOuterMeasure_kargerorminRuns_ne_minCut_le(withhighProb_failure_lefor the high-probability program). The cut realization comes through the law fromexists_cut_of_mem_support_answerLaw.Deleted (proof-body lines,
scripts/proof_lengths.py):ampTrialBody_spec(221): the per-trial survival composition, thebestValstickiness and the per-trial failure bound onm.eval.ampLoop_spec(109): the failure product over machine states.singleCode_spec(116),ampCore_spec(59),amplifiedCode_spec(16),highProbCode_spec(20), and the privateampTrial_step_bound(2).AmpInv.best_cut: thatbestValis a cut weight now comes from the specification through the law.Statement changes
KargerMinCutAbstract.leanand the public theorems ofKargerMinCutBridge.leanare unchanged. A script compared declaration headers with the base: only the internal ones listed below differ._speclemmas above become_lawlemmas, andAmpInvlosesbest_cut.highProbTime_boundbecomes public, as4 log₂ n + highProbTrials n (50 n² + 12 n + 30) + 22 ≤ highProbTime n, because the bridge needs it. The privaterun_kargeris generalized from2 + stonvertices.ExecRandwitness and the time bound from the_lawlemmas instead of the_speclemmas.Size
+492 / −626, net −134. By file:
WordRAM/KargerMinCut.leanLean/Karger/Contraction.leanWordRAM/Karger/Contract.leanRandomized/Law.leanKargerMinCutBridge.leanThe longest proof in
KargerMinCut.leanwasampTrialBody_spec(221 lines). It is nowampTrialPost_exec(112, unchanged), andampTrialBody_lawhas 94. ElaboratingKargerMinCut.leantakes 4.6 s instead of 10.0 s (lake env lean, three runs each, same machine and load).The net is smaller than the plan's −200 to −400 estimate. The spec-level client and its bounds add about 140 lines to
Contraction.lean, and the deleted reasoning was about 500 proof lines.Existing notions considered
Reused:
OracleComp.iteratefor the loop of runs, withiterate_invariantfor the support lemma.OracleComp.evalWithfor independent answers.ExecRandLawand its rules, and refactor(Algorithms/WordRAM/Karger): derive contraction survival from Karger.spec through a simulation lemma #2269'scontractDownTo_law.Not used:
repeatRoundWithis aPMF Boolthat stops at the first success. It is aPMF-valued algorithm, while CONTRIBUTING asks for programs, and it combines runs differently.Probability.PMF.iidgives tuples of independent draws. Matching the machine's running minimum would need an extra exchange argument.ProbComp.iterate_failure_leadds per-step failures; this proof needs their product.answerLawis new: no existing declaration names the law ofkarger's answer.Validation
lake build --wfail --iofail Complexity ComplexityTests ComplexityAbstractspasses locally on the merged head.lake test --wfail --iofail,mk_all --check,checkInitImportsandlint-stylepass, as do the Batteries linters on the four changed library modules.check_hygiene.py --check-simp,check_tidy_surface.pyandcheck_changed_files.py --base origin/mainpass.parallel_defs.py --theoremsreports no duplicate statements.Hosted CI runs the six gates.
Not in scope
randbudgets stay:copyMatrixCode_exec,ampTrialPost_exec, the setup lemmas,logLoop_execand the deterministic part ofampCore_law. They are the hop-4 part that the native migration (K2, feat(Algorithms/Lean/Karger): lay out the contraction structure in memory, with the sampling query #2253–feat(Algorithms/Lean/Karger): Karger's algorithm over memory, with its laws and costs transferred #2255) replaces.KargerStein.lean(fastCutAmpBody_spec,KSAmpInv.best_cut) still proves its failure product on machine states.minRuns_ne_leis stated for any trial, so K3 can reuse it once FastCut has a spec-level law.AI assistance
Written by Claude Code (Opus) as
kargeramp-claude-015dlg8k; not yet reviewed.🤖 Generated with Claude Code
https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG