Documentation

CslibFrontier.Algorithms.WordRAM.HopcroftKarp.MatrixCSR

Dense and square 0/1-matrix to CSR conversion for word-RAM Hopcroft–Karp #

Converts a row-major m × r 0/1 adjacency matrix in word-RAM memory into exact compressed sparse row (CSR) neighbour arrays (exactBipAdj) and initializes the BaseRegs workspace pointers in O(m + m r) instructions. Shared by dense Hopcroft–Karp (CslibFrontier.Algorithms.WordRAM.HopcroftKarp) and Dilworth minimum chain cover / maximum antichain (CslibFrontier.Algorithms.WordRAM.ChainCover).

Main definitions #

Main results #

Convert a row-major m × r 0/1 adjacency matrix stored starting at matBase into exact CSR arrays starting at bOffReg, then initialize all BaseRegs workspace pointers.

theorem Cslib.Algorithms.WordRAM.HopcroftKarp.exec_buildCSRCode {w m r matBase bOff : ℕ} (G : Fin m × Fin r → Bool) (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 = m) (hrr : x.regs Reg.rr = r) (hbOff : x.regs Reg.bOffReg = bOff) (hmat_le : matBase + m * r ≤ bOff) (hmat : ∀ (u : Fin m) (v : Fin r), x.mem (matBase + (↑u * r + ↑v)) = if G (u, v) = true then 1 else 0) (hfit : WordRAM.Fits w (bOff + 7 * m + 5 * r + m * r + 8)) :
have sInst := { m := m, r := r, adj := Lean.MaxFlow.exactBipAdj G }; ∃ (z : WordRAM.Data 34), WordRAM.ExecWithin w (buildCSRCode matBase) x z (9 * m * r + 8 * m + 25) ∧ BaseRegs sInst bOff z ∧ CSRMem sInst bOff z.mem

Exact O(m + m r) matrix-to-CSR conversion and BaseRegs setup (buildCSRCode).

Read header dimensions (m, and r if isSquare = false else r = m) from input memory, compute bOffReg := matBase + m * r (with matBase = 2 if isSquare else 3), and convert the row-major m × r 0/1 adjacency matrix starting at matBase into exact CSR arrays.

theorem Cslib.Algorithms.WordRAM.HopcroftKarp.exec_matrixSetupCode {w m r : ℕ} (isSquare : Bool) (hsq : isSquare = true → m = r) (G : Fin m × Fin r → Bool) (input : List ℕ) (hm : (WordRAM.Data.init input).mem 1 = m) (hr : isSquare = false → (WordRAM.Data.init input).mem 2 = r) (hmat : ∀ (u : Fin m) (v : Fin r), (WordRAM.Data.init input).mem ((if isSquare = true then 2 else 3) + (↑u * r + ↑v)) = if G (u, v) = true then 1 else 0) (hfit : WordRAM.Fits w ((if isSquare = true then 2 else 3) + m * r + 7 * m + 5 * r + m * r + 8)) :
∃ (y : WordRAM.Data 34), WordRAM.ExecWithin w (matrixSetupCode isSquare) (WordRAM.Data.init input) y (9 * m * r + 8 * m + if isSquare = true then 33 else 35) ∧ BaseRegs { m := m, r := r, adj := Lean.MaxFlow.exactBipAdj G } ((if isSquare = true then 2 else 3) + m * r) y ∧ CSRMem { m := m, r := r, adj := Lean.MaxFlow.exactBipAdj G } ((if isSquare = true then 2 else 3) + m * r) y.mem

Shared header-read and matrix-to-CSR conversion for dense (isSquare = false, header [m, r]) and square poset (isSquare = true, header [n]) encodings.