Search

Search papers and lessons

Cauchy–Schwarz Inequality

Level 2 · 11 min read

The Cauchy–Schwarz inequality says a dot product is never larger than the product of the two vector lengths, with equality only when the vectors point along one line.

On this page

  • Colour = topic mix
  • Discrete math
  • Linear algebra
  • ReadReady to readNot yet

TL;DR

The Cauchy–Schwarz inequality says that the dot product of two vectors is never larger than the product of their lengths. It gives a hard upper limit on how much two vectors can line up, and it is the reason the cosine of the angle between two vectors always lies between minus one and one. Equality holds only when one vector is a multiple of the other.

Builds on: Vector Norm, Dot Product · Leads to: Large Sieve Inequality (an analysis result that uses the same bound), Hilbert Space (where the same inequality holds for functions)

Where it's used

Correlation in statistics. Treat two lists of measurements, after centring each around its mean, as two vectors. Their dot product divided by the product of their lengths is the correlation coefficient. Cauchy–Schwarz is exactly the reason that this number cannot be bigger than 1 or smaller than minus 1.

Search and text similarity. A search engine turns each document into a vector of word counts, then ranks documents by how closely their vectors point in the same direction, measured by cosine similarity. The cosine is always between minus one and one, because the inequality bounds the dot product by the lengths.

Machine learning proofs. Many convergence proofs for gradient methods bound a dot product between a gradient and a step by the product of their sizes. The bound is the first line of the argument, and the rest of the proof works with the resulting number. The same bound also yields the triangle inequality for lengths, which is what lets us say that the length of a sum is at most the sum of lengths.

How it works

Take two small vectors in the plane, u=(3,4)u = (3, 4) and v=(1,2)v = (1, 2), and check the inequality by hand.

  1. Pick the two vectors. u=(3,4)u = (3, 4) and v=(1,2)v = (1, 2). Each is a point, or an arrow from the origin.

  2. Compute the dot product. Multiply matching entries and add: 3⋅1+4⋅2=3+8=113 \cdot 1 + 4 \cdot 2 = 3 + 8 = 11. Check: the answer is a single number, not a vector.

  3. Compute the two lengths. The length of uu is 32+42=25=5\sqrt{3^2 + 4^2} = \sqrt{25} = 5. The length of vv is 12+22=5≈2.236\sqrt{1^2 + 2^2} = \sqrt{5} \approx 2.236. Check: each length is a square root of a sum of squares.

  4. Multiply the lengths. 5×2.236=11.185 \times 2.236 = 11.18, to two decimals. Check: this is the largest value the dot product is allowed to take.

  5. Compare. The dot product 1111 is less than 11.1811.18, so the inequality holds. A cleaner way to see the same fact is to square both sides: 112=12111^2 = 121 and (55)2=125(5\sqrt{5})^2 = 125, and 121≤125121 \le 125. Check: the gap is small, so these two vectors point fairly close to the same direction.

  6. See equality. Now take w=(6,8)w = (6, 8), which is 2u2u. Its dot product with uu is 18+32=5018 + 32 = 50, and the product of lengths is 5×10=505 \times 10 = 50. The two sides are equal. Check: ww points along the same line as uu, and that is the only way to reach equality.

The plot below shows the ratio in step 5 as an angle. The dot product divided by the product of lengths is the cosine of the angle between the vectors, so it can never leave the band between minus one and one.

0123456−1−0.500.51angle between the vectors (radians)dot product divided by product of lengths
  • cos of the angle between two vectors
  • upper limit 1
  • lower limit -1
The ratio is cos of the angle, so it stays inside the band from minus one to one. It reaches one when the vectors point the same way and minus one when they point opposite ways.

The math

Definition: Cauchy–Schwarz inequality

For any two vectors uu and vv in Rn\mathbb{R}^n,

∣⟨u,v⟩∣≤∥u∥ ∥v∥.|\langle u, v \rangle| \le \lVert u \rVert \, \lVert v \rVert.

Equality holds if and only if one of the vectors is a scalar multiple of the other, that is, u=tvu = t v or v=tuv = t u for some number tt.

In words: the absolute value of the dot product is at most the product of the lengths. The absolute value on the left covers vectors that point in opposite directions, where the dot product is negative.

Step 2 in symbols: the ratio form

When uu and vv are both nonzero, divide both sides by ∥u∥∥v∥\lVert u \rVert \lVert v \rVert:

−1≤⟨u,v⟩∥u∥ ∥v∥≤1.-1 \le \frac{\langle u, v \rangle}{\lVert u \rVert \, \lVert v \rVert} \le 1.

The middle quantity is, by definition, the cosine of the angle θ\theta between uu and vv, so this says exactly cos⁡θ∈[−1,1]\cos \theta \in [-1, 1], which is true for every angle. The plot in the walkthrough draws this ratio.

Step 3 in symbols: the proof

The idea is to look at the length of u−tvu - t v, a vector that is uu with the part along vv removed for a suitable tt. Its squared length is never negative:

0≤∥u−tv∥2=∥u∥2−2t⟨u,v⟩+t2∥v∥2.0 \le \lVert u - t v \rVert^2 = \lVert u \rVert^2 - 2t \langle u, v \rangle + t^2 \lVert v \rVert^2.

This holds for every number tt. Assume v≠0v \ne 0 and choose t=⟨u,v⟩/∥v∥2t = \langle u, v \rangle / \lVert v \rVert^2. This is the value that makes u−tvu - tv perpendicular to vv, since ⟨u−tv,v⟩=⟨u,v⟩−t∥v∥2=0\langle u - tv, v \rangle = \langle u, v \rangle - t \lVert v \rVert^2 = 0, so the leftover piece is exactly the part of uu that is not along vv. Substituting gives

0≤∥u∥2−2⟨u,v⟩2∥v∥2+⟨u,v⟩2∥v∥2=∥u∥2−⟨u,v⟩2∥v∥2.0 \le \lVert u \rVert^2 - \frac{2\langle u, v \rangle^2}{\lVert v \rVert^2} + \frac{\langle u, v \rangle^2}{\lVert v \rVert^2} = \lVert u \rVert^2 - \frac{\langle u, v \rangle^2}{\lVert v \rVert^2}.

Multiply by ∥v∥2\lVert v \rVert^2 and rearrange to get ⟨u,v⟩2≤∥u∥2∥v∥2\langle u, v \rangle^2 \le \lVert u \rVert^2 \lVert v \rVert^2. Taking square roots gives the inequality.

Step 4 in symbols: equality

Equality in the proof forces ∥u−tv∥2=0\lVert u - t v \rVert^2 = 0, which means u−tv=0u - tv = 0, so u=tvu = tv. The converse is a direct check: if u=tvu = tv, both sides equal ∣t∣∥v∥2|t| \lVert v \rVert^2. This is why equality needs the vectors to lie on one line.

Worked examples

Example
1. A tiny case (hand-computable)

Take u=(1,0)u = (1, 0) and v=(1,1)v = (1, 1).

  1. Dot product: 1⋅1+0⋅1=11 \cdot 1 + 0 \cdot 1 = 1.
  2. Lengths: ∥u∥=1\lVert u \rVert = 1 and ∥v∥=2≈1.414\lVert v \rVert = \sqrt{2} \approx 1.414.
  3. Product of lengths: 1×1.414=1.4141 \times 1.414 = 1.414.
  4. Compare: 1≤1.4141 \le 1.414, so the inequality holds with room to spare.
  5. The cosine is 1/1.414≈0.7071 / 1.414 \approx 0.707, which is the cosine of 45∘45^\circ.

Interpretation: the vectors are at a 45 degree angle, so they are not parallel and the inequality is strict.

Example
2. The standard case (the walkthrough pair)

Take u=(3,4)u = (3, 4) and v=(1,2)v = (1, 2).

  1. Dot product: 3⋅1+4⋅2=113 \cdot 1 + 4 \cdot 2 = 11.
  2. Lengths: ∥u∥=5\lVert u \rVert = 5 and ∥v∥=5\lVert v \rVert = \sqrt{5}.
  3. Product of lengths: 55=1255 \sqrt{5} = \sqrt{125}.
  4. Squared comparison: 112=12111^2 = 121 and 125125, and 121≤125121 \le 125.
  5. Cosine: 11/125≈0.98411 / \sqrt{125} \approx 0.984.

Interpretation: the cosine is close to one, so the vectors point in nearly the same direction, but they are not parallel.

Example
3. A realistic case: comparing two documents

Two short documents are described by counts of the words cat, dog and fish. Document AA has counts (3,0,1)(3, 0, 1) and document BB has counts (1,2,0)(1, 2, 0).

  1. Dot product: 3⋅1+0⋅2+1⋅0=33 \cdot 1 + 0 \cdot 2 + 1 \cdot 0 = 3.
  2. Lengths: ∥A∥=9+0+1=10≈3.162\lVert A \rVert = \sqrt{9 + 0 + 1} = \sqrt{10} \approx 3.162 and ∥B∥=1+4+0=5≈2.236\lVert B \rVert = \sqrt{1 + 4 + 0} = \sqrt{5} \approx 2.236.
  3. Product of lengths: 3.162×2.236≈7.073.162 \times 2.236 \approx 7.07.
  4. Compare: 3≤7.073 \le 7.07, so the inequality holds.
  5. Cosine similarity: 3/7.07≈0.423 / 7.07 \approx 0.42.

Interpretation: a cosine of about 0.42 says the documents share some vocabulary, but they differ a lot. The bound from the inequality is what keeps this score on a fixed scale, so documents of very different length can still be compared.

Try it: documents C=(2,2,2)C = (2, 2, 2) and D=(1,1,1)D = (1, 1, 1). What are the dot product, the product of lengths, and the cosine? Answer: the dot product is 2+2+2=62 + 2 + 2 = 6. The lengths are 12\sqrt{12} and 3\sqrt{3}, whose product is 36=6\sqrt{36} = 6. So the two sides are equal and the cosine is 1. This is correct because C=2DC = 2D, so the documents point the same way.

Common mistakes and tradeoffs

It is tempting to think the bound is the sum of the two lengths. In fact it is their product. Take u=v=(10,0)u = v = (10, 0): the dot product is 100100, while the sum of the lengths is 2020, so the sum would be a false bound. The product 10×10=10010 \times 10 = 100 is exactly right.

It is tempting to think equality means the two vectors are the same. In fact equality means they are parallel, so v=2uv = 2u or v=−uv = -u also reach it. The absolute value on the left is what lets opposite directions count.

It is tempting to think the inequality needs unit vectors. In fact it holds for any vectors. The lengths on the right side do the scaling, which is why the cosine form divides by them.

It is tempting to think Cauchy–Schwarz is only about arrows in the plane. In fact it holds in any space with an inner product, including spaces of functions, which is the setting of Hilbert spaces.

When to use it: whenever you need an upper bound on a dot product or an inner product, or need to show that a cosine or correlation stays in its range.

When not to use it: when you measure size with a different norm, such as the sum of absolute values. Then the matching bound is Hölder's inequality, which pairs the two norms differently.

QuestionUseWhy
Is the dot product at most the product of lengths?Cauchy–SchwarzIt is the exact statement
Is the length of a sum at most the sum of lengths?Triangle inequalityFollows from Cauchy–Schwarz
Are the two vectors parallel?Check for equalityEquality holds only then

History

Augustin-Louis Cauchy stated the inequality for finite sums in the 1820s, in his lectures on analysis. Viktor Bunyakovsky proved the integral form around 1859, and Hermann Amandus Schwarz gave a version for integrals in 1888. The inequality is named for the three of them because each contributed a form of it.

It caught on because it is short to prove and reaches far. The same bound gives the triangle inequality, shows that correlations stay between minus one and one, and gives the basic estimates in analysis. Modern textbooks prove it from the squared-length argument above, which works without any calculus.

Recap

  • The dot product of two vectors is at most the product of their lengths, in absolute value.
  • The proof looks at the squared length of u−tvu - tv for a well-chosen tt, which is never negative.
  • Dividing by the lengths gives the cosine, which therefore lies between minus one and one.
  • Equality holds exactly when one vector is a multiple of the other.
  • The inequality holds in any inner product space, which is where Hilbert Space comes in.

Next, read Large Sieve Inequality to see the same bound used in analysis.

Check yourself

QuestionRecall: state the Cauchy–Schwarz inequality, and say when equality holds.Show answer

For any vectors uu and vv, the absolute value of the dot product is at most the product of the lengths: ∣⟨u,v⟩∣≤∥u∥∥v∥|\langle u, v \rangle| \le \lVert u \rVert \lVert v \rVert. Equality holds exactly when one vector is a scalar multiple of the other, so they lie on the same line.

QuestionComputation: for u=(2,1)u = (2, 1) and v=(−1,3)v = (-1, 3), compute the dot product, the product of the lengths, and the cosine.Show answer

The dot product is 2⋅(−1)+1⋅3=12 \cdot (-1) + 1 \cdot 3 = 1. The lengths are 5\sqrt{5} and 10\sqrt{10}, and their product is 50≈7.071\sqrt{50} \approx 7.071. The inequality holds, since 1≤7.0711 \le 7.071. The cosine is 1/7.071≈0.1411 / 7.071 \approx 0.141, so the vectors are nearly perpendicular.

QuestionWhy: why does equality in Cauchy–Schwarz force the two vectors to be parallel?Show answer

In the proof, equality makes the squared length of u−tvu - tv zero for the chosen tt. A vector with zero squared length is the zero vector, so u−tv=0u - tv = 0, which means u=tvu = tv. Two vectors that are multiples of one another are parallel.

QuestionApplied: a colleague reports two sensor readings, treated as vectors, with a dot product of 50 and lengths 4 and 5. Is this possible?Show answer

No. The product of the lengths is 4×5=204 \times 5 = 20, and the inequality says the dot product cannot exceed 20 in absolute value. The value 50 breaks the bound, so the readings, the lengths, or the dot product calculation must be wrong, and the colleague should recheck the data before using it.

Sources