0
$\begingroup$

The version of the partial theta function I want to compute is

$O(z) = \sum\limits^\infty_{n=0}\exp(-(z+n\pi)^2)$

Does anyone have or know of code to efficiently compute $O(z)$? There are two papers dealing with this computation, but can't find any code.

Hiary, G. (2008). A nearly-optimal method to compute the truncated theta fcn, its derivatives and integrals. Annals of Mathematics, Second Series, Vol 174, No. 2, pp 859-889.

Kuznetsov, A (2015). Computing the truncated theta function via Mordel-Integral. Math comp 84, pp 2911-2926

$\endgroup$
2
  • $\begingroup$ I'm guessing this is not a mathematica question, but if it is start by whats wrong with NSum[ Exp[-(z + n Pi)^2 ], {n, 0, Infinity}] $\endgroup$
    – george2079
    Commented Jan 23, 2018 at 17:08
  • $\begingroup$ Is there an I missing? $\endgroup$
    – Michael E2
    Commented Jan 23, 2018 at 18:03

2 Answers 2

4
$\begingroup$
θ[z_?NumericQ] := NSum[Exp[-(z + n Pi)^2], {n, 0, Infinity}]

Using a partial sum

θp[z_] := Sum[Exp[-(z + n Pi)^2], {n, 0, 100}]

Comparing the plots

Plot[{θ[z], θp[z]}, {z, -2.5, 2.5},
 PlotStyle -> {{AbsoluteThickness[4], Green}, Red},
 PlotLegends -> Placed["Expressions", {.2, .75}]]

enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ just think someone got a journal paper out of that :-). (Something tells me there is more to this.) $\endgroup$
    – george2079
    Commented Jan 23, 2018 at 17:42
3
$\begingroup$

The sum $O(z) = \sum\limits^\infty_{n=0}\exp(-(z+n\pi)^2)$ is extremely rapidly convergent, unlike the sums in the references cited in the question.

Pick an accuracy eps. Then one can sum to that accuracy as follows:

(* solve for limits of summation *)
n /. Simplify[Solve[Exp[-(z + n Pi)^2] == eps, n, Reals], 0 < eps < 1]
(*  {-((z + Sqrt[-Log[eps]])/π), (-z + Sqrt[-Log[eps]])/π}  *)

ClearAll[sum];
sum[z_?NumericQ, accgoal_: Automatic] := Module[{n, eps},
   eps = 10^-(accgoal /. Automatic -> $MachinePrecision);
   n = Range @@  (* range of terms to sum *)
     N@Clip[
      Floor@{-((z + Sqrt[-Log[eps]])/π), (-z + Sqrt[-Log[eps]])/π} + {0, 1}, 
      {0, Infinity}];
   Total[Exp[-(z + n Pi)^2]] (* vectorized sum for speed *)
   ];

Plot[sum[z], {z, -30, 10}]

Mathematica graphics

The number of terms in the sum for machine precision accuracy is about 4 or 5:

2*Sqrt[-Log[$MachineEpsilon]]/Pi
(*3.82203  *)
$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.