{
  "aliases": null,
  "backlinks": null,
  "body": "\n## Definition\n\nLet $t_k$ be a hypergeometric term in $k$ over a field of characteristic $0$.\nThis means that $t_k \\ne 0$ and that $r(k) = t_{k+1}/t_k$ is a [[rational function|0XDK9CGYKJ]] of $k$.\n*Gosper's algorithm* takes $t_k$ and either returns a hypergeometric term $T_k$ with $T_{k+1} - T_k = t_k$, or reports that no such term exists.\nIt runs as follows.\n\n1. Write $r(k) = \\dfrac{a(k)}{b(k)}\\cdot\\dfrac{c(k+1)}{c(k)}$ with polynomials $a, b, c$ such that $\\gcd\\big(a(k), b(k + h)\\big) = 1$ for every integer $h \\ge 0$ (a [[polynomial gcd|Q75YRG25JK]] condition).\n2. Search for a polynomial $x(k)$ with\n$$a(k)\\,x(k + 1) - b(k - 1)\\,x(k) = c(k),$$\nusing a bound on its degree computed from $a$, $b$, $c$ and linear algebra on its coefficients.\n3. If such an $x$ exists, return $T_k = \\dfrac{b(k - 1)\\,x(k)}{c(k)}\\,t_k$. Otherwise report that $t_k$ has no hypergeometric indefinite sum.\n\n## Remarks\n\nCheck of step 3: with $y(k) = b(k-1)x(k)/c(k)$, one has $T_{k+1} - T_k = \\big(y(k + 1)r(k) - y(k)\\big)t_k$, and $y(k+1)r(k) - y(k) = \\big(a(k)x(k+1) - b(k-1)x(k)\\big)/c(k) = 1$ by step 2.\nGosper's theorem says that the method is complete: if some hypergeometric $T_k$ works, then $T_k/t_k$ is rational and the equation in step 2 has a polynomial solution.\nExample: $t_k = k\\cdot k!$ has $r(k) = (k + 1)^2/k$; take $a(k) = k + 1$, $b(k) = 1$, $c(k) = k$, which satisfy the gcd condition.\nThe equation $(k + 1)x(k + 1) - x(k) = k$ has the solution $x = 1$, so $T_k = k!$ for $k \\ge 1$, and indeed $(k + 1)! - k! = k\\cdot k!$.\nNon-example: for $t_k = 1/(k + 1)$ the algorithm reports failure, since the partial sums are harmonic numbers, which are not a hypergeometric term.\nThe equation of step 2 is a linear [[recurrence|0FYX44GP92]] with polynomial coefficients for the unknown polynomial $x$.\n",
  "commit": "ff8a40749dc16545e3d2fc637f6b0196e81d0bfa",
  "front": {
    "defines": "NHMJQBS04M",
    "kind": "definition",
    "msc": [
      "33F10",
      "68W30",
      "39A10"
    ],
    "name": "Gosper's algorithm",
    "sources": [
      {
        "url": "https://en.wikipedia.org/wiki/Gosper%27s_algorithm"
      }
    ],
    "tag": "WTXMRG6WR4",
    "uses": [
      "0XDK9CGYKJ",
      "Q75YRG25JK",
      "0FYX44GP92"
    ]
  },
  "kind": "definition",
  "link": "https://tamnd.github.io/math2/node/WTXMRG6WR4/",
  "links": [
    {
      "field": "defines",
      "target": "NHMJQBS04M"
    },
    {
      "field": "uses",
      "target": "0XDK9CGYKJ"
    },
    {
      "field": "uses",
      "target": "Q75YRG25JK"
    },
    {
      "field": "uses",
      "target": "0FYX44GP92"
    }
  ],
  "markdown": "https://tamnd.github.io/math2/node/WTXMRG6WR4.md",
  "msc": [
    "33F10",
    "68W30",
    "39A10"
  ],
  "name": "Gosper's algorithm",
  "prov": null,
  "role": "",
  "source": "https://github.com/tamnd/math2/blob/main/nodes/WTX/WTXMRG6WR4.md",
  "status": null,
  "tag": "WTXMRG6WR4",
  "uri": "m2://WTXMRG6WR4",
  "url": "https://tamnd.github.io/math2/wiki/gospers-algorithm-definition/",
  "writing": {
    "tag": "WTXMRG6WR4",
    "kind": "definition",
    "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
      }
    ]
  }
}
