Zeilberger's algorithm returns a telescoper of least order full
This proof shows: correctness.
Setting. K is a field of characteristic 0 (in the code, K=Q), and F=K(n). The summand is
F(n,k)=poly(n,k)xki∏(ain+bik+ci)!ei with poly∈K[n,k], x∈K∗, integers ai,bi,ci and ei=±1. A telescoper of order J with rational certificate is a vector (α0,…,αJ)∈FJ+1, not all zero, together with R∈K(n,k), such that
j=0∑JαjF(n+j,k)=G(n,k+1)−G(n,k),G=RF.(1) Identity (1) is an identity of hypergeometric terms: after division by F(n,k) it is an identity of rational functions in n and k.
Theorem. (a) If the algorithm returns (J,a0,…,aJ,R), then the aj are polynomials in n, not all zero, and (1) holds. (b) J is the least order for which a telescoper with rational certificate exists. (c) If the summand is 0, the output is J=0, a0=1 and G=0.
Part (c) is the first line of the code. From now on poly=0.
Lemma 1 (step L2)
For 0≤j≤J, F(n+j,k)=H(k)φj(k) with φj∈K[n][k], where H(k)=xk∏i(ain+bik+ci′)!ei with ci′=ci+min(0,aiJ) if ei=1 and ci′=ci+max(0,aiJ) if ei=−1. Also H(k+1)/H(k)=num(k)/den(k), where num and den are a constant times a product of monic linear factors k+u(n), with u of degree at most 1 in n.
Proof. Write L=ain+bik. If ei=1, then ci+aij≥ci′, and (L+ci+aij)!=(L+ci′)!∏l=ci′+1ci+aij(L+l). If ei=−1, then ci+aij≤ci′, and 1/(L+ci+aij)!=(1/(L+ci′)!)∏l=ci+aij+1ci′(L+l). In both cases the extra factor is a polynomial, and φj is poly(n+j,k) times these products. For the ratio, (L+bi+c)!/(L+c)! is ∏l=1bi(L+c+l) if bi>0, the inverse of ∏l=0−bi−1(L+c−l) if bi<0, and 1 if bi=0. Each factor ain+bik+c with bi=0 is bi(k+u) with u=(ain+c)/bi. For ei=−1 the factor moves to the other side. □
Lemma 2 (step L3)
The output q,r,c of the Gosper-Petkovšek step satisfies
H(k)H(k+1)=r(k+1)q(k)⋅c(k)c(k+1),(2) with q,r,c∈K[n][k], and gcd(q(k),r(k+h))=1 in F[k] for every integer h≥1.
Proof. Start with q=num, r(k)=den(k−1) and c=1. Then (2) holds. A step removes a factor k+u from q and a factor k+w from r with u−w=h, an integer h≥1, and multiplies c by C(k)=∏i=1h−1(k+u−i). The removed part of q(k)/r(k+1) is (k+u)/(k+1+u−h). A direct computation gives
C(k)C(k+1)=∏i=1h−1(k+u−i)∏i=1h−1(k+u+1−i)=k+u+1−hk+u, so (2) still holds. Each step removes two factors, so the loop stops. When it stops, no pair u,w has u−w∈{1,2,…}. Over F, q(k) and r(k+h) are products of monic linear factors k+u and k+w+h. They have a common factor exactly when some u=w+h, that is, u−w=h. So the gcd condition holds. □
Lemma 3 (steps L4 to L6, the parametrized Gosper equation)
Fix α∈FJ+1, let t(k)=∑jαjF(n+j,k) and P(k)=c(k)∑jαjφj(k). If f∈F[k] satisfies
q(k)f(k+1)−r(k)f(k)=P(k),(3) then G=RF with R=r(k)f(k)/(c(k)φ0(k)) satisfies (1). Conversely, if (1) holds for α with some rational R, then (3) has a polynomial solution of degree at most the bound D of L5.
Proof. By Lemma 1, t=H⋅P/c. If P=0, then t=0 and f=0 solves (3), and R=0 satisfies (1). Let P=0. By (2), t(k+1)/t(k)=(P(k+1)/P(k))⋅q(k)/r(k+1). Put z(k)=r(k)f(k)t(k)/P(k). Then
z(k+1)−z(k)=P(k)t(k)(r(k+1)f(k+1)P(k+1)t(k)P(k)t(k+1)−r(k)f(k))=P(k)t(k)(q(k)f(k+1)−r(k)f(k))=t(k). Also z=rfH/c=RF, since F=Hφ0. This proves the first claim.
For the converse, (1) says that t has the antidifference G=RF, a rational multiple of t when t=0. With the representation of t's ratio above and the gcd condition of Lemma 2, Gosper's theorem says that then (3) has a polynomial solution f, of degree degP−max(degq,degr) if degq=degr or LC(q)=LC(r), and otherwise of degree degP−degq+1 or s=(rd−1−qd−1)/LC(q), where rd−1 and qd−1 are the coefficients of kd−1. The second option is possible only if s is a nonnegative integer. The proof is the comparison of the two top coefficients of (3) (Petkovšek, Wilf and Zeilberger, A = B, Chapter 5, and the page on Gosper's algorithm). Here the leading coefficients of q and r lie in K, and s∈F is an integer only if it is a constant. L5 uses degP≤maxjdeg(cφj), and the bound is increasing in degP, so the true degree is at most D. If D<0, only f=0 is possible, and the code then allows no f unknowns. □
Lemma 4 (step L7)
The vectors returned by the fraction-free elimination form a basis of the kernel over F of the coefficient matrix of (3), with unknowns (α0,…,αJ,f0,…,fD).
Proof. Row i is replaced by p⋅rowi−m⋅rowr with the pivot p=0, and then divided by a nonzero polynomial. Both operations are invertible over F, and they keep the row space and so the kernel. Swaps also keep it. At the end, every pivot column has a single nonzero entry Mi,ci in its row i, and the rows below are zero. For a free column, the vector with 1 there, 0 in the other free columns and −Mi,free/Mi,ci in pivot column ci satisfies every row. These vectors are independent, one for each free column, and the kernel has dimension equal to the number of free columns. □
Proof of the theorem
(a) The equations of L6 are the coefficients in k of (3), and they are linear in the unknowns. A kernel vector with some αj=0 gives, by Lemma 3, a solution of (1) with R=rf/(cφ0). The code multiplies the vector by a common denominator L(n) and then divides the α part by its content g(n). This multiplies the whole vector by L/g∈F∗, and (3) and (1) are linear, so they still hold with f replaced by f/g. That is why g appears in the denominator of R. A final scaling by a nonzero rational number does not change this. So the aj are polynomials, not all zero, and (1) holds.
(b) Suppose some order J′<J has a telescoper with rational certificate. By the converse in Lemma 3 at order J′, (3) has a solution with degf≤D, so the system of L6 at order J′ has a kernel vector with α=0, and by Lemma 4 the basis of L7 contains a vector with a nonzero α part (the kernel vectors with α=0 form a subspace, and a basis of the whole kernel cannot lie in it). So the algorithm would have stopped at order J′, a contradiction. ■
Termination. For a proper hypergeometric term, a telescoper with rational certificate exists. This is the fundamental theorem of Wilf and Zeilberger (Inventiones 1992; A = B, Chapter 4 and Chapter 6), which gives a k-free recurrence for F, and a k-free recurrence yields a telescoper. By (b) the algorithm then stops at an order at most that bound. The parameter max_order only cuts the search short. The code returns None when it is reached, and that says nothing about larger orders.