A formal proof, in Lean 4 with Mathlib, of the first-order optimality condition for minimizing a convex, not necessarily differentiable function over a convex set:
Let
f : ℝⁿ → ℝbe convex andD ⊆ ℝⁿconvex. A pointx ∈ DminimizesfoverDif and only if there is a subgradientv ∈ ∂f(x)withvᵀ(y − x) ≥ 0for ally ∈ D, that is,0 ∈ ∂f(x) + N_D(x).
This was asked on MathOverflow, question 167745 (2014), as the nonsmooth version of Boyd–Vandenberghe, Convex Optimization, Section 4.2.3.
theorem NonsmoothOptimality.isMinOn_iff_exists_subgradient : OptimalityStatement
-- where
def OptimalityStatement : Prop :=
∀ (n : ℕ) (f : EuclideanSpace ℝ (Fin n) → ℝ) (D : Set (EuclideanSpace ℝ (Fin n))),
ConvexOn ℝ Set.univ f → Convex ℝ D → ∀ x ∈ D,
(IsMinOn f D x ↔
∃ v : EuclideanSpace ℝ (Fin n),
(∀ y, f x + inner ℝ v (y - x) ≤ f y) ∧ ∀ y ∈ D, 0 ≤ inner ℝ v (y - x))#print axioms NonsmoothOptimality.isMinOn_iff_exists_subgradient reports only propext,
Classical.choice, Quot.sound. CI enforces this, and it also fails on any warning, including a
sorry.
Reading of the statement:
fis real valued and convex on all ofℝⁿ, as in the question. Thenfis continuous and the sum rule∂(f + δ_D) = ∂f + N_Dneeds no constraint qualification. For extended-valuedfone would need one, for exampleri(dom f) ∩ ri D ≠ ∅.Dis only assumed convex, not closed and not nonempty;x ∈ Dis a hypothesis.- Optimality is Mathlib's
IsMinOn f D x. Mathlib has no subdifferential, sov ∈ ∂f(x)is written out as the subgradient inequalityf x + ⟪v, y − x⟫ ≤ f yfor everyy ∈ ℝⁿ.
This is a textbook theorem, not a new one: it is the case of finite f in Rockafellar, Convex
Analysis (1970), Section 27, and the MathOverflow question was answered by its author in an
edit, via the sum rule. What is new here is only the formal proof. Mathlib has no subdifferential;
optlib has the unconstrained version
(first_order_convex_iff_subgradient) and the sum rule for finite convex functions, but not this
constrained form.
The easy direction (⇐) is the subgradient inequality: f y ≥ f x + vᵀ(y − x) ≥ f x for y ∈ D.
For (⇒), in NonsmoothOptimality/Main.lean:
fis convex and finite onℝⁿ, hence continuous (ConvexOn.continuousOn), so the strict epigraphS = {(y, t) : f(y) < t}is open and convex inℝⁿ × ℝ;Sis disjoint from the convex setT = D × {f(x)}, becausexis optimal;- Hahn–Banach (
geometric_hahn_banach_open) gives a continuous linearφanduwithφ < uonSandu ≤ φonT; - write
φ(y, r) = w(y) + α r. Testing with(x, f(x) + 1)givesα < 0, and lettingε → 0in(y, f(y) + ε) ∈ Sgivesw(y) + α f(y) ≤ u ≤ w(x) + α f(x)for everyy; - hence
v = w / (−α), a vector by the Riesz isomorphism, is a subgradient atx, andw(d − x) ≥ 0ford ∈ Dbecause(d, f(x)) ∈ T.
| File | Content |
|---|---|
NonsmoothOptimality/Statement.lean |
the statement OptimalityStatement |
NonsmoothOptimality/Main.lean |
the proof isMinOn_iff_exists_subgradient |
verify/Axioms.lean, verify/check_axioms.py |
axiom check run by CI |
The same statement is problem mo-167745 on
Left to Solve, which collects Lean statements of open and known problems.
The proposition in Statement.lean is word for word the Lean statement submitted there, and the
toolchain and Mathlib pins below are those of its checker (google-deepmind/formal-conjectures at
commit 9097e2f), so the proof checks against the same Mathlib in both places.
- Statement: lefttosolve2/open-math-agents#110030, waiting for a human review of the translation.
- Proof: submitted there after the statement is merged.
Toolchain leanprover/lean4:v4.33.1, Mathlib 0df444a.
lake exe cache get # Mathlib build cache
lake build # under a minute after the cache
lake env lean verify/Axioms.leanThis repository was written with substantial assistance from Claude (Anthropic), including the
statement and the Lean proof. A second model (Google Gemini) reviewed the formal statement against
the question. Lean checks the proof; humans should still check that the statement in
NonsmoothOptimality/Statement.lean says what is claimed.
Apache-2.0.