/** Generalized hypergeometric functions: elementary identities. **/

/*K: hypergeometric; generalized hypergeometric functions; Ghg; sums;
     summation; gauss; vandermonde; saalschutz; whipple; kummer; watson; dixon; 
     dougall */
/*A: John Gottschalk */
/*S: University of Western Australia */
/*D: September 1984 */
 
/* This file contains assignments and substitutions for rewriting special 
   generalized hypergeometric functions in terms of 
   Gamma and Polygamma functions. */

/* These identities are from Appendix 3 of Slater "Generalized Hypergeometric
   Functions". Those that have been omitted may be simply derived form other
   results, for example equation III.25 is is a result of equation III.11. */

#_:    Comm
Ghg_:  Tier
SGhg_: Ldist
_Sum[Smp] : Inf

/* Some commonly used theorems can be called by the following names. */
Intdiff      ::  SGhg[0,{1..4}]
Gauss        ::  SGhg[0,5]
GaussII      ::  SGhg[0,20]
Vandermonde  ::  SGhg[0,6]
Saalschutz   ::  SGhg[0,7]
Whipple      ::  SGhg[0,8]
Kummer       ::  SGhg[0,9]
Watson       ::  SGhg[0,10]
Dixon        ::  SGhg[0,11]
Dougall      ::  SGhg[0,12]
Nearlypoised ::  SGhg[0,{13..15}]
Wellpoised   ::  Flat[{SGhg[0,{16..19}],Dixon,Dougall,Kummer}]

/* The patterns are written with a "=" sign as the pattern matcher in
   version 1.5.0. will return a 0 for matches like Match[a/2+1/2,(a+1)/2],
   but use of Eq gets around this problem. */

/* Reduction for 2F1(1,a;a+m;-1) when m is a natural number. */
SGhg[0,1] : Ghg[2,1,#[1,$a],#[$b_=Natp[$b-$a]],-1] -> \
     (-1)^($b-$a-1) Gamma[$b]/\
     (2Gamma[$a]) Sum[(-1)^%#n/(Gamma[%#n+1] Gamma[$b-$a-%#n])\ 
     (Psi[$b/2-%#n/2]-Psi[$b/2-%#n/2-1/2]),{%#n,0,$b-$a-1}] 

SGhg[0,2] : Ghg[$p_=$p>2,$p-1,#[1,$$a],\
		 #[$$b]_=Union[{$$b}]-Union[{$$a}] = {1},1] --> \
     -Psi[$p-2,{$$a}[1]] (-1)^$p ({$$a}[1])^($p-1)/Fctl[$p-2]

SGhg[0,3] : Ghg[$p_=$p>2,$p-1,#[1,$$a],\
            #[$$b]_=Union[{$$b}]-Union[{$$a}] = {1},-1] --> \
     (Psi[$p-2,({$$a}[1])/2+1/2]-Psi[$p-2,({$$a}[1])/2]) (-1)^$p \
     ({$$a}[1])^($p-1) 2^(1-$p)/Fctl[$p-2]

SGhg[0,4] : Ghg[3,2,#[1,$a,$b],#[$a+1,$b+1],1_=SymbWT[$b~=$a]] -> \
     $a $b/($a-$b) (Psi[$a]-Psi[$b])

/* Gauss's theorem */
SGhg[0,5] : Ghg[2,1,#[$a,$b],#[$c],1] -> \
     Gamma[$c] Gamma[$c-$a-$b]/(Gamma[$c-$a] Gamma[$c-$b])

/* Vandermonde's theorem */
SGhg[0,6] : Ghg[2,1,#[$a,$n_=Natp[1-$n]],#[$c],1] -> Poc[$c-$a,-$n]/Poc[$c,-$n]

/* Saalschutz's theorem */
SGhg[0,7] : Ghg[3,2,#[$a,$b,$n_=Natp[1-$n]],#[$c,$d_=$d=$a+$b+$n-$c+1],1] -> \
     Gamma[$c-$a-$n] Gamma[$c-$b-$n] Gamma[$c] Gamma[$c-$a-$b]/\
     (Gamma[$c-$a] Gamma[$c-$b] Gamma[$c-$n] Gamma[$c-$a-$b-$n])

/* Whipple's theorem */
SGhg[0,8] : Ghg[3,2,#[$a,$b_=$b=1-$a,$c],#[$d,$e]_=$d+$e=1+2$c,1] -> \
     Pi 2^(1-2$c) Gamma[$d] Gamma[$e]/\
     (Gamma[($a+$e)/2] Gamma[($a+$d)/2] Gamma[($d+$e)/2] Gamma[($b+$d)/2])

/* Kummer's theorem */
SGhg[0,9] : Ghg[2,1,#[$a,$b],#[$c_=$c=1+$a-$b],-1] -> \
    Gamma[1+$a-$b] Gamma[1+$a/2]/(Gamma[1+$a] Gamma[1+$a/2-$b]) 

/* Watson's Theorem */
SGhg[0,10] : Ghg[3,2,#[$a,$b,$c],#[$d_=$d=(1+$a+$b)/2,$e_=$e=2$c],1] -> \
     Gamma[1/2] Gamma[$c+1/2] Gamma[(1+$a+$b)/2] Gamma[(1-$a-$b)/2+$c]/\
     (Gamma[(1+$a)/2] Gamma[(1+$b)/2] Gamma[(1-$a)/2+$c] Gamma[(1-$b)/2+$c])

/* Dixon's theorem */
SGhg[0,11] : Ghg[3,2,#[$a,$b,$c],#[$d_=$d=1+$a-$b,$e_=$e=1+$a-$c],1] -> \
     Gamma[1+$a/2] Gamma[1+$a-$b] Gamma[1+$a-$c] Gamma[1+$a/2-$b-$c]/\
     (Gamma[1+$a] Gamma[1+$a/2-$b] Gamma[1+$a/2-$c] Gamma[1+$a-$b-$c])

/* Dougall's theorem */
SGhg[0,12] : Ghg[7,6,#[$a,$f_=$f=1+$a/2,$b,$c,$d,$e,$n_=Natp[1-$n] & \
     1+2$a-$b-$c-$d-$e-$n=0],\
     #[$g_=$g=$a/2,$h_=$h=1+$a-$b,$i_=$i=1+$a-$c,$j_=$j=1+$a-$d,\
					  $k_=$k=1+$a-$e,$l_=$l=1+$a-$n],1] -> \
     Poc[1+$a,-$n] Poc[1+$a-$b-$c,-$n] Poc[1+$a-$b-$d,-$n] Poc[1+$a-$c-$d,-$n]/\
     (Poc[1+$a-$b,-$n] Poc[1+$a-$c,-$n] Poc[1+$a-$d,-$n] \
     Poc[1+$a-$b-$c-$d,-$n])

/* Appendix III.15 in Slater's book */
SGhg[0,13] : Ghg[3,2,#[$a,$c_=$c=1+$a/2,$n_=Natp[1-$n]],#[$d_=$d=$a/2,$b],1] ->\
     ($b-$a-1+$n) Poc[$b-$a,-$n-1]/Poc[$b,-$n]

/* Appendix III.16 in Slater's book */
SGhg[0,14] : Ghg[3,2,#[$a,$b,$n_=Natp[1-$n]],\
			  #[$c_=$c=1+$a-$b,$d_=$d=1+2$b+$n],1] -> \
     Poc[$a-2$b,-$n] Poc[1+$a/2-$b,-$n] Poc[-$b,-$n]/\
     (Poc[1+$a-$b,-$n] Poc[$a/2-$b,-$n] Poc[-2$b,-$n])

/* Appendix III.17 in Slater's book */
SGhg[0,15] : Ghg[4,3,#[$a,$c_=$c=1+$a/2,$b,$n_=Natp[1-$n]],\
	  #[$d_=$d=$a/2,$e_=$e=1+$a-$b,$f_=$f=1+2$b+$n],1] -> \
     Poc[$a-2$b,-$n] Poc[-$b,-$n]/(Poc[1+$a-$b,-$n] Poc[-2$b,-$n])

/* Appendix III.19 in Slater's book */
SGhg[0,16] : Ghg[7,6,#[$a,$b,$c_=$c=1+$a/2,$d_=$d=1/2+$b,$e_=$e=$a-2$b,\
  $f_=$f=1+2$a-2$b-$n,$n_=Natp[1-$n]],#[$g_=$g=$a/2,$h_=$h=1+$a-$b,\
  $i_=$i=$a+1/2-$b,$j_=$j=1+2$b,$k_=$k=2$b-$a+$n,$l_=$l=1+$a-$n],1] -> \
     Poc[1+$a,-$n] Poc[1+2$a-4$b,-$n]/(Poc[1+$a-2$b,-$n] Poc[1+2$a-2$b,-$n])

/* Appendix III.20 in Slater's book */
SGhg[0,17] : Ghg[4,3,#[$a,$b,$n_=Natp[1-$n],$c_=$c=1/2+$a],\
	  #[$d_=$d=$b/2+$n/2,$e_=$e=$b/2+$n/2+1/2,$f_=$f=1+2$a],1] -> \
     Poc[$b+$n-2$a,-$n]/Poc[$b+$n,-$n]

/* Appendix III.10 in Slater's book */
SGhg[0,18] : Ghg[4,3,#[$a,$b,$c,$d_=$d=1+$a/2],\
  #[$e_=$e=$a/2,$f_=$f=1+$a-$b,$g_=$g=1+$a-$c],-1] -> \
     Gamma[1+$a-$b] Gamma[1+$a-$c]/(Gamma[1+$a] Gamma[1+$a-$b-$c])

/* Appendix III.12 in Slater's book */
SGhg[0,19] : Ghg[5,4,#[$a,$b,$c,$d,$e_=$e=1+$a/2],\
  #[$f_=$f=$a/2,$g_=$g=1+$a-$b,$h_=$h=1+$a-$c,$i_=$i=1+$a-$d],1] -> \
     Gamma[1+$a-$b] Gamma[1+$a-$c] Gamma[1+$a-$d] Gamma[1+$a-$b-$c-$d]/\
     (Gamma[1+$a] Gamma[1+$a-$b-$c] Gamma[1+$a-$b-$d] Gamma[1+$a-$c-$d])

/*Gausses Second Theorem */
SGhg[0,20] : Ghg[2,1,#[$a,$b],#[$c_=$c=1/2+$a/2+$b/2],1/2] -> \
	Gamma[1/2]Gamma[$c]/(Gamma[1/2+$a/2]Gamma[1/2+$b/2])


/*W: Sum[Smp] is redefined to be Inf. 
     The identities may not be correct if one of the bottom parameters
     is a negative integer, even though the function may be well-behaved.
     The convergence of hypergeometric series should be checked using the
     file XCvgt before the identities here are used. */

/*R: [AS 15.1; Slater, Generalized Hypergeometric Functions,
     Cambridge University Press,1966] */

