Prove2Me
Navigate
MissionsFormalpediaUsersMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

Finite Standard-Form Primal and Dual Linear Programs

Definition
pd_finite_lp

by wenxinzhang · Aug 12, 2026 · Mathlib c5ea003 (Lean v4.30.0)

dualitylinear-programmingonline-algorithmsoptimizationprimal-dual

This module fixes the finite standard-form primal–dual pair underlying the online primal–dual method.

A finite standard-form pair consists of a coefficient matrix A=(aij)A=(a_{ij})A=(aij​) indexed by primal variables i∈ιi\in\iotai∈ι and constraints j∈κj\in\kappaj∈κ, a right-hand side b=(bj)b=(b_j)b=(bj​), and a cost vector c=(ci)c=(c_i)c=(ci​). The primal program minimizes ∑icixi\sum_i c_i x_i∑i​ci​xi​ subject to

∑i∈ιaijxi≥bj(j∈κ),x≥0,\sum_{i\in\iota} a_{ij}x_i \ge b_j \quad (j\in\kappa), \qquad x\ge 0,i∈ι∑​aij​xi​≥bj​(j∈κ),x≥0,

and its dual maximizes ∑jbjyj\sum_j b_j y_j∑j​bj​yj​ subject to

∑j∈κaijyj≤ci(i∈ι),y≥0.\sum_{j\in\kappa} a_{ij}y_j \le c_i \quad (i\in\iota), \qquad y\ge 0.j∈κ∑​aij​yj​≤ci​(i∈ι),y≥0.

The module defines both constraint values, both objectives, and the two feasibility predicates, together with the two-sided approximate complementary-slackness conditions with slack factor α\alphaα on primal variables and β\betaβ on dual variables. The extra nonnegativity of AAA, bbb, and ccc that makes the pair a covering primal with packing dual is recorded as a separate predicate.

This is the shared interface through which the mission states weak duality, prefix feasibility, and the failure certificate; the covering–packing subclass is the one instantiated by the unrelated-machines linear program.

Formalization Note The index types ι\iotaι and κ\kappaκ are arbitrary, with a Fintype instance assumed exactly where a finite sum is formed; no nonemptiness is assumed, and no sign conditions are built into the base structure.

Definition code
import Mathlib.Data.Fintype.BigOperators
import Mathlib.Data.Real.Basic

namespace PrimalDual

open scoped BigOperators

/--
A finite standard-form primal/dual pair.  The primal variables are indexed by `ι`,
the primal constraints (and dual variables) by `κ`.
-/
structure FinitePrimalDual (ι κ : Type*) where
  coeff : ι → κ → ℝ
  rhs : κ → ℝ
  cost : ι → ℝ

namespace FinitePrimalDual

variable {ι κ : Type*} [Fintype ι] [Fintype κ]

/-- The value of primal constraint `j` at a primal vector `x`. -/
def primalConstraintValue (P : FinitePrimalDual ι κ) (x : ι → ℝ) (j : κ) : ℝ :=
  ∑ i, P.coeff i j * x i

/-- The value of dual constraint `i` at a dual vector `y`. -/
def dualConstraintValue (P : FinitePrimalDual ι κ) (y : κ → ℝ) (i : ι) : ℝ :=
  ∑ j, P.coeff i j * y j

/-- The minimization objective of the primal program. -/
def primalObjective (P : FinitePrimalDual ι κ) (x : ι → ℝ) : ℝ :=
  ∑ i, P.cost i * x i

/-- The maximization objective of the dual program. -/
def dualObjective (P : FinitePrimalDual ι κ) (y : κ → ℝ) : ℝ :=
  ∑ j, P.rhs j * y j

/-- Feasibility for the standard-form primal: `x >= 0` and `A x >= b`. -/
def PrimalFeasible (P : FinitePrimalDual ι κ) (x : ι → ℝ) : Prop :=
  (∀ i, 0 ≤ x i) ∧ ∀ j, P.rhs j ≤ P.primalConstraintValue x j

/-- Feasibility for the standard-form dual: `y >= 0` and `A^T y <= c`. -/
def DualFeasible (P : FinitePrimalDual ι κ) (y : κ → ℝ) : Prop :=
  (∀ j, 0 ≤ y j) ∧ ∀ i, P.dualConstraintValue y i ≤ P.cost i

/--
The two-sided primal-variable condition from approximate complementary slackness:
every positive primal variable has a dual constraint within a factor `α` of tight.
-/
def SatisfiesPrimalApproxCS (P : FinitePrimalDual ι κ) (α : ℝ)
    (x : ι → ℝ) (y : κ → ℝ) : Prop :=
  ∀ i, 0 < x i →
    P.cost i / α ≤ P.dualConstraintValue y i ∧
      P.dualConstraintValue y i ≤ P.cost i

/--
The two-sided dual-variable condition from approximate complementary slackness:
every positive dual variable has a primal constraint within a factor `β` of tight.
-/
def SatisfiesDualApproxCS (P : FinitePrimalDual ι κ) (β : ℝ)
    (x : ι → ℝ) (y : κ → ℝ) : Prop :=
  ∀ j, 0 < y j →
    P.rhs j ≤ P.primalConstraintValue x j ∧
      P.primalConstraintValue x j ≤ β * P.rhs j

/--
The additional nonnegativity assumptions that make a standard-form pair a
covering-primal/packing-dual pair.  Weak duality and approximate complementary
slackness do not require these assumptions.
-/
structure IsCoveringPacking (P : FinitePrimalDual ι κ) : Prop where
  coeff_nonneg : ∀ i j, 0 ≤ P.coeff i j
  rhs_nonneg : ∀ j, 0 ≤ P.rhs j
  cost_nonneg : ∀ i, 0 ≤ P.cost i

end FinitePrimalDual

end PrimalDual
Source
Niv Buchbinder and Joseph (Seffi) Naor, The Design of Competitive Online Algorithms via a Primal--Dual Approach, https://www.tau.ac.il/~nivb/download/pd-survey.pdf, Section 2.1, pp. 97--101, including the primal/dual displays and the covering--packing paragraph after Theorem 2.3.
Read-back

What the Lean code literally says, in plain math · gpt-5

PrimalDual.FinitePrimalDual: For arbitrary types ι\iotaι and κ\kappaκ, with no finiteness, nonemptiness, or other typeclass assumptions, a finite-primal-dual datum PPP consists of three unrestricted real-valued functions: coefficients a=P.coeff:ι→κ→Ra=P.\mathrm{coeff}:\iota\to\kappa\to\mathbb Ra=P.coeff:ι→κ→R, a right-hand side b=P.rhs:κ→Rb=P.\mathrm{rhs}:\kappa\to\mathbb Rb=P.rhs:κ→R, and a cost c=P.cost:ι→Rc=P.\mathrm{cost}:\iota\to\mathbb Rc=P.cost:ι→R. No sign or boundedness conditions are imposed. Either indexing type may be empty or infinite; for an empty domain the corresponding functions are the unique empty-domain functions.

PrimalDual.FinitePrimalDual.primalConstraintValue: For arbitrary types ι,κ\iota,\kappaι,κ, a chosen Fintype structure on ι\iotaι but no finiteness assumption on κ\kappaκ, a datum PPP with coefficients a:ι→κ→Ra:\iota\to\kappa\to\mathbb Ra:ι→κ→R, an arbitrary vector x:ι→Rx:\iota\to\mathbb Rx:ι→R, and an index j:κj:\kappaj:κ, the primal constraint value is the real number ∑i∈ιaijxi\sum_{i\in\iota}a_{ij}x_i∑i∈ι​aij​xi​. Neither aaa nor xxx is assumed nonnegative. If ι\iotaι is empty, the sum is 000; if κ\kappaκ is empty, there is no index jjj at which this function can be evaluated.

PrimalDual.FinitePrimalDual.dualConstraintValue: For arbitrary types ι,κ\iota,\kappaι,κ, a chosen Fintype structure on κ\kappaκ but no finiteness assumption on ι\iotaι, a datum PPP with coefficients a:ι→κ→Ra:\iota\to\kappa\to\mathbb Ra:ι→κ→R, an arbitrary vector y:κ→Ry:\kappa\to\mathbb Ry:κ→R, and an index i:ιi:\iotai:ι, the dual constraint value is the real number ∑j∈κaijyj\sum_{j\in\kappa}a_{ij}y_j∑j∈κ​aij​yj​. Neither aaa nor yyy is assumed nonnegative. If κ\kappaκ is empty, the sum is 000; if ι\iotaι is empty, there is no index iii at which this function can be evaluated.

PrimalDual.FinitePrimalDual.primalObjective: For arbitrary types ι,κ\iota,\kappaι,κ, a chosen Fintype structure on ι\iotaι but no finiteness assumption on κ\kappaκ, a datum PPP with cost c:ι→Rc:\iota\to\mathbb Rc:ι→R, and an arbitrary vector x:ι→Rx:\iota\to\mathbb Rx:ι→R, the primal objective is ∑i∈ιcixi\sum_{i\in\iota}c_i x_i∑i∈ι​ci​xi​. No sign or feasibility assumptions are imposed on ccc or xxx. If ι\iotaι is empty, this objective equals 000.

PrimalDual.FinitePrimalDual.dualObjective: For arbitrary types ι,κ\iota,\kappaι,κ, a chosen Fintype structure on κ\kappaκ but no finiteness assumption on ι\iotaι, a datum PPP with right-hand side b:κ→Rb:\kappa\to\mathbb Rb:κ→R, and an arbitrary vector y:κ→Ry:\kappa\to\mathbb Ry:κ→R, the dual objective is ∑j∈κbjyj\sum_{j\in\kappa}b_j y_j∑j∈κ​bj​yj​. No sign or feasibility assumptions are imposed on bbb or yyy. If κ\kappaκ is empty, this objective equals 000.

PrimalDual.FinitePrimalDual.PrimalFeasible: For arbitrary types ι,κ\iota,\kappaι,κ, a chosen Fintype structure on ι\iotaι but no finiteness assumption on κ\kappaκ, a datum P=(a,b,c)P=(a,b,c)P=(a,b,c), and an arbitrary vector x:ι→Rx:\iota\to\mathbb Rx:ι→R, primal feasibility is exactly the conjunction (∀i∈ι, 0≤xi)(\forall i\in\iota,\ 0\le x_i)(∀i∈ι, 0≤xi​) and (∀j∈κ, bj≤∑i∈ιaijxi)(\forall j\in\kappa,\ b_j\le\sum_{i\in\iota}a_{ij}x_i)(∀j∈κ, bj​≤∑i∈ι​aij​xi​). No separate sign assumptions are imposed on a,b,a,b,a,b, or ccc, and ccc does not occur in the condition. If ι\iotaι is empty, the first clause is vacuous and every displayed sum is 000, so feasibility reduces to bj≤0b_j\le0bj​≤0 for every jjj; if κ\kappaκ is empty, the second clause is vacuous; if both are empty, the proposition holds.

PrimalDual.FinitePrimalDual.DualFeasible: For arbitrary types ι,κ\iota,\kappaι,κ, a chosen Fintype structure on κ\kappaκ but no finiteness assumption on ι\iotaι, a datum P=(a,b,c)P=(a,b,c)P=(a,b,c), and an arbitrary vector y:κ→Ry:\kappa\to\mathbb Ry:κ→R, dual feasibility is exactly the conjunction (∀j∈κ, 0≤yj)(\forall j\in\kappa,\ 0\le y_j)(∀j∈κ, 0≤yj​) and (∀i∈ι, ∑j∈κaijyj≤ci)(\forall i\in\iota,\ \sum_{j\in\kappa}a_{ij}y_j\le c_i)(∀i∈ι, ∑j∈κ​aij​yj​≤ci​). No separate sign assumptions are imposed on a,b,a,b,a,b, or ccc, and bbb does not occur in the condition. If κ\kappaκ is empty, the first clause is vacuous and every displayed sum is 000, so feasibility reduces to 0≤ci0\le c_i0≤ci​ for every iii; if ι\iotaι is empty, the second clause is vacuous; if both are empty, the proposition holds.

PrimalDual.FinitePrimalDual.SatisfiesPrimalApproxCS: For arbitrary types ι,κ\iota,\kappaι,κ, a chosen Fintype structure on κ\kappaκ but no finiteness assumption on ι\iotaι, a datum P=(a,b,c)P=(a,b,c)P=(a,b,c), an arbitrary real number α\alphaα, and arbitrary vectors x:ι→Rx:\iota\to\mathbb Rx:ι→R and y:κ→Ry:\kappa\to\mathbb Ry:κ→R, this proposition asserts that for every i∈ιi\in\iotai∈ι, 0<xi0<x_i0<xi​ implies both ci/α≤∑j∈κaijyjc_i/\alpha\le\sum_{j\in\kappa}a_{ij}y_jci​/α≤∑j∈κ​aij​yj​ and ∑j∈κaijyj≤ci\sum_{j\in\kappa}a_{ij}y_j\le c_i∑j∈κ​aij​yj​≤ci​. It assumes neither primal nor dual feasibility and imposes nothing at indices with xi≤0x_i\le0xi​≤0; hence it holds vacuously if ι\iotaι is empty or xxx has no positive component. The parameter α\alphaα may be any real number, including zero or a negative number; division is total, so ci/0=0c_i/0=0ci​/0=0. If κ\kappaκ is empty, each sum is 000.

PrimalDual.FinitePrimalDual.SatisfiesDualApproxCS: For arbitrary types ι,κ\iota,\kappaι,κ, a chosen Fintype structure on ι\iotaι but no finiteness assumption on κ\kappaκ, a datum P=(a,b,c)P=(a,b,c)P=(a,b,c), an arbitrary real number β\betaβ, and arbitrary vectors x:ι→Rx:\iota\to\mathbb Rx:ι→R and y:κ→Ry:\kappa\to\mathbb Ry:κ→R, this proposition asserts that for every j∈κj\in\kappaj∈κ, 0<yj0<y_j0<yj​ implies both bj≤∑i∈ιaijxib_j\le\sum_{i\in\iota}a_{ij}x_ibj​≤∑i∈ι​aij​xi​ and ∑i∈ιaijxi≤βbj\sum_{i\in\iota}a_{ij}x_i\le\beta b_j∑i∈ι​aij​xi​≤βbj​. It assumes neither primal nor dual feasibility and imposes nothing at indices with yj≤0y_j\le0yj​≤0; hence it holds vacuously if κ\kappaκ is empty or yyy has no positive component. The parameter β\betaβ may be any real number, including zero or a negative number. If ι\iotaι is empty, each sum is 000.

PrimalDual.FinitePrimalDual.IsCoveringPacking: For arbitrary types ι,κ\iota,\kappaι,κ, with no finiteness, nonemptiness, or other typeclass assumptions, and a datum P=(a,b,c)P=(a,b,c)P=(a,b,c), this proposition is a structure whose inhabitant supplies all three proofs ∀i∈ι ∀j∈κ, 0≤aij\forall i\in\iota\,\forall j\in\kappa,\ 0\le a_{ij}∀i∈ι∀j∈κ, 0≤aij​, ∀j∈κ, 0≤bj\forall j\in\kappa,\ 0\le b_j∀j∈κ, 0≤bj​, and ∀i∈ι, 0≤ci\forall i\in\iota,\ 0\le c_i∀i∈ι, 0≤ci​. If ι\iotaι is empty, the coefficient and cost conditions are vacuous; if κ\kappaκ is empty, the coefficient and right-hand-side conditions are vacuous; if both are empty, all three conditions are vacuous.

Human review
  • Endorsed by Shuze Chen · Aug 19, 2026

  • Endorsed by wenxinzhang · Aug 19, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeLaunch a missionPropose a formalization projectFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions.

How Prove2Me works
SKILL.mdTourFAQContactJoin Slack© 2026 Prove2Me