{
  "aliases": null,
  "backlinks": null,
  "body": "\n## Statement\n\nLet $U_1$ and $U_2$ be independent random variables, each with the [[uniform distribution|0AREFQ9Z65]] on $(0, 1)$.\nLet\n$$Z_1 = \\sqrt{-2 \\ln U_1}\\, \\cos(2\\pi U_2), \\qquad Z_2 = \\sqrt{-2 \\ln U_1}\\, \\sin(2\\pi U_2).$$\nThen $Z_1$ and $Z_2$ are [[independent|0GQ938GDE0]], and each has the standard [[normal distribution|05AQE0QR0D]], with mean $0$ and variance $1$.\n\n## Remarks\n\nLet $R = \\sqrt{-2 \\ln U_1}$ and $\\Theta = 2\\pi U_2$, so that $(Z_1, Z_2)$ has [[polar coordinates|0BSW4T7THS]] $(R, \\Theta)$.\nFor $t \\ge 0$, $P(R^2 \u003e t) = P(U_1 \u003c e^{-t/2}) = e^{-t/2}$, so $R^2$ has the [[exponential distribution|0E99F51GVB]] with mean $2$, and $R$ has density $r e^{-r^2/2}$ on $(0, \\infty)$.\nAlso $\\Theta$ is uniform on $(0, 2\\pi)$ and independent of $R$.\nBy the [[change of variables formula|00N5FHP1CV]] with Jacobian $r$, the pair $(Z_1, Z_2)$ has density $\\frac{1}{2\\pi} e^{-r^2/2} = \\frac{1}{\\sqrt{2\\pi}} e^{-z_1^2/2} \\cdot \\frac{1}{\\sqrt{2\\pi}} e^{-z_2^2/2}$, which is the product of two standard normal densities.\nExample: $U_1 = e^{-2}$ and $U_2 = 1/8$ give $R = 2$, $\\Theta = \\pi/4$, and $(Z_1, Z_2) = (\\sqrt{2}, \\sqrt{2})$.\nIndependence of $U_1$ and $U_2$ is necessary: with $U_2 = U_1$ the point $(Z_1, Z_2)$ lies on one curve in the plane, so the pair is not a standard normal pair.\nTo obtain a normal variable with mean $\\mu$ and standard deviation $s$, use $\\mu + s Z_1$.\n\n## Explanations\n\n### L1 human\n\nThe transform turns two uniform random numbers into two independent bell-curve random numbers.\nThe first uniform number decides the distance from the origin, through a logarithm, and the second decides the direction.\nThe trick works because the two-dimensional standard normal distribution is the same in every direction, and its squared radius has a simple exponential law.\n\n### L2 human\n\nOne cannot invert the normal distribution function in closed form, so plain inverse transform sampling does not give normal variables cheaply; going to two dimensions and polar coordinates solves this.\nMarsaglia's polar method avoids the sine and cosine by sampling a uniform point in the unit disc by rejection and rescaling it.\nIn floating point, $U_1$ must avoid $0$, and the tail of $Z_1$ is truncated by the smallest representable $U_1$.\nFor speed, many libraries now prefer the ziggurat algorithm, which uses mostly one multiplication and one comparison per sample.\n",
  "commit": "ff8a40749dc16545e3d2fc637f6b0196e81d0bfa",
  "front": {
    "about": [
      "05AQE0QR0D"
    ],
    "kind": "statement",
    "msc": [
      "65C10",
      "60E05"
    ],
    "name": "Box–Muller transform",
    "role": "theorem",
    "same_as": {
      "wikidata": "Q895514",
      "wikipedia": "Box–Muller transform"
    },
    "sources": [
      {
        "url": "https://en.wikipedia.org/wiki/Box–Muller_transform"
      }
    ],
    "tag": "8G07Q9SVQ4",
    "uses": [
      "0AREFQ9Z65",
      "05AQE0QR0D",
      "0GQ938GDE0",
      "0BSW4T7THS",
      "00N5FHP1CV",
      "0E99F51GVB"
    ]
  },
  "kind": "statement",
  "link": "https://tamnd.github.io/math2/node/8G07Q9SVQ4/",
  "links": [
    {
      "field": "about",
      "target": "05AQE0QR0D"
    },
    {
      "field": "uses",
      "target": "0AREFQ9Z65"
    },
    {
      "field": "uses",
      "target": "05AQE0QR0D"
    },
    {
      "field": "uses",
      "target": "0GQ938GDE0"
    },
    {
      "field": "uses",
      "target": "0BSW4T7THS"
    },
    {
      "field": "uses",
      "target": "00N5FHP1CV"
    },
    {
      "field": "uses",
      "target": "0E99F51GVB"
    }
  ],
  "markdown": "https://tamnd.github.io/math2/node/8G07Q9SVQ4.md",
  "msc": [
    "65C10",
    "60E05"
  ],
  "name": "Box–Muller transform",
  "prov": null,
  "role": "theorem",
  "source": "https://github.com/tamnd/math2/blob/main/nodes/8G0/8G07Q9SVQ4.md",
  "status": null,
  "tag": "8G07Q9SVQ4",
  "uri": "m2://8G07Q9SVQ4",
  "url": "https://tamnd.github.io/math2/wiki/box-muller-transform/",
  "writing": {
    "tag": "8G07Q9SVQ4",
    "kind": "statement",
    "level": "W0",
    "next": [
      {
        "what": "a source with a locator",
        "have": 0,
        "want": 1
      }
    ]
  }
}
