-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathgettingStarted.simpledoc
More file actions
311 lines (311 loc) · 9.79 KB
/
gettingStarted.simpledoc
File metadata and controls
311 lines (311 loc) · 9.79 KB
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
Key
"a first Macaulay2 session"
Headline
Basic Introduction to Macaulay2
Description
Code
SUBSECTION "Basic usage"
Text
First, let's restart Macaulay2 so that we are starting fresh.
Example
restart
Text
Your first input prompt will be {\tt "i1 : "}. In response to the prompt,
type {\tt 2+2} and press return. The expression you entered will be
evaluated - no punctuation is required at the end of the line.
Example
2+2
Text
The answer is displayed to the right of the output label {\tt "o1 = "}.
Text
Here is some arithmetic with fractions.
Example
3/5 + 7/11
Text
Notice the additional line of output labeled with {\tt "o2 : "}.
Output lines labeled with colons provide information about the type of
output. In this case, the symbol {\tt QQ} is our notation for
the class of all rational numbers, and indicates that the answer on
the previous line is a rational number.
Text
Multiplication is indicated with {\tt "*"}.
Example
1*2*3*4
Text
Powers are obtained with {\tt "^"}.
Example
2^200
Text
Factorials are obtained with {\tt "!"}.
Example
40!
Text
Some output is longer than the window. Scroll horizontally to see
the rest of the output.
Example
100!
Text
Multiple expressions may be separated by semicolons.
Example
1;2;3*4
Text
A semicolon at the end of the line suppresses the printing of the value.
Example
4*5;
Text
The output from the previous line can be obtained with {\tt "oo"} even if
a semicolon prevented it from being printed.
Example
oo
Text
Lines before that can be obtained with {\tt "ooo"} and {\tt "oooo"}.
Alternatively, the symbol labeling an output line
can be used to retrieve the value, as in the following example.
Example
o5 + 1
Text
To enter a string, use quotation marks.
Example
"hi there"
Text
A value can be assigned to a variable with {\tt "="}.
Example
s = "hi there"
Text
Strings may be concatenated horizontally with {\tt "|"}.
Example
s | " - " | s
Text
or vertically with {\tt "||"}.
Example
s || " - " || s
Code
SUBSECTION "Lists and functions"
Text
A list of expressions can be formed with braces.
Example
L = {1, 2, s}
Text
All indexing in Macaulay2 is 0-based. Indexing is done
using {\tt "_"}.
Example
L_0
L_1
Text
Lists behave like vectors.
Example
10*{1,2,3} + {1,1,1}
Text
A function can be created with the arrow operator, {\tt "->"}.
Example
f = i -> i^3
Text
To evaluate a function, place its argument to the right of the function.
Example
f 5
Text
Functions of more than one variable take a parenthesized sequence of arguments.
Example
g = (x,y) -> x * y
g(6,9)
Text
The function {\tt "apply"} can be used to apply a function to each element of a list.
Example
apply({1,2,3,4}, i -> i^2)
apply({1,2,3,4}, f)
Text
The operator {\tt ".."} may be used to generate sequences of consecutive numbers.
Example
apply(1 .. 4, f)
Text
If the first argument to {\tt "apply"} is an integer {\tt n}, then it stands for the list {\tt \{0, 1, ..., n-1\}}.
Example
apply(5, f)
Text
The syntax for a {\tt "for"} loop is the following.
Example
for i from 1 to 5 do print(i, i^3)
Code
SUBSECTION "Rings, matrices, and ideals"
Text
Most computations with polynomials take place in rings that may be specified in usual mathematical notation.
Example
R = ZZ/5[x,y,z];
Text
{\tt "ZZ"} represents the ring of integers.
The symbols {\tt "ZZ/5"}
represent the quotient ring {\tt "Z/5Z"}, and then {\tt "ZZ/5[x,y,z]"}
represents the ring of polynomials in the variables x,y, and z with coefficients
in the ring {\tt "Z/5Z"}.
Example
(x+y)^5
Text
Rings and certain other types of things acquire the name of the global variable they are assigned to.
Example
R
Text
To see the original description of a ring, use {\tt "describe"}.
Example
describe R
Text
A free module can be created as follows.
Example
F = R^3
Text
The i-th basis element of {\tt "F"} can be obtained as {\tt "F_i"}.
In this example, the valid values for {\tt "i"} are 0, 1, and 2.
Example
F_1
Text
Using a list of indices instead will produce the homomorphism
corresponding to the basis vectors indicated.
Example
F_{1,2}
Text
Repetitions are allowed.
Example
F_{2,1,1}
Text
We can create a homomorphism between free modules with {\tt "matrix"}
by providing the list of rows of the matrix, each of which is in turn
a list of ring elements.
Example
f = matrix {{x,y,z}}
Text
Use {\tt "image"} to get the image of f.
Example
image f
Text
We may use {\tt "ideal"} to produce the corresponding ideal.
Example
ideal (x,y,z)
Text
We may use {\tt "kernel"} to compute the kernel of f.
Example
kernel f
Text
The answer comes out as a module that is expressed as the image of
a homomorphism whose matrix is displayed. Integers inside braces to
the left of the matrix give the degrees of the basis elements of the
target of the matrix; they are omitted if the degrees are all zero.
In case the matrix itself is desired, it can be obtained
with {\tt "generators"}, as follows.
Example
generators oo
Text
We may use {\tt "poincare"} to compute the Poincare polynomial (the numerator of
the Hilbert function).
Example
poincare kernel f
Text
We may use {\tt "rank"} to compute the rank.
Example
rank kernel f
Text
A presentation for the kernel can be obtained with {\tt "presentation"}.
Example
presentation kernel f
Text
We can produce the cokernel with {\tt "cokernel"}; no computation is performed.
Example
cokernel f
Text
The direct sum is formed with {\tt (symbol ++,Module,Module)}.
Example
N = kernel f ++ cokernel f
Text
The answer is expressed in terms of the {\tt "subquotient"} function, which
produces subquotient modules. Each subquotient module is accompanied
by its matrix of generators and its matrix of relations. These matrices
can be recovered with {\tt "generators"} and {\tt "relations"}.
Example
generators N
relations N
Text
The function {\tt "prune"} can be used to convert a subquotient
module to a quotient module.
Example
prune N
Text
We can use {\tt "resolution"} to compute a projective resolution of the
cokernel of {\tt "f"}.
Example
C = resolution cokernel f
Text
To see the differentials we examine {\tt "C.dd"}.
Example
C.dd
Text
We can verify that {\tt "C"} is a complex by squaring the differential map.
Example
C.dd^2 == 0
Text
We can use {\tt "betti"} to see the degrees of the components of C.
Example
betti C
Text
Let's try a harder example. We can use {\tt "vars"} to create a sequence
of variables.
Example
R = ZZ/101[a .. r];
Text
We use {\tt "genericMatrix"} to make a 3 by 6 generic matrix whose
entries are drawn from the variables of the ring {\tt "R"}.
Example
g = genericMatrix(R,a,3,6)
Text
Then we construct its cokernel with {\tt "cokernel"}.
Example
M = cokernel g
Text
We may use {\tt "resolution"} to produce a projective resolution of it, and
{\tt "time"}, to report the time required.
Example
time C = resolution M
Text
As before, we may examine the degrees of its components, or display it.
Example
betti C
Text
We can make a polynomial ring with 18 {\tt "IndexedVariable"}s.
Example
S = ZZ/101[t_1 .. t_9, u_1 .. u_9];
Text
We can use {\tt "genericMatrix"} to pack the variables into
3-by-3 matrices.
Example
m = genericMatrix(S, t_1, 3, 3)
n = genericMatrix(S, u_1, 3, 3)
Text
We may look at the matrix product.
Example
m*n
Text
Let's produce the equations generated by the equations that assert
that m and n commute with each other. (See {\tt "flatten"}.)
Example
j = flatten(m*n - n*m)
Text
Let's compute a Groebner basis for the image of {\tt "j"} with {\tt "gb"}.
Example
gb j
Text
The resulting Groebner basis contains a lot of information.
We can get the generators of the basis, and even though we call upon
{\tt "gb"}, again, the computation will not be repeated.
Example
generators gb j;
Text
The semicolon prevents the matrix of generators from appearing on the
screen, but the class of the matrix appears -- we see that there are 26
generators.
Text
We can use {\tt "betti"} to see the degrees involved in the Groebner basis.
Example
betti gb j
Text
Macaulay2 has many more mathematical functions, and many user defined packages.
Try out other tutorials to see some possibilities, or peruse the documentation
at
Example
viewHelp "Macaulay2Doc"