1
$\begingroup$

This question is a follow-up to a previous question.

I am interested in numerically evaluating the hypergeometric functions:

HypergeometricPFQRegularized[{1/2, 3, n/2}, {1 - m, 1 + m}, x]
HypergeometricPFQRegularized[{1/2, 2, n/2}, {1 - m, 1 + m}, x]
HypergeometricPFQRegularized[{1/2, 1, n/2}, {1 - m, 1 + m}, x]

It seems that the first two take substantially longer to evaluate. For example, with $x=99/100$, they take about $100$x longer.

HypergeometricPFQRegularized[{1/2, 3, 2}, {1 - 30, 1 + 30}, 99/100] //  N // Timing
HypergeometricPFQRegularized[{1/2, 2, 2}, {1 - 30, 1 + 30}, 99/100] //  N // Timing
HypergeometricPFQRegularized[{1/2, 1, 2}, {1 - 30, 1 + 30}, 99/100] //  N // Timing
(* Output:
{0.278759, 816592.}
{0.244387, 3465.51}
{0.002092, 8.51496} *)

This difference is progressively exacerbated as $x$ gets close to $1$.

By inspection, the functional form of all three expressions are quite similar. The only notable difference is that the last one can be written in terms of $\mbox{}_2F_1$:

HypergeometricPFQRegularized[{1/2, 3, 2}, {1 - 30, 1 + 30}, x] // Timing
HypergeometricPFQRegularized[{1/2, 2, 2}, {1 - 30, 1 + 30}, x] // Timing
HypergeometricPFQRegularized[{1/2, 1, 2}, {1 - 30, 1 + 30}, x] // Timing 

It can be confirm that this is the source of the slowdown by trying:

HypergeometricPFQRegularized[{1/2, 3, 1}, {1 - 30, 1 + 30}, 99/100] // N // Timing
HypergeometricPFQRegularized[{1/2, 2, 1}, {1 - 30, 1 + 30}, 99/100] // N // Timing
HypergeometricPFQRegularized[{1/2, 1, 1}, {1 - 30, 1 + 30}, 99/100] // N // Timing
(* Output:
{0.006002, 1737.01}
{0.005309, 8.51496}
{0.005624, 0.0242938} *)

In this case, they all take about as long, since all three (in terms of general $x$) can be written in terms of $\mbox{}_2F_1$.

Is there a way to speed up the calculations for when $n \neq 2$?

$\endgroup$
3
  • $\begingroup$ RepeatedTiming[HypergeometricPFQRegularized[{1/2, #, 2}, {1 - 30, 1 + 30}, 99/100] // FullSimplify // N] & /@ Range[3, 1, -1] $\endgroup$
    – Bob Hanlon
    Commented Jul 15, 2022 at 14:40
  • $\begingroup$ The use of FullSimplify helps a bit, but there is still a huge difference in runtime, that is more and more noticeable for $x$ closer to $1$. Try your suggested code with $x=999/1000$ for example. $\endgroup$
    – Patrick.B
    Commented Jul 15, 2022 at 15:39
  • 2
    $\begingroup$ If you want to be evaluating a given function multiple times, then I suggest this: func[x_] = FunctionExpand@ HypergeometricPFQRegularized[{1/2, 3, 2}, {1 - 30, 1 + 30}, x]; with Set (=); then use func[x]. Redefine func[x] when you switch functions. For instance, func[999/1000] // N. One might be worried about numerical precision with this workaround. With your examples, it doesn't seem to matter much. $\endgroup$
    – Michael E2
    Commented Jul 15, 2022 at 17:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.