Skip to content

Commit 86ac2d9

Browse files
committed
Finish examples to 1.2.6, page 26
1 parent 0be8834 commit 86ac2d9

1 file changed

Lines changed: 35 additions & 5 deletions

File tree

test/test_combinatorica.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@
1313
"""
1414
)
1515

16-
# A number of examples from Implementing Discrete Mathematics by
17-
# Steven Skiena and
18-
# A number of examples from Computation Discrete Mathematics by
19-
# Sriram Pemmaraju and Steven Skiena.
16+
# A number of examples from:
17+
# * Implementing Discrete Mathematics by Steven Skiena and
18+
# * Computation Discrete Mathematics by Sriram Pemmaraju and Steven Skiena.
2019

2120
# Page numbers below come from the first book
2221

23-
2422
def test_combinatorica_permutations_1_1():
2523

2624
for str_expr, str_expected, message in (
@@ -241,6 +239,38 @@ def test_combinatorica_permutations_1_2():
241239
"{90, 90}",
242240
"StirlingSecond 1.2.4, Page 24",
243241
),
242+
(
243+
"SignaturePermutation[{1,3,2,4,5,6,7,8}]",
244+
"-1",
245+
"SignaturePermutation 1.2.5, Page 25",
246+
),
247+
(
248+
"SignaturePermutation[p] == SignaturePermutation[InversePermutation[p]]",
249+
"True",
250+
"A particular permutation has the same sign as its inverse 1.2.5, Page 25",
251+
),
252+
(
253+
"PermutationGroupQ[ Select [ Permutations[Range[4]], (SignaturePermutation[#]==1)&] ]",
254+
"True",
255+
"All permutations have the same sign as their inverse 1.2.5, Page 25",
256+
),
257+
(
258+
"Polya[Table[RotateRight[Range[8],i], {i, 8}], m]",
259+
"(4 m + 2 m ^ 2 + m ^ 4 + m ^ 8) / 8",
260+
"Polya counting resulting in polynomial 1.2.6, Page 25",
261+
),
262+
# MapAt not finished which is probably causing Poly to fail here...
263+
# (
264+
# "Polya[Automorphisms[Cycle[8]], m]",
265+
# "(4 m + 2 m ^ 2 + m ^ 4 + m ^ 8) / 8",
266+
# "Polya counting resulting in polynomial 1.2.6, Page 26",
267+
# ),
268+
(
269+
"Factor[(4 m + 2 m^2 + 5m^4 + 4m^5 + m^8)/16]",
270+
"m (1 + m) (4 - 2 m + 2 m ^ 2 + 3 m ^ 3 + m ^ 4 - m ^ 5 + m ^ 6) / 16",
271+
"Factor example in Polya polynomial 1.2.6, Page 26",
272+
),
273+
244274
):
245275
check_evaluation(str_expr, str_expected, message)
246276

0 commit comments

Comments
 (0)