Foundations to Frontier
Tests
A. Mathematical Foundations › A1 Prerequisites and Mathematical Thinking

Inequalities: AM–GM, Cauchy–Schwarz, Triangle, Jensen

Four inequalities that bound, compare and estimate. They show up in proofs of convergence, generalization, variational inference and robot safety.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

The shortest path

You want to walk from your house to the park. You can walk straight there, or stop at a friend’s house on the way. The detour can never be shorter than walking straight. At best it’s equal, if your friend lives exactly on the straight line. This simple idea is the triangle inequality.

The best fence

You have 16 metres of fence and want to make a rectangular garden with the most space inside.

Shape Sides Space inside
Long and thin 7 × 1 7
Rectangle 6 × 2 12
Rectangle 5 × 3 15
Square 4 × 4 16 ← the most!

For a fixed amount of fence, the square always wins. This is the idea behind the AM–GM inequality.

Averages of bowls

Some shapes curve upward like a bowl. Pick two points on the bowl and connect them with a straight string. The string always sits above the bowl. That’s Jensen’s inequality, and AI uses it to make hard calculations easier.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Going from A to B directly is 5 km. Going through C is 3 km + 4 km. Which is shorter?
  2. 2. With 20 metres of fence, which rectangle holds the most space?
  3. 3. A string between two points on a bowl-shaped curve is…

Level 1: Beginner

★★☆☆☆ Basic⏱ 15 minSecondary-school mathematics: arithmetic and elementary algebra.

AM–GM for two numbers

For any two non-negative numbers a,ba, b:

a+b2⏟arithmetic mean ≥ ab⏟geometric mean\underbrace{\frac{a + b}{2}}_{\text{arithmetic mean}} \ \ge\ \underbrace{\sqrt{ab}}_{\text{geometric mean}}

with equality exactly when a=ba = b. Example: a=4,b=9a = 4, b = 9. AM = 6.5, GM = 6.

The fence, explained. With perimeter PP, the sides satisfy w+h=P/2w + h = P/2. AM–GM gives wh≤w+h2=P4\sqrt{wh} \le \frac{w+h}{2} = \frac{P}{4}, so the area wh≤(P/4)2wh \le (P/4)^2. Equality needs w=hw = h: a square.

The triangle inequality

For numbers: ∣a+b∣≤∣a∣+∣b∣\lvert a + b \rvert \le \lvert a\rvert + \lvert b\rvert. For example, ∣−3+5∣=2≤3+5=8\lvert -3 + 5\rvert = 2 \le 3 + 5 = 8.

For distances between points: d(A,C)≤d(A,B)+d(B,C)d(A, C) \le d(A, B) + d(B, C). In any triangle, each side is shorter than the other two combined. So if two sides are 3 and 5, the third is less than 8 (and more than 2).

Cauchy–Schwarz in 2D

For vectors (a1,a2)(a_1, a_2) and (b1,b2)(b_1, b_2):

∣a1b1+a2b2∣≤a12+a22 b12+b22\lvert a_1 b_1 + a_2 b_2 \rvert \le \sqrt{a_1^2 + a_2^2}\,\sqrt{b_1^2 + b_2^2}

The left side is the dot product. The right side is the product of the two lengths. In words, the dot product can never be bigger than the lengths multiplied.

📝 Quick check (Level 1)
0/3 answered
  1. 1. AM and GM of 2 and 8?
  2. 2. Two sides of a triangle are 4 and 7. The third side must be…
  3. 3. When does AM = GM?

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 35 minUndergraduate students and practising engineers.

The general forms

AM–GM–HM. For positive x1,…,xnx_1, \dots, x_n:

x1+⋯+xnn ≥ x1⋯xnn ≥ n1x1+⋯+1xn\frac{x_1 + \dots + x_n}{n} \ \ge\ \sqrt[n]{x_1 \cdots x_n} \ \ge\ \frac{n}{\frac1{x_1} + \dots + \frac1{x_n}}

with equality exactly when all the xix_i are equal.

Cauchy–Schwarz. For vectors in Rn\mathbb{R}^n:

∣x⋅y∣=∣∑ixiyi∣≤∥x∥ ∥y∥\lvert \mathbf x \cdot \mathbf y \rvert = \Big\lvert\sum_i x_i y_i\Big\rvert \le \lVert \mathbf x\rVert\,\lVert \mathbf y \rVert

with equality exactly when one vector is a multiple of the other.

Triangle inequality for vectors. ∥x+y∥≤∥x∥+∥y∥\lVert \mathbf x + \mathbf y\rVert \le \lVert \mathbf x\rVert + \lVert \mathbf y\rVert. Its “reverse” form is ∣∥x∥−∥y∥∣≤∥x−y∥\big\lvert \lVert\mathbf x\rVert - \lVert \mathbf y\rVert \big\rvert \le \lVert \mathbf x - \mathbf y\rVert.

Jensen’s inequality. A function is convex if every chord lies above its graph. For convex ff, weights ti≥0t_i \ge 0 with ∑ti=1\sum t_i = 1:

f(∑itixi)≤∑itif(xi),in probability language: f(E[X])≤E[f(X)]f\Big(\sum_i t_i x_i\Big) \le \sum_i t_i f(x_i), \qquad \text{in probability language: } f(\mathbb E[X]) \le \mathbb E[f(X)]

For a concave function such as ln⁡\ln, the inequality flips: ln⁡E[X]≥E[ln⁡X]\ln \mathbb{E}[X] \ge \mathbb{E}[\ln X].

Jensen's inequality: the chord sits above a convex curve
f(average) = 0.000  vs  average of f = 4.410 → gap = 4.410 (≥ 0 for a convex function)

Why ML needs these

Inequality Where it’s used
Cauchy–Schwarz Cosine similarity x⋅y∥x∥∥y∥∈[−1,1]\frac{\mathbf x\cdot\mathbf y}{\lVert\mathbf x\rVert\lVert\mathbf y\rVert} \in [-1, 1] in search, embeddings and RAG
Triangle inequality Makes distance a metric. Lets kNN and vector search skip far-away candidates (ball trees, D4)
Jensen The ELBO in variational autoencoders. Proving KL divergence ≥ 0. Why E[X2]≥(EX)2\mathbb E[X^2] \ge (\mathbb E X)^2, so variance is ≥ 0
AM–GM Bounding products by sums in convergence proofs. The fence problem is a tiny constrained optimization
🐍 Exercise 1: cosine similarity and the triangle inequality
Write norm, cosine_similarity and distance. The tests check Cauchy–Schwarz and the triangle inequality on 1000 random vectors.
📝 Quick check (Level 2)
0/3 answered
  1. 1. What is the minimum of x + 1/x for x > 0?
  2. 2. Cosine similarity of (1, 0) and (1, 1)?
  3. 3. For the convex f(x) = x², Jensen says…

Level 3: Advanced

★★★★☆ Advanced⏱ 50 minGraduate level, with full derivations and proofs.

Proofs

AM–GM for two numbers

For a,b≥0a, b \ge 0: a+b2≥ab\frac{a+b}{2} \ge \sqrt{ab}, with equality if and only if a=ba = b.

Proof. 0≤(a−b)2=a−2ab+b0 \le (\sqrt a - \sqrt b)^2 = a - 2\sqrt{ab} + b. Rearrange. Equality holds exactly when a=b\sqrt a = \sqrt b. ∎

Cauchy–Schwarz inequality

For x,y∈Rn\mathbf x, \mathbf y \in \mathbb{R}^n: ∣x⋅y∣≤∥x∥∥y∥\lvert \mathbf x \cdot \mathbf y\rvert \le \lVert\mathbf x\rVert\lVert\mathbf y\rVert.

Proof. If y=0\mathbf y = 0, both sides are 0. Otherwise, for every real tt:

0≤∥x−ty∥2=∥y∥2t2−2(x⋅y) t+∥x∥2.0 \le \lVert \mathbf x - t\mathbf y\rVert^2 = \lVert\mathbf y\rVert^2 t^2 - 2(\mathbf x\cdot\mathbf y)\,t + \lVert\mathbf x\rVert^2.

A quadratic in tt that’s never negative has discriminant ≤0\le 0: 4(x⋅y)2−4∥x∥2∥y∥2≤04(\mathbf x \cdot \mathbf y)^2 - 4\lVert\mathbf x\rVert^2\lVert\mathbf y\rVert^2 \le 0. ∎ Equality means x−ty=0\mathbf x - t\mathbf y = 0 for some tt, so the vectors are parallel.

Triangle inequality

∥x+y∥≤∥x∥+∥y∥\lVert \mathbf x + \mathbf y\rVert \le \lVert\mathbf x\rVert + \lVert\mathbf y\rVert.

Proof. ∥x+y∥2=∥x∥2+2 x⋅y+∥y∥2≤∥x∥2+2∥x∥∥y∥+∥y∥2=(∥x∥+∥y∥)2\lVert\mathbf x + \mathbf y\rVert^2 = \lVert\mathbf x\rVert^2 + 2\,\mathbf x\cdot\mathbf y + \lVert\mathbf y\rVert^2 \le \lVert\mathbf x\rVert^2 + 2\lVert\mathbf x\rVert\lVert\mathbf y\rVert + \lVert\mathbf y\rVert^2 = (\lVert\mathbf x\rVert + \lVert\mathbf y\rVert)^2, using Cauchy–Schwarz. ∎

Jensen's inequality (finite form)

If ff is convex, ti≥0t_i \ge 0 and ∑i=1nti=1\sum_{i=1}^n t_i = 1, then f(∑tixi)≤∑tif(xi)f(\sum t_i x_i) \le \sum t_i f(x_i).

Proof by induction on nn. n=2n = 2 is the definition of convexity. For n+1n+1 points with tn+1<1t_{n+1} < 1, write ∑i=1n+1tixi=(1−tn+1) xˉ+tn+1xn+1\sum_{i=1}^{n+1} t_i x_i = (1 - t_{n+1})\,\bar x + t_{n+1} x_{n+1}, where xˉ=∑i≤nti1−tn+1xi\bar x = \sum_{i \le n} \frac{t_i}{1 - t_{n+1}} x_i. Apply the two-point case, then the induction hypothesis to f(xˉ)f(\bar x). ∎

AM–GM for n numbers, via Jensen

ln⁡\ln is concave, so ln⁡(1n∑xi)≥1n∑ln⁡xi=ln⁡∏xin\ln\left(\frac1n\sum x_i\right) \ge \frac1n\sum \ln x_i = \ln \sqrt[n]{\prod x_i}. Exponentiate. ∎

Two generalizations

  • Hölder’s inequality. For p,q>1p, q > 1 with 1p+1q=1\frac1p + \frac1q = 1: ∑∣xiyi∣≤∥x∥p∥y∥q\sum \lvert x_i y_i\rvert \le \lVert\mathbf x\rVert_p\lVert\mathbf y\rVert_q, where ∥x∥p=(∑∣xi∣p)1/p\lVert\mathbf x\rVert_p = (\sum\lvert x_i\rvert^p)^{1/p}. With p=q=2p = q = 2, this is Cauchy–Schwarz.
  • Minkowski’s inequality. ∥x+y∥p≤∥x∥p+∥y∥p\lVert\mathbf x + \mathbf y\rVert_p \le \lVert\mathbf x\rVert_p + \lVert\mathbf y\rVert_p for p≥1p \ge 1. It’s why the LpL^p “norms” really are norms when p≥1p \ge 1. For p<1p < 1 it fails (Practice Code 3).
Exercise 3.1: Maximise xyz subject to x + y + z = 12 with x, y, z positive

AM–GM: xyz3≤x+y+z3=4\sqrt[3]{xyz} \le \frac{x+y+z}{3} = 4, so xyz≤64xyz \le 64, with equality at x=y=z=4x = y = z = 4. The answer is 64.

Exercise 3.2: Prove (a + b)(1/a + 1/b) ≥ 4 for positive a and b

Apply Cauchy–Schwarz to (a,b)(\sqrt a, \sqrt b) and (1/a,1/b)(1/\sqrt a, 1/\sqrt b): (1+1)2≤(a+b)(1/a+1/b)(1 + 1)^2 \le (a + b)(1/a + 1/b). Equality holds when a=ba = b.

📝 Quick check (Level 3)
0/3 answered
  1. 1. In the Cauchy–Schwarz proof, which fact gives the inequality?
  2. 2. Hölder with p = 3 pairs with q = …
  3. 3. Is ‖x‖₀.₅ = (Σ|xᵢ|^0.5)² a norm?

Level 4: Expert

★★★★★ Expert⏱ 35 minResearchers: original papers and open problems.

Jensen powers variational inference

For a model with hidden variables zz, the likelihood ln⁡p(x)=ln⁡∫p(x,z) dz\ln p(x) = \ln \int p(x, z)\,dz is usually impossible to compute. Pick any distribution q(z)q(z) and use Jensen with the concave ln⁡\ln:

ln⁡p(x)=ln⁡Eq[p(x,z)q(z)] ≥ Eq[ln⁡p(x,z)q(z)]=:ELBO.\ln p(x) = \ln \mathbb{E}_{q}\Big[\frac{p(x,z)}{q(z)}\Big] \ \ge\ \mathbb{E}_{q}\Big[\ln\frac{p(x,z)}{q(z)}\Big] =: \text{ELBO}.

The gap is exactly KL(q(z) ∥ p(z∣x))≥0\mathrm{KL}(q(z)\,\Vert\,p(z\mid x)) \ge 0. Maximizing the ELBO is the training objective of variational autoencoders (Kingma and Welling, 2014) and of variational inference in general (Jordan et al., 1999). It’s also the basis of diffusion-model training losses (H3, H7).

🐍 Exercise 2 (research): measure the Jensen gap
Compute log(E[X]) − E[log X] for samples of a lognormal X. Watch the gap (what the ELBO loses) shrink as X becomes less random.

KL divergence is non-negative (Gibbs’ inequality). −KL(p∥q)=Ep[ln⁡(q/p)]≤ln⁡Ep[q/p]=ln⁡∑q=0-\mathrm{KL}(p\Vert q) = \mathbb{E}_p[\ln(q/p)] \le \ln \mathbb{E}_p[q/p] = \ln \sum q = 0. This one line underlies much of information theory (A7).

From inequalities to probability bounds

  • Markov: for X≥0X \ge 0, P(X≥a)≤E[X]/aP(X \ge a) \le \mathbb{E}[X]/a.
  • Chebyshev: P(∣X−μ∣≥kσ)≤1/k2P(\lvert X - \mu\rvert \ge k\sigma) \le 1/k^2.
  • These lead to the concentration inequalities (Hoeffding, Bernstein; A4.3) that power generalization bounds in learning theory (B2).

Inequalities that keep robots safe

  • Safety certificates. A control barrier function requires h˙(x)≥−α h(x)\dot h(x) \ge -\alpha\,h(x). An inequality on the dynamics guarantees the robot never leaves the safe set h(x)≥0h(x) \ge 0 (S6).
  • Lyapunov stability. Show the “energy” VV satisfies V˙≤−cV\dot V \le -cV. Then V(t)≤V(0)e−ctV(t) \le V(0)e^{-ct}, an exponential decay guarantee (S3).
  • Collision checking. Bounding volumes and the triangle inequality let planners rule out collisions quickly without exact geometry (U1).

Open directions

Many deep-learning theory results are inequalities that are true but too loose to be useful. Making them tight, for example PAC-Bayes and compression bounds for large networks, is active research. In robotics, verifying neural network controllers means proving inequalities over every possible input in a region (M2).

References

  1. A.-L. Cauchy (1821). Cours d’analyse de l’École Royale Polytechnique.
  2. V. Bunyakovsky (1859). Mémoires de l’Académie impériale des sciences de St-Pétersbourg, 1(9). (The integral form.)
  3. H. A. Schwarz (1888). “Über ein die Flächen kleinsten Flächeninhalts betreffendes Problem der Variationsrechnung.” Acta Societatis Scientiarum Fennicae, 15.
  4. J. L. W. V. Jensen (1906). “Sur les fonctions convexes et les inégalités entre les valeurs moyennes.” Acta Mathematica, 30.
  5. G. H. Hardy, J. E. Littlewood, G. Pólya (1934). Inequalities. Cambridge University Press.
  6. M. Jordan, Z. Ghahramani, T. Jaakkola, L. Saul (1999). “An introduction to variational methods for graphical models.” Machine Learning, 37.
  7. J. M. Steele (2004). The Cauchy–Schwarz Master Class. Cambridge University Press.
  8. D. Kingma and M. Welling (2014). “Auto-encoding variational Bayes.” ICLR.
  9. A. Ames et al. (2019). “Control barrier functions: theory and applications.” European Control Conference.