@@ -46,7 +46,16 @@ def test_combinatorica_permutations_1_1():
4646 " {d, b, c, a}, {d, c, a, b}, {d, c, b, a}}" ,
4747 "LexicographicPermuations, 1.1.1 Page 4" ,
4848 ),
49- # NthPermutation does not work
49+ (
50+ "Table[ NthPermutation[n, Range[4]], {n, 0, 23}]" ,
51+ "{{1, 2, 3, 4}, {1, 2, 4, 3}, {1, 3, 2, 4}, {1, 3, 4, 2}, "
52+ " {1, 4, 2, 3}, {1, 4, 3, 2}, {2, 1, 3, 4}, {2, 1, 4, 3}, "
53+ " {2, 3, 1, 4}, {2, 3, 4, 1}, {2, 4, 1, 3}, {2, 4, 3, 1}, "
54+ " {3, 1, 2, 4}, {3, 1, 4, 2}, {3, 2, 1, 4}, {3, 2, 4, 1}, "
55+ " {3, 4, 1, 2}, {3, 4, 2, 1}, {4, 1, 2, 3}, {4, 1, 3, 2}, "
56+ " {4, 2, 1, 3}, {4, 2, 3, 1}, {4, 3, 1, 2}, {4, 3, 2, 1}} " ,
57+ "slower method for computing permutations in lex order, 1.1.2, Page 6"
58+ ),
5059 (
5160 "Map[RankPermutation, Permutations[Range[4]]]" ,
5261 "Range[0, 23]" ,
@@ -146,13 +155,13 @@ def test_combinatorica_permutations_1_2():
146155 (
147156 "EquivalenceClasses[relation]" ,
148157 "{{1, 2, 3, 4}, {5}}" ,
149- "EquivalenceClasses, 1.2.3, Page 19"
158+ "EquivalenceClasses, 1.2.3, Page 19" ,
159+ ),
160+ (
161+ "PermutationGroupQ[{{1, 2, 3, 4}, {4, 2, 3, 1}}]" ,
162+ "True" ,
163+ "PermutationGroupQ, 1.2.3 Page 20" ,
150164 ),
151- # (
152- # "PermutationGroupQ[Range[4], {4, 2, 3, 1}]",
153- # "True",
154- # "PermutationGroupQ, 1.2.3 Page 20",
155- # ),
156165 (
157166 "ToCycles[Range[10]]" ,
158167 "{{1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}}" ,
@@ -198,6 +207,34 @@ def test_combinatorica_permutations_1_2():
198207 check_evaluation (str_expr , str_expected , message )
199208
200209
210+ def test_combinatorica_permutations_1_5 ():
211+
212+ # We include this earlier since the above in fact rely on KSubsets
213+ for str_expr , str_expected , message in (
214+ (
215+ "KSubsets[Range[5], 3]" ,
216+ "{{1, 2, 3}, {1, 2, 4}, {1, 2, 5}, {1, 3, 4}, {1, 3, 5}, "
217+ "{1, 4, 5}, {2, 3, 4}, {2, 3, 5}, {2, 4, 5}, {3, 4, 5}}" ,
218+ "KSubsets 1.5.5, Page 45" ,
219+ ),
220+ (
221+ "KSubsets[Range[3], 0]" ,
222+ "{ {} } " ,
223+ "KSubsets[0] == { {} }" ,
224+ ),
225+ (
226+ "KSubsets[Range[5], 1]" ,
227+ "{{1}, {2}, {3}, {4}, {5}}" ,
228+ "KSubsets[Range[n, 1] == Partition[n]" ,
229+ ),
230+ (
231+ "KSubsets[Range[5], 5]" ,
232+ "{Range[5]} " ,
233+ "KSubsets[l, k] == Length(l)" ,
234+ ),
235+ ):
236+ check_evaluation (str_expr , str_expected , message )
237+
201238def test_combinatorica_rest ():
202239
203240 # Permutation[3] doesn't work
0 commit comments