Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle branch cut using signed zero for imag(m) for ellipticK #33

Open
ahbarnett opened this issue Jan 11, 2024 · 1 comment
Open

handle branch cut using signed zero for imag(m) for ellipticK #33

ahbarnett opened this issue Jan 11, 2024 · 1 comment

Comments

@ahbarnett
Copy link

Dear stla,
Thanks for an timely library! Certainly helped me, since Matlab only covers (0,1) on real axis. I'm going to report some findings re limits on the branch cut of ellipticK, which may be in the weeds, but it had me confused in my application.

I noticed that for k^2=m>1 real, ie on the branch cut, the limit imag(m) = 0^- is taken (ie from below). However, for complex of the same value (with either sign of imaginary zero), the upper limit is taken. The latter seems standard to me, compared to say, IEEE-754 for sqrt of complex, which for negative real (and positive zero in imaginary) takes the limit from above. It is also usual to infer the side of the cut from the imaginary signed zero, but that doesn't happen:

julia> ellipticK(4.0)                                          # real input
0.8428751774062979 - 1.0782578237498217im
julia> ellipticK(4.0 +1e-15im)
0.8428751774062979 + 1.0782578237498217im
julia> ellipticK(4.0 -1e-15im)                         # ... matches this side of branch
0.8428751774062979 - 1.0782578237498217im
julia> m=Complex(4.0,0); ellipticK(m)          # complex input with +0 imag,  correct up side
0.8428751774062979 + 1.0782578237498217im
julia> m = Complex(-2.0)^2; ellipticK(m)      # hack to make m = 4-0im;  sign of imag ignored
0.8428751774062979 + 1.0782578237498217im

I'll point out that a simple AGM implementation of K with IEEE sqrt gets the sides of the cut I would consider standard, including heeding the sign of the imaginary zero.

Anyway this is a detail, apart from the difference between real m and complex m for the same number would be the main thing to fix. Maybe the above should be documented if it isn't going to be changed? Cheers, Alex

@stla
Copy link
Owner

stla commented Jan 15, 2024

Thanks! I'm not an expert in elliptic integrals and I don't understand what is going on here. I will implement ellipticK from the AGM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants