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)(hence at most1 / n) whenever0 < minCut W(excluded only for proof convenience).
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)(1 / 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 #
Under 2 ≤ n and logWidth 4 n ≤ w, stack workspace end-addresses up to 2 + 27 * (n * n) fit
in w-bit words.
Under 2 ≤ n and logWidth 4 n ≤ w, fastCutTrials n = (Nat.log 2 n + 15) * (Nat.log 2 n + 2)
fits in w-bit words.
logWidth 4 n ≤ w and Fits w (totalDoubledWeight W) suffice for
InputFits w (n :: flattenMatrix W).
In Data.init (n :: flattenMatrix W), memory holds W at base 2 with stride n.
Register layout (r = 24) #
Base address (2) of the immutable input matrix W.
Instances For
Root vertex count n, preserved across all trees.
Instances For
Current stack frame base address fp.
Instances For
Current active stack depth sp (0 = empty).
Instances For
Cut weight returned by the most recently popped frame.
Instances For
Number of FastCut trees completed so far.
Instances For
Minimum cut weight seen across completed FastCut trees.
Instances For
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).
Instances For
Copy rem words from uReg to wBase via Cslib.WordRAM.ArrayCopy.program.
Instances For
Loop body of thresholdCode: advance t to t + 1 while maintaining uReg = t
(= (t + 1) - 1) and val1 = 2 * (t + 1) * t without subtraction.
Instances For
Preamble of thresholdCode: initialize rem = k * (k - 1) and (targetT, uReg, val2, val1) = (2, 1, 2, 4).
Instances For
Inner column loop body of copySubmatrixCode: copy mem[idx + vReg] to mem[rem + vReg].
Instances For
Row-pointer advance at the end of copySubRowBody.
Instances For
Preamble of copySubmatrixCode.
Instances For
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.
Instances For
Stage 0 update (7 ≤ k): set mem[fp + 2 + k * k] ← 1 before contracting Branch 1.
Instances For
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.
Instances For
Workspace setup for branchContractAndPush (7 ≤ k).
Instances For
Destination setup before compacting the contracted t × t submatrix into childFp + 2.
Instances For
Deterministic tail of branchContractAndPush: compact the t × t contracted submatrix into
childFp + 2 and push the child frame header at childFp.
Instances For
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.
Instances For
Single iteration body of the explicit-stack FastCut loop.
Instances For
Outer explicit-stack while loop executing all active frames down to spReg = 0.
Instances For
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₀.
Instances For
Structural LoopSegment specification of recursive FastCut over depth budget d.
Root-frame setup before copying the input matrix W from srcBase into fp₀ + 2.
Instances For
Root-frame stage/stack-pointer initialization after copying W into fp₀ + 2.
Instances For
Endpoint 1: Single-tree recursive FastCut (r = 24) #
Setup for fastCutCode on n :: flattenMatrix W: load n = mem[1] and set srcBase = 2.
Instances For
Structured 24-register single-tree Karger–Stein FastCut code on n :: flattenMatrix W.
Instances For
Compiled 24-register single-tree Karger–Stein FastCut program.
Instances For
Worst-case O(n ^ 2 log n) instruction bound 2500 * n ^ 2 * (Nat.log 2 n + 2) for
fastCutProgram.
Instances For
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.
Instances For
Postprocessing after each fastCutTree trial: update bestVal with retVal (unconditionally
on trial 0 and via minimum thereafter) and increment trialIdx.
Instances For
Body of one outer FastCut amplification trial.
Instances For
Outer amplification loop running numTrials independent FastCut trees.
Instances For
Structured 24-register O(n ^ 2 log ^ 3 n) high-probability Karger–Stein program on
n :: flattenMatrix W.
Instances For
Compiled 24-register O(n ^ 2 log ^ 3 n) high-probability Karger–Stein program.
Instances For
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.
Instances For
Loop invariant for fastCutAmpLoop at trialIdx = i ≤ R.
- src_matrix : HoldsMatrix x.mem sb n W
- modifies_ws : WordRAM.Modifies (Finset.Ico (sb + n * n) (sb + 27 * (n * n))) mem₀ x.mem
- best_cut : 0 < i → ∃ (C : Finset (Fin n)), IsNonTrivialCut C ∧ x.regs KSReg.bestVal = cutWeight W C
Instances For
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).
Corollary of fastCutHighProbProgram_spec: when 0 < minCut W, fastCutHighProbProgram
misses minCut W with probability at most 1 / n.