{
  "aliases": null,
  "backlinks": null,
  "body": "\n## Statement\n\nLet $n \\ge 1$, let $a_i = \\arctan 2^{-i}$ for $i \\ge 0$ (see [[arctangent|0CE768XNVP]]), and let $K_n = \\prod_{i=0}^{n-1} (1 + 2^{-2i})^{-1/2}$.\nLet $\\theta$ be a real number with $\\abs{\\theta} \\le \\sum_{i=0}^{n-1} a_i$.\nThe *CORDIC* iteration in rotation mode starts from $x_0 = K_n$, $y_0 = 0$, $z_0 = \\theta$ and, for $i = 0, \\ldots, n-1$, sets $\\sigma_i = 1$ if $z_i \\ge 0$ and $\\sigma_i = -1$ otherwise, and\n$$x_{i+1} = x_i - \\sigma_i 2^{-i} y_i, \\qquad y_{i+1} = y_i + \\sigma_i 2^{-i} x_i, \\qquad z_{i+1} = z_i - \\sigma_i a_i.$$\nThen, in exact arithmetic,\n\n1. $x_n = \\cos(\\theta - z_n)$ and $y_n = \\sin(\\theta - z_n)$;\n2. $\\abs{z_n} \\le a_{n-1} \u003c 2^{-(n-1)}$;\n3. hence $\\abs{x_n - \\cos\\theta} \u003c 2^{-(n-1)}$ and $\\abs{y_n - \\sin\\theta} \u003c 2^{-(n-1)}$.\n\n## Remarks\n\nEach step multiplies the vector $(x_i, y_i)$ by the matrix with rows $(1, -\\sigma_i t)$ and $(\\sigma_i t, 1)$, $t = 2^{-i}$, which is $\\sqrt{1 + t^2}$ times the [[rotation|0HFREYRSZP]] by the angle $\\sigma_i \\arctan t$.\nAfter $n$ steps the scale factors multiply to $1/K_n$, which cancels $x_0 = K_n$, and the total angle is $\\sum_i \\sigma_i a_i = \\theta - z_n$; this is clause 1.\nFor clause 2, concavity of $\\arctan$ on $[0, \\infty)$ gives $a_i \\le 2 a_{i+1}$, hence $a_i \\le a_{i+1} + \\cdots + a_{n-1} + a_{n-1}$ by induction.\nWith this, the bound $\\abs{z_i} \\le a_i + \\cdots + a_{n-1} + a_{n-1}$ passes from $z_i$ to $z_{i+1} = z_i - \\sigma_i a_i$, and at $i = n$ it gives $\\abs{z_n} \\le a_{n-1}$.\nClause 3 follows because $\\cos$ and $\\sin$ are $1$-Lipschitz.\nSince $a_0 + a_1 + a_2 + a_3 \\approx 1.618 \u003e \\pi/2$, for $n \\ge 4$ the method covers all $\\theta \\in [-\\pi/2, \\pi/2]$; other angles are first reduced by symmetries.\nMultiplication by $2^{-i}$ is a shift in binary, so each step needs only shifts, additions and a table lookup of $a_i$.\n\n## Explanations\n\n### L1 human\n\nCORDIC computes sine and cosine without any multiplication.\nIt turns a vector towards the target angle by smaller and smaller fixed angles: $45°$, about $26.6°$, about $14°$, and so on.\nEach turn goes to the left or to the right.\nThese special angles are chosen so that each turn needs only a binary shift and an addition.\nEach step gains about one binary digit of accuracy.\nThis made it the method of choice in pocket calculators and in hardware without a multiplier.\n\n### L2 human\n\nThe same iteration in vectoring mode drives $y$ to $0$ instead of $z$, and then computes $\\arctan(y_0/x_0)$ and, up to the known constant factor, the length $\\sqrt{x_0^2 + y_0^2}$.\nReplacing $\\arctan 2^{-i}$ by $\\operatorname{artanh} 2^{-i}$ and rotations by hyperbolic rotations gives the hyperbolic functions, the exponential and the logarithm; in that case some steps must be repeated to ensure convergence.\nThe constant $K_n$ tends to about $0.6073$ and is applied once at the start, not at each step.\n",
  "commit": "ff8a40749dc16545e3d2fc637f6b0196e81d0bfa",
  "front": {
    "about": [
      "H313BRXEJS"
    ],
    "kind": "statement",
    "msc": [
      "65Y04",
      "65D20"
    ],
    "name": "CORDIC",
    "role": "theorem",
    "same_as": {
      "wikidata": "Q116076",
      "wikipedia": "CORDIC"
    },
    "sources": [
      {
        "url": "https://en.wikipedia.org/wiki/CORDIC"
      }
    ],
    "tag": "M4ZJ8QV3MR",
    "uses": [
      "H313BRXEJS",
      "0CE768XNVP",
      "0HFREYRSZP"
    ]
  },
  "kind": "statement",
  "link": "https://tamnd.github.io/math2/node/M4ZJ8QV3MR/",
  "links": [
    {
      "field": "about",
      "target": "H313BRXEJS"
    },
    {
      "field": "uses",
      "target": "H313BRXEJS"
    },
    {
      "field": "uses",
      "target": "0CE768XNVP"
    },
    {
      "field": "uses",
      "target": "0HFREYRSZP"
    }
  ],
  "markdown": "https://tamnd.github.io/math2/node/M4ZJ8QV3MR.md",
  "msc": [
    "65Y04",
    "65D20"
  ],
  "name": "CORDIC",
  "prov": null,
  "role": "theorem",
  "source": "https://github.com/tamnd/math2/blob/main/nodes/M4Z/M4ZJ8QV3MR.md",
  "status": null,
  "tag": "M4ZJ8QV3MR",
  "uri": "m2://M4ZJ8QV3MR",
  "url": "https://tamnd.github.io/math2/wiki/cordic/",
  "writing": {
    "tag": "M4ZJ8QV3MR",
    "kind": "statement",
    "level": "W0",
    "next": [
      {
        "what": "an inventory row",
        "note": "the row of the inventory that the node accounts for",
        "have": 0,
        "want": 1
      },
      {
        "what": "a source with a locator",
        "have": 0,
        "want": 1
      }
    ]
  }
}
