<?xml version="1.0" encoding="utf-8" ?> <!-- for emacs: -*- coding: utf-8 -*- --> <!-- Apache may like this line in the file .htaccess: AddCharset utf-8 .html --> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg-flat.dtd" > <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head><title>a first Macaulay2 session</title> <link rel="stylesheet" type="text/css" href="../../../../Macaulay2/Style/doc.css"/> </head> <body> <table class="buttons"> <tr> <td><div><a href="_reading_spthe_spdocumentation.html">next</a> | <a href="_using_sp__Macaulay2_spwith_sp__Te__Xmacs.html">previous</a> | <a href="_reading_spthe_spdocumentation.html">forward</a> | <a href="_using_sp__Macaulay2_spwith_sp__Te__Xmacs.html">backward</a> | <a href="_getting_spstarted.html">up</a> | <a href="index.html">top</a> | <a href="master.html">index</a> | <a href="toc.html">toc</a> | <a href="http://www.math.uiuc.edu/Macaulay2/">Macaulay2 web site</a></div> </td> </tr> </table> <div><a href="index.html" title="">Macaulay2Doc</a> > <a href="_getting_spstarted.html" title="">getting started</a> > <a href="_a_spfirst_sp__Macaulay2_spsession.html" title="">a first Macaulay2 session</a></div> <hr/> <div><h1>a first Macaulay2 session</h1> <div><p>Your first input prompt will be <tt>i1 : </tt>. In response to the prompt, type <tt>2+2</tt> and press return. The expression you entered will be evaluated - no punctuation is required at the end of the line.</p> <table class="examples"><tr><td><pre>i1 : 2+2 o1 = 4</pre> </td></tr> </table> The answer is displayed to the right of the output label <tt>o1 =</tt>.<p/> Here is some arithmetic with fractions.<table class="examples"><tr><td><pre>i2 : 3/5 + 7/11 68 o2 = -- 55 o2 : QQ</pre> </td></tr> </table> <p>Notice the additional line of output labeled with <tt>o2 :</tt>. Output lines labeled with colons provide information about the type of output. In this case, the symbol <a href="___Q__Q.html" title="the class of all rational numbers">QQ</a> is our notation for the class of all rational numbers, and indicates that the answer on the previous line is a rational number.</p> <p/> Multiplication is indicated with <a href="__st.html" title="a binary operator, usually used for multiplication">*</a>.<table class="examples"><tr><td><pre>i3 : 1*2*3*4 o3 = 24</pre> </td></tr> </table> Powers are obtained with <a href="_^.html" title="a binary operator, usually used for powers">^</a>.<table class="examples"><tr><td><pre>i4 : 2^200 o4 = 1606938044258990275541962092341162602522202993782792835301376</pre> </td></tr> </table> Factorials are obtained with <a href="_!.html" title="factorial">!</a>.<table class="examples"><tr><td><pre>i5 : 40! o5 = 815915283247897734345611269596115894272000000000</pre> </td></tr> </table> Because some answers can be very long, it is a good idea to run the program in a window that does not wrap output lines, and allows the user to scroll left horizontally to see the rest of the output. (See <a href="_using_sp__Macaulay2_spwith_spemacs.html" title="">using Macaulay2 with emacs</a>.)<table class="examples"><tr><td><pre>i6 : 100! o6 = 933262154439441526816992388562667004907159682643816214685929638952175999 932299156089414639761565182862536979208272237582511852109168640000000000 00000000000000</pre> </td></tr> </table> Multiple expressions may be separated by semicolons.<table class="examples"><tr><td><pre>i7 : 1;2;3*4 o9 = 12</pre> </td></tr> </table> A semicolon at the end of the line suppresses the printing of the value.<table class="examples"><tr><td><pre>i10 : 4*5;</pre> </td></tr> </table> The output from the previous line can be obtained with <a href="_oo.html" title="the last output value">oo</a>, even if a semicolon prevented it from being printed.<table class="examples"><tr><td><pre>i11 : oo o11 = 20</pre> </td></tr> </table> Lines before that can be obtained with <a href="_ooo.html" title="the next to the last output value">ooo</a> and <a href="_oooo.html" title="the third to the last output value">oooo</a>. Alternatively, the symbol labeling an output line can be used to retrieve the value, as in the following example.<table class="examples"><tr><td><pre>i12 : o5 + 1 o12 = 815915283247897734345611269596115894272000000001</pre> </td></tr> </table> To enter a string, use quotation marks.<table class="examples"><tr><td><pre>i13 : "hi there" o13 = hi there</pre> </td></tr> </table> A value can be assigned to a variable with <a href="__eq.html" title="assignment">=</a>.<table class="examples"><tr><td><pre>i14 : s = "hi there" o14 = hi there</pre> </td></tr> </table> Strings may be concatenated horizontally with <tt>|</tt>, (see <a href="___Net_sp_vb_sp__Net.html" title="join strings or nets">String | String</a>).<table class="examples"><tr><td><pre>i15 : s | " - " | s o15 = hi there - hi there</pre> </td></tr> </table> or vertically with <tt>||</tt>, (see <a href="___Net_sp_vb_vb_sp__Net.html" title="join nets or strings vertically">Net || Net</a>).<table class="examples"><tr><td><pre>i16 : s || " - " || s o16 = hi there - hi there</pre> </td></tr> </table> A list of expressions can be formed with braces.<table class="examples"><tr><td><pre>i17 : {1, 2, s} o17 = {1, 2, hi there} o17 : List</pre> </td></tr> </table> Lists behave like vectors.<table class="examples"><tr><td><pre>i18 : 10*{1,2,3} + {1,1,1} o18 = {11, 21, 31} o18 : List</pre> </td></tr> </table> A function can be created with the arrow operator, <a href="_-_gt.html" title="make a function">-></a> .<table class="examples"><tr><td><pre>i19 : f = i -> i^3 o19 = f o19 : FunctionClosure</pre> </td></tr> </table> To evaluate a function, place its argument to the right of the function.<table class="examples"><tr><td><pre>i20 : f 5 o20 = 125</pre> </td></tr> </table> Functions of more than one variable take a parenthesized sequence of arguments.<table class="examples"><tr><td><pre>i21 : g = (x,y) -> x * y o21 = g o21 : FunctionClosure</pre> </td></tr> <tr><td><pre>i22 : g(6,9) o22 = 54</pre> </td></tr> </table> The function <a href="_apply.html" title="apply a function to each element">apply</a> can be used to apply a function to each element of a list.<table class="examples"><tr><td><pre>i23 : apply({1,2,3,4}, i -> i^2) o23 = {1, 4, 9, 16} o23 : List</pre> </td></tr> <tr><td><pre>i24 : apply({1,2,3,4}, f) o24 = {1, 8, 27, 64} o24 : List</pre> </td></tr> </table> The operator <a href="_...html" title="a binary operator, used for sequences of consecutive items">..</a> may be used to generate sequences of consecutive numbers.<table class="examples"><tr><td><pre>i25 : apply(1 .. 4, f) o25 = (1, 8, 27, 64) o25 : Sequence</pre> </td></tr> </table> If the first argument to <tt>apply</tt> is an integer <tt>n</tt> then it stands for the list <tt>{0, 1, ..., n-1}</tt>.<table class="examples"><tr><td><pre>i26 : apply(5, f) o26 = {0, 1, 8, 27, 64} o26 : List</pre> </td></tr> </table> The function <a href="_scan.html" title="apply a function to each element">scan</a> is analogous to <a href="_apply.html" title="apply a function to each element">apply</a> except that no value is returned. It may be used to implement loops in programs.<table class="examples"><tr><td><pre>i27 : scan(5, i -> print (i, i^3)) (0, 0) (1, 1) (2, 8) (3, 27) (4, 64)</pre> </td></tr> <tr><td><pre>i28 : j=1; scan(10, i -> j = 2*j); j o30 = 1024</pre> </td></tr> </table> Most computations with polynomials take place in rings that may be specified in usual mathematical notation.<table class="examples"><tr><td><pre>i31 : R = ZZ/5[x,y,z];</pre> </td></tr> </table> (We reserve single letter symbols such as <tt>Z</tt> for use as variables in rings, hence we must use something like <a href="___Z__Z.html" title="the class of all integers">ZZ</a> to stand for the ring of integers. It may remind you of the "blackboard bold" font of AMSTeX. If you prefer <tt>Z</tt> to <a href="___Z__Z.html" title="the class of all integers">ZZ</a>, you may put <tt>Z=ZZ</tt> in your <a href="_initialization_spfile.html" title="">initialization file</a>. The symbols <tt>ZZ/5</tt> represent the quotient ring <tt>Z/5Z</tt>, and then <tt>ZZ/5[x,y,z]</tt> represents the ring of polynomials in the variables x,y, and z with coefficients in the ring <tt>Z/5Z</tt>.)<table class="examples"><tr><td><pre>i32 : (x+y)^5 5 5 o32 = x + y o32 : R</pre> </td></tr> </table> Rings and certain other types of things acquire the name of the global variable they are assigned to.<table class="examples"><tr><td><pre>i33 : R o33 = R o33 : PolynomialRing</pre> </td></tr> </table> To see the original description of a ring, use <a href="_describe.html" title="real description">describe</a>.<table class="examples"><tr><td><pre>i34 : describe R ZZ o34 = --[x..z, Degrees => {3:1}, Heft => {1}, MonomialOrder => {MonomialSize => 32}, DegreeRank => 1] 5 {GRevLex => {3:1} } {Position => Up }</pre> </td></tr> </table> A free module can be created as follows.<table class="examples"><tr><td><pre>i35 : F = R^3 3 o35 = R o35 : R-module, free</pre> </td></tr> </table> The i-th basis element of <tt>F</tt> can be obtained as <tt>F_i</tt>. In this example, the valid values for <tt>i</tt> are 0, 1, and 2.<table class="examples"><tr><td><pre>i36 : F_1 o36 = | 0 | | 1 | | 0 | 3 o36 : R</pre> </td></tr> </table> Using a list of indices instead will produce the homomorphism corresponding to the basis vectors indicated.<table class="examples"><tr><td><pre>i37 : F_{1,2} o37 = | 0 0 | | 1 0 | | 0 1 | 3 2 o37 : Matrix R <--- R</pre> </td></tr> </table> Repetitions are allowed.<table class="examples"><tr><td><pre>i38 : F_{2,1,1} o38 = | 0 0 0 | | 0 1 1 | | 1 0 0 | 3 3 o38 : Matrix R <--- R</pre> </td></tr> </table> We can create a homomorphism between free modules with <a href="_matrix.html" title="make a matrix">matrix</a> by providing the list of rows of the matrix, each of which is in turn a list of ring elements.<table class="examples"><tr><td><pre>i39 : f = matrix {{x,y,z}} --warning: function f redefined o39 = | x y z | 1 3 o39 : Matrix R <--- R</pre> </td></tr> </table> Use <a href="_image.html" title="image of a map">image</a> to get the image of f.<table class="examples"><tr><td><pre>i40 : image f o40 = image | x y z | 1 o40 : R-module, submodule of R</pre> </td></tr> </table> We may use <a href="_ideal.html" title="make an ideal">ideal</a> to produce the corresponding ideal.<table class="examples"><tr><td><pre>i41 : ideal (x,y,z) o41 = ideal (x, y, z) o41 : Ideal of R</pre> </td></tr> </table> We may use <a href="_kernel.html" title="kernel of a ringmap, matrix, or chain complex">kernel</a> to compute the kernel of f.<table class="examples"><tr><td><pre>i42 : kernel f o42 = image {1} | -y 0 -z | {1} | x -z 0 | {1} | 0 y x | 3 o42 : R-module, submodule of R</pre> </td></tr> </table> 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 <a href="_generators.html" title="provide matrix or list of generators">generators</a>, as follows.<table class="examples"><tr><td><pre>i43 : generators oo o43 = {1} | -y 0 -z | {1} | x -z 0 | {1} | 0 y x | 3 3 o43 : Matrix R <--- R</pre> </td></tr> </table> We may use <a href="_poincare.html" title="assemble degrees into polynomial">poincare</a> to compute the Poincare polynomial.<table class="examples"><tr><td><pre>i44 : poincare kernel f 2 3 o44 = 3T - T o44 : ZZ[T]</pre> </td></tr> </table> We may use <a href="_rank.html" title="compute the rank">rank</a> to compute the rank.<table class="examples"><tr><td><pre>i45 : rank kernel f o45 = 2</pre> </td></tr> </table> A presentation for the kernel can be obtained with <a href="_presentation.html" title="presentation of a module or ring">presentation</a>.<table class="examples"><tr><td><pre>i46 : presentation kernel f o46 = {2} | z | {2} | x | {2} | -y | 3 1 o46 : Matrix R <--- R</pre> </td></tr> </table> We can produce the cokernel with <a href="_cokernel.html" title="cokernel of a map of modules, graded modules, or chaincomplexes">cokernel</a>; no computation is performed.<table class="examples"><tr><td><pre>i47 : cokernel f o47 = cokernel | x y z | 1 o47 : R-module, quotient of R</pre> </td></tr> </table> The direct sum is formed with <a href="___Module_sp_pl_pl_sp__Module.html" title="direct sum of modules">Module ++ Module</a>.<table class="examples"><tr><td><pre>i48 : N = kernel f ++ cokernel f o48 = subquotient ({1} | -y 0 -z 0 |, {1} | 0 0 0 |) {1} | x -z 0 0 | {1} | 0 0 0 | {1} | 0 y x 0 | {1} | 0 0 0 | {0} | 0 0 0 1 | {0} | x y z | 4 o48 : R-module, subquotient of R</pre> </td></tr> </table> The answer is expressed in terms of the <a href="_subquotient.html" title="make a subquotient module">subquotient</a> 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 <a href="_generators.html" title="provide matrix or list of generators">generators</a> and <a href="_relations.html" title="the defining relations">relations</a>.<table class="examples"><tr><td><pre>i49 : generators N o49 = {1} | -y 0 -z 0 | {1} | x -z 0 0 | {1} | 0 y x 0 | {0} | 0 0 0 1 | 4 4 o49 : Matrix R <--- R</pre> </td></tr> <tr><td><pre>i50 : relations N o50 = {1} | 0 0 0 | {1} | 0 0 0 | {1} | 0 0 0 | {0} | x y z | 4 3 o50 : Matrix R <--- R</pre> </td></tr> </table> The function <a href="_prune.html" title="prune, e.g., compute a minimal presentation">prune</a> can be used to convert a subquotient module to a quotient module.<table class="examples"><tr><td><pre>i51 : prune N o51 = cokernel {2} | 0 0 0 z | {2} | 0 0 0 x | {2} | 0 0 0 -y | {0} | z y x 0 | 4 o51 : R-module, quotient of R</pre> </td></tr> </table> We can use <a href="_resolution.html" title="projective resolution">resolution</a> to compute a projective resolution of the cokernel of <tt>f</tt>.<table class="examples"><tr><td><pre>i52 : C = resolution cokernel f 1 3 3 1 o52 = R <-- R <-- R <-- R <-- 0 0 1 2 3 4 o52 : ChainComplex</pre> </td></tr> </table> To see the differentials we examine 'C.dd'.<table class="examples"><tr><td><pre>i53 : C.dd 1 3 o53 = 0 : R <------------- R : 1 | x y z | 3 3 1 : R <-------------------- R : 2 {1} | -y -z 0 | {1} | x 0 -z | {1} | 0 x y | 3 1 2 : R <-------------- R : 3 {2} | z | {2} | -y | {2} | x | 1 3 : R <----- 0 : 4 0 o53 : ChainComplexMap</pre> </td></tr> </table> We can verify that <tt>C</tt> is a complex by squaring the differential map.<table class="examples"><tr><td><pre>i54 : C.dd^2 == 0 o54 = true</pre> </td></tr> </table> We can use <a href="_betti.html" title="display degrees">betti</a> to see the degrees of the components of C.<table class="examples"><tr><td><pre>i55 : betti C 0 1 2 3 o55 = total: 1 3 3 1 0: 1 3 3 1 o55 : BettiTally</pre> </td></tr> </table> Let's try a harder example. We can use <a href="_vars.html" title="variables">vars</a> to create a sequence of variables.<table class="examples"><tr><td><pre>i56 : R = ZZ/101[a .. r];</pre> </td></tr> </table> We use <a href="_generic__Matrix.html" title="make a generic matrix of variables">genericMatrix</a> to make a 3 by 6 generic matrix whose entries are drawn from the variables of the ring <tt>R</tt>.<table class="examples"><tr><td><pre>i57 : g = genericMatrix(R,a,3,6) o57 = | a d g j m p | | b e h k n q | | c f i l o r | 3 6 o57 : Matrix R <--- R</pre> </td></tr> </table> Then we construct its cokernel with <a href="_cokernel.html" title="cokernel of a map of modules, graded modules, or chaincomplexes">cokernel</a>.<table class="examples"><tr><td><pre>i58 : M = cokernel g o58 = cokernel | a d g j m p | | b e h k n q | | c f i l o r | 3 o58 : R-module, quotient of R</pre> </td></tr> </table> We may use <a href="_resolution.html" title="projective resolution">resolution</a> to produce a projective resolution of it, and <a href="_time.html" title="time a computation">time</a> to report the time required.<table class="examples"><tr><td><pre>i59 : time C = resolution M -- used 0.001 seconds 3 6 15 18 6 o59 = R <-- R <-- R <-- R <-- R <-- 0 0 1 2 3 4 5 o59 : ChainComplex</pre> </td></tr> </table> As before, we may examine the degrees of its components, or display it.<table class="examples"><tr><td><pre>i60 : betti C 0 1 2 3 4 o60 = total: 3 6 15 18 6 0: 3 6 . . . 1: . . . . . 2: . . 15 18 6 o60 : BettiTally</pre> </td></tr> </table> We can make a polynomial ring with 18 <a href="___Indexed__Variable.html" title="the class of all indexed variables">IndexedVariable</a>s.<table class="examples"><tr><td><pre>i61 : S = ZZ/101[t_1 .. t_9, u_1 .. u_9];</pre> </td></tr> </table> We can use <a href="_generic__Matrix.html" title="make a generic matrix of variables">genericMatrix</a> to pack the variables into 3-by-3 matrices.<table class="examples"><tr><td><pre>i62 : m = genericMatrix(S, t_1, 3, 3) o62 = | t_1 t_4 t_7 | | t_2 t_5 t_8 | | t_3 t_6 t_9 | 3 3 o62 : Matrix S <--- S</pre> </td></tr> <tr><td><pre>i63 : n = genericMatrix(S, u_1, 3, 3) o63 = | u_1 u_4 u_7 | | u_2 u_5 u_8 | | u_3 u_6 u_9 | 3 3 o63 : Matrix S <--- S</pre> </td></tr> </table> We may look at the matrix product.<table class="examples"><tr><td><pre>i64 : m*n o64 = | t_1u_1+t_4u_2+t_7u_3 t_1u_4+t_4u_5+t_7u_6 t_1u_7+t_4u_8+t_7u_9 | | t_2u_1+t_5u_2+t_8u_3 t_2u_4+t_5u_5+t_8u_6 t_2u_7+t_5u_8+t_8u_9 | | t_3u_1+t_6u_2+t_9u_3 t_3u_4+t_6u_5+t_9u_6 t_3u_7+t_6u_8+t_9u_9 | 3 3 o64 : Matrix S <--- S</pre> </td></tr> </table> Let's produce the equations generated by the equations that assert that m and n commute with each other. (See <a href="_flatten.html" title="flatten a list by unnesting lists">flatten</a>.)<table class="examples"><tr><td><pre>i65 : j = flatten(m*n - n*m) o65 = | t_4u_2+t_7u_3-t_2u_4-t_3u_7 t_2u_1-t_1u_2+t_5u_2+t_8u_3-t_2u_5-t_3u_8 ----------------------------------------------------------------------- t_3u_1+t_6u_2-t_1u_3+t_9u_3-t_2u_6-t_3u_9 ----------------------------------------------------------------------- -t_4u_1+t_1u_4-t_5u_4+t_4u_5+t_7u_6-t_6u_7 -t_4u_2+t_2u_4+t_8u_6-t_6u_8 ----------------------------------------------------------------------- -t_4u_3+t_3u_4+t_6u_5-t_5u_6+t_9u_6-t_6u_9 ----------------------------------------------------------------------- -t_7u_1-t_8u_4+t_1u_7-t_9u_7+t_4u_8+t_7u_9 ----------------------------------------------------------------------- -t_7u_2-t_8u_5+t_2u_7+t_5u_8-t_9u_8+t_8u_9 -t_7u_3-t_8u_6+t_3u_7+t_6u_8 ----------------------------------------------------------------------- | 1 9 o65 : Matrix S <--- S</pre> </td></tr> </table> Let's compute a Gröbner basis for the image of <tt>j</tt> with <a href="_gb.html" title="compute a Gröbner basis">gb</a>.<table class="examples"><tr><td><pre>i66 : gb j o66 = GroebnerBasis[status: done; S-pairs encountered up to degree 5] o66 : GroebnerBasis</pre> </td></tr> </table> The resulting Gröbner basis contains a lot of information. We can get the generators of the basis, and even though we call upon <a href="_gb.html" title="compute a Gröbner basis">gb</a> again, the computation will not be repeated.<table class="examples"><tr><td><pre>i67 : generators gb j; 1 26 o67 : Matrix S <--- S</pre> </td></tr> </table> 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.<p/> We can use <a href="_betti.html" title="display degrees">betti</a> to see the degrees involved in the Gröbner basis.<table class="examples"><tr><td><pre>i68 : betti gb j 0 1 o68 = total: 1 26 0: 1 . 1: . 8 2: . 12 3: . 5 4: . 1 o68 : BettiTally</pre> </td></tr> </table> </div> </div> </body> </html>