Cauchy–Schwarz Inequality

lean4-proofalgebrainequalitylinear-algebravisualization
u,vuv|\langle u, v \rangle| \leq \|u\| \, \|v\|

Statement

For any two vectors uu and vv in an inner product space:

u,vuv|\langle u, v \rangle| \leq \|u\| \cdot \|v\|

Equality holds if and only if uu and vv are linearly dependent (one is a scalar multiple of the other).

In Rn\mathbb{R}^n with the dot product, this reads:

i=1nuivii=1nui2i=1nvi2\left| \sum_{i=1}^n u_i v_i \right| \leq \sqrt{\sum_{i=1}^n u_i^2} \cdot \sqrt{\sum_{i=1}^n v_i^2}

The geometric consequence: cosθ1|\cos\theta| \leq 1 for the angle θ\theta between two vectors.

Visualization

Worked example in R3\mathbb{R}^3 with u=(1,2,2)u = (1, 2, 2) and v=(2,1,2)v = (2, 1, -2):

u = (1, 2, 2)        v = (2, 1, -2)

  dot product:          norms:
  u·v = 1·2            ‖u‖ = √(1²+2²+2²) = √9 = 3
      + 2·1            ‖v‖ = √(2²+1²+2²) = √9 = 3
      + 2·(-2)
      = 2+2-4 = 0      ‖u‖·‖v‖ = 3·3 = 9

  |u·v| = 0  ≤  9 = ‖u‖·‖v‖   ✓   (vectors are orthogonal)

Another example with u=(1,1,0)u = (1, 1, 0) and v=(1,0,1)v = (1, 0, 1):

QuantityValue
uv=11+10+01u \cdot v = 1{\cdot}1 + 1{\cdot}0 + 0{\cdot}111
u=12+12+02\|u\| = \sqrt{1^2+1^2+0^2}21.414\sqrt{2} \approx 1.414
v=12+02+12\|v\| = \sqrt{1^2+0^2+1^2}21.414\sqrt{2} \approx 1.414
uv\|u\| \cdot \|v\|22
<span class="math-inline" data-latex="u \cdot v
cosθ=(uv)/(uv)\cos\theta = (u\cdot v)/(\|u\|\|v\|)0.50.5, so θ=60°\theta = 60°

When u=(a,a)u = (a, a) and v=(b,b)v = (b, b) (parallel), equality holds: ab+ab=2a22b2=2ab|ab + ab| = \sqrt{2a^2}\cdot\sqrt{2b^2} = 2|ab|.

Proof Sketch

Fix v0v \neq 0 and consider the real-valued function f(t)=utv20f(t) = \|u - tv\|^2 \geq 0:

u22tu,v+t2v20for all tR\|u\|^2 - 2t\langle u,v\rangle + t^2\|v\|^2 \geq 0 \quad \text{for all } t \in \mathbb{R}

This quadratic in tt is always non-negative, so its discriminant must be 0\leq 0:

Δ=4u,v24u2v20\Delta = 4|\langle u,v\rangle|^2 - 4\|u\|^2\|v\|^2 \leq 0

Therefore u,vuv|\langle u, v\rangle| \leq \|u\|\|v\|.

Connections

Cauchy–Schwarz is a cornerstone of analysis and algebra:

  • AM–GM InequalityAM–GM Inequalitya1++anna1ann\frac{a_1+\cdots+a_n}{n} \geq \sqrt[n]{a_1 \cdots a_n}The arithmetic mean is always at least as large as the geometric meanRead more → — a one-dimensional shadow; both follow from convexity / Jensen's inequality
  • Quadratic FormulaQuadratic Formulax=b±b24ac2ax = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}Solve any quadratic equation using the discriminantRead more → — the discriminant condition b24acb^2 \leq 4ac in disguise
  • Binomial TheoremBinomial Theorem(x+y)n=k=0n(nk)xkynk(x+y)^n = \sum_{k=0}^{n} \binom{n}{k} x^k y^{n-k}Expanding powers of a sum via binomial coefficientsRead more → — the "cross term" bound in u+v2\|u+v\|^2 is Cauchy–Schwarz
  • Geometric SeriesGeometric Seriesk=0n1xk=xn1x1\sum_{k=0}^{n-1} x^k = \frac{x^n - 1}{x - 1}Partial sums and convergence of the geometric progressionRead more → — Bessel's inequality for orthonormal expansions uses Cauchy–Schwarz
  • Vieta Formulas — in the Gram matrix approach to polynomial roots, Cauchy–Schwarz controls error

Lean4 Proof

Mathlib provides norm_inner_le_norm in Mathlib.Analysis.InnerProductSpace.Basic, which is exactly the Cauchy–Schwarz inequality for inner product spaces.

Lean4 Proof

import Mathlib.Analysis.InnerProductSpace.Basic

/-- Cauchy–Schwarz inequality: the norm of the inner product is bounded by
    the product of the norms. This is `norm_inner_le_norm` in Mathlib.  -/
theorem cauchy_schwarz
    {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace  E]
    (u v : E) : ‖(inner u v : )‖  ‖u‖ * ‖v‖ :=
  norm_inner_le_norm u v

/-- Consequence: the cosine of the angle between two vectors has absolute value ≤ 1. -/
theorem cos_angle_le_one
    {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace  E]
    (u v : E) (hu : ‖u‖  0) (hv : ‖v‖  0) :
    ‖(inner u v : )‖ / (‖u‖ * ‖v‖)  1 := by
  apply div_le_one_of_le
  · exact norm_inner_le_norm u v
  · positivity

/-- The real dot-product version: (Σ uᵢvᵢ)² ≤ (Σ uᵢ²)(Σ vᵢ²). -/
theorem cauchy_schwarz_sum (n : ) (u v : Fin n  ) :
    (∑ i, u i * v i) ^ 2  (∑ i, u i ^ 2) * (∑ i, v i ^ 2) := by
  have h := norm_inner_le_norm (𝕜 := ) (E := EuclideanSpace  (Fin n)) u v
  simp only [EuclideanSpace.inner_eq_star_mulVec, Matrix.dotProduct, EuclideanSpace.norm_sq] at h
  nlinarith [sq_nonneg (∑ i, u i * v i), h]