# Computing a Gaussian hypergeometric function

I want to calculate the function gg[m, x] given by

gg[m_, x_] :=  Hypergeometric2F1[2 + m, 5/2 + m, 2 + 2 m, x^2]


in which x is between 1 and 0. I need to calculate this function with high values of m (1000 <= m <= 2000).

In some regions the calculation gives the result quickly. For example, when x is between 0, and .66, the speed of calculation is fast. Further, by using $MaxExtraPrecision = Infinity, I can calculate gg in the region .8 < x <. 999 quickly, However, in the region .72 < x < .80, it gets very slow. At x = .77 the calculation takes nearly a day to finish. I want to know how can I eliminate this hindrance to my calculations. I must mention that I give x as a rational number, say, 66/100 or 77/100, because I want to avoid machine arithmetic. • Why is a a parameter of gg if it is not used in gg? Might you have made an error in your definition? – Edmund Dec 19 '16 at 12:38 • ais probably x. But it is absolutely unclear, what do you ask? – Alexei Boulbitch Dec 19 '16 at 12:41 • Your function at least has a pole at x=1, going to infinity for every positive value of m: Limit[gg[m, x], x -> 1, Direction -> 1, Assumptions -> m > 0]==Infinity. So it is to be expected that it grows fast. Apart from that tabulating data from the function seems to work just fine here from what i can see. – Thies Heidecke Dec 19 '16 at 14:22 • I'm voting to close this question as off-topic because the issue it raises is not really a Mathematica issue but a matter of the OP not having grasped the mathematics involved. – m_goldberg Dec 20 '16 at 0:15 • @Amir Nasser To what precision do you need those numbers? Can you motivate for what application you need such high m values of your given function? Maybe this question could still be interesting to others in terms of optimizing function evaluation for performance. But i think it could use some motivation by understanding better what the problem is, that you're trying to solve. – Thies Heidecke Dec 20 '16 at 0:39 ## 2 Answers As shown by @ChipHurst, FunctionExpand accelerates the calculations gg1[m_, x_] = Hypergeometric2F1[2 + m, 5/2 + m, 2 + 2 m, x^2] // FunctionExpand; N[gg1[2000, 77/100], 20] // AbsoluteTiming (* {0.000321, 3.0916351054753710754*10^347} *) N[gg1[2000, 99/100], 20] // AbsoluteTiming (* {0.000224, 4.7018876879700276638*10^977} *)  Some additional speed - up can be made by simplifying the expression after FunctionExpand, and using arbitrary precision to avoid machine precision rather than applying N to exact evaluations. There is a small reduction in precision. gg2[m_, x_] = Assuming[{Abs[x] < 1}, Hypergeometric2F1[2 + m, 5/2 + m, 2 + 2 m, x^2] // FunctionExpand // FullSimplify]; gg2[2000, 0.7720] // AbsoluteTiming (* {0.000081, 3.0916351054753711*10^347} *) gg2[2000, 0.9920] // AbsoluteTiming (* {0.000076, 4.70188768797003*10^977} *)  You can use FunctionExpand to express this expression in terms of elementary functions: gg[m_, x_] = FunctionExpand[Hypergeometric2F1[2 + m, 5/2 + m, 2 + 2 m, x^2]] N[gg[2000, 77/100], 20] // AbsoluteTiming  {0.000261, 3.0916351054753710754*10^347}  N[gg[2000, 99/100], 20] // AbsoluteTiming  {0.000203, 4.7018876879700276638*10^977}  Plot[Log10[gg[1000, x]], {x, 0, 1}, Exclusions -> None] • A look at the elementary form of the function would at once tell me that numerical evaluation might become troublesome at$x\approx 1\$, and that cleverness, arbitrary precision, or both would be needed in that case. – J. M. will be back soon Dec 20 '16 at 4:40
• Shouldn't arbitrary precision be enough, because of precision tracking? – Chip Hurst Dec 20 '16 at 4:41
• One might want to keep things entirely in machine precision (e.g. the function becomes embedded somewhere in a compiled function), for example. – J. M. will be back soon Dec 20 '16 at 4:44
• thanks you very much. your answer is so helpful . FunctionExpand Function works good – Amir Nasser Dec 20 '16 at 10:17