1212import mathics .eval .tracing as tracing
1313from mathics .core .attributes import (
1414 A_LISTABLE ,
15- A_N_HOLD_FIRST ,
1615 A_NUMERIC_FUNCTION ,
1716 A_PROTECTED ,
1817 A_READ_PROTECTED ,
2120from mathics .core .convert .mpmath import from_mpmath
2221from mathics .core .convert .sympy import from_sympy
2322from mathics .core .evaluation import Evaluation
24- from mathics .core .number import FP_MANTISA_BINARY_DIGITS
2523from mathics .core .systemsymbols import SymbolComplexInfinity , SymbolMachinePrecision
24+ from mathics .eval .specialfns .hypergeom import (
25+ eval_Hypergeometric2F1 ,
26+ eval_HypergeometricPQF ,
27+ eval_N_HypergeometricPQF ,
28+ )
2629
2730
2831class HypergeometricPFQ (MPMathFunction ):
@@ -70,27 +73,12 @@ class HypergeometricPFQ(MPMathFunction):
7073
7174 def eval (self , a , b , z , evaluation : Evaluation ):
7275 "HypergeometricPFQ[a_, b_, z_]"
73- try :
74- a_sympy = [e .to_sympy () for e in a ]
75- b_sympy = [e .to_sympy () for e in b ]
76- result_sympy = tracing .run_sympy (
77- sympy .hyper , a_sympy , b_sympy , z .to_sympy ()
78- )
79- return from_sympy (result_sympy )
80- except Exception :
81- pass
76+ return eval_HypergeometricPQF (a , b , z )
8277
8378 def eval_N (self , a , b , z , prec , evaluation : Evaluation ):
8479 "N[HypergeometricPFQ[a_, b_, z_], prec_]"
85- try :
86- result_mpmath = tracing .run_mpmath (
87- mpmath .hyper , a .to_python (), b .to_python (), z .to_python ()
88- )
89- return from_mpmath (result_mpmath )
90- except ZeroDivisionError :
91- return SymbolComplexInfinity
92- except Exception as ex :
93- pass
80+ # FIXME: prec is not used. Why?
81+ return eval_N_HypergeometricPQF (a , b , z )
9482
9583 def eval_numeric (self , a , b , z , evaluation : Evaluation ):
9684 "HypergeometricPFQ[a:{__?NumericQ}, b:{__?NumericQ}, z_?MachineNumberQ]"
@@ -124,7 +112,7 @@ class Hypergeometric1F1(MPMathFunction):
124112 """
125113
126114 attributes = A_LISTABLE | A_NUMERIC_FUNCTION | A_PROTECTED
127- mpmath_name = ""
115+ mpmath_name = "hymp1f1 "
128116 nargs = {3 }
129117 rules = {
130118 "Hypergeometric1F1[a_, b_, z_]" : "HypergeometricPFQ[{a},{b},z]" ,
@@ -133,6 +121,45 @@ class Hypergeometric1F1(MPMathFunction):
133121 sympy_name = ""
134122
135123
124+ class Hypergeometric2F1 (MPMathFunction ):
125+ """
126+ <url>
127+ :Hypergeometric function: https://en.wikipedia.org/wiki/Hypergeometric_function</url> (<url>
128+ :mpmath: https://mpmath.org/doc/current/functions/hypergeometric.html#mpmath.hyp2f1</url>, <url>
129+ :WMA: https://reference.wolfram.com/language/ref/Hypergeometric2F1.html</url>)
130+ <dl>
131+ <dt>'Hypergeometric2F1'[$a$, $b$, $c$, $z$]
132+ <dd>returns ${}_2 F_1(a; b; c; z)$.
133+ </dl>
134+
135+ >> Hypergeometric2F1[2., 3., 4., 5.0]
136+ = 0.156542 + 0.150796 I
137+
138+ Evaluate symbolically:
139+ >> Hypergeometric2F1[2, 3, 4, x]
140+ = 6 Log[1 - x] / x ^ 3 + (-6 + 3 x) / (-x ^ 2 + x ^ 3)
141+
142+ Evaluate using complex arguments:
143+ >> Hypergeometric2F1[2 + I, -I, 3/4, 0.5 - 0.5 I]
144+ = -0.972167 - 0.181659 I
145+
146+ Plot over a subset of the reals:
147+ >> Plot[Hypergeometric2F1[1/3, 1/3, 2/3, x], {x, -1, 1}]
148+ = -Graphics-
149+ """
150+
151+ attributes = A_LISTABLE | A_NUMERIC_FUNCTION | A_PROTECTED
152+ mpmath_name = "hyp2f1"
153+ nargs = {4 }
154+ summary_text = "compute Gauss hypergeometric function function"
155+ sympy_name = "hyper"
156+
157+ def eval (self , a , b , c , z , evaluation : Evaluation ):
158+ "Hypergeometric2F1[a_, b_, c_, z_]"
159+
160+ return eval_Hypergeometric2F1 (a , b , c , z )
161+
162+
136163class MeijerG (MPMathFunction ):
137164 """
138165 <url>
0 commit comments