I am interested in certain hypergeometric functions $ G_p(z) = \frac{1}{2} {}_3F_2 \left( \begin{matrix} p & p + 1 & \frac{1}{2} \\ 1 + i & 1 - i & \end{matrix} ;z \right) $ and would like to plot them in the complex $z$ plane, on both sides of the branch cut $\operatorname{Re} z \in (1,\infty)$. However
G[p_, z_] := 1/2 HypergeometricPFQ[{-p, p + 1, 1/2}, {I + 1, -I + 1}, z]
ComplexPlot[G[1/2, z], {z, -I, 2 + I}, PerformanceGoal -> "Speed", ColorFunction -> "GreenPinkTones"]
takes at least 5 minutes to evaluate.
(I ran it inside TimeConstrained.)
I thought maybe this is just because there is a lot of detail for ComplexPlot to resolve.
(Actually, I'd like the plot with ColorFunction -> "CyclicReImLogAbs", which would be even more computationally intensive in that case.
And eventually with PerformanceGoal -> "Quality", too.) I tried evaluating the function on a fixed grid to see if that excessive detail was the problem:
mesh = Flatten@Table[{x + I y}, {x, -1, 1, 0.1}, {y, -1, 1, 0.1}];
AbsoluteTiming@G[1/2, mesh]/Length@mesh
(* 0481893 *)
≈ 50 ms per function evaluation, no wonder plotting it is slow!
In contrast, evaluating and plotting ${}_2F_1$ is reasonably fast:
H = Hypergeometric2F1[-9/14, 1, -2/3, #] & ;
EchoTiming@ComplexPlot[H[z], {z, -I, 2 + I}, PerformanceGoal -> "Speed",
ColorFunction -> "GreenPinkTones"
]
(* 0.876022 *)
EchoTiming@ComplexPlot[H[z], {z, -I, 2 + I}, PerformanceGoal -> "Speed",
ColorFunction -> "CyclicReImLogAbs"
]
(* 2.98155 *)
First@AbsoluteTiming@H[mesh]/Length@mesh
(* 0.0000524331 *)
As seen on the last line, ${}_2F_1$ is roughly $1000$ times faster to evaluate than ${}_3F_2$!
I saw elsewhere on MMA.SE that MeijerGReduce could offer speedups, but it didn't work in this case.
Is this because higher hypergeometric functions are inherently expensive to compute? Is it a known issue? Is there anything I can do to speed the computations up?
I am on Linux, Mathematica 13.0, i9-10900K @ 3.70 GHz. The machine scores 4.49 on the WolframMark Benchmark.
MeijerGwith the integral definition is efficient, but maybe this was mistaken. And some things just can't be helped I guess. – Robin Ekman Jun 08 '22 at 20:57ComplexPlot[]is anything like what's being done here, then the choice ofColorFunctiondoesn't actually matter; any choice should still take about the same amount of computational effort. – J. M.'s missing motivation Jun 08 '22 at 22:13RuntimeTools``Profileand the latter shows about 3-4 times as many calls toHypergeometric2F1as the former. Maybe I'm not interpreting the output correctly, but I doubt it. – Robin Ekman Jun 09 '22 at 01:39ContourPlot[G[1/2, x + I y] // Arg, {x, 0, 2}, {y, -1, 1}, ColorFunction -> Hue] // AbsoluteTiming. It takes 3754.8 s on my computer and nothing to see on this picture. What is the problem here? – Alex Trounev Jun 09 '22 at 09:56N[HypergeometricPFQ[{-p, p + 1, 1/2}, {I + 1, -I + 1}, z] /. {z -> 2 - I, p -> 1/2}] // AbsoluteTimingresults in{0.708953,0.725416 +0.37877 I}andN[HypergeometricPFQ[{-p, p + 1, 1/2}, {1, 1}, z] /. {z -> 2 - I, p -> 1/2}] // AbsoluteTimingproduces{9.50802, 0.555427 + 0.809427 I}on my comp. " – user64494 Jun 09 '22 at 17:11