Elliptic theta functions

Are elliptic theta functions implemented in Julia? They exist in Mathematica as EllipticTheta, but I need them for heavy numerical calculations.

Googling “julia theta function” gives a bunch of results, did you try them?

I tried very much all of them. They are mostly related to Riemann theta functions, not elliptic theta functions.

I don’t know if that is acceptable for your use case, but there is Nemo.jl, which wraps the arbitrary-precision interval arithmetic C library Arb. It has the method jacobi_theta, which calculates the four Jacobi theta functions all at once.

Note that the definitions are slightly different from what is implemented in Mathematica as EllipticTheta (compare this MathWorld entry to Eq. 1.10 in this reference).
Specifically, jacobi_theta is in terms of \tau, while EllipticTheta is in terms of q, where q = \mathrm{e}^{\mathrm{i}\pi \tau}. Also, the z argument differs by a factor of \pi.

For example, the basic example given in the Wolfram documentation is EllipticTheta[1, 2., 1/3], which should give 1.42788. To replicate this, one could do:

julia> using Nemo;

julia> CC = ComplexField(64)
Complex Field with 64 bits of precision and error bounds

julia> ϑ = jacobi_theta(CC(2/π), CC(0, log(3)/π));

julia> ϑ[1]
[1.42787634002218211 +/- 5.93e-18]


If needed, this could also be converted back to a floating point number (possibly already taking into account that we know the result is purely real, as in this case):

julia> convert(ComplexF64, ϑ[1])
1.4278763400221821 + 0.0im

julia> convert(Float64, real(ϑ[1]))
1.4278763400221821

3 Likes

There is a Julia binding to the GSL library elliptic functions at JuliaHub which might also be useful.

Thanks for your reply! This library definitely works, but is slow. I am indeed using it right now, but it would be better if a direct numerical implementation of elliptic thetas of type 3 existed… Especially without relying on an algebraic package.

Unfortunately I don’t know how to express elliptic theta functions in terms of elliptic sines and cosines efficiently… In fact, it might even be impossible to invert them.

Yes, when you said “heavy numerical calculations” I already figured this solution would probably be too slow for your use case. Unfortunately I wasn’t able to find any other Julia package that provides ready-made access to the elliptic theta functions, as you said it seems to be mostly either Riemann theta functions or the elliptic sines and cosines mentioned above.

As an alternative, you could also try an implementation from a different programming language and call that from within Julia. Boost seems to have it, and I believe the currently recommended way of interfacing C++ and Julia is to use GitHub - JuliaInterop/CxxWrap.jl: Package to make C++ libraries available in Julia . I haven’t used it myself so far, so I cannot say how much additional work that would be. Maybe it isn’t too bad if you only need that one function anyway.

1 Like