Lagrange Multipliers

lean4-proofoptimizationvisualization
f(x)=λg(x)\nabla f(x^*) = \lambda\, \nabla g(x^*)

Statement

To find the extrema of f:RnRf : \mathbb{R}^n \to \mathbb{R} subject to the constraint g(x)=0g(x) = 0, introduce a multiplier λR\lambda \in \mathbb{R} and require:

f(x)=λg(x).\nabla f(x^*) = \lambda\, \nabla g(x^*).

Geometrically: at the constrained extremum, the level set of ff and the constraint surface g=0g = 0 are tangent — their normals are parallel.

Concrete example. Maximise f(x,y)=xyf(x,y) = xy subject to g(x,y)=x+y4=0g(x,y) = x + y - 4 = 0.

Lagrangian: L=xyλ(x+y4)\mathcal{L} = xy - \lambda(x + y - 4).

First-order conditions: y=λy = \lambda and x=λx = \lambda, so x=yx = y. From x+y=4x + y = 4: x=y=2x^* = y^* = 2, λ=2\lambda = 2, f(x)=4f(x^*) = 4.

Visualization

Level curves of f(x,y)=xyf(x,y) = xy (hyperbolas) and the constraint x+y=4x + y = 4 (line):

  y
  4 *
    |\ tangent point at (2,2)
  3 | \  xy = 4  (tangent level curve)
    |  *------
  2 |  |(2,2)  <-- optimum
    |  |    \
  1 |  |     xy = 1
    |  |
  0 +--+--+--*---  x
     0  1  2  4

At the optimum (2,2)(2,2): f=(y,x)=(2,2)\nabla f = (y,x) = (2,2) and g=(1,1)\nabla g = (1,1), so f=2g\nabla f = 2 \cdot \nabla g, confirming λ=2\lambda = 2.

(x,y)(x,y)xyxyx+yx + yfeasible?
(1,3)(1, 3)34yes
(2,2)(2, 2)44yes (max)
(3,1)(3, 1)34yes
(0,4)(0, 4)04yes

Proof Sketch

  1. Parametrise the constraint: the feasible set is a smooth manifold M={g=0}M = \{g = 0\}.
  2. Tangent condition: at a constrained extremum, f(x)\nabla f(x^*) must be orthogonal to every tangent vector of MM, i.e., f(x)ker(g(x))\nabla f(x^*) \perp \ker(\nabla g(x^*)).
  3. Linear algebra: vker(L)v \perp \ker(L) iff vrange(L)v \in \text{range}(L^\top) — so f=λg\nabla f = \lambda \nabla g.
  4. Mathlib: IsLocalExtrOn.exists_multipliers_of_hasStrictFDerivAt_1d provides the rigorous 1D-constraint version in Mathlib.Analysis.Calculus.LagrangeMultipliers.

For maxxy\max xy s.t. x+y=4x + y = 4: verified directly that f(2,2)=4f(x,y)f(2,2) = 4 \ge f(x,y) for all (x,y)(x,y) with x+y=4x + y = 4.

Connections

  • KKT ConditionsKKT Conditionsf(x)=iλigi(x),λigi(x)=0,λi0\nabla f(x^*) = \sum_i \lambda_i \nabla g_i(x^*),\quad \lambda_i g_i(x^*) = 0,\quad \lambda_i \ge 0Necessary optimality conditions for constrained optimization via Lagrangian gradient and complementary slacknessRead more → — KKT conditions extend Lagrange multipliers to inequality constraints with sign conditions on λ\lambda
  • Mean Value TheoremMean Value Theoremc(a,b)  :  f(c)=f(b)f(a)ba\exists\, c \in (a,b)\;:\; f'(c) = \frac{f(b)-f(a)}{b-a}There exists a point where the instantaneous rate of change equals the average rate of changeRead more → — the proof of Lagrange multipliers uses the MVT to construct the tangent parametrisation
  • Cauchy–Schwarz InequalityCauchy–Schwarz Inequalityu,vuv|\langle u, v \rangle| \leq \|u\| \, \|v\|The inner product of two vectors is bounded by the product of their normsRead more → — Cauchy–Schwarz maximises u,v\langle u, v \rangle subject to u=v=1\|u\| = \|v\| = 1 via Lagrange multipliers
  • Spectral TheoremSpectral TheoremA=QΛQT  (real symmetric case)A = Q \Lambda Q^T \;\text{(real symmetric case)}Every real symmetric matrix is orthogonally diagonalizableRead more → — eigenvalue problems are Lagrange multiplier problems: maxAx,x\max \langle Ax, x \rangle s.t. x=1\|x\| = 1

Lean4 Proof

import Mathlib.Analysis.InnerProductSpace.Basic

/-- The Lagrange optimum for max xy s.t. x+y=4 is (2,2) with value 4.
    Any feasible (x,y) satisfies xy ≤ 4. -/
theorem lagrange_max_product :
     x y : , x + y = 4  x * y  4 := by
  intro x y hxy
  nlinarith [sq_nonneg (x - y)]