<s> """<STR_LIT>""" <EOL> from __future__ import print_function , division <EOL> from sympy . core import S , pi , I <EOL> from sympy . core . function import Function , ArgumentIndexError <EOL> from sympy . functions . elementary . hyperbolic import atanh <EOL> from sympy . functions . elementary . trigonometric import sin , tan <EOL> from sympy . functions . elementary . miscellaneous import sqrt <EOL> from sympy . functions . elementary . complexes import sign <EOL> from sympy . functions . special . hyper import hyper , meijerg <EOL> from sympy . functions . special . gamma_functions import gamma <EOL> class elliptic_k ( Function ) : <EOL> r"""<STR_LIT>""" <EOL> @ classmethod <EOL> def eval ( cls , z ) : <EOL> if z is S . Zero : <EOL> return pi / <NUM_LIT:2> <EOL> elif z is S . Half : <EOL> return <NUM_LIT:8> * pi ** ( S ( <NUM_LIT:3> ) / <NUM_LIT:2> ) / gamma ( - S ( <NUM_LIT:1> ) / <NUM_LIT:4> ) ** <NUM_LIT:2> <EOL> elif z is S . One : <EOL> return S . ComplexInfinity <EOL> elif z is S . NegativeOne : <EOL> return gamma ( S ( <NUM_LIT:1> ) / <NUM_LIT:4> ) ** <NUM_LIT:2> / ( <NUM_LIT:4> * sqrt ( <NUM_LIT:2> * pi ) ) <EOL> elif z in ( S . Infinity , S . NegativeInfinity , I * S . Infinity , <EOL> I * S . NegativeInfinity , S . ComplexInfinity ) : <EOL> return S . Zero <EOL> def fdiff ( self , argindex = <NUM_LIT:1> ) : <EOL> z = self . args [ <NUM_LIT:0> ] <EOL> return ( elliptic_e ( z ) - ( <NUM_LIT:1> - z ) * elliptic_k ( z ) ) / ( <NUM_LIT:2> * z * ( <NUM_LIT:1> - z ) ) <EOL> def _eval_conjugate ( self ) : <EOL> z = self . args [ <NUM_LIT:0> ] <EOL> if ( z . is_real and ( z - <NUM_LIT:1> ) . is_positive ) is False : <EOL> return self . func ( z . conjugate ( ) ) <EOL> def _eval_nseries ( self , x , n , logx ) : <EOL> from sympy . simplify import hyperexpand <EOL> return hyperexpand ( self . rewrite ( hyper ) . _eval_nseries ( x , n = n , logx = logx ) ) <EOL> def _eval_rewrite_as_hyper ( self , z ) : <EOL> return ( pi / <NUM_LIT:2> ) * hyper ( ( S . Half , S . Half ) , ( S . One , ) , z ) <EOL> def _eval_rewrite_as_meijerg ( self , z ) : <EOL> return meijerg ( ( ( S . Half , S . Half ) , [ ] ) , ( ( S . Zero , ) , ( S . Zero , ) ) , - z ) / <NUM_LIT:2> <EOL> def _sage_ ( self ) : <EOL> import sage . all as sage <EOL> return sage . elliptic_kc ( self . args [ <NUM_LIT:0> ] . _sage_ ( ) ) <EOL> class elliptic_f ( Function ) : <EOL> r"""<STR_LIT>""" <EOL> @ classmethod <EOL> def eval ( cls , z , m ) : <EOL> k = <NUM_LIT:2> * z / pi <EOL> if m . is_zero : <EOL> return z <EOL> elif z . is_zero : <EOL> return S . Zero <EOL> elif k . is_integer : <EOL> return k * elliptic_k ( m ) <EOL> elif m in ( S . Infinity , S . NegativeInfinity ) : <EOL> return S . Zero <EOL> elif z . could_extract_minus_sign ( ) : <EOL> return - elliptic_f ( - z , m ) <EOL> def fdiff ( self , argindex = <NUM_LIT:1> ) : <EOL> z , m = self . args <EOL> fm = sqrt ( <NUM_LIT:1> - m * sin ( z ) ** <NUM_LIT:2> ) <EOL> if argindex == <NUM_LIT:1> : <EOL> return <NUM_LIT:1> / fm <EOL> elif argindex == <NUM_LIT:2> : <EOL> return ( elliptic_e ( z , m ) / ( <NUM_LIT:2> * m * ( <NUM_LIT:1> - m ) ) - elliptic_f ( z , m ) / ( <NUM_LIT:2> * m ) - <EOL> sin ( <NUM_LIT:2> * z ) / ( <NUM_LIT:4> * ( <NUM_LIT:1> - m ) * fm ) ) <EOL> raise ArgumentIndexError ( self , argindex ) <EOL> def _eval_conjugate ( self ) : <EOL> z , m = self . args <EOL> if ( m . is_real and ( m - <NUM_LIT:1> ) . is_positive ) is False : <EOL> return self . func ( z . conjugate ( ) , m . conjugate ( ) ) <EOL> class elliptic_e ( Function ) : <EOL> r"""<STR_LIT>""" <EOL> @ classmethod <EOL> def eval ( cls , z , m = None ) : <EOL> if m is not None : <EOL> k = <NUM_LIT:2> * z / pi <EOL> if m . is_zero : <EOL> return z <EOL> if z . is_zero : <EOL> return S . Zero <EOL> elif k . is_integer : <EOL> return k * elliptic_e ( m ) <EOL> elif m in ( S . Infinity , S . NegativeInfinity ) : <EOL> return S . ComplexInfinity <EOL> elif z . could_extract_minus_sign ( ) : <EOL> return - elliptic_e ( - z , m ) <EOL> else : <EOL> if z . is_zero : <EOL> return pi / <NUM_LIT:2> <EOL> elif z is S . One : <EOL> return S . One <EOL> elif z is S . Infinity : <EOL> return I * S . Infinity <EOL> elif z is S . NegativeInfinity : <EOL> return S . Infinity <EOL> elif z is S . ComplexInfinity : <EOL> return S . ComplexInfinity <EOL> def fdiff ( self , argindex = <NUM_LIT:1> ) : <EOL> if len ( self . args ) == <NUM_LIT:2> : <EOL> z , m = self . args <EOL> if argindex == <NUM_LIT:1> : <EOL> return sqrt ( <NUM_LIT:1> - m * sin ( z ) ** <NUM_LIT:2> ) <EOL> elif argindex == <NUM_LIT:2> : <EOL> return ( elliptic_e ( z , m ) - elliptic_f ( z , m ) ) / ( <NUM_LIT:2> * m ) <EOL> else : <EOL> z = self . args [ <NUM_LIT:0> ] <EOL> if argindex == <NUM_LIT:1> : <EOL> return ( elliptic_e ( z ) - elliptic_k ( z ) ) / ( <NUM_LIT:2> * z ) <EOL> raise ArgumentIndexError ( self , argindex ) <EOL> def _eval_conjugate ( self ) : <EOL> if len ( self . args ) == <NUM_LIT:2> : <EOL> z , m = self . args <EOL> if ( m . is_real and ( m - <NUM_LIT:1> ) . is_positive ) is False : <EOL> return self . func ( z . conjugate ( ) , m . conjugate ( ) ) <EOL> else : <EOL> z = self . args [ <NUM_LIT:0> ] <EOL> if ( z . is_real and ( z - <NUM_LIT:1> ) . is_positive ) is False : <EOL> return self . func ( z . conjugate ( ) ) <EOL> def _eval_nseries ( self , x , n , logx ) : <EOL> from sympy . simplify import hyperexpand <EOL> if len ( self . args ) == <NUM_LIT:1> : <EOL> return hyperexpand ( self . rewrite ( hyper ) . _eval_nseries ( x , n = n , logx = logx ) ) <EOL> return super ( elliptic_e , self ) . _eval_nseries ( x , n = n , logx = logx ) <EOL> def _eval_rewrite_as_hyper ( self , * args ) : <EOL> if len ( args ) == <NUM_LIT:1> : <EOL> z = args [ <NUM_LIT:0> ] <EOL> return ( pi / <NUM_LIT:2> ) * hyper ( ( - S . Half , S . Half ) , ( S . One , ) , z ) <EOL> def _eval_rewrite_as_meijerg ( self , * args ) : <EOL> if len ( args ) == <NUM_LIT:1> : <EOL> z = args [ <NUM_LIT:0> ] <EOL> return - meijerg ( ( ( S . Half , S ( <NUM_LIT:3> ) / <NUM_LIT:2> ) , [ ] ) , ( ( S . Zero , ) , ( S . Zero , ) ) , - z ) / <NUM_LIT:4> <EOL> class elliptic_pi ( Function ) : <EOL> r"""<STR_LIT>""" <EOL> @ classmethod <EOL> def eval ( cls , n , m , z = None ) : <EOL> if z is not None : <EOL> n , z , m = n , m , z <EOL> k = <NUM_LIT:2> * z / pi <EOL> if n == S . Zero : <EOL> return elliptic_f ( z , m ) <EOL> elif n == S . One : <EOL> return ( elliptic_f ( z , m ) + <EOL> ( sqrt ( <NUM_LIT:1> - m * sin ( z ) ** <NUM_LIT:2> ) * tan ( z ) - <EOL> elliptic_e ( z , m ) ) / ( <NUM_LIT:1> - m ) ) <EOL> elif k . is_integer : <EOL> return k * elliptic_pi ( n , m ) <EOL> elif m == S . Zero : <EOL> return atanh ( sqrt ( n - <NUM_LIT:1> ) * tan ( z ) ) / sqrt ( n - <NUM_LIT:1> ) <EOL> elif n == m : <EOL> return ( elliptic_f ( z , n ) - elliptic_pi ( <NUM_LIT:1> , z , n ) + <EOL> tan ( z ) / sqrt ( <NUM_LIT:1> - n * sin ( z ) ** <NUM_LIT:2> ) ) <EOL> elif n in ( S . Infinity , S . NegativeInfinity ) : <EOL> return S . Zero <EOL> elif m in ( S . Infinity , S . NegativeInfinity ) : <EOL> return S . Zero <EOL> elif z . could_extract_minus_sign ( ) : <EOL> return - elliptic_pi ( n , - z , m ) <EOL> else : <EOL> if n == S . Zero : <EOL> return elliptic_k ( m ) <EOL> elif n == S . One : <EOL> return S . ComplexInfinity <EOL> elif m == S . Zero : <EOL> return pi / ( <NUM_LIT:2> * sqrt ( <NUM_LIT:1> - n ) ) <EOL> elif m == S . One : <EOL> return - S . Infinity / sign ( n - <NUM_LIT:1> ) <EOL> elif n == m : <EOL> return elliptic_e ( n ) / ( <NUM_LIT:1> - n ) <EOL> elif n in ( S . Infinity , S . NegativeInfinity ) : <EOL> return S . Zero <EOL> elif m in ( S . Infinity , S . NegativeInfinity ) : <EOL> return S . Zero <EOL> def _eval_conjugate ( self ) : <EOL> if len ( self . args ) == <NUM_LIT:3> : <EOL> n , z , m = self . args <EOL> if ( n . is_real and ( n - <NUM_LIT:1> ) . is_positive ) is False and ( m . is_real and ( m - <NUM_LIT:1> ) . is_positive ) is False : <EOL> return self . func ( n . conjugate ( ) , z . conjugate ( ) , m . conjugate ( ) ) <EOL> else : <EOL> n , m = self . args <EOL> return self . func ( n . conjugate ( ) , m . conjugate ( ) ) <EOL> def fdiff ( self , argindex = <NUM_LIT:1> ) : <EOL> if len ( self . args ) == <NUM_LIT:3> : <EOL> n , z , m = self . args <EOL> fm , fn = sqrt ( <NUM_LIT:1> - m * sin ( z ) ** <NUM_LIT:2> ) , <NUM_LIT:1> - n * sin ( z ) ** <NUM_LIT:2> <EOL> if argindex == <NUM_LIT:1> : <EOL> return ( elliptic_e ( z , m ) + ( m - n ) * elliptic_f ( z , m ) / n + <EOL> ( n ** <NUM_LIT:2> - m ) * elliptic_pi ( n , z , m ) / n - <EOL> n * fm * sin ( <NUM_LIT:2> * z ) / ( <NUM_LIT:2> * fn ) ) / ( <NUM_LIT:2> * ( m - n ) * ( n - <NUM_LIT:1> ) ) <EOL> elif argindex == <NUM_LIT:2> : <EOL> return <NUM_LIT:1> / ( fm * fn ) <EOL> elif argindex == <NUM_LIT:3> : <EOL> return ( elliptic_e ( z , m ) / ( m - <NUM_LIT:1> ) + <EOL> elliptic_pi ( n , z , m ) - <EOL> m * sin ( <NUM_LIT:2> * z ) / ( <NUM_LIT:2> * ( m - <NUM_LIT:1> ) * fm ) ) / ( <NUM_LIT:2> * ( n - m ) ) <EOL> else : <EOL> n , m = self . args <EOL> if argindex == <NUM_LIT:1> : <EOL> return ( elliptic_e ( m ) + ( m - n ) * elliptic_k ( m ) / n + <EOL> ( n ** <NUM_LIT:2> - m ) * elliptic_pi ( n , m ) / n ) / ( <NUM_LIT:2> * ( m - n ) * ( n - <NUM_LIT:1> ) ) <EOL> elif argindex == <NUM_LIT:2> : <EOL> return ( elliptic_e ( m ) / ( m - <NUM_LIT:1> ) + elliptic_pi ( n , m ) ) / ( <NUM_LIT:2> * ( n - m ) ) <EOL> raise ArgumentIndexError ( self , argindex ) </s>
