Documentation

CslibFrontier.Algorithms.WordRAM.Hungarian.MemLayout

Internal scratch registers, phase memory invariants, and loop helpers #

Internal support module for the O(n³) Word-RAM Hungarian implementation, providing scratch register indices, OuterMem, StepMem, reduced-cost arithmetic, and fillConst / exec_forLoop.

@[reducible, inline]

Current phase root row r.

@[reducible, inline]

Phase termination flag (0 while growing the tree, 1 once augmented).

@[reducible, inline]

Chosen minimum-slack unused column j₁.

@[reducible, inline]

Minimum slack δ = minv[j₁].

@[reducible, inline]

Matched row i₀ = colMate[j₁].

@[reducible, inline]

Primary loop index.

@[reducible, inline]

Secondary loop index / augmenting-path column cursor.

@[reducible, inline]

Scratch address register.

@[reducible, inline]

Scratch value register 1.

@[reducible, inline]

Scratch value register 2.

@[reducible, inline]

Scratch temporary register.

theorem Cslib.Algorithms.WordRAM.Hungarian.BaseRegs.of_eq {n bC M : ℕ} {x y : WordRAM.Data 28} (h : BaseRegs n bC M x) (heq : ∀ (i : Fin 28), ↑i < 16 → y.regs i = x.regs i) :
BaseRegs n bC M y
theorem Cslib.Algorithms.WordRAM.Hungarian.CostMem.of_outside {n bC : ℕ} {C : Fin n × Fin n → ℕ} {m₁ m₂ : ℕ → ℕ} (h : CostMem bC C m₁) (hout : ∀ a < bC + n * n, m₂ a = m₁ a) :
CostMem bC C m₂

Encode Option (Fin n) as n for none and i.val for some i.

structure Cslib.Algorithms.WordRAM.Hungarian.OuterMem {n : ℕ} (bC : ℕ) (y z : Vector ℤ n) (mate : Vector (Option (Fin n)) n) (mem : ℕ → ℕ) :

Between-phase memory representation of (y, z, mate) at layout bC.

structure Cslib.Algorithms.WordRAM.Hungarian.StepMem {n : ℕ} (bC : ℕ) (s : Lean.MaxFlow.HgState n) (bestRow : Fin n → Fin n) (mem : ℕ → ℕ) extends Cslib.Algorithms.WordRAM.Hungarian.OuterMem bC s.y s.z s.mate mem :

Within-phase memory representation of (s, bestRow) at layout bC.

theorem Cslib.Algorithms.WordRAM.Hungarian.hgRed_nat_eq {n W : ℕ} {C : Fin n × Fin n → ℕ} {y z : Vector ℤ n} {i j : Fin n} (hCW : C (i, j) ≤ W) (hy : 0 ≤ Lean.MaxFlow.vget y i ∧ Lean.MaxFlow.vget y i ≤ ↑W) (hz : -↑W ≤ Lean.MaxFlow.vget z j ∧ Lean.MaxFlow.vget z j ≤ 0) (hfeas : 0 ≤ Lean.MaxFlow.hgRed (fun (p : Fin n × Fin n) => ↑(C p)) y z i j) :
(Lean.MaxFlow.vget y i).toNat ≤ C (i, j) + (-Lean.MaxFlow.vget z j).toNat ∧ C (i, j) + (-Lean.MaxFlow.vget z j).toNat ≤ 2 * W ∧ C (i, j) + (-Lean.MaxFlow.vget z j).toNat - (Lean.MaxFlow.vget y i).toNat = (Lean.MaxFlow.hgRed (fun (p : Fin n × Fin n) => ↑(C p)) y z i j).toNat
theorem Cslib.Algorithms.WordRAM.Hungarian.exec_forLoop {w N T : ℕ} {idxReg limReg : Fin 28} {body : WordRAM.Code WordRAM.Basis.standard 28} (P : ℕ → WordRAM.Data 28 → Prop) (hlim : ∀ (y : WordRAM.Data 28), P (y.regs idxReg) y → y.regs limReg = N) (hbody : ∀ (y : WordRAM.Data 28), P (y.regs idxReg) y → y.regs idxReg < N → ∃ (z : WordRAM.Data 28), WordRAM.ExecWithin w body y z T ∧ P (y.regs idxReg + 1) z ∧ z.regs idxReg = y.regs idxReg + 1) {x : WordRAM.Data 28} (h0 : P 0 (x.set idxReg 0)) :
∃ (y : WordRAM.Data 28), WordRAM.ExecWithin w ((WordRAM.Code.op (WordRAM.Op.const idxReg 0)).seq (WordRAM.Code.loop (WordRAM.Cond.lt idxReg limReg) body)) x y (N * (T + 2) + 3) ∧ P N y

Reusable leaf loops #

@[reducible, inline]

Fill [dst, dst + n) with valReg.

theorem Cslib.Algorithms.WordRAM.Hungarian.exec_fillConst {w n bC M : ℕ} (dst valReg : Fin 28) (hd_lt : ↑dst < 21) (hv_lt : ↑valReg < 21) (x : WordRAM.Data 28) (hb : BaseRegs n bC M x) (hdst : x.regs dst + n ≤ bC + n * n + 8 * n + 1) (hfit : WordRAM.Fits w (bC + n * n + 8 * n + 2)) :
∃ (y : WordRAM.Data 28), WordRAM.ExecWithin w (fillConst dst valReg) x y (5 * n + 3) ∧ (∀ (i : Fin 28), ↑i < 21 → y.regs i = x.regs i) ∧ (∀ k < n, y.mem (x.regs dst + k) = x.regs valReg) ∧ ∀ (a : ℕ), ¬(x.regs dst ≤ a ∧ a < x.regs dst + n) → y.mem a = x.mem a