math::special(n)
okay bestie, pull up a chair ๐ซถ you just opened the math::special(n) page from the Tcl Math Library and honestly? it's giving "secret math treasure chest" โจ we're talking Gamma functions, Bessel functions, elliptic everything. no cap, this one's a whole journey, so let's go ๐
๐ NAME ๐
math::special โ special mathematical functions ๐งฎ๐
โจ SYNOPSIS โจ
first things first, you gotta actually load the thing, so:
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
look at that list. it's long, it's iconic, it ate ๐
๐ธ DESCRIPTION ๐ธ
so this package implements a bunch of the so-called special functions โ like the Gamma function, the Bessel functions and such. the classics, the icons, the ones your math professor whispers about ๐ซ
each function is implemented by a procedure that bears its name (wellโฆ in close approximation, we love a loose naming convention ๐):
J0for the zeroth-order Bessel function of the first kindJ1for the first-order Bessel function of the first kindJnfor the nth-order Bessel function of the first kindJ1/2for the half-order Bessel function of the first kindJ-1/2for the minus-half-order Bessel function of the first kindI_nfor the modified Bessel function of the first kind of order nGammafor the Gamma function,erfanderfcfor the error function and the complementary error functionfresnel_Candfresnel_Sfor the Fresnel integralselliptic_Kandelliptic_E(complete elliptic integrals)exponent_Eiand other functions related to the so-called exponential integralslegendre,hermite: some of the classical orthogonal polynomials.
๐ฆ OVERVIEW ๐ฆ
here's the vibe check for the whole fam ๐ซถ โ for every function we've got the domain for the argument, the values for the parameters, and the error bounds. (the original lays this out in one big table; we're serving it up family by family instead, but every single number is exactly the same, promise ๐ค)
๐ Bessel
J0,J1,Jnโ domain x: all of R ยท parameter:n = integerยท error bound:< 1.0e-8(that's for|x|<20,n<20)J1/2,J-1/2โ domain x:x > 0ยท parameter:n = integerยท error bound: exact ๐ฏI_nโ domain x: all of R ยท parameter:n = integerยท error bound:< 1.0e-6
๐ธ Elliptic functions
cnโ domain x:0 <= x <= 1ยท parameter:--ยท error bound:< 1.0e-10dnโ domain x:0 <= x <= 1ยท parameter:--ยท error bound:< 1.0e-10snโ domain x:0 <= x <= 1ยท parameter:--ยท error bound:< 1.0e-10
๐ Elliptic integrals
Kโ domain x:0 <= x < 1ยท parameter:--ยท error bound:< 1.0e-6Eโ domain x:0 <= x < 1ยท parameter:--ยท error bound:< 1.0e-6
๐ Error functions
erfโ domain x: (nothing listed) ยท parameter:--ยท error bound: (nothing listed)erfcโ domain x: (nothing listed) ยท parameter:--ยท error bound: (nothing listed)
not us with the blank cells ๐ the original table just doesn't fill these in, so we're not filling them in either. facts over vibes.
๐ฎ Inverse normal distribution
invnormโ domain x:0 < x < 1ยท parameter:--ยท error bound:< 1.2e-9
โญ Exponential integrals
Eiโ domain x:x != 0ยท parameter:--ยท error bound:< 1.0e-10(relative)Enโ domain x:x > 0ยท parameter:--ยท error bound: asEiliโ domain x:x > 0ยท parameter:--ยท error bound: asEiChiโ domain x:x > 0ยท parameter:--ยท error bound:< 1.0e-8Shiโ domain x:x > 0ยท parameter:--ยท error bound:< 1.0e-8Ciโ domain x:x > 0ยท parameter:--ยท error bound:< 2.0e-4Siโ domain x:x > 0ยท parameter:--ยท error bound:< 2.0e-4
๐ฆ Fresnel integrals
Cโ domain x: all of R ยท parameter:--ยท error bound:< 2.0e-3Sโ domain x: all of R ยท parameter:--ยท error bound:< 2.0e-3
๐ง general
Betaโ domain x: (see Gamma) ยท parameter:--ยท error bound:< 1.0e-9Gammaโ domain x:x != 0,-1, -2, ...ยท parameter:--ยท error bound:< 1.0e-9incBetaโ domain x: (nothing listed) ยท parameter:a, b > 0ยท error bound:< 1.0e-9regIncBetaโ domain x: (nothing listed) ยท parameter:a, b > 0ยท error bound:< 1.0e-9digammaโ domain x:x != 0,-1 -2, ...ยท parameter: (nothing listed) ยท error bound:< 1.0e-9sincโ domain x: all of R ยท parameter:--ยท 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,...,alpha el. Rยท error bound: exact ๐ฏHermiteโ domain x: all of R ยท parameter:n = 0,1,...ยท error bound: exact ๐ฏ
Note: some of those error bounds are estimated, because no "formal" bounds were available with the implemented approximation method. the others hold for the auxiliary functions used for estimating the primary functions. so likeโฆ mostly trustworthy, occasionally vibes-based, we're being honest about it ๐ญ
and now the sad part bestie ๐ฅฒ โ 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
okay that's the tea so far โ part 2 is coming, so don't go anywhere, we're not done yet โ more special-function goodness loadingโฆ ๐โจ
โจ PROCEDURES โจ
Okay bestie, this is the main character section ๐ the package defines the following public procedures:
::math::special::eulerNumber index
Returns the index'th Euler number โ and note that these are integer values, no decimals in sight. The catch? These numbers grow fast, like full-blowup fast ๐ญ, so only a limited number of them are even available.
int indexโ index of the number to be returned (should be between0and54)
::math::special::bernoulliNumber index
Returns the index'th Bernoulli number. Same situation as above โ the numbers get big super quickly, so only a limited number are available.
int indexโ index of the number to be returned (should be between0and52)
::math::special::Beta x y
Computes the Beta function for arguments x and y.
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 argument x with parameters a and b.
float 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 argument x with parameters a and b.
float 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 argument x.
float xโ argument for the Gamma function
::math::special::digamma x
Computes the digamma function (psi) for argument x.
float xโ argument for the digamma function
::math::special::erf x
Computes the error function for argument x.
float xโ argument for the error function
::math::special::erfc x
Computes the complementary error function for argument x.
float xโ argument for the complementary error function
::math::special::invnorm p
Computes the inverse of the normal distribution function for argument p.
float 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 argument x.
float xโ argument for the Bessel function
::math::special::J1 x
Computes the first-order Bessel function of the first kind for the argument x.
float xโ argument for the Bessel function
::math::special::Jn n x
Computes the nth-order Bessel function of the first kind for the argument x.
integer 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 argument x.
float 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 argument x.
float 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 argument x.
int xโ positive integer order of the functionfloat xโ argument for the function
ngl bestie, the manpage really does call both of these x ๐ we do not make the rules, we just report them faithfully.
::math::special::cn u k
Computes the elliptic function cn for the argument u and parameter k.
float uโ argument for the functionfloat kโ parameter
::math::special::dn u k
Computes the elliptic function dn for the argument u and parameter k.
float uโ argument for the functionfloat kโ parameter
::math::special::sn u k
Computes the elliptic function sn for the argument u and parameter k.
float uโ argument for the functionfloat kโ parameter
::math::special::elliptic_K k
Computes the complete elliptic integral of the first kind for the argument k.
float kโ argument for the function
::math::special::elliptic_E k
Computes the complete elliptic integral of the second kind for the argument k.
float kโ argument for the function
::math::special::exponential_Ei x
Computes the exponential integral of the second kind for the argument x.
float xโ argument for the function (x != 0)
::math::special::exponential_En n x
Computes the exponential integral of the first kind for the argument x and order n.
int 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 argument x.
float xโ argument for the function (x > 0)
::math::special::exponential_Ci x
Computes the cosine integral for the argument x.
float xโ argument for the function (x > 0)
::math::special::exponential_Si x
Computes the sine integral for the argument x.
float xโ argument for the function (x > 0)
::math::special::exponential_Chi x
Computes the hyperbolic cosine integral for the argument x.
float xโ argument for the function (x > 0)
::math::special::exponential_Shi x
Computes the hyperbolic sine integral for the argument x.
float xโ argument for the function (x > 0)
::math::special::fresnel_C x
Computes the Fresnel cosine integral for real argument x.
float xโ argument for the function
::math::special::fresnel_S x
Computes the Fresnel sine integral for real argument x.
float xโ argument for the function
::math::special::sinc x
Computes the sinc function for real argument x.
float xโ argument for the function
::math::special::legendre n
Returns the Legendre polynomial of degree n (peep THE ORTHOGONAL POLYNOMIALS down below ๐).
int nโ degree of the polynomial
::math::special::chebyshev n
Returns the Chebyshev polynomial of degree n (of the first kind).
int nโ degree of the polynomial
::math::special::laguerre alpha n
Returns the Laguerre polynomial of degree n with parameter alpha.
float alphaโ parameter of the Laguerre polynomialint nโ degree of the polynomial
::math::special::hermite n
Returns the Hermite polynomial of degree n.
int nโ degree of the polynomial
๐ฆ THE ORTHOGONAL POLYNOMIALS ๐ฆ
For dealing with the classical families of orthogonal polynomials, the package leans on the math::polynomials package. So to 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 here's the little plot twist ๐ the return value from legendre and the other commands is actually the definition of the corresponding polynomial, as used in that package.
๐ธ REMARKS ON THE IMPLEMENTATION ๐ธ
Gonna be real with you, some of this is a bit "it's giving approximation" and you should know about it:
- Real talk: the actual implementation of
J0andJ1depends on straightforward Gaussian quadrature formulas. The (absolute) accuracy of the results is of the order1.0e-4or better. The main reason they were implemented like that was that it was fast to do (the formulas are simple) and the computations are fast too. Efficiency slay ๐ - The implementation of
J1/2does not suffer from this โ this function can be expressed exactly in terms of elementary functions. No approximation era. โจ - The functions
J0andJ1are the ones you will encounter most frequently in practice. - The computation of
I_nis based on Miller's algorithm for computing the minimal function from recurrence relations. - The computation of the Gamma and Beta functions relies on the
combinatoricspackage, whereas that of the error functions relies on thestatisticspackage. - 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 ๐
This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category math :: special of the Tcllib Trackers http://core.tcl.tk/tcllib/reportlist. Please also report any ideas for enhancements you may have for either package and/or documentation. We want the feedback, fr fr ๐ซถ
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.
โญ 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 was tcllib version 0.5.4, page math::special(n), and honestly? She ate. Go compute something iconic. โจ๐
๐ฆ where this page comes from
- fedora 43: tcllib 2.0-3.fc43 ยท TCL
- fedora 44: tcllib 2.0-4.fc44 ยท TCL
- nixos 26.05: tcllib 2.0
- nixpkgs unstable: tcllib 2.0
- 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