Documentation

CslibFrontier.Algorithms.WordRAM.HopcroftKarp.Internal

Internal workspace predicates and setup helpers for word-RAM Hopcroft–Karp #

Scratch registers (19 .. 33), value encodings (encodeOptFin, encodeDist), in-memory matching/distance predicates (MateMem, DistMem), and shared subroutines (clearAt, initBaseRegsFromCSR) used privately by the HopcroftKarp sub-modules (BFS, DFSStep, DFS, MatrixCSR, and HopcroftKarp). This module is imported privately by the umbrella module CslibFrontier.Algorithms.WordRAM.HopcroftKarp so its declarations do not leak into the public surface.

@[reducible, inline]

Scratch register 19: outer phase-loop active flag.

@[reducible, inline]

Scratch register 20: current augmenting-path layer depth k.

@[reducible, inline]

Scratch register 21: flag set when BFS reaches an unmatched right vertex.

@[reducible, inline]

Scratch register 22: BFS queue head cursor / DFS root scan cursor.

@[reducible, inline]

Scratch register 23: BFS queue tail index.

@[reducible, inline]

Scratch register 24: end index of the current BFS layer in the queue.

@[reducible, inline]

Scratch register 25: current BFS distance / explicit DFS stack depth.

@[reducible, inline]

Scratch register 26: number of disjoint augmenting paths collected in the phase.

@[reducible, inline]

Scratch register 27 (Reg.acc): inner loop-active flag for bfsCode and dfsLoop.

@[reducible, inline]

Scratch register 28: general loop and CSR edge index.

@[reducible, inline]

Scratch register 29: general loop upper-bound register.

@[reducible, inline]

Scratch register 30: scratch memory-address register.

@[reducible, inline]

Scratch register 31: primary scratch value register.

@[reducible, inline]

Scratch register 32: secondary scratch value register.

@[reducible, inline]

Scratch register 33: general temporary scratch value register.

Encode Option (Fin m) into {0, …, m} with none ↦ m.

Encode Option ℕ layer distances with none ↦ 0 and some j ↦ j + 1.

def Cslib.Algorithms.WordRAM.HopcroftKarp.Internal.MateMem (inst : SparseInstance) (bOff : ℕ) (mate : Vector (Option (Fin inst.m)) inst.r) (mem : ℕ → ℕ) :

In-memory right-vertex mate table colMate[0..r) starting at bOff + m + 1 + numEdges.

theorem Cslib.Algorithms.WordRAM.HopcroftKarp.Internal.MateMem.of_outside {inst : SparseInstance} {bOff : ℕ} {mate : Vector (Option (Fin inst.m)) inst.r} {mem mem' : ℕ → ℕ} (h : MateMem inst bOff mate mem) (hf : ∀ (a : ℕ), bOff + inst.m + 1 + inst.numEdges ≤ a ∧ a < bOff + inst.m + 1 + inst.numEdges + inst.r → mem' a = mem a) :
MateMem inst bOff mate mem'

In-memory left-vertex layer-distance table dist[0..m) starting at bDist.

theorem Cslib.Algorithms.WordRAM.HopcroftKarp.Internal.DistMem.of_outside {inst : SparseInstance} {bOff : ℕ} {dist : Vector (Option ℕ) inst.m} {mem mem' : ℕ → ℕ} (h : DistMem inst bOff dist mem) (hf : ∀ (a : ℕ), bOff + inst.m + 1 + inst.numEdges + inst.r + inst.m ≤ a ∧ a < bOff + inst.m + 1 + inst.numEdges + inst.r + 2 * inst.m → mem' a = mem a) :
DistMem inst bOff dist mem'
theorem Cslib.Algorithms.WordRAM.HopcroftKarp.Internal.DistMem.vset {inst : SparseInstance} {bOff : ℕ} {dist : Vector (Option ℕ) inst.m} {mem mem' : ℕ → ℕ} (h : DistMem inst bOff dist mem) (u : Fin inst.m) (d : Option ℕ) (hself : mem' (bOff + inst.m + 1 + inst.numEdges + inst.r + inst.m + ↑u) = encodeDist d) (hother : ∀ (w₀ : Fin inst.m), w₀ ≠ u → mem' (bOff + inst.m + 1 + inst.numEdges + inst.r + inst.m + ↑w₀) = mem (bOff + inst.m + 1 + inst.numEdges + inst.r + inst.m + ↑w₀)) :
DistMem inst bOff (Lean.MaxFlow.vset dist u d) mem'

Zero-fill [x.regs baseReg, x.regs baseReg + x.regs lenReg) via Cslib.WordRAM.zeroFill.

theorem Cslib.Algorithms.WordRAM.HopcroftKarp.Internal.exec_clearAt {w base len : ℕ} (baseReg lenReg : Fin 34) (hb_lt : ↑baseReg < 29) (hl_lt : ↑lenReg < 29) (x : WordRAM.Data 34) (h0 : x.regs Reg.zero = 0) (h1 : x.regs Reg.one = 1) (hbase : x.regs baseReg = base) (hlen : x.regs lenReg = len) (hfit : WordRAM.Fits w (base + len)) :
∃ (y : WordRAM.Data 34), WordRAM.ExecWithin w (clearAt baseReg lenReg) x y (4 * len + 4) ∧ (∀ (i : Fin 34), ↑i < 29 → y.regs i = x.regs i) ∧ (∀ k < len, y.mem (base + k) = 0) ∧ ∀ (a : ℕ), ¬(base ≤ a ∧ a < base + len) → y.mem a = x.mem a

Populate bEdgesReg .. outBase from zero, one, two, rm, rr, rE, bOffReg.

theorem Cslib.Algorithms.WordRAM.HopcroftKarp.Internal.exec_initBaseRegsFromCSR {w bOff : ℕ} (inst : SparseInstance) (x : WordRAM.Data 34) (h0 : x.regs Reg.zero = 0) (h1 : x.regs Reg.one = 1) (h2 : x.regs Reg.two = 2) (hrm : x.regs Reg.rm = inst.m) (hrr : x.regs Reg.rr = inst.r) (hrE : x.regs Reg.rE = inst.numEdges) (hbOff : x.regs Reg.bOffReg = bOff) (hfit : WordRAM.Fits w (bOff + 7 * inst.m + 5 * inst.r + inst.numEdges + 8)) :
∃ (y : WordRAM.Data 34), WordRAM.ExecWithin w initBaseRegsFromCSR x y 16 ∧ BaseRegs inst bOff y ∧ y.mem = x.mem