Skip to content

Commit d436c1d

Browse files
committed
Start adding book section correspondences
1 parent 4445408 commit d436c1d

3 files changed

Lines changed: 35 additions & 15 deletions

File tree

mathics/packages/DiscreteMath/CombinatoricaLite.m

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,30 @@
2525
authors, Wolfram Research, or Cambridge University Press, their licensees,
2626
distributors and dealers shall in no event be liable for any indirect,
2727
incidental, or consequential damages.
28+
*)
2829

30+
(* :History:
31+
Version 2.1 updated to Mathematica 6 by John M. Novak, 2006.
32+
Version 2.0 most code rewritten Sriram V. Pemmaraju, 2000-2002
33+
Too many changes to describe here. Read the book!
34+
Version 1.1 modification by ECM, March 1996.
35+
Replaced K with CompleteGraph because K is now the
36+
default generic name for the summation index in
37+
symbolic sum.
38+
Added CombinatorialFunctions.m and Permutations.m to
39+
BeginPackage, and commented out CatalanNumber,
40+
PermutationQ, ToCycles, FromCycles, and
41+
RandomPermutation so there would be no shadowing of
42+
symbols among the DiscreteMath packages.
43+
Replaced old BinarySearch with new code by Paul Abbott
44+
correctly implementing binary search.
45+
Version 1.0 by Steven S. Skiena, April 1995.
46+
Version .9 by Steven S. Skiena, February 1992.
47+
Version .8 by Steven S. Skiena, July 1991.
48+
Version .7 by Steven S. Skiena, January 1991.
49+
Version .6 by Steven S. Skiena, June 1990.
50+
*)
51+
(*
2952
And for the 0.6 version:
3053
Version 0.6 6/11/90 Beta Release
3154
Copyright (c) 1990 by Steven S. Skiena

mathics/packages/DiscreteMath/CombinatoricaV0.9.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,8 @@
597597
Permute[l_List,p_?PermutationQ] := l [[ p ]]
598598
Permute[l_List,p_List] := Map[ (Permute[l,#])&, p] /; (Apply[And, Map[PermutationQ, p]])
599599

600+
(* Section 1.1.1 Lexicographically Ordered Permutions, Pages 3-4 *)
601+
600602
LexicographicPermutations[{l_}] := {{l}}
601603

602604
LexicographicPermutations[{a_,b_}] := {{a,b},{b,a}}
@@ -617,6 +619,8 @@
617619
]
618620
]
619621

622+
(* Section 1.1.2 Ranking and Unranking Permutations, Pages 5-6 *)
623+
620624
RankPermutation[{1}] = 0
621625

622626
RankPermutation[p_?PermutationQ] := (p[[1]]-1) (Length[Rest[p]]!) +
@@ -636,6 +640,8 @@
636640
NextPermutation[p_?PermutationQ] :=
637641
NthPermutation[ RankPermutation[p]+1, Sort[p] ]
638642

643+
(* Section 1.1.3 RandomPermutations, Pages 6-7 *)
644+
639645
RandomPermutation1[n_Integer?Positive] :=
640646
Map[ Last, Sort[ Map[({RandomInteger[],#})&,Range[n]] ] ]
641647

@@ -651,6 +657,7 @@
651657

652658
RandomPermutation[n_Integer?Positive] := RandomPermutation1[n]
653659

660+
(* Section 1.1.4 Permutation from Transpostions, Page 11 *)
654661
MinimumChangePermutations[l_List] :=
655662
Module[{i=1,c,p=l,n=Length[l],k},
656663
c = Table[1,{n}];
@@ -668,6 +675,7 @@
668675
]
669676
]
670677

678+
(* Section 1.1.5 Backtracking and Distict Permutations, Page 12-13 *)
671679
Backtrack[space_List,partialQ_,solutionQ_,flag_:One] :=
672680
Module[{n=Length[space],all={},done,index,v=2,solution},
673681
index=Prepend[ Table[0,{n-1}],1];
@@ -709,6 +717,8 @@
709717
]
710718
]
711719

720+
(* Section 1.1.6 Sorting and Searching, Page 14-16 *)
721+
712722
MinOp[l_List,f_] :=
713723
Module[{min=First[l]},
714724
Scan[ (If[ Apply[f,{#,min}], min = #])&, l];
@@ -739,6 +749,7 @@
739749
]
740750
]
741751

752+
(* Section 1.2.1 Multiplying Permutations, Page 17 *)
742753
MultiplicationTable[elems_List,op_] :=
743754
Module[{i,j,n=Length[elems],p},
744755
Table[
@@ -748,6 +759,7 @@
748759
]
749760
]
750761

762+
(* Section 1.2.2 The Inverse of a Permutation, Page 18 *)
751763
InversePermutation[p_?PermutationQ] :=
752764
Module[{inverse=p, i},
753765
Do[ inverse[[ p[[i]] ]] = i, {i,Length[p]} ];

test/test_combinatorica.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -100,21 +100,6 @@ def test_combinatorica_permutations_1_1():
100100
"{1, 2, 3}, {3, 4}, {1, 2, 4}, {1, 3, 4}, {2, 3, 4}, {1, 2, 3, 4}}",
101101
"Sort to total order subsets, Page 15",
102102
),
103-
(
104-
"InversePermutation[{4,8,5,2,1,3,7,6}]",
105-
"{5, 4, 6, 1, 3, 8, 7, 2}",
106-
"InversePermutation: 7 is fixed point. Page 18",
107-
),
108-
(
109-
"star = Automorphisms[Star[5]]",
110-
"{{1, 2, 3, 4, 5}, {1, 2, 4, 3, 5}, {1, 3, 2, 4, 5}, {1, 3, 4, 2, 5}, "
111-
"{1, 4, 2, 3, 5}, {1, 4, 3, 2, 5}, {2, 1, 3, 4, 5}, {2, 1, 4, 3, 5}, "
112-
"{2, 3, 1, 4, 5}, {2, 3, 4, 1, 5}, {2, 4, 1, 3, 5}, {2, 4, 3, 1, 5}, "
113-
"{3, 1, 2, 4, 5}, {3, 1, 4, 2, 5}, {3, 2, 1, 4, 5}, {3, 2, 4, 1, 5}, "
114-
"{3, 4, 1, 2, 5}, {3, 4, 2, 1, 5}, {4, 1, 2, 3, 5}, {4, 1, 3, 2, 5}, "
115-
"{4, 2, 1, 3, 5}, {4, 2, 3, 1, 5}, {4, 3, 1, 2, 5}, {4, 3, 2, 1, 5}}",
116-
"Automorphisms, Page 19",
117-
),
118103
):
119104
check_evaluation(str_expr, str_expected, message)
120105

0 commit comments

Comments
 (0)