/** Generalized hypergeometric functions: relations between 4F3's and 7F6's **/

/*K: hypergeometric functions; Ghg; sums; summation; well-poised series; 
     saalschutzian series */
/*A: John Gottschalk */
/*S: University of Western Australia */
/*D: May 1985 */

/*P: XSets and XCvgt are automatically loaded as needed. */

If[~P[_XLoadonce[Loaded]],<XLoadonce]
_Cmpl[Init]     :: Loadonce[XSets]
_AllCvgtp[Init] :: Loadonce[XCvgt]

EqualS_:EqualW_:EqualWN_:Tier
#_:Comm
Ghg_:Tier

Saal_:Tier
/*: Saal[$Ghg,|$p|] 
	calculates equivalent series to $Ghg, which is 
	a Saalschutzian function of the form Ghg[4,3,#[...],#[...],1].
	One of the numerator parameters, c say, must have the property 
	Natp[1-c]=1.  The choice of 
		$p = 1 yields a list of Saalschutzian 4F3(1)'s,
		$p = 2 yields a list of terminating well-poised 7F6(1)'s and 
		|$p| = |3,r| yields nonterminating well-poised 7F6(1)'s.
	r may be either 1,2 or 3. Each choice of r produces a list of no more 
	than 20 elements with divergent and identical elements removed. */
Saal[Ghg[4,3,#[$x,$y,$z,$n_=Natp[1-$n]],\
     #[$u,$v,$w_=$w=$x+$y+$z+$n+1-$u-$v],1],$p] :: (Lcl[%l,%nertms,%p,%r];\
             %nterms : 1-$n;\
	       %r[1] : -$n/6-1/6-$x/2+$y/2+$z/2;\
               %r[2] : -$n/6-1/6+$x/2-$y/2+$z/2;\
               %r[3] : -$n/6-1/6+$x/2+$y/2-$z/2;\
               %r[4] : -$n/6-1/6+$u-$x/2-$y/2-$z/2;\
               %r[5] : -$n/6-1/6+$v-$x/2-$y/2-$z/2;\
               %r[6] : 5$n/6+5/6-$u-$v+$x/2+$y/2+$z/2;\
    %p : If[Listp[$p],$p,{$p}];\
    If[%p[1]=1 | %p[1]=2, Pr["All series in the list have",%nterms,"terms"]];\
    Sel[%p[1] = 1, %l : EqualS[%r,$n];\
		   Union[Ar[19,%l[$1+1]]/S[%l[1],Ghg[$$x]->1]],\
        %p[1] = 2, Union[EqualW[%r,$n]] (-1)^$n Gamma[$u] Gamma[$v]\
		   Gamma[$w]/(Gamma[$u-$n] Gamma[$v-$n] Gamma[$w-$n]),\
        %p[1] = 3, Union[EqualWN[%r,$n,%p[2]]] (-1)^$n Gamma[$u] Gamma[$v]\
	           Gamma[$w]/(Gamma[$u-$n] Gamma[$v-$n] Gamma[$w-$n])])

WPT_:Tier
/*: WPT[$Ghg,|$p|] 
	calculates equivalent series to $Ghg, which must be 
	a terminating well-poised function of the form Ghg[7,6,#[...],#[...],1].
	One of the numerator parameters, c say, must have the property 
	Natp[1-c]=1.  The choice of 
		$p = 1 yields a list of Saalschutzian 4F3(1)'s,
		$p = 2 yields a list of terminating well-poised 7F6(1)'s and 
		|$p| = |3,r| yields nonterminating well-poised 7F6(1)'s.
	r may be either 1,2 or 3. Each choice of r produces a list of no
	more than 20 elements with divergent and identical elements removed. */
WPT[Ghg[7,6,#[$a,$b_=$b=1+$a/2,$c,$d,$e,$f,$n_=Natp[1-$n]],\
 #[$g_=$g=$a/2,$h_=$h=1+$a-$c,$i_=$i=1+$a-$d,$j_=$j=1+$a-$e,\
 $k_=$k=1+$a-$f,$l_=$l=1+$a-$n],1],$p] :: \
       (Lcl[%l,%nertms,%p,%r]; %nterms : 1-$n;\
               %r[1] : -2/3-$a/2+$c/2+$d/2+$e/2+$f/2-$n/6;\
               %r[2] : -2/3-3$a/2+$c/2+$d/2+$e/2+$f/2+5$n/6;\
               %r[3] :  1/3+$a/2+$c/2-$d/2-$e/2-$f/2-$n/6;\
               %r[4] :  1/3+$a/2-$c/2+$d/2-$e/2-$f/2-$n/6;\
               %r[5] :  1/3+$a/2-$c/2-$d/2+$e/2-$f/2-$n/6;\
               %r[6] :  1/3+$a/2-$c/2-$d/2-$e/2+$f/2-$n/6;\
    %p : If[Listp[$p],$p,{$p}];\
    If[%p[1]=1 | %p[1]=2, Pr["All series in the list have",%nterms,"terms"]];\
    Sel[%p[1] = 1, Union[EqualS[%r,$n]] Gamma[1+$a-$c] Gamma[1+$a-$d] \
		   Gamma[1+$a-$e] Gamma[1+$a-$f] Gamma[1+$a-$n]/(Gamma[1+$a] \
		   Gamma[1+$a-$c-$n] Gamma[1+$a-$d-$n] Gamma[1+$a-$e-$n] \
		   Gamma[1+$a-$f-$n]),\
        %p[1] = 2, %l : EqualW[%r,$n];\
    	           Union[Ar[29,%l[$1+1]]/S[%l[1],Ghg[$$x]->1]],\
        %p[1] = 3, Union[EqualWN[%r,$n,%p[2]]] Gamma[1+$a-$c] Gamma[1+$a-$d] \
		   Gamma[1+$a-$e] Gamma[1+$a-$f] Gamma[1+$a-$n]/(Gamma[1+$a] \
		   Gamma[1+$a-$c-$n] Gamma[1+$a-$d-$n] Gamma[1+$a-$e-$n] \
		   Gamma[1+$a-$f-$n])])

WPNT_:Tier
/*: WPNT[$Ghg,|$p|] 
	calculates equivalent series to $Ghg, which must be 
	a nonterminating well-poised function of the form
	Ghg[7,6,#[c+d-n-1,1+(c+d-n-1)/2,c,d,e,f,g],
		#[(c+d-n-1)/2,d-n,c-n,c+d-e-n,c+d-f-n,c+d-g-n],1] 
	where n must have the property Natp[-n]=1.
	The choice of 
		$p = 1 yields a list of Saalschutzian 4F3(1)'s,
		$p = 2 yields a list of terminating well-poised 7F6(1)'s and 
		|$p| = |3,r| yields nonterminating well-poised 7F6(1)'s.
	r may be either 1,2 or 3. Each choice of r produces a list of no
	more than 20 elements with divergent and identical elements removed. */
WPNT[Ghg[7,6,#[$a_=$a=$c+$i-1,$b_=$b=1+$a/2,$c,$d,$e,$f,$g],\
 #[$h_=$h=$a/2,$i_=Natp[$d-$i],$j_=$j=1+$a-$d,$k_=$k=1+$a-$e,\
 $l_=$l=1+$a-$f,$m_=$m=1+$a-$g],1],$p] :: \
       (Lcl[%mult,%n,%nterms,%p,%r]; %n : $i-$d; %nterms : 1-%n;\
               %r[1] : -1/6-$e/2+$f/2+$g/2-%n/6;\
               %r[2] : -1/6+$e/2-$f/2+$g/2-%n/6;\
               %r[3] : -1/6+$e/2+$f/2-$g/2-%n/6;\
               %r[4] :  5/6-$c-$d+$e/2+$f/2+$g/2-7%n/6;\
               %r[5] : -1/6+$d-$e/2-$f/2-$g/2+5%n/6;\
               %r[6] : -1/6+$c-$e/2-$f/2-$g/2+5%n/6;\
    %p : If[Listp[$p],$p,{$p}];\
    %mult : Gamma[$c+%n] Gamma[$d+%n] Gamma[$c+$d-$e+%n] Gamma[$c+$d-$f+%n] \
	    Gamma[$c+$d-$g+%n] Gamma[$c+$d-$e-$f-$g+2%n]/(Gamma[$c] Gamma[$d] \
	    Gamma[$c+$d+%n] Gamma[$c+$d-$e-$f+%n] Gamma[$c+$d-$e-$g+%n] \
	    Gamma[$c+$d-$f-$g+%n]);\
    If[%p[1]=1 | %p[1]=2, Pr["All series in the list have",%nterms,"terms"]];\
    Sel[%p[1] = 1, Union[EqualS[%r,%n]] %mult,\
        %p[1] = 2, Union[EqualW[%r,%n]] %mult,\
        %p[1] = 3, Union[EqualWN[%r,%n,%p[2]]] %mult])

/*: EqualS[$r,$n] produces a list of 20 equivalent Saalschutzian 4F3(1)'s,
    including the series obtained by reversal. It is used by functions
    Saal, WPT and WPNT. */
EqualS[$r,$n] :: (Lcl[%eps,%S,%Svalue];\
   %eps[$i,$j] : $r[$i]+$r[$j]+1/3+$n/3;\
       %Svalue : %S[$k,$l,$m] --> \
    Ap[(-1)^$n Gamma[1-%eps[$L,$M]] Gamma[1-%eps[$K,$M]] Gamma[1-%eps[$K,$L]]/\
      (Gamma[1+$n-%eps[$L,$M]] Gamma[1+$n-%eps[$K,$M]] Gamma[1+$n-%eps[$K,$L]])\
       Ghg[4,3,#[%eps[$l,$m],%eps[$k,$m],%eps[$k,$l],$n],\
	      #[1+$n-%eps[$L,$M],1+$n-%eps[$K,$M],1+$n-%eps[$K,$L]],1],\
	     Cmpl[{$k,$l,$m},{1,2,3,4,5,6}]];\
  S[Sort[Flat[Ar[4,Ar[5-$1,Ar[$2,%S[$1,6-$2,7-$3]]]]]],%Svalue])

/*: EqualW[$r,$n] produces a list of 30 equivalent terminating 
    well-poised 7F6(1)'s, including the series obtained by reversal. 
    It is used by functions Saal, WPT and WPNT. */
EqualW[$r,$n] :: (Lcl[%del,%eps,%W,%Wvalue];\
       %del[$i,$j] : $r[$i]-$r[$j]+$n;\
       %eps[$i,$j] : $r[$i]+$r[$j]+1/3+$n/3;\
           %Wvalue : %W[$k,$K] --> \
    Ap[Gamma[1+%del[$k,$K]] Gamma[1-%eps[$1,$K]] Gamma[1-%eps[$2,$K]]\
       Gamma[1-%eps[$3,$K]] Gamma[1-%eps[$4,$K]]/\
      (Gamma[1-$n+%del[$k,$K]] Gamma[1+$n-%eps[$1,$K]] Gamma[1+$n-%eps[$2,$K]]\
       Gamma[1+$n-%eps[$3,$K]] Gamma[1+$n-%eps[$4,$K]])\
    Ghg[7,6,#[%del[$k,$K],1+%del[$k,$K]/2,$n,%eps[$k,$1],%eps[$k,$2],\
       %eps[$k,$3],%eps[$k,$4]],#[%del[$k,$K]/2,1-$n+%del[$k,$K],\
       1+$n-%eps[$K,$1],1+$n-%eps[$K,$2],1+$n-%eps[$K,$3],1+$n-%eps[$K,$4]],1],\
       Cmpl[{$k,$K},{1,2,3,4,5,6}]];\
   S[Cat[Sort[Flat[Ar[5,Ar[6-$1,%W[$1,7-$2]]]]],\
         Sort[Flat[Ar[5,Ar[6-$1,%W[7-$2,$1]]]]]],%Wvalue])

/*: EqualWN[$r,$n,$set] produces a list of 20 equivalent nonterminating 
    well-poised 7F6(1)'s. $set may take on the values of 1, 2 or 3 to
    produce the complete set of 60 equivalent series. EqualWN is used 
    by functions Saal, WPT and WPNT. */
EqualWN[$r,$n,$set_=$set=1|$set=2|$set=3] :: \
 (Lcl[%del,%eps,%lam,%list,%W,%Wvalue];\
       %del[$i,$j] : $r[$i]-$r[$j]+$n;\
       %eps[$i,$j] : $r[$i]+$r[$j]+1/3+$n/3;\
    %lam[$i,$j,$k] : $n/3+1/3-2$r[$i]-$r[$j]-$r[$k];\
            %W[$K,$L,$M] :: \
 Ap[Gamma[1+%lam[$K,$L,$M]] Gamma[1-%eps[$K,$L]] Gamma[1-%eps[$K,$M]]\
    Gamma[1-%eps[$k,$K]] Gamma[1-%eps[$l,$K]] Gamma[1-%eps[$m,$K]]/\
   (Gamma[1-$n+%del[$k,$K]] Gamma[1-$n+%del[$l,$K]] Gamma[1-$n+%del[$m,$K]]\
    Gamma[1+$n-%eps[$K,$L]] Gamma[1+$n-%eps[$K,$M]] Gamma[%eps[$L,$M]])\
 Ghg[7,6,#[%lam[$K,$L,$M],1+%lam[$K,$L,$M]/2,1-%eps[$K,$L],1-%eps[$K,$M],\
    %eps[$k,$l],%eps[$k,$m],%eps[$l,$m]],#[%lam[$K,$L,$M]/2,1+$n-%eps[$K,$M],\
    1+$n-%eps[$K,$L],1-$n+%del[$k,$K],1-$n+%del[$l,$K],1-$n+%del[$m,$K]],1],\
    Cmpl[{$K,$L,$M},{1,2,3,4,5,6}]];\
 %list : Cat[Flat[Ar[2,Ar[5,Ar[6-$2,\
     %W[$1+2$set-2,$2,7-$3],(7-$3)~=$1+2$set-2],$2~=$1+2$set-2]]]];\
 Cat[Ar[20,%list,,AllCvgtp]])
/* In EqualWN the test AllCvgtp is applied last to conserve memory. */

_XGhg4[Loaded] : 1

/*R: F J W Whipple, Proc. London Math. Soc. (2), Vol.25, 525-44, 1926.
     See also L J Slater 1966 "Generalized Hypergeometric Functions",
     Cambridge University Press. The notation in these works has been
     adhered to fairly closely, but $n and %n are opposite in sign to 
     variable n used in the references. */

