Expand description
Real-degree Ferrers functions of the first kind with integer order.
Upstream: treams.special.lpmv at a non-integer degree and a real argument, which
calls scipy’s lpmv.
ferrers_real_degree evaluates P_ν^m(x) and dP_ν^m/dx for a non-integer degree
0 < ν < 128, an integer order |m| <= 130 and -1 < x <= 1, with the conventions of
NIST DLMF §14.3 (Ferrers functions “on the cut”, Condon–Shortley phase included for
m > 0). It implements the DLMF formulas cited below.
§Method
Write μ = |m|, n = ⌊ν⌋, f = ν - n, y = |x|, w = 1 - y² = sin²θ and
t = s = (1 - y)/2. The functions are computed for the order -μ; positive orders follow
from DLMF 14.9.3, P_ν^μ = (-1)^μ Γ(ν+μ+1)/Γ(ν-μ+1) P_ν^{-μ}, with the gamma ratio formed as
∏_{i=1}^{μ} (ν(ν + 1) - i(i - 1)) from an exactly split ν(ν + 1).
- About
x = 1(x >= 0). DLMF 14.3.1 with Euler’s transformation (DLMF 15.8.1) givesP_ν^{-μ}(y) = w^{μ/2}/(2^μ μ!) F(μ - ν, μ + ν + 1; μ + 1; t). The series is summed at a start degreeν₀ ≡ ν (mod 1),μ <= ν₀ <= ν, as large as its alternating leading terms allow, and carried toνby the degree recurrence DLMF 14.10.3 written forP_νandD_ν = P_{ν-1} - yP_ν:P_{ν+1} = yP_ν - c_ν D_ν,D_{ν+1} = wP_ν + y c_ν D_ν,c_ν = (ν - μ)/(ν + μ + 1). This form never subtracts nearly equal values neary = 1, and increasing the degree is stable: the regular solution dominates where(ν + 1/2) sinθ < μ, and both solutions oscillate elsewhere.D_ν₀comes from the same series; the derivative is DLMF 14.10.5,w P' = (ν - μ) D_ν - μ y P_ν. - About
x = 0(small degrees,(ν + 1/2)|x|small).G = (1 - x²)^{-μ/2} P_ν^{-μ}solves(1 - x²) G'' - 2(μ + 1) x G' + (ν - μ)(ν + μ + 1) G = 0(from DLMF 14.2.2), so its Taylor coefficients satisfy a two-term recurrence started from the values at zero, DLMF 14.5.1 and 14.5.2, with1/Γfrom a Taylor polynomial and DLMF 5.5.1. - About
x = -1(x < 0). The connection formula DLMF 14.9.10,P_ν^{-μ}(-y) = (-1)^μ [cos(νπ) P_ν^{-μ}(y) + sin(νπ) S_ν^{-μ}(y)]withS = -(2/π) Q, separates the part regular atx = -1from the singular one.sin(νπ)andcos(νπ)come from the exactly reduced degreeν - round(ν), so degrees within an ulp of an integer keep their exact offset. Both parts follow from the degenerate (logarithmic) casec = a + b + μof the1 - zconnection formulas of DLMF §15.8 applied to DLMF 14.3.1: in powers ofswith digamma coefficients, plus a finite sum ofμterms forμ >= 1. The digamma reflection DLMF 5.5.4 turnsψat non-positive arguments intoπ cot(νπ), whose pole is cancelled analytically against the vanishing factorn - νof the series coefficients. The order-zero expansion givesQ_ν(y) = ½ Σ_k (ν+1)_k (-ν)_k/(k!)² [2ψ(k+1) - ψ(ν+k+1) - ψ(ν-k+1) - ln s] s^k. These expansions are summed directly when(ν + 1/2) θis small. Otherwise the order-zero pair is summed at a lower degree and carried toνby the recurrence above; the regular part of order-μcomes from the series aboutx = 1, and the singular part fromS^1 = -w S^0'/sinθand the order recurrence DLMF 14.10.1,S^{k+1} = -2k cotθ S^k - (ν - k + 1)(ν + k) S^{k-1}, which is stable upwards becauseQ_ν^μ(y)dominatesP_ν^μ(y)asμgrows fory > 0; its derivative usesw S^μ' = (ν + μ)(ν - μ + 1) sinθ S^{μ-1} + μ y S^μ(§14.10). - The digamma function uses DLMF 5.5.2 and the asymptotic expansion DLMF 5.11.2.
- Quantities that can leave the double range carry a separate binary exponent, so only a final
value or derivative beyond the double range is reported as an error. Sums that share the
low-order bits of
fare formed without rounding them as a whole, so their rounding errors do not accumulate systematically. Atx = 1the exact limits are returned.
Structs§
- Convergence 🔒
- Convergence test of one series: the term must be negligible twice in a row and the tail,
bounded geometrically with ratio
rho, as well. Once reached, it stays reached. - Order
Sums 🔒 - Sums of
order_series:Σ r_k,Σ k r_k,Σ r_k g_kandΣ (k r_k g_k + r_k). - Order
Zero 🔒 - Order-zero functions at
0 < y < 1, withw = 1 - y²:P_ν(y),w P_ν'(y), andS_ν(y) = -(2/π) Q_ν(y)(Ferrers second kind),w S_ν'(y). - Scaled 🔒
mantissa · 2^exponentwith1/2 <= |mantissa| < 1(or zero): a double with a wider exponent range.- Sums 🔒
- Running sums of the logarithmic expansion:
Σ q_k (c_k - ln s),Σ q_k, and, as requested,Σ (k q_k (c_k - ln s) - q_k)(SINGULAR) andΣ k q_k(REGULAR). The values and each slope converge separately (for tinyνthe regular slope is tiny next to everything else); the values are frozen once converged, so they do not depend on which slopes are summed.
Enums§
- Slopes 🔒
- Which order-zero slopes a caller needs.
Constants§
- BIG 🔒
- Rescaling threshold
2^512for recurrences that could leave the double range. - BIG_
EXPONENT 🔒 - CENTRAL_
DEGREE 🔒 - CENTRAL_
LIMIT 🔒 - CENTRAL_
LIMIT_ 🔒POSITIVE - CENTRAL_
ORDER 🔒 - CENTRAL_
REACH 🔒 - The expansion about
x = 0is used for(ν + 1/2)|x| <= CENTRAL_REACH(well conditioned) and|x| <=CENTRAL_LIMIT(orCENTRAL_LIMIT_POSITIVEforx > 0, where the series aboutx = 1is cheaper), for degrees and orders that keep1/Γcheap. - EXPONENT_
MASK 🔒 - INVALID 🔒
- INV_
FACTORIAL 🔒 - Correctly rounded
1/k!fork = 0..=130(MAX_REAL_DEGREE_ORDER). - MAX_
REAL_ 🔒DEGREE_ ORDER - The largest
|m|offerrers_real_degree, two above its largest degree. Orders above the degree are valid; the angular functions pass|m| <= degree. - MAX_
TERMS 🔒 - Safety bound on series terms; the series converge geometrically for
t, s <= 1/2. - NONFINITE 🔒
- REGULAR_
REACH 🔒 - Largest leading-ratio size
(ν₀ - μ)(ν₀ + μ + 1) t / (μ + 1)of a regular start series. - RGAMMA_
TAYLOR 🔒 - Taylor coefficients of
1/Γ(3/2 + h)abouth = 0(enough for|h| <= 1/2). - SINGULAR_
REACH 🔒 - Largest
2 (ν₀ + 1/2) √s ≈ (ν₀ + 1/2) θat which the logarithmic series is summed. - SQRT_PI 🔒
- TOLERANCE 🔒
- Relative truncation tolerance for the series (
2^-54).
Functions§
- central 🔒
(P_ν^{-μ}(x), (1 - x²) dP_ν^{-μ}/dx)from the expansion aboutx = 0.- degree_
product 🔒 ν(ν + 1)as an unevaluated sumhigh + low.- digamma 🔒
- Digamma for
x >= 1: DLMF 5.5.2 up tox >= 10, then DLMF 5.11.2. - digamma_
reflection_ 🔒step ψ(2 - f) - ψ(1 + f). Forf <= 1/2it isπ cot(πf) - 1/f + 1/(1 - f)(DLMF 5.5.2, 5.5.4) fromfrac_cot = f π cot(πf), with an absolute error of aboutε/fthat the callers’ factorfremoves; otherwise two digamma values.- endpoint 🔒
- Exact limits at
x = 1:P_ν^m(1) = δ_{m0}; the slope isν(ν+1)/2(m = 0), infinite (|m| = 1),-Γ(ν+3)/(4Γ(ν-1))(m = 2),-1/4(m = -2) and zero otherwise. - exact_
square 🔒 - Dekker’s exact square:
v² = square + error. - ferrers_
real_ 🔒degree - Real-degree Ferrers function
P_v^m(x)(degreevnot an integer) and, withDERIVATIVE, its analytic derivative inx; without it the second element is0.0. - finish 🔒
- Converts
(P, (1 - x²) P')to doubles, rejecting results beyond the double range. - floor_
small 🔒 ⌊value⌋for0 <= value < 2^31.- frexp 🔒
value = mantissa · 2^exponentwith1/2 <= |mantissa| < 1; inline fast path for normal numbers,libmotherwise.- gamma_
ratio 🔒 Γ(ν + μ + 1)/Γ(ν - μ + 1) = ∏_{i=1}^{μ} (ν + i)(ν + 1 - i); withskip = Some(i)the factorν + 1 - iof that pair is left out.- log_
series 🔒 OrderZerofrom the logarithmic expansion abouty = 1ins = (1 - y)/2:P_ν = Σ q_k,Q_ν = ½ Σ q_k (c_k - ln s)withq_k = (ν+1)_k (-ν)_k s^k/(k!)²andc_k = 2ψ(k+1) - ψ(ν+k+1) - ψ(ν+1-k), with the slopes selected as inSums.- nearest_
integer 🔒 - The integer nearest to
0 <= value < 2^31(halves rounded up). - nonfinite 🔒
- one_
minus_ 🔒square 1 - y²as an unevaluated sumhigh + low, accurate far beyond a double.- order_
log_ 🔒sums - The logarithmic sums of
order_serieswithn - μ = pivot, in three phases likelog_series: direct terms fork <= n - μ, the cancelled pole atk = n - μ + 1, and the reflected digamma beyond. One division per term serves all reciprocals. - order_
series 🔒 P_ν^m(-y)for0 < y < 1,1 <= μ = |m| <= ⌊ν⌋, from the expansion aboutx = -1ins = (1 - y)/2: the degenerate casec - a - b = μof the1 - zconnection formulas (DLMF §15.8) applied to DLMF 14.3.1, after the digamma reflection DLMF 5.5.4,P_ν^{-μ}(-y) = (-1)^μ cos(νπ) R + sin(νπ) (L + F/G)withG = Γ(ν+μ+1)/Γ(ν-μ+1),R = (w/4)^{μ/2}/μ! Σ r_k(that isP_ν^{-μ}(y)),L = (-1)^μ (w/4)^{μ/2}/(π μ!) Σ r_k [ln s - ψ(k+1) - ψ(k+μ+1) + ψ(ν+μ+k+1) + ψ(ν-μ-k+1)],F = (-1)^{μ+1} (μ-1)!/π (w/4)^{μ/2} s^{-μ} Σ_{k<μ} (ν+1)_k (-ν)_k s^k/(k! (1-μ)_k)andr_k = (ν+μ+1)_k (μ-ν)_k s^k/((μ+1)_k k!). As inlog_series, the pole ofψ(ν - μ - k + 1)is cancelled against the factorn - νofr_k(n = ⌊ν⌋).- order_
zero 🔒 OrderZeroat degreeν: the logarithmic expansion at the largest degreeν₀ ≡ ν(mod 1) with(ν₀ + 1/2) θsmall, then the degree recurrence (μ = 0) for both solutions. Only the requested slopes are formed, unless the recurrence needs both.- pi_
cot_ 🔒scaled πr cot(πr)for|r| <= 1/2, accurate (and finite) asr → 0.- raise_
singular 🔒 (S_ν^μ(y), (1 - y²) dS_ν^μ/dy)forμ >= 1from order zero:S^1 = -w S^0'/sinθ, then the order recurrence DLMF 14.10.1 upwards.- reflected 🔒
P_ν^m(-y)for0 < y < 1by the connection formula DLMF 14.9.10.- regular 🔒
(P_ν^{-μ}(y), (1 - y²) dP_ν^{-μ}/dy)for0 <= y < 1.- rgamma 🔒
1/Γ(z)for moderate realz: DLMF 5.5.1 shifts into[1, 2), then a Taylor polynomial. The shifts multiply byz + kexactly whereΓhas poles, so those zeros are exact.- rgamma_
core 🔒 1/Γ(3/2 + h)for|h| <= 1/2by Estrin’s scheme (short dependency chains).- scalbn 🔒
value · 2^exponent, correctly rounded; inline fast path when2^exponentis a normal number andvalueis normalised as inScaled.- shifted_
sum 🔒 Σ_{i=1}^{count} 1/(start + i)for a small integercount, as one fraction.- sin_
cos_ 🔒pi (sin(νπ), cos(νπ))from the exactly reduced degreeν - round(ν).- sine_
over_ 🔒gamma_ ratio sin(νπ) Γ(ν - μ + 1)/Γ(ν + μ + 1); outside the caller domain (μ > round(ν)) the vanishing factorν - round(ν)of the gamma ratio is cancelled againstsin(νπ).- sine_
power 🔒 w^{μ/2}for1 - y² = w + w_low(0 < w <= 1).- small_
integer 🔒 valuerounded towards zero, for|value| < 2^31(larger magnitudes saturate). Callers use it on validated degrees and small shifts; unlikef64::floorit needs no library call.- two_sum 🔒
- Knuth’s error-free sum:
a + b = sum + errorexactly.