Repository navigation
Computation of elliptic_pi
This note covers how Maxima should evaluate the incomplete elliptic integral of the third kind,
for real
- what the existing code returns;
- what Mathematica, Wolfram|Alpha and mpmath return;
- how the Sokhotski–Plemelj formula connects the two;
- how the result was implemented and tested.
- The problem
- What the Carlson code computes
- The Sokhotski–Plemelj formula
- Applying it to Π
- The same result as a contour indentation
- Regions of the real parameter space
- Implementation
- Tests
- Known limitations
- References
When
and at
- The Cauchy principal value (CPV). This is real.
-
The analytic continuation from one side of the branch cut
$n \in (1, \infty)$ . This is complex.
Mathematica, Wolfram|Alpha and mpmath use the analytic continuation. For example,
Before this change, Maxima returned only the real part,
Maxima evaluates
where
bf-rj handles real
with
and
The real part was verified independently: a brute-force symmetric cut-out around the pole converges to the same value. For
Carlson (1995) does not say how to get the imaginary part, and it does not treat the complete case
Let
The real part of the limit is the principal value. The imaginary part is
To see why, split the kernel into real and imaginary parts:
- The real part equals
$1/x$ except within about$\varepsilon$ of$0$ , where it stays bounded and is odd. Integrated against$f$ , it tends to the principal value. - The imaginary part is a peak of width about
$\varepsilon$ at$0$ , with total area$\int_{-\infty}^{\infty} \varepsilon/(x^2 + \varepsilon^2)\thinspace dx = \pi$ . As$\varepsilon \to 0$ it only sees$f(0)$ , so it contributes$\mp i\pi f(0)$ .
Write the integrand as
For
Replace
Near the pole,
Take a small interval
At poles where
From
Each pole therefore contributes
At every zero of
the imaginary part is
Check. For
This matches the imaginary part of
With
just above the real axis. The path along the real axis therefore passes below the pole. That is equivalent to indenting the path with a small semicircle below the pole. The semicircle goes counterclockwise around the pole, so it contributes
The result is the same as in §4.
Taking
The Sokhotski–Plemelj term is needed exactly where bf-rj takes its CPV branch, that is, where bf-rj1 handles the continuation and already returns the
Let
| Region | Behaviour | Action |
|---|---|---|
| No pole on the path | Nothing to add | |
| Double zero at |
None; no principal value exists | |
| Poles at |
Add |
|
|
|
Pole crossed before the branch point | Add |
|
|
Past the branch point | Nothing to add; bf-rj1 already gives the |
| Branch point comes before the pole, where |
Nothing to add; bf-rj1 already gives the |
|
| Pole and branch point coincide, giving |
None; only a Hadamard finite part exists | |
| Endpoint on the pole, giving a logarithmic divergence | None |
Here
The cycles of bf-rj1 and already includes the term.
These rules were found by comparing the uncorrected code with mpmath over a grid of
bf-elliptic-pi reduces
and sums the CPV pieces. The new function bf-elliptic-pi-residue, in the bigfloat package in src/ellipt.lisp, computes the imaginary correction:
(defun bf-elliptic-pi-residue (n phi m)
(if (and (realp n) (realp phi) (realp m) (> n 1))
(let* ((bf-pi (%pi phi))
(cycles (round phi bf-pi))
(rem (- phi (* cycles bf-pi)))
(s2 (expt (sin rem) 2))
(crossings (+ (if (<= m 1)
(* 2 cycles)
0)
(if (and (> (* n s2) 1) (<= (* m s2) 1))
(signum rem)
0))))
(if (zerop crossings)
0
(* (complex 0 -1) crossings (/ bf-pi 2)
(sqrt (/ n (* (- n 1) (- n m)))))))
0))The elliptic_pi simplifier adds this correction in its real-float and real-bigfloat branches. The complex branches are unchanged.
((float-numerical-eval-p n phi m)
(add (elliptic-pi ($float n) ($float phi) ($float m))
(to (bigfloat::bf-elliptic-pi-residue ($float n) ($float phi) ($float m)))))
...
((bigfloat-numerical-eval-p n phi m)
(to (bigfloat:+ (bigfloat::bf-elliptic-pi (bigfloat:to n)
(bigfloat:to phi)
(bigfloat:to m))
(bigfloat::bf-elliptic-pi-residue (bigfloat:to n)
(bigfloat:to phi)
(bigfloat:to m)))))New tests in tests/rtest_elliptic.mac check each case in both double float and bigfloat at fpprec: 32, against 50-digit references from mpmath's ellippi.
- All inputs are dyadic rationals, so the float and bigfloat arguments are exact.
- Each tolerance is the error observed in testing, rounded up to five significant digits.
| What it covers | Reference value | |
|---|---|---|
| Complete integral, |
||
| Pole crossed | ||
| Pole not reached; imaginary part is exactly |
||
| Odd in |
||
| Reduction by |
||
| Reduction by |
||
| Complete integral, |
||
|
|
||
|
|
||
|
|
||
The last tests check the sign convention without relying on reference values:
-
$\Pi(n - i\varepsilon;\thinspace\varphi\thinspace|\thinspace m)$ , computed through the complex path, must equal the new real-$n$ result. -
$\Pi(n + i\varepsilon;\thinspace\varphi\thinspace|\thinspace m)$ must equal its complex conjugate.
They use
With the patch, all 288 tests in the file pass. Without the source changes, 11 of the new tests fail. The four that still pass cover regions where the rule adds nothing: the no-pole case, its imaginary-part check, past the branch point, and
These results come from an SBCL build. Tolerances may need adjusting for other Lisps.
A wider comparison of 336 cases also matched mpmath:
$n \in \lbrace 1.1,\ 1.5,\ 4\rbrace$ $m \in \lbrace -2,\ 0,\ 0.5,\ 0.99,\ 1.2,\ 2,\ 3,\ 6\rbrace$ - 14 values of
$\varphi$ , including negative values and several cycles of$\pi$
The worst relative errors were:
Bigfloat at fpprec: 30
|
||
| Double float |
-
$m = 1$ .bf-elliptic-pialways evaluates the complete integral, which is infinite at$m = 1$ , so even$\varphi < \pi/2$ fails with0.0/0.0. This also happens on master. -
Complex arguments. The correction applies only to real
$n$ ,$\varphi$ and$m$ . Complex inputs go throughbf-rj1unchanged. Continuity with the real-axis value from below is tested, but that is the only check of the complex path here.
- B. C. Carlson, "Numerical computation of real or complex elliptic integrals", Numerical Algorithms 10 (1995) 13–26. arXiv:math/9409227. Eq. (33) gives the Cauchy principal value of
$R_J$ for$p < 0$ . -
NIST Digital Library of Mathematical Functions, §19.20(iii) for
$R_J$ with$p < 0$ (19.20.14), and §19.25 for$\Pi$ in terms of Carlson integrals. - N. I. Muskhelishvili, Singular Integral Equations, and F. D. Gakhov, Boundary Value Problems. Both are standard treatments of the Sokhotski–Plemelj formulas. Section numbers have not been verified.
- F. Johansson et al., mpmath,
ellippi, used for the reference values.