From 9029bd567b7ca108c81c3874d1720e2b1b3bb4c3 Mon Sep 17 00:00:00 2001 From: rocky Date: Sat, 21 Dec 2024 21:19:59 -0500 Subject: [PATCH 1/6] More tests... but after we have MapAt in core merged --- .github/workflows/ubuntu.yml | 2 +- test/test_combinatorica_v09.py | 61 ++++++++++++++-------------------- test/test_combinatorica_v20.py | 12 ++++--- 3 files changed, 33 insertions(+), 42 deletions(-) diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 882a850..44b43ab 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -31,7 +31,7 @@ jobs: cd mathics-scanner/ pip install -e . cd .. - git clone https://github.com/Mathics3/mathics-core.git + git clone https://github.com/Mathics3/mathics-core.git --branch multi-dimensional-MapAt cd mathics-core/ remake -x develop remake -x install diff --git a/test/test_combinatorica_v09.py b/test/test_combinatorica_v09.py index 95a3205..f64b1da 100644 --- a/test/test_combinatorica_v09.py +++ b/test/test_combinatorica_v09.py @@ -281,8 +281,8 @@ def test_permutations_groups_1_2(): "(4 m + 2 m ^ 2 + m ^ 4 + m ^ 8) / 8", "Polya counting resulting in polynomial 1.2.6, Page 25", ), - # Automorphism is slow. So we reduce Cycle[8] given as the example in the - # book to Cycle[3]. + # Automorphism is slow. So we reduce Cycle[8] given as the + # example in the book to Cycle[3]. ( "Polya[Automorphisms[Cycle[3]], m]", "(2 m + 3 m ^ 2 + m ^ 3) / 6", @@ -585,41 +585,35 @@ def test_2_1_to_2_3(): check_evaluation(str_expr, str_expected, assert_fail_message) -# def test_combinatorica_3_1(): -# for str_expr, str_expected, message in ( -# ( -# "TableForm[ Edges[K[5]] ]", -# """ 0 1 1 1 1 - -# 1 0 1 1 1 - -# 1 1 0 1 1 - -# 1 1 1 0 1 - -# 1 1 1 1 0 -# """, -# "Adjancency Matrices 3.1.1, Page 82", -# ), -# ): -# check_evaluation(str_expr, str_expected, message) +def test_combinatorica_3_1(): + for str_expr, str_expected, message in ( + ( + "Edges[K[5]]", + "{{0, 1, 1, 1, 1}, " + "{1, 0, 1, 1, 1}, " + "{1, 1, 0, 1, 1}, " + "{1, 1, 1, 0, 1}, " + "{1, 1, 1, 1, 0}}", + "Adjacency Matrices 3.1.1, Page 82", + ), + ): + check_evaluation(str_expr, str_expected, message) def test_4_1(): for str_expr, str_expected, message in ( - # Reinstate these two after MapAt is - # ( - # "ConnectedComponents[ ExpandGraph[K[5], 10] ]", - # "{{1, 2, 3, 4, 5}, {6}, {7}, {8}, {9}, {10}}", - # "Unions and Intersections 4.1.1, Page 130", - # ), + ( + "ConnectedComponents[ ExpandGraph[K[5], 10] ]", + "{{1, 2, 3, 4, 5}, {6}, {7}, {8}, {9}, {10}}", + "Unions and Intersections 4.1.1, Page 130", + ), - # ( - # "IdenticalQ[ GraphIntersection[Wheel[10], K[10]], Wheel[10]]", - # "True", - # "Unions and Intersections 4.1.1, Page 131", - # ), + ( + "IdenticalQ[ GraphIntersection[Wheel[10], K[10]], Wheel[10]]", + "True", + "Unions and Intersections 4.1.1, Page 131", + ), ( "CompleteQ[ GraphSum[ Cycle[10], GraphComplement[Cycle[10]] ] ]", "True", @@ -677,11 +671,6 @@ def test_combinatorica_rest(): "2", "BinarySearch - find where key is a list", ), - # ( - # "SetPartitions[3]", - # "{{{1, 2, 3}}, {{1}, {2, 3}}, {{1, 2}, {3}}, {{1, 3}, {2}}, {{1}, {2}, {3}}}", - # "SetPartitions" - # ), ( "TransposePartition[{8, 6, 4, 4, 3, 1}]", "{6, 5, 5, 4, 2, 2, 1, 1}", diff --git a/test/test_combinatorica_v20.py b/test/test_combinatorica_v20.py index 8b0f258..b3d183b 100644 --- a/test/test_combinatorica_v20.py +++ b/test/test_combinatorica_v20.py @@ -100,11 +100,13 @@ def test_permutations_and_subsets_1_1_1(): # "???", # "Necklace polynomial, 1.1.1 Page 4", # ), - # ( - # "Subsets[{1,2,3,4}]" - # "??", - # "MinimumChangePermuations; 1.1.1, Page 5", - # ), + ( + "Subsets[{1,2,3,4}]", + "{{}, {4}, {3, 4}, {3}, {2, 3}, {2, 3, 4}, {2, 4}, " + "{2}, {1, 2}, {1, 2, 4}, {1, 2, 3, 4}, {1, 2, 3}, " + "{1, 3}, {1, 3, 4}, {1, 4}, {1}}", + "all 4-element subsets, minimum change order; 1.1.1, Page 5", + ), # ( # "KSubsets[{1,2,3,4,5}, 3]", # "??", From 31f81e1c0a8a968869b4a532f0505909a70c3408 Mon Sep 17 00:00:00 2001 From: rocky Date: Wed, 25 Dec 2024 20:37:20 -0500 Subject: [PATCH 2/6] Fill in more tests --- test/test_combinatorica_v09.py | 79 ++++++++++++++++++++++++++++++++-- test/test_combinatorica_v20.py | 2 +- 2 files changed, 76 insertions(+), 5 deletions(-) diff --git a/test/test_combinatorica_v09.py b/test/test_combinatorica_v09.py index f64b1da..117e0c7 100644 --- a/test/test_combinatorica_v09.py +++ b/test/test_combinatorica_v09.py @@ -497,7 +497,6 @@ def test_2_1_to_2_3(): for str_expr, str_expected, assert_fail_message in ( # 2.1.2 Ferrers Diagrams can't be tested easily and robustly here # easily - # 2.1.3 uses Partitions which is broken ( "Partitions[6]", "{{6}, {5, 1}, {4, 2}, {4, 1, 1}, {3, 3}, " @@ -525,6 +524,17 @@ def test_2_1_to_2_3(): "permutations or subsets. Counting Partitions 2.1.1, Page 52" ), ), + # Both WMA and Mathics3 give different results from the book. + # ( + # "Select[Partitions[7], (Apply[And,Map[OddQ#]])&]", + # "???", + # "Bijections between Partitions 2.1.3, Page 56", + # ), + # ( + # "Select[Partitions[7], (Length[#] == Lenghth[Union[#]])&]", + # "???", + # "Bijections between Partitions 2.1.3, Page 56", + # ), ( "PartitionsP[10]", "NumberOfPartitions[10]", @@ -535,6 +545,12 @@ def test_2_1_to_2_3(): "28", "Random Compositions 2.2.1, Page 60", ), + # Both WMA and Mathics3 give different results from the book. + # ( + # "(c = {0, 0, 6); Table[NextComposition[c], {28}])", + # "???", + # "Random Compositions 2.2.1, Page 62", + # ), ( "TableauQ[{{1,2,5}, {3,4,5}, {6}}]", "True", @@ -574,12 +590,24 @@ def test_2_1_to_2_3(): ( "FirstLexicographicTableau[{4, 4, 3, 3}]", "{{1, 5, 9, 13}, {2, 6, 10, 14}, {3, 7, 11}, {4, 8, 12}}", - "FirstLexicograpicTableaux 2.3.3, Page 66", + "FirstLexicograpicTableaux 2.3.3, Page 68", ), ( "LastLexicographicTableau[{4, 3, 3, 2}]", "{{1, 2, 3, 4}, {5, 6, 7}, {8, 9, 10}, {11, 12}}", - "LastLexicograpicTableaux 2.3.3, Page 66", + "LastLexicograpicTableaux 2.3.3, Page 68", + ), + ( + "Table[CatalanNumber[i], {i, 2, 20}]", + "{2, 5, 14, 42, 132, 429, 1430, 4862, 16796, " + "58786, 208012, 742900, 2674440, 9694845, 35357670, " + "129644790, 477638700, 1767263190, 6564120420}", + "Counting Tableaux by Shape 2.3.4, Page 71", + ), + ( + "EncroachingListSet[{6,7,1,8,2,5,9,3,4}]", + "{{1, 6, 7, 8, 9}, {2, 5}, {3, 4}}", + "Counting Tableaux by Shape 2.3.7, Page 76", ), ): check_evaluation(str_expr, str_expected, assert_fail_message) @@ -596,6 +624,50 @@ def test_combinatorica_3_1(): "{1, 1, 1, 1, 0}}", "Adjacency Matrices 3.1.1, Page 82", ), + ( + "V[ K[5] ]", + "5", + "Adjacency Matrices 3.1.1, Page 82", + ), + ( + "{M[K[5]], M[K[5],Directed]}", + "{10, 20}", + "Adjacency Matrices 3.1.1, Page 82", + ), + ( + "ConnectedComponents[ AddVertex[Star[10]] ]", + "{{1, 10, 2, 3, 4, 5, 6, 7, 8, 9}, {11}}", + "Adjacency Matrices 3.1.1, Page 84", + ), + ( + # WMA and Mathics3 agree, but differ from in + # the order of the list from book. + "Spectrum[ Star[5] ]", + "{-2, 2, 0, 0, 0}", + "Eigenvalues 3.1.2, Page 85", + ), + # WMA and Mathics don't work. + # ( + # "Spectrum[ GraphUnion[Cycle[4], K[1]] ]", + # "{4, -2, -2, 0, 0, 0}", + # "Eigenvalues 3.1.2, Page 85", + # ), + ( + "Spectrum[RealizeDegreeSequence[{4,4,4,4,4,4}]]", + "{4, -2, -2, 0, 0, 0}", + "Eigenvalues 3.1.2, Page 85", + ), + ( + "Spectrum[K[3,4]]", + "{-2 Sqrt[3], 2 Sqrt[3], 0, 0, 0, 0, 0}", + "Eigenvalues 3.1.2, Page 85", + ), + ( + "ToAdjacencyLists[K[5]]", + "{{2, 3, 4, 5}, {1, 3, 4, 5}, {1, 2, 4, 5}, {1, 2, 3, 5}, " + "{1, 2, 3, 4}}", + "Adjacency Lists 3.1.2, Page 86", + ), ): check_evaluation(str_expr, str_expected, message) @@ -608,7 +680,6 @@ def test_4_1(): "{{1, 2, 3, 4, 5}, {6}, {7}, {8}, {9}, {10}}", "Unions and Intersections 4.1.1, Page 130", ), - ( "IdenticalQ[ GraphIntersection[Wheel[10], K[10]], Wheel[10]]", "True", diff --git a/test/test_combinatorica_v20.py b/test/test_combinatorica_v20.py index b3d183b..de9fbac 100644 --- a/test/test_combinatorica_v20.py +++ b/test/test_combinatorica_v20.py @@ -139,7 +139,7 @@ def test_partitions_compositions_and_young_tableaux_1_1_2(): "Set partitions, 1.1.2 Page 7", ), # ( - # "Tableaux[{2,2,1}", + # "Tableaux[{2,2,1}]", # "???", # "Tableaux, 1.1.2 Page 8", # ), From 8e45c02a8be0144b33b71a69752f30f3eb4763ca Mon Sep 17 00:00:00 2001 From: rocky Date: Fri, 27 Dec 2024 09:57:07 -0500 Subject: [PATCH 3/6] Start section 3.2 --- Combinatorica/.gitignore | 1 + test/test_combinatorica_v09.py | 46 ++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 Combinatorica/.gitignore diff --git a/Combinatorica/.gitignore b/Combinatorica/.gitignore new file mode 100644 index 0000000..183700b --- /dev/null +++ b/Combinatorica/.gitignore @@ -0,0 +1 @@ +/.python-version diff --git a/test/test_combinatorica_v09.py b/test/test_combinatorica_v09.py index 117e0c7..46e32d9 100644 --- a/test/test_combinatorica_v09.py +++ b/test/test_combinatorica_v09.py @@ -668,6 +668,52 @@ def test_combinatorica_3_1(): "{1, 2, 3, 4}}", "Adjacency Lists 3.1.2, Page 86", ), + ( + "ToOrderedPairs[ K[5] ]", + "{{1, 2}, {1, 3}, {1, 4}, {1, 5}, {2, 1}, {2, 3}, " + "{2, 4}, {2, 5}, {3, 1}, {3, 2}, {3, 4}, {3, 5}, " + "{4, 1}, {4, 2}, {4, 3}, {4, 5}, {5, 1}, {5, 2}, {5, 3}, {5, 4}}", + "OrderedPairs 3.1.3, Page 88", + ), + ( + "ToUnorderedPairs[ K[5] ]", + "{{1, 2}, {1, 3}, {1, 4}, {1, 5}, {2, 3}, " + "{2, 4}, {2, 5}, {3, 4}, {3, 5}, {4, 5}}", + "OrderedPairs 3.1.3, Page 88", + ), + ): + check_evaluation(str_expr, str_expected, message) + + +def test_combinatorica_3_2(): + for str_expr, str_expected, message in ( + ( + "SimpleQ[ K[5] ] && CompleteQ[ K[5] ]", + "True", + "Classifying Simple Graph 3.2.2, Page 89", + ), + ( + "UnweightedQ[ AddEdge[K[5], {1,4}] ]", + "False", + "Classifying Simple Graph 3.2.2, Page 90", + ), + ( + "PseudographQ[ AddEdge[K[5], {3,3}] ]", + "True", + "Classifying Simple Graph 3.2.2, Page 90", + ), + ( + "UndirectedQ[ DeleteEdge[K[20], {1,2}, Directed] ]", + "False", + "Undirected Graphs 3.2.4, Page 94", + ), + + ( + "UndirectedQ[ K[20] ]", + "True", + "Undirected Graphs 3.2.4, Page 94", + ), + ): check_evaluation(str_expr, str_expected, message) From 523a5fb1ce435684c1f3d713e59cf573110ffb82 Mon Sep 17 00:00:00 2001 From: rocky Date: Fri, 27 Dec 2024 13:06:42 -0500 Subject: [PATCH 4/6] Add more of section 3.2 --- test/test_combinatorica_v09.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/test_combinatorica_v09.py b/test/test_combinatorica_v09.py index 46e32d9..4febd39 100644 --- a/test/test_combinatorica_v09.py +++ b/test/test_combinatorica_v09.py @@ -713,6 +713,38 @@ def test_combinatorica_3_2(): "True", "Undirected Graphs 3.2.4, Page 94", ), + ( + "BreadthFirstTraversal[Cycle[20], 1]", + "{1, 2, 20, 3, 19, 4, 18, 5, 17, 6, 16, 7, 15, 8, " + "14, 9, 13, 10, 12, 11}", + "BreadthfirstTraversal Graphs 3.2.5, Page 95", + ), + ( + "BreadthFirstTraversal[K[2,2,2], 1, Edge]", + "{{1, 3}, {1, 4}, {1, 5}, {1, 6}, {3, 2}}", + "BreadthfirstTraversal Graphs 3.2.5, Page 96", + ), + ( + "BreadthFirstTraversal[Star[9], 9]", + "{9, 1, 2, 3, 4, 5, 6, 7, 8}", + "BreadthfirstTraversal Graphs 3.2.5, Page 96", + ), + ( + "DepthFirstTraversal[GraphUnion[K[3],K[4]], 1]", + "{1, 2, 3}", + "DepthfirstTraversal Graphs 3.2.6, Page 96", + ), + ( + "DepthFirstTraversal[Cycle[20], 1]", + "{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, " + "15, 16, 17, 18, 19, 20}", + "DepthfirstTraversal Graphs 3.2.6, Page 96", + ), + ( + "DepthFirstTraversal[K[2,2,2], 1, Edge]", + "{{1, 3}, {3, 2}, {2, 4}, {4, 5}, {4, 6}}", + "DepthfirstTraversal Graphs 3.2.6, Page 97", + ), ): check_evaluation(str_expr, str_expected, message) From 5ace61d24847b713197184a58cdf17b3addf9a32 Mon Sep 17 00:00:00 2001 From: rocky Date: Fri, 27 Dec 2024 15:49:35 -0500 Subject: [PATCH 5/6] More tests in section 2.1.4 --- test/test_combinatorica_v09.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/test_combinatorica_v09.py b/test/test_combinatorica_v09.py index 4febd39..b340bfd 100644 --- a/test/test_combinatorica_v09.py +++ b/test/test_combinatorica_v09.py @@ -540,6 +540,17 @@ def test_2_1_to_2_3(): "NumberOfPartitions[10]", "Counting Partitions 2.1.4, Page 57", ), + ( + "NumberOfPartitions[10] == Length[Partitions[10]]", + "True", + "Counting Partitions 2.1.4, Page 57", + ), + ( + "Select[Partitions[10], (Length[#] == Length[Union[#]])&]", + "{{10}, {9, 1}, {8, 2}, {7, 3}, {7, 2, 1}, " + "{6, 4}, {6, 3, 1}, {5, 4, 1}, {5, 3, 2}, {4, 3, 2, 1}}", + "Counting Partitions 2.1.4, Page 58", + ), ( "NumberOfCompositions[6,3]", "28", From 50ddcea387923e068945dbae2fc0805750fd3ffe Mon Sep 17 00:00:00 2001 From: rocky Date: Fri, 27 Dec 2024 15:53:03 -0500 Subject: [PATCH 6/6] Go back to testing against master --- .github/workflows/ubuntu.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 44b43ab..882a850 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -31,7 +31,7 @@ jobs: cd mathics-scanner/ pip install -e . cd .. - git clone https://github.com/Mathics3/mathics-core.git --branch multi-dimensional-MapAt + git clone https://github.com/Mathics3/mathics-core.git cd mathics-core/ remake -x develop remake -x install