77"""
88
99import mpmath
10- import sympy
1110
1211import mathics .eval .tracing as tracing
1312from mathics .core .attributes import (
1817)
1918from mathics .core .builtin import MPMathFunction
2019from mathics .core .convert .mpmath import from_mpmath
21- from mathics .core .convert .sympy import from_sympy
2220from mathics .core .evaluation import Evaluation
2321from mathics .core .systemsymbols import SymbolComplexInfinity , SymbolMachinePrecision
2422from mathics .eval .specialfns .hypergeom import (
2523 eval_Hypergeometric1F1 ,
2624 eval_Hypergeometric2F1 ,
2725 eval_HypergeometricPQF ,
26+ eval_MeijerG ,
2827 eval_N_HypergeometricPQF ,
2928)
3029
@@ -202,6 +201,47 @@ def eval(self, a, b, c, z, evaluation: Evaluation):
202201 return eval_Hypergeometric2F1 (a , b , c , z )
203202
204203
204+ class HypergeometricU (MPMathFunction ):
205+ """
206+ <url>
207+ :Confluent hypergeometric function: https://en.wikipedia.org/wiki/Confluent_hypergeometric_function</url> (<url>
208+ :mpmath: https://mpmath.org/doc/current/functions/bessel.html#mpmath.hyperu</url>, <url>
209+ :WMA: https://reference.wolfram.com/language/ref/HypergeometricU.html</url>)
210+ <dl>
211+ <dt>'HypergeometricU'[$a$, $b$, $z$]
212+ <dd>returns $U(a, b, z)$.
213+ </dl>
214+ Result is symbollicaly simplified, where possible:
215+ >> HypergeometricU[3, 2, 1]
216+ = MeijerG[{{-2}, {}}, {{0, -1}, {}}, 1] / 2
217+ >> HypergeometricU[1,4,8]
218+ = HypergeometricU[1, 4, 8]
219+ unless a numerical evaluation is explicitly requested:
220+ >> HypergeometricU[3, 2, 1] // N
221+ = 0.105479
222+ >> HypergeometricU[3, 2, 1.]
223+ = 0.105479
224+
225+ Plot 'U'[3, 2, x] from 0 to 10 in steps of 0.5:
226+ >> Plot[HypergeometricU[3, 2, x], {x, 0.5, 10}]
227+ = -Graphics-
228+
229+ We handle this special case:
230+ >> HypergeometricU[0, b, z]
231+ = 1
232+ """
233+
234+ attributes = A_LISTABLE | A_NUMERIC_FUNCTION | A_PROTECTED | A_READ_PROTECTED
235+ mpmath_name = "hyperu"
236+ nargs = {3 }
237+ rules = {
238+ "HypergeometricU[0, c_, z_]" : "1" ,
239+ "HypergeometricU[a_, b_, z_] /; (a > 0) && (a-b+1 > 0)" : "MeijerG[{{1-a},{}},{{0,1-b},{}},z]/Gamma[a]/Gamma[a-b+1]" ,
240+ }
241+ summary_text = "compute the Tricomi confluent hypergeometric function"
242+ sympy_name = ""
243+
244+
205245class MeijerG (MPMathFunction ):
206246 """
207247 <url>
@@ -232,15 +272,7 @@ class MeijerG(MPMathFunction):
232272
233273 def eval (self , a , b , z , evaluation : Evaluation ):
234274 "MeijerG[a_, b_, z_]"
235- try :
236- a_sympy = [[e2 .to_sympy () for e2 in e1 ] for e1 in a ]
237- b_sympy = [[e2 .to_sympy () for e2 in e1 ] for e1 in b ]
238- result_sympy = tracing .run_sympy (
239- sympy .meijerg , a_sympy , b_sympy , z .to_sympy ()
240- )
241- return from_sympy (result_sympy )
242- except Exception :
243- pass
275+ return eval_MeijerG (a , b , z )
244276
245277 def eval_N (self , a , b , z , prec , evaluation : Evaluation ):
246278 "N[MeijerG[a_, b_, z_], prec_]"
@@ -257,44 +289,3 @@ def eval_N(self, a, b, z, prec, evaluation: Evaluation):
257289 def eval_numeric (self , a , b , z , evaluation : Evaluation ):
258290 "MeijerG[a:{___List?(AllTrue[#, NumericQ, Infinity]&)}, b:{___List?(AllTrue[#, NumericQ, Infinity]&)}, z_?MachineNumberQ]"
259291 return self .eval_N (a , b , z , SymbolMachinePrecision , evaluation )
260-
261-
262- class HypergeometricU (MPMathFunction ):
263- """
264- <url>
265- :Confluent hypergeometric function: https://en.wikipedia.org/wiki/Confluent_hypergeometric_function</url> (<url>
266- :mpmath: https://mpmath.org/doc/current/functions/bessel.html#mpmath.hyperu</url>, <url>
267- :WMA: https://reference.wolfram.com/language/ref/HypergeometricU.html</url>)
268- <dl>
269- <dt>'HypergeometricU'[$a$, $b$, $z$]
270- <dd>returns $U(a, b, z)$.
271- </dl>
272- Result is symbollicaly simplified, where possible:
273- >> HypergeometricU[3, 2, 1]
274- = MeijerG[{{-2}, {}}, {{0, -1}, {}}, 1] / 2
275- >> HypergeometricU[1,4,8]
276- = HypergeometricU[1, 4, 8]
277- unless a numerical evaluation is explicitly requested:
278- >> HypergeometricU[3, 2, 1] // N
279- = 0.105479
280- >> HypergeometricU[3, 2, 1.]
281- = 0.105479
282-
283- Plot 'U'[3, 2, x] from 0 to 10 in steps of 0.5:
284- >> Plot[HypergeometricU[3, 2, x], {x, 0.5, 10}]
285- = -Graphics-
286-
287- We handle this special case:
288- >> HypergeometricU[0, b, z]
289- = 1
290- """
291-
292- attributes = A_LISTABLE | A_NUMERIC_FUNCTION | A_PROTECTED | A_READ_PROTECTED
293- mpmath_name = "hyperu"
294- nargs = {3 }
295- rules = {
296- "HypergeometricU[0, c_, z_]" : "1" ,
297- "HypergeometricU[a_, b_, z_] /; (a > 0) && (a-b+1 > 0)" : "MeijerG[{{1-a},{}},{{0,1-b},{}},z]/Gamma[a]/Gamma[a-b+1]" ,
298- }
299- summary_text = "compute the Tricomi confluent hypergeometric function"
300- sympy_name = ""
0 commit comments