math::combinatorics(3tcl) | Tcl Math Library | math::combinatorics(3tcl) |
math::combinatorics - Combinatorial functions in the Tcl Math Library
package require Tcl 8.2
package require math ?1.2.3?
::math::ln_Gamma z
::math::factorial x
::math::choose n k
::math::Beta z w
The math package contains implementations of several functions useful in combinatorial problems.
The Gamma function is defined as the improper integral from zero to positive infinity of
t**(x-1)*exp(-t) dt
The approximation used in the Tcl Math Library is from Lanczos, ISIAM J. Numerical Analysis, series B, volume 1, p. 86. For "x > 1", the absolute error of the result is claimed to be smaller than 5.5*10**-10 -- that is, the resulting value of Gamma when
exp( ln_Gamma( x) )
For integer x, 0 <= x <= 12, an exact integer result is returned.
For integer x, 13 <= x <= 21, an exact floating-point result is returned on machines with IEEE floating point.
For integer x, 22 <= x <= 170, the result is exact to 1 ULP.
For real x, x >= 0, the result is approximated by computing Gamma(x+1) using the ::math::ln_Gamma function, and the result is expected to be precise to better than nine significant figures.
It is an error to present x <= -1 or x > 170, or a value of x that is not numeric.
C(n,k) = n! / k! (n-k)!
Integer results are exact up to at least n = 34. Floating point results are precise to better than nine significant figures.
Beta(z,w) = Beta(w,z) = Gamma(z) * Gamma(w) / Gamma(z+w)
This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category math 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.
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.
Mathematics
1.2.3 | tcllib |