Documentation

CslibFrontier.Algorithms.WordRAM.Hungarian.InputSteps

Input decoding, cost shifting, and output cost encoding subroutines #

Internal O(n²) / O(n) pre- and post-processing steps (setupCode, scanMaxCode, fillCCode, sumCostCode) around coreCode for Data.init inst.encode.

Read n = mem[1] and set up all constants and array bases starting at baseC = 2 + n * n.

Populate [baseC, baseC + n²) with nonnegative shifted costs.

Compute Signed.encode of the optimal unshifted matching cost into acc.

theorem Cslib.Algorithms.WordRAM.Hungarian.exec_setupCode {w : ℕ} (inst : Instance) (hw : WordRAM.Fits w inst.wordBound) :
∃ (y₁ : WordRAM.Data 28), WordRAM.ExecWithin w setupCode (WordRAM.Data.init inst.encode) y₁ 16 ∧ BaseRegs inst.n (2 + inst.n * inst.n) 0 y₁ ∧ y₁.mem = (WordRAM.Data.init inst.encode).mem
theorem Cslib.Algorithms.WordRAM.Hungarian.exec_scanMaxCode {w : ℕ} (inst : Instance) (hw : WordRAM.Fits w inst.wordBound) (y₁ : WordRAM.Data 28) (hb₁ : BaseRegs inst.n (2 + inst.n * inst.n) 0 y₁) (hmem₁ : y₁.mem = (WordRAM.Data.init inst.encode).mem) :
∃ (y₂ : WordRAM.Data 28), WordRAM.ExecWithin w scanMaxCode y₁ y₂ (9 * inst.n * inst.n + 4) ∧ BaseRegs inst.n (2 + inst.n * inst.n) (y₂.regs Reg.rM) y₂ ∧ y₂.mem = (WordRAM.Data.init inst.encode).mem ∧ y₂.regs Reg.rM ≤ inst.maxMag ∧ ∀ (u v : Fin inst.n), (inst.cost (u, v)).natAbs ≤ y₂.regs Reg.rM
theorem Cslib.Algorithms.WordRAM.Hungarian.exec_fillCCode {w M : ℕ} (inst : Instance) (hw : WordRAM.Fits w inst.wordBound) (hM_le : M ≤ inst.maxMag) (hM_ge : ∀ (u v : Fin inst.n), (inst.cost (u, v)).natAbs ≤ M) (y₂ : WordRAM.Data 28) (hb₂ : BaseRegs inst.n (2 + inst.n * inst.n) M y₂) (hmem₂ : y₂.mem = (WordRAM.Data.init inst.encode).mem) :
∃ (y₃ : WordRAM.Data 28), WordRAM.ExecWithin w fillCCode y₂ y₃ (12 * inst.n * inst.n + 3) ∧ BaseRegs inst.n (2 + inst.n * inst.n) M y₃ ∧ CostMem (2 + inst.n * inst.n) (fun (p : Fin inst.n × Fin inst.n) => (inst.cost p + ↑M).toNat) y₃.mem
theorem Cslib.Algorithms.WordRAM.Hungarian.exec_sumCostCode {w M : ℕ} (inst : Instance) (hw : WordRAM.Fits w inst.wordBound) (hM_le : M ≤ inst.maxMag) (hC_cast : ∀ (p : Fin inst.n × Fin inst.n), ↑(inst.cost p + ↑M).toNat = inst.cost p + ↑M) (hC_le : ∀ (u v : Fin inst.n), (inst.cost (u, v) + ↑M).toNat ≤ 2 * M) (y₄ : WordRAM.Data 28) (hb₄ : BaseRegs inst.n (2 + inst.n * inst.n) M y₄) (hC₄ : CostMem (2 + inst.n * inst.n) (fun (p : Fin inst.n × Fin inst.n) => (inst.cost p + ↑M).toNat) y₄.mem) (hrm_eq : ∀ (u : Fin inst.n), y₄.mem (2 + inst.n * inst.n + inst.n * inst.n + 7 * inst.n + 1 + ↑u) = ↑(inst.assignedCol u)) :
∃ (y₆ : WordRAM.Data 28), WordRAM.ExecWithin w sumCostCode y₄ y₆ (10 * inst.n + 10) ∧ BaseRegs inst.n (2 + inst.n * inst.n) M y₆ ∧ y₆.mem = y₄.mem ∧ y₆.regs Reg.acc = inst.encodedMinCost