Skip to content

Commit 017373e

Browse files
committed
More combinatorica
1 parent a47e3c6 commit 017373e

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

mathics/packages/DiscreteMath/CombinatoricaLite.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,18 @@
426426
]
427427

428428

429+
MultiplicationTable::usage = "MultiplicationTable[l,f] constructs the complete transition table defined by the binary relation function f on the elements of list l."
430+
431+
MultiplicationTable[elems_List,op_] :=
432+
Module[{i,j,n=Length[elems],p},
433+
Table[
434+
p = Position[elems, Apply[op,{elems[[i]],elems[[j]]}]];
435+
If [p === {}, 0, p[[1,1]]],
436+
{i,n},{j,n}
437+
]
438+
]
439+
440+
429441
RandomPermutation::usage = "RandomPermutation[n] returns a random permutation of length n."
430442
RandomPermutation1[n_Integer?Positive] :=
431443
Map[ Last, Sort[ Map[({RandomInteger[],#})&,Range[n]] ] ]

test/test_combinatorica.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,16 @@ def test_combinatorica():
153153
"2",
154154
"BinarySearch - find where key is a list",
155155
),
156+
# (
157+
# "TableForm[ MultiplicationTable[Permutations[Range[3]], Permute ] ]",
158+
# "1 2 3 4 5 6\n"
159+
# "2 1 5 6 3 4\n"
160+
# "3 4 1 2 6 5\n"
161+
# "4 3 6 5 1 2\n"
162+
# "5 6 2 1 4 3\n"
163+
# "6 5 4 3 2 1\n",
164+
# "Symmetric group S_n. S_n is not commutative. Page 17"
165+
# ),
156166
(
157167
"KSubsets[Range[5], 3]",
158168
"{{1, 2, 3}, {1, 2, 4}, {1, 2, 5}, {1, 3, 4}, {1, 3, 5}, {1, 4, 5}, "

0 commit comments

Comments
 (0)