Impressum/Kontaktparent nodes: implemented functions

Binomial

testAplBinominal
"http://www.microapl.co.uk/apl_help/ch_020_020_260.htm"

"In its two-argument form, with positive arguments, !! tells you how many different ways there are of selecting the number of items specified on the left from the population of items specified on the right. The order of items in each pair is ignored. So if the population of four consisted of the letters A B C D, the 6 possible combinations of 2 letters would be: AB AC AD BC BD CD. The combination BA would be regarded as the same as AB."

| table1 table2 result |

"Number of unique pairs from a population of 4"
self assert: 6 asApl = (2 asApl aplBinominal:4).

"Number of groups of three from a population of 20"
self assert: 1140 asApl = (3 asApl aplBinominal:20).

"Number of pairs from a population of 6 12 20 respectively"
self assert: #(15 66 190) asApl = (2 asApl aplBinominal:#(6 12 20)).

table1 := 6 aplInterval aplReshape:#(2 3).
table2 := table1 * 3.
result := #(3 15 84 495 3003 18564)aplReshape:#(2 3).

"TABLE1 is table of group sizes, TABLE2 is table of populations"
self assert: result = (table1 aplBinominal: table2).


"Other cases, such as negative or non-integer arguments, are also catered for. The various results that can be obtained are:

LeftArg RightArg Right-Left Result
+ve +ve +ve (!RIGHT)/(!LEFT)*!RIGHT-LEFT
+ve +ve -ve 0
+ve -ve -ve (-1^LEFT)*LEFT!LEFT-RIGHT+1
-ve +ve +ve 0
-ve -ve +ve (-1^RIGHT-LEFT)*(|RIGHT+1)!(|LEFT+1)
-ve -ve -ve 0
"