Tutorials › Statistical Theory I - Probability and Distribution Theory › Cauchy–Schwarz for Random Variables

Moment Inequalities and Jensen · Tutorial 378 of 994

Cauchy–Schwarz for Random Variables

Learn when the random-variable Cauchy–Schwarz inequality applies, why it holds, and how it bounds expectations of products and covariances.

Intermediate 9 min read

What You'll Learn

  • State the moment conditions needed for the random-variable Cauchy–Schwarz inequality.
  • Prove the inequality by expanding the expectation of a squared difference.
  • Apply the result to discrete and continuous distributions.
  • Use centered variables to derive a covariance bound.
  • Recognize why independence is not required and why finite second moments matter.

Why Bound an Expected Product?

Expressions such as \(E[XY]\) arise whenever two random variables are studied together. Their value can depend on the variables’ scales and dependence, so it is useful to have a general bound that applies even when their joint distribution is complicated. The Cauchy–Schwarz inequality supplies one: if both variables have finite second moments, their expected product cannot exceed the product of their root mean squares in absolute value.

The bound is useful for discrete variables, continuous variables, and mixtures of the two. It does not require independence. Its proof is short, but the moment assumptions matter: they ensure that the product has a finite expectation and that the quadratic expression used in the proof is well-defined.

Statement and Conditions

Definition: A random variable \(X\) is square-integrable if \(E[X^2]<\infty\). Equivalently, its second moment is finite. The root mean square of \(X\) is \(\sqrt{E[X^2]}\).

For the inequality below, \(X\) and \(Y\) need not be independent, and they need not have mean zero. The only assumptions are that they are defined on the same probability space and that each has a finite second moment.

Theorem (Cauchy–Schwarz inequality for random variables): If \(E[X^2]<\infty\) and \(E[Y^2]<\infty\), then \(E[XY]\) exists as a finite expectation and $$ |E[XY]|\leq \sqrt{E[X^2]E[Y^2]}. $$

Here, “exists as a finite expectation” means that \(E[|XY|]<\infty\). This condition allows us to expand and manipulate \(E[(X-tY)^2]\) using ordinary expectation rules. The next proof verifies it rather than presuming it.

Proof From a Nonnegative Quadratic

For any real numbers \(x\) and \(y\), \(2|xy|\leq x^2+y^2\), since \((|x|-|y|)^2\geq 0\). Applying this pointwise to \(X\) and \(Y\) gives $$ |XY|\leq \frac{X^2+Y^2}{2}. $$

The right-hand side has finite expectation by the assumptions. Therefore \(E[|XY|]\leq (E[X^2]+E[Y^2])/2<\infty\), so \(E[XY]\) is finite. Also, for every real \(t\), \(X-tY\) is square-integrable: \((X-tY)^2\leq 2X^2+2t^2Y^2\), whose expectation is finite.

Now use the fact that a square is nonnegative. Thus \(E[(X-tY)^2]\geq 0\) for every real \(t\). Expansion is legitimate because the terms have finite expectations: $$ E[(X-tY)^2]=E[X^2]-2tE[XY]+t^2E[Y^2]\geq 0. $$

If \(E[Y^2]>0\), choose \(t=E[XY]/E[Y^2]\). Substitution yields $$ 0\leq E[X^2]-\frac{(E[XY])^2}{E[Y^2]}, \qquad (E[XY])^2\leq E[X^2]E[Y^2]. $$ Both sides of the latter inequality are nonnegative, so taking square roots proves the stated bound.

If instead \(E[Y^2]=0\), then \(Y=0\) almost surely. To see this, for every positive integer \(k\), Markov’s inequality gives \(P(Y^2\geq 1/k)\leq kE[Y^2]=0\). The event \(\{Y^2>0\}\) is the countable union of the events \(\{Y^2\geq 1/k\}\), so it has probability zero. Consequently \(XY=0\) almost surely, \(E[XY]=0\), and the inequality holds in this case as well. \(\square\)

Using the Inequality for Discrete Variables

For variables with a discrete joint distribution, expectations are sums over their joint probability mass function. If \(p(x,y)=P(X=x,Y=y)\), then $$ E[XY]=\sum_x\sum_y xy\,p(x,y),\qquad E[X^2]=\sum_x\sum_y x^2p(x,y),\qquad E[Y^2]=\sum_x\sum_y y^2p(x,y). $$ The theorem compares the absolute value of the first sum with the square root of the product of the two second-moment sums. No special structure in the joint mass function is needed.

Worked Example: Checking the Bound on a Finite Sample Space

Suppose one of four outcomes is selected with probability \(1/4\) each. The values of \(X\) across the outcomes are \(1,2,0,-1\), and the corresponding values of \(Y\) are \(2,-1,3,1\). Calculate the expected product and the two second moments, then check the inequality.

The product \(XY\) takes values \(2,-2,0,-1\), so $$ E[XY]=\frac{2-2+0-1}{4}=-\frac14. $$

The squared values of \(X\) sum to \(1+4+0+1=6\), and those of \(Y\) sum to \(4+1+9+1=15\). Therefore $$ E[X^2]=\frac64=\frac32,\qquad E[Y^2]=\frac{15}{4}. $$

The right-hand side of the bound is $$ \sqrt{E[X^2]E[Y^2]}=\sqrt{\frac32\cdot\frac{15}{4}} =\sqrt{\frac{45}{8}}=\frac{3\sqrt{10}}{4}. $$ Since \(|E[XY]|=1/4\) and \(1/4\leq 3\sqrt{10}/4\), the inequality holds. The positive and negative products partly cancel in \(E[XY]\), while the second moments measure squared sizes without cancellation.

Using the Inequality for Continuous Variables

If \((X,Y)\) has a joint density \(f_{X,Y}(x,y)\), expectations of functions are calculated by integrating against that density. In particular, when the second moments are finite, $$ E[XY]=\int_{\mathbb R^2}xy f_{X,Y}(x,y)\,dx\,dy, \quad E[X^2]=\int_{\mathbb R^2}x^2 f_{X,Y}(x,y)\,dx\,dy, \quad E[Y^2]=\int_{\mathbb R^2}y^2 f_{X,Y}(x,y)\,dx\,dy. $$ Cauchy–Schwarz then bounds the absolute value of the product integral. A joint density is not essential to the theorem; it is simply one way to compute these expectations.

Worked Example: A Continuous Pair Built From One Uniform Variable

Let \(U\sim\operatorname{Uniform}(0,1)\), set \(X=U\), and set \(Y=1+U\). Both variables are bounded, so their second moments are finite. Calculate each quantity in the inequality directly from the density of \(U\), which is \(1\) on \((0,1)\).

First, \(XY=U(1+U)=U+U^2\). Hence $$ E[XY]=\int_0^1(u+u^2)\,du =\left[\frac{u^2}{2}+\frac{u^3}{3}\right]_0^1 =\frac12+\frac13=\frac56. $$

Next, $$ E[X^2]=\int_0^1u^2\,du=\frac13, \qquad E[Y^2]=\int_0^1(1+u)^2\,du =\int_0^1(1+2u+u^2)\,du =1+1+\frac13=\frac73. $$ Thus the bound is $$ |E[XY]|=\frac56 \leq\sqrt{\frac13\cdot\frac73} =\frac{\sqrt7}{3}. $$ For a numerical check, \(5/6\approx0.8333\), while \(\sqrt7/3\approx0.8819\). The variables are dependent because both are functions of the same \(U\); dependence does not prevent the inequality from applying.

A Consequence for Covariance

The theorem also gives a bound on covariance, which measures dependence after centering the variables. Suppose \(E[X^2]\) and \(E[Y^2]\) are finite. Their means are finite, and their variances are finite. Apply Cauchy–Schwarz to \(X-E[X]\) and \(Y-E[Y]\). By the definition of covariance, $$ \operatorname{Cov}(X,Y) =E[(X-E[X])(Y-E[Y])]. $$ The second moments of the centered variables are their variances, so $$ |\operatorname{Cov}(X,Y)| \leq \sqrt{\operatorname{Var}(X)\operatorname{Var}(Y)}. $$ This bound uses the same finite-second-moment conditions and does not require independence.

Worked Example: Bounding Covariance for Nested Events

Let \(A\) and \(B\) be events with \(P(A)=1/4\), \(P(B)=1/2\), and \(A\subseteq B\). Set \(X=\mathbf{1}_A\) and \(Y=\mathbf{1}_B\), where an indicator is \(1\) when its event occurs and \(0\) otherwise. Since \(A\subseteq B\), \(P(A\cap B)=1/4\).

For an indicator, \(E[\mathbf{1}_A]=P(A)\) and \(\operatorname{Var}(\mathbf{1}_A)=P(A)(1-P(A))\). Therefore $$ \operatorname{Cov}(X,Y)=P(A\cap B)-P(A)P(B) =\frac14-\frac14\cdot\frac12=\frac18, $$ and $$ \operatorname{Var}(X)=\frac14\cdot\frac34=\frac{3}{16}, \qquad \operatorname{Var}(Y)=\frac12\cdot\frac12=\frac14. $$ The covariance bound gives $$ |\operatorname{Cov}(X,Y)| \leq\sqrt{\frac{3}{16}\cdot\frac14} =\frac{\sqrt3}{8}. $$ Indeed, \(1/8\leq\sqrt3/8\), since \(1\leq\sqrt3\). The variables are dependent: knowing that \(A\) occurred guarantees that \(B\) occurred. The bound still applies.

Common Mistakes and Scope

  • Assuming independence is required. It is not. The proof uses only finite second moments and the nonnegativity of \(E[(X-tY)^2]\).
  • Using means instead of second moments. The direct bound involves \(E[X^2]\) and \(E[Y^2]\), not \(E[X]\) and \(E[Y]\). To bound covariance, first center the variables; then the relevant second moments are variances.
  • Ignoring moment conditions. The theorem as stated requires both second moments to be finite. Without them, its right-hand side may be infinite or undefined, and the finite-expectation conclusion need not follow.
  • Dropping the absolute value. \(E[XY]\) can be negative. The theorem bounds its magnitude, so the correct statement is \(|E[XY]|\leq\sqrt{E[X^2]E[Y^2]}\).

The core technique is broadly useful: form a squared linear combination, take its expectation, and use the fact that the resulting quadratic is nonnegative for every real coefficient. Here that argument controls a product moment and, after centering, covariance. For any application, first check that the needed second moments are finite, then calculate the relevant quantities with the distribution at hand.

Check Your Understanding

Use the assumptions and proof strategy in this tutorial to answer the following questions.

  1. What finite-moment assumptions are needed to apply the random-variable Cauchy–Schwarz inequality to \(X\) and \(Y\)?
  2. Why does \(2|XY|\leq X^2+Y^2\) help establish that \(E[XY]\) is finite?
  3. If \(E[Y^2]>0\), which value of \(t\) is substituted into \(E[(X-tY)^2]\) to obtain the bound?
  4. How do you use the inequality to bound \(|\operatorname{Cov}(X,Y)|\)?
  5. Does the inequality require \(X\) and \(Y\) to be independent? Explain briefly.