Documentation

CslibFrontier.Foundations.LinearAlgebra.Matrix.LinearProgramming

Linear-programming duality over linearly ordered fields #

For a matrix A : Matrix ι κ K, a right-hand side b and an objective c over a linearly ordered field K, the primal linear program in inequality form maximizes c ⬝ᵥ x subject to A *ᵥ x ≤ b. Its dual minimizes y ⬝ᵥ b subject to 0 ≤ y and y ᵥ* A = c. The proofs use Fourier–Motzkin elimination (Matrix.FourierMotzkin.exists_projection) and Farkas' lemma (Matrix.not_exists_mulVec_le_iff), so they hold over every linearly ordered field, including ℚ. See also [DK24] for an independent Lean 4 formalization of linear-programming duality over linearly ordered fields. The closed leanprover-community/mathlib4 pull requests 7386, 9693, 10026 and 10159 (opened 2023–24) take other approaches to linear programming; nothing here is copied from them or from [DK24].

Main results #

References #

theorem Matrix.dotProduct_le_dotProduct_add_parts_of_mulVec_le {ι : Type u_1} {κ : Type u_2} [Fintype ι] [Fintype κ] {K : Type u_3} [CommRing K] [LinearOrder K] [IsStrictOrderedRing K] {A : Matrix ι κ K} {b : ι → K} {c x l u : κ → K} {y : ι → K} (hx : A.mulVec x ≤ b) (hy : 0 ≤ y) (hl : ∀ (j : κ), (c - vecMul y A) j < 0 → l j ≤ x j) (hu : ∀ (j : κ), 0 < (c - vecMul y A) j → x j ≤ u j) :
c ⬝ᵥ x ≤ y ⬝ᵥ b + ((c - vecMul y A)⁺ ⬝ᵥ u - (c - vecMul y A)⁻ ⬝ᵥ l)

Residual-corrected weak duality. For the residual d = c - y ᵥ* A, only the upper bound on a variable with positive residual and the lower bound on a variable with negative residual are needed. This is the exact-coefficient step towards interval LP bounds (#6981).

theorem Matrix.dotProduct_le_dotProduct_add_max_of_mulVec_le {ι : Type u_1} {κ : Type u_2} [Fintype ι] [Fintype κ] {K : Type u_3} [CommRing K] [LinearOrder K] [IsStrictOrderedRing K] {A : Matrix ι κ K} {b : ι → K} {c x l u : κ → K} {y : ι → K} (hx : A.mulVec x ≤ b) (hy : 0 ≤ y) (hl : l ≤ x) (hu : x ≤ u) :
c ⬝ᵥ x ≤ y ⬝ᵥ b + ∑ j : κ, max ((c - vecMul y A) j * l j) ((c - vecMul y A) j * u j)

With two-sided variable bounds, the residual correction can equivalently be written as the sum of the worse endpoint products. The vector y need not be dual feasible.

theorem Matrix.dotProduct_le_dotProduct_of_mulVec_le {ι : Type u_1} {κ : Type u_2} [Fintype ι] [Fintype κ] {K : Type u_3} [Field K] [LinearOrder K] [IsStrictOrderedRing K] {A : Matrix ι κ K} {b : ι → K} {c x : κ → K} {y : ι → K} (hx : A.mulVec x ≤ b) (hy : 0 ≤ y) (hyA : vecMul y A = c) :
c ⬝ᵥ x ≤ y ⬝ᵥ b

Weak duality: the value of a primal solution A *ᵥ x ≤ b is at most the value of any dual solution 0 ≤ y, y ᵥ* A = c [Schrijver1986, Section 7.4].

theorem Matrix.exists_dual_eq_of_bddAbove {ι : Type u_1} {κ : Type u_2} [Fintype ι] [Fintype κ] {K : Type u_3} [Field K] [LinearOrder K] [IsStrictOrderedRing K] (A : Matrix ι κ K) (b : ι → K) (c : κ → K) (hP : ∃ (x : κ → K), A.mulVec x ≤ b) (hbdd : BddAbove ((fun (x : κ → K) => c ⬝ᵥ x) '' {x : κ → K | A.mulVec x ≤ b})) :
∃ (x : κ → K) (y : ι → K), A.mulVec x ≤ b ∧ 0 ≤ y ∧ vecMul y A = c ∧ y ⬝ᵥ b = c ⬝ᵥ x

A linear objective bounded above on a nonempty polyhedron A *ᵥ x ≤ b attains its maximum at a point x, certified by a dual solution y of the same value [Schrijver1986, Section 7.4].

theorem Matrix.exists_isGreatest_of_bddAbove {ι : Type u_1} {κ : Type u_2} [Fintype κ] {K : Type u_3} [Field K] [LinearOrder K] [IsStrictOrderedRing K] [Finite ι] (A : Matrix ι κ K) (b : ι → K) (c : κ → K) (hP : ∃ (x : κ → K), A.mulVec x ≤ b) (hbdd : BddAbove ((fun (x : κ → K) => c ⬝ᵥ x) '' {x : κ → K | A.mulVec x ≤ b})) :
∃ (x : κ → K), A.mulVec x ≤ b ∧ IsGreatest ((fun (x : κ → K) => c ⬝ᵥ x) '' {x : κ → K | A.mulVec x ≤ b}) (c ⬝ᵥ x)

A linear objective bounded above on a nonempty polyhedron attains its supremum [Schrijver1986, Section 7.4].

theorem Matrix.exists_isGreatest_isLeast_dotProduct {ι : Type u_1} {κ : Type u_2} [Fintype ι] [Fintype κ] {K : Type u_3} [Field K] [LinearOrder K] [IsStrictOrderedRing K] (A : Matrix ι κ K) (b : ι → K) (c : κ → K) (hP : ∃ (x : κ → K), A.mulVec x ≤ b) (hD : ∃ (y : ι → K), 0 ≤ y ∧ vecMul y A = c) :
∃ (v : K), IsGreatest ((fun (x : κ → K) => c ⬝ᵥ x) '' {x : κ → K | A.mulVec x ≤ b}) v ∧ IsLeast ((fun (x : ι → K) => x ⬝ᵥ b) '' {y : ι → K | 0 ≤ y ∧ vecMul y A = c}) v

Strong duality: if the primal max {c ⬝ᵥ x | A *ᵥ x ≤ b} and the dual min {y ⬝ᵥ b | 0 ≤ y, y ᵥ* A = c} are both feasible, then both optima are attained and equal [Schrijver1986, Corollary 7.1g].

theorem Matrix.bddAbove_image_dotProduct_iff {ι : Type u_1} {κ : Type u_2} [Fintype ι] [Fintype κ] {K : Type u_3} [Field K] [LinearOrder K] [IsStrictOrderedRing K] (A : Matrix ι κ K) (b : ι → K) (c : κ → K) (hP : ∃ (x : κ → K), A.mulVec x ≤ b) :
BddAbove ((fun (x : κ → K) => c ⬝ᵥ x) '' {x : κ → K | A.mulVec x ≤ b}) ↔ ∃ (y : ι → K), 0 ≤ y ∧ vecMul y A = c

A feasible primal program is bounded above iff its dual is feasible. In particular a feasible primal program with infeasible dual is unbounded [Schrijver1986, Section 7.4].

theorem Matrix.bddBelow_image_dotProduct_iff {ι : Type u_1} {κ : Type u_2} [Fintype ι] [Fintype κ] {K : Type u_3} [Field K] [LinearOrder K] [IsStrictOrderedRing K] (A : Matrix ι κ K) (b : ι → K) (c : κ → K) (hD : ∃ (y : ι → K), 0 ≤ y ∧ vecMul y A = c) :
BddBelow ((fun (x : ι → K) => x ⬝ᵥ b) '' {y : ι → K | 0 ≤ y ∧ vecMul y A = c}) ↔ ∃ (x : κ → K), A.mulVec x ≤ b

A feasible dual program is bounded below iff the primal is feasible. In particular a feasible dual program with infeasible primal is unbounded [Schrijver1986, Section 7.4].

theorem Matrix.exists_isLeast_of_bddBelow {ι : Type u_1} {κ : Type u_2} [Fintype ι] {K : Type u_3} [Field K] [LinearOrder K] [IsStrictOrderedRing K] [Finite κ] (A : Matrix ι κ K) (b : ι → K) (c : κ → K) (hD : ∃ (y : ι → K), 0 ≤ y ∧ vecMul y A = c) (hbdd : BddBelow ((fun (x : ι → K) => x ⬝ᵥ b) '' {y : ι → K | 0 ≤ y ∧ vecMul y A = c})) :
∃ (v : K), IsLeast ((fun (x : ι → K) => x ⬝ᵥ b) '' {y : ι → K | 0 ≤ y ∧ vecMul y A = c}) v

A dual objective bounded below on a nonempty dual polyhedron attains its infimum [Schrijver1986, Section 7.4].

theorem Matrix.dotProduct_eq_dotProduct_iff_of_mulVec_le {ι : Type u_1} {κ : Type u_2} [Fintype ι] [Fintype κ] {K : Type u_3} [Field K] [LinearOrder K] [IsStrictOrderedRing K] {A : Matrix ι κ K} {b : ι → K} {c x : κ → K} {y : ι → K} (hx : A.mulVec x ≤ b) (hy : 0 ≤ y) (hyA : vecMul y A = c) :
c ⬝ᵥ x = y ⬝ᵥ b ↔ ∀ (i : ι), y i = 0 ∨ A.mulVec x i = b i

Complementary slackness: a primal solution x and a dual solution y have equal values iff every constraint i with y i ≠ 0 is tight at x [Schrijver1986, Section 7.9].

theorem Matrix.exists_dual_le_of_forall_le {ι : Type u_1} {κ : Type u_2} [Fintype ι] [Fintype κ] {K : Type u_3} [Field K] [LinearOrder K] [IsStrictOrderedRing K] (A : Matrix ι κ K) (b : ι → K) (c : κ → K) (δ : K) (hP : ∃ (x : κ → K), A.mulVec x ≤ b) (h : ∀ (x : κ → K), A.mulVec x ≤ b → c ⬝ᵥ x ≤ δ) :
∃ (y : ι → K), 0 ≤ y ∧ vecMul y A = c ∧ y ⬝ᵥ b ≤ δ

Affine Farkas lemma: if the inequality c ⬝ᵥ x ≤ δ holds on a nonempty polyhedron A *ᵥ x ≤ b, then it is implied by a nonnegative combination of the constraints [Schrijver1986, Corollary 7.1h].

The canonical pair max {c ⬝ᵥ x | A *ᵥ x ≤ b, 0 ≤ x}, min {y ⬝ᵥ b | c ≤ y ᵥ* A, 0 ≤ y} #

theorem Matrix.dotProduct_le_dotProduct_of_nonneg_of_mulVec_le {ι : Type u_1} {κ : Type u_2} [Fintype ι] [Fintype κ] {K : Type u_3} [Field K] [LinearOrder K] [IsStrictOrderedRing K] {A : Matrix ι κ K} {b : ι → K} {c x : κ → K} {y : ι → K} (hx : 0 ≤ x) (hAx : A.mulVec x ≤ b) (hy : 0 ≤ y) (hc : c ≤ vecMul y A) :
c ⬝ᵥ x ≤ y ⬝ᵥ b

Weak duality for the canonical pair [MatousekGartner2007, Chapter 6].

theorem Matrix.exists_isGreatest_isLeast_dotProduct_of_nonneg {ι : Type u_1} {κ : Type u_2} [Fintype ι] [Fintype κ] {K : Type u_3} [Field K] [LinearOrder K] [IsStrictOrderedRing K] (A : Matrix ι κ K) (b : ι → K) (c : κ → K) (hP : ∃ (x : κ → K), 0 ≤ x ∧ A.mulVec x ≤ b) (hD : ∃ (y : ι → K), 0 ≤ y ∧ c ≤ vecMul y A) :
∃ (v : K), IsGreatest ((fun (x : κ → K) => c ⬝ᵥ x) '' {x : κ → K | 0 ≤ x ∧ A.mulVec x ≤ b}) v ∧ IsLeast ((fun (x : ι → K) => x ⬝ᵥ b) '' {y : ι → K | 0 ≤ y ∧ c ≤ vecMul y A}) v

Strong duality for the canonical pair max {c ⬝ᵥ x | A *ᵥ x ≤ b, 0 ≤ x} and min {y ⬝ᵥ b | c ≤ y ᵥ* A, 0 ≤ y}: if both are feasible, both optima are attained and equal [MatousekGartner2007, Chapter 6].