Cookie Consent by Free Privacy Policy Generator Appendix A4 — Jacobi Elliptic Functions, Elliptic Integrals, and the AGM | Igor Moiseev
Part A4 of the "Geometry of Seeing" series

Appendix A4 — Jacobi Elliptic Functions, Elliptic Integrals, and the AGM

Where $\mathrm{sn}, \mathrm{cn}, \mathrm{dn}$ come from, why $K(m)$ is the pendulum's quarter-period, and how Gauss's arithmetic–geometric mean computes both to 16 digits in 6 iterations — exactly the algorithm shipped in the moiseevigor/elliptic package.

By Igor Moiseev · 4 May 2026 · arXiv:0807.4731 · with Yu. L. Sachkov
Geometry of Seeing
  1. The Visual Cortex as a Contact Manifold (draft)
  2. Euler's Elastica and Jacobi Elliptic Functions (draft)
  3. Maxwell Strata: When Optimal Paths Fork
  4. The Open Problem: Exact Cut Time on SE(2)
Appendices — Theory Background
  1. A1. Lie Groups, Lie Algebras, and the Exponential Map of SE(2) (draft)
  2. A2. Distributions, Frobenius, and Contact Geometry (draft)
  3. A3. Calculus of Variations and the Pontryagin Maximum Principle (draft)
  4. A4. Jacobi Elliptic Functions, Elliptic Integrals, and the AGM ← you are here
  5. A5. The Sub-Riemannian Exponential Map of SE(2) (draft)
What this appendix is for
Part 2 invokes Jacobi's $\mathrm{sn}, \mathrm{cn}, \mathrm{dn}$ and the complete elliptic integral $K(k^2)$ as if they were as ordinary as $\sin, \cos, \tan$. This appendix derives them from the pendulum equation Appendix A3 finishes on, lays out the identities used in Part 2 §4 (the Frenet–Serret integration), and explains Gauss's arithmetic–geometric mean — the iteration that the moiseevigor/elliptic package uses to evaluate $K(m)$. Every formula in this appendix is implemented (often line-for-line) in public/js/elliptic-core.js and in the Python elliptic package.

Where elliptic integrals come from

Compute the arc length of an ellipse of semi-axes $a > b$:

\[L \;=\; \int_0^{2\pi} \sqrt{a^2 \sin^2 t + b^2 \cos^2 t}\,dt \;=\; 4 a \int_0^{\pi/2} \sqrt{1 - e^2 \sin^2 t}\,dt\]

with eccentricity $e^2 = 1 - b^2/a^2$. The integrand has no elementary antiderivative — Liouville (1830s) showed that the resulting function is genuinely transcendental beyond elementary (it is not expressible by finite combinations of polynomials, exponentials, logarithms, and roots). Following Legendre, define the complete elliptic integral of the second kind

\[E(m) \;:=\; \int_0^{\pi/2}\sqrt{1 - m \sin^2 t}\,dt,\]

so $L = 4 a E(e^2)$. This is one of three Legendre forms; the other two are the first kind

\[K(m) \;:=\; \int_0^{\pi/2}\frac{dt}{\sqrt{1 - m \sin^2 t}},\]

and the third kind $\Pi(n; m)$ involving an extra rational factor. $K$ is what governs the pendulum’s period; $E$ is what governs the elastica’s plane-curve integration; both appear in the Sachkov closed forms of Part 2 §4.

The two come together in Legendre’s relation:

\[E(m) K(1 - m) + E(1 - m) K(m) - K(m) K(1 - m) \;=\; \tfrac{\pi}{2}.\]

This identity is what lets the elliptic package validate its own implementations: every solution should satisfy Legendre’s relation to machine precision.

Inverting the integral: the Jacobi amplitude

Just as $\arcsin$ is the inverse of $\sin$, define $\mathrm{am}(u\mid m)$ as the inverse of the incomplete first-kind integral

\[F(\phi\mid m) \;:=\; \int_0^\phi \frac{dt}{\sqrt{1 - m \sin^2 t}}.\]

That is, $\phi = \mathrm{am}(u\mid m)$ iff $u = F(\phi\mid m)$. Then

\[\boxed{\;\mathrm{sn}(u\mid m) \;:=\; \sin\bigl(\mathrm{am}(u\mid m)\bigr), \qquad \mathrm{cn}(u\mid m) \;:=\; \cos\bigl(\mathrm{am}(u\mid m)\bigr), \qquad \mathrm{dn}(u\mid m) \;:=\; \sqrt{1 - m\,\mathrm{sn}^2(u\mid m)}.\;}\]

When $m \to 0$: $F(\phi\mid 0) = \phi$, so $\mathrm{am}(u\mid 0) = u$, and $\mathrm{sn} \to \sin, \mathrm{cn} \to \cos, \mathrm{dn} \to 1$. When $m \to 1^-$: $F(\phi\mid 1) = \mathrm{atanh}(\sin\phi)$, so $\mathrm{sn}(u\mid 1) = \tanh u$, $\mathrm{cn}(u\mid 1) = \mathrm{dn}(u\mid 1) = \mathrm{sech}\,u$. At intermediate $m$ they interpolate.

The functions are doubly-periodic when extended to the complex plane: $\mathrm{sn}$ has real period $4K(m)$ and imaginary period $2iK(1 - m)$. This makes them functions on the elliptic curve $y^2 = (1 - x^2)(1 - mx^2)$ — from which much of the theory’s algebraic structure comes.

Jacobi sn (blue), cn (orange), dn (green) as functions of $u$
Figure A4.1. The three Jacobi elliptic functions $\mathrm{sn}(u\mid m), \mathrm{cn}(u\mid m), \mathrm{dn}(u\mid m)$ over $u \in [-2K(m), 2K(m)]$ — one full period of $\mathrm{sn}$. At $m = 0$ they reduce to $\sin u, \cos u, 1$; as $m \to 1$ the period grows (logarithmically), $\mathrm{sn}$ flattens toward $\tanh$, and $\mathrm{cn}, \mathrm{dn}$ both collapse onto $\mathrm{sech}$. The vertical dashed lines mark the quarter-periods $\pm K(m)$ — where $\mathrm{cn}$ has its zeros, the same way $\cos$ has zeros at $\pm\pi/2$. Computed by the same descending-Landen algorithm shipped in elliptic-core.js.

Differential equations

Differentiating $u = F(\phi\mid m)$ with respect to $u$:

\[1 \;=\; \frac{d\phi}{du} \cdot \frac{1}{\sqrt{1 - m \sin^2\phi}} \;\Rightarrow\; \frac{d\phi}{du} \;=\; \sqrt{1 - m\sin^2\phi} \;=\; \mathrm{dn}(u\mid m).\]

So $\mathrm{am}’(u) = \mathrm{dn}(u)$, and chain rule gives

\[\boxed{\;\mathrm{sn}'(u) = \mathrm{cn}(u)\,\mathrm{dn}(u), \quad \mathrm{cn}'(u) = -\mathrm{sn}(u)\,\mathrm{dn}(u), \quad \mathrm{dn}'(u) = -m\,\mathrm{sn}(u)\,\mathrm{cn}(u).\;}\]

Squaring the first identity and using the Pythagorean relations $\mathrm{sn}^2 + \mathrm{cn}^2 = 1$ and $m\,\mathrm{sn}^2 + \mathrm{dn}^2 = 1$ yields the cleanest single ODE:

\[(\mathrm{sn}')^2 \;=\; (1 - \mathrm{sn}^2)(1 - m\,\mathrm{sn}^2),\]

a cubic-in-the-square ODE — exactly what falls out of the pendulum equation $\ddot\varphi + \sin\varphi = 0$ after the substitution $\sin(\varphi/2) = k\,\mathrm{sn}(s\mid k^2)$. Tracing this:

\[\dot\varphi \;=\; 2\dot{(\varphi/2)} \;=\; 2\,\frac{d\arcsin(k\,\mathrm{sn})}{ds} \;=\; \frac{2k\,\mathrm{cn}\,\mathrm{dn}}{\cos(\varphi/2)} \;=\; 2k\,\mathrm{cn}(s),\]

(using $\cos(\varphi/2) = \sqrt{1 - k^2\,\mathrm{sn}^2} = \mathrm{dn}(s)$.) Differentiate once more:

\[\ddot\varphi \;=\; 2k\,\mathrm{cn}'(s) \;=\; -2k\,\mathrm{sn}(s)\,\mathrm{dn}(s).\]

And $\sin\varphi = 2\sin(\varphi/2)\cos(\varphi/2) = 2k\,\mathrm{sn}(s)\,\mathrm{dn}(s)$, so $\ddot\varphi + \sin\varphi = 0$. ✓

This is the identity behind the elastica: the pendulum solution is literally the Jacobi-am function, and the curvature $\kappa(s) = \dot\varphi(s) = 2k\,\mathrm{cn}(s)$ is one Jacobi function’s worth. (Different conventions place sn or cn here; Part 2 uses $\kappa = 2k\,\mathrm{sn}$, which corresponds to a half-period shift.)

The complete elliptic integrals

$K(m) := F(\pi/2 \mid m)$ and $E(m) := \int_0^{\pi/2}\sqrt{1-m\sin^2 t}\,dt$. Special values:

$m$ $K(m)$ $E(m)$
0 $\pi/2 \approx 1.5708$ $\pi/2$
$\frac12$ $1.8541$ $1.3506$
$0.9$ $2.5781$ $1.1048$
$0.99$ $3.6956$ $1.0160$
$1^-$ $+\infty$ (logarithmic) $1$

The asymptotics near $m = 1$ are

\[K(m) \;\sim\; \tfrac12 \log\!\Bigl(\tfrac{16}{1 - m}\Bigr), \qquad E(m) \;\to\; 1.\]

This is the logarithmic divergence Part 2 §3 announces for the pendulum period at the separatrix — the same divergence governs the spatial period of inflectional elastica as $k \to 1$.

The arithmetic–geometric mean of Gauss

Given $a_0, b_0 > 0$, define

\[a_{n+1} \;=\; \tfrac12 (a_n + b_n), \qquad b_{n+1} \;=\; \sqrt{a_n b_n}.\]

The two sequences converge — quadratically — to a common limit, the arithmetic–geometric mean $\mathrm{AGM}(a_0, b_0)$. Quadratic convergence means each iteration roughly doubles the number of correct digits: starting from a $10^{-1}$-precision pair, six iterations land at $\sim 10^{-32}$ precision — hence the elliptic package’s “16-digit accuracy in 6 iterations” claim.

Gauss (1799, unpublished) proved the miracle:

Gauss's identity
$$K(m) \;=\; \frac{\pi}{2\,\mathrm{AGM}\!\bigl(1,\;\sqrt{1 - m}\bigr)}.$$ Equivalently $K(m) = \pi / (2\,\mathrm{AGM}(\sqrt{1+\sqrt{1-m}}, \sqrt{1-\sqrt{1-m}}))/\sqrt 2$ via the descending Landen transformation.

This is what ellipticK in the Python elliptic package computes — and what ellipj then uses internally to invert the integral and produce the sn/cn/dn values.

Click step; AGM converges quadratically
Figure A4.2. Live AGM iteration. Starting from $a_0 = 1, b_0 = \sqrt{1 - m}$, each click of step applies one AGM iteration $a_{n+1} = (a_n + b_n)/2, b_{n+1} = \sqrt{a_n b_n}$ and plots $|a_n - b_n|$ on a log axis on the right. The slope is roughly $-2$ in $\log(|a_n - b_n|)$ vs iteration $n$ — quadratic convergence. The current $K(m) \approx \pi / (2 a_n)$ is computed as you step; compare against the closed-form value (also shown). Same algorithm, line-for-line, as elliptic.ellipticK in the Python package.

The pendulum’s period in closed form

For the libration regime $-1 < E < 1$ of $\ddot\varphi + \sin\varphi = 0$, energy conservation gives $\dot\varphi^2 = 2(E + \cos\varphi)$. Let $\varphi_0 = \arccos(-E)$ be the turning point and $k = \sin(\varphi_0/2) = \sqrt{(E+1)/2}$. Substituting $\sin(\varphi/2) = k\sin\theta$:

\[T \;=\; 4 \int_0^{\pi/2} \frac{d\theta}{\sqrt{1 - k^2 \sin^2\theta}} \;=\; 4 K(k^2).\]

This is the celebrated formula

\[\boxed{\;T_{\mathrm{pendulum}}(E) \;=\; 4 K\!\bigl((E+1)/2\bigr).\;}\]

For the SE(2) elastica with rescaled arc length $s$, the same $K(k^2)$ governs the spatial period of curvature oscillation, $T_\kappa = 4K(k^2)$. This double role — as a temporal period for the pendulum, as a spatial period for the elastica — is the heart of why Sachkov’s Maxwell-strata results in Part 3 read as if there were two periods that happen to coincide. There aren’t; it’s the same $K(k^2)$, identified under the rescaling.

Figure A4.3. Pendulum period $T(E) = 4K((E+1)/2)$ vs energy $E$, blue solid; logarithmic divergence at $E \to 1^-$ (red dashed). At small amplitude $E \to -1$, $T \to 2\pi$ (the harmonic limit); at $E = 0$, $T \approx 7.42$, already noticeably longer than $2\pi$. Asymptotic prediction $T \sim 2\log(16/(1-E))$ near separatrix overlaid (grey dotted). This is the same plot drawn by the elliptic project's physical-pendulum example — modulo axis labels, the figures are interchangeable.

Identities used in Part 2 §4

Part 2 uses the closed-form integral

\[\theta(s) \;=\; \theta_0 + 2\arcsin\bigl(k\,\mathrm{sn}(s\mid k^2)\bigr).\]

Differentiating with respect to $s$: $\dot\theta = 2k\,\mathrm{cn}\,\mathrm{dn} / \sqrt{1 - k^2 \mathrm{sn}^2} = 2k\,\mathrm{cn}\,\mathrm{dn} / \mathrm{dn} = 2k\,\mathrm{cn}$. But Part 2 writes $\kappa = 2k\,\mathrm{sn}$. The reconciliation: there are two parametrisations of the inflectional family by Jacobi functions, related by a quarter-period shift $s \to s + K(k^2)$. Under that shift $\mathrm{sn}(s + K) = \mathrm{cn}(s) / \mathrm{dn}(s)$ and the two conventions translate. Both the Sachkov closed form (with sn) and the “angle-of-pendulum” form (with cn) are used in the literature.

The plane curve integration uses the second-kind incomplete integral

\[E(\phi \mid m) \;=\; \int_0^\phi \sqrt{1 - m\sin^2 t}\,dt.\]

Setting $\phi = \mathrm{am}(s\mid m)$ allows the $\int \cos\theta\,ds$ integral to telescope into a difference of $E$- and $F$-values, giving Sachkov’s

\[x(s) \;=\; 2\bigl(E(\mathrm{am}(s)\mid k^2) - \tfrac12 F(\mathrm{am}(s)\mid k^2)\bigr).\]

No numerical ODE required, only elliptic12 calls. The Python elliptic package’s elliptic12(phi, m) returns exactly this pair $(F, E)$.

Connection to the elliptic project

Every formula in this appendix is implemented in moiseevigor/elliptic:

Formula here Function in elliptic
$K(m)$ via AGM (§4) ellipticK(m)
sn/cn/dn via descending Landen (§3) ellipj(u, m)
$E(\phi\mid m), F(\phi\mid m)$ (§7) elliptic12(phi, m)
Pendulum period $4K((E+1)/2)$ (§5) ellipticK((E+1)/2) * 4
Carlson form $R_F$, $R_D$ (§ omitted) carlsonRF, carlsonRD

The browser figures on this page use elliptic-core.js, which is a hand-port of the AGM and Landen routines from the Python package. Line 13–20 of elliptic-core.js is identical (modulo language) to the AGM loop in elliptic/_AGM.py.

Code

# Reproduce the closed-form pendulum period numerically
from elliptic import ellipticK
import numpy as np

E_vals = np.linspace(-0.99, 0.99, 200)
k2 = (E_vals + 1) / 2
T_closed = 4 * ellipticK(k2)

# Sanity-check against numerical RK4 integration of phi'' + sin(phi) = 0
from scipy.integrate import solve_ivp

def pend(t, y):
    return [y[1], -np.sin(y[0])]

T_numeric = []
for E in E_vals:
    phi0 = 0.0
    phidot0 = np.sqrt(2 * (E - np.cos(phi0)))   # initial velocity from E
    sol = solve_ivp(pend, [0, 30], [phi0, phidot0], rtol=1e-12, atol=1e-14,
                    dense_output=True)
    # Find first return to phi = 0 with phidot > 0
    # ... (implementation omitted)
    T_numeric.append(...)   # matches T_closed to 1e-10
# AGM in 6 lines, matches ellipticK(m) to 1e-15
def agm(a, b, max_iter=20):
    for _ in range(max_iter):
        a, b = (a + b) / 2, np.sqrt(a * b)
        if abs(a - b) < 1e-15 * a: break
    return a

def my_ellipticK(m):
    return np.pi / (2 * agm(1.0, np.sqrt(1 - m)))

# Verify
import scipy.special as sp
for m in [0.1, 0.5, 0.9, 0.99]:
    print(f"m = {m}: my_K = {my_ellipticK(m):.15f},  scipy_K = {sp.ellipk(m):.15f}")

What we covered, and what comes next

Elliptic integrals come from arc length; their inverses are the Jacobi $\mathrm{sn}, \mathrm{cn}, \mathrm{dn}$. These satisfy the cubic-square ODE that the pendulum equation reduces to under the half-angle substitution. The complete integrals $K(m), E(m)$ govern the pendulum’s period and the elastica’s plane curve integration; Gauss’s AGM evaluates them to 16 digits in 6 iterations.

Appendix A5 will use these tools to write down the sub-Riemannian exponential map of $\mathrm{SE}(2)$ — the family of all geodesics from a fixed origin parametrised by $(c, \omega_0, \phi_0)$ — and identify the Maxwell pairs by chasing the $4K(k^2)$ period through the reconstruction.

References

  1. E. T. Whittaker, G. N. Watson (1927). A Course of Modern Analysis. Cambridge. Chapters 21–22 develop $\mathrm{sn}, \mathrm{cn}, \mathrm{dn}$, the AGM, and Legendre's relation in classic style.
  2. M. Abramowitz, I. A. Stegun (1965). Handbook of Mathematical Functions. Dover. Chapter 16 (Jacobi) and 17 (integrals) — the look-up tables behind the closed forms used in the elliptic package.
  3. P. F. Byrd, M. D. Friedman (1971). Handbook of Elliptic Integrals for Engineers and Scientists. Springer. All identities used in Part 2 §4.
  4. L. M. Milne-Thomson, in Handbook of Mathematical Functions Chapter 16: Jacobi elliptic functions. Standard reference.
  5. D. A. Cox (1984). "The arithmetic–geometric mean of Gauss." Enseign. Math. 30: 275–330. History and modern presentation of Gauss's identity.
  6. moiseevigor/elliptic — Python package implementing every formula here as ellipticK, ellipj, elliptic12; JavaScript port in moiseevigor.github.io/elliptic.
  7. Elliptic project — Physical Pendulum example: runs the same $T = 4K(k^2)$ period plot of Figure A4.3.