Finite covering/packing LP pair, optimality and complementary slackness
DefinitionPrimalDualOnline_FiniteLPThe primal-dual pair of Section 2.1 over arbitrary finite index types (primal variables, dual constraints) and (primal constraints, dual variables). The primal minimises subject to for every and ; the dual maximises subject to for every and . The matrix is indexed with the primal-variable index first, matching the source's convention.
Optimality is defined as attainment: PrimalOptimal asserts that is feasible and no feasible point has smaller cost, not merely that the infimum is bounded. Because the source's informal word "bounded" conflates several distinct conditions, four notions are kept apart deliberately: having an attained optimum (PrimalHasOptimum), having a nonempty feasible set (PrimalFeasibleNonempty), having a bounded objective (PrimalObjectiveBddBelow), and the dual-side counterparts of each.
NonnegInstance singles out the covering/packing subclass in which , and are all nonnegative. PrimalApproxCS says that whenever the dual constraint is satisfied to within a factor , that is ; DualApproxCS says that whenever the primal constraint is satisfied to within a factor , that is . Both are two-sided, as in the source.
import Mathlib.Tactic
import Mathlib.Algebra.Order.BigOperators.Ring.Finset
namespace PrimalDualOnline.LP
/-!
The finite primal-dual pair of Section 2.1.
Data: finite index types `I` (primal variables / dual constraints) and `J` (primal
constraints / dual variables), a matrix `A : I → J → ℝ`, a primal cost `c : I → ℝ`, and a
primal right-hand side `b : J → ℝ`.
Orientation follows the source (p. 7–8):
* primal `(P)`: minimise `∑ i, c i * x i` subject to `∀ j, b j ≤ ∑ i, A i j * x i` and `x ≥ 0`;
* dual `(D)`: maximise `∑ j, b j * y j` subject to `∀ i, ∑ j, A i j * y j ≤ c i` and `y ≥ 0`.
Note the index convention: `A i j` has the primal-variable index FIRST, so the primal
constraint `j` sums over `i` and the dual constraint `i` sums over `j`. The source writes
`a_{ij}` with `i` ranging over primal variables and `j` over primal constraints, which is the
same convention.
-/
variable {I J : Type*} [Fintype I] [Fintype J]
/-- Primal feasibility: every covering constraint is met and every variable is nonnegative.
Does not mention the cost vector `c`. -/
def PrimalFeasible (A : I → J → ℝ) (b : J → ℝ) (x : I → ℝ) : Prop :=
(∀ j : J, b j ≤ ∑ i : I, A i j * x i) ∧ ∀ i : I, 0 ≤ x i
/-- Dual feasibility: every packing constraint is met and every variable is nonnegative.
Does not mention the right-hand side `b`. -/
def DualFeasible (A : I → J → ℝ) (c : I → ℝ) (y : J → ℝ) : Prop :=
(∀ i : I, ∑ j : J, A i j * y j ≤ c i) ∧ ∀ j : J, 0 ≤ y j
/-- The primal objective `∑ i, c i * x i`, to be minimised. -/
def primalObjective (c : I → ℝ) (x : I → ℝ) : ℝ := ∑ i : I, c i * x i
/-- The dual objective `∑ j, b j * y j`, to be maximised. -/
def dualObjective (b : J → ℝ) (y : J → ℝ) : ℝ := ∑ j : J, b j * y j
/-- `x` is an optimal primal solution: feasible, and no feasible point has smaller cost.
This is attainment, not merely a bound on the infimum. -/
def PrimalOptimal (A : I → J → ℝ) (b : J → ℝ) (c : I → ℝ) (x : I → ℝ) : Prop :=
PrimalFeasible A b x ∧
∀ x' : I → ℝ, PrimalFeasible A b x' → primalObjective c x ≤ primalObjective c x'
/-- `y` is an optimal dual solution: feasible, and no feasible point has larger value. -/
def DualOptimal (A : I → J → ℝ) (b : J → ℝ) (c : I → ℝ) (y : J → ℝ) : Prop :=
DualFeasible A c y ∧
∀ y' : J → ℝ, DualFeasible A c y' → dualObjective b y' ≤ dualObjective b y
/-- The primal program has a finite attained optimum: some feasible point is optimal.
This is deliberately distinct from "the objective is bounded below on the feasible set" and
from "the feasible set is nonempty"; see `PrimalFeasibleNonempty` and
`PrimalObjectiveBddBelow`. -/
def PrimalHasOptimum (A : I → J → ℝ) (b : J → ℝ) (c : I → ℝ) : Prop :=
∃ x : I → ℝ, PrimalOptimal A b c x
/-- The dual program has a finite attained optimum. -/
def DualHasOptimum (A : I → J → ℝ) (b : J → ℝ) (c : I → ℝ) : Prop :=
∃ y : J → ℝ, DualOptimal A b c y
/-- The primal feasible set is nonempty. Separated from optimality on purpose: the source's
informal word "bounded" conflates feasibility, boundedness and attainment. -/
def PrimalFeasibleNonempty (A : I → J → ℝ) (b : J → ℝ) : Prop :=
∃ x : I → ℝ, PrimalFeasible A b x
/-- The dual feasible set is nonempty. -/
def DualFeasibleNonempty (A : I → J → ℝ) (c : I → ℝ) : Prop :=
∃ y : J → ℝ, DualFeasible A c y
/-- The primal objective is bounded below on the primal feasible set. Weaker than having an
attained optimum in general, though for linear programs over `ℝ` the two coincide when the
feasible set is nonempty. -/
def PrimalObjectiveBddBelow (A : I → J → ℝ) (b : J → ℝ) (c : I → ℝ) : Prop :=
∃ M : ℝ, ∀ x : I → ℝ, PrimalFeasible A b x → M ≤ primalObjective c x
/-- The dual objective is bounded above on the dual feasible set. -/
def DualObjectiveBddAbove (A : I → J → ℝ) (b : J → ℝ) (c : I → ℝ) : Prop :=
∃ M : ℝ, ∀ y : J → ℝ, DualFeasible A c y → dualObjective b y ≤ M
/-- A nonnegative covering/packing instance: all data nonnegative. This is the subclass the
source calls a covering problem (primal) with a packing dual. -/
def NonnegInstance (A : I → J → ℝ) (b : J → ℝ) (c : I → ℝ) : Prop :=
(∀ i : I, ∀ j : J, 0 ≤ A i j) ∧ (∀ j : J, 0 ≤ b j) ∧ ∀ i : I, 0 ≤ c i
/-- Primal approximate complementary slackness with factor `α`: whenever a primal variable is
positive, its dual constraint is satisfied to within a factor `α`. -/
def PrimalApproxCS (α : ℝ) (A : I → J → ℝ) (c : I → ℝ) (x : I → ℝ) (y : J → ℝ) : Prop :=
∀ i : I, 0 < x i → c i / α ≤ ∑ j : J, A i j * y j ∧ ∑ j : J, A i j * y j ≤ c i
/-- Dual approximate complementary slackness with factor `β`: whenever a dual variable is
positive, its primal constraint is satisfied to within a factor `β`. -/
def DualApproxCS (β : ℝ) (A : I → J → ℝ) (b : J → ℝ) (x : I → ℝ) (y : J → ℝ) : Prop :=
∀ j : J, 0 < y j → b j ≤ ∑ i : I, A i j * x i ∧ ∑ i : I, A i j * x i ≤ β * b j
end PrimalDualOnline.LP
Read-back
What the Lean code literally says, in plain math · claude-opus-5
Read-back — PrimalDualOnline.LP bundle (15 declarations)
Shared binders. Every declaration below lives in the namespace PrimalDualOnline.LP and is stated for two implicit type variables and , each drawn from an arbitrary universe, together with two implicit instance hypotheses asserting that is a finite type and that is a finite type. Finiteness is the only structure assumed of and : they are not assumed nonempty, not assumed decidably ordered, and not related to one another. Nothing in the bundle is a theorem; all fifteen declarations are definitions, twelve of them producing a proposition (a truth-valued predicate) and two producing a real number, so nothing here asserts that any of these propositions holds. Throughout, a matrix-like datum is a function taking a first index and a second index to a real number, written below; the orientation is uniform across the whole bundle — the symbol is always applied as (first index in , second index in ), and no transpose is ever formed. Vectors indexed by are and ; vectors indexed by are and . Sums are finite sums over the whole index type, justified by the finiteness instances, and are when the index type is empty.
1. PrimalFeasible
PrimalFeasible is a predicate with two implicit arguments (the finite types , , with their two implicit finiteness instances) and three explicit arguments: a two-index real array with first index in and second index in , a real vector indexed by , and a real vector indexed by . It asserts the conjunction of two families of conditions:
The index convention is explicit here: for each fixed second index , the sum runs over the first index , i.e. over the -indexed family paired with . Both inequalities are non-strict, and the constraint direction is "" in the sense that the -side is the lower bound. There is no assumption that , , or have any sign beyond the stated . Degenerate cases: if is empty, every sum is , the nonnegativity clause is vacuously true, and the predicate reduces to " for all "; if is empty, the first clause is vacuously true and the predicate reduces to " for all "; if both are empty the predicate is unconditionally true (and is then satisfied by the unique empty vector).
2. DualFeasible
DualFeasible is a predicate with implicit arguments , and their two implicit finiteness instances, and three explicit arguments: the two-index array (first index in , second in ), a real vector indexed by , and a real vector indexed by . It asserts the conjunction
Here the summation convention is the mirror image of the primal one: for each fixed first index , the sum runs over the second index , over the -indexed family paired with . Both inequalities are non-strict and the -side is the upper bound. No sign assumption is placed on or . Degenerate cases: if is empty, all sums are , the nonnegativity clause is vacuous, and the predicate reduces to " for all "; if is empty, the first clause is vacuous and the predicate reduces to " for all "; if both are empty it is unconditionally true.
3. primalObjective
primalObjective is not a proposition but a real-valued function. It takes the implicit type with its implicit finiteness instance (the type and its instance are also in scope as implicit arguments of the surrounding variable block, though plays no role in the body) and two explicit real vectors and , both indexed by , and returns the finite sum
that is, the pairing of the coefficient vector with the vector in the order " factor first, factor second". No feasibility, sign, or normalization condition is imposed on either argument: the value is defined for arbitrary real vectors. If is empty the value is .
4. dualObjective
dualObjective is likewise a real-valued function, taking the implicit type with its implicit finiteness instance (and the implicit and its instance, unused in the body) and two explicit real vectors and , both indexed by , and returning
the pairing of with in the order " factor first, factor second". Again no feasibility or sign condition is imposed on the arguments, and the value is when is empty.
5. PrimalOptimal
PrimalOptimal is a predicate on a specific vector. Its implicit arguments are , and their two finiteness instances; its explicit arguments are (first index , second index ), indexed by , indexed by , and indexed by . It asserts the conjunction of two things: first, that is primal feasible in the sense of declaration 1, i.e. for every and for every ; and second, that for every real vector indexed by — the quantifier ranges over all functions , filtered by the hypothesis that is itself primal feasible in the same sense — one has
So the direction of optimality is minimization: the objective at is a lower bound for the objective at every feasible competitor. The inequality is non-strict, so nothing about uniqueness is claimed and several vectors may simultaneously satisfy this predicate. The statement does not require , , or to be nonnegative. If is empty, feasibility of and of each reduces to nonnegativity, so the predicate says and for all . If is empty, the predicate reduces to " for all " (the objective comparison becomes ).
6. DualOptimal
DualOptimal is the corresponding predicate on a specific -indexed vector, with implicit , and their two finiteness instances, and explicit arguments , indexed by , indexed by , and indexed by . It asserts, first, that is dual feasible in the sense of declaration 2, i.e. for every and for every ; and second, that for every real vector indexed by that is dual feasible in the same sense,
Note the orientation of this second clause: the competitor's objective appears on the left, so the direction of optimality is maximization — the objective at dominates that at every dual feasible competitor. The inequality is non-strict and no uniqueness is claimed. If is empty, dual feasibility reduces to and the clause says for all nonnegative . If is empty, the predicate reduces to " for all " (the objective comparison becomes ).
7. PrimalHasOptimum
PrimalHasOptimum takes implicit , with their two finiteness instances and explicit (first index , second ), indexed by , and indexed by ; it asserts the bare existence statement: there exists a real vector indexed by such that is primal optimal in the sense of declaration 5 — that is, satisfies for all and for all , and for every primal feasible . This is an ordinary existential, not a unique existential, so it does not claim that the minimizer is unique. It does assert, as part of the unfolded content, that the primal feasible set is nonempty (the witness lies in it) and that the infimum of the objective over that set is attained. If is empty it reduces to " for all "; if is empty it reduces to the existence of a nonnegative minimizing over all nonnegative vectors.
8. DualHasOptimum
DualHasOptimum takes implicit , with their two finiteness instances and explicit , indexed by , and indexed by ; it asserts that there exists a real vector indexed by that is dual optimal in the sense of declaration 6 — i.e. for all , for all , and for every dual feasible . Again this is a plain existential with no uniqueness, and it entails both that the dual feasible set is nonempty and that the supremum of the dual objective over it is attained. If is empty it reduces to " for all "; if is empty it reduces to the existence of a nonnegative maximizing over all nonnegative vectors.
9. PrimalFeasibleNonempty
PrimalFeasibleNonempty takes implicit , with their two finiteness instances and only two explicit arguments — (first index , second ) and indexed by ; the objective vector does not appear. It asserts that there exists a real vector indexed by with for every and for every . Nothing is said about the value of any objective at this witness or about optimality. If is empty the statement is true for the zero vector (indeed for any nonnegative vector); if is empty it is equivalent to " for all ", witnessed by the empty vector.
10. DualFeasibleNonempty
DualFeasibleNonempty takes implicit , with their two finiteness instances and two explicit arguments — and indexed by ; the vector does not appear. It asserts that there exists a real vector indexed by with for every and for every . Nothing is said about the value of the dual objective at this witness or about optimality. If is empty the statement is true for the zero vector (indeed any nonnegative ); if is empty it is equivalent to " for all ", witnessed by the empty vector.
11. PrimalObjectiveBddBelow
PrimalObjectiveBddBelow takes implicit , with their two finiteness instances and explicit , indexed by , and indexed by . It asserts that there exists a real number such that for every real vector indexed by , if is primal feasible — i.e. for all and for all — then
The bound is merely some lower bound: it is not required to be tight, to be the infimum, or to be attained by any feasible point, and the quantifier order is ", ", so a single must work uniformly. Crucially, the implication is vacuous when no is primal feasible: if the feasible set is empty, the statement holds with any whatsoever, so this predicate carries no existence content. If is empty, every feasible has objective , so the predicate holds (e.g. with ) regardless of ; if is empty the predicate says the objective is bounded below over the nonnegative orthant.
12. DualObjectiveBddAbove
DualObjectiveBddAbove takes implicit , with their two finiteness instances and explicit , indexed by , and indexed by . It asserts that there exists a real number such that for every real vector indexed by , if is dual feasible — i.e. for all and for all — then
Again is only some uniform upper bound, not required to be the supremum or to be attained, with quantifier order ", "; and the implication is vacuous when the dual feasible set is empty, in which case any works and the predicate asserts nothing about existence. If is empty the objective of any feasible is and the predicate holds (e.g. ); if is empty the predicate says is bounded above over the nonnegative orthant.
13. NonnegInstance
NonnegInstance takes implicit , with their two finiteness instances and explicit (first index , second ), indexed by , and indexed by , and asserts a threefold conjunction of non-strict sign conditions:
All three are , not , so zero entries, the zero matrix, and the zero vectors are all permitted; nothing is required about row or column sums, nonzero-ness, or any relation between , , and . If is empty, the first and third clauses are vacuous and only " for all " survives; if is empty, the first and second are vacuous and only " for all " survives; if both are empty the conjunction is vacuously true.
14. PrimalApproxCS
PrimalApproxCS takes implicit , with their two finiteness instances, and five explicit arguments: a real number (the first argument), the array (first index , second ), the vector indexed by , the vector indexed by , and the vector indexed by ; the vector does not appear. It asserts that for every , if is strictly positive, then the quantity — a sum over the second index of with the first index fixed at , i.e. exactly the left-hand side of the -th dual constraint — is two-sidedly bounded:
So the bounded quantity is the dual-constraint sum , with the lower bound and the upper bound ; both inequalities are non-strict, and they are imposed only at those indices where (indices with , or , are entirely unconstrained — the hypothesis is the strict inequality , so the predicate is vacuously true whenever has no strictly positive coordinate, in particular for ). Note that the upper bound is the -th dual feasibility inequality restated at the support of only; the predicate does not require it at other indices, nor does it require , , or any sign condition on , , or . Because division in the reals is a total operation here, is permitted and yields , so at the predicate degenerates to "for every with : " — a nonnegativity requirement on the dual-constraint sum rather than anything involving on the left. For the quotient has the opposite sign pattern from the positive case (e.g. it is negative when ), and no hypothesis such as or is present to exclude this. Degenerate index types: if is empty the predicate is vacuously true; if is empty then for every and the predicate says "for every with : and ".
15. DualApproxCS
DualApproxCS takes implicit , with their two finiteness instances, and five explicit arguments: a real number (the first argument), the array (first index , second ), the vector indexed by , the vector indexed by , and the vector indexed by ; the vector does not appear. It asserts that for every , if is strictly positive, then the quantity — a sum over the first index of with the second index fixed at , i.e. exactly the left-hand side of the -th primal constraint — is two-sidedly bounded:
So the bounded quantity is the primal-constraint sum , with the lower bound and the upper bound the product (a multiplication, not a division, so no junk-value issue arises); both inequalities are non-strict and are imposed only at indices with , leaving indices with or unconstrained, and making the predicate vacuously true when has no strictly positive coordinate, in particular for . The lower bound is the -th primal feasibility inequality restated at the support of only; the predicate does not require it elsewhere, nor does it require , , or any sign condition on , , or . At the upper bound becomes , so the predicate then requires, for each with , that — which in particular forces at every such ; for the two bounds read , which is unsatisfiable whenever and , and no hypothesis such as or is present. Degenerate index types: if is empty the predicate is vacuously true; if is empty then for every and the predicate says "for every with : and ".
The four primal notions, as literally written
PrimalOptimal A b c x is a predicate about a named vector : it says is feasible and its objective is that of every feasible competitor. Unfolding it, it contains a feasible witness ( itself) and a uniform lower bound for the objective over the feasible set (namely ), so as written it entails both PrimalFeasibleNonempty A b and PrimalObjectiveBddBelow A b c, and it entails PrimalHasOptimum A b c by taking as witness. It does not claim is the only such vector.
PrimalHasOptimum A b c asserts only that some such exists; it therefore entails feasible-nonemptiness and bounded-belowness and attainment of the minimum, but, having discarded the witness, it names no particular vector and asserts no uniqueness.
PrimalFeasibleNonempty A b mentions only and and asserts only that the constraint system has at least one solution with . As written it says nothing whatsoever about or the objective: it does not imply PrimalObjectiveBddBelow, does not imply PrimalHasOptimum, and does not imply that any particular vector is optimal.
PrimalObjectiveBddBelow A b c asserts only the existence of one real number bounding the objective from below across all feasible points. It does not imply that a feasible point exists (an empty feasible set makes the inner implication vacuous, so every works and the predicate holds), it does not imply that the bound is tight or attained, and it does not imply PrimalHasOptimum or PrimalOptimal for any vector. Nor is any implication from the conjunction of feasible-nonemptiness and bounded-belowness to the existence of an optimum asserted anywhere in this bundle: these are four separate definitions, and no theorem connecting them is stated here.
The dual side is the exact mirror in every respect, with the direction of the objective comparison reversed: DualOptimal is maximality of among dual feasible vectors, DualHasOptimum its existential form, DualFeasibleNonempty (which mentions and but not ) the bare solvability of the dual constraint system, and DualObjectiveBddAbove the existence of one uniform upper bound , vacuously true when the dual feasible set is empty. No relation between the primal and dual notions — no weak- or strong-duality inequality, no complementary-slackness implication — is stated in this bundle.
Confirmed by the mission captain (proposal self-audit).