[next][previous][up][top][index]
search for:

Getting started

The best way to run Macaulay 2 is with emacs - for details on getting that set up, see emacs. (On MacOS systems, we include a shareware editor called alpha for this purpose.) Learning emacs is worth the effort! Alternatively, you may start Macaulay 2 with the command M2 in a shell window. On most systems Macaulay 2 will start very quickly, but other parts of the program may have to be loaded from the disk later, causing a slight delay.

Your first input prompt will be i1 : . In response to the prompt, type 2+2 and press return. The expression you entered will be evaluated -- no punctuation is required at the end of the line.

i1 : 2+2

o1 = 4

The answer is displayed to the right of the output label o1 =.

Here is some arithmetic with fractions.

i2 : 3/5 + 7/11

     68
o2 = --
     55

o2 : QQ

Notice the additional line of output labelled with o2 :. Output lines labelled with colons provide information about the type of output. In this case, the symbol QQ is our notation for the class of all rational numbers, and indicates that the answer on the previous line is a rational number.

Multiplication is indicated with *.

i3 : 1*2*3*4

o3 = 24

Powers are obtained with ^.

i4 : 2^200

o4 = 1606938044258990275541962092341162602522202993782792835301376

Factorials are obtained with !.

i5 : 40!

o5 = 815915283247897734345611269596115894272000000000

Because some answers can be very long, it is a good idea to run the program in a window which does not wrap output lines, and allows the user to scroll left horizontally to see the rest of the output. (See emacs.)

i6 : 100!

o6 = 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000

Multiple expressions may be separated by semicolons.

i7 : 1;2;3*4

o9 = 12

A semicolon at the end of the line suppresses the printing of the value.

i10 : 4*5;

The output from the previous line can be obtained with oo, even if a semicolon prevented it from being printed.

i11 : oo

o11 = 20

Lines before that can be obtained with ooo and oooo. Alternatively, the symbol labeling an output line can be used to retrieve the value, as in the following example.

i12 : o5 + 1

o12 = 815915283247897734345611269596115894272000000001

To enter a string, use quotation marks.

i13 : "hi there"

o13 = hi there

A value can be assigned to a variable with =.

i14 : s = "hi there"

o14 = hi there

Strings may be concatenated horizontally with |, (see String | String).

i15 : s | " - " | s

o15 = hi there - hi there

or vertically with ||, (see Net || Net).

i16 : s || " - " || s

o16 = hi there
       - 
      hi there

A list of expressions can be formed with braces.

i17 : {1, 2, s}

o17 = {1, 2, hi there}

o17 : List

Lists behave like vectors.

i18 : 10*{1,2,3} + {1,1,1}

o18 = {11, 21, 31}

o18 : List

A function can be created with the arrow operator, -> .

i19 : f = i -> i^3

o19 = f

o19 : Function

To evaluate a function, place its argument to the right of the function.

i20 : f 5

o20 = 125

Functions of more than one variable take a parenthesized sequence of arguments.

i21 : g = (x,y) -> x * y

o21 = g

o21 : Function
i22 : g(6,9)

o22 = 54

The function apply can be used to apply a function to each element of a list.

i23 : apply({1,2,3,4}, i -> i^2)

o23 = {1, 4, 9, 16}

o23 : List
i24 : apply({1,2,3,4}, f)

o24 = {1, 8, 27, 64}

o24 : List

The operator .. may be used to generate sequences of consecutive numbers.

i25 : apply(1 .. 4, f)

o25 = (1, 8, 27, 64)

o25 : Sequence

If the first argument to apply is an integer n then it stands for the list {0, 1, ..., n-1}.

i26 : apply(5, f)

o26 = {0, 1, 8, 27, 64}

o26 : List

The function scan is analogous to apply except that no value is returned. It may be used to implement loops in programs.

i27 : scan(5, i -> print (i, i^3))
(0, 0)
(1, 1)
(2, 8)
(3, 27)
(4, 64)

i28 : j=1; scan(10, i -> j = 2*j); j

o30 = 1024

Most computations with polynomials take place in rings that may be specified in usual mathematical notation.

i31 : R = ZZ/5[x,y,z];

(We reserve single letter symbols such as Z for use as variables in rings, hence we must use something like ZZ to stand for the ring of integers. It may remind you of the "blackboard bold" font of AMSTeX. If you prefer Z to ZZ, you may put Z=ZZ in your initialization file.)

i32 : (x+y)^5

       5    5
o32 = x  + y

o32 : R

Rings and certain other types of things acquire the name of the global variable they are assigned to.

i33 : R

o33 = R

o33 : PolynomialRing

To see the original description of a ring, use describe.

i34 : describe R

      ZZ
o34 = -- [x, y, z]
       5

A free module can be created as follows.

i35 : F = R^3

       3
o35 = R

o35 : R-module, free

The i-th basis element of F can be obtained as F_i. In this example, the valid values for i are 0, 1, and 2.

i36 : F_1

o36 = <1>

       3
o36 : R

Using a list of indices instead will produce the homomorphism corresponding to the basis vectors indicated.

i37 : F_{1,2}

o37 = | 0 0 |
      | 1 0 |
      | 0 1 |

              3       2
o37 : Matrix R  <--- R

Repetitions are allowed.

i38 : F_{2,1,1}

o38 = | 0 0 0 |
      | 0 1 1 |
      | 1 0 0 |

              3       3
o38 : Matrix R  <--- R

We can create a homomorphism between free modules with matrix by providing the list of rows of the matrix, each of which is in turn a list of ring elements.

i39 : f = matrix {{x,y,z}}

o39 = | x y z |

              1       3
o39 : Matrix R  <--- R

Use image to get the image of f.

i40 : image f

o40 = image | x y z |

                              1
o40 : R-module, submodule of R

We may use ideal to produce the corresponding ideal.

i41 : ideal (x,y,z)

o41 = ideal (x, y, z)

o41 : Ideal of R

We may use kernel to compute the kernel of f.

i42 : kernel f

o42 = image {1} | 0  -y -z |
            {1} | -z x  0  |
            {1} | y  0  x  |

                              3
o42 : R-module, submodule of R

The answer comes out as a module which is expressed as the image of a homomorphism whose matrix is displayed. In case the matrix itself is desired, it can be obtained with generators.

i43 : generators oo

o43 = {1} | 0  -y -z |
      {1} | -z x  0  |
      {1} | y  0  x  |

              3       3
o43 : Matrix R  <--- R

We may use poincare to compute the Poincare polynomial.

i44 : poincare kernel f

         2     3
o44 = 3$T  - $T

o44 : ZZ[ZZ^1]

We may use rank to compute the rank.

i45 : rank kernel f

o45 = 2

A presentation for the kernel can be obtained with presentation.

i46 : presentation kernel f

o46 = {2} | x  |
      {2} | z  |
      {2} | -y |

              3       1
o46 : Matrix R  <--- R

We can produce the cokernel with cokernel; no computation is performed.

i47 : cokernel f

o47 = cokernel | x y z |

                             1
o47 : R-module, quotient of R

The direct sum is formed with Module ++ Module.

i48 : N = kernel f ++ cokernel f

o48 = subquotient ({1} | 0  -y -z 0 |, {1} | 0 0 0 |)
                   {1} | -z x  0  0 |  {1} | 0 0 0 |
                   {1} | y  0  x  0 |  {1} | 0 0 0 |
                   {0} | 0  0  0  1 |  {0} | x y z |

                                4
o48 : R-module, subquotient of R

The answer is expressed in terms of the 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 generators and relations.

i49 : generators N

o49 = {1} | 0  -y -z 0 |
      {1} | -z x  0  0 |
      {1} | y  0  x  0 |
      {0} | 0  0  0  1 |

              4       4
o49 : Matrix R  <--- R
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

The function prune can be used to convert a subquotient module to a quotient module.

i51 : prune N

o51 = cokernel {2} | 0 0 0 -y |
               {2} | 0 0 0 z  |
               {2} | 0 0 0 x  |
               {0} | z y x 0  |

                             4
o51 : R-module, quotient of R

We can use resolution to compute a projective resolution of the cokernel of f.

i52 : C = resolution cokernel f

       1      3      3      1
o52 = R  <-- R  <-- R  <-- R  <-- 0
                                   
      0      1      2      3      4

o52 : ChainComplex

To see the differentials we examine 'C.dd'.

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

We can verify that C is a complex by squaring the differential map.

i54 : C.dd^2 == 0

o54 = true

We can use betti to see the degrees of the components of C.

i55 : betti C

o55 = total: 1 3 3 1
          0: 1 3 3 1

Let's try a harder example. We can use vars to create a sequence of variables.

i56 : R = ZZ/101[a .. r];

We use genericMatrix to make a 3 by 6 generic matrix whose entries are drawn from the variables of the ring R.

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

Then we construct its cokernel with cokernel.

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

We may use resolution to produce a projective resolution of it, and time to report the time required.

i59 : time C = resolution M
     -- used 0.02 seconds

       3      6      15      18      6
o59 = R  <-- R  <-- R   <-- R   <-- R  <-- 0
                                            
      0      1      2       3       4      5

o59 : ChainComplex

As before, we may examine the degrees of its components, or display it.

i60 : betti C

o60 = total: 3 6 15 18 6
          0: 3 6  .  . .
          1: . .  .  . .
          2: . . 15 18 6

We can make a polynomial ring with 18 IndexedVariables.

i61 : S = ZZ/101[t_1 .. t_9, u_1 .. u_9];

We can use genericMatrix to pack the variables into 3-by-3 matrices.

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
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

We may look at the matrix product.

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

Let's produce the equations generated by the equations which assert that m and n commute with each other. (See flatten.)

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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2t_3t_4t_8u_6+t_1t_2t_6t_8u_6+t_3^2t_7t_8u_6+t_3t_6t_8^2u_6-t_2t_3t_7t_9u_6-t_2t_6t_8t_9u_6-t_2t_3t_5t_6u_7+t_2^2t_6^2u_7-t_3^2t_6t_8u_7+t_2t_3t_6t_9u_7-t_3^2t_4t_5u_8+t_2t_3t_4t_6u_8+t_1t_3t_5t_6u_8-t_3t_5^2t_6u_8-t_1t_2t_6^2u_8+t_2t_5t_6^2u_8-t_3t_6^2t_8u_8+t_3^2t_4t_9u_8-t_1t_3t_6t_9u_8+t_3t_5t_6t_9u_8-t_3^2t_4t_8u_9+t_1t_3t_6t_8u_9-t_3t_5t_6t_8u_9+t_2t_6^2t_8u_9 |

o66 : GroebnerBasis

The resulting Groebner basis contains a lot of information. We can get the generators of the basis, and even though we call upon gb again, the computation will not be repeated.

i67 : generators gb j;

              1       26
o67 : Matrix S  <--- S

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.

We can use betti to see the degrees involved in the Groebner basis.

i68 : betti gb j

o68 = total: 1 26
          0: 1  .
          1: .  8
          2: . 12
          3: .  5
          4: .  1


[next][previous][up][top][index]
search for: