1math::combinatorics(n) Tcl Math Library math::combinatorics(n)
2
3
4
5______________________________________________________________________________
6
8 math::combinatorics - Combinatorial functions in the Tcl Math Library
9
11 package require Tcl 8.2
12
13 package require math ?1.2.3?
14
15 ::math::ln_Gamma z
16
17 ::math::factorial x
18
19 ::math::choose n k
20
21 ::math::Beta z w
22
23______________________________________________________________________________
24
26 The math package contains implementations of several functions useful
27 in combinatorial problems.
28
30 ::math::ln_Gamma z
31 Returns the natural logarithm of the Gamma function for the
32 argument z.
33
34 The Gamma function is defined as the improper integral from zero
35 to positive infinity of
36
37
38 t**(x-1)*exp(-t) dt
39
40
41 The approximation used in the Tcl Math Library is from Lanczos, ISIAM
42 J. Numerical Analysis, series B, volume 1, p. 86. For "x > 1", the
43 absolute error of the result is claimed to be smaller than 5.5*10**-10
44 -- that is, the resulting value of Gamma when
45
46
47 exp( ln_Gamma( x) )
48
49
50 is computed is expected to be precise to better than nine sig‐
51 nificant figures.
52
53 ::math::factorial x
54 Returns the factorial of the argument x.
55
56 For integer x, 0 <= x <= 12, an exact integer result is
57 returned.
58
59 For integer x, 13 <= x <= 21, an exact floating-point result is
60 returned on machines with IEEE floating point.
61
62 For integer x, 22 <= x <= 170, the result is exact to 1 ULP.
63
64 For real x, x >= 0, the result is approximated by computing
65 Gamma(x+1) using the ::math::ln_Gamma function, and the result
66 is expected to be precise to better than nine significant fig‐
67 ures.
68
69 It is an error to present x <= -1 or x > 170, or a value of x
70 that is not numeric.
71
72 ::math::choose n k
73 Returns the binomial coefficient C(n, k)
74
75
76 C(n,k) = n! / k! (n-k)!
77
78
79 If both parameters are integers and the result fits in 32 bits,
80 the result is rounded to an integer.
81
82 Integer results are exact up to at least n = 34. Floating point
83 results are precise to better than nine significant figures.
84
85 ::math::Beta z w
86 Returns the Beta function of the parameters z and w.
87
88
89 Beta(z,w) = Beta(w,z) = Gamma(z) * Gamma(w) / Gamma(z+w)
90
91
92 Results are returned as a floating point number precise to bet‐
93 ter than nine significant digits provided that w and z are both
94 at least 1.
95
97 This document, and the package it describes, will undoubtedly contain
98 bugs and other problems. Please report such in the category math of
99 the Tcllib Trackers [http://core.tcl.tk/tcllib/reportlist]. Please
100 also report any ideas for enhancements you may have for either package
101 and/or documentation.
102
103 When proposing code changes, please provide unified diffs, i.e the out‐
104 put of diff -u.
105
106 Note further that attachments are strongly preferred over inlined
107 patches. Attachments can be made by going to the Edit form of the
108 ticket immediately after its creation, and then using the left-most
109 button in the secondary navigation bar.
110
112 Mathematics
113
114
115
116tcllib 1.2.3 math::combinatorics(n)