stla / EllipticFunctions.jl

Jacobi theta functions and related functions.
https://stla.github.io/EllipticFunctions.jl/dev/
MIT License
15 stars 4 forks source link

Wrong signs #17

Closed stla closed 1 year ago

stla commented 1 year ago

My R implementation of the Jacobi theta functions is the same as the Julia implementation, and it gives:

> q <- 0.556 + 0.283i 
> jtheta2(0, q=q) 
[1] -2.006298-0.829697i 
> jtheta3(0, q=q) 
[1] -2.006103-0.829843i 
> jtheta4(0, q=q) 
[1] 0.1917222+0.2512025i

Assuming the Python library mpmath has the right values, then the above three results are wrong: the right values are the opposite of these ones.

I'm wondering what is the result of @fremling 's Fortran implementation.

I don't know whether this is related, but jtheta1(0, q) is very close to 0 for this value of the nome q.

cc @simonp0420

stla commented 1 year ago

I still have my R-C++ implementation of @fremling 's algorithm. It also gives the wrong sign.

stla commented 1 year ago

Now I checked with Wolfram, and the Python library is indeed right.

fremling commented 1 year ago

For theta 3, with

tau = -i*log(q)/pi = 0.1498653698657948 + 0.15017823767320393i

the FORTRAN implementation gives

theta3(0,tau) = 2.0061026281212841 +0.8298431381942418i,

so it would appear this has the correct sign.

stla commented 1 year ago

Thanks @fremling ! Weird, I have to check why I got the opposite.

stla commented 1 year ago

You're right, works perfectly.

@simonp0420 I suspect the problem lies in my function alpha. Because it has a square root, and possibly its sign can be the two possibilities. I don't see what could be the problem otherwise.

stla commented 1 year ago

I confirm. Everything works now! I replaced the expressions involving alpha.

I'm surprised the unit tests work because I already tried to get rid of alpha and there were some failures.

stla commented 1 year ago

I'm surprised the unit tests work because I already tried to get rid of alpha and there were some failures.

I see: they didn't fail because I used @fremling's jtheta3 function in the Dedekind eta function. Otherwise they fail :-( Lost again...

stla commented 1 year ago

Works now. I believe formula 20.4.6 here is wrong, it is only true up to the sign. So I use a direct implementation of the derivative now.

This seems definitely ok now :)