Karger's randomized global minimum cut algorithm on the word RAM #
Implements Karger's randomized contraction algorithm [Karger1993] on n-vertex weighted
undirected multigraphs (n ≥ 2, IsMultigraph W) over Cslib.WordRAM.Basis.standard, providing
three complete machine-level endpoints built on the workspace-relocatable subroutine
contractDownTo:
- Single-trial contraction (
singleProgram,r = 16): runs onn :: flattenMatrix W, computes row degrees at2 + n ^ 2, contracts in place down to2supervertices in at most42 * n ^ 2 + 12 * n + 21steps andn - 2randcalls, outputs a genuine non-trivial cut weightcutWeight W C ≥ minCut Won every supported branch, and achievesminCut Wwith probability at least2 / (n * (n - 1))whenever0 < minCut W. - Repeated-trial amplification (
amplifiedProgram,r = 22): runs onR :: n :: flattenMatrix W(1 ≤ R), copies the immutable input matrix from[3, 3 + n ^ 2)into[3 + n ^ 2, 3 + 2 * n ^ 2)viaCslib.WordRAM.ArrayCopybefore each ofRindependent contractions, halts withinR * (50 * n ^ 2 + 12 * n + 30) + 16steps andR * (n - 2)randcalls with a genuine non-trivial cut weight≥ minCut W, and missesminCut Wwith probability at most(1 - 2 / (n * (n - 1))) ^ Rwhenever0 < minCut W. - Explicit
O(n ^ 4 log n)high-probability global minimum cut (highProbProgram,r = 22): runs onn :: flattenMatrix W, computeshighProbTrials n = (n * (n - 1) / 2) * (⌊log₂ n⌋ + 2)in registers using shifts and multiplication (without.divor.mod), halts within33 * n ^ 4 * (Nat.log 2 n + 2)steps with a genuine non-trivial cut weight≥ minCut W, and missesminCut Wwith probability at most1 / (2 * n)(hence at most1 / n) whenever0 < minCut W, via an elementary Bernoulli power bound withoutReal.exp.
Source statements and notation mapping #
- Source locators (paraphrase):
[Karger1993], Section 2, Theorem 2.1 and Corollary 2.1 (paraphrase): contracting uniformly chosen edges in ann-vertex multigraph down to2meta-vertices returns any fixed global minimum cut with probability at leastC(n, 2)⁻¹ = 2 / (n * (n - 1)), and repeatingO(n ^ 2 log n)independent trials amplifies the success probability to1 - 1 / poly(n).[KargerStein1996], Section 2, Lemma 2.1, Theorem 2.2, and Corollary 2.3, Section 2.1, Corollary 2.4, and Section 3 ("Implementing the Contraction Algorithm", Section 3.1, Lemma 3.1 and Section 3.2, Corollary 3.2) (paraphrase): contracting ann-vertex weighted multigraph fromkdown totsupervertices via edge-weight-proportional selection preserves any fixed minimum cut with probability at leastC(t, 2) / C(k, 2) = t * (t - 1) / (k * (k - 1))(2 / (n * (n - 1))att = 2, k = n), and ann × nweighted adjacency matrix with a maintained row-degree array executes each trial inO(n ^ 2)total time (O(n)per step in Section 3.2).[MitzenmacherUpfal2017], Section 1.5, Theorem 1.8 (paraphrase): multiplying single-step survival bounds1 - 2 / ifromi = ndown to3yields2 / (n * (n - 1)).
- Notation mapping, implementation variants, and parameter choices:
C(n, 2)⁻¹↔2 / (n * (n - 1))(singleProgram_spec,amplifiedProgram_spec);- whereas
[KargerStein1996], Section 3.1 draws twice (uproportional toD[u]thenvproportional toW[u, v]via twoRandom-Selectcalls),contractDownTouses an equivalent single-draw variant: one unit-costranddraw in{0, …, S - 1}(S = totalDoubledWeight W) resolved through linear prefix-sum scansuScan(rowDeg) andvScan(W[u, v]), achieving the same2 * W[u, v] / Sdistribution of Lemma 3.1; and whereas Section 3.2 statesO(n)per contraction step, our swap-compaction of active slotk - 1intovgivesO(k)instructions onkactive supervertices; - the concrete trial count
highProbTrials n = (n * (n - 1) / 2) * (Nat.log 2 n + 2)and the1 / (2 * n)failure bound inhighProbProgram_specare our own parameter choice instantiating theO(n ^ 2 log n)amplification of[Karger1993], Section 2, Corollary 2.1; - the hypothesis
0 < minCut Win the probability clauses is included only for proof convenience (whenminCut W = 0, deterministicS = 0contraction still halts without faulting and outputs a valid non-trivial cut weight).
Main definitions #
Cslib.Algorithms.WordRAM.Karger.singleCode,Cslib.Algorithms.WordRAM.Karger.singleProgram,Cslib.Algorithms.WordRAM.Karger.singleTime: single-trial Basic Karger (r = 16).Cslib.Algorithms.WordRAM.Karger.ampCore,Cslib.Algorithms.WordRAM.Karger.amplifiedCode,Cslib.Algorithms.WordRAM.Karger.amplifiedProgram,Cslib.Algorithms.WordRAM.Karger.amplifiedTime:R-trial amplified Karger (r = 22).Cslib.Algorithms.WordRAM.Karger.highProbCode,Cslib.Algorithms.WordRAM.Karger.highProbProgram,Cslib.Algorithms.WordRAM.Karger.highProbTime:O(n ^ 4 log n)high-probability global min-cut (r = 22).
Main results #
Cslib.Algorithms.WordRAM.Karger.singleProgram_spec: worst-caseO(n ^ 2)step bound,n - 2rand-call bound, pathwise non-trivial cut realization,Modifiesframe, and2 / (n * (n - 1))success probability lower bound forsingleProgram.Cslib.Algorithms.WordRAM.Karger.amplifiedProgram_spec: worst-caseO(R * n ^ 2)step bound,R * (n - 2)rand-call bound, pathwise non-trivial cut realization,Modifiesframe, and(1 - 2 / (n * (n - 1))) ^ Rfailure probability upper bound foramplifiedProgram.Cslib.Algorithms.WordRAM.Karger.highProbProgram_spec,Cslib.Algorithms.WordRAM.Karger.highProbProgram_failure_le_inv_n: worst-case33 * n ^ 4 * (Nat.log 2 n + 2)step bound, pathwise non-trivial cut realization,Modifiesframe, and1 / (2 * n)(1 / n) failure probability upper bound forhighProbProgram.
References #
Word-size sufficiency and Data.init matrix layout #
Under 2 ≤ n and logWidth 3 n ≤ w, workspace end-addresses up to 3 + 2 * (n * n) + n fit in
w-bit words.
Under 2 ≤ n and logWidth 3 n ≤ w, highProbTrials n and intermediate n * (n - 1) and
Nat.log 2 n + 2 values fit in w-bit words.
logWidth 3 n ≤ w and Fits w (totalDoubledWeight W) suffice for
InputFits w (n :: flattenMatrix W).
logWidth 3 n ≤ w, Fits w R, and Fits w (totalDoubledWeight W) suffice for
InputFits w (R :: n :: flattenMatrix W).
In Data.init (pfx ++ flattenMatrix W), the flattened matrix occupies memory starting at
1 + pfx.length with stride n.
In Data.init (n :: flattenMatrix W), memory holds W at base 2 with stride n.
In Data.init (R :: n :: flattenMatrix W), memory holds W at base 3 with stride n.
Endpoint 1: Single-trial Basic Karger (r = 16) #
Setup for singleCode: read n from mem[1] and configure (wBase, dBase, stride, activeK, targetT) = (2, 2 + n * n, n, n, 2).
Instances For
Postprocessing for singleCode: load the contracted superedge weight mem[wBase + 1] into
val1.
Instances For
Structured 16-register single-trial Karger contraction program on n :: flattenMatrix W.
Instances For
Compiled 16-register single-trial Karger contraction program.
Instances For
Worst-case instruction bound 42 * n ^ 2 + 12 * n + 21 for singleProgram.
Instances For
Structured ProbComp specification of singleCode.
Single-trial Basic Karger specification (singleProgram).
At word size w ≥ logWidth 3 n when totalDoubledWeight W < 2 ^ w:
singleProgramhalts withinsingleTime n = 42 * n ^ 2 + 12 * n + 21steps;- executes at most
n - 2randcalls; - on every supported branch, outputs
cutWeight W C ≥ minCut Wfor a genuine non-trivial cutCofWwhile modifying memory only in[2, 2 + n * n + n); - when
0 < minCut W(excluded only for proof convenience;S = 0contraction still halts fault-free with a valid cut weight), outputsminCut Wwith probability at least2 / (n * (n - 1)).
Shared R-trial amplification engine (r = 22) #
Base address of the immutable input matrix W.
Instances For
Original vertex count n, preserved across all trials.
Instances For
Word count n * n of the flattened matrix.
Instances For
Total number R of independent trials to execute.
Instances For
Number of trials completed so far (0 .. R).
Instances For
Minimum cut weight seen across completed trials.
Instances For
Injective register map embedding Cslib.WordRAM.ArrayCopy (r = 7) into Fin 22 with
(src, dst, len, idx, addr, value, one) = (srcBase, wBase, matLen, idx, addr1, val1, one).
Instances For
Copy matLen words from srcBase to wBase via Cslib.WordRAM.ArrayCopy.program.
Instances For
Loop running numTrials independent contractions.
Instances For
Loop invariant for ampLoop at trialIdx = i ≤ R.
- src_matrix : HoldsMatrix x.mem sb n W
- modifies_ws : WordRAM.Modifies (Finset.Ico (sb + n * n) (sb + 2 * (n * n) + n)) mem₀ x.mem
- best_cut : 0 < i → ∃ (C : Finset (Fin n)), IsNonTrivialCut C ∧ x.regs AmpReg.bestVal = cutWeight W C
Instances For
Specification of a single trial ampTrialBody from AmpInv.
Specification of ampCore for 1 ≤ R trials from any state with srcBase = sb,
nOrig = n, numTrials = R, and HoldsMatrix x.mem sb n W.
Endpoint 2: Amplified R-trial Karger (r = 22) #
Setup for amplifiedCode on R :: n :: flattenMatrix W: load R = mem[1], n = mem[2], and
set srcBase = 3.
Instances For
Structured 22-register R-trial Karger program on R :: n :: flattenMatrix W.
Instances For
Compiled 22-register R-trial Karger program.
Instances For
Worst-case instruction bound R * (50 * n ^ 2 + 12 * n + 30) + 16 for amplifiedProgram.
Instances For
Structured ProbComp specification of amplifiedCode.
R-trial amplified Karger specification (amplifiedProgram).
At word size w ≥ logWidth 3 n when 1 ≤ R, R < 2 ^ w, and totalDoubledWeight W < 2 ^ w:
amplifiedProgramhalts withinamplifiedTime R n = R * (50 * n ^ 2 + 12 * n + 30) + 16steps;- executes at most
R * (n - 2)randcalls; - on every supported branch, outputs
cutWeight W C ≥ minCut Wfor a genuine non-trivial cutCofWwhile modifying memory only in[3 + n * n, 3 + 2 * (n * n) + n); - when
0 < minCut W(excluded only for proof convenience;S = 0contraction still halts fault-free with a valid cut weight), missesminCut Wwith probability at most(1 - 2 / (n * (n - 1))) ^ R.
Endpoint 3: Explicit O(n ^ 4 log n) high-probability global minimum cut (r = 22) #
Setup for highProbCode on n :: flattenMatrix W: load n = mem[1], compute
numTrials = highProbTrials n = (n * (n - 1) / 2) * (Nat.log 2 n + 2) using shifts and
multiplications, and set srcBase = 2.
Instances For
Structured 22-register O(n ^ 4 log n) high-probability Karger program on
n :: flattenMatrix W.
Instances For
Compiled 22-register O(n ^ 4 log n) high-probability Karger program.
Instances For
Worst-case instruction bound 33 * n ^ 4 * (Nat.log 2 n + 2) for highProbProgram.
Instances For
Structured ProbComp specification of highProbCode.
Explicit O(n ^ 4 log n) high-probability global minimum cut (highProbProgram).
At word size w ≥ logWidth 3 n when 2 ≤ n and totalDoubledWeight W < 2 ^ w:
highProbProgramhalts withinhighProbTime n = 33 * n ^ 4 * (Nat.log 2 n + 2)steps;- executes at most
highProbTrials n * (n - 2)randcalls; - on every supported branch, outputs
cutWeight W C ≥ minCut Wfor a genuine non-trivial cutCofWwhile modifying memory only in[2 + n * n, 2 + 2 * (n * n) + n); - when
0 < minCut W(excluded only for proof convenience;S = 0contraction still halts fault-free with a valid cut weight), missesminCut Wwith probability at most1 / (2 * n).
Corollary of highProbProgram_spec: when 0 < minCut W, highProbProgram misses minCut W
with probability at most 1 / n.