/**Generalized Hypergeometric functions - transformations on pFq's*/
/*K: Hypergeometric, Ghg, Transformations, reversal of series, Saalschutz*/
/*A: K McIsaac*/
/*S: UWA, Nedlands 6009, Australia*/
/*D: July 1985*/
/*P: XPocV and XGammaV are automatically loaded as needed. */

#_:Comm;
Gamma[{$$a}] :: Ap['Mult,Map['Gamma,{$$a}]]

_Gamma[Init] :: Loadonce[XGammaV]
_Poc[Init]   :: Loadonce[XPocV]

/*: SRev 
	Reverses finite Hypergeometric series */
SGhg[6,1] : SRev ::\
  Ghg[$p,$q,#[$m_=Natp[1-$m],$$a],#[$$b],$z] --> \
   Ap['Mult,Map[Poc[$1,-$m],{$$a}]]/Ap['Mult,Map[Poc[$1,-$m],{$$b}]](-$z)^(-$m)\
   Ghg[$q+1,$p-1,Ap[#,Cat[{$m},Map[1-$1+$m,{$$b}]]],Ap[#,Map[1-$1+$m,{$$a}]],\
		(-1)^(-1 + $p + $q)/$z]

/*B: If there is more than one -ve integer in the numerator the smallest 
should be used. In the current implementation the largest is used because of 
the natural ordering of Comm functions*/

/*:SSaal
	Saalschutz's theorem in non-terminating form*/
SGhg[6,1] : SSaal: \
    Ghg[3,2,#[$e,$f,$g],#[$b,$c_=($e+$f+$g+1=$b+$c)],1] ->\
	Gamma[{$e,$f,$g,$e+$b-1,$f+$b-1,$g+$b-1}]/Gamma[{$c-$e,$c-$f,$c-$g}]-\
	Gamma[{$b,1+$g-$c,1+$f-$c,1+$e-$c,$c-1}]/Gamma[{1-$c,1+$b-$c,$e,$f,$g}]\
	Ghg[3,2,#[1+$e-$c,1+$f-$c,1+$g-$c],#[2-$c,1+$b-$c],1]
/*: SDixon
	Generalization of Dixons theorem, Slater p52 (2.3.3.7)*/

SGhg[6,3] : SDixon : \
   Ghg[3,2,#[$a,$b,$c],#[$e,$f],1] -> \
	Gamma[{$e,$f,$e+$f-$a-$b-$c}]/Gamma[{$a,$e+$f-$a-$c,$e+$f-$a-$b}]\
	Ghg[3,2,#[$e-$a,$f-$a,$e+$f-$a-$b-$c],#[$e+$f-$a-$c,$e+$f-$a-$b],1]

/*: SGhg[6,4]
	Three term relations, Slater p 115 (4.3.4)*/

SGhg[6,4] :\
   Ghg[3,2,#[$a,$b,$c],#[$d,$e],1] ->\
   Gamma[{1-$a,$d,$e,$c-$b}]/Gamma[{$e-$b,$d-$b,1+$b-$a,$c}] \
   Ghg[3,2,#[$b,1+$b-$d,1+$b-$e],#[1+$b-$c,1+$b-$a],1] +\
   Gamma[{1-$a,$d,$e,$b-$c}]/Gamma[{$e-$c,$d-$c,1+$c-$a,$b}] \
   Ghg[3,2,#[$c,1+$c-$e,1+$c-$d],#[1+$c-$b,1+$c-$a],1]

/*: SGhg[6,5] 
	transforms a nearly-poised 3F2(-1) to a 4F3(1). Page 33 of Bailey. */

SGhg[6,5] : Ghg[3,2,#[$a,$b,$c],#[$d,$e_=$e+$c=$d+$b],-1] --> \
   Ap[Gamma[{$k-$b,$k-$c}]/Gamma[{$k,$k-$b-$c}] \
      Ghg[4,3,#[$b,$c,$k/2-$a/2,$k/2+1/2-$a/2],#[$k-$a,$k/2,$k/2+1/2],1],\
      {$b+$d}]

/* SGhg[6,6][$n] 
	writes Ghg[p,q,#[a1,..,ap],#[b1,..,bq],z] in terms of 
	Ghg[p+1,q+1,#[1,a1+n,..,ap+n],#[n+1,b1+n,..,bq+n],z] for
	n positive or negative. */
SGhg[6,6][$n_=Natp[1+$n]] : Ghg[$p,$q,#[$$a],#[$$b],$z] --> \
   Ap[Sum,{Ap['Mult,Map[Poc[$1,%#r],{$$a}]] $z^%#r/\
	  (Ap['Mult,Map[Poc[$1,%#r],{$$b}]] Gamma[%#r+1]),\
	  {%#r,0,$n-1}}] + \
   Ap['Mult,Map[Poc[$1,$n],{$$a}]] $z^$n /\
  (Ap['Mult,Map[Poc[$1,$n],{$$b}]] Gamma[1+$n]) \
   Ghg[$p+1,$q+1,Ap[#,Cat[{$$a}+$n,{1}]],Ap[#,Cat[{$$b}+$n,{1+$n}]],$z]

SGhg[6,6][$n_=Natp[-$n]] : Ghg[$p,$q,#[$$a],#[$$b],$z] --> \
  -Ap[Sum,{Ap['Mult,Map[Gamma[$1+%#r]/Gamma[$1],{$$a}]] $z^%#r/\
	  (Ap['Mult,Map[Poc[$1,%#r],{$$b}]] Gamma[%#r+1]),\
	  {%#r,$n,-1}}] + \
   Ap['Mult,Map[Gamma[$1+$n]/Gamma[$1],{$$a}]] $z^$n/\
  (Ap['Mult,Map[Poc[$1,$n],{$$b}]] Gamma[1+$n]) \
   Ghg[$p+1,$q+1,Ap[#,Cat[{$$a}+$n,{1}]],Ap[#,Cat[{$$b}+$n,{1+$n}]],$z]

SGhg[6,7] : Ghg[6,5,#[$a,1+$a/2,$c,$d,$e,$f],\
		    #[$a/2,1+$a-$c,1+$a-$d,1+$a-$e,1+$a-$f],-1] -> \
  Gamma[1+$a-$e] Gamma[1+$a-$f]/(Gamma[1+$a] Gamma[1+$a-$e-$f]) \
  Ghg[3,2,#[1+$a-$c-$d,$e,$f],#[1+$a-$c,1+$a-$d],1]

SGhg[6,8] : Ghg[6,5,#[$a,$b_=$b=1+$a/2,$c,$d,$e,$n_=Natp[1-$n]],\
		    #[$f_=$f=$a/2,$g_=$g=1+$a-$c,$h_=$h=1+$a-$d,\
		    $i_=$i=1+$a-$e,$j_=$j=1+$a-$n],-1] -> \
  Gamma[1+$a-$e] Gamma[1+$a-$n]/(Gamma[1+$a] Gamma[1+$a-$e-$n]) \
  Ghg[3,2,#[1+$a-$c-$d,$e,$n],#[1+$a-$c,1+$a-$d],1]

/*: SGhg[6,9] increases all the parameters of a pFq by one. */
SGhg[6,9] : Ghg[$p,$q,#[$a,$n_=Natp[1-$n],$$a],#[$b_=$b=$a+1,$$b],$z] --> \
	Ghg[$p-1,$q-1,#[$n,$$a],#[$$b],$z] - \
	$n $z/($a+1) Ap['Mult,{$$a}]/Ap['Mult,{$$b}] \
	Ghg[$p,$q,Ap['#,Cat[{$$a}+1,{1+$n,$a+1}]],Ap['#,Cat[{$$b}+1,{$a+2}]],$z]

_XGhg6[Loaded] : 1

/*R: Slater, J.L. (1966). Generalized Hypergeometric Functions,
	Cambridge University Press, London. */

/*E:
SMP 1.5.0

#I[1]::  <XGhg6

#I[2]::  ghg : Ghg[3,2,#[a,2,b],#[5/2,7/2],1/2]

#O[2]:   Ghg[3,2,#[2,a,b],#[5/2,7/2],1/2]

#I[3]::  ghgnew : S[ghg,SGhg[6,6,-2]]

	 45Gamma[-2 + a] Gamma[-2 + b]   15Gamma[-1 + a] Gamma[-1 + b]
#O[3]:   ----------------------------- - -----------------------------
	      4Gamma[a] Gamma[b]	  2Gamma[0] Gamma[a] Gamma[b]

		   45Gamma[-2 + a] Gamma[-2 + b]

			     * Ghg[4,3,#[0,1,-2 + a,-2 + b],#[-1,1/2,3/2],1/2]
		 - -----------------------------------------------------------
				       4Gamma[a] Gamma[b]

#I[4]::  <XGhgC

#I[5]::  S[S[{ghg,ghgnew},{a->-3,b->3/2}],SGhgtoSum]

				15
#O[5]:   {14471/24255,-9/4 + ---------
			     4Gamma[0]

					 %r   1/2
				  -30 1/2   Pi    Gamma[%r] Gamma[-5 + %r]

					  * Gamma[-1/2 + %r]
			     9Sum[----------------------------------------,
				  Gamma[0] Gamma[-1 + %r] Gamma[1/2 + %r]

					  * Gamma[3/2 + %r]

				  {%r,0,-1 + Nterms[Ghg[4,3,#[-5,-1/2,0,1],

						       #[-1,1/2,3/2],1/2]]}]
			   + -----------------------------------------------}
						    4

#I[6]::  S[%,Nterms[$$x] -> 6]

#O[6]:   {14471/24255,14471/24255}
*/
