Algorithm Search⌘K

Proofs: Gosper's algorithm

These are the human proofs of Gosper's algorithm, at full length.

Gosper's algorithm finds a hypergeometric antidifference exactly when one exists full

This proof shows: correctness, termination.

Let KK be a field of characteristic 0 (the implementation uses K=QK = \mathbb{Q}), and let tt be a hypergeometric term with ratio r(n)=t(n+1)/t(n)=num(n)/den(n)r(n) = t(n+1)/t(n) = \mathrm{num}(n)/\mathrm{den}(n), where num,den∈K[n]\mathrm{num}, \mathrm{den} \in K[n] are nonzero. A hypergeometric antidifference of tt is a hypergeometric term zz with z(n+1)−z(n)=t(n)z(n+1) - z(n) = t(n).

Lemma 1 (reduction to a rational equation). tt has a hypergeometric antidifference if and only if there is a rational function y∈K(n)y \in K(n) with

r(n) y(n+1)−y(n)=1.(1)r(n)\, y(n+1) - y(n) = 1. \tag{1}

If yy solves (1), then z=ytz = y t is an antidifference.

Proof. If yy solves (1) and z=ytz = y t, then z(n+1)−z(n)=y(n+1)r(n)t(n)−y(n)t(n)=t(n)z(n+1) - z(n) = y(n+1) r(n) t(n) - y(n) t(n) = t(n), and zz is hypergeometric because z(n+1)/z(n)=r(n)y(n+1)/y(n)z(n+1)/z(n) = r(n) y(n+1)/y(n) is rational. Conversely, let zz be a hypergeometric antidifference with ratio ρ=z(n+1)/z(n)∈K(n)\rho = z(n+1)/z(n) \in K(n). Then t=z(ρ−1)t = z(\rho - 1), and ρ≠1\rho \ne 1 since t≠0t \ne 0. So y=z/t=1/(ρ−1)y = z/t = 1/(\rho - 1) is rational, and yt=zy t = z gives (1). □\square

Lemma 2 (the Gosper form). Lines L1 to L4 terminate, and afterwards

r(n)=a(n)b(n)⋅c(n+1)c(n),gcd⁡(a(n),b(n+h))=1 for every integer h≥0.(2)r(n) = \frac{a(n)}{b(n)} \cdot \frac{c(n+1)}{c(n)}, \qquad \gcd(a(n), b(n+h)) = 1 \text{ for every integer } h \ge 0. \tag{2}

Proof. After line L1, a/b=ra/b = r and c=1c = 1, so (2) holds in its first part. Suppose an update at line L4 is made with g=gcd⁡(a(n),b(n+h))g = \gcd(a(n), b(n+h)), so g(n)∣a(n)g(n) \mid a(n) and g(n−h)∣b(n)g(n-h) \mid b(n). Let C(n)=∏i=1hg(n−i)C(n) = \prod_{i=1}^{h} g(n-i). Then C(n+1)/C(n)=g(n)/g(n−h)C(n+1)/C(n) = g(n)/g(n-h) by telescoping the product, so

a(n)b(n)=a(n)/g(n)b(n)/g(n−h)⋅C(n+1)C(n),\frac{a(n)}{b(n)} = \frac{a(n)/g(n)}{b(n)/g(n-h)} \cdot \frac{C(n+1)}{C(n)},

and replacing aa, bb, cc by a/ga/g, b/g(n−h)b/g(n-h), c Cc\,C keeps the first part of (2). Each update lowers deg⁡a\deg a by deg⁡g≥1\deg g \ge 1, so there are at most deg⁡num\deg \mathrm{num} updates, and the loops stop.

For the coprimality, note that aa and bb are only ever divided, so their roots are among the roots of num\mathrm{num} and den\mathrm{den} (in an algebraic closure). If gcd⁡(a(n),b(n+h))≠1\gcd(a(n), b(n+h)) \ne 1 for some integer h≥0h \ge 0, there is a root α\alpha of aa with b(α+h)=0b(\alpha + h) = 0, so h=β−αh = \beta - \alpha for a root β\beta of bb, and h≤∣α∣+∣β∣≤Hh \le |\alpha| + |\beta| \le H by Fujiwara's bound, which is what root_bound computes. So only h≤Hh \le H can fail. The loop of line L2 visits each such hh, and the inner loop at line L3 runs until gcd⁡(a(n),b(n+h))=1\gcd(a(n), b(n+h)) = 1. Later updates divide aa and bb further, which cannot create a common factor of a(n)a(n) and b(n+h′)b(n + h') for an h′h' already visited. □\square

Lemma 3 (the polynomial equation). With a,b,ca, b, c as in (2) and B(n)=b(n−1)B(n) = b(n-1), a rational yy solves (1) if and only if y=B(n) x(n)/c(n)y = B(n)\,x(n)/c(n) for a polynomial xx with

a(n) x(n+1)−B(n) x(n)=c(n).(3)a(n)\, x(n+1) - B(n)\, x(n) = c(n). \tag{3}

Proof. Put x=c y/Bx = c\,y/B, a rational function. Substituting y=Bx/cy = B x / c and r=(a/b)(c(n+1)/c(n))r = (a/b)(c(n+1)/c(n)) into (1):

a(n)b(n)c(n+1)c(n)⋅b(n) x(n+1)c(n+1)−b(n−1) x(n)c(n)=1,\frac{a(n)}{b(n)} \frac{c(n+1)}{c(n)} \cdot \frac{b(n)\, x(n+1)}{c(n+1)} - \frac{b(n-1)\, x(n)}{c(n)} = 1,

which after multiplying by c(n)c(n) is (3). So (1) and (3) are equivalent; it remains to show that a rational solution xx of (3) is a polynomial.

Write x=f/gx = f/g in lowest terms with gg monic, and suppose deg⁡g≥1\deg g \ge 1. Multiplying (3) by g(n)g(n+1)g(n) g(n+1) gives

a(n)f(n+1)g(n)−B(n)f(n)g(n+1)=c(n)g(n)g(n+1).a(n) f(n+1) g(n) - B(n) f(n) g(n+1) = c(n) g(n) g(n+1).

Hence g(n+1)g(n+1) divides a(n)f(n+1)g(n)a(n) f(n+1) g(n), and since gcd⁡(f(n+1),g(n+1))=1\gcd(f(n+1), g(n+1)) = 1, g(n+1)∣a(n)g(n)g(n+1) \mid a(n) g(n). In the same way g(n)∣B(n)g(n+1)g(n) \mid B(n) g(n+1).

Let SS be the finite set of roots of gg in an algebraic closure. Choose γ∈S\gamma \in S and m≥0m \ge 0 such that γ,γ+1,…,γ+m∈S\gamma, \gamma + 1, \ldots, \gamma + m \in S, γ−1∉S\gamma - 1 \notin S and γ+m+1∉S\gamma + m + 1 \notin S; this exists because SS is finite and nonempty. The point n=γ−1n = \gamma - 1 is a root of g(n+1)g(n+1) but not of g(n)g(n), so by g(n+1)∣a(n)g(n)g(n+1) \mid a(n) g(n) it is a root of aa: a(γ−1)=0a(\gamma - 1) = 0. The point n=γ+mn = \gamma + m is a root of g(n)g(n) but not of g(n+1)g(n+1), so by g(n)∣B(n)g(n+1)g(n) \mid B(n) g(n+1) it is a root of BB: b(γ+m−1)=0b(\gamma + m - 1) = 0. Then a(n)a(n) and b(n+m)b(n + m) have the common root n=γ−1n = \gamma - 1, which contradicts (2) with h=m≥0h = m \ge 0. So g=1g = 1 and xx is a polynomial. □\square

Lemma 4 (degree bound). Every polynomial solution xx of (3) has degree at most DD, the value computed at line L5.

Proof. Since c≠0c \ne 0, x≠0x \ne 0; let e=deg⁡xe = \deg x and x=xene+⋯x = x_e n^e + \cdots with xe≠0x_e \ne 0. Write d1=deg⁡ad_1 = \deg a, d2=deg⁡Bd_2 = \deg B, λa=LC⁡(a)\lambda_a = \operatorname{LC}(a) and λB=LC⁡(B)\lambda_B = \operatorname{LC}(B). Note x(n+1)=xene+(exe+xe−1)ne−1+⋯x(n+1) = x_e n^e + (e x_e + x_{e-1}) n^{e-1} + \cdots.

  • If d1≠d2d_1 \ne d_2, the left side of (3) has degree exactly max⁡(d1,d2)+e\max(d_1, d_2) + e, with leading coefficient λaxe\lambda_a x_e or −λBxe-\lambda_B x_e. So e=deg⁡c−max⁡(d1,d2)e = \deg c - \max(d_1, d_2).
  • If d1=d2=dd_1 = d_2 = d and λa≠λB\lambda_a \ne \lambda_B, the coefficient of nd+en^{d + e} is (λa−λB)xe≠0(\lambda_a - \lambda_B) x_e \ne 0, so e=deg⁡c−de = \deg c - d.
  • If d1=d2=dd_1 = d_2 = d and λa=λB=λ\lambda_a = \lambda_B = \lambda, the coefficient of nd+en^{d+e} cancels. Let α\alpha and β\beta be the coefficients of nd−1n^{d-1} in aa and BB (0 if d=0d = 0). The coefficient of nd+e−1n^{d + e - 1} is λ(exe+xe−1)+αxe−λxe−1−βxe=xe(λe+α−β)\lambda (e x_e + x_{e-1}) + \alpha x_e - \lambda x_{e-1} - \beta x_e = x_e (\lambda e + \alpha - \beta). If e≠(β−α)/λe \ne (\beta - \alpha)/\lambda, this is nonzero, so d+e−1=deg⁡cd + e - 1 = \deg c and e=deg⁡c−d+1e = \deg c - d + 1. Otherwise e=(β−α)/λe = (\beta - \alpha)/\lambda, which is then a nonnegative integer.

In each case e≤De \le D, as computed by degree_bound. □\square

Theorem. GOSPER(num,den)(\mathrm{num}, \mathrm{den}) terminates. It returns a rational yy that solves (1) if such a yy exists, and returns None otherwise. In the first case z=ytz = y t is a hypergeometric antidifference of tt; in the second, tt has none.

Proof. Termination: Lemma 2 for lines L1 to L4, and the rest is straight-line code with one linear system. By Lemma 2 the form (2) holds at line L5. If D<0D < 0, Lemma 4 shows that (3) has no polynomial solution, and line L6 returns None. Otherwise line L7 sets up (3) as a linear system for the coefficients x0,…,xDx_0, \ldots, x_D, which by Lemma 4 contains every polynomial solution; line L8 returns None exactly when there is none. By Lemma 3, (1) has a rational solution exactly when (3) has a polynomial one, and line L9 returns y=Bx/cy = B x / c, reduced, which solves (1). Lemma 1 turns both answers into the statements about antidifferences. ■\blacksquare

Back to Gosper's algorithm