Documentation

ConvexAnalysis.LinearProgramming

Farkas' lemma and linear programming duality #

Finitely generated cones are closed, which gives Farkas' lemma for cones and matrices and the duality theorem of linear programming, with all feasibility cases, attainment on both sides and complementary slackness. Linear programs are stated with matrices on m → ℝ (see DESIGN.md, section 1).

Main statements #

Implementation notes #

Carathéodory's theorem is proved by induction on the set of generators: if they are linearly dependent, a linear relation with a positive coefficient removes one generator from every representation. So a finitely generated cone is the finite union of the cones of its linearly independent sets of generators, and each of these is the image of the closed orthant under an injective linear map, a closed embedding; hence the cone is closed. LP duality then needs no Slater condition: the primal minimum is attained because the cone {(A x, c ⬝ᵥ x + s) | x ≥ 0, s ≥ 0} is closed, and the dual solution comes from Farkas' lemma for the system yᵀ A ≤ c, b ⬝ᵥ y ≥ min.

References #

Tags #

linear programming, LP duality, Farkas' lemma, finitely generated cone, Carathéodory's theorem, complementary slackness, strong duality

theorem ConvexAnalysis.exists_linearIndepOn_of_mem_finiteCone {E : Type u_1} [AddCommGroup E] [Module ℝ E] {ι : Type u_2} [Fintype ι] (v : ι → E) {x : E} (hx : ∃ (l : ι → ℝ), (∀ (j : ι), 0 ≤ l j) ∧ ∑ j : ι, l j • v j = x) :
∃ (s : Finset ι) (l : ι → ℝ), LinearIndepOn ℝ v ↑s ∧ (∀ (j : ι), 0 ≤ l j) ∧ (∀ j ∉ s, l j = 0) ∧ ∑ j : ι, l j • v j = x

Carathéodory's theorem for cones: a point of the cone generated by finitely many vectors v j is a nonnegative combination of linearly independent ones among them. This is the case of finitely many points in R, Corollary 17.1.2, which Rockafellar states on ℝⁿ for the cone generated by a union of convex sets; here E is any real vector space.

theorem ConvexAnalysis.isClosed_finiteCone {E : Type u_1} [AddCommGroup E] [Module ℝ E] {ι : Type u_2} [Fintype ι] [TopologicalSpace E] [IsTopologicalAddGroup E] [ContinuousSMul ℝ E] [T2Space E] (v : ι → E) :
IsClosed {x : E | ∃ (l : ι → ℝ), (∀ (j : ι), 0 ≤ l j) ∧ ∑ j : ι, l j • v j = x}

A finitely generated cone is closed in a Hausdorff real topological vector space; on ℝⁿ this is part of R, Theorem 19.1 ((c) ⇒ (b)), proved there with Carathéodory's theorem as here (exists_linearIndepOn_of_mem_finiteCone).

theorem ConvexAnalysis.coe_hull_range_eq {E : Type u_1} [AddCommGroup E] [Module ℝ E] {ι : Type u_2} [Fintype ι] (v : ι → E) :
↑(PointedCone.hull ℝ (Set.range v)) = {x : E | ∃ (l : ι → ℝ), (∀ (j : ι), 0 ≤ l j) ∧ ∑ j : ι, l j • v j = x}

The ad hoc cone of isClosed_finiteCone is Mathlib's PointedCone.hull ℝ (range v).

A finitely generated pointed cone is closed: the PointedCone.FG form.

A finitely generated pointed cone as a ProperCone, to which Mathlib's Farkas lemmas (ProperCone.hyperplane_separation_point) and double-dual theorems apply.

Equations
Instances For
    theorem ConvexAnalysis.exists_strongDual_of_notMem_finiteCone {E : Type u_1} [AddCommGroup E] [Module ℝ E] [TopologicalSpace E] [IsTopologicalAddGroup E] [ContinuousSMul ℝ E] [LocallyConvexSpace ℝ E] [T2Space E] {ι : Type u_2} [Fintype ι] (v : ι → E) {b : E} (hb : ¬∃ (l : ι → ℝ), (∀ (j : ι), 0 ≤ l j) ∧ ∑ j : ι, l j • v j = b) :
    ∃ (φ : StrongDual ℝ E), (∀ (j : ι), φ (v j) ≤ 0) ∧ 0 < φ b

    Farkas' lemma R, Corollary 22.3.1 (there in ℝⁿ, in the form K°° = K): in a Hausdorff locally convex space, a point b outside the cone generated by finitely many vectors v j is separated from it: some continuous linear functional is ≤ 0 on every v j and > 0 at b. Local convexity is needed: Lᵖ with p < 1 has no nonzero continuous functionals.

    theorem ConvexAnalysis.exists_nonneg_mulVec_eq_iff {m : Type u_1} {n : Type u_2} [Fintype m] [Fintype n] (A : Matrix m n ℝ) (b : m → ℝ) :
    (∃ (x : n → ℝ), 0 ≤ x ∧ A.mulVec x = b) ↔ ∀ (y : m → ℝ), 0 ≤ Matrix.vecMul y A → 0 ≤ b ⬝ᵥ y

    Farkas' lemma for matrices BV, Chapter 5, a reformulation of R, Corollary 22.3.1: A x = b has a solution x ≥ 0 iff b ⬝ᵥ y ≥ 0 for every y with yᵀ A ≥ 0.

    theorem ConvexAnalysis.exists_nonneg_mulVec_le_iff {m : Type u_1} {n : Type u_2} [Fintype m] [Fintype n] (A : Matrix m n ℝ) (b : m → ℝ) :
    (∃ (x : n → ℝ), 0 ≤ x ∧ A.mulVec x ≤ b) ↔ ∀ (y : m → ℝ), 0 ≤ y → 0 ≤ Matrix.vecMul y A → 0 ≤ b ⬝ᵥ y

    Farkas' lemma, mixed form: A x ≤ b has a solution x ≥ 0 iff b ⬝ᵥ y ≥ 0 for every y ≥ 0 with yᵀ A ≥ 0.

    theorem ConvexAnalysis.exists_mulVec_le_iff {m : Type u_1} {n : Type u_2} [Fintype m] [Fintype n] (A : Matrix m n ℝ) (b : m → ℝ) :
    (∃ (x : n → ℝ), A.mulVec x ≤ b) ↔ ∀ (y : m → ℝ), 0 ≤ y → Matrix.vecMul y A = 0 → 0 ≤ b ⬝ᵥ y

    Farkas' lemma, inequality form (Gale) R, Theorem 22.1: A x ≤ b has a solution iff b ⬝ᵥ y ≥ 0 for every y ≥ 0 with yᵀ A = 0.

    theorem ConvexAnalysis.lp_weak_duality {m : Type u_1} {n : Type u_2} [Fintype m] [Fintype n] (A : Matrix m n ℝ) (b : m → ℝ) (c : n → ℝ) {x : n → ℝ} {y : m → ℝ} (hx : 0 ≤ x) (hAx : A.mulVec x = b) (hy : Matrix.vecMul y A ≤ c) :
    b ⬝ᵥ y ≤ c ⬝ᵥ x

    Weak duality for linear programs: b ⬝ᵥ y ≤ c ⬝ᵥ x for x ≥ 0 with A x = b and y with yᵀ A ≤ c.

    theorem ConvexAnalysis.lp_gap_eq {m : Type u_1} {n : Type u_2} [Fintype m] [Fintype n] (A : Matrix m n ℝ) (b : m → ℝ) (c : n → ℝ) {x : n → ℝ} {y : m → ℝ} (hAx : A.mulVec x = b) :
    c ⬝ᵥ x - b ⬝ᵥ y = ∑ j : n, (c j - Matrix.vecMul y A j) * x j

    The duality gap of feasible x and y is ∑ j, (c j - (yᵀ A) j) x j.

    theorem ConvexAnalysis.lp_complementary_slackness {m : Type u_1} {n : Type u_2} [Fintype m] [Fintype n] (A : Matrix m n ℝ) (b : m → ℝ) (c : n → ℝ) {x : n → ℝ} {y : m → ℝ} (hx : 0 ≤ x) (hAx : A.mulVec x = b) (hy : Matrix.vecMul y A ≤ c) :
    c ⬝ᵥ x = b ⬝ᵥ y ↔ ∀ (j : n), (c j - Matrix.vecMul y A j) * x j = 0

    Complementary slackness BV, Chapter 5: feasible x and y have equal values iff (c j - (yᵀ A) j) x j = 0 for every j; then both are optimal by weak duality.

    theorem ConvexAnalysis.exists_isMinOn_lp {m : Type u_1} {n : Type u_2} [Fintype m] [Fintype n] (A : Matrix m n ℝ) (b : m → ℝ) (c : n → ℝ) (hfeas : ∃ (x : n → ℝ), 0 ≤ x ∧ A.mulVec x = b) (hbdd : BddBelow ((fun (x : n → ℝ) => c ⬝ᵥ x) '' {x : n → ℝ | 0 ≤ x ∧ A.mulVec x = b})) :
    ∃ x ∈ {x : n → ℝ | 0 ≤ x ∧ A.mulVec x = b}, IsMinOn (fun (x : n → ℝ) => c ⬝ᵥ x) {x : n → ℝ | 0 ≤ x ∧ A.mulVec x = b} x

    Existence of a primal solution: a feasible linear program whose objective is bounded below on the feasible set has a minimizer BV, Chapter 5. No Slater condition is needed.

    theorem ConvexAnalysis.exists_lp_strong_duality {m : Type u_1} {n : Type u_2} [Fintype m] [Fintype n] (A : Matrix m n ℝ) (b : m → ℝ) (c : n → ℝ) (hfeas : ∃ (x : n → ℝ), 0 ≤ x ∧ A.mulVec x = b) (hbdd : BddBelow ((fun (x : n → ℝ) => c ⬝ᵥ x) '' {x : n → ℝ | 0 ≤ x ∧ A.mulVec x = b})) :
    ∃ (x : n → ℝ) (y : m → ℝ), 0 ≤ x ∧ A.mulVec x = b ∧ Matrix.vecMul y A ≤ c ∧ c ⬝ᵥ x = b ⬝ᵥ y

    Strong duality for linear programs BV, Chapter 5: if the primal min c ⬝ᵥ x s.t. A x = b, x ≥ 0 is feasible and bounded below, then it has a solution x, the dual max b ⬝ᵥ y s.t. yᵀ A ≤ c has a solution y, and the values are equal.

    theorem ConvexAnalysis.lp_isMinOn_and_isMaxOn_of_eq {m : Type u_1} {n : Type u_2} [Fintype m] [Fintype n] (A : Matrix m n ℝ) (b : m → ℝ) (c : n → ℝ) {x : n → ℝ} {y : m → ℝ} (hx : 0 ≤ x) (hAx : A.mulVec x = b) (hy : Matrix.vecMul y A ≤ c) (h : c ⬝ᵥ x = b ⬝ᵥ y) :
    IsMinOn (fun (x : n → ℝ) => c ⬝ᵥ x) {x : n → ℝ | 0 ≤ x ∧ A.mulVec x = b} x ∧ IsMaxOn (fun (y : m → ℝ) => b ⬝ᵥ y) {y : m → ℝ | Matrix.vecMul y A ≤ c} y

    Feasible x, y with equal values are optimal.

    theorem ConvexAnalysis.bddBelow_lp_of_dual_feasible {m : Type u_1} {n : Type u_2} [Fintype m] [Fintype n] (A : Matrix m n ℝ) (b : m → ℝ) (c : n → ℝ) (hd : ∃ (y : m → ℝ), Matrix.vecMul y A ≤ c) :
    BddBelow ((fun (x : n → ℝ) => c ⬝ᵥ x) '' {x : n → ℝ | 0 ≤ x ∧ A.mulVec x = b})

    Weak duality: if the dual program is feasible, the primal objective is bounded below on the primal feasible set.

    theorem ConvexAnalysis.bddAbove_lp_dual_of_feasible {m : Type u_1} {n : Type u_2} [Fintype m] [Fintype n] (A : Matrix m n ℝ) (b : m → ℝ) (c : n → ℝ) (hp : ∃ (x : n → ℝ), 0 ≤ x ∧ A.mulVec x = b) :
    BddAbove ((fun (y : m → ℝ) => b ⬝ᵥ y) '' {y : m → ℝ | Matrix.vecMul y A ≤ c})

    Weak duality: if the primal program is feasible, the dual objective is bounded above on the dual feasible set.

    theorem ConvexAnalysis.not_bddAbove_lp_dual_of_infeasible {m : Type u_1} {n : Type u_2} [Fintype m] [Fintype n] (A : Matrix m n ℝ) (b : m → ℝ) (c : n → ℝ) (hp : ¬∃ (x : n → ℝ), 0 ≤ x ∧ A.mulVec x = b) (hd : ∃ (y : m → ℝ), Matrix.vecMul y A ≤ c) :
    ¬BddAbove ((fun (y : m → ℝ) => b ⬝ᵥ y) '' {y : m → ℝ | Matrix.vecMul y A ≤ c})

    Primal infeasible, dual feasible ⇒ dual unbounded (Farkas).

    theorem ConvexAnalysis.lp_feasible_and_dual_feasible_iff {m : Type u_1} {n : Type u_2} [Fintype m] [Fintype n] (A : Matrix m n ℝ) (b : m → ℝ) (c : n → ℝ) :
    ((∃ (x : n → ℝ), 0 ≤ x ∧ A.mulVec x = b) ∧ ∃ (y : m → ℝ), Matrix.vecMul y A ≤ c) ↔ ∃ (x : n → ℝ) (y : m → ℝ), 0 ≤ x ∧ A.mulVec x = b ∧ Matrix.vecMul y A ≤ c ∧ c ⬝ᵥ x = b ⬝ᵥ y

    LP duality, textbook form: both programs are feasible iff both have solutions with equal values.

    theorem ConvexAnalysis.exists_lp_strong_duality_of_dual {m : Type u_1} {n : Type u_2} [Fintype m] [Fintype n] (A : Matrix m n ℝ) (b : m → ℝ) (c : n → ℝ) (hd : ∃ (y : m → ℝ), Matrix.vecMul y A ≤ c) (hbdd : BddAbove ((fun (y : m → ℝ) => b ⬝ᵥ y) '' {y : m → ℝ | Matrix.vecMul y A ≤ c})) :
    ∃ (x : n → ℝ) (y : m → ℝ), 0 ≤ x ∧ A.mulVec x = b ∧ Matrix.vecMul y A ≤ c ∧ c ⬝ᵥ x = b ⬝ᵥ y

    Strong duality from the dual side: a feasible dual bounded above has a solution.

    theorem ConvexAnalysis.lp_sInf_eq_sSup {m : Type u_1} {n : Type u_2} [Fintype m] [Fintype n] (A : Matrix m n ℝ) (b : m → ℝ) (c : n → ℝ) (hp : ∃ (x : n → ℝ), 0 ≤ x ∧ A.mulVec x = b) (hd : ∃ (y : m → ℝ), Matrix.vecMul y A ≤ c) :
    sInf ((fun (x : n → ℝ) => c ⬝ᵥ x) '' {x : n → ℝ | 0 ≤ x ∧ A.mulVec x = b}) = sSup ((fun (y : m → ℝ) => b ⬝ᵥ y) '' {y : m → ℝ | Matrix.vecMul y A ≤ c})

    Equal optimal values as sInf = sSup.

    theorem ConvexAnalysis.not_bddBelow_lp_of_dual_infeasible {m : Type u_1} {n : Type u_2} [Fintype m] [Fintype n] (A : Matrix m n ℝ) (b : m → ℝ) (c : n → ℝ) (hp : ∃ (x : n → ℝ), 0 ≤ x ∧ A.mulVec x = b) (hd : ¬∃ (y : m → ℝ), Matrix.vecMul y A ≤ c) :
    ¬BddBelow ((fun (x : n → ℝ) => c ⬝ᵥ x) '' {x : n → ℝ | 0 ≤ x ∧ A.mulVec x = b})

    Primal feasible, dual infeasible ⇒ primal unbounded (contrapositive of strong duality).

    theorem ConvexAnalysis.exists_lp_strong_duality_le {m : Type u_1} {n : Type u_2} [Fintype m] [Fintype n] (A : Matrix m n ℝ) (b : m → ℝ) (c : n → ℝ) (hfeas : ∃ (x : n → ℝ), A.mulVec x ≤ b) (hbdd : BddAbove ((fun (x : n → ℝ) => c ⬝ᵥ x) '' {x : n → ℝ | A.mulVec x ≤ b})) :
    ∃ (x : n → ℝ) (y : m → ℝ), A.mulVec x ≤ b ∧ 0 ≤ y ∧ Matrix.vecMul y A = c ∧ c ⬝ᵥ x = b ⬝ᵥ y

    Strong duality for the inequality form max c ⬝ᵥ x s.t. A x ≤ b, whose dual is min b ⬝ᵥ y s.t. y ≥ 0, yᵀ A = c: the dual is a program in standard form, so this is exists_lp_strong_duality_of_dual.