/** Generalized Kampe de Feriet functions: Sum, Kdf interconversion **/

/*K: Ghg; generalized Kampe de Feriet functions; Kampe de Feriet ; sum;
     summation */
/*A: Kevin McIsaac*/
/*S: University of Western Australia */
/*D: April 1987 */

/*W: On test on the limits of the sum */
	
/*P: XGhgC loaded */ 

Loadonce[XGhgC]
Loadonce[XSEmbed]

_SKdftosum[Init] :: Loadonce[XGammaV] 


/* SSumtokdf is a substitution used to express summations as Kampe de
Fereit functions. */

SSumtokdf : Sum[$x,{{$r,0,$m},{$s,0,$n}}] -->  \
(Lcl[%o,%sum,%summand,%top,%bot,%x,%z];\
  %sum : Sum[$x,{{$r,0,$m},{$s,0,$n}}]; \
  %summand : GammaConv[$x];\
  %summand : SEmbed[%summand,$r+$s->%rs%];\
  %summand : GammaConv[%summand ,%rs%];\
  %summand : GammaConv[%summand ,$r];\
  %summand : GammaConv[%summand ,$s];\
  %p1 : Ghgargs[%summand,%rs%];\
  If[~Valp[%p1]|In[{$r,$s},%p1],Ret[%sum]];\
  %p2 : Ghgargs[%summand Gamma[1+$r],$r];\
  If[~Valp[%p2]|In[{%rs%,$s},%p2],Ret[%sum]];\
  %p3 : Ghgargs[%summand Gamma[1+$s],$s];\
  If[~Valp[%p3]|In[{%rs%,$r},%p3],Ret[%sum]];\
  S[%sum[1,1],{%rs%->0, $r->0, $s->0}] \
     Kdf[{Len[%p1[1]], Len[%p1[2]], %fn%[%p1[1]], %fn%[%p1[2]]},\
         {Len[%p2[1]], Len[%p2[2]], %fn%[%p2[1]], %fn%[%p2[2]], %p2[3]%p1[3]}, \
         {Len[%p3[1]], Len[%p3[2]], %fn%[%p3[1]], %fn%[%p3[2]], %p3[3]%p1[3]}])



/* SKdf is a substitution transforming a hypergeometric into a sum */
/*Use Inf as upper limit */
SKdftosum[1] : Kdf[{$p1,$q1,#[$$a1],#[$$b1]},\
                   {$p2,$q2,#[$$a2],#[$$b2],$z2},\
                   {$p3,$q3,#[$$a3],#[$$b3],$z3} ] --> \
    Ap['Sum, {\
      Ap['Mult,Map[Gamma[$1+%#r+%#s]/Gamma[$1],{$$a1}]]/\
      (Ap['Mult,Map[Gamma[$1+%#r+%#s]/Gamma[$1],{$$b1}]] )\
       Ap['Mult,Map[Gamma[$1+%#r]/Gamma[$1],{$$a2}]] $z2^%#r/\
      (Ap['Mult,Map[Gamma[$1+%#r]/Gamma[$1],{$$b2}]] Gamma[1+%#r])\
       Ap['Mult,Map[Gamma[$1+%#s]/Gamma[$1],{$$a3}]] $z3^%#s/\
      (Ap['Mult,Map[Gamma[$1+%#s]/Gamma[$1],{$$b3}]] Gamma[1+%#s]),\
    {{%#r,0,Inf},{%#s,0,Inf}} }]

/* The following are used by Convtoghg */

_XKdf[Loaded] : 1
/*E:
SMP 1.5.0   (May 14 1986)
Thu Apr 23 14:49:21 1987


#I[1]::  <XKdfPR; <XKdf;

#I[2]::  Sum[Gamma[s+r+3+m]Gamma[s+n]x^r y^s/((s+r)!*Gamma[r+3/2]),{{r,0,Inf},{s,0,Inf}}]

		  r  s
		 x  y  Gamma[n + s] Gamma[3 + m + r + s]
#O[2]:   Sum[Sum[---------------------------------------,{r,0,Inf}],{s,0,Inf}]
			 (r + s)! Gamma[3/2 + r]

#I[3]::  S[%,SSumtokdf]

	 Gamma[n] Gamma[3 + m]   1:1:2|3 + m: 1  ; 1,n;    |
#O[3]:*  ---------------------  F     | 	       x, y|
	      Gamma[3/2]	 1:1:0|1    : 3/2;    ;    |

#I[4]::  <end>
*/
