# Imaginary terms in the derivative of Jacobi theta function (2) on the real line

I am trying to calculate/plot the derivative of the second Jacobi theta function $d\theta_2(0, e^{-\pi t} )/dt$.

Calculating or plotting the function itself works fine:

In[1]:= theta2[t_] := EllipticTheta[2, 0, Exp[-1*Pi*t]];
theta2[.8]

Out[2]= 1.07398


with the result being real - as expected from Mathematica's definition:

However, when I try to calculate derivatives of the above, I get a significant imaginary part:

In[3]:= dtheta2[t_] = D[EllipticTheta[2, 0, Exp[-1*Pi^2 *t]], t];
dtheta2[.8]

Out[4]= -0.794774 + 0.280078 I


(Using Set (=) rather than SetDelayed (:=) as discussed. Taking the derivative of theta2[t] instead does not seem to make a difference).

Any ideas what might be going on?

(Note, the branch cut is taken from 0 to -1, so should not be an issue.)

## 2 Answers

One can use the PDE satisfied by the Jacobi theta function to compute the required derivative:

With[{t = 4/5},
N[π^2/4 Derivative[0, 2, 0][EllipticTheta][2, 0, E^(-π^2 t)], 35]]
-0.68549982086695914178518686511587505


(see the edit history for the older version of this answer)

You are using insufficient precision:

theta2'[.8]

(* -0.794774 + 0.280078 I *)

Precision[.8]

(* MachinePrecision *)


Use exact arguments:

theta2'[8/10]


and get the exact result. Use N et. al. with desired precision to retrieve numeric values.

N[theta2'[8/10], 10]

(* -0.8874928427 + 4.596*10^-7 I *)

• Thx for the reply, @rasher. I've tried increasing precision before and did not get any substantive improvements wrt size of the imaginary term (e.g., with above I get: dtheta2[t_] = D[EllipticTheta[2, 0, Exp[-1*Pi *t]], t]; N[dtheta2[8/10], 10] N[theta2'[8/10], 10] output: -0.3317952035 - 0.4122258903 I -0.3317952035 - 0.4122258903 I) though the values in this case are different, which is also troubling...(using Mathematica 9). – albert818 Apr 21 '15 at 5:39
• @albert818: Hmm. Something fishy perhaps - I restarted kernel, got a different result (not matching mine in post, or yours). Then did exact calculation, then applied N to that, got a different result, but when re-doing the N[...] surrounding all version, it now matches the latter, though both are different from the post and yours. It appears to be caching results but something gets whacked (try doing it with N[...,10], then re-do with say N[...,100], then re-do with N[...,10] again. Weird. Also on 9, btw. – ciao Apr 21 '15 at 6:00
• Same story: did a complete program restart and got: -1.2947074204 - 0.4939796009 I with N[...,10], then ran N[...,100] and got -1.0078730012 + 0.0790778685 I (truncated paste). Back to N[...,10] - now same as N[...,100] (must be caching). Finally, did N[...,1000] and got yet another number and now same at N[...,10]: -0.8874927502 - 2.184*10^-7 I. This one has the Im part at close to chopping levels, at last(!) - but not sure I can believe it due to earlier instabilities. – albert818 Apr 21 '15 at 6:26
• Tried plotting with N[...,500] while setting \$MaxExtraPrecision = 500, but still get the same pattern of significant oscillatory Im component (though the frequency of oscillations seems to have gone up, which suggests numerics to me). The whole thing is particularly odd, since I believe theta series are generally rather fast-converging due to the n^2 term in the exponent... Any additional clues would be appreciated. – albert818 Apr 21 '15 at 7:35
• @albert818: I'm at a loss to further theories - hopefully one of the wolfram gang that hangs out here might have some insight, and perhaps pinging wolfram support might get some info. – ciao Apr 21 '15 at 19:27