File: random-doc.m2

package info (click to toggle)
macaulay2 1.17.1%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 68,376 kB
  • sloc: cpp: 102,995; ansic: 10,040; javascript: 6,019; sh: 3,506; makefile: 3,426; lisp: 727; yacc: 590; perl: 369; xml: 177; python: 141; lex: 65; awk: 3
file content (188 lines) | stat: -rw-r--r-- 6,597 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
document {
     Key => random,
     Headline => "get a random element",
     "This function can be used to get random elements of various sorts.",
     SeeAlso => {"setRandomSeed"}
     }
document {
     Key => (random, ZZ),
     Headline => "random integer",
     Usage => "random n",
     Inputs => {"n"=> {}},
     Outputs => {ZZ => {"a random integer in the range ", TT "0 .. n-1"}},
     EXAMPLE lines ///
     random 57
     random 10^50
     tally apply(100, i -> random 7)
     ///,
     SeeAlso => {setRandomSeed, tally}
     }

document {
     Key => (random, ZZ,ZZ),
     Headline => "random integer in a range",
     Usage => "random(min,max)",
     Inputs => {"min","max"},
     Outputs => {ZZ => {"a random integer in the range ", TT "min .. max"}},
     EXAMPLE lines ///
     for i to 10 list random(100,200)
     tally apply(100, i -> random(10,15))
     ///,
     SeeAlso => {"setRandomSeed"}
     }

document {
     Key => (random, RR),
     Headline => "random real number",
     Usage => "random x",
     Inputs => {"x"},
     Outputs => { RR=> {"a random positive real number less than ", TT "x", ", of the same precision"}},
     EXAMPLE lines ///
     random 3.14
     random 3p200
     ///,
     SeeAlso => {"setRandomSeed", (random,RR,RR)}
     }

document {
     Key => (random, RR,RR),
     Headline => "random real number",
     Usage => "random(x,y)",
     Inputs => {"x","r"},
     Outputs => { RR=> {"a random real number between ", TT "x", " and ", TT "y"}},
     EXAMPLE lines ///
     random(10.,20.)
     random(10p100,20p100)
     ///,
     SeeAlso => {"setRandomSeed", (random,RR)}
     }

document {
     Key => {(random, Type),(random, RingFamily),(random, QuotientRing),(random, GaloisField),
	  (random, ZZ, Ring),(random, List, Ring),[random,Height]
	  },
     Headline => "random element of a type",
     SYNOPSIS (
	  Usage => "random T",
	  Inputs => {
	       "T" => {ofClass Type},
	       Height => ZZ
	       },
	  Outputs => { { "a random instance of the type ", TT "T", ".  If the Height option specifies a number ", TT "h", "
		    and ", TT "T", " is ", TO "ZZ", " and , then the integers
		    returned are in the range ", TT "0 .. h-1", "; for ", TO "QQ", "
		    the numerator and denominator are in the range ", TT "1 .. h", "." } },
	  EXAMPLE lines ///
	  random RR
	  random CC_100
	  tally for i to 100 list random GF 11
	  random GF(2,40)
	  ///
	  ),
     SYNOPSIS (
	  Usage => "random(d,R)",
	  Inputs => {
	       "d" => {ofClass{ZZ,List}, ", the degree or multi-degree to use"},
	       "R" => Ring
	       },
	  Outputs => { { "a random homogeneous element of the ring ", TT "R", " of degree ", TT "d" } },
	  EXAMPLE lines ///
	  R = ZZ[x,y];
	  random(5,R)
	  R = GF(25,Variable=>a)[x,y];
	  VerticalList for i to 6 list random(3,R)
	  ///,
	  "The length of ", TT "d", ", if it's a list, should be the same as ", TT "degreeLength R", ".",
	  ),
     SeeAlso => {setRandomSeed}
     }

document {
     Key => {(random, Module, Module),[random, MaximalRank],[random, Density],[random, UpperTriangular]},
     Headline => "make a random module map",
     Usage => "f = random(F,G)",
     Inputs => {
	  "F" => {"a free module"},
	  "G" => {"a free module"},
	  MaximalRank => {"whether to ensure that the resulting map has maximal rank: designed mostly
	       for use with matrices of numbers: for polynomial rings, returns inhomogeneous results"},
	  Density => RR => {"the proportion of entries to set"},
	  UpperTriangular => Boolean => {"whether to set just entries strictly above the diagonal"}
	  },
     Outputs => {"f" => {"a random, graded, degree ", TT "0", " map, from ", TT "G", " to ", TT "F"}},
     EXAMPLE lines ///
	  R = ZZ/101[x,y];
	  random(R^{1,2,3},R^{1,2,3})
	  random(ZZ^3,ZZ^6,MaximalRank=>true)
	  random(ZZ^3,ZZ^10,Density=>.3)
	  random(ZZ^6,ZZ^6,UpperTriangular=>true)
	  ///,
     Caveat => {
	  "Over a polynomial ring, specifying ", TT "MaximalRank=>true", " will yield a non-homogeneous matrix."
	  },
     SeeAlso => {"setRandomSeed"}
     }

document {
     Key => (random,List),
     Headline => "shuffle a list randomly",
     Usage => "random x",
     Inputs => { "x" },
     Outputs => { List => {"a new list containing the elements of ", TT "x", " in a shuffled random order"} },
     EXAMPLE lines ///
	  random toList (0 .. 12)
     ///
     }

document { Key => {(randomMutableMatrix, ZZ, ZZ, RR, ZZ),
	  [randomMutableMatrix,Dense],
	  randomMutableMatrix},
     Headline => "a random mutable matrix of integers",
     Usage => "randomMutableMatrix(nrows,ncols,zerof,max)",
     Inputs => {
	  "nrows",
	  "ncols",
	  "zerof" => { "between 0 and 1" },
	  "max",
	  Dense => {"whether the encoding of the matrix should be dense or not: see ", TO MutableMatrix}
	  },
     Outputs => {
	  {"a random mutable ", TT "nrows", " by ", TT "ncols", " matrix of integers.
	       The absolute value of the
	       entries is less than ", TT "max", ", and
	       the frequency of entries equal to zero is given by ", TT "zerof", "." }
	  },
     "This function has been superceded by ", TO fillMatrix, ", which works over
     more rings, is much faster for large matrices, and is more flexible.",
     EXAMPLE lines ///
       randomMutableMatrix(10,15,.9,100)
     ///,
     SeeAlso => {mutableMatrix, fillMatrix, setRandomSeed, random}
     }

document {
     Headline => "fill a mutable matrix with random numbers",
     Key => {fillMatrix,(fillMatrix, MutableMatrix),(fillMatrix, MutableMatrix, ZZ),
	  [fillMatrix, Height],[fillMatrix,Density],[fillMatrix,UpperTriangular]},
     Usage => "fillMatrix M\nfillMatrix(M,n)",
     BaseFunction => fillMatrix,
     Inputs => {
	  "M"=>MutableMatrix,
	  "n" => ZZ => {"if specified, the maximum number of entries to replace"},
	  Density => RR => {"the fraction of entries of ", TT "M", " to be replaced, if ", TT "n", " is
	       not specified"},
	  UpperTriangular => Boolean => "whether to fill entries only above the diagonal",
	  Height => ZZ => "a bound on the absolute values of the generated random numbers"
	  },
     Outputs => {"M"},
     Consequences => {{ "some entries of M are replaced with randomly generated numbers, whose
	       size depends on the value of the option ", TT "Height" }},
     EXAMPLE lines ///
	  printingPrecision = 2
	  fillMatrix(mutableMatrix(RR,5,10))
	  fillMatrix(mutableMatrix(ZZ,5,10),UpperTriangular=>true)
	  fillMatrix(mutableMatrix(QQ,5,10),Density=>.2,Height=>1000)
	  fillMatrix(mutableMatrix(ZZ,5,10),25,Height=>1000)
	  ///,
     SeeAlso => {setRandomSeed, random, mutableMatrix}
     }