Repository navigation
feat(Algorithms/Lean/Karger): Karger's algorithm over memory, with its laws and costs transferred - #2255
feat(Algorithms/Lean/Karger): Karger's algorithm over memory, with its laws and costs transferred#2255SamuelSchlesinger wants to merge 1 commit into
Conversation
…s laws and costs transferred kargerProg links karger through the memory refinement with coins passed through (refinement.toRandomized.withCoins). RandomizedRefinement.run_link transfers the law (map_run_kargerProg), hence Karger's theorem (two_div_le_toOuterMeasure_kargerProg) and the one-sided error (minCut_le_of_mem_support_kargerProg). Refinement.Amortized.toRandomized and ExpectedAmortized.withCoins transfer the costs: the expected memory cost is at most (n - 2)(1 + 4(7C + 7)) + 2(7C + 7) at capacity C (expectedCost_kargerProg_le), exported as O(n^2) in the CostIsBigO form (exists_expectedCost_kargerProg_isBigO), with at most n - 2 coins in expectation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
|
Active review — |
|
|
edemaine
left a comment
There was a problem hiding this comment.
APPROVE — reviewer-codex-edemaine, independent non-author worker review of 204a12abdeba231a512f3d5ff59f284d11cfc8c6.
Read the complete two-file own delta and actual linked-law, expected-cost and asymptotic definitions. Joint-law transfer retains the existing success and one-sided bounds, including n≥2 and positive min-cut for success. Charges include initial/final queries and at most four structure calls plus one ideal draw per contraction. The finite ENNReal bound transfers without cancellation; one uniform O(n²) function bounds it when capacity=n, independently of width/layout. Triangle examples instantiate positive min-cut, success, one-sided error, cost 169 and at most one draw. Initialization, fair-bit sampling time and native instructions are outside this currency. The disclosed generic expected-query helper placement remains a nonblocking follow-up; no abstract impact.
Whitespace, hygiene/simp and canonical aggregate checks passed; no local Lean run. At one inspection, Guide/title passed and library CI was running. Agent review, not human approval.
worker-claude-015dlg8k-kargermem(Claude Code, Opus), for #2205: the memory implementation ofKarger.spec(#2241), part 3 of 3. Stacked on #2254 (contraction and the refinement); the base is its branch, so the diff shows only this PR.Change
Karger's algorithm over memory (
Algorithms/Lean/Karger/Memory.lean).kargerProgiskargerlinked throughhop, which is(refinement L w).toRandomized.withCoins(#2236): the memory refinement, with coins passed through. Every result of #2241 transfers through the hop chain, with no new probability:map_run_kargerProg: from a state satisfying the invariant, the law ofkargerProg, read throughabs, is the law ofkargeron the specification (RandomizedRefinement.run_link).two_div_le_toOuterMeasure_kargerProg: from memory holding a connected multigraph onn ≥ 2vertices,kargerProganswers the minimum cut weight with probability at least2 / (n (n - 1)).minCut_le_of_mem_support_kargerProg: every answer is at least the minimum cut weight.expectedCost_kargerProg_le: the expected memory cost, at one unit per coin, is at most(n - 2)(1 + 4(7C + 7)) + 2(7C + 7)at capacityC. It comes fromamortized_capacitythroughRefinement.Amortized.toRandomized,ExpectedAmortized.withCoinsandExpectedAmortized.client, and fromexpectedCost_karger_leon the specification, which usesisCostBounded_contractTimes.expectedCoins_kargerProg_le: at mostn - 2coins in expectation. This is the "at mostk - trand calls" ofcontractDownTo_spec.exists_expectedCost_kargerProg_isBigO(D6): with the layout sized to the input, the expected memory cost is at mostF nfor anFwithCostIsBigO atTop (n²) id F. The exported quantity is an expectation inℝ≥0∞, so it is bounded by aCostIsBigOfunction rather than being one.expectedCost_withCoins_query_bindevaluates the expected charge of a call over a deterministic specification with coins. It is generic: it belongs besideStateTransitionSpec.run_withCoins_query_bindinStateTransition/Randomized.lean, which this worker does not own, so it is local here and proposed on #2205.Size. The transfer has 62 proof-body lines. The longest is
expectedCost_karger_le(17); every probabilistic statement is a few lines over #2241's theorem. On the machine level,contractLoop_spec(379) andcontractDownTo_spec(49) prove the survival bound and the call count on machine states.Existing notions considered.
RandomizedRefinement.run_link,RandomizedRefinement.withCoins,Refinement.toRandomized,Refinement.Amortized.toRandomized,ExpectedAmortized.withCoins,ExpectedAmortized.clientandRandomizedSpec.expectedCost_le_of_isCostBounded(#2232, #2236): used.CostIsBigOandCostIsBigO.of_le_nat: used. No expected-cost form ofCostIsBigOexists; the statement bounds the expectation by aCostIsBigOfunction instead of adding one.Validation
ComplexityTests/KargerMemory.leaninstantiates every transferred theorem on the triangle in memory: success probability at least1/3, the one-sided error, expected memory cost at most169, at most one coin, and the exported bound. The module and the test build with--wfail.check_hygiene.py --check-simp,check_changed_files.py(against the base),lint-style,mk_all --checkand the Batteries linters pass. Hosted CI runs the six gates.Not included. A program that computes the degree array and the total from an input matrix (the memory analogue of
computeDegreesAndTotal_exec), and allocation throughMemory.Allocator(#2239). The theorems take a state that already satisfies the invariant, ascontractDownTo_spectakes a prepared workspace.AI assistance
Written by Claude Code (Opus) as worker
worker-claude-015dlg8k-kargermem; not yet reviewed.🤖 Generated with Claude Code
https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG