math::special(3tcl)

πŸ“¦
version 2.0 Β· 3 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– 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, plus erf and erfc for the error function and the complementary error function ✨
  • fresnel_C and fresnel_S β€” the Fresnel integrals 🌊
  • elliptic_K and elliptic_E β€” the complete elliptic integrals πŸ₯š
  • exponent_Ei and 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)
  • 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
  • dn
    • Domain x: 0 <= x <= 1
    • Parameter: -- (none)
    • Error bound: < 1.0e-10
  • sn
    • Domain x: 0 <= x <= 1
    • Parameter: -- (none)
    • Error bound: < 1.0e-10

πŸ₯šβž‘️ Elliptic integrals

  • K
    • Domain x: 0 <= x < 1
    • Parameter: -- (none)
    • Error bound: < 1.0e-6
  • E
    • Domain x: 0 <= x < 1
    • Parameter: -- (none)
    • Error bound: < 1.0e-6

😭 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

πŸ”₯ Exponential integrals

  • Ei
    • Domain x: x != 0
    • Parameter: -- (none)
    • Error bound: < 1.0e-10 (relative)
  • En
    • Domain x: x > 0
    • Parameter: -- (none)
    • Error bound: as Ei
  • li
    • Domain x: x > 0
    • Parameter: -- (none)
    • Error bound: as Ei
  • Chi
    • Domain x: x > 0
    • Parameter: -- (none)
    • Error bound: < 1.0e-8
  • Shi
    • Domain x: x > 0
    • Parameter: -- (none)
    • Error bound: < 1.0e-8
  • Ci
    • Domain x: x > 0
    • Parameter: -- (none)
    • Error bound: < 2.0e-4
  • Si
    • Domain x: x > 0
    • Parameter: -- (none)
    • Error bound: < 2.0e-4

🌊 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
  • Gamma
    • Domain x: x != 0,-1, -2, ...
    • Parameter: -- (none)
    • Error bound: < 1.0e-9
  • 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
  • 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,..., and alpha 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 between 0 and 54)
  • ::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 between 0 and 52)
  • ::math::special::Beta x y β€” computes the Beta function for the arguments x and y ✨
    • float x β€” first argument for the Beta function
    • float 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 > 0
    • float b β€” second parameter for the incomplete Beta function, b > 0
    • float 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 > 0
    • float b β€” second parameter for the incomplete Beta function, b > 0
    • float 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 (that's psi, iykyk) 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 (p must be greater than 0 and lower than 1)
  • ::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 function
    • float 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 function
    • float x β€” argument for the function
  • ::math::special::cn u k β€” computes the elliptic function cn for the argument u and parameter k.
    • float u β€” argument for the function
    • float k β€” parameter
  • ::math::special::dn u k β€” computes the elliptic function dn for the argument u and parameter k.
    • float u β€” argument for the function
    • float k β€” parameter
  • ::math::special::sn u k β€” computes the elliptic function sn for the argument u and parameter k.
    • float u β€” argument for the function
    • float 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 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 alpha
    • float alpha β€” parameter of the Laguerre polynomial
    • int 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 πŸ¦‹

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 (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