# Product of summation too slow

I have been trying to do the below given problem but even after 5-10 minutes results are not obtained so i killed the job.

AbsoluteTiming[Sum[Hypergeometric2F1[k^2*Sin[k*(Pi/6)]^2,k/2, 0.5,-1]
*Sin[k*(Pi/6)]^2*Sum[0.8*(Pochhammer[k - p, 0.5]/Cos[Pi/6]^2),{p, 1, k^2}]
,{k, 1, 500}]]


Also how can I increase the number of decimal of the result or how can i avoid numerical rounding issue. Thank you.

• You'll get more help if you include the code which can be copy-and-pasted into Mathematica rather than a picture of the code.
– JimB
May 5 '17 at 23:26

If I entered your code in correctly and then change 0.5 to 1/2 and 0.8 to 4/5, it looks like you might only need to sum to maybe 20 rather than 500:

data = Table[{n, N[Sum[Hypergeometric2F1[k^2 Sin[k π/6]^2, k/2,
1/2, -1] Sin[k π/6]^2 Sum[(4/5) Pochhammer[k - p, 1/2]/
Cos[π/6]^2, {p, 1, k^2}], {k, 1, n}], 20]}, {n, 10, 30}]

{{10, -0.071544615273026846805}, {11, -0.071571059489707821402},
{12, -0.071571059489707821402}, {13, -0.071570886837749513845},
{14, -0.071570886870953425127}, {15, -0.071570886870953425127},
{16, -0.071570886870709821681}, {17, -0.071570886870544288955},
{18, -0.071570886870544288955}, {19, -0.071570886870544312666},
{20, -0.071570886870544304098}, {21, -0.071570886870544304098},
{22, -0.071570886870544304141}, {23, -0.071570886870544304141},
{24, -0.071570886870544304141}, {25, -0.071570886870544304141},
{26, -0.071570886870544304141}, {27, -0.071570886870544304141},
{28, -0.071570886870544304141}, {29, -0.071570886870544304141},
{30, -0.071570886870544304141}}

• That's ok. But Imagine a case similar to this where it get converge only at very high value of upper limit of k i.e n(in your code), so that it takes much time as you see in the same case when n is 500 it takes long. Then what approach will be reliable. May 6 '17 at 9:50
• The answer to your question is "It depends." Certainly one would first want to attempt to see if the slow convergence is due to slowness of the terms going to zero or if there's some oscillatory nature to the terms. But to get specific advice, I think you'd need to have a specific example.
– JimB
May 6 '17 at 16:26
• Can you suggest me some methods that people usually do in such cases. May 17 '17 at 21:46
• Who says that the above doesn't give the desired answer when the upper limit is 500? You just might have to wait a long time. And if the person requesting you to use 500 is on your committee, then you have my condolences.
– JimB
May 17 '17 at 22:22
• Just an upper limit of 20 does the job in this case. If one chooses to use and upper limit of 500 unnecessarily which takes a whole lot longer, I don't see that being the fault of Mathematica.
– JimB
May 17 '17 at 23:05

As an experiment, I tried simplifying the internal summation. Replace decimals with rational expressions as per @Jim Baldwin. Then blast it with FullSimplify[ ] to get a closed form solution...

Sum[(4/5)*(Pochhammer[kk - p, 1/2]/Cos[Pi/6]^2), {p, 1, kk^2}] // FullSimplify

= (32*(Gamma[1/2 + kk]/Gamma[-1 + kk] - Gamma[1/2 + kk - kk^2]/Gamma[-1 + kk - kk^2]))/45


Stuffing this into the original summation and setting decimals to fractions, and you can actually get the full 500 in short order (just under 5 seconds).

Timing[res = Sum[Hypergeometric2F1[k^2*Sin[k*(Pi/6)]^2, k/2, 1/2, -1]
*Sin[k*(Pi/6)]^2
*(32*(Gamma[1/2 + k]/Gamma[-1 + k] - Gamma[1/2 + k - k^2]/Gamma[-1 + k - k^2]))/45,
{k, 1, 500}];]

{4.875, Null}


But it is in symbolic form. When you ask for a numerical answer with a //N...resolving res//N takes forever unfortunately. Barely faster than the original summation. Go figure...

• Imagine a case where there is one more sum after second summation May 6 '17 at 9:53
• Sorry as in this case: AbsoluteTiming[Sum[Hypergeometric2F1[k^2*Sin[k*(Pi/6)]^2, k/2, 0.5, -1]*Sin[k*(Pi/6)]^2* Sum[0.8*(Pochhammer[k - p, 0.5]/Cos[Pi/6]^2)* Sum[(q - p)^2, {q, 1, 500}], {p, 1, k^2}], {k, 1, 500}]] May 6 '17 at 10:01
• Hypergeometric2F1 is time-consuming. May 6 '17 at 10:53
• Ok. but how can I get out of this problem. Is there any better approach in these kind of problems especially when the sum is slowly converging, the problem of the type I posted in my comment. May 6 '17 at 12:53