Skip to content

Commit 7087172

Browse files
committed
Add "shuffle" method to replace random(List)
Now random(List) returns a random element of the list
1 parent dd1db4a commit 7087172

9 files changed

Lines changed: 31 additions & 7 deletions

File tree

M2/Macaulay2/m2/exports.m2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,7 @@ export {
11431143
"showStructure",
11441144
"showTex",
11451145
"showUserStructure",
1146+
"shuffle",
11461147
"sign",
11471148
"sin",
11481149
"singularLocus",

M2/Macaulay2/m2/lists.m2

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,10 @@ flexibleOperators = sort flexibleOperators
228228
fixedOperators = sort fixedOperators
229229
allOperators = sort allOperators
230230

231-
random List := opts -> s -> (
231+
random List := opts -> x -> x#(random(#x))
232+
233+
shuffle = method()
234+
shuffle List := s -> (
232235
n := #s;
233236
if n <= 1 then return s;
234237
s = new MutableList from s;

M2/Macaulay2/packages/Macaulay2Doc/functions.m2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ load "./functions/setup-doc.m2"
250250
load "./functions/setupLift-doc.m2"
251251
load "./functions/setupPromote-doc.m2"
252252
load "./functions/show-doc.m2"
253+
load "./functions/shuffle-doc.m2"
253254
load "./functions/sign-doc.m2"
254255
load "./functions/sin-doc.m2"
255256
load "./functions/sinh-doc.m2"

M2/Macaulay2/packages/Macaulay2Doc/functions/random-doc.m2

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,19 +180,19 @@ Node
180180
Key
181181
(random, List)
182182
Headline
183-
shuffle a list randomly
183+
select a random element of a list
184184
Usage
185185
random L
186186
Inputs
187187
L:List
188188
Outputs
189-
:List
190-
a new list containing the elements of @TT "L"@ in a shuffled random order
189+
:Thing -- random element of @VAR "L"@
191190
Description
192191
Example
193192
random toList (0 .. 12)
194193
SeeAlso
195194
setRandomSeed
195+
shuffle
196196

197197
Node
198198
Key
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
doc ///
2+
Key
3+
shuffle
4+
(shuffle, List)
5+
Headline
6+
shuffle a list randomly
7+
Usage
8+
shuffle L
9+
Inputs
10+
L:List
11+
Outputs
12+
:List
13+
a new list containing the elements of @TT "L"@ in a shuffled random order
14+
Description
15+
Example
16+
shuffle toList (0 .. 12)
17+
SeeAlso
18+
setRandomSeed
19+
(random, List)
20+
///

M2/Macaulay2/packages/Macaulay2Doc/ov_examples.m2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ Node
121121
inversePermutation
122122
partitions
123123
random
124+
shuffle
124125
Set
125126
rays
126127
cone

M2/Macaulay2/packages/PathSignatures.m2

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export {
2121
"tensorParametrization",
2222
"wordAlgebra",
2323
"sgnVolTensor",
24-
"shuffle",
2524
"halfshuffle",
2625
"wordFormat",
2726
"wordString",

M2/Macaulay2/packages/PathSignatures/algebra.m2

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ shuffleHelper(NCRingElement, NCRingElement) := (f,g) -> (
102102

103103
-- Exposed versions of shuffle
104104

105-
shuffle = method();
106105
shuffle (NCRingElement, NCRingElement) := (a, b) -> shuffleHelper(a,b);
107106

108107
NCRingElement ** NCRingElement := shuffle

M2/Macaulay2/packages/PieriMaps.m2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ isStandard = T -> (
9090
-- entries (ignoring that some entries might be equal). The output is given in
9191
-- the form a hash table where the keys are the resulting tableau and the
9292
-- values are -1
93-
shuffle = (T, col, row1, row2) -> (
93+
shuffle(List, ZZ, ZZ, ZZ) := (T, col, row1, row2) -> (
9494
len1 := #(T#row1);
9595
len2 := #(T#row2);
9696
truncatedrow1 := (T#row1)_{0..col-2}; -- grab row1 entries

0 commit comments

Comments
 (0)