Menu ▾ ▴

#5904 elliptic_pi inaccurate

None
closed
5
2 days ago
2026-11-25
Raymond Toy
No

Elliptic pi is inaccurate. Claude found these examples. For n near 1 and phi near pi/2:

elliptic_pi(float(1-2^-40), float(%pi/2)-2^-20, 0.5);
    → 1164674.2577077919
exact 1164674.2576808747        (1.2e5 ulps)

For m near 1 and phi near pi/2:

elliptic_pi(0.5, float(%pi/2)-2^-20, float(1-2^-40));
    → 27.489278290283551
exact 27.489278290246303        (1.1e4 ulps)

For phi near the pole n*sin^2(phi) = 1

elliptic_pi(float(1-2^-40), float(%pi/2)-2^-20, 0.5);
    → 1164674.2577077919
exact 1164674.2576808747        (1.2e5 ulps)

At the double nearest the pole:

elliptic_pi(4.0, float(%pi/6), 0.5);
    → 11.424932073116509
exact 11.458898371615306        (1.9e13 ulps)

elliptic_pi(4.0, float(%pi/6)+2^-53, 0.5);
    → Lisp error
exact 11.480110833541524 - 0.96951654133040569*%i

Imaginary part just past the branch point m*sin(phi)^2 = 1:

imagpart(elliptic_pi(0.5, float(%pi/4)+2^-30, 2.0));
    → -5.7544497178783444e-5
exact -5.7544496232928483e-5    (1.4e8 ulps)

Bigfloats have the same problems. For example, at fpprec : 32, elliptic_pi(4b0, bfloat(%pi/6), 0.5b0) returns 47.656… with no imaginary part, and the exact value is 23.582… − 0.96951… i.

Related

Bugs: #5908
Bugs: #5909
Bugs: #5910

Discussion

  • Raymond Toy

    Raymond Toy - 2026-11-25

    While investigating how to improve accuracy, Claude discovered that some values from using Carlson's Rj function are completely wrong when compared to the values from mpmath. And indeed Carlson's article give (very) conservative conditions on where the Rj duplication is valid.

    mpmath solves this by using numerical integration and shifts the arguments to Rj so that Rj produces the correct values.

    My copy of Lawden shows an analytical solution for ellipitic_pi that involves the theta4 function and Jacobi's Zeta function. I think we should implement these and use them for numerical evaluation of elliptic pi. These functions are useful in their own right. And maybe with theta4 we can get the other 3 theta functions with minimal work. That would be useful too.

     
  • Raymond Toy

    Raymond Toy - 2 days ago
    • status: open --> closed
     
  • Raymond Toy

    Raymond Toy - 2 days ago

    With [#5915] fixed, I think we have reasonably accurate elliptic_pi for all complex values of the parameters. Note that we don't use lots of extra digits so the values could be 50 ulp off.

     

    Related

    Bugs: #5915


Log in to post a comment.