Karger–Stein's recursive FastCut algorithm on the word RAM #
Implements the Karger–Stein recursive randomized global minimum cut algorithm ([KargerStein1996],
Section 4, Figure 6, Lemmas 4.1–4.3, and the minimum-cut-value part of Theorem 4.4; paraphrase) on
n-vertex weighted undirected
multigraphs (n ≥ 2, IsMultigraph W) over Cslib.WordRAM.Basis.standard using r = 24
registers and an explicit iterative frame stack in O(n ^ 2) scratch words (≤ 26 * n ^ 2 stack
words plus n ^ 2 input words, matching Section 4, Lemma 4.2), providing two machine-level
endpoints on n :: flattenMatrix W:
- Single-tree recursive contraction (
fastCutProgram,r = 24,[KargerStein1996], Section 4, Figure 6 and Lemmas 4.1–4.3; paraphrase): contracts recursively fromk ≥ 7down to the pure-integer thresholdt = fastCutThreshold k(smallestt ≥ 2withk * (k - 1) ≤ 2 * t * (t - 1), an integer deviation from Figure 6's⌈k / √2 + 1⌉that is never larger and is strictly smaller at e.g.k = 8, wheret = 6vs7) along two independent branches, switches atk ≤ 6to a single contraction down to2supervertices (the source's base case: Figure 6'sContract(G, 2)with the size-7 cutoff of equation (2); a leaf keeps a fixed minimum cut with probability≥ 2 / (k * (k - 1)) ≥ 1 / 15, equation (2)'s base-case bound, which is where the15comes from), halts withinfastCutTime n = 2500 * n ^ 2 * (Nat.log 2 n + 2)(O(n ^ 2 log n)) steps andfastCutNodeQueries n ≤ 6 * n ^ 2(O(n ^ 2))randcalls with a genuine non-trivial cut weightcutWeight W C ≥ minCut Won every supported path, modifies only[2 + n ^ 2, 2 + 27 * n ^ 2), and achievesminCut Wwith probability at least1 / (Nat.log 2 n + 15)whenever0 < minCut W(excluded only for proof convenience; whenminCut W = 0, any non-trivial zero-weight cut is already optimal). - Amplified high-probability global minimum cut (
fastCutHighProbProgram,r = 24,[KargerStein1996], Section 4, Theorem 4.4; paraphrase, the value part only: the source finds all minimum cuts inO(m log(n ^ 2 / m))space; we prove the returned value isminCut Wexcept with probability≤ 1 / (2 * n)): executes our concreteO(log ^ 2 n)trial schedulefastCutTrials n = (Nat.log 2 n + 15) * (Nat.log 2 n + 2)of independentFastCuttrees reusing the same[2 + n ^ 2, 2 + 27 * n ^ 2)scratch arena, halts withinfastCutHighProbTime n = 2600 * n ^ 2 * (Nat.log 2 n + 15) * (Nat.log 2 n + 2) ^ 2(O(n ^ 2 log ^ 3 n)) steps andfastCutTrials n * (6 * n ^ 2)randcalls with a genuine non-trivial cut weight≥ minCut W, and missesminCut Wwith probability at most1 / (2 * n)whenever0 < minCut W(and unconditionally at most1 / ninfastCutHighProbProgram_failure_le_inv_n, without2 ≤ nor0 < minCut W).
The probability argument is proved once for the oracle client
Cslib.Algorithms.Lean.Karger.fastCut. Native segments observe exactly that client's answer law
(fastCutNode_law, fastCutTree_law), and the outer loop observes the existing independent
minRuns client (fastCutAmpLoop_law, fastCutHighProbCode_law). Their certificates keep the
original supported-path instruction and random-call bounds and memory frames. They do not
replace those bounds with expected costs.
baseCaseAndPop_spec, branchContractAndPush_spec, fastCutTree_spec and
fastCutAmpBody_spec remain law-derived compatibility statements for the existing exact-basis
bridge. Its still-used ChildMinCutSurvives proposition and KSAmpInv.best_cut field are retained
for that bridge; the native recursive and amplification stages consume laws directly.
Main definitions #
Cslib.Algorithms.WordRAM.Karger.fastCutCode,Cslib.Algorithms.WordRAM.Karger.fastCutProgram,Cslib.Algorithms.WordRAM.Karger.fastCutTime: single-treeO(n ^ 2 log n)Karger–SteinFastCut(r = 24).Cslib.Algorithms.WordRAM.Karger.fastCutHighProbCode,Cslib.Algorithms.WordRAM.Karger.fastCutHighProbProgram,Cslib.Algorithms.WordRAM.Karger.fastCutHighProbTime: amplifiedO(n ^ 2 log ^ 3 n)high-probability Karger–Stein (r = 24).
Main results #
Cslib.Algorithms.WordRAM.Karger.fastCutProgram_spec: worst-caseO(n ^ 2 log n)step bound,O(n ^ 2)rand-call bound, pathwise non-trivial cut realization,Modifiesframe, and1 / (Nat.log 2 n + 15)success probability lower bound forfastCutProgram([KargerStein1996], Section 4, Figure 6 and Lemmas 4.1–4.3; paraphrase).Cslib.Algorithms.WordRAM.Karger.fastCutHighProbProgram_spec,Cslib.Algorithms.WordRAM.Karger.fastCutHighProbProgram_failure_le_inv_n: worst-caseO(n ^ 2 log ^ 3 n)step bound, pathwise non-trivial cut realization,Modifiesframe, and1 / (2 * n)(unconditional1 / n) failure probability upper bound forfastCutHighProbProgram(the minimum-cut-value part of[KargerStein1996], Section 4, Theorem 4.4; paraphrase).
References #
Word-size sufficiency (logWidth 4 n ≤ w) and input layout #
Register layout (r = 24) #
Base address (2) of the immutable input matrix W.
Root vertex count n, preserved across all trees.
Current stack frame base address fp.
Current active stack depth sp (0 = empty).
Cut weight returned by the most recently popped frame.
Total number of FastCut trees to run in fastCutHighProbCode.
Number of FastCut trees completed so far.
Minimum cut weight seen across completed FastCut trees.
Deterministic subroutines: block copy, integer threshold, and submatrix compaction #
Injective register map embedding Cslib.WordRAM.ArrayCopy (r = 7) into Fin 24 with
(src, dst, len, idx, addr, value, one) = (uReg, wBase, rem, idx, addr1, val1, one).
Copy rem words from uReg to wBase via Cslib.WordRAM.ArrayCopy.program.
Loop body of thresholdCode: advance t to t + 1 while maintaining uReg = t
(= (t + 1) - 1) and val1 = 2 * (t + 1) * t without subtraction.
Preamble of thresholdCode: initialize rem = k * (k - 1) and (targetT, uReg, val2, val1) = (2, 1, 2, 4).
Inner column loop body of copySubmatrixCode: copy mem[idx + vReg] to mem[rem + vReg].
Row-pointer advance at the end of copySubRowBody.
Explicit iterative call-stack machine for FastCut (r = 24) #
Each active frame at base address fp for a k-supervertex subproblem (frameSize k = 4 + 2 * (k * k) + k) lays out its immutable data first and its mutable workspace second:
mem[fp + 0] = parentFp(immutable during this frame),mem[fp + 1] = k(immutable during this frame),[fp + 2, fp + 2 + k * k): immutablek × kmatrixW_k(stridek),mem[fp + 2 + k * k] = stage(0,1, or2),mem[fp + 3 + k * k] = savedVal1(Branch 1's returned cut weight),[fp + 4 + k * k, fp + 4 + 2 * (k * k)): workingk × kcontraction matrix (wBase),[fp + 4 + 2 * (k * k), fp + frameSize k): workingk-word degree buffer (dBase),childFp = fp + frameSize k: child frame pushed by Stages0and1.
Consequently, executing a frame at fp (including all of its recursive descendants) modifies only
Finset.Ico (fp + 2 + k * k) (fp + fastCutScratch k), leaving parentFp, k, W_k, and every
ancestor frame below fp untouched.
Base-case execution (2 ≤ k ≤ 6): copy W_k to wBase, compute degrees, contract once down to
2 supervertices, read W'[0, 1], and pop the frame.
Stage 0 update (7 ≤ k): set mem[fp + 2 + k * k] ← 1 before contracting Branch 1.
Stage 1 update (7 ≤ k): set mem[fp + 2 + k * k] ← 2 and save retVal into
mem[fp + 3 + k * k] before contracting Branch 2.
Workspace setup for branchContractAndPush (7 ≤ k).
Destination setup before compacting the contracted t × t submatrix into childFp + 2.
Deterministic tail of branchContractAndPush: compact the t × t contracted submatrix into
childFp + 2 and push the child frame header at childFp.
Shared Branch 1 / Branch 2 contraction-and-push body (7 ≤ k): compute
t = fastCutThreshold k, copy W_k to wBase, compute degrees, contract down to t, compact the
t × t submatrix into childFp + 2, and push the child frame at childFp = fp + frameSize k.
Single iteration body of the explicit-stack FastCut loop.
Outer explicit-stack while loop executing all active frames down to spReg = 0.
Event on a child-frame entry state d at childFp asserting that d.mem holds a valid
t-supervertex contraction (W₁, part₁) of W₀ together with a non-trivial cut B₁ pulling back
to a minimum cut of W₀.
Every native recursive node has exactly the specification's answer law, with the existing supported-path instruction, random-call and memory-frame bounds.
Structural LoopSegment specification of recursive FastCut over depth budget d.
Root-frame setup before copying the input matrix W from srcBase into fp₀ + 2.
Root-frame stage/stack-pointer initialization after copying W into fp₀ + 2.
A complete native tree has exactly the recursive specification answer law.
Endpoint 1: Single-tree recursive FastCut (r = 24) #
Setup for fastCutCode on n :: flattenMatrix W: load n = mem[1] and set srcBase = 2.
Structured 24-register single-tree Karger–Stein FastCut code on n :: flattenMatrix W.
Compiled 24-register single-tree Karger–Stein FastCut program.
Worst-case O(n ^ 2 log n) instruction bound 2500 * n ^ 2 * (Nat.log 2 n + 2) for
fastCutProgram.
The single-tree code observes the recursive answer law, including the charged input setup.
Structured ProbComp specification of fastCutCode.
Single-tree Karger–Stein FastCut specification (fastCutProgram, [KargerStein1996],
Section 4, Figure 6 and Lemmas 4.1–4.3; paraphrase).
At word size w ≥ logWidth 4 n when 2 ≤ n and totalDoubledWeight W < 2 ^ w:
fastCutProgramhalts withinfastCutTime n = 2500 * n ^ 2 * (Nat.log 2 n + 2)steps;- executes at most
fastCutNodeQueries n(≤ 6 * (n * n))randcalls; - on every supported branch, outputs
cutWeight W C ≥ minCut Wfor a genuine non-trivial cutCofWwhile modifying memory only in[2 + n * n, 2 + 27 * (n * n)); - when
0 < minCut W(excluded only for proof convenience), outputsminCut Wwith probability at least1 / (Nat.log 2 n + 15).
Endpoint 2: Amplified O(n ^ 2 log ^ 3 n) high-probability FastCut (r = 24) #
Setup for fastCutHighProbCode on n :: flattenMatrix W: load n = mem[1], compute
numTrials = fastCutTrials n = (Nat.log 2 n + 15) * (Nat.log 2 n + 2) without subtraction or
division, and initialize srcBase = 2, trialIdx = 0, bestVal = 0.
Postprocessing after each fastCutTree trial: update bestVal with retVal (unconditionally
on trial 0 and via minimum thereafter) and increment trialIdx.
Body of one outer FastCut amplification trial.
Outer amplification loop running numTrials independent FastCut trees.
Structured 24-register O(n ^ 2 log ^ 3 n) high-probability Karger–Stein program on
n :: flattenMatrix W.
Compiled 24-register O(n ^ 2 log ^ 3 n) high-probability Karger–Stein program.
Worst-case instruction bound 2600 * n ^ 2 * (Nat.log 2 n + 15) * (Nat.log 2 n + 2) ^ 2
(O(n ^ 2 log ^ 3 n)) for fastCutHighProbProgram.
Loop invariant for fastCutAmpLoop at trialIdx = i ≤ R.
- src_matrix : HoldsMatrix x.mem sb n W
- best_cut : 0 < i → ∃ (C : Finset (Fin n)), WeightedCut.IsNonTrivialCut C ∧ x.regs KSReg.bestVal = WeightedCut.cutWeight W C
The native loop has the law of independent trials of the existing amplification client. The positive total trial count excludes the empty-client convention at an arbitrary initial word.
The full native high-probability code observes the existing independent-trial law, paying for the original setup, every loop-control instruction and the same random-call budget.
Structured ProbComp specification of fastCutHighProbCode.
Amplified O(n ^ 2 log ^ 3 n) high-probability Karger–Stein (fastCutHighProbProgram,
the minimum-cut-value part of [KargerStein1996], Section 4, Theorem 4.4; paraphrase).
At word size w ≥ logWidth 4 n when 2 ≤ n and totalDoubledWeight W < 2 ^ w:
fastCutHighProbProgramhalts withinfastCutHighProbTime n = 2600 * n ^ 2 * (Nat.log 2 n + 15) * (Nat.log 2 n + 2) ^ 2steps;- executes at most
fastCutTrials n * (6 * (n * n))randcalls; - on every supported branch, outputs
cutWeight W C ≥ minCut Wfor a genuine non-trivial cutCofWwhile modifying memory only in[2 + n * n, 2 + 27 * (n * n)); - when
0 < minCut W(excluded only for proof convenience), missesminCut Wwith probability at most1 / (2 * n).
fastCutHighProbProgram misses minCut W with probability at most 1 / n, unconditionally
without 2 ≤ n or 0 < minCut W: for n < 2 the bound 1 / n is at least 1, and for 2 ≤ n
with minCut W = 0 every recursive trial outputs 0.