NIST DLMF (2026)
The NIST Digital Library of Mathematical Functions defines the spherical harmonics in terms of Ferrers functions in a way that agrees with the definition used in the SphericalFunctions package.
The NIST Digital Library of Mathematical Functions is the successor to Abramowitz and Stegun, and is probably the most careful modern reference for the special functions. The statements below are quoted from Release 1.2.7 of 2026-06-15, accessed 2026-09-08.
The DLMF distinguishes between Ferrers' function (of the first kind) $\mathsf{P}_\nu^\mu$ and the associated Legendre function (of the first kind) $P_\nu^\mu$. Here, $\nu$ is called the "degree" and $\mu$ is called the "order". We can see from their definitions in Eqs. 14.3.1 and 14.3.6, respectively, that they differ only by a phase $e^{\pm iπ\mu/2}$ (the sign depending on the side from which the cut along $(-1, 1)$ is approached; see Eq. 14.23.1).
For integer degree and order, we have Eq. 14.7.10
\[ \mathsf{P}^{m}_{n}\left(x\right) = (-1)^{m+n} \frac{\left(1-x^{2}\right)^{m/2}}{2^{n}n!} \frac{{\mathrm{d}}^{m+n}}{{\mathrm{d}x}^{m+n}} \left(1-x^{2}\right)^{n},\]
or Eq. 14.7.14
\[ P^{m}_{n}\left(x\right) = \frac{\left(x^{2}-1\right)^{m/2}}{2^{n}n!} \frac{{\mathrm{d}}^{m+n}}{{\mathrm{d}x}^{m+n}} \left(x^{2}-1\right)^{n}.\]
Note that Eq. 14.7.10 includes the Condon–Shortley phase $(-1)^m$ in the Ferrers function itself. The spherical harmonics are then defined in Eq. 14.30.1, for $0 \leq θ \leq π$ and $0 \leq ϕ \leq 2π$, as
\[ Y_{l, m}\left(θ,ϕ\right) = \left(\frac{(l-m)!(2l+1)}{4π(l+m)!}\right)^{1/2} e^{imϕ} \mathsf{P}_{l}^{m}\left(\cos θ\right),\]
using the Ferrers function. Eq. 14.30.6 records the conjugation relation
\[ Y_{l,-m}(θ, ϕ) = (-1)^m\, \overline{Y_{l,m}(θ, ϕ)}.\]
Since Eq. 14.7.10 is only stated for $m \geq 0$, we use Eq. 14.30.6 for negative $m$. This is the standard Condon–Shortley convention, so we expect agreement with our spherical harmonics. The DLMF does not define Wigner's $D$ matrices.
Implementing formulas
We begin by writing code that implements the formulas from the DLMF. We encapsulate the formulas in a module so that we can test them against the SphericalFunctions package.
module NIST_DLMFWe'll use some predefined utilities to make the code look more like the equations, including ∂ⁿ, which computes derivatives symbolically so that we can transcribe the formulas literally.
import ..ConventionsUtilities: 𝒾, ❗, ∂ⁿFerrers' function of the first kind, Eq. 14.7.10:
function 𝖯(n, m, x) (-1)^(m+n) * (1 - x^2)^(m/2) / (2^n * (n)❗) * ∂ⁿ(x -> (1 - x^2)^n, m+n)(x)endThe associated Legendre function of the first kind, Eq. 14.7.14. For $|x| < 1$ the factor $(x^2-1)^{m/2}$ is complex; with the principal branch of the power (which corresponds to approaching the cut from above), it differs from the Ferrers function by $e^{-iπm/2}$. We include it only to check that relation.
function P(n, m, x) (complex(x^2 - 1))^(m/2) / (2^n * (n)❗) * ∂ⁿ(x -> (x^2 - 1)^n, m+n)(x)endThe spherical harmonics, Eq. 14.30.1 for $m \geq 0$ and Eq. 14.30.6 for $m < 0$. We capture the floating-point type T to ensure that we don't lose precision when converting π and the factorials to floating-point numbers.
function Y(l, m, θ::T, ϕ::T) where {T<:Real} if m < 0 return (-1)^m * conj(Y(l, -m, θ, ϕ)) end √T((l-m)❗ * (2l+1) / (4big(π) * (l+m)❗)) * exp(𝒾 * m * ϕ) * T(𝖯(l, m, cos(θ)))endend # module NIST_DLMFTests
We can now test the functions against the equivalent functions from the SphericalFunctions package. We will need to test approximate floating-point equality, so we set absolute and relative tolerances (respectively) in terms of the machine epsilon:
ϵₐ = 100eps()ϵᵣ = 1000eps()We only test up to
ℓₘₐₓ = 6because the symbolic derivatives in the formulas become expensive to compute at higher orders, and this will be sufficient to sort out any sign or normalization differences, which are the most likely source of error.
We will also need the imaginary unit from the utilities module.
import .ConventionsUtilities: 𝒾First, the relation between the Ferrers function and the associated Legendre function, $P_n^m(x) = e^{-iπm/2}\, \mathsf{P}_n^m(x)$ for $-1 < x < 1$ with the principal branch of the power:
for x ∈ range(-0.9, 0.9, length=7) for n ∈ 0:ℓₘₐₓ, m ∈ 0:n @test NIST_DLMF.P(n, m, x) ≈ exp(-𝒾 * π * m / 2) * NIST_DLMF.𝖯(n, m, x) atol=ϵₐ rtol=ϵᵣ endendNow, the spherical harmonics agree with ours:
for (θ, ϕ) ∈ θϕrange(rng, Float64, 7) for (ℓ, Yˡ) ∈ SphericalFunctions.YlmCalculator(θ, ϕ, ℓₘₐₓ), m ∈ -ℓ:ℓ @test NIST_DLMF.Y(ℓ, m, θ, ϕ) ≈ Yˡ[m] atol=ϵₐ rtol=ϵᵣ endendThis successful test shows that the spherical harmonics defined by the DLMF agree with the spherical harmonics defined by the SphericalFunctions package.
This page was generated using Literate.jl.