{
  "aliases": null,
  "backlinks": null,
  "body": "\n## Proof\n\nWe use the notation $x_n$, $a_n$ of the [[continued fraction expansion|0SJ7Z6VKWK]] of $x$: $x_0 = x$, $a_n = \\floor{x_n}$, and $x_{n+1} = 1/(x_n - a_n)$ when $x_n \\ne a_n$.\n\n1. Suppose the expansion is finite. Then the process stops at some $n$, so $x_n = a_n$ is an integer.\n2. For $k \u003c n$, the process did not stop at $k$, so $x_{k+1} = 1/(x_k - a_k)$. Solving gives $x_k = a_k + 1/x_{k+1}$.\n3. If $x_{k+1}$ is rational, then so is $x_k = a_k + 1/x_{k+1}$, since $a_k$ is an integer.\n4. By step 1 and step 3, applied for $k = n-1, n-2, \\dots, 0$ in turn, each $x_k$ is rational. In particular $x = x_0$ is rational.\n5. Conversely, let $x = r/s$ with integers $r$ and $s$, $s \u003e 0$. We show that the process stops.\n6. Claim: if the process has not stopped before step $k$, then $x_k = r_k / s_k$ with integers $r_k$ and $s_k$, and $1 \\le s_k \\le s - k$.\n7. For $k = 0$, take $r_0 = r$ and $s_0 = s$.\n8. Suppose the claim holds for $k$, and the process does not stop at $k$, so $x_k \\ne a_k$. Since $a_k$ is the [[floor|0YVRNEDSVG]] of $x_k$, we have $0 \u003c x_k - a_k \u003c 1$.\n9. Put $t_k = r_k - a_k s_k$, an integer. Then $x_k - a_k = t_k / s_k$, so $0 \u003c t_k \u003c s_k$ by step 8.\n10. Then $x_{k+1} = 1/(x_k - a_k) = s_k / t_k$. Put $r_{k+1} = s_k$ and $s_{k+1} = t_k$. We get $1 \\le s_{k+1} \\le s_k - 1 \\le s - (k+1)$. This proves the claim by [[induction|0ASJVEFA9J]] on $k$.\n11. If the process had not stopped before step $s$, the claim would give $1 \\le s_s \\le 0$, which is impossible. So the process stops at some $k \u003c s$, and the expansion of $x$ is finite.\n12. So the expansion of $x$ is finite if and only if $x$ is rational.\n\n## Idea\n\nFor a fraction $r/s$, each step of the algorithm replaces the denominator by a smaller positive integer, exactly as in the Euclidean algorithm.\nA decreasing sequence of positive integers must stop.\nConversely, a finite expansion can be folded back from its last term, and each step keeps the number rational.\n",
  "commit": "68a8c3dc73fd55004b2796431c607c30960d1a85",
  "front": {
    "kind": "proof",
    "msc": [
      "11A55"
    ],
    "name": "Proof that the continued fraction of a real number is finite exactly when the number is rational",
    "proves": "0PMY0YQYXX",
    "sources": [
      {
        "locator": "Finite continued fractions",
        "url": "https://en.wikipedia.org/wiki/Simple_continued_fraction"
      }
    ],
    "tag": "7EDZQY5MV9",
    "uses": [
      "0SJ7Z6VKWK",
      "0YVRNEDSVG",
      "0ASJVEFA9J"
    ]
  },
  "kind": "proof",
  "link": "https://math2.tamnd.com/node/7EDZQY5MV9/",
  "links": [
    {
      "field": "proves",
      "target": "0PMY0YQYXX"
    },
    {
      "field": "uses",
      "target": "0SJ7Z6VKWK"
    },
    {
      "field": "uses",
      "target": "0YVRNEDSVG"
    },
    {
      "field": "uses",
      "target": "0ASJVEFA9J"
    }
  ],
  "markdown": "https://math2.tamnd.com/node/7EDZQY5MV9.md",
  "msc": [
    "11A55"
  ],
  "name": "Proof that the continued fraction of a real number is finite exactly when the number is rational",
  "prov": null,
  "role": "",
  "source": "https://github.com/tamnd/math2/blob/main/nodes/7ED/7EDZQY5MV9.md",
  "status": null,
  "tag": "7EDZQY5MV9",
  "uri": "m2://7EDZQY5MV9",
  "url": "https://math2.tamnd.com/wiki/proof-that-the-continued-fraction-of-a-real-number-is-finite-exactly-when-the-number-is-rational/",
  "writing": {
    "tag": "7EDZQY5MV9",
    "kind": "proof",
    "level": "W0",
    "next": [
      {
        "what": "an inventory row",
        "note": "the row of the inventory that the node accounts for",
        "have": 0,
        "want": 1
      }
    ]
  }
}
