| 573 | } |
| 574 | const K = new Complex(Math.PI / 2, 0).div(a); |
| 575 | return K.mul(C_ONE.sub(sum)); |
| 576 | } |
| 577 | |
| 578 | // |
| 579 | // ---------------- Carlson symmetric elliptic integrals (complex) ---------------- |
| 580 | // |
| 581 | // Duplication-theorem algorithms (Carlson 1995, same series tails as the |
| 582 | // machine-real kernels in numerics/special-functions.ts and as mpmath). |
| 583 | // With principal-branch square roots the duplication theorem is valid for |
| 584 | // arguments in the cut plane C ∖ (−∞, 0); arguments ON the negative real |
| 585 | // axis are evaluated as their boundary value from above (Im → 0⁺), which |
| 586 | // matches the mpmath/Mathematica convention for the incomplete elliptic |
| 587 | // integrals built on them. |
| 588 | // |
| 589 | |
| 590 | const CARLSON_TOL_C = 1e-24; |
| 591 | |
| 592 | /** Carlson R_C(x, y), complex, principal value for y on (−∞, 0). */ |
| 593 | export function carlsonRCComplex(x: Complex, y: Complex): Complex { |
| 594 | if (x.isNaN() || y.isNaN()) return C_NAN; |
| 595 | if (y.isZero()) return new Complex(Infinity, 0); |
| 596 | if (x.isZero()) return new Complex(Math.PI / 2, 0).div(y.sqrt()); |
| 597 | // Cauchy principal value for real y < 0 (DLMF 19.2.20) |
| 598 | if (y.im === 0 && y.re < 0) |