Documentation

CslibFrontier.Algorithms.Lean.Karger.Memory

The contraction structure over memory #

The contraction structure Karger.spec is implemented over the memory oracle Memory.spec w by the programs of Karger.Memory.Layout (size, total, pairAt) and Karger.Memory.Contract (contract), on the layout of a Layout. This file assembles them into a refinement.

Each obligation comes from one weakest-precondition lemma per operation (wp_methods), through StateTransitionSpec.wp_iff. Nothing here mentions a register or an instruction.

Karger's algorithm over memory (kargerProg) is the client karger linked through the refinement with its coins passed through (hop, which is refinement.toRandomized.withCoins). Every law proved on the specification transfers through RandomizedRefinement.run_link (map_run_kargerProg): the success probability 2 / (n (n - 1)) and the one-sided error. The costs transfer through Refinement.Amortized.toRandomized and RandomizedRefinement.ExpectedAmortized.withCoins: the expected memory cost, counting a unit per coin, is at most (n - 2) (1 + 4 (7 C + 7)) + 2 (7 C + 7) at capacity C (expectedCost_kargerProg_le), which is O(n²) when the layout is sized to the input (exists_expectedCost_kargerProg_isBigO).

Main definitions #

Main results #

References #

The operations of the contraction structure as memory programs.

The memory charge of each operation on a graph of k supervertices: one unit for the size and the total, 2 k + 1 for the sampling query, and 7 k + 7 for a contraction.

theorem Cslib.Algorithms.Lean.Karger.Memory.wp_methods {L : Layout} {w : ℕ} {s : DataStructure.Memory.State} (hs : Inv L w s) (o : Op) (hv : spec.valid (abs L s) o) :
(DataStructure.Memory.spec w).wp DataStructure.Memory.charge (methods L w o) (fun (a : spec.Result o) (s' : (DataStructure.Memory.spec w).State) (t : ℕ) => spec.stepFn (abs L s) o = (abs L s', a) ∧ Inv L w s' ∧ t ≤ opCharge (abs L s) o ∧ s'.frontier = s.frontier ∧ ∀ b ∉ L.footprint, s'.mem b = s.mem b) s

Every operation over memory. From a state satisfying the invariant, each admissible operation answers and steps as the specification, preserves the invariant, costs at most opCharge, keeps the frontier and changes no cell outside the layout.

The contraction structure over memory.

Cost. Each operation costs at most opCharge memory units, with no potential.

At most capacity supervertices, every operation costs at most 7 capacity + 7 memory units.

The framed implementation. The refinement, with the layout's region as its footprint.

The framed implementation has the same costs.

Karger's algorithm over memory #

@[reducible, inline]

The distributional hop: the memory implementation, with coins passed through.

Karger's algorithm over memory: karger, with every call of the contraction structure replaced by its memory program.

The law transfers. From a memory state satisfying the invariant, the law of Karger's algorithm over memory, read through the abstraction, is the law of karger on the specification, provided karger is admissible there.

theorem Cslib.Algorithms.Lean.Karger.Memory.two_div_le_toOuterMeasure_kargerProg {L : Layout} {w : ℕ} {e : DataStructure.Memory.State} (he : Inv L w e) {n : ℕ} {W₀ : Fin n → Fin n → ℕ} (habs : abs L e = { size := n, weight := W₀ }) (hn : 2 ≤ n) (hW₀ : WeightedCut.IsMultigraph W₀) (hmin : 0 < WeightedCut.minCut W₀) :

Karger's theorem over memory. From a memory state holding a connected multigraph on n ≥ 2 vertices, Karger's algorithm over memory answers the minimum cut weight with probability at least 2 / (n (n - 1)).

theorem Cslib.Algorithms.Lean.Karger.Memory.minCut_le_of_mem_support_kargerProg {L : Layout} {w : ℕ} {e : DataStructure.Memory.State} (he : Inv L w e) {n : ℕ} {W₀ : Fin n → Fin n → ℕ} (habs : abs L e = { size := n, weight := W₀ }) (hn : 2 ≤ n) (hW₀ : WeightedCut.IsMultigraph W₀) {x : ℕ × DataStructure.Memory.State} (hx : x ∈ ((DataStructure.Memory.spec w).toRandomized.withCoins.run (kargerProg L w) e).support) :

One-sided error over memory. Every answer of Karger's algorithm over memory, from a memory state holding a multigraph on n ≥ 2 vertices, is at least the minimum cut weight.

Cost #

theorem Cslib.Algorithms.Lean.Karger.Memory.expectedCost_withCoins_query_bind {D : DataStructure.StateTransitionSpec} {f : D.State → (o : D.Op) → D.State × D.Result o} [D.HasStepFn f] {β : Type} (coin : ℕ → ℕ) (c : D.State → D.Op → ℕ) (o : D.Op) (k : D.Result o → ProbOracleComp D.Result β) (s : D.State) :

Over a deterministic specification with coins, a call charges its cost, then continues with its answer from the next state.

theorem Cslib.Algorithms.Lean.Karger.Memory.expectedCost_karger_le {n : ℕ} (W : Fin n → Fin n → ℕ) (K : ℕ) :
spec.toRandomized.withCoins.expectedCost (spec.toRandomized.coinCharge (fun (x : ℕ) => 1) fun (x : spec.toRandomized.State) (x_1 : spec.toRandomized.Op) => K) karger { size := n, weight := W } ≤ ↑((n - 2) * (1 + 4 * K) + 2 * K)

Expected calls of karger on the specification. From a graph on n vertices, at one unit per coin and K per call of the structure, karger costs at most (n - 2) (1 + 4 K) + 2 K in expectation.

theorem Cslib.Algorithms.Lean.Karger.Memory.expectedCost_kargerProg_le {L : Layout} {w : ℕ} {e : DataStructure.Memory.State} (he : Inv L w e) {n : ℕ} {W₀ : Fin n → Fin n → ℕ} (habs : abs L e = { size := n, weight := W₀ }) (hn : 2 ≤ n) (hW₀ : WeightedCut.IsMultigraph W₀) :

Expected memory cost of Karger's algorithm. From a memory state holding a multigraph on n ≥ 2 vertices at capacity C, Karger's algorithm over memory costs at most (n - 2) (1 + 4 (7 C + 7)) + 2 (7 C + 7) memory units in expectation, counting one unit per coin.

theorem Cslib.Algorithms.Lean.Karger.Memory.expectedCoins_kargerProg_le {L : Layout} {w : ℕ} {e : DataStructure.Memory.State} (he : Inv L w e) {n : ℕ} {W₀ : Fin n → Fin n → ℕ} (habs : abs L e = { size := n, weight := W₀ }) (hn : 2 ≤ n) (hW₀ : WeightedCut.IsMultigraph W₀) :

Expected coins of Karger's algorithm over memory. It draws at most n - 2 coins in expectation.

theorem Cslib.Algorithms.Lean.Karger.Memory.exists_expectedCost_kargerProg_isBigO :
∃ (F : ℕ → ℕ), CostIsBigO Filter.atTop (fun (n : ℕ) => ↑n ^ 2) id F ∧ ∀ {L : Layout} {w : ℕ} {e : DataStructure.Memory.State} {n : ℕ} {W₀ : Fin n → Fin n → ℕ}, Inv L w e → abs L e = { size := n, weight := W₀ } → L.capacity = n → 2 ≤ n → WeightedCut.IsMultigraph W₀ → (DataStructure.Memory.spec w).toRandomized.withCoins.expectedCost ((DataStructure.Memory.spec w).toRandomized.coinCharge (fun (x : ℕ) => 1) DataStructure.Memory.charge) (kargerProg L w) e ≤ ↑(F n)

The exported cost. With the layout sized to the input, the expected memory cost of Karger's algorithm over memory on n vertices is at most F n for some F that is O(n²).