math::special(n)

๐Ÿ“ฆ
version 2.0 ยท 2 versions
, in fedora 43, fedora 44, nixos 26.05, nixpkgs unstable

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 ๐Ÿ™ˆ):

  • J0 for the zeroth-order Bessel function of the first kind
  • J1 for the first-order Bessel function of the first kind
  • Jn for the nth-order Bessel function of the first kind
  • J1/2 for the half-order Bessel function of the first kind
  • J-1/2 for the minus-half-order Bessel function of the first kind
  • I_n for the modified Bessel function of the first kind of order n
  • Gamma for the Gamma function, erf and erfc for the error function and the complementary error function
  • fresnel_C and fresnel_S for the Fresnel integrals
  • elliptic_K and elliptic_E (complete elliptic integrals)
  • exponent_Ei and other functions related to the so-called exponential integrals
  • legendre, 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-10
  • dn โ€” domain x: 0 <= x <= 1 ยท parameter: -- ยท error bound: < 1.0e-10
  • sn โ€” domain x: 0 <= x <= 1 ยท parameter: -- ยท error bound: < 1.0e-10

๐ŸŽ€ Elliptic integrals

  • K โ€” domain x: 0 <= x < 1 ยท parameter: -- ยท error bound: < 1.0e-6
  • E โ€” 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: as Ei
  • li โ€” domain x: x > 0 ยท parameter: -- ยท error bound: as Ei
  • Chi โ€” domain x: x > 0 ยท parameter: -- ยท error bound: < 1.0e-8
  • Shi โ€” domain x: x > 0 ยท parameter: -- ยท error bound: < 1.0e-8
  • Ci โ€” domain x: x > 0 ยท parameter: -- ยท error bound: < 2.0e-4
  • Si โ€” domain x: x > 0 ยท parameter: -- ยท error bound: < 2.0e-4

๐Ÿฆ‹ Fresnel integrals

  • C โ€” domain x: all of R ยท parameter: -- ยท error bound: < 2.0e-3
  • S โ€” domain x: all of R ยท parameter: -- ยท error bound: < 2.0e-3

๐Ÿงš general

  • Beta โ€” domain x: (see Gamma) ยท parameter: -- ยท error bound: < 1.0e-9
  • Gamma โ€” domain x: x != 0,-1, -2, ... ยท parameter: -- ยท error bound: < 1.0e-9
  • incBeta โ€” domain x: (nothing listed) ยท parameter: a, b > 0 ยท error bound: < 1.0e-9
  • regIncBeta โ€” domain x: (nothing listed) ยท parameter: a, b > 0 ยท error bound: < 1.0e-9
  • digamma โ€” domain x: x != 0,-1 -2, ... ยท parameter: (nothing listed) ยท error bound: < 1.0e-9
  • sinc โ€” 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 between 0 and 54)

::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 between 0 and 52)

::math::special::Beta x y

Computes the Beta function for 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 (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 (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
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 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 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 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 ๐Ÿฆ‹

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 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 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/2 does not suffer from this โ€” this function can be expressed exactly in terms of elementary functions. No approximation era. โœจ
  • The functions J0 and J1 are the ones you will 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 ๐Ÿ’€

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