{
  "aliases": null,
  "backlinks": null,
  "body": "\n## Proof\n\nWe study the quadratic polynomial $s \\mapsto E[(X + sY)^2]$, which is never negative.\n\n1. Let $X$ and $Y$ be real random variables on one probability space $(\\Omega, \\mathcal{F}, P)$ with $E[X^2] \u003c \\infty$ and $E[Y^2] \u003c \\infty$.\n2. For real $u$ and $v$, $\\abs{uv} \\le (u^2 + v^2)/2$, since $(\\abs{u} - \\abs{v})^2 \\ge 0$. So $\\abs{XY} \\le (X^2 + Y^2)/2$.\n3. The integral of nonnegative functions is monotone. So $E[\\abs{XY}] \u003c \\infty$, and $XY$ is integrable.\n4. Let $A = E[X^2]$, $B = E[XY]$ and $C = E[Y^2]$. These are real numbers with $A \\ge 0$ and $C \\ge 0$.\n5. Fix $s \\in \\R$. Pointwise, $(X + sY)^2 = X^2 + 2s XY + s^2 Y^2$, and all three terms are integrable.\n6. By [[linearity of expectation|0P7PTC8DDE]], $q(s) := E[(X + sY)^2] = A + 2sB + s^2 C$.\n7. The [[expected value|0DCT0QZVQ1]] of the nonnegative variable $(X + sY)^2$ is nonnegative. So $q(s) \\ge 0$ for all real $s$.\n8. Case $C = 0$. Then $q(s) = A + 2sB$. If $B \\ne 0$, then $s = -(A + 1)/(2B)$ gives $q(s) = -1 \u003c 0$, which contradicts step 7.\n9. So in the case $C = 0$ we have $B = 0$, and $B^2 = 0 = AC$.\n10. Case $C \u003e 0$. Let $s_0 = -B/C$. Then $q(s_0) = A - 2B^2/C + B^2/C = A - B^2/C$.\n11. By step 7, $A - B^2/C \\ge 0$. Multiplying by $C \u003e 0$ gives $B^2 \\le AC$.\n12. Steps 9 and 11 prove $(E[XY])^2 \\le E[X^2] \\, E[Y^2]$.\n\nNow the equality case.\n\n13. First a lemma. Let $W \\ge 0$ be a random variable with $E[W] = 0$. For each integer $k \\ge 1$, [[Markov's inequality|05PWWHYBX5]] gives $P(W \\ge 1/k) \\le k E[W] = 0$.\n14. The event $\\set{W \u003e 0}$ is the union of the events $\\set{W \\ge 1/k}$ over $k \\ge 1$. A [[probability measure|0VGMEBVW1M]] is countably subadditive, so $P(W \u003e 0) = 0$.\n15. So $W = 0$ [[almost surely|0R46A1XY60]].\n16. Suppose $B^2 = AC$ and $C = 0$. Then $E[Y^2] = 0$. By step 15 for $W = Y^2$, $Y = 0$ almost surely. So $0 \\cdot X + 1 \\cdot Y = 0$ almost surely.\n17. Suppose $B^2 = AC$ and $C \u003e 0$. By step 10, $q(s_0) = A - B^2/C = 0$. So $E[(X + s_0 Y)^2] = 0$.\n18. By step 15 for $W = (X + s_0 Y)^2$, $X + s_0 Y = 0$ almost surely. So $a = 1$ and $b = s_0$ work, and $a \\ne 0$.\n19. Conversely, let $aX + bY = 0$ almost surely, with reals $a$ and $b$ not both $0$. Variables that agree almost surely have the same expectation, since the integral ignores null sets.\n20. If $b \\ne 0$, let $c = -a/b$. Then $Y = cX$ almost surely. So $XY = cX^2$ and $Y^2 = c^2 X^2$ almost surely.\n21. By steps 19 and 20, $B = cA$ and $C = c^2 A$. So $B^2 = c^2 A^2 = AC$.\n22. If $b = 0$, then $a \\ne 0$ and $X = 0$ almost surely. So $X^2 = 0$ and $XY = 0$ almost surely, and $A = B = 0$. Thus $B^2 = 0 = AC$.\n23. So equality holds if and only if $aX + bY = 0$ almost surely for some reals $a$ and $b$, not both $0$.\n\n## Idea\n\nThe mean of $(X + sY)^2$ is a quadratic polynomial in $s$ that is never negative. So it cannot have two distinct real roots, which is exactly the inequality. Equality means the polynomial reaches $0$, so some combination $X + sY$ vanishes almost surely.\n",
  "commit": "4a3290d299c8b2cd6493fce2296920ba7f82d942",
  "front": {
    "kind": "proof",
    "msc": [
      "60E15"
    ],
    "name": "Proof of the Cauchy–Schwarz inequality for expectations",
    "proves": "03PGHKAJG3",
    "sources": [
      {
        "locator": "Proof by analyzing a quadratic",
        "url": "https://en.wikipedia.org/wiki/Cauchy–Schwarz_inequality"
      }
    ],
    "tag": "ZX91JA56FM",
    "uses": [
      "0DCT0QZVQ1",
      "0P7PTC8DDE",
      "05PWWHYBX5",
      "0VGMEBVW1M",
      "0R46A1XY60"
    ]
  },
  "kind": "proof",
  "link": "https://math2.tamnd.com/node/ZX91JA56FM/",
  "links": [
    {
      "field": "proves",
      "target": "03PGHKAJG3"
    },
    {
      "field": "uses",
      "target": "0DCT0QZVQ1"
    },
    {
      "field": "uses",
      "target": "0P7PTC8DDE"
    },
    {
      "field": "uses",
      "target": "05PWWHYBX5"
    },
    {
      "field": "uses",
      "target": "0VGMEBVW1M"
    },
    {
      "field": "uses",
      "target": "0R46A1XY60"
    }
  ],
  "markdown": "https://math2.tamnd.com/node/ZX91JA56FM.md",
  "msc": [
    "60E15"
  ],
  "name": "Proof of the Cauchy–Schwarz inequality for expectations",
  "prov": null,
  "role": "",
  "source": "https://github.com/tamnd/math2/blob/main/nodes/ZX9/ZX91JA56FM.md",
  "status": null,
  "tag": "ZX91JA56FM",
  "uri": "m2://ZX91JA56FM",
  "url": "https://math2.tamnd.com/wiki/proof-of-the-cauchy-schwarz-inequality-for-expectations/",
  "writing": {
    "tag": "ZX91JA56FM",
    "kind": "proof",
    "level": "W0",
    "next": [
      {
        "what": "an inventory row",
        "note": "the row of the inventory that the node accounts for",
        "have": 0,
        "want": 1
      }
    ]
  }
}
