       /** Convergence of generalized hypergeometric functions. **/

/*K: Hypergeometric, Sums, convergent */
/*A: K McIsaac */
/*S: University of Western Australia, Crawley 6009, Australia */
/*D: May 1985*/

/*: AllCvgtp[$expr] checks if all hypergeometric functions in $expr are
     convergent. */
AllCvgtp[$expr] :: \
     Ap[And,Map[Cvgtp,Ap[$1/Map[Nc,$1],{Pos[Ghg[$$1],$expr,$expr]}]]]

/*: Cvgtp[$Ghg] 
	checks if $Ghg is convergent generalized hypergeometric series. */

/*R: Rainville, Special Functions, p73*/

Cvgtp[Ghg[$p,$q,#[$$a],#[$$b]_=Ap[Max,NegElem[{$$a}]] < \
		      		        Ap[Max,NegElem[{$$b}]],$z]] : 0
Cvgtp[Ghg[$p,$q,#[$$a_=Negparm[{$$a}]],#[$$b_=~Negparm[{$$b}]],$z]] : 1
Cvgtp[Ghg[$p,$q,#[$$a_=~Negparm[{$$a}]],#[$$b_=~Negparm[{$$b}]],$z]]:: \
						Hcvgtp[$p,$q,{$$a},{$$b},$z] 
Cvgtp[Ghg[$p,$q,#[$$a],#[$$b],0]] : 1

Hcvgtp_:Tier
Hcvgtp[$p,$q_=$q>=$p ,$a,$b,$z] : 1
Hcvgtp[$p,$q_=$q<$p-1,$a,$b,$z] :: P[$z=0]
Hcvgtp[$p,$p-1,$a,$b,$z] ::         Abs[$z] < 1|\
			   ($z= 1 & Re[Ap['Plus,$b]-Ap['Plus,$a]] >  0)|\
			   ($z=-1 & Re[Ap['Plus,$b]-Ap['Plus,$a]] > -1)


/*:  Nterms[$Ghg]
	returns the number of terms in the series representation of the 
	generalized hypergeometric function $Ghg or Inf if it doesn't
	terminate. The number of terms is 1 plus the absolute value
	of the parameter which causes the series to terminate (as the
	first term in the series corresponds to the index being zero). */
Nterms[Ghg[$p,$q,#[$$a_=Negparm[{$$a}]],#[$$b_=~Negparm[{$$b}]],$z]] ::\ 
		1-Ap[Max,NegElem[{$$a}]] 

Nterms[Ghg[$p,$q,#[$$a_=Negparm[{$$a}]],#[$$b_=Negparm[{$$b}]]_=\
		Ap[Max,NegElem[{$$a}]] > Ap[Max,NegElem[{$$b}]] ,$z]] ::\ 
		1-Ap[Max,NegElem[{$$a}]] 

Nterms[Ghg[$p,$q,#[$$a_=~Negparm[{$$a}]],#[$$b_=~Negparm[{$$b}]],$z]] :: Inf

Nterms[Ghg[$p,0,#[$$a_= Negparm[{$$a}]],#[],$z]] :: 1-Ap[Max,NegElem[{$$a}]] 

Nterms[Ghg[$p,0,#[$$a_=~Negparm[{$$a}]],#[],$z]] :: Inf

Nterms[Ghg[0,$q,#[],#[$$b],$z]] :: Inf


/* Hypergeometrics with negative lower parameters are generally divergent.
   It they do terminate the last element may be ambiguous, so it  should be
   specified by the user. */

/*: NegElem[$list] returns an ordered list of the distinct non-positive integral
    elements of $list. */
NegElem[$list_=Listp[$list]] :: Union[Cat[Ar[Len[$list],$list,,Natp[1-$1]]]]

/*: Negparm[$list] returns 1 if one of the elements of $list is a negative 
   (or zero) integer. */
Negparm[$list_=Listp[$list]] :: In[$x_=Natp[1-$x],$list,2]  

_XCvgt[Loaded] : 1

