 ## 11.8 combinations: a small program and a testsuite   Page 385 of 800 Search internet

The combinations page defines a function (the 'combinations' function, also known as the binomial coefficient) and a test case. It also defines the rendering of the function such the function looks the same as it does in math books. A numbered version of the combinations.lgs source text is included below. Also see the original, unnumbered lgs file, the main pdf, and the document root.

     1	"";;0143BAB3BC67212340C9406BDB560819F3DCD4E859FC96F7B1C2B2BB0806
2	""P combinations
3
4	""R base
5
6	""D 0
7	(( " , " ))
8
9	""B
10	page ( ""N , ""C )
11	title "Combinations"
12	bib "
13	@techreport{appendix,
14	  author    = {A. U. Thor},
15	  year      = {2006},
16	  title     = {Combinations - appendix},
17	  institution={Logiweb},
18	  note      =
19	{\href{\lgwBlockRelay \lgwBlockThis /page/appendix.pdf}{%
20	\lgwBreakRelay \lgwBreakThis /page/appendix.pdf}}}
21	"
22	main text "
23	\title{Combinations}
24	\author{A. U. Thor}
25	\maketitle
26	\tableofcontents
27	\section{Combinations}
28	The number of combinations of size "[[ k ]]" from a set
29	of size "[[ n ]]" is given by the binomial coefficient
30	"[[ (( n , k )) = n factorial div k factorial
31	div ( n - k ) factorial ]]". A recursive definition
32	of "[[ (( n , k )) ]]" may be stated thus:
33	"[[[ value define (( n , k )) as if k = 0 then 1
34	else (( n - 1 , k - 1 )) * n div k end define ]]]"
35	As an example, we have "[[ ttst (( 4 , 2 )) = 6 end test ]]".
36	For details on how the binomial coefficient is rendered, see
37	\cite{appendix}.
38	\bibliography{./page}
39	"
40	appendix "
41	\title{Combinations - appendix}
42	\author{A. U. Thor}
43	\maketitle
44	\tableofcontents
45	\section{\TeX\ definitions}
46	\begin{statements}
47	\item "[[ tex show define (( n , k )) as "
48	\left( \begin{array}{l} "[ n ]"
49	\\ "[ k ]"
50	\end{array}\right)" end define ]]"
51	\end{statements}
52	"
53	end page
54
55
56
57   Page 385 of 800 Search logiweb.eu