Petkovšek's algorithm (also Hyper) is a computer algebra algorithm that computes a basis of hypergeometric terms solution of its input linear recurrence equation with polynomial coefficients. Equivalently, it computes a first order right factor of linear difference operators with polynomial coefficients. This algorithm was developed by Marko Petkovšek in his PhD-thesis 1992.[1] The algorithm is implemented in all the major computer algebra systems.
Let K {\textstyle \mathbb {K} } be a field of characteristic zero. A nonzero sequence y ( n ) {\textstyle y(n)} is called hypergeometric if the ratio of two consecutive terms is rational, i.e. y ( n + 1 ) / y ( n ) ∈ K ( n ) {\textstyle y(n+1)/y(n)\in \mathbb {K} (n)} . The Petkovšek algorithm uses as key concept that this rational function has a specific representation, namely the Gosper-Petkovšek normal form. Let r ( n ) ∈ K [ n ] {\textstyle r(n)\in \mathbb {K} [n]} be a nonzero rational function. Then there exist monic polynomials a , b , c ∈ K [ n ] {\textstyle a,b,c\in \mathbb {K} [n]} and 0 ≠ z ∈ K {\textstyle 0\neq z\in \mathbb {K} } such that
r ( n ) = z a ( n ) b ( n ) c ( n + 1 ) c ( n ) {\displaystyle r(n)=z{\frac {a(n)}{b(n)}}{\frac {c(n+1)}{c(n)}}}
and
This representation of r ( n ) {\textstyle r(n)} is called Gosper-Petkovšek normal form. These polynomials can be computed explicitly. This construction of the representation is an essential part of Gosper's algorithm.[2] Petkovšek added the conditions 2. and 3. of this representation which makes this normal form unique.[1]
Using the Gosper-Petkovšek representation one can transform the original recurrence equation into a recurrence equation for a polynomial sequence c ( n ) {\textstyle c(n)} . The other polynomials a ( n ) , b ( n ) {\textstyle a(n),b(n)} can be taken as the monic factors of the first coefficient polynomial p 0 ( n ) {\textstyle p_{0}(n)} resp. the last coefficient polynomial shifted p r ( n − r + 1 ) {\textstyle p_{r}(n-r+1)} . Then z {\textstyle z} has to fulfill a certain algebraic equation. Taking all the possible finitely many triples ( a ( n ) , b ( n ) , z ) {\textstyle (a(n),b(n),z)} and computing the corresponding polynomial solution of the transformed recurrence equation c ( n ) {\textstyle c(n)} gives a hypergeometric solution if one exists.[1][3][4]
In the following pseudocode the degree of a polynomial p ( n ) ∈ K [ n ] {\textstyle p(n)\in \mathbb {K} [n]} is denoted by deg ( p ( n ) ) {\textstyle \deg(p(n))} and the coefficient of n d {\textstyle n^{d}} is denoted by coeff ( p ( n ) , n d ) {\textstyle {\text{coeff}}(p(n),n^{d})} .
algorithm petkovsek is input: Linear recurrence equation ∑ k = 0 r p k ( n ) y ( n + k ) = 0 , p k ∈ K [ n ] , p 0 , p r ≠ 0 {\textstyle \sum _{k=0}^{r}p_{k}(n)\,y(n+k)=0,p_{k}\in \mathbb {K} [n],p_{0},p_{r}\neq 0} . output: A hypergeometric solution y {\textstyle y} if there are any hypergeometric solutions. for each monic divisor a ( n ) {\textstyle a(n)} of p 0 ( n ) {\textstyle p_{0}(n)} do for each monic divisor b ( n ) {\textstyle b(n)} of p r ( n − r + 1 ) {\textstyle p_{r}(n-r+1)} do for each k = 0 , … , r {\textstyle k=0,\dots ,r} do p ~ k ( n ) = p k ( n ) ∏ j = 0 k − 1 a ( n + j ) ∏ i = k r − 1 b ( n + i ) {\textstyle {\tilde {p}}_{k}(n)=p_{k}(n)\prod _{j=0}^{k-1}a(n+j)\prod _{i=k}^{r-1}b(n+i)} d = max k = 0 , … , r deg ( p ~ k ( n ) ) {\textstyle d=\max _{k=0,\dots ,r}\deg({\tilde {p}}_{k}(n))} for each root z {\textstyle z} of ∑ k = 0 r coeff ( p ~ k ( n ) , n d ) z k {\textstyle \sum _{k=0}^{r}{\text{coeff}}({\tilde {p}}_{k}(n),n^{d})z^{k}} do Find non-zero polynomial solution c ( n ) {\textstyle c(n)} of ∑ k = 0 r z k p ~ k ( n ) c ( n + k ) = 0 {\textstyle \sum _{k=0}^{r}z^{k}\,{\tilde {p}}_{k}(n)\,c(n+k)=0} if such a non-zero solution c ( n ) {\textstyle c(n)} exists then r ( n ) = z a ( n ) / b ( n ) c ( n + 1 ) / c ( n ) {\textstyle r(n)=z\,a(n)/b(n)\,c(n+1)/c(n)} return a non-zero solution y ( n ) {\textstyle y(n)} of y ( n + 1 ) = r ( n ) y ( n ) {\textstyle y(n+1)=r(n)\,y(n)}
If one does not end if a solution is found it is possible to combine all hypergeometric solutions to get a general hypergeometric solution of the recurrence equation, i.e. a generating set for the kernel of the recurrence equation in the linear span of hypergeometric sequences.[1]
Petkovšek also showed how the inhomogeneous problem can be solved. He considered the case where the right-hand side of the recurrence equation is a sum of hypergeometric sequences. After grouping together certain hypergeometric sequences of the right-hand side, for each of those groups a certain recurrence equation is solved for a rational solution. These rational solutions can be combined to get a particular solution of the inhomogeneous equation. Together with the general solution of the homogeneous problem this gives the general solution of the inhomogeneous problem.[1]
The number of signed permutation matrices of size n × n {\textstyle n\times n} can be described by the sequence y ( n ) {\textstyle y(n)} which is determined by the recurrence equation 4 ( n + 1 ) 2 y ( n ) + 2 y ( n + 1 ) + ( − 1 ) y ( n + 2 ) = 0 {\displaystyle 4(n+1)^{2}\,y(n)+2\,y(n+1)+(-1)\,y(n+2)=0} over Q {\textstyle \mathbb {Q} } . Taking a ( n ) = n + 1 , b ( n ) = 1 {\textstyle a(n)=n+1,b(n)=1} as monic divisors of p 0 ( n ) = 4 ( n + 1 ) 2 , p 2 ( n ) = − 1 {\textstyle p_{0}(n)=4(n+1)^{2},p_{2}(n)=-1} respectively, one gets z = ± 2 {\textstyle z=\pm 2} . For z = 2 {\textstyle z=2} the corresponding recurrence equation which is solved in Petkovšek's algorithm is 4 ( n + 1 ) 2 c ( n ) + 4 ( n + 1 ) c ( n + 1 ) − 4 ( n + 1 ) ( n + 2 ) c ( n + 2 ) = 0. {\displaystyle 4(n+1)^{2}\,c(n)+4(n+1)\,c(n+1)-4(n+1)(n+2)\,c(n+2)=0.} This recurrence equation has the polynomial solution c ( n ) = c 0 {\textstyle c(n)=c_{0}} for an arbitrary c 0 ∈ Q {\textstyle c_{0}\in \mathbb {Q} } . Hence r ( n ) = 2 ( n + 1 ) {\textstyle r(n)=2(n+1)} and y ( n ) = 2 n n ! {\textstyle y(n)=2^{n}\,n!} is a hypergeometric solution. In fact it is (up to a constant) the only hypergeometric solution and describes the number of signed permutation matrices.[5]
Given the sum
coming from Apéry's proof of the irrationality of ζ ( 3 ) {\displaystyle \zeta (3)} , Zeilberger's algorithm computes the linear recurrence
Given this recurrence, the algorithm does not return any hypergeometric solution, which proves that a ( n ) {\displaystyle a(n)} does not simplify to a hypergeometric term.[3]