We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4445408 commit d436c1dCopy full SHA for d436c1d
3 files changed
mathics/packages/DiscreteMath/CombinatoricaLite.m
@@ -25,7 +25,30 @@
25
authors, Wolfram Research, or Cambridge University Press, their licensees,
26
distributors and dealers shall in no event be liable for any indirect,
27
incidental, or consequential damages.
28
+ *)
29
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
+(*
52
And for the 0.6 version:
53
Version 0.6 6/11/90 Beta Release
54
Copyright (c) 1990 by Steven S. Skiena
mathics/packages/DiscreteMath/CombinatoricaV0.9.m
@@ -597,6 +597,8 @@
597
Permute[l_List,p_?PermutationQ] := l [[ p ]]
598
Permute[l_List,p_List] := Map[ (Permute[l,#])&, p] /; (Apply[And, Map[PermutationQ, p]])
599
600
+(* Section 1.1.1 Lexicographically Ordered Permutions, Pages 3-4 *)
601
+
602
LexicographicPermutations[{l_}] := {{l}}
603
604
LexicographicPermutations[{a_,b_}] := {{a,b},{b,a}}
@@ -617,6 +619,8 @@
617
619
]
618
620
621
622
+(* Section 1.1.2 Ranking and Unranking Permutations, Pages 5-6 *)
623
624
RankPermutation[{1}] = 0
625
626
RankPermutation[p_?PermutationQ] := (p[[1]]-1) (Length[Rest[p]]!) +
@@ -636,6 +640,8 @@
636
640
NextPermutation[p_?PermutationQ] :=
637
641
NthPermutation[ RankPermutation[p]+1, Sort[p] ]
638
642
643
+(* Section 1.1.3 RandomPermutations, Pages 6-7 *)
644
639
645
RandomPermutation1[n_Integer?Positive] :=
646
Map[ Last, Sort[ Map[({RandomInteger[],#})&,Range[n]] ] ]
647
@@ -651,6 +657,7 @@
651
657
652
658
RandomPermutation[n_Integer?Positive] := RandomPermutation1[n]
653
659
660
+(* Section 1.1.4 Permutation from Transpostions, Page 11 *)
654
661
MinimumChangePermutations[l_List] :=
655
662
Module[{i=1,c,p=l,n=Length[l],k},
656
663
c = Table[1,{n}];
@@ -668,6 +675,7 @@
668
675
669
676
670
677
678
+(* Section 1.1.5 Backtracking and Distict Permutations, Page 12-13 *)
671
679
Backtrack[space_List,partialQ_,solutionQ_,flag_:One] :=
672
680
Module[{n=Length[space],all={},done,index,v=2,solution},
673
681
index=Prepend[ Table[0,{n-1}],1];
@@ -709,6 +717,8 @@
709
717
710
718
711
719
720
+(* Section 1.1.6 Sorting and Searching, Page 14-16 *)
721
712
722
MinOp[l_List,f_] :=
713
723
Module[{min=First[l]},
714
724
Scan[ (If[ Apply[f,{#,min}], min = #])&, l];
@@ -739,6 +749,7 @@
739
749
740
750
741
751
752
+(* Section 1.2.1 Multiplying Permutations, Page 17 *)
742
753
MultiplicationTable[elems_List,op_] :=
743
754
Module[{i,j,n=Length[elems],p},
744
755
Table[
@@ -748,6 +759,7 @@
748
759
760
761
762
+(* Section 1.2.2 The Inverse of a Permutation, Page 18 *)
763
InversePermutation[p_?PermutationQ] :=
764
Module[{inverse=p, i},
765
Do[ inverse[[ p[[i]] ]] = i, {i,Length[p]} ];
test/test_combinatorica.py
@@ -100,21 +100,6 @@ def test_combinatorica_permutations_1_1():
100
"{1, 2, 3}, {3, 4}, {1, 2, 4}, {1, 3, 4}, {2, 3, 4}, {1, 2, 3, 4}}",
101
"Sort to total order subsets, Page 15",
102
),
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
118
):
119
check_evaluation(str_expr, str_expected, message)
120
0 commit comments