Documentation

CslibFrontier.Algorithms.WordRAM.MaxCut

Deterministic 1/2-approximation for weighted MaxCut on the word RAM #

Implements the method of conditional expectations for weighted multigraph MaxCut on a deterministic Basis.standard word RAM (Cslib.WordRAM.Code .standard 18).

Memory layout and algorithm #

On an n-vertex weighted multigraph edges : List WeightedEdge (m = edges.length) whose endpoints satisfy e.u < n and e.v < n, Data.init (encode n edges) stores:

The scratch array [3 + 3 * m, 3 + 3 * m + n) stores the chosen vertex sides 0 (false) or 1 (true). For each vertex z = 0, …, n - 1 in order, the inner scan walks the m edges and accumulates:

Self-loops (u = v = z) are ignored, and edges with an endpoint > z remain balanced between both sides under conditional expectations. Placing z on the larger-gain side (1 when w0 ≤ w1, 0 when w1 < w0) adds max w0 w1 ≥ (w0 + w1) / 2 to Reg.cutWt, maintaining that twice the cut weight on edges inside {0, …, z - 1} is at least the total non-loop weight inside {0, …, z - 1}.

At z = n, all endpoints lie below n, so maxCutCode halts within maxCutTime n m = n * (20 * m + 15) + 12 (O(|V| |E| + |V|)) instructions with Reg.cutWt holding cutWeight edges side and nonLoopWeight edges ≤ 2 * cutWeight edges side, giving a certified deterministic 1 / 2-approximation against every cut τ : ℕ → Bool.

Main definitions #

Main results #

References #

Input encoding and memory views #

Flat [u, v, weight] word list for a list of weighted edges.

theorem Cslib.Algorithms.WordRAM.MaxCut.getElem_encodeEdges (edges : List Complexity.MaxCut.WeightedEdge) (i : ℕ) (hi : i < edges.length) :
have x := ⋯; have x_1 := ⋯; have x_2 := ⋯; (encodeEdges edges)[3 * i] = edges[i].u ∧ (encodeEdges edges)[3 * i + 1] = edges[i].v ∧ (encodeEdges edges)[3 * i + 2] = edges[i].weight

Full input word list [n, edges.length, u₀, v₀, w₀, ...] for maxCutProgram.

Sufficient upper bound on every constant, vertex/edge counter, memory address and accumulated cut weight computed during maxCutProgram.

theorem Cslib.Algorithms.WordRAM.MaxCut.inputFits_encode {w n : ℕ} {edges : List Complexity.MaxCut.WeightedEdge} (hends : ∀ e ∈ edges, e.u < n ∧ e.v < n) (hw : WordRAM.Fits w (wordBound n edges)) :

Every word of encode n edges and (encode n edges).length fit in width w whenever all endpoints lie below n and Fits w (wordBound n edges).

def Cslib.Algorithms.WordRAM.MaxCut.sideAt (mem : ℕ → ℕ) (base n u : ℕ) :

Cut indicator read from n cells starting at base (true iff u < n and cell base + u contains 1).

Prefix conditional-expectation invariants #

Registers and word-RAM program #

@[reducible, inline]

Output register holding the accumulated cut weight.

Complete structured conditional-expectations MaxCut program.

Compiled flat Program .standard 18 halting with the achieved cut weight in Reg.cutWt.

Instruction budget of maxCutCode on n vertices and m edges (O(n * m + n)).

Correctness and instruction-count proof #

theorem Cslib.Algorithms.WordRAM.MaxCut.maxCutCode_spec {w n : ℕ} (edges : List Complexity.MaxCut.WeightedEdge) (hends : ∀ e ∈ edges, e.u < n ∧ e.v < n) (hw : WordRAM.Fits w (wordBound n edges)) :
∃ (y : WordRAM.Data 18), WordRAM.ExecWithin w maxCutCode (WordRAM.Data.init (encode n edges)) y (maxCutTime n edges.length) ∧ (∀ u < n, y.mem (3 + 3 * edges.length + u) ≤ 1) ∧ y.regs Reg.cutWt = Complexity.MaxCut.cutWeight edges (sideAt y.mem (3 + 3 * edges.length) n) ∧ Lean.MaxCut.nonLoopWeight edges ≤ 2 * Complexity.MaxCut.cutWeight edges (sideAt y.mem (3 + 3 * edges.length) n) ∧ ∀ (τ : ℕ → Bool), Complexity.MaxCut.cutWeight edges τ ≤ 2 * Complexity.MaxCut.cutWeight edges (sideAt y.mem (3 + 3 * edges.length) n)

Structured word-RAM specification of deterministic 1 / 2-approximation MaxCut. When every endpoint in edges is below n and Fits w (wordBound n edges), maxCutCode executes within maxCutTime n edges.length = n * (20 * edges.length + 15) + 12 instructions, writing a boolean cut side = sideAt y.mem (3 + 3 * edges.length) n to [3 + 3 * edges.length, 3 + 3 * edges.length + n) and leaving cutWeight edges side in register Reg.cutWt with nonLoopWeight edges ≤ 2 * cutWeight edges side and cutWeight edges τ ≤ 2 * cutWeight edges side for every cut τ : ℕ → Bool.

theorem Cslib.Algorithms.WordRAM.MaxCut.maxCutProgram_spec {w n : ℕ} (edges : List Complexity.MaxCut.WeightedEdge) (hends : ∀ e ∈ edges, e.u < n ∧ e.v < n) (hw : WordRAM.Fits w (wordBound n edges)) :
∃ (side : ℕ → Bool), ∃ steps ≤ maxCutTime n edges.length + 1, WordRAM.Executes w maxCutProgram (WordRAM.State.init (encode n edges)) (Complexity.MaxCut.cutWeight edges side) steps ∧ Lean.MaxCut.nonLoopWeight edges ≤ 2 * Complexity.MaxCut.cutWeight edges side ∧ ∀ (τ : ℕ → Bool), Complexity.MaxCut.cutWeight edges τ ≤ 2 * Complexity.MaxCut.cutWeight edges side

Compiled word-RAM specification of deterministic 1 / 2-approximation MaxCut. At any word width w with Fits w (wordBound n edges), maxCutProgram halts within maxCutTime n edges.length + 1 instructions from State.init (encode n edges) and outputs the weight cutWeight edges side of an explicit cut side : ℕ → Bool achieving at least half of nonLoopWeight edges and at least half of every cut τ : ℕ → Bool.