math::special(3tcl)
π math::special β the Tcl Math Library glow-up π
okay bestie, so this is math::special(3tcl), straight out of the Tcl Math Library, and it's genuinely one of the most iconic pages in the whole collection. buckle up, because there's a LOT of math here and every single crumb matters. π§β¨
β¨ NAME β¨
math::special β Special mathematical functions π
πΈ SYNOPSIS πΈ
package require Tcl ?8.5 9?
package require math::special ?0.5.3?
::math::special::eulerNumber index
::math::special::bernoulliNumber index
::math::special::Beta x y
::math::special::incBeta a b x
::math::special::regIncBeta a b x
::math::special::Gamma x
::math::special::digamma x
::math::special::erf x
::math::special::erfc x
::math::special::invnorm p
::math::special::J0 x
::math::special::J1 x
::math::special::Jn n x
::math::special::J1/2 x
::math::special::J-1/2 x
::math::special::I_n x
::math::special::cn u k
::math::special::dn u k
::math::special::sn u k
::math::special::elliptic_K k
::math::special::elliptic_E k
::math::special::exponential_Ei x
::math::special::exponential_En n x
::math::special::exponential_li x
::math::special::exponential_Ci x
::math::special::exponential_Si x
::math::special::exponential_Chi x
::math::special::exponential_Shi x
::math::special::fresnel_C x
::math::special::fresnel_S x
::math::special::sinc x
::math::special::legendre n
::math::special::chebyshev n
::math::special::laguerre alpha n
::math::special::hermite n
π¦ DESCRIPTION π¦
So this package is literally the special functions package β like, the ones that get their own name in math because they're too famous to just be a normal formula, yk? the Gamma function, the Bessel functions, all of that. π
Every function here has a procedure that carries its name β well, close approximation of its name, bestie, don't come for the naming conventions. π Here's the whole squad:
J0β the zeroth-order Bessel function of the first kind πJ1β the first-order Bessel function of the first kind πJnβ the nth-order Bessel function of the first kind πJ1/2β the half-order Bessel function of the first kind πJ-1/2β the minus-half-order Bessel function of the first kind πI_nβ the modified Bessel function of the first kind of order n πGammaβ the Gamma function, pluserfanderfcfor the error function and the complementary error function β¨fresnel_Candfresnel_Sβ the Fresnel integrals πelliptic_Kandelliptic_Eβ the complete elliptic integrals π₯exponent_Eiand the other functions related to the so-called exponential integrals π₯legendre,hermiteβ some of the classical orthogonal polynomials π
π OVERVIEW π
Okay so the original page has this whole table, and I'm gonna walk you through every single row because the details are the moment, periodt. For each family I'm giving you the function, the domain of the argument x, the parameters, and the error bound. π
π§‘ Bessel
J0,J1,Jn- Domain x: all of R
- Parameter:
n = integer - Error bound:
< 1.0e-8β and that holds for|x|<20, n<20
J1/2,J-1/2,I_nβ wait, hold up, these are two different rows, lemme split them π«ΆJ1/2,J-1/2- Domain x:
x > 0 - Parameter:
n = integer - Error bound: exact (yes bestie, EXACT, she ate and left no crumbs)
- Domain x:
I_n- Domain x: all of R
- Parameter:
n = integer - Error bound:
< 1.0e-6
π₯ Elliptic functions
cn- Domain x:
0 <= x <= 1 - Parameter:
--(none) - Error bound:
< 1.0e-10
- Domain x:
dn- Domain x:
0 <= x <= 1 - Parameter:
--(none) - Error bound:
< 1.0e-10
- Domain x:
sn- Domain x:
0 <= x <= 1 - Parameter:
--(none) - Error bound:
< 1.0e-10
- Domain x:
π₯β‘οΈ Elliptic integrals
K- Domain x:
0 <= x < 1 - Parameter:
--(none) - Error bound:
< 1.0e-6
- Domain x:
E- Domain x:
0 <= x < 1 - Parameter:
--(none) - Error bound:
< 1.0e-6
- Domain x:
π Error functions
erf- Domain x: (not specified)
- Parameter:
--(none) - Error bound: (not specified)
erfc- Domain x: (not specified)
- Parameter:
--(none) - Error bound: (not specified)
π Inverse normal distribution
invnorm- Domain x:
0 < x < 1 - Parameter:
--(none) - Error bound:
< 1.2e-9
- Domain x:
π₯ Exponential integrals
Ei- Domain x:
x != 0 - Parameter:
--(none) - Error bound:
< 1.0e-10 (relative)
- Domain x:
En- Domain x:
x > 0 - Parameter:
--(none) - Error bound: as
Ei
- Domain x:
li- Domain x:
x > 0 - Parameter:
--(none) - Error bound: as
Ei
- Domain x:
Chi- Domain x:
x > 0 - Parameter:
--(none) - Error bound:
< 1.0e-8
- Domain x:
Shi- Domain x:
x > 0 - Parameter:
--(none) - Error bound:
< 1.0e-8
- Domain x:
Ci- Domain x:
x > 0 - Parameter:
--(none) - Error bound:
< 2.0e-4
- Domain x:
Si- Domain x:
x > 0 - Parameter:
--(none) - Error bound:
< 2.0e-4
- Domain x:
π Fresnel integrals
C- Domain x: all of R
- Parameter:
--(none) - Error bound:
< 2.0e-3
S- Domain x: all of R
- Parameter:
--(none) - Error bound:
< 2.0e-3
π general
Beta- Domain x: (see
Gamma) - Parameter:
--(none) - Error bound:
< 1.0e-9
- Domain x: (see
Gamma- Domain x:
x != 0,-1, -2, ... - Parameter:
--(none) - Error bound:
< 1.0e-9
- Domain x:
incBeta- Domain x: (not specified)
- Parameter:
a, b > 0 - Error bound:
< 1.0e-9
regIncBeta- Domain x: (not specified)
- Parameter:
a, b > 0 - Error bound:
< 1.0e-9
digamma- Domain x:
x != 0,-1 -2, ... - Parameter:
--(none) - Error bound:
< 1.0e-9
- Domain x:
sinc- Domain x: all of R
- Parameter:
--(none) - Error bound: exact
π orthogonal polynomials
Legendre- Domain x: all of R
- Parameter:
n = 0,1,... - Error bound: exact
Chebyshev- Domain x: all of R
- Parameter:
n = 0,1,... - Error bound: exact
Laguerre- Domain x: all of R
- Parameter:
n = 0,1,..., andalpha el. R - Error bound: exact
Hermite- Domain x: all of R
- Parameter:
n = 0,1,... - Error bound: exact
β οΈ note bestie: some of those error bounds are estimated β because there was literally no "formal" bound available with the implemented approximation method. and some of them hold for the auxiliary functions used for estimating the primary functions. so, yk, read them with that in mind. π«Ά
π the ones that are MISSING
not everything made it to the party, and the original is very upfront about it. the following well-known functions are currently missing from the package:
- Bessel functions of the second kind (
Y_n,K_n) π - Bessel functions of arbitrary order β and hence the Airy functions π
- Chebyshev polynomials of the second kind (
U_n) π₯² - The incomplete gamma function π
more parts coming, don't go anywhere bestie π β¨
β¨ PROCEDURES β¨
okay bestie, here's the whole menu of public procedures this package serves up π
::math::special::eulerNumber indexβ hands you the index'th Euler number (heads up: these are integer values, no decimals here). these numbers get big fast, so only a limited set of them is available.int indexβ which number you want back (should be between0and54)
::math::special::bernoulliNumber indexβ returns the index'th Bernoulli number. same deal as above, the values blow up quick, so only a limited amount exists.int indexβ index of the number you want (should be between0and52)
::math::special::Beta x yβ computes the Beta function for the argumentsxandyβ¨float xβ first argument for the Beta functionfloat yβ second argument for the Beta function
::math::special::incBeta a b xβ computes the incomplete Beta function for argumentxwith parametersaandbfloat aβ first parameter for the incomplete Beta function,a > 0float bβ second parameter for the incomplete Beta function,b > 0float xβ argument for the incomplete Beta function
::math::special::regIncBeta a b xβ computes the regularized incomplete Beta function for argumentxwith parametersaandbfloat aβ first parameter for the incomplete Beta function,a > 0float bβ second parameter for the incomplete Beta function,b > 0float xβ argument for the regularized incomplete Beta function
::math::special::Gamma xβ computes the Gamma function for argumentxπfloat xβ argument for the Gamma function
::math::special::digamma xβ computes the digamma function (that's psi, iykyk) for argumentxfloat xβ argument for the digamma function
::math::special::erf xβ computes the error function for argumentxfloat xβ argument for the error function
::math::special::erfc xβ computes the complementary error function for argumentxfloat xβ argument for the complementary error function
::math::special::invnorm pβ computes the inverse of the normal distribution function for argumentpfloat pβ argument for the inverse normal distribution function (pmust be greater than0and lower than1)
::math::special::J0 xβ computes the zeroth-order Bessel function of the first kind for the argumentxfloat xβ argument for the Bessel function
::math::special::J1 xβ computes the first-order Bessel function of the first kind for the argumentxfloat xβ argument for the Bessel function
::math::special::Jn n xβ computes the nth-order Bessel function of the first kind for the argumentxinteger nβ order of the Bessel functionfloat xβ argument for the Bessel function
::math::special::J1/2 xβ computes the half-order Bessel function of the first kind for the argumentxfloat xβ argument for the Bessel function
::math::special::J-1/2 xβ computes the minus-half-order Bessel function of the first kind for the argumentxfloat xβ argument for the Bessel function
::math::special::I_n xβ computes the modified Bessel function of the first kind of order n for the argumentxint xβ positive integer order of the functionfloat xβ argument for the function
::math::special::cn u kβ computes the elliptic function cn for the argumentuand parameterk.float uβ argument for the functionfloat kβ parameter
::math::special::dn u kβ computes the elliptic function dn for the argumentuand parameterk.float uβ argument for the functionfloat kβ parameter
::math::special::sn u kβ computes the elliptic function sn for the argumentuand parameterk.float uβ argument for the functionfloat kβ parameter
::math::special::elliptic_K kβ computes the complete elliptic integral of the first kind for the argumentkfloat kβ argument for the function
::math::special::elliptic_E kβ computes the complete elliptic integral of the second kind for the argumentkfloat kβ argument for the function
::math::special::exponential_Ei xβ computes the exponential integral of the second kind for the argumentxfloat xβ argument for the function (x != 0)
::math::special::exponential_En n xβ computes the exponential integral of the first kind for the argumentxand order nint nβ order of the integral (n >= 0)float xβ argument for the function (x >= 0)
::math::special::exponential_li xβ computes the logarithmic integral for the argumentxfloat xβ argument for the function (x > 0)
::math::special::exponential_Ci xβ computes the cosine integral for the argumentxfloat xβ argument for the function (x > 0)
::math::special::exponential_Si xβ computes the sine integral for the argumentxfloat xβ argument for the function (x > 0)
::math::special::exponential_Chi xβ computes the hyperbolic cosine integral for the argumentxfloat xβ argument for the function (x > 0)
::math::special::exponential_Shi xβ computes the hyperbolic sine integral for the argumentxfloat xβ argument for the function (x > 0)
::math::special::fresnel_C xβ computes the Fresnel cosine integral for real argument xfloat xβ argument for the function
::math::special::fresnel_S xβ computes the Fresnel sine integral for real argument xfloat xβ argument for the function
::math::special::sinc xβ computes the sinc function for real argument xfloat xβ argument for the function
::math::special::legendre nβ returns the Legendre polynomial of degree n (peep THE ORTHOGONAL POLYNOMIALS below π)int nβ degree of the polynomial
::math::special::chebyshev nβ returns the Chebyshev polynomial of degree n (first kind, obviously)int nβ degree of the polynomial
::math::special::laguerre alpha nβ returns the Laguerre polynomial of degree n with parameter alphafloat alphaβ parameter of the Laguerre polynomialint nβ degree of the polynomial
::math::special::hermite nβ returns the Hermite polynomial of degree nint nβ degree of the polynomial
π¦ THE ORTHOGONAL POLYNOMIALS π¦
so for the classical families of orthogonal polynomials, this package is lowkey leaning on the math::polynomials package. if you wanna actually evaluate the polynomial at some coordinate, you use the evalPolyn command like this:
set leg2 [::math::special::legendre 2]
puts "Value at x=$x: [::math::polynomials::evalPolyn $leg2 $x]"
and fr fr, the return value from legendre and the other commands is actually the definition of the corresponding polynomial as it's used in that package. that's the whole vibe β¨
π§ REMARKS ON THE IMPLEMENTATION π§
ngl you should know that the actual implementation of J0 and J1 depends on straightforward Gaussian quadrature formulas. the (absolute) accuracy of the results is of the order 1.0e-4 or better. the main reason they got implemented like that was that it was fast to do (the formulas are simple) and the computations are fast too. efficient queen π
the implementation of J1/2 does not suffer from this: this function can be expressed exactly in terms of elementary functions. no approximation, just math being iconic π
the functions J0 and J1 are the ones you'll encounter most frequently in practice.
the computation of I_n is based on Miller's algorithm for computing the minimal function from recurrence relations.
the computation of the Gamma and Beta functions relies on the combinatorics package, whereas that of the error functions relies on the statistics package.
the computation of the complete elliptic integrals uses the AGM algorithm.
much information about these functions can be found in:
Abramowitz and Stegun: Handbook of Mathematical Functions (Dover, ISBN 486-61272-4)
π BUGS, IDEAS, FEEDBACK π
okay so this document, and the package it describes, will undoubtedly contain bugs and other problems. no cap, nothing is perfect π please report such in the category math :: special of the Tcllib Trackers at [http://core.tcl.tk/tcllib/reportlist].
please also report any ideas for enhancements you may have for either the package and/or the documentation. we wanna hear them π«Ά
when proposing code changes, please provide unified diffs, i.e the output of diff -u.
note further that attachments are strongly preferred over inlined patches. attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar. (yes, the left-most one, don't make me come find you π)
πΈ KEYWORDS πΈ
Bessel functions, error function, math, special functions
π CATEGORY π
Mathematics
π COPYRIGHT π
Copyright (c) 2004 Arjen Markus <arjenmarkus@users.sourceforge.net>
and that's a wrap bestie!! this whole thing lives in tcllib, version 0.5.4, and it's the math::special(3tcl) page π go forth and compute your special functions, you absolute main character βπ
π¦ where this page comes from
- debian trixie: tcllib 2.0+dfsg-4 Β· Tcl
- ubuntu questing: tcllib 2.0+dfsg-4
- ubuntu resolute: tcllib 2.0+dfsg-5 Β· Tcl
- ubuntu stonking: tcllib 2.0+dfsg-6 Β· Tcl
- Copyright (c) 2004 Arjen Markus <arjenmarkus@users\&.sourceforge\&.net>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms