Hyper returns exactly the hypergeometric solutions full
This proof shows: correctness, termination.
Let K be a field of characteristic 0 and L=∑i=0rpi(n)Si with pi∈K[n], r≥1, p0=0 and pr=0. A hypergeometric term t is eventually nonzero with t(n+1)=R(n)t(n) for a rational R∈K(n) and all large n.
Lemma 1 (Gosper-Petkovšek form). Every nonzero R∈K(n) can be written R=Zb(n)a(n)c(n)c(n+1) with Z∈K∖{0}, monic a,b,c∈K[n], gcd(a(n),b(n+h))=1 for all integers h≥0, gcd(a(n),c(n))=1 and gcd(b(n),c(n+1))=1. This is the lemma of Petkovšek (1992) and of A = B, Chapter 5. Its proof uses only gcds over K and the integer roots of a resultant, so a,b,c and Z lie in K.
Lemma 2 (the key identity). For R in the form of Lemma 1 and Pi=pi(n)∏j=0i−1a(n+j)∏j=ir−1b(n+j),
c(n)j=0∏r−1b(n+j)⋅i=0∑rpi(n)k=0∏i−1R(n+k)=i=0∑rZiPi(n)c(n+i). Proof. ∏k<iR(n+k)=Zi∏k<ib(n+k)a(n+k)⋅c(n)c(n+i), because the factors c(n+k+1)/c(n+k) telescope. Multiplying by c(n)∏j<rb(n+j) cancels c(n) and ∏k<ib(n+k), and leaves ∏j=ir−1b(n+j). □
If t has ratio R, then (Lt)(n)=t(n)∑ipi(n)∏k<iR(n+k). So for eventually nonzero t, Lt=0 holds if and only if the rational function ∑ipi∏k<iR(n+k) is zero, if and only if the right side of Lemma 2 is the zero polynomial.
Termination. p0 and pr(n−r+1) have finitely many monic factors. For each pair, ∑αiZi is a nonzero polynomial, because αi=0 for some i by the choice of m, so it has at most r roots. Line L6 solves one finite linear system, by Lemma 4. So the algorithm stops.
Soundness. Let a ratio R=Za(n)c(n+1)/(b(n)c(n)) be output, with c=0 from line L6. Then ∑iZiPi(n)c(n+i)=0, and Lemma 2 holds for this R even if the gcd conditions fail, since its proof used none of them. Since c(n)∏jb(n+j) is a nonzero polynomial, ∑ipi∏k<iR(n+k)=0 as a rational function. Define t(n0)=1 and t(n+1)=R(n)t(n) for n≥n0, where n0 exceeds every integer root of the numerator and denominator of R. Then t is a hypergeometric solution.
Lemma 3 (the necessary conditions). If t is a hypergeometric solution with ratio R in the form of Lemma 1, with degc=δ, then a(n)∣p0(n), b(n)∣pr(n−r+1), ∑iαiZi=0 for the αi of line L4, and c solves ∑iZiPi(n)c(n+i)=0.
Proof. The last claim is Lemma 2 with Lt=0. In ∑iZiPi(n)c(n+i)=0, each term with i≥1 contains the factor a(n). So a(n) divides P0(n)c(n)=p0(n)∏j=0r−1b(n+j)c(n). By Lemma 1, a(n) is coprime to each b(n+j) with j≥0 and to c(n), so a(n)∣p0(n). Each term with i≤r−1 contains the factor b(n+r−1), so it divides Pr(n)c(n+r)=pr(n)∏j=0r−1a(n+j)c(n+r). Here gcd(b(n+r−1),a(n+j))=1 for 0≤j≤r−1: substituting n↦n−j, it is gcd(a(n),b(n+h)) with h=r−1−j≥0. And gcd(b(n+r−1),c(n+r))=1 is the shift of gcd(b(n),c(n+1))=1. So b(n+r−1)∣pr(n), that is, b(n)∣pr(n−r+1). Finally, c is monic of degree δ, so c(n+i) has leading term nδ for every i, and the coefficient of nm+δ in the sum is ∑iZiαi, which must be 0. Z=0 because R=0. □
Lemma 4 (degree bound). Let Q0,…,Qr∈K[n], not all zero, and Rk=∑i≥k(ki)Qi. Let b∗=max{degRk−k:Rk=0} and φ(δ)=∑k:degRk−k=b∗lc(Rk)δ(δ−1)⋯(δ−k+1). Every nonzero polynomial solution c of ∑iQi(n)c(n+i)=0 has a degree δ with φ(δ)=0.
Proof. Some Rk is nonzero: the map from (Qi) to (Rk) is triangular with 1 on the diagonal, so it is invertible. With Ec(n)=c(n+1) and Δ=E−1, the binomial theorem Ei=∑k(ki)Δk gives ∑iQiEi=∑kRkΔk. For c of degree δ, Δkc has degree δ−k and leading coefficient δ(δ−1)⋯(δ−k+1)lc(c) when k≤δ, and is 0 when k>δ, where the product also vanishes. So RkΔkc has degree at most degRk+δ−k≤b∗+δ, and the coefficient of nb∗+δ in the sum is lc(c)φ(δ), which must be 0. The polynomial φ is nonzero, since the falling factorials of distinct degrees k are linearly independent and their coefficients lc(Rk) are nonzero. □
So with D the largest nonnegative integer root of φ, the solutions of degree at most D are all the polynomial solutions, and they are the kernel of a linear map on the coefficient vectors (c0,…,cD). Line L6 computes a basis c1,…,cs of this kernel.
Completeness. Let t be a hypergeometric solution with ratio R∈K(n), and write R in the form of Lemma 1. By Lemma 3 the pair (a,b) is tried at line L2 and Z is found at line L5, provided the factorizations of p0 and pr(n−r+1) and the roots are taken over K. Also by Lemma 3, c=∑jλjcj for the basis of line L6. Choose n0 beyond all integer roots of a, b, c and the cj, and let A(n)=∏k=n0n−1a(k)/b(k). Then for n≥n0, t(n)=κZnA(n)c(n) for a constant κ, and the output solution hj with ratio Za(n)cj(n+1)/(b(n)cj(n)) is hj(n)=κjZnA(n)cj(n) with κj=0. Hence t=∑j(κλj/κj)hj for n≥n0. Reducing the ratio to lowest terms at line L7 does not change the sequence hj for n≥n0. ■