Documentation

Complexity.Algorithms.WordRAM.KargerStein

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:

  1. Single-tree recursive contraction (fastCutProgram, r = 24, [KargerStein1996], Section 4, Figure 6 and Lemmas 4.1–4.3; paraphrase): contracts recursively from k ≥ 7 down to the pure-integer threshold t = fastCutThreshold k (smallest t ≥ 2 with k * (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, where t = 6 vs 7) along two independent branches, switches at k ≤ 6 to a single contraction down to 2 supervertices (the source's base case: Figure 6's Contract(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 the 15 comes from), halts within fastCutTime n = 2500 * n ^ 2 * (Nat.log 2 n + 2) (O(n ^ 2 log n)) steps and fastCutNodeQueries n ≤ 6 * n ^ 2 (O(n ^ 2)) rand calls with a genuine non-trivial cut weight cutWeight W C ≥ minCut W on every supported path, modifies only [2 + n ^ 2, 2 + 27 * n ^ 2), and achieves minCut W with probability at least 1 / (Nat.log 2 n + 15) whenever 0 < minCut W (excluded only for proof convenience; when minCut W = 0, any non-trivial zero-weight cut is already optimal).
  2. 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 in O(m log(n ^ 2 / m)) space; we prove the returned value is minCut W except with probability ≤ 1 / (2 * n)): executes our concrete O(log ^ 2 n) trial schedule fastCutTrials n = (Nat.log 2 n + 15) * (Nat.log 2 n + 2) of independent FastCut trees reusing the same [2 + n ^ 2, 2 + 27 * n ^ 2) scratch arena, halts within fastCutHighProbTime n = 2600 * n ^ 2 * (Nat.log 2 n + 15) * (Nat.log 2 n + 2) ^ 2 (O(n ^ 2 log ^ 3 n)) steps and fastCutTrials n * (6 * n ^ 2) rand calls with a genuine non-trivial cut weight ≥ minCut W, and misses minCut W with probability at most 1 / (2 * n) (hence at most 1 / n) whenever 0 < minCut W (excluded only for proof convenience).

Main definitions #

Main results #

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) #

@[reducible, inline]

Constant register 0 (Reg.zero embedded into Fin 24).

Instances For
    @[reducible, inline]

    Constant register 1 (Reg.one embedded into Fin 24).

    Instances For
      @[reducible, inline]

      Working matrix base address (Reg.wBase embedded into Fin 24).

      Instances For
        @[reducible, inline]

        Working degree-array base address (Reg.dBase embedded into Fin 24).

        Instances For
          @[reducible, inline]

          Working matrix row stride (Reg.stride embedded into Fin 24).

          Instances For
            @[reducible, inline]

            Active supervertex count k (Reg.activeK embedded into Fin 24).

            Instances For
              @[reducible, inline]

              Target supervertex count t (Reg.targetT embedded into Fin 24).

              Instances For
                @[reducible, inline]

                Active doubled edge weight S (Reg.totS embedded into Fin 24).

                Instances For
                  @[reducible, inline]

                  Row / auxiliary scratch register (Reg.uReg embedded into Fin 24).

                  Instances For
                    @[reducible, inline]

                    Column / auxiliary scratch register (Reg.vReg embedded into Fin 24).

                    Instances For
                      @[reducible, inline]

                      Loop index scratch register (Reg.idx embedded into Fin 24).

                      Instances For
                        @[reducible, inline]

                        Loop length / remainder scratch register (Reg.rem embedded into Fin 24).

                        Instances For
                          @[reducible, inline]

                          Primary scratch address register (Reg.addr1 embedded into Fin 24).

                          Instances For
                            @[reducible, inline]

                            Secondary scratch address register (Reg.addr2 embedded into Fin 24).

                            Instances For
                              @[reducible, inline]

                              Primary scratch value register (Reg.val1 embedded into Fin 24).

                              Instances For
                                @[reducible, inline]

                                Secondary scratch value register (Reg.val2 embedded into Fin 24).

                                Instances For
                                  @[reducible, inline]

                                  Base address (2) of the immutable input matrix W.

                                  Instances For
                                    @[reducible, inline]

                                    Root vertex count n, preserved across all trees.

                                    Instances For
                                      @[reducible, inline]

                                      Current stack frame base address fp.

                                      Instances For
                                        @[reducible, inline]

                                        Current active stack depth sp (0 = empty).

                                        Instances For
                                          @[reducible, inline]

                                          Cut weight returned by the most recently popped frame.

                                          Instances For
                                            @[reducible, inline]

                                            Total number of FastCut trees to run in fastCutHighProbCode.

                                            Instances For
                                              @[reducible, inline]

                                              Number of FastCut trees completed so far.

                                              Instances For
                                                @[reducible, inline]

                                                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
                                                    theorem Cslib.Algorithms.WordRAM.Karger.holdsMatrix_of_copyPrefix {mem : ℕ → ℕ} {sb db k : ℕ} {W : Fin k → Fin k → ℕ} (hsrc : HoldsMatrix mem sb k W) :
                                                    HoldsMatrix (WordRAM.ArrayCopy.copyPrefix mem sb db (k * k)) db k W
                                                    theorem Cslib.Algorithms.WordRAM.Karger.ksCopyCode_exec {w sb db k : ℕ} {W : Fin k → Fin k → ℕ} {x : WordRAM.Data 24} (hsb : x.regs KSReg.uReg = sb) (hdb : x.regs KSReg.wBase = db) (hlen : x.regs KSReg.rem = k * k) (hdisj : sb + k * k ≤ db) (h1 : WordRAM.Fits w 1) (hdEnd : WordRAM.Fits w (db + k * k)) (hsrc : HoldsMatrix x.mem sb k W) :

                                                    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

                                                        Compute targetT = fastCutThreshold k in O(k) instructions for k = x.regs activeK ≥ 7.

                                                        Instances For

                                                          Inner column loop body of copySubmatrixCode: copy mem[idx + vReg] to mem[rem + vReg].

                                                          Instances For

                                                            Outer row loop body of copySubmatrixCode: copy row uReg of length targetT and advance row pointers idx by stride and rem by targetT.

                                                            Instances For

                                                              Copy the active t × t submatrix at wBase (stride stride) densely into addr2 (stride t) without .sub, .div, or .mod.

                                                              Instances For
                                                                theorem Cslib.Algorithms.WordRAM.Karger.copySubmatrixCode_exec {w wb str dstBase t : ℕ} {W : Fin t → Fin t → ℕ} {x : WordRAM.Data 24} (hwBase : x.regs KSReg.wBase = wb) (hstride : x.regs KSReg.stride = str) (htargetT : x.regs KSReg.targetT = t) (hdst : x.regs KSReg.addr2 = dstBase) (hone : x.regs KSReg.one = 1) (hstr : t ≤ str) (hdisj : wb + str * t ≤ dstBase) (hwEnd : WordRAM.Fits w (wb + str * t)) (hdstEnd : WordRAM.Fits w (dstBase + t * t)) (hmat : HoldsMatrix x.mem wb str W) :
                                                                ∃ (y : WordRAM.Data 24), WordRAM.ExecWithin w copySubmatrixCode x y (7 * t ^ 2 + 8 * t + 5) ∧ HoldsMatrix y.mem dstBase t W ∧ WordRAM.Modifies (Finset.Ico dstBase (dstBase + t * t)) x.mem y.mem ∧ y.regs KSReg.one = 1 ∧ y.regs KSReg.wBase = wb ∧ y.regs KSReg.dBase = x.regs KSReg.dBase ∧ y.regs KSReg.stride = str ∧ y.regs KSReg.activeK = x.regs KSReg.activeK ∧ y.regs KSReg.targetT = t ∧ y.regs KSReg.addr2 = dstBase ∧ ∀ (j : Fin 24), 16 ≤ ↑j → y.regs j = x.regs j
                                                                theorem Cslib.Algorithms.WordRAM.Karger.totalDoubledWeight_le_of_isContractionOf {n k : ℕ} {W₀ : Fin n → Fin n → ℕ} {part : Fin n → Fin k} {W : Fin k → Fin k → ℕ} (hC : IsContractionOf W₀ part W) :

                                                                Contracting a multigraph never increases totalDoubledWeight.

                                                                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:

                                                                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.

                                                                Frame-dispatch header: load activeK = k = mem[fp + 1], compute rem = k * k, addr1 = fp + 2, and addr2 = fp + 2 + k * k, load val2 = stage = mem[addr2], and set val1 = 7.

                                                                Instances For

                                                                  Base-case workspace pointer setup (2 ≤ k ≤ 6): set uReg = fp + 2, wBase = fp + 4 + k * k, dBase = wBase + k * k, stride = k, and targetT = 2.

                                                                  Instances For

                                                                    Base-case epilogue: read retVal = mem[wBase + 1] and pop the frame (fpReg ← mem[fpReg], spReg ← spReg - 1).

                                                                    Instances For

                                                                      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

                                                                            Destination setup before compacting the contracted t × t submatrix into childFp + 2.

                                                                            Instances For

                                                                              Initialize the child frame header at childFp = dBase + stride (parentFp = fp, k_child = t, stage_child = 0) and push (fpReg, spReg) ← (childFp, spReg + 1).

                                                                              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

                                                                                    Stage 2 epilogue (7 ≤ k): set retVal ← min savedVal1 retVal and pop the frame.

                                                                                    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
                                                                                          theorem Cslib.Algorithms.WordRAM.Karger.stepHeader_exec {w fp k stg : ℕ} {x : WordRAM.Data 24} (hk2 : 2 ≤ k) (hfp : x.regs KSReg.fpReg = fp) (hmem_k : x.mem (fp + 1) = k) (hmem_stg : x.mem (fp + 2 + k * k) = stg) (hfit : WordRAM.Fits w (fp + frameSize k)) :
                                                                                          ∃ (y : WordRAM.Data 24), WordRAM.Exec w stepHeader x y 9 ∧ y.mem = x.mem ∧ y.regs KSReg.zero = 0 ∧ y.regs KSReg.one = 1 ∧ y.regs KSReg.activeK = k ∧ y.regs KSReg.rem = k * k ∧ y.regs KSReg.addr1 = fp + 2 ∧ y.regs KSReg.addr2 = fp + 2 + k * k ∧ y.regs KSReg.val2 = stg ∧ y.regs KSReg.val1 = 7 ∧ ∀ (j : Fin 24), 16 ≤ ↑j → y.regs j = x.regs j
                                                                                          theorem Cslib.Algorithms.WordRAM.Karger.combineAndPop_exec {w fp parentFp b k v1 r2 : ℕ} {x : WordRAM.Data 24} (hk2 : 2 ≤ k) (h0 : x.regs KSReg.zero = 0) (h1 : x.regs KSReg.one = 1) (ha2 : x.regs KSReg.addr2 = fp + 2 + k * k) (hfp : x.regs KSReg.fpReg = fp) (hsp : x.regs KSReg.spReg = b + 1) (hr2 : x.regs KSReg.retVal = r2) (hmem_p : x.mem fp = parentFp) (hmem_v1 : x.mem (fp + 3 + k * k) = v1) (hfit : WordRAM.Fits w (fp + frameSize k)) (hsp_fit : WordRAM.Fits w b) :
                                                                                          theorem Cslib.Algorithms.WordRAM.Karger.baseCaseAndPop_spec {n w fp parentFp b k : ℕ} {W₀ : Fin n → Fin n → ℕ} {W_k : Fin k → Fin k → ℕ} {part : Fin n → Fin k} {x : WordRAM.Data 24} (hk2 : 2 ≤ k) (hk6 : k ≤ 6) (hk_reg : x.regs KSReg.activeK = k) (hrem_reg : x.regs KSReg.rem = k * k) (ha1_reg : x.regs KSReg.addr1 = fp + 2) (ha2_reg : x.regs KSReg.addr2 = fp + 2 + k * k) (hfp : x.regs KSReg.fpReg = fp) (hsp : x.regs KSReg.spReg = b + 1) (hmem_p : x.mem fp = parentFp) (hmat : HoldsMatrix x.mem (fp + 2) k W_k) (hC : IsContractionOf W₀ part W_k) (hfit : WordRAM.Fits w (fp + frameSize k)) (hsp_fit : WordRAM.Fits w b) (htot : WordRAM.Fits w (totalDoubledWeight W₀)) :
                                                                                          ∃ (m : ProbComp (WordRAM.Data 24 × ℕ)), WordRAM.ExecRand w baseCaseAndPop x m ∧ OracleComp.IsQueryBounded m (k - 2) ∧ (∀ z ∈ OracleComp.support m, z.2 ≤ 2000 ∧ WordRAM.Modifies (Finset.Ico (fp + 2 + k * k) (fp + frameSize k)) x.mem z.1.mem ∧ z.1.regs KSReg.zero = 0 ∧ z.1.regs KSReg.fpReg = parentFp ∧ z.1.regs KSReg.spReg = b ∧ ∃ (C : Finset (Fin n)), IsNonTrivialCut C ∧ z.1.regs KSReg.retVal = cutWeight W₀ C) ∧ ∀ (B : Finset (Fin k)), 0 < minCut W₀ → IsNonTrivialCut B → cutWeight W₀ (pullbackCut part B) = minCut W₀ → 2 / 30 ≤ m.eval.toOuterMeasure {z : WordRAM.Data 24 × ℕ | z.1.regs KSReg.retVal = minCut W₀}
                                                                                          def Cslib.Algorithms.WordRAM.Karger.ChildMinCutSurvives {n : ℕ} (W₀ : Fin n → Fin n → ℕ) (childFp t : ℕ) (d : WordRAM.Data 24) :

                                                                                          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
                                                                                            theorem Cslib.Algorithms.WordRAM.Karger.branchTail_exec {w fp b k t : ℕ} {x : WordRAM.Data 24} (ht6 : 6 ≤ t) (htk : t ≤ k) (hwBase : x.regs KSReg.wBase = fp + 4 + k * k) (hdBase : x.regs KSReg.dBase = fp + 4 + 2 * (k * k)) (hstride : x.regs KSReg.stride = k) (htargetT : x.regs KSReg.targetT = t) (hfp : x.regs KSReg.fpReg = fp) (hsp : x.regs KSReg.spReg = b + 1) (hfit : WordRAM.Fits w (fp + frameSize k + frameSize t)) (hsp_fit : WordRAM.Fits w (b + 2)) :
                                                                                            ∃ (y : WordRAM.Data 24), WordRAM.ExecWithin w branchTail x y (7 * t ^ 2 + 8 * t + 21) ∧ WordRAM.Modifies (Finset.Ico (fp + frameSize k) (fp + frameSize k + frameSize t)) x.mem y.mem ∧ y.regs KSReg.zero = 0 ∧ y.regs KSReg.fpReg = fp + frameSize k ∧ y.regs KSReg.spReg = b + 2 ∧ y.mem (fp + frameSize k) = fp ∧ y.mem (fp + frameSize k + 1) = t ∧ y.mem (fp + frameSize k + 2 + t * t) = 0 ∧ ∀ (i j : Fin t), y.mem (fp + frameSize k + 2 + ↑i * t + ↑j) = x.mem (fp + 4 + k * k + ↑i * k + ↑j)
                                                                                            theorem Cslib.Algorithms.WordRAM.Karger.branchContractAndPush_spec {n w fp b k : ℕ} {W₀ : Fin n → Fin n → ℕ} {W_k : Fin k → Fin k → ℕ} {part : Fin n → Fin k} {x : WordRAM.Data 24} (hk7 : 7 ≤ k) (hk_reg : x.regs KSReg.activeK = k) (hfp : x.regs KSReg.fpReg = fp) (hsp : x.regs KSReg.spReg = b + 1) (hmat : HoldsMatrix x.mem (fp + 2) k W_k) (hC : IsContractionOf W₀ part W_k) (hfit : WordRAM.Fits w (fp + fastCutScratch k)) (hsp_fit : WordRAM.Fits w (b + 2)) (htot : WordRAM.Fits w (totalDoubledWeight W₀)) :
                                                                                            have t := fastCutThreshold k; have childFp := fp + frameSize k; ∃ (m : ProbComp (WordRAM.Data 24 × ℕ)), WordRAM.ExecRand w branchContractAndPush x m ∧ OracleComp.IsQueryBounded m (k - t) ∧ (∀ z ∈ OracleComp.support m, z.2 ≤ 80 * (k * k) ∧ WordRAM.Modifies (Finset.Ico (fp + 4 + k * k) (fp + fastCutScratch k)) x.mem z.1.mem ∧ z.1.regs KSReg.zero = 0 ∧ z.1.regs KSReg.fpReg = childFp ∧ z.1.regs KSReg.spReg = b + 2 ∧ z.1.mem childFp = fp ∧ z.1.mem (childFp + 1) = t ∧ z.1.mem (childFp + 2 + t * t) = 0 ∧ ∃ (W' : Fin t → Fin t → ℕ) (part' : Fin n → Fin t), IsContractionOf W₀ part' W' ∧ HoldsMatrix z.1.mem (childFp + 2) t W') ∧ ∀ (B : Finset (Fin k)), 0 < minCut W₀ → IsNonTrivialCut B → cutWeight W₀ (pullbackCut part B) = minCut W₀ → 1 / 2 ≤ m.eval.toOuterMeasure {z : WordRAM.Data 24 × ℕ | ChildMinCutSurvives W₀ childFp t z.1}
                                                                                            theorem Cslib.Algorithms.WordRAM.Karger.fastCutStep_base_seg {n w fp parentFp b k : ℕ} {W₀ : Fin n → Fin n → ℕ} {W_k : Fin k → Fin k → ℕ} {part : Fin n → Fin k} {x : WordRAM.Data 24} (hk2 : 2 ≤ k) (hk6 : k ≤ 6) (h0 : x.regs KSReg.zero = 0) (hfp : x.regs KSReg.fpReg = fp) (hsp : x.regs KSReg.spReg = b + 1) (hmem_p : x.mem fp = parentFp) (hmem_k : x.mem (fp + 1) = k) (hmat : HoldsMatrix x.mem (fp + 2) k W_k) (hC : IsContractionOf W₀ part W_k) (hfit : WordRAM.Fits w (fp + frameSize k)) (hsp_fit : WordRAM.Fits w b) (htot : WordRAM.Fits w (totalDoubledWeight W₀)) :
                                                                                            theorem Cslib.Algorithms.WordRAM.Karger.fastCutNode_base {n w d fp parentFp b k : ℕ} {W₀ : Fin n → Fin n → ℕ} {W_k : Fin k → Fin k → ℕ} {part : Fin n → Fin k} {x : WordRAM.Data 24} (hk2 : 2 ≤ k) (hk6 : k ≤ 6) (h0 : x.regs KSReg.zero = 0) (hfp : x.regs KSReg.fpReg = fp) (hsp : x.regs KSReg.spReg = b + 1) (hmem_p : x.mem fp = parentFp) (hmem_k : x.mem (fp + 1) = k) (hmat : HoldsMatrix x.mem (fp + 2) k W_k) (hC : IsContractionOf W₀ part W_k) (hfit : WordRAM.Fits w (fp + fastCutScratch k)) (hsp_fit : WordRAM.Fits w (b + 1 + d)) (htot : WordRAM.Fits w (totalDoubledWeight W₀)) :
                                                                                            theorem Cslib.Algorithms.WordRAM.Karger.fastCutStep_stage0_seg {n w fp b k : ℕ} {W₀ : Fin n → Fin n → ℕ} {W_k : Fin k → Fin k → ℕ} {part : Fin n → Fin k} {x : WordRAM.Data 24} (hk7 : 7 ≤ k) (h0 : x.regs KSReg.zero = 0) (hfp : x.regs KSReg.fpReg = fp) (hsp : x.regs KSReg.spReg = b + 1) (hmem_k : x.mem (fp + 1) = k) (hmem_stg : x.mem (fp + 2 + k * k) = 0) (hmat : HoldsMatrix x.mem (fp + 2) k W_k) (hC : IsContractionOf W₀ part W_k) (hfit : WordRAM.Fits w (fp + fastCutScratch k)) (hsp_fit : WordRAM.Fits w (b + 2)) (htot : WordRAM.Fits w (totalDoubledWeight W₀)) :
                                                                                            have t := fastCutThreshold k; have childFp := fp + frameSize k; ∃ (m : ProbComp (WordRAM.Data 24 × ℕ)), WordRAM.LoopSegment w (WordRAM.Cond.lt KSReg.zero KSReg.spReg) fastCutStep x m ∧ OracleComp.IsQueryBounded m (k - t) ∧ (∀ z ∈ OracleComp.support m, z.2 ≤ 80 * (k * k) + 15 ∧ WordRAM.Modifies (Finset.Ico (fp + 2 + k * k) (fp + fastCutScratch k)) x.mem z.1.mem ∧ z.1.mem (fp + 2 + k * k) = 1 ∧ z.1.regs KSReg.zero = 0 ∧ z.1.regs KSReg.fpReg = childFp ∧ z.1.regs KSReg.spReg = b + 2 ∧ z.1.mem childFp = fp ∧ z.1.mem (childFp + 1) = t ∧ z.1.mem (childFp + 2 + t * t) = 0 ∧ ∃ (W' : Fin t → Fin t → ℕ) (part' : Fin n → Fin t), IsContractionOf W₀ part' W' ∧ HoldsMatrix z.1.mem (childFp + 2) t W') ∧ ∀ (B : Finset (Fin k)), 0 < minCut W₀ → IsNonTrivialCut B → cutWeight W₀ (pullbackCut part B) = minCut W₀ → 1 / 2 ≤ m.eval.toOuterMeasure {z : WordRAM.Data 24 × ℕ | ChildMinCutSurvives W₀ childFp t z.1}
                                                                                            theorem Cslib.Algorithms.WordRAM.Karger.fastCutStep_stage1_seg {n w fp b k v1 : ℕ} {W₀ : Fin n → Fin n → ℕ} {W_k : Fin k → Fin k → ℕ} {part : Fin n → Fin k} {x : WordRAM.Data 24} (hk7 : 7 ≤ k) (h0 : x.regs KSReg.zero = 0) (hfp : x.regs KSReg.fpReg = fp) (hsp : x.regs KSReg.spReg = b + 1) (hret : x.regs KSReg.retVal = v1) (hmem_k : x.mem (fp + 1) = k) (hmem_stg : x.mem (fp + 2 + k * k) = 1) (hmat : HoldsMatrix x.mem (fp + 2) k W_k) (hC : IsContractionOf W₀ part W_k) (hfit : WordRAM.Fits w (fp + fastCutScratch k)) (hsp_fit : WordRAM.Fits w (b + 2)) (htot : WordRAM.Fits w (totalDoubledWeight W₀)) :
                                                                                            have t := fastCutThreshold k; have childFp := fp + frameSize k; ∃ (m : ProbComp (WordRAM.Data 24 × ℕ)), WordRAM.LoopSegment w (WordRAM.Cond.lt KSReg.zero KSReg.spReg) fastCutStep x m ∧ OracleComp.IsQueryBounded m (k - t) ∧ (∀ z ∈ OracleComp.support m, z.2 ≤ 80 * (k * k) + 20 ∧ WordRAM.Modifies (Finset.Ico (fp + 2 + k * k) (fp + fastCutScratch k)) x.mem z.1.mem ∧ z.1.mem (fp + 2 + k * k) = 2 ∧ z.1.mem (fp + 3 + k * k) = v1 ∧ z.1.regs KSReg.zero = 0 ∧ z.1.regs KSReg.fpReg = childFp ∧ z.1.regs KSReg.spReg = b + 2 ∧ z.1.mem childFp = fp ∧ z.1.mem (childFp + 1) = t ∧ z.1.mem (childFp + 2 + t * t) = 0 ∧ ∃ (W' : Fin t → Fin t → ℕ) (part' : Fin n → Fin t), IsContractionOf W₀ part' W' ∧ HoldsMatrix z.1.mem (childFp + 2) t W') ∧ ∀ (B : Finset (Fin k)), 0 < minCut W₀ → IsNonTrivialCut B → cutWeight W₀ (pullbackCut part B) = minCut W₀ → 1 / 2 ≤ m.eval.toOuterMeasure {z : WordRAM.Data 24 × ℕ | ChildMinCutSurvives W₀ childFp t z.1}
                                                                                            theorem Cslib.Algorithms.WordRAM.Karger.fastCutStep_stage2_seg {w fp parentFp b k v1 r2 : ℕ} {x : WordRAM.Data 24} (hk7 : 7 ≤ k) (h0 : x.regs KSReg.zero = 0) (hfp : x.regs KSReg.fpReg = fp) (hsp : x.regs KSReg.spReg = b + 1) (hr2 : x.regs KSReg.retVal = r2) (hmem_p : x.mem fp = parentFp) (hmem_k : x.mem (fp + 1) = k) (hmem_stg : x.mem (fp + 2 + k * k) = 2) (hmem_v1 : x.mem (fp + 3 + k * k) = v1) (hfit : WordRAM.Fits w (fp + frameSize k)) (hsp_fit : WordRAM.Fits w b) :
                                                                                            theorem Cslib.Algorithms.WordRAM.Karger.fastCutNode_spec {n w : ℕ} {W₀ : Fin n → Fin n → ℕ} (htot : WordRAM.Fits w (totalDoubledWeight W₀)) (d : ℕ) {fp parentFp b k : ℕ} {W_k : Fin k → Fin k → ℕ} {part : Fin n → Fin k} {x : WordRAM.Data 24} :
                                                                                            2 ≤ k → fastCutDepth k ≤ d → x.regs KSReg.zero = 0 → x.regs KSReg.fpReg = fp → x.regs KSReg.spReg = b + 1 → x.mem fp = parentFp → x.mem (fp + 1) = k → x.mem (fp + 2 + k * k) = 0 → HoldsMatrix x.mem (fp + 2) k W_k → IsContractionOf W₀ part W_k → WordRAM.Fits w (fp + fastCutScratch k) → WordRAM.Fits w (b + 1 + d) → ∃ (m : ProbComp (WordRAM.Data 24 × ℕ)), WordRAM.LoopSegment w (WordRAM.Cond.lt KSReg.zero KSReg.spReg) fastCutStep x m ∧ OracleComp.IsQueryBounded m (fastCutNodeQueries k) ∧ (∀ z ∈ OracleComp.support m, z.2 ≤ fastCutNodeTime k ∧ WordRAM.Modifies (Finset.Ico (fp + 2 + k * k) (fp + fastCutScratch k)) x.mem z.1.mem ∧ z.1.regs KSReg.zero = 0 ∧ z.1.regs KSReg.fpReg = parentFp ∧ z.1.regs KSReg.spReg = b ∧ ∃ (C : Finset (Fin n)), IsNonTrivialCut C ∧ z.1.regs KSReg.retVal = cutWeight W₀ C) ∧ ∀ (B : Finset (Fin k)), 0 < minCut W₀ → IsNonTrivialCut B → cutWeight W₀ (pullbackCut part B) = minCut W₀ → 2 / ↑(d + 30) ≤ m.eval.toOuterMeasure {z : WordRAM.Data 24 × ℕ | z.1.regs KSReg.retVal = minCut W₀}

                                                                                            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

                                                                                                Single FastCut tree execution from srcBase and nOrig, writing retVal and preserving srcBase, nOrig, numTrials, trialIdx, and bestVal.

                                                                                                Instances For
                                                                                                  theorem Cslib.Algorithms.WordRAM.Karger.fastCutTree_spec {n w sb : ℕ} {W : Fin n → Fin n → ℕ} {x : WordRAM.Data 24} (hn : 2 ≤ n) (hW : IsMultigraph W) (hsb : x.regs KSReg.srcBase = sb) (hnOrig : x.regs KSReg.nOrig = n) (hmat : HoldsMatrix x.mem sb n W) (hws_fit : WordRAM.Fits w (sb + 27 * (n * n))) (hsp_fit : WordRAM.Fits w (2 * Nat.log 2 n + 1)) (htot : WordRAM.Fits w (totalDoubledWeight W)) :

                                                                                                  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

                                                                                                          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:

                                                                                                          1. fastCutProgram halts within fastCutTime n = 2500 * n ^ 2 * (Nat.log 2 n + 2) steps;
                                                                                                          2. executes at most fastCutNodeQueries n (≤ 6 * (n * n)) rand calls;
                                                                                                          3. on every supported branch, outputs cutWeight W C ≥ minCut W for a genuine non-trivial cut C of W while modifying memory only in [2 + n * n, 2 + 27 * (n * n));
                                                                                                          4. when 0 < minCut W (excluded only for proof convenience), outputs minCut W with probability at least 1 / (Nat.log 2 n + 15).

                                                                                                          Endpoint 2: Amplified O(n ^ 2 log ^ 3 n) high-probability FastCut (r = 24) #

                                                                                                          Body of ksLogLoop: halve rem via right-shift by 1 and increment idx.

                                                                                                          Instances For

                                                                                                            Loop computing idx = Nat.log 2 n from rem = n (n ≥ 1), idx = 0, one = 1.

                                                                                                            Instances For

                                                                                                              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
                                                                                                                            structure Cslib.Algorithms.WordRAM.Karger.KSAmpInv (sb n R i : ℕ) (W : Fin n → Fin n → ℕ) (mem₀ : ℕ → ℕ) (x : WordRAM.Data 24) :

                                                                                                                            Loop invariant for fastCutAmpLoop at trialIdx = i ≤ R.

                                                                                                                            Instances For
                                                                                                                              theorem Cslib.Algorithms.WordRAM.Karger.ksLogLoop_exec {w n : ℕ} {x : WordRAM.Data 24} (hn : 1 ≤ n) (hone : x.regs KSReg.one = 1) (hrem : x.regs KSReg.rem = n) (hidx : x.regs KSReg.idx = 0) (hnOrig : x.regs KSReg.nOrig = n) (hn_fit : WordRAM.Fits w n) (hlg_fit : WordRAM.Fits w (Nat.log 2 n)) :
                                                                                                                              theorem Cslib.Algorithms.WordRAM.Karger.fastCutAmpBody_spec {w sb n R i : ℕ} {W : Fin n → Fin n → ℕ} {mem₀ : ℕ → ℕ} {x : WordRAM.Data 24} (hn : 2 ≤ n) (hW : IsMultigraph W) (hiR : i < R) (h1 : WordRAM.Fits w 1) (hws_fit : WordRAM.Fits w (sb + 27 * (n * n))) (hsp_fit : WordRAM.Fits w (2 * Nat.log 2 n + 1)) (hR_fit : WordRAM.Fits w R) (htot : WordRAM.Fits w (totalDoubledWeight W)) (hinv : KSAmpInv sb n R i W mem₀ x) :
                                                                                                                              ∃ (m : ProbComp (WordRAM.Data 24 × ℕ)), WordRAM.ExecRand w fastCutAmpBody x m ∧ OracleComp.IsQueryBounded m (6 * (n * n)) ∧ (∀ z ∈ OracleComp.support m, z.2 + 2 ≤ 2500 * n ^ 2 * (Nat.log 2 n + 2) ∧ KSAmpInv sb n R (i + 1) W mem₀ z.1 ∧ (0 < i → x.regs KSReg.bestVal = minCut W → z.1.regs KSReg.bestVal = minCut W)) ∧ (0 < minCut W → m.eval.toOuterMeasure {z : WordRAM.Data 24 × ℕ | z.1.regs KSReg.bestVal ≠ minCut W} ≤ 1 - 1 / ↑(Nat.log 2 n + 15))
                                                                                                                              theorem Cslib.Algorithms.WordRAM.Karger.fastCutAmpLoop_spec {w sb n R : ℕ} {W : Fin n → Fin n → ℕ} {mem₀ : ℕ → ℕ} (hn : 2 ≤ n) (hW : IsMultigraph W) (h1 : WordRAM.Fits w 1) (hws_fit : WordRAM.Fits w (sb + 27 * (n * n))) (hsp_fit : WordRAM.Fits w (2 * Nat.log 2 n + 1)) (hR_fit : WordRAM.Fits w R) (htot : WordRAM.Fits w (totalDoubledWeight W)) (rem i : ℕ) (x : WordRAM.Data 24) :
                                                                                                                              i + rem = R → KSAmpInv sb n R i W mem₀ x → ∃ (m : ProbComp (WordRAM.Data 24 × ℕ)), WordRAM.ExecRand w fastCutAmpLoop x m ∧ OracleComp.IsQueryBounded m (rem * (6 * (n * n))) ∧ (∀ z ∈ OracleComp.support m, z.2 ≤ rem * (2500 * n ^ 2 * (Nat.log 2 n + 2)) + 2 ∧ KSAmpInv sb n R R W mem₀ z.1 ∧ (0 < i → x.regs KSReg.bestVal = minCut W → z.1.regs KSReg.bestVal = minCut W)) ∧ (0 < minCut W → m.eval.toOuterMeasure {z : WordRAM.Data 24 × ℕ | z.1.regs KSReg.bestVal ≠ minCut W} ≤ (1 - 1 / ↑(Nat.log 2 n + 15)) ^ rem)

                                                                                                                              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:

                                                                                                                              1. fastCutHighProbProgram halts within fastCutHighProbTime n = 2600 * n ^ 2 * (Nat.log 2 n + 15) * (Nat.log 2 n + 2) ^ 2 steps;
                                                                                                                              2. executes at most fastCutTrials n * (6 * (n * n)) rand calls;
                                                                                                                              3. on every supported branch, outputs cutWeight W C ≥ minCut W for a genuine non-trivial cut C of W while modifying memory only in [2 + n * n, 2 + 27 * (n * n));
                                                                                                                              4. when 0 < minCut W (excluded only for proof convenience), misses minCut W with probability at most 1 / (2 * n).

                                                                                                                              Corollary of fastCutHighProbProgram_spec: when 0 < minCut W, fastCutHighProbProgram misses minCut W with probability at most 1 / n.