special

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 1 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package special is the special functions tukey needs: the elliptic functions for Ellip, I0 for the Kaiser windows, and exactly reduced sines and cosines of π·x.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CarlsonRF added in v0.10.0

func CarlsonRF(x, y, z float64) (rf float64)

CarlsonRF is Carlson's symmetric elliptic integral of the first kind, for x, y and z ≥ 0 with at most one of them 0:

RF(x, y, z) = ½·∫ dt/√((t + x)(t + y)(t + z)), for t from 0 to ∞

It gives the incomplete integral of the first kind as:

F(φ | m) = sin φ·RF(cos²φ, 1 - m·sin²φ, 1)

where the second argument can be formed without cancellation when m is near 1. It's by Carlson's duplication theorem, then his fifth-order series, which is within 1e-18 once the arguments are within 1e-3 of their mean, same as scipy.special.elliprf(x, y, z).

func EllipK added in v0.10.0

func EllipK(m float64) (k float64)

EllipK is the complete elliptic integral of the first kind, K(m), for the parameter m = k² in [0, 1]. K(1) is +Inf, and m outside [0, 1] gives NaN. For m near 1, where 1 - m has lost its digits, use EllipKM1.

func EllipKM1 added in v0.10.0

func EllipKM1(p float64) (k float64)

EllipKM1 is K(1 - p), taking the complementary parameter p directly, so a parameter near 1 keeps every digit of its distance from 1. EllipKM1(0) is +Inf, and p outside [0, 1] gives NaN. It's found by the arithmetic-geometric mean, same as scipy.special.ellipkm1(p):

K(1 - p) = π/(2·AGM(1, √p))

func I0

func I0(x float64) (y float64)

I0 is the modified Bessel function of the first kind, of order zero:

I0(x) = Σ ((x/2)^k/k!)², for k from 0

It's even, I0(0) = 1, and it grows like e^|x|/√(2π·|x|), overflowing to +Inf beyond |x| ≈ 713.99. I0(±Inf) is +Inf, and I0(NaN) is NaN. Its relative error is within about 6e-16, by Cephes's measurement over [0, 30].

The method and coefficients are Cephes's i0, via SciPy's xsf, as THIRD_PARTY_NOTICES records: a Chebyshev expansion of e^-x·I0(x) on [0, 8], and of e^-x·√x·I0(x) in 32/x beyond. Same as current xsf, and unlike SciPy 1.18, it stays finite past exp's overflow at x ≈ 709.78, or 709.44 with Go's amd64 math.Exp.

func IncompleteF added in v1.0.0

func IncompleteF(tanSq, m1 float64) (f float64)

IncompleteF is F(arctan(√tanSq) | 1 - m1), the incomplete elliptic integral of the first kind at a parameter near 1. It comes from Carlson's RF, whose second argument needs no subtraction:

1 - (1 - m1)·sin²φ = cos²φ + m1·sin²φ

func Jacobi added in v0.10.0

func Jacobi(u, m, mc float64) (sn, cn, dn float64)

Jacobi returns the Jacobi elliptic functions sn, cn and dn of u for the parameter m, whose complement mc = 1 - m is given too, so neither loses digits when the other is near 0. m and mc must be in [0, 1] and sum to 1. It's by the descending Landen transformation, with the AGM's c_n found as c_n²/(4·a_(n+1)) rather than (a_n - b_n)/2, which cancels. dn is √(mc + m·cn²), a sum of positive terms, rather than Cephes's cn/cos(φ_1 - φ), which is 0/0 at u = K.

For u in [0, K/2] each function is within a few ULP of its exact value while mc ≥ 1e-4, losing about two digits by mc = 1e-6, and four by 1e-9. In (K/2, K], cn is small, and its relative error grows as it shrinks, so a caller needing it there should use u′ = K - u, and JacobiInQuarter does:

cn(u) = √mc·sn(u′)/dn(u′)
dn(u) = √mc/dn(u′)
sn(u) = cn(u′)/dn(u′)

It's scipy.special.ellipj(u, m)'s first three outputs, and MATLAB's ellipj(u, m), and more accurate than both as m approaches 1.

func JacobiInQuarter added in v1.0.0

func JacobiInQuarter(u, uc, m, mc float64) (sn, cn, dn float64)

JacobiInQuarter is Jacobi of u in [0, K], given uc = K - u too. Above K/2, cn is small and Jacobi loses its relative digits, so the functions come from uc instead, where Jacobi is accurate:

sn(u) = cn(uc)/dn(uc)
cn(u) = √mc·sn(uc)/dn(uc)
dn(u) = √mc/dn(uc)

func ParameterFromNome added in v0.10.0

func ParameterFromNome(q float64) (m float64)

ParameterFromNome is the parameter m whose nome, e^(-π·K(1 - m)/K(m)), is q, for q in [0, 1), by the theta series:

m = 16q·(Σ_(n≥0) q^(n(n+1))/(1 + 2·Σ_(n≥1) q^(n²)))^4

The series needs at most 4 terms for q ≤ e^-π, where m ≤ ½. Above that, m is found as 1 - m′, where m′ is the parameter of the complementary nome q′, with ln q·ln q′ = π², and q′ < e^-π. m is then accurate, but 1 - m isn't, so a caller needing 1 - m should pass q′ itself. A q outside [0, 1) gives NaN. It's the same as mpmath.mfrom(q=q).

func SinCosPi added in v1.0.0

func SinCosPi(x float64) (sin, cos float64)

SinCosPi is sin(π·x) and cos(π·x), within a few ULP for any x. x is reduced exactly to a quarter turn either side of a multiple of π/2, so an x far from 0 is as accurate as one near it.

func SinCosPiProduct added in v1.0.0

func SinCosPiProduct(a, b float64) (sin, cos float64)

SinCosPiProduct is sin(π·a·b) and cos(π·a·b). The rounding error of a·b is added back by its first-order term, so a product in the hundreds, such as a long FIR filter's outer taps, keeps its digits.

Types

type DoubleDouble added in v1.1.0

type DoubleDouble struct {
	Hi, Lo float64
}

DoubleDouble is the unevaluated sum Hi + Lo, with |Lo| at most half an ULP of Hi, which carries about 32 significant digits, twice a float64's. Its arithmetic is within a few parts in 2^104 of exact, for sums such as a chirp's phase, where float64 would leave too few digits after removing whole cycles.

Algorithms from Hida, Li and Bailey, "Library for double-double and quad-double arithmetic" (2007), with products split by math.FMA.

func Exact added in v1.1.0

func Exact(x float64) (d DoubleDouble)

Exact is x as a DoubleDouble.

func Exp added in v1.1.0

func Exp(d DoubleDouble) (e DoubleDouble)

Exp is e^d, within about 2^-94 relative of exact. It's +Inf above ln(MaxFloat64), and 0 far below 0.

func ExpM1 added in v1.1.0

func ExpM1(d DoubleDouble) (e DoubleDouble)

ExpM1 is e^d - 1, within about 2^-94 relative of exact, and as accurate for a d near 0, where e^d - 1 cancels. It's +Inf above ln(MaxFloat64), and -1 far below 0.

func Log added in v1.1.0

func Log(d DoubleDouble) (y DoubleDouble)

Log is ln(d), within about 2^-100 relative of exact. d = m·2^k with m between √½ and √2, and ln(m) is math.Log's estimate y, corrected by one Newton step, y + m·e^-y - 1. It's -Inf at 0, and NaN below 0.

func ProductOf added in v1.1.0

func ProductOf(a, b float64) (d DoubleDouble)

ProductOf is a·b, exactly unless it underflows.

func SumOf added in v1.1.0

func SumOf(a, b float64) (d DoubleDouble)

SumOf is a + b, exactly.

func (DoubleDouble) Add added in v1.1.0

func (d DoubleDouble) Add(e DoubleDouble) (sum DoubleDouble)

Add is d + e.

func (DoubleDouble) Div added in v1.1.0

func (d DoubleDouble) Div(e DoubleDouble) (quotient DoubleDouble)

Div is d/e, three float64 quotients each taken from the remainder of the last.

func (DoubleDouble) Float64 added in v1.1.0

func (d DoubleDouble) Float64() (x float64)

Float64 is d rounded to a float64.

func (DoubleDouble) Mul added in v1.1.0

func (d DoubleDouble) Mul(e DoubleDouble) (product DoubleDouble)

Mul is d·e.

func (DoubleDouble) Neg added in v1.1.0

func (d DoubleDouble) Neg() (n DoubleDouble)

Neg is -d.

func (DoubleDouble) Sub added in v1.1.0

func (d DoubleDouble) Sub(e DoubleDouble) (diff DoubleDouble)

Sub is d - e.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL