Documentation

CslibFrontier.Algorithms.WordRAM.Hungarian.Core

In-memory O(n³) Hungarian solver (coreCode and core_exec) #

Assembles alternating-tree phases into coreCode and proves its O(n³) Word-RAM execution bound core_exec on an unsigned/shifted row-major cost matrix.

Instruction bound for coreCode (O(n³)).

Core O(n³) Hungarian solver on an in-memory n × n unsigned cost matrix C at baseC: initializes row potentials y, column potentials nz, and mates, runs n augmenting phases, and writes length n at outBase.

theorem Cslib.Algorithms.WordRAM.Hungarian.core_exec {w n bC M W : ℕ} {C : Fin n × Fin n → ℕ} (hCW : ∀ (u v : Fin n), C (u, v) ≤ W) (x : WordRAM.Data 28) (hb : BaseRegs n bC M x) (hC : CostMem bC C x.mem) (hfit : WordRAM.Fits w (bC + n * n + 8 * n + 2 * W + 2)) :
have c := fun (p : Fin n × Fin n) => ↑(C p); have out := Lean.MaxFlow.hungarian c; ∃ (y : WordRAM.Data 28), WordRAM.ExecWithin w coreCode x y (coreTime n) ∧ (∀ (i : Fin 28), ↑i < 16 → y.regs i = x.regs i) ∧ (∀ (u : Fin n), ↑(y.mem (bC + n * n + ↑u)) = out.y u) ∧ (∀ (v : Fin n), -↑(y.mem (bC + n * n + n + ↑v)) = out.z v) ∧ y.mem (bC + n * n + 7 * n) = n ∧ (∀ (u : Fin n), ∃ (v : Fin n), y.mem (bC + n * n + 7 * n + 1 + ↑u) = ↑v ∧ (u, v) ∈ out.matching) ∧ ∀ (a : ℕ), a < bC + n * n ∨ bC + n * n + 8 * n + 1 ≤ a → y.mem a = x.mem a

O(n³) Word-RAM execution on an in-memory unsigned/shifted cost matrix. Given BaseRegs and CostMem for an n × n matrix C : Fin n × Fin n → ℕ bounded by W at bC, coreCode halts within coreTime n = O(n³) instructions at every word width satisfying Fits w (bC + n * n + 8 * n + 2 * W + 2), leaving (hungarian fun p => (C p : ℤ))'s potentials and perfect matching in memory.