Skip to content

cds2.special

Deprecated since 4.3.0

Importing this module emits a DeprecationWarning. Use scipy.special directly instead. See Deprecated modules for the migration guide.

Special mathematical functions on scipy.special - gamma family, error functions, Bessels and zeta.

Special mathematical functions built on scipy.special.

gamma_fn(x)

Euler gamma function for real arguments.

Source code in src/cds2/special.py
69
70
71
def gamma_fn(x: object) -> NDArray[np.float64]:
    """Euler gamma function for real arguments."""
    return _as_array(sps.gamma(_as_array(x)))

gammaln(x)

Log-gamma function - numerically stable for large inputs.

Source code in src/cds2/special.py
74
75
76
def gammaln(x: object) -> NDArray[np.float64]:
    """Log-gamma function - numerically stable for large inputs."""
    return _as_array(sps.gammaln(_as_array(x)))

digamma(x)

Digamma (psi) function - logarithmic derivative of gamma.

Source code in src/cds2/special.py
79
80
81
def digamma(x: object) -> NDArray[np.float64]:
    """Digamma (psi) function - logarithmic derivative of gamma."""
    return _as_array(sps.digamma(_as_array(x)))

fresnel_c(x)

Fresnel cosine integral C(x).

Source code in src/cds2/special.py
84
85
86
def fresnel_c(x: object) -> NDArray[np.float64]:
    """Fresnel cosine integral C(x)."""
    return _as_array(sps.fresnel(_as_array(x))[0])

fresnel_s(x)

Fresnel sine integral S(x).

Source code in src/cds2/special.py
89
90
91
def fresnel_s(x: object) -> NDArray[np.float64]:
    """Fresnel sine integral S(x)."""
    return _as_array(sps.fresnel(_as_array(x))[1])

erf(x)

Gaussian error function.

Source code in src/cds2/special.py
94
95
96
def erf(x: object) -> NDArray[np.float64]:
    """Gaussian error function."""
    return _as_array(sps.erf(_as_array(x)))

erfc(x)

Complementary error function (accurate in the far tail).

Source code in src/cds2/special.py
 99
100
101
def erfc(x: object) -> NDArray[np.float64]:
    """Complementary error function (accurate in the far tail)."""
    return _as_array(sps.erfc(_as_array(x)))

erfinv(x)

Inverse error function on [-1, 1].

Source code in src/cds2/special.py
104
105
106
def erfinv(x: object) -> NDArray[np.float64]:
    """Inverse error function on [-1, 1]."""
    return _as_array(sps.erfinv(_as_array(x)))

beta_fn(a, b)

Euler beta function.

Source code in src/cds2/special.py
109
110
111
def beta_fn(a: float, b: float) -> float:
    """Euler beta function."""
    return float(sps.beta(a, b))

betaln(a, b)

Log-beta function.

Source code in src/cds2/special.py
114
115
116
def betaln(a: float, b: float) -> float:
    """Log-beta function."""
    return float(sps.betaln(a, b))

bessel_j0(x)

Bessel function of the first kind, order 0.

Source code in src/cds2/special.py
119
120
121
def bessel_j0(x: object) -> NDArray[np.float64]:
    """Bessel function of the first kind, order 0."""
    return _as_array(sps.j0(_as_array(x)))

bessel_j1(x)

Bessel function of the first kind, order 1.

Source code in src/cds2/special.py
124
125
126
def bessel_j1(x: object) -> NDArray[np.float64]:
    """Bessel function of the first kind, order 1."""
    return _as_array(sps.j1(_as_array(x)))

bessel_y0(x)

Bessel function of the second kind (Neumann), order 0.

Source code in src/cds2/special.py
129
130
131
def bessel_y0(x: object) -> NDArray[np.float64]:
    """Bessel function of the second kind (Neumann), order 0."""
    return _as_array(sps.y0(_as_array(x)))

spherical_bessel_j0(x)

Spherical Bessel function of the first kind, order 0.

Source code in src/cds2/special.py
134
135
136
def spherical_bessel_j0(x: object) -> NDArray[np.float64]:
    """Spherical Bessel function of the first kind, order 0."""
    return _as_array(sps.spherical_jn(0, _as_array(x)))

spherical_bessel_j1(x)

Spherical Bessel function of the first kind, order 1.

Source code in src/cds2/special.py
139
140
141
def spherical_bessel_j1(x: object) -> NDArray[np.float64]:
    """Spherical Bessel function of the first kind, order 1."""
    return _as_array(sps.spherical_jn(1, _as_array(x)))

airy_ai(x)

Airy function Ai - solves y'' = x*y, decaying for x > 0.

Source code in src/cds2/special.py
144
145
146
147
def airy_ai(x: object) -> NDArray[np.float64]:
    """Airy function Ai - solves y'' = x*y, decaying for x > 0."""
    ai, _aip, _bi, _bip = sps.airy(_as_array(x))
    return _as_array(ai)

airy_bi(x)

Airy function Bi - grows exponentially for x > 0.

Source code in src/cds2/special.py
150
151
152
153
def airy_bi(x: object) -> NDArray[np.float64]:
    """Airy function Bi - grows exponentially for x > 0."""
    _ai, _aip, bi, _bip = sps.airy(_as_array(x))
    return _as_array(bi)

legendre_pn(n, x)

Legendre polynomial P_n evaluated on [-1, 1].

Source code in src/cds2/special.py
156
157
158
def legendre_pn(n: int, x: object) -> NDArray[np.float64]:
    """Legendre polynomial P_n evaluated on [-1, 1]."""
    return _as_array(sps.eval_legendre(n, _as_array(x)))

elliptic_k(m)

Complete elliptic integral of the first kind K(m).

Source code in src/cds2/special.py
161
162
163
def elliptic_k(m: object) -> NDArray[np.float64]:
    """Complete elliptic integral of the first kind K(m)."""
    return _as_array(sps.ellipk(_as_array(m)))

elliptic_e(m)

Complete elliptic integral of the second kind E(m).

Source code in src/cds2/special.py
166
167
168
def elliptic_e(m: object) -> NDArray[np.float64]:
    """Complete elliptic integral of the second kind E(m)."""
    return _as_array(sps.ellipe(_as_array(m)))

exp1(x)

Exponential integral E1(x) = integral from x to inf of e^-t/t.

Source code in src/cds2/special.py
171
172
173
def exp1(x: object) -> NDArray[np.float64]:
    """Exponential integral E1(x) = integral from x to inf of e^-t/t."""
    return _as_array(sps.exp1(_as_array(x)))

hypergeometric_2f1(a, b, c, z)

Gauss hypergeometric function 2F1(a, b; c; z).

Source code in src/cds2/special.py
176
177
178
def hypergeometric_2f1(a: float, b: float, c: float, z: object) -> NDArray[np.float64]:
    """Gauss hypergeometric function 2F1(a, b; c; z)."""
    return _as_array(sps.hyp2f1(a, b, c, _as_array(z)))

zeta(x, q=None)

Riemann (or Hurwitz with q) zeta function at a real point.

Source code in src/cds2/special.py
181
182
183
184
185
def zeta(x: float, q: float | None = None) -> float:
    """Riemann (or Hurwitz with ``q``) zeta function at a real point."""
    if q is None:
        return float(sps.zeta(x))
    return float(sps.zeta(x, q))

bessel_jv(nu, x)

Bessel function of the first kind of real order nu.

Source code in src/cds2/special.py
189
190
191
def bessel_jv(nu: float, x: object) -> NDArray[np.float64]:
    """Bessel function of the first kind of real order ``nu``."""
    return _as_array(sps.jv(nu, _as_array(x)))

bessel_yv(nu, x)

Bessel function of the second kind of real order nu.

Source code in src/cds2/special.py
194
195
196
def bessel_yv(nu: float, x: object) -> NDArray[np.float64]:
    """Bessel function of the second kind of real order ``nu``."""
    return _as_array(sps.yv(nu, _as_array(x)))

bessel_iv(nu, x)

Modified Bessel function of the first kind.

Source code in src/cds2/special.py
199
200
201
def bessel_iv(nu: float, x: object) -> NDArray[np.float64]:
    """Modified Bessel function of the first kind."""
    return _as_array(sps.iv(nu, _as_array(x)))

bessel_kv(nu, x)

Modified Bessel function of the second kind.

Source code in src/cds2/special.py
204
205
206
def bessel_kv(nu: float, x: object) -> NDArray[np.float64]:
    """Modified Bessel function of the second kind."""
    return _as_array(sps.kv(nu, _as_array(x)))

hankel1_fn(nu, x)

Hankel function of the first kind H1_nu (real part).

Source code in src/cds2/special.py
209
210
211
def hankel1_fn(nu: float, x: object) -> NDArray[np.float64]:
    """Hankel function of the first kind H1_nu (real part)."""
    return _as_array(np.real(sps.hankel1(nu, _as_array(x))))

struve_h0(x)

Struve function H_0.

Source code in src/cds2/special.py
214
215
216
def struve_h0(x: object) -> NDArray[np.float64]:
    """Struve function H_0."""
    return _as_array(sps.struve(0, _as_array(x)))

struve_h1(x)

Struve function H_1.

Source code in src/cds2/special.py
219
220
221
def struve_h1(x: object) -> NDArray[np.float64]:
    """Struve function H_1."""
    return _as_array(sps.struve(1, _as_array(x)))

chebyshev_tn(n, x)

Chebyshev polynomial T_n on [-1, 1].

Source code in src/cds2/special.py
224
225
226
def chebyshev_tn(n: int, x: object) -> NDArray[np.float64]:
    """Chebyshev polynomial T_n on [-1, 1]."""
    return _as_array(sps.eval_chebyt(n, _as_array(x)))

chebyshev_un(n, x)

Chebyshev polynomial U_n on [-1, 1].

Source code in src/cds2/special.py
229
230
231
def chebyshev_un(n: int, x: object) -> NDArray[np.float64]:
    """Chebyshev polynomial U_n on [-1, 1]."""
    return _as_array(sps.eval_chebyu(n, _as_array(x)))

laguerre_ln(n, x)

Laguerre polynomial L_n on [0, inf).

Source code in src/cds2/special.py
234
235
236
def laguerre_ln(n: int, x: object) -> NDArray[np.float64]:
    """Laguerre polynomial L_n on [0, inf)."""
    return _as_array(sps.eval_laguerre(n, _as_array(x)))

hermite_hn(n, x)

Physicists' Hermite polynomial H_n.

Source code in src/cds2/special.py
239
240
241
def hermite_hn(n: int, x: object) -> NDArray[np.float64]:
    """Physicists' Hermite polynomial H_n."""
    return _as_array(sps.eval_hermite(n, _as_array(x)))

jacobi_pnab(n, alpha, beta_param, x)

Jacobi polynomial P_n^(alpha, beta) on [-1, 1].

Source code in src/cds2/special.py
244
245
246
def jacobi_pnab(n: int, alpha: float, beta_param: float, x: object) -> NDArray[np.float64]:
    """Jacobi polynomial P_n^(alpha, beta) on [-1, 1]."""
    return _as_array(sps.eval_jacobi(n, alpha, beta_param, _as_array(x)))

spherical_harmonic(m, l_degree, theta, phi)

Spherical harmonic Y_l^m at polar theta and azimuth phi.

Source code in src/cds2/special.py
249
250
251
252
253
254
255
256
257
def spherical_harmonic(m: int, l_degree: int, theta: object, phi: object) -> NDArray[np.complex128]:
    """Spherical harmonic Y_l^m at polar ``theta`` and azimuth ``phi``."""
    values = sps.sph_harm_y(
        l_degree,
        m,
        np.asarray(theta, dtype=float),
        np.asarray(phi, dtype=float),
    )
    return np.atleast_1d(np.asarray(values, dtype=np.complex128))

lambert_w(x)

Lambert W function solving W*exp(W) = x (principal branch).

Source code in src/cds2/special.py
260
261
262
def lambert_w(x: object) -> NDArray[np.float64]:
    """Lambert W function solving W*exp(W) = x (principal branch)."""
    return _as_array(np.real(sps.lambertw(_as_array(x))))

faddeeva_w(z_real, z_imag)

Faddeeva function w(z) for z = z_real + i*z_imag.

Source code in src/cds2/special.py
265
266
267
268
def faddeeva_w(z_real: object, z_imag: object) -> NDArray[np.complex128]:
    """Faddeeva function w(z) for z = z_real + i*z_imag."""
    argument = np.asarray(z_real, dtype=float) + 1j * np.asarray(z_imag, dtype=float)
    return np.atleast_1d(np.asarray(sps.wofz(argument), dtype=np.complex128))

exponential_integral_en(n_order, x)

Generalized exponential integral E_n(x).

Source code in src/cds2/special.py
271
272
273
def exponential_integral_en(n_order: int, x: object) -> NDArray[np.float64]:
    """Generalized exponential integral E_n(x)."""
    return _as_array(sps.expn(n_order, _as_array(x)))

sine_cosine_integrals(x)

Return (Si(x), Ci(x)) - sine and cosine integrals.

Source code in src/cds2/special.py
276
277
278
279
def sine_cosine_integrals(x: object) -> tuple[NDArray[np.float64], NDArray[np.float64]]:
    """Return (Si(x), Ci(x)) - sine and cosine integrals."""
    si_values, ci_values = sps.sici(_as_array(x))
    return _as_array(si_values), _as_array(ci_values)

binomial_coefficient(n, k)

Number of ways to choose k items from n.

Source code in src/cds2/special.py
282
283
284
def binomial_coefficient(n: int, k: int) -> float:
    """Number of ways to choose ``k`` items from ``n``."""
    return float(sps.comb(n, k, exact=True))