<s> from scipy . special import gamma , hyp2f1 , gammaln <EOL> from numpy import * <EOL> import pdb <EOL> def pochdivgamma ( a , b , iterations ) : <EOL> out = zeros ( iterations , float64 ) <EOL> out [ <NUM_LIT:0> ] = <NUM_LIT:1.0> / gamma ( b ) <EOL> out [ <NUM_LIT:1> : ] = ( a + arange ( iterations - <NUM_LIT:1> ) . astype ( float64 ) ) / ( b + arange ( iterations - <NUM_LIT:1> ) . astype ( float64 ) ) <EOL> return cumprod ( out ) <EOL> def hyper3F2regularizedZ1 ( a1 , a2 , a3 , b1 , b2 ) : <EOL> '''<STR_LIT>''' <EOL> iterations = int ( max ( - <NUM_LIT:2> * a1 , - <NUM_LIT:2> * a2 , - <NUM_LIT:2> * a3 , <NUM_LIT:100> ) ) <EOL> a1b1term = pochdivgamma ( a1 , b1 , iterations ) <EOL> a3b2term = pochdivgamma ( a3 , b2 , iterations ) <EOL> a2kterm = pochdivgamma ( a2 , <NUM_LIT:1> , iterations ) <EOL> termprod = a1b1term * a3b2term * a2kterm <EOL> pdb . set_trace ( ) <EOL> return sum ( termprod ) , abs ( termprod [ - <NUM_LIT:1> ] ) <EOL> def pochdivpoch ( a , b , iterations ) : <EOL> out = zeros ( iterations , float64 ) <EOL> out [ <NUM_LIT:0> ] = <NUM_LIT:1.0> <EOL> out [ <NUM_LIT:1> : ] = ( a + arange ( iterations - <NUM_LIT:1> ) . astype ( float128 ) ) / ( b + arange ( iterations - <NUM_LIT:1> ) . astype ( float128 ) ) <EOL> return cumprod ( out ) <EOL> def pochdivpochgen ( a , b ) : <EOL> '<STR_LIT>' <EOL> count = <NUM_LIT:0> <EOL> oldval = <NUM_LIT:0.0> <EOL> out = zeros ( <NUM_LIT> , float64 ) <EOL> out [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> while True : <EOL> out [ <NUM_LIT:1> : ] = ( a + arange ( count , count + <NUM_LIT:100> , dtype = float64 ) ) / ( b + arange ( count , count + <NUM_LIT:100> , dtype = float64 ) ) <EOL> out = cumprod ( out ) <EOL> yield out [ <NUM_LIT:1> : ] <EOL> out [ <NUM_LIT:0> ] = out [ - <NUM_LIT:1> ] <EOL> count += <NUM_LIT:100> <EOL> def hyper3F2Z1 ( a1 , a2 , a3 , b1 , b2 , tol = <NUM_LIT> ) : <EOL> '''<STR_LIT>''' <EOL> a1b1terms = pochdivpochgen ( a1 , b1 ) <EOL> a3b2terms = pochdivpochgen ( a3 , b2 ) <EOL> a2kterms = pochdivpochgen ( a2 , <NUM_LIT:1> ) <EOL> terms = [ ] <EOL> while True : <EOL> termprod = a1b1terms . next ( ) * a3b2terms . next ( ) * a2kterms . next ( ) <EOL> terms . append ( termprod ) <EOL> if abs ( termprod [ - <NUM_LIT:1> ] ) < tol : <EOL> break <EOL> terms . reverse ( ) <EOL> return <NUM_LIT:1.0> + sum ( [ sum ( t [ : : - <NUM_LIT:1> ] ) for t in terms ] ) , terms [ <NUM_LIT:0> ] [ - <NUM_LIT:1> ] <EOL> def hyp2f1mine ( a , b , c ) : <EOL> '<STR_LIT>' <EOL> return exp ( gammaln ( c ) + gammaln ( c - a - b ) - gammaln ( c - a ) - gammaln ( c - b ) ) <EOL> def hyper3F2aZ1 ( a1 , a2 , a3 , b2 , tol = <NUM_LIT> ) : <EOL> '''<STR_LIT>''' <EOL> if ( a2 > - <NUM_LIT:2> ) : <EOL> toladjust = tol / max ( <NUM_LIT:1> , abs ( ( a2 - a1 - <NUM_LIT:1> ) / ( a2 - <NUM_LIT:1> ) ) ) <EOL> temp = ( ( a2 - a1 - <NUM_LIT:1> ) * hyper3F2aZ1 ( a1 , a2 - <NUM_LIT:1> , a3 , b2 , tol = toladjust ) + a1 * hyp2f1mine ( a2 - <NUM_LIT:1> , a3 , b2 ) ) / ( a2 - <NUM_LIT:1> ) <EOL> return temp <EOL> if ( a2 < - <NUM_LIT:10> ) : <EOL> a2new = arange ( a2 , - <NUM_LIT:9> ) <EOL> A = [ a1 * hyp2f1mine ( a2n , a3 , b2 ) for a2n in a2new ] <EOL> B = a2new <EOL> C = ( a1 - a2new ) <EOL> B [ - <NUM_LIT:1> ] = a2new [ - <NUM_LIT:1> ] * hyper3F2aZ1 ( a1 , a2new [ - <NUM_LIT:1> ] + <NUM_LIT:1> , a3 , b2 ) <EOL> for idx in arange ( len ( B ) - <NUM_LIT:1> , <NUM_LIT:0> , - <NUM_LIT:1> ) : <EOL> B [ idx - <NUM_LIT:1> ] *= ( A [ idx ] - B [ idx ] ) / C [ idx ] <EOL> return ( A [ <NUM_LIT:0> ] - B [ <NUM_LIT:0> ] ) / C [ <NUM_LIT:0> ] <EOL> else : <EOL> return hyper3F2Z1 ( a1 , a2 , a3 , a1 + <NUM_LIT:1> , b2 , tol = tol ) [ <NUM_LIT:0> ] </s>
