Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > 7ebd25ac536d248d499a3ce2acda963a > files > 1304

Macaulay2-1.3.1-8.fc15.i686.rpm

<?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>BeginningMacaulay2 -- Mathematicians' Introduction to  Macaulay2</title>
<link rel="stylesheet" type="text/css" href="../../../../Macaulay2/Style/doc.css"/>
</head>
<body>
<table class="buttons">
  <tr>
    <td><div>next | previous | forward | backward | up | top | <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>
<hr/>
<div><h1>BeginningMacaulay2 -- Mathematicians' Introduction to  Macaulay2</h1>
<div class="single"><h2>Description</h2>
<div><div>We assume you&rsquo;ve installed <em>Macaulay2</em> and can type</div>
<table class="examples"><tr><td><pre>M2</pre>
</td></tr>
</table>
<div>on a command line to bring up the program. You should see something like:</div>
<table class="examples"><tr><td><pre>Macaulay2, version 1.3
with packages: ConwayPolynomials, Elimination, IntegralClosure, LLLBases,
       PrimaryDecomposition, ReesAlgebra, SchurRings, TangentCone</pre>
</td></tr>
</table>
<p>We suggest you do that now, so that you can experiment while you read this tutorial!</p>
<p></p>
<div/>
<h2>Arithmetic with integers, rings and ideals</h2>
<div>You can immediately do arithmetic with integers:</div>
<table class="examples"><tr><td><pre>i1 : 2+2

o1 = 4</pre>
</td></tr>
<tr><td><pre>i2 : 107*431

o2 = 46117</pre>
</td></tr>
<tr><td><pre>i3 : 25!

o3 = 15511210043330985984000000</pre>
</td></tr>
<tr><td><pre>i4 : binomial(5,4)

o4 = 5</pre>
</td></tr>
<tr><td><pre>i5 : factor 32004

      2 2
o5 = 2 3 7*127

o5 : Expression of class Product</pre>
</td></tr>
</table>
<p></p>
<div>Most <em>Macaulay2</em> applications involve polynomial rings over fields and their quotient rings. Fields can be made in various ways:</div>
<table class="examples"><tr><td><pre>i6 : ZZ/101

      ZZ
o6 = ---
     101

o6 : QuotientRing</pre>
</td></tr>
<tr><td><pre>i7 : QQ

o7 = QQ

o7 : Ring</pre>
</td></tr>
<tr><td><pre>i8 : GF 2^5

o8 = GF 32

o8 : GaloisField</pre>
</td></tr>
<tr><td><pre>i9 : k = toField (QQ[i]/(i^2+1))

o9 = k

o9 : PolynomialRing</pre>
</td></tr>
</table>
<div>After making <tt>k</tt> we can compute in it:</div>
<table class="examples"><tr><td><pre>i10 : 1/i

o10 = -i

o10 : k</pre>
</td></tr>
</table>
<p></p>
<p>Computation is often fastest and needs least memory when performed over finite prime fields of the form <i>&#x2124;/p</i>. Fortunately, when the characteristic <i>p</i> is not too small, qualitative questions often have similar answers over <i>&#x2124;/p</i> and over <i>&#x211A;</i>, so we mostly use the former. In <em>Macaulay2</em> the prime <i>p</i> can range up to 32749.</p>
<div>We make a polynomial ring in 5 variables over <i>&#x2124;/101</i>:</div>
<table class="examples"><tr><td><pre>i11 : kk=ZZ/101

o11 = kk

o11 : QuotientRing</pre>
</td></tr>
<tr><td><pre>i12 : S=kk[x_1..x_5]

o12 = S

o12 : PolynomialRing</pre>
</td></tr>
</table>
<div>Here is another way:</div>
<table class="examples"><tr><td><pre>i13 : S=kk[a,b,c,d,e]

o13 = S

o13 : PolynomialRing</pre>
</td></tr>
</table>
<div>One can do arithmetic on polynomials:</div>
<table class="examples"><tr><td><pre>i14 : (3*a^2+1)^5

         10    8      6      4      2
o14 = 41a   + a  - 33a  - 11a  + 15a  + 1

o14 : S</pre>
</td></tr>
</table>
<p></p>
<div>We make an ideal in <i>S</i>:</div>
<table class="examples"><tr><td><pre>i15 : I=ideal(a^3-b^3, a+b+c+d+e)

              3    3
o15 = ideal (a  - b , a + b + c + d + e)

o15 : Ideal of S</pre>
</td></tr>
</table>
<div>Using this ideal, we can make a factor ring:</div>
<table class="examples"><tr><td><pre>i16 : R=S/I

o16 = R

o16 : QuotientRing</pre>
</td></tr>
</table>
<div>Another way to make an ideal, with more compact notation (familiar to anyone who used the classic Macaulay) is:</div>
<table class="examples"><tr><td><pre>i17 : use S

o17 = S

o17 : PolynomialRing</pre>
</td></tr>
<tr><td><pre>i18 : I=ideal"3(a+b)3, 4c5"

               3     2        2     3    5
o18 = ideal (3a  + 9a b + 9a*b  + 3b , 4c )

o18 : Ideal of S</pre>
</td></tr>
</table>
<p>Note the command &ldquo;<tt>use S</tt>&rdquo;, which specifies that we want to work with the generators of the polynomial ring S again; otherwise the variables <tt>a</tt>, <tt>b</tt>, and <tt>c</tt> would still have had values in <i>R</i> instead of in <i>S</i>.</p>
<div>Algebraic operations on ideals are available:</div>
<table class="examples"><tr><td><pre>i19 : I^2

               6      5       4 2      3 3      2 4        5     6     3 5  
o19 = ideal (9a  - 47a b + 34a b  - 22a b  + 34a b  - 47a*b  + 9b , 12a c  +
      -----------------------------------------------------------------------
         2   5        2 5      3 5     10
      36a b*c  + 36a*b c  + 12b c , 16c  )

o19 : Ideal of S</pre>
</td></tr>
<tr><td><pre>i20 : I*I

               6      5       4 2      3 3      2 4        5     6     3 5  
o20 = ideal (9a  - 47a b + 34a b  - 22a b  + 34a b  - 47a*b  + 9b , 12a c  +
      -----------------------------------------------------------------------
         2   5        2 5      3 5     3 5      2   5        2 5      3 5 
      36a b*c  + 36a*b c  + 12b c , 12a c  + 36a b*c  + 36a*b c  + 12b c ,
      -----------------------------------------------------------------------
         10
      16c  )

o20 : Ideal of S</pre>
</td></tr>
<tr><td><pre>i21 : I+ideal"a2"

               3     2        2     3    5   2
o21 = ideal (3a  + 9a b + 9a*b  + 3b , 4c , a )

o21 : Ideal of S</pre>
</td></tr>
</table>
<p></p>
<div>In case you forget any of these things, <a href="../../Macaulay2Doc/html/_help.html" title="help command">help</a> is available! The most useful way to get it is often to type something like:</div>
<table class="examples"><tr><td><pre>viewHelp ideal</pre>
</td></tr>
</table>
<p>Then a browser window will pop up that contains documentation about the function <a href="../../Macaulay2Doc/html/_ideal.html" title="make an ideal">ideal</a> that we&rsquo;ve been using; links on that page allow one to explore all of the <em>Macaulay2</em> documentation.</p>
<div>On the other hand, we might have wanted information about the <a href="../../Macaulay2Doc/html/_class.html" title="class of an object">class</a> of all ideals. Not too surprisingly, this class is called <a href="../../Macaulay2Doc/html/___Ideal.html" title="the class of all ideals">Ideal</a>. We could get information about what functions create or use ideals by typing:</div>
<table class="examples"><tr><td><pre>viewHelp Ideal</pre>
</td></tr>
</table>
<p>To see the names of classes, you can begin by looking at the output of commands; the second line output (the one introduced by a colon) often contains the name of the class of the result.</p>
<div>Here are some basic operations on matrices:</div>
<table class="examples"><tr><td><pre>i22 : M= matrix{{a,b,c},{b,c,d},{c,d,e}}

o22 = | a b c |
      | b c d |
      | c d e |

              3       3
o22 : Matrix S  &lt;--- S</pre>
</td></tr>
<tr><td><pre>i23 : M^2

o23 = | a2+b2+c2 ab+bc+cd ac+bd+ce |
      | ab+bc+cd b2+c2+d2 bc+cd+de |
      | ac+bd+ce bc+cd+de c2+d2+e2 |

              3       3
o23 : Matrix S  &lt;--- S</pre>
</td></tr>
<tr><td><pre>i24 : determinant M

         3               2    2
o24 = - c  + 2b*c*d - a*d  - b e + a*c*e

o24 : S</pre>
</td></tr>
<tr><td><pre>i25 : trace M

o25 = a + c + e

o25 : S</pre>
</td></tr>
<tr><td><pre>i26 : M-transpose M

o26 = 0

              3       3
o26 : Matrix S  &lt;--- S</pre>
</td></tr>
</table>
<div>The function <a href="../../Macaulay2Doc/html/_entries.html" title="lists the entries of a matrix">entries</a> gives the entries of a matrix:</div>
<table class="examples"><tr><td><pre>i27 : entries M

o27 = {{a, b, c}, {b, c, d}, {c, d, e}}

o27 : List</pre>
</td></tr>
</table>
<div>The result is a list of lists, one for each row of the matrix <i>M</i>. The function <a href="../../Macaulay2Doc/html/_flatten.html" title="flatten a list by unnesting lists">flatten</a> can be used to merge the lists into a single list:</div>
<table class="examples"><tr><td><pre>i28 : flatten entries M

o28 = {a, b, c, b, c, d, c, d, e}

o28 : List</pre>
</td></tr>
</table>
<div>If you want a particular entry, say the one in the upper left corner, you can use the underscore operator <a href="../../Macaulay2Doc/html/___Matrix_sp_us_sp__Sequence.html">_</a>:</div>
<table class="examples"><tr><td><pre>i29 : M_(0,0)

o29 = a

o29 : S</pre>
</td></tr>
</table>
<div>Here, as everywhere in <em>Macaulay2</em>, all indexing starts with 0. For example:</div>
<table class="examples"><tr><td><pre>i30 : I_0

        3     2        2     3
o30 = 3a  + 9a b + 9a*b  + 3b

o30 : S</pre>
</td></tr>
</table>
<div>is the first generator of I. You can list all the generators with:</div>
<table class="examples"><tr><td><pre>i31 : I_*

         3     2        2     3    5
o31 = {3a  + 9a b + 9a*b  + 3b , 4c }

o31 : List</pre>
</td></tr>
</table>
<p></p>
<div>A <em>module</em> can be defined as a cokernel, kernel, image, or even as a subquotient:</div>
<table class="examples"><tr><td><pre>i32 : coker M

o32 = cokernel | a b c |
               | b c d |
               | c d e |

                             3
o32 : S-module, quotient of S</pre>
</td></tr>
<tr><td><pre>i33 : image M

o33 = image | a b c |
            | b c d |
            | c d e |

                              3
o33 : S-module, submodule of S</pre>
</td></tr>
<tr><td><pre>i34 : kernel matrix"a,b,0;0,a,b"

o34 = image {1} | b2  |
            {1} | -ab |
            {1} | a2  |

                              3
o34 : S-module, submodule of S</pre>
</td></tr>
<tr><td><pre>i35 : N = matrix{{a,b},{b,c},{c,d}}

o35 = | a b |
      | b c |
      | c d |

              3       2
o35 : Matrix S  &lt;--- S</pre>
</td></tr>
<tr><td><pre>i36 : (image M)/(image N)

o36 = subquotient (| a b c |, | a b |)
                   | b c d |  | b c |
                   | c d e |  | c d |

                                3
o36 : S-module, subquotient of S</pre>
</td></tr>
<tr><td><pre>i37 : subquotient(M,N)

o37 = subquotient (| a b c |, | a b |)
                   | b c d |  | b c |
                   | c d e |  | c d |

                                3
o37 : S-module, subquotient of S</pre>
</td></tr>
</table>
<p>Note that the matrix <i>N</i> above was defined with an alternate syntax, parallel to the alternate syntax for <a href="../../Macaulay2Doc/html/_ideal.html" title="make an ideal">ideal</a>.</p>
<div>Before going on, the reader might want to explore a bit. A good place to start is the top of the documentation tree, which can be reached, for example, by typing:</div>
<table class="examples"><tr><td><pre>viewHelp Macaulay2Doc</pre>
</td></tr>
</table>
<p></p>
<p></p>
<div/>
<h2>Properties of ideals and modules</h2>
<div>To compute the Gröbner basis of an ideal <i>(x<sup>2</sup>y,xy<sup>2</sup>+x<sup>3</sup>)</i> in the polynomial ring in four variables we proceed as follows. First we make our favorite field:</div>
<table class="examples"><tr><td><pre>i38 : kk = ZZ/32003

o38 = kk

o38 : QuotientRing</pre>
</td></tr>
</table>
<div>Then the polynomial ring:</div>
<table class="examples"><tr><td><pre>i39 : R = kk[x,y,z,w]

o39 = R

o39 : PolynomialRing</pre>
</td></tr>
</table>
<div>And then the ideal:</div>
<table class="examples"><tr><td><pre>i40 : I = ideal(x^2*y,x*y^2+x^3)

              2    3      2
o40 = ideal (x y, x  + x*y )

o40 : Ideal of R</pre>
</td></tr>
</table>
<div>Now the punch line.  We compute the Gröbner basis with the <a href="../../Macaulay2Doc/html/_groebner__Basis.html" title="Gröbner basis, as a matrix">groebnerBasis</a> function:</div>
<table class="examples"><tr><td><pre>i41 : J = groebnerBasis I

o41 = | x2y x3+xy2 xy3 |

              1       3
o41 : Matrix R  &lt;--- R</pre>
</td></tr>
</table>
<p></p>
<div>Gr&ouml;bner bases are always computed with respect to a particular monomial order on the ring. In fact, the ring we defined above has a default monomial order, the graded reverse lex order. For many other possibilities, see <a href="../../Macaulay2Doc/html/___Monomial__Order.html" title="monomial ordering">MonomialOrder</a>, or type:</div>
<table class="examples"><tr><td><pre>viewHelp MonomialOrder</pre>
</td></tr>
</table>
<p></p>
<div>The analogue of factorization in the theory of ideals is primary decomposition. For example, we can begin by intersecting three ideals:</div>
<table class="examples"><tr><td><pre>i42 : I= intersect (ideal"x2,y3", ideal"y2,z3", (ideal"x,y,z")^4)

              3    4     3   2 2   2 3
o42 = ideal (y z, y , x*y , x y , x z )

o42 : Ideal of R</pre>
</td></tr>
</table>
<div>We can almost undo this operation by computing a primary decomposition:</div>
<table class="examples"><tr><td><pre>i43 : primaryDecomposition I

               2   3           2   3              4
o43 = {ideal (x , y ), ideal (y , z ), ideal (x, y , z)}

o43 : List</pre>
</td></tr>
</table>
<p>Inspecting the output, we see that the first two ideals are the same as the first two ideals we intersected, but the third one differs from the corresponding input ideal. This is because only the primary components corresponding to minimal primes (here, the first two) are unique. All three of the input ideals are primary, so they constitute a primary decomposition of <i>I</i> different from the one provided by <em>Macaulay2</em> on the output line.</p>
<div>For larger examples, primary decomposition is computationally challenging! Sometimes it is easier to compute just the minimal primes. To do this we can use <a href="../../Macaulay2Doc/html/_minimal__Primes.html" title="minimal associated primes of an ideal">decompose</a>:</div>
<table class="examples"><tr><td><pre>i44 : decompose I

o44 = {ideal (y, x), ideal (y, z)}

o44 : List</pre>
</td></tr>
</table>
<p></p>
<div>Using Gröbner bases we can compute codimensions, dimensions, degrees, Hilbert functions, and Hilbert polynomials. This will be more fun if we work with a meaningful example.  We will use the ideal defining the smooth rational quartic curve in <i>&#x2119;<sup>3</sup></i> given parametrically (in an affine representation) by <p align=center><i>t &rarr; (t,t<sup>3</sup>,t<sup>4</sup>).</i></p> (The reader more interested in algebra than geometry may simply treat the ideal given below as a gift from the gods.) First we make the polynomial ring in 4 variables, to serve as the homogeneous coordinate ring of <i>&#x2119;<sup>3</sup></i>:</div>
<table class="examples"><tr><td><pre>i45 : R = kk[a..d]

o45 = R

o45 : PolynomialRing</pre>
</td></tr>
</table>
<div>We introduce the ring map <i>&phi;: R &rarr;kk[s,t]</i> defined by <i>(a,b,c,d) &rarr; (s<sup>4</sup>, s<sup>3</sup> t, s t<sup>3</sup>, t<sup>4</sup>)</i>:</div>
<table class="examples"><tr><td><pre>i46 : phi = map(kk[s,t],R,{s^4, s^3*t, s*t^3, t^4})

                       4   3      3   4
o46 = map(kk[s, t],R,{s , s t, s*t , t })

o46 : RingMap kk[s, t] &lt;--- R</pre>
</td></tr>
</table>
<div>Here the syntax of the function <a href="../../Macaulay2Doc/html/_map_lp__Ring_cm__Ring_cm__List_rp.html">map</a> has the target ring first and the source ring second: maps in <em>Macaulay2</em> generally go from right to left! The last input to the command is a list of the elements to which to send the variables of the source ring. The ideal we want is the kernel of this map:</div>
<table class="examples"><tr><td><pre>i47 : I = ker phi

                         3      2     2    2    3    2
o47 = ideal (b*c - a*d, c  - b*d , a*c  - b d, b  - a c)

o47 : Ideal of R</pre>
</td></tr>
</table>
<div>Shortcut notation for this construction is provided by the function <a href="../../Macaulay2Doc/html/_monomial__Curve__Ideal.html" title="make the ideal of a monomial curve">monomialCurveIdeal</a>:</div>
<table class="examples"><tr><td><pre>i48 : I = monomialCurveIdeal(R,{1,3,4})

                         3      2     2    2    3    2
o48 = ideal (b*c - a*d, c  - b*d , a*c  - b d, b  - a c)

o48 : Ideal of R</pre>
</td></tr>
</table>
<div>We can compute the <a href="../../Macaulay2Doc/html/_dim_lp__Ideal_rp.html">dimension</a>, <a href="../../Macaulay2Doc/html/_codim_lp__Ideal_rp.html">codimension</a> (also called the height) and <a href="../../Macaulay2Doc/html/_degree_lp__Ideal_rp.html">degree</a> of this ideal:</div>
<table class="examples"><tr><td><pre>i49 : dim I

o49 = 2</pre>
</td></tr>
<tr><td><pre>i50 : codim I

o50 = 2</pre>
</td></tr>
<tr><td><pre>i51 : degree I

o51 = 4</pre>
</td></tr>
</table>
<div>The Hilbert polynomial is obtained with the function <a href="../../Macaulay2Doc/html/_hilbert__Polynomial.html" title="compute the Hilbert polynomial">hilbertPolynomial</a>:</div>
<table class="examples"><tr><td><pre>i52 : hilbertPolynomial(R/I)

o52 = - 3*P  + 4*P
           0      1

o52 : ProjectiveHilbertPolynomial</pre>
</td></tr>
</table>
<p>The output above may not be what the user expected: the term <i><b>P</b><sub>m</sub></i> represents the Hilbert polynomial of projective <i>m</i>-space.  Thus the output tells us that the Hilbert polynomial of <i>M</i> is <i>i &rarr; -3*1+4*(i+1) = 4i + 1</i>.  Thus the degree is four, the dimension of the projective variety that is the support of <i>M</i> is 1 (and so the affine dimension is 2), and the (arithmetic) genus is 0 (obtained as 1 minus the constant term of the polynomial.)</p>
<div>The more usual expression for the Hilbert polynomial can be obtained as follows:</div>
<table class="examples"><tr><td><pre>i53 : hilbertPolynomial(R/I, Projective => false)

o53 = 4i + 1

o53 : QQ[i]</pre>
</td></tr>
</table>
<div>The construction <tt>Projective => false</tt> is our first example of an <em>option</em> to a function: we specified that the option <tt>Projective</tt> was to have the value <tt>false</tt>. The form we used first could also have been written this way:</div>
<table class="examples"><tr><td><pre>i54 : hilbertPolynomial(R/I, Projective => true)

o54 = - 3*P  + 4*P
           0      1

o54 : ProjectiveHilbertPolynomial</pre>
</td></tr>
</table>
<div>The Hilbert series of <i>M</i> (the generating function for the dimensions of the graded pieces of <i>M</i>) is obtained with:</div>
<table class="examples"><tr><td><pre>i55 : hilbertSeries (R/I)

           2     3     4    5
      1 - T  - 3T  + 4T  - T
o55 = -----------------------
                     4
              (1 - T)

o55 : Expression of class Divide</pre>
</td></tr>
</table>
<div>This generating function is expressed as a rational function with denominator equal to (1-T)<sup>n</sup>, where n is the number of variables in R. Since R/I has dimension 2, it can also be written with denominator (1-t)<sup>2</sup>. To see it in this form, use <a href="../../Macaulay2Doc/html/_reduce__Hilbert.html" title="reduce a Hilbert series expression">reduceHilbert</a>:</div>
<table class="examples"><tr><td><pre>i56 : reduceHilbert hilbertSeries (R/I)

                 2    3
      1 + 2T + 2T  - T
o56 = -----------------
                  2
           (1 - T)

o56 : Expression of class Divide</pre>
</td></tr>
</table>
<div>It is possible to manipulate the numerator and denominator of this expression. To learn how to do so, see <a href="../../Macaulay2Doc/html/_hilbert__Series.html" title="compute the Hilbert series">hilbertSeries</a> or type:</div>
<table class="examples"><tr><td><pre>viewHelp hilbertSeries</pre>
</td></tr>
</table>
<p></p>
<div>A great deal of subtle information about a module is visible using free resolutions. For an example, we begin by turning <i>R/I</i> into a module. Here the code <tt>R^1</tt> produces the free module of rank 1 over <i>R</i>, and <a href="../../Macaulay2Doc/html/_resolution_lp__Module_rp.html">res</a> computes a free resolution:</div>
<table class="examples"><tr><td><pre>i57 : M=R^1/I

o57 = cokernel | bc-ad c3-bd2 ac2-b2d b3-a2c |

                             1
o57 : R-module, quotient of R</pre>
</td></tr>
<tr><td><pre>i58 : Mres = res M

       1      4      4      1
o58 = R  &lt;-- R  &lt;-- R  &lt;-- R  &lt;-- 0
                                   
      0      1      2      3      4

o58 : ChainComplex</pre>
</td></tr>
</table>
<div>To get more precise information about <tt>Mres</tt>, we could compute its Betti table with <a href="../../Macaulay2Doc/html/_betti_lp__Graded__Module_rp.html">betti</a>:</div>
<table class="examples"><tr><td><pre>i59 : betti Mres

             0 1 2 3
o59 = total: 1 4 4 1
          0: 1 . . .
          1: . 1 . .
          2: . 3 4 1

o59 : BettiTally</pre>
</td></tr>
</table>
<p>The display is chosen for compactness. Each column of the table corresponds to a free module in the resolution. The column&rsquo;s heading specifies the <em>homological degree</em> (the position of the free module in the resolution). The entry just below the homological degree is the rank of the free module, also called the <em>total betti number</em>. The remaining entries in the column tell us how many generators of each degree this free module has: the number in the column labelled <i>j</i> and in the row labelled <i>d</i> tells how many generators of degree <i>j+d</i> the <i>j</i>-th free module has. Thus, in our case, the single generator of the third (and last) free module in the resolution has degree <i>3+2=5</i>.</p>
<div>Commonly computed homological invariants such as <a href="../../Macaulay2Doc/html/_pdim_lp__Module_rp.html">projective dimension</a> and <a href="../../Macaulay2Doc/html/_regularity.html">regularity</a> are (also) available directly:</div>
<table class="examples"><tr><td><pre>i60 : pdim M

o60 = 3</pre>
</td></tr>
<tr><td><pre>i61 : regularity M

o61 = 2</pre>
</td></tr>
</table>
<p></p>
<p></p>
<div/>
<h2>Division With Remainder</h2>
<div>A major application of Gröbner bases is to give the normal form for an element modulo an ideal, allowing one, for example, to decide whether the element is in the ideal. For example, we can decide which power of the trace of a generic 3x3 matrix is expressible in terms of the entries of the cube of the matrix with the following code:</div>
<table class="examples"><tr><td><pre>i62 : R = kk[a..i]

o62 = R

o62 : PolynomialRing</pre>
</td></tr>
<tr><td><pre>i63 : M = genericMatrix(R,a,3,3)

o63 = | a d g |
      | b e h |
      | c f i |

              3       3
o63 : Matrix R  &lt;--- R</pre>
</td></tr>
<tr><td><pre>i64 : I = ideal M^3

              3                                                     2     2 
o64 = ideal (a  + 2a*b*d + b*d*e + 2a*c*g + b*f*g + c*d*h + c*g*i, a b + b d
      -----------------------------------------------------------------------
                   2                                           2           
      + a*b*e + b*e  + b*c*g + a*c*h + c*e*h + b*f*h + c*h*i, a c + b*c*d +
      -----------------------------------------------------------------------
                       2                               2   2       2        
      a*b*f + b*e*f + c g + c*f*h + a*c*i + b*f*i + c*i , a d + b*d  + a*d*e
      -----------------------------------------------------------------------
           2                                                            3  
      + d*e  + c*d*g + a*f*g + e*f*g + d*f*h + f*g*i, a*b*d + 2b*d*e + e  +
      -----------------------------------------------------------------------
                                                               2           
      b*f*g + c*d*h + 2e*f*h + f*h*i, a*c*d + c*d*e + b*d*f + e f + c*f*g +
      -----------------------------------------------------------------------
       2                       2   2               2                        
      f h + c*d*i + e*f*i + f*i , a g + b*d*g + c*g  + a*d*h + d*e*h + f*g*h
      -----------------------------------------------------------------------
                           2                           2               2  
      + a*g*i + d*h*i + g*i , a*b*g + b*e*g + b*d*h + e h + c*g*h + f*h  +
      -----------------------------------------------------------------------
                         2                                                   
      b*g*i + e*h*i + h*i , a*c*g + b*f*g + c*d*h + e*f*h + 2c*g*i + 2f*h*i +
      -----------------------------------------------------------------------
       3
      i )

o64 : Ideal of R</pre>
</td></tr>
</table>
<div>This gives the ideal of entries of the matrix. In the expression &ldquo;<tt>M = genericMatrix(R,a,3,3)</tt>&rdquo; the arguments &ldquo;<tt>R,a,3,3</tt>&rdquo; specify the ring, the first variable to use, and the numbers of rows and columns desired.</div>
<table class="examples"><tr><td><pre>i65 : Tr = trace M

o65 = a + e + i

o65 : R</pre>
</td></tr>
<tr><td><pre>i66 : for p from 1 to 10 do print (Tr^p % I)
a + e + i
 2           2                  2
a  + 2a*e + e  + 2a*i + 2e*i + i
  2                 2     3                                2               2                          2       2     3
3a e + 3b*d*e + 3a*e  + 3e  + 3b*f*g + 3c*d*h + 6e*f*h + 3a i + 6a*e*i + 3e i + 3c*g*i + 6f*h*i + 3a*i  + 3e*i  + 3i
  2 2         2       3     4                                                  2                   2 2      2                       2       3                                                               2 2          2     2 2         2          2       3        3     4
6a e  + 6b*d*e  + 6a*e  + 6e  + 6b*e*f*g + 6c*d*e*h - 6b*d*f*h + 6a*e*f*h + 12e f*h - 6c*f*g*h - 6f h  + 12a e*i + 12b*d*e*i + 12a*e i + 12e i + 12c*e*g*i + 6b*f*g*i + 6c*d*h*i + 6a*f*h*i + 36e*f*h*i + 6a i  + 12a*e*i  + 6e i  + 6c*g*i  + 12f*h*i  + 6a*i  + 12e*i  + 6i
   2 2           2         3       4         2         2                                       2                         2 2       2   2            2        2 2      3 2            2            2             2      2 3          3          3      2 3          3          3        4        4      5
30a e i + 30b*d*e i + 30a*e i + 30e i + 30c*e g*i + 30a f*h*i + 30b*d*f*h*i + 60a*e*f*h*i + 90e f*h*i + 30c*f*g*h*i + 30f h i + 30a e*i  + 30b*d*e*i  + 30a*e i  + 30e i  + 30c*e*g*i  + 60a*f*h*i  + 120e*f*h*i  + 30a i  + 30b*d*i  + 30a*e*i  + 30e i  + 30c*g*i  + 90f*h*i  + 30a*i  + 30e*i  + 30i
   2 2 2          2 2        3 2      4 2        2   2      2     2              2               2       2     2              2      2 2 2      2   3            3        2 3      3 3            3             3             3      2 4          4          4      2 4          4           4        5        5      6
90a e i  + 90b*d*e i  + 90a*e i  + 90e i  + 90c*e g*i  + 90a f*h*i  + 90b*d*f*h*i  + 180a*e*f*h*i  + 270e f*h*i  + 90c*f*g*h*i  + 90f h i  + 90a e*i  + 90b*d*e*i  + 90a*e i  + 90e i  + 90c*e*g*i  + 180a*f*h*i  + 360e*f*h*i  + 90a i  + 90b*d*i  + 90a*e*i  + 90e i  + 90c*g*i  + 270f*h*i  + 90a*i  + 90e*i  + 90i
0
0
0
0</pre>
</td></tr>
</table>
<div>The expression &ldquo;<tt>Tr^p % I</tt>&rdquo; computes the normal form for the p-th power of the trace <tt>Tr</tt> with respect to the Gröbner basis of I. The expression &ldquo;<tt>for p from 1 to 10 do</tt>&rdquo; specifies a <em>for loop</em> that executes the following expression, &ldquo;<tt>print (Tr^p % I)</tt>&rdquo;, with 10 consecutive values of <tt>p</tt>. For more information on such loops see <a href="../../Macaulay2Doc/html/_for.html" title="for loops">for</a> or type:</div>
<table class="examples"><tr><td><pre>viewHelp "for"</pre>
</td></tr>
</table>
<p>Here we have put quotes around &ldquo;for&rdquo; because &ldquo;for&rdquo; is a keyword in the <em>Macaulay2</em> language.  (In general, it&rsquo;s always safe to use quotes with viewHelp.)</p>
<div>We see from the output of these commands that the 6-th power of the trace is NOT in the ideal of entries of the cube of M, but the 7-th power is. We can compute the coefficients in the expression for it using the division algorithm, denoted in this setting by <a href="../../Macaulay2Doc/html/___Matrix_sp_sl_sl_sp__Matrix.html">//</a>:</div>
<table class="examples"><tr><td><pre>i67 : Tr^7//(gens I)

o67 = {3} | a4+7a3e+3abde+21a2e2+21bde2+37ae3+49e4+6aefh+36e2fh-6f2h2+7a3i+42
      {3} | 0                                                                
      {3} | 0                                                                
      {3} | -63abe2-81be3-288bcdh-297ce2h+636befh-264cfh2-189abei-315be2i-276
      {3} | -2a4-14a3e-6abde+21a2e2+30bde2+7ae3+e4+288abfg+939befg+45cdeh-6a2
      {3} | -288b2dg+324abeg+81be2g-288bcg2+3a3h+288abdh+18a2eh+288bdeh+279ae
      {3} | 288bcde-252ace2+282abef-378be2f+288bcfg-264acfh-378cefh+24bf2h-28
      {3} | 3a3f-288abdf-264a2ef-1212bdef+453ae2f-891e3f+333cefg-258cdfh-276a
      {3} | -2a4+288b2d2-14a3e-618abde+210a2e2-132bde2-74ae3-98e4+288bcdg+252
      -----------------------------------------------------------------------
      a2ei+21bdei+105ae2i+154e3i+6afhi+75efhi+21a2i2+105aei2+210e2i2+30fhi2+3
                                                                             
                                                                             
      cehi+1323bfhi-252abi2-504bei2+105chi2-288bi3                           
      fh-672aefh+687e2fh+258cfgh-12f2h2-14a3i+105a2ei+147bdei+42ae2i+7e3i+147
      2h+300e3h+45cegh-546bfgh+276afh2+684efh2+612abgi+834begi+15a2hi+171bdhi
      8bcdi-168acei-504ce2i+540abfi+18befi-1347cfhi-48aci2-336cei2+1482bfi2-9
      f2h-1200ef2h-147cdei-525a2fi-2070bdfi+426aefi-1122e2fi+666cfgi-2169f2hi
      ce2g-288abfg-939befg-45cdeh+258a2fh+810bdfh+612aefh-255e2fh+264cfgh+540
      -----------------------------------------------------------------------
      7ai3+154ei3+46i4                                                       
                                                                             
                                                                             
                                                                             
      cegi+1530bfgi+153cdhi-1365afhi+1581efhi+210a2i2+252bdi2+105aei2+21e2i2+
      +159aehi+510e2hi+153cghi+1101fh2i+624bgi2-324ahi2+360ehi2+210hi3       
      6ci3                                                                   
      -240cdi2-1497afi2+528efi2-567fi3                                       
      f2h2-11a3i-324abdi+105a2ei-510bdei+105ae2i-197e3i+168cegi-1530bfgi-153c
      -----------------------------------------------------------------------
                                                                            
                                                                            
                                                                            
                                                                            
      240cgi2+639fhi2+214ai3+133ei3+232i4                                   
                                                                            
                                                                            
                                                                            
      dhi+1593afhi-1143efhi+21a2i2+42aei2+21e2i2+48cgi2+123fhi2+7ai3+7ei3+i4
      -----------------------------------------------------------------------
      |
      |
      |
      |
      |
      |
      |
      |
      |

              9       1
o67 : Matrix R  &lt;--- R</pre>
</td></tr>
</table>
<p></p>
<p></p>
<div/>
<h2>Elimination Theory</h2>
<div>Consider the problem of projecting the &ldquo;twisted cubic&rdquo;, a curve in <i>&#x2119;<sup>3</sup></i> defined by the three <i>2 &times; 2</i> minors of a certain <i>2 &times; 3</i> matrix. We already have the simplest tools for solving such a problem. We first clear the earlier meaning of <tt>x</tt> to allow it to be used as a subscripted variable:</div>
<table class="examples"><tr><td><pre>i68 : x = symbol x

o68 = x

o68 : Symbol</pre>
</td></tr>
</table>
<div>Since we are going to deal with a curve in <i>&#x2119;<sup>3</sup></i>, we begin with a polynomial ring in four variables:</div>
<table class="examples"><tr><td><pre>i69 : R = kk[x_0..x_3]

o69 = R

o69 : PolynomialRing</pre>
</td></tr>
</table>
<div>The ideal of the twisted cubic curve is generated by the <i>2 &times; 2</i> minors of a &ldquo;catalecticant" or &ldquo;Hankel" matrix, conveniently defined as follows:</div>
<table class="examples"><tr><td><pre>i70 : M = map(R^2, 3, (i,j)->x_(i+j))

o70 = | x_0 x_1 x_2 |
      | x_1 x_2 x_3 |

              2       3
o70 : Matrix R  &lt;--- R</pre>
</td></tr>
<tr><td><pre>i71 : I = minors(2,M)

                2                           2
o71 = ideal (- x  + x x , - x x  + x x , - x  + x x )
                1    0 2     1 2    0 3     2    1 3

o71 : Ideal of R</pre>
</td></tr>
</table>
<div>As projection center we take the point with homogeneous coordinates <i>(1,0,0,-1)</i>, which is defined by the ideal:</div>
<table class="examples"><tr><td><pre>i72 : pideal = ideal(x_0+x_3, x_1, x_2)

o72 = ideal (x  + x , x , x )
              0    3   1   2

o72 : Ideal of R</pre>
</td></tr>
</table>
<div>The ideal J of the image of the curve under the projection from this point is the kernel of the ring map <i>S=kk[u,v,w] &rarr;R/I</i> sending the variables of S to the generators of <tt>pIdeal</tt>, regarded as elements of <i>R/I</i>.  This is the same as the more usual formulation: <p align=center><i>J = I &cap; kk[x<sub>0</sub>+x<sub>3</sub>, x<sub>1</sub>, x<sub>x</sub>]</i></p> To compute this we first substitute <tt>pIdeal</tt> into <i>R/I</i>, and then form the necessary ring map:</div>
<table class="examples"><tr><td><pre>i73 : Rbar = R/I

o73 = Rbar

o73 : QuotientRing</pre>
</td></tr>
<tr><td><pre>i74 : pideal = substitute(pideal, Rbar)

o74 = ideal (x  + x , x , x )
              0    3   1   2

o74 : Ideal of Rbar</pre>
</td></tr>
<tr><td><pre>i75 : S = kk[u,v,w]

o75 = S

o75 : PolynomialRing</pre>
</td></tr>
<tr><td><pre>i76 : J=kernel map (Rbar, S, gens pideal)

             3            3
o76 = ideal(v  - u*v*w + w )

o76 : Ideal of S</pre>
</td></tr>
</table>
<div>The ideal J defines a curve with one singular point. We can compute the ideal of the singular locus with:</div>
<table class="examples"><tr><td><pre>i77 : K = ideal singularLocus(J)

              3            3          2                  2
o77 = ideal (v  - u*v*w + w , -v*w, 3v  - u*w, - u*v + 3w )

o77 : Ideal of S</pre>
</td></tr>
</table>
<div>This doesn&rsquo;t look like the ideal of a reduced point! But that&rsquo;s because it isn&rsquo;t yet saturated:</div>
<table class="examples"><tr><td><pre>i78 : saturate K

o78 = ideal (w, v)

o78 : Ideal of S</pre>
</td></tr>
</table>
<div>We have just seen the <a href="../../Macaulay2Doc/html/_saturate.html" title="saturation of ideal or submodule">saturate</a> function in its most common use: to saturate with respect to the maximal ideal. but we can also find the saturation of any ideal with respect to another:</div>
<table class="examples"><tr><td><pre>i79 : saturate (ideal"u3w,uv", ideal"u")

o79 = ideal (w, v)

o79 : Ideal of S</pre>
</td></tr>
</table>
<div>We can also take the &ldquo;ideal quotient&rdquo; I:J of an ideal I with respect to another, J defined as the set of elements f such that f*J is contained in I:</div>
<table class="examples"><tr><td><pre>i80 : ideal"u3w,uv":ideal"u"

                 2
o80 = ideal (v, u w)

o80 : Ideal of S</pre>
</td></tr>
</table>
<p></p>
<p></p>
<div/>
<h2>Defining functions and loading packages</h2>
<div>It is easy to define your own functions in <em>Macaulay2</em>, and this can save a lot of typing. Functions are defined with the symbol ->. For example, the famous <em>Collatz Conjecture</em> (also called the &ldquo;hailstone problem&rdquo;) asks about the following procedure: given an integer <i>n</i>, divide it by 2 if possible, or else multiply by 3 and add 1. If we repeat this over and over, does the process always reach 1?  Here is a function that performs the Hailstone procedure again and again, producing a list of the intermediate results.</div>
<table class="examples"><tr><td><pre>i81 : Collatz = n ->
          while n != 1 list if n%2 == 0 then n=n//2 else n=3*n+1

o81 = Collatz

o81 : FunctionClosure</pre>
</td></tr>
</table>
<div>For example:</div>
<table class="examples"><tr><td><pre>i82 : Collatz 27

o82 = {82, 41, 124, 62, 31, 94, 47, 142, 71, 214, 107, 322, 161, 484, 242,
      -----------------------------------------------------------------------
      121, 364, 182, 91, 274, 137, 412, 206, 103, 310, 155, 466, 233, 700,
      -----------------------------------------------------------------------
      350, 175, 526, 263, 790, 395, 1186, 593, 1780, 890, 445, 1336, 668,
      -----------------------------------------------------------------------
      334, 167, 502, 251, 754, 377, 1132, 566, 283, 850, 425, 1276, 638, 319,
      -----------------------------------------------------------------------
      958, 479, 1438, 719, 2158, 1079, 3238, 1619, 4858, 2429, 7288, 3644,
      -----------------------------------------------------------------------
      1822, 911, 2734, 1367, 4102, 2051, 6154, 3077, 9232, 4616, 2308, 1154,
      -----------------------------------------------------------------------
      577, 1732, 866, 433, 1300, 650, 325, 976, 488, 244, 122, 61, 184, 92,
      -----------------------------------------------------------------------
      46, 23, 70, 35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1}

o82 : List</pre>
</td></tr>
</table>
<div>If you don&rsquo;t understand this code easily, see <a href="../../Macaulay2Doc/html/___Function.html" title="the class of all functions">Function</a> and <a href="../../Macaulay2Doc/html/_while.html" title="while loops">while</a>, or try:</div>
<table class="examples"><tr><td><pre>viewHelp Function</pre>
</td></tr>
<tr><td><pre>viewHelp "while"</pre>
</td></tr>
</table>
<div>In order to understand a process it is often useful to tabulate the results of applying it many times. One feature of the Collatz process is how many steps it takes to get to 1. We can tabulate this statistic for the first 25 values of n with the function <a href="../../Macaulay2Doc/html/_tally.html" title="tally the elements of a list or sequence">tally</a>, as follows:</div>
<table class="examples"><tr><td><pre>i83 : tally for n from 1 to 30 list length Collatz n

o83 = Tally{0 => 1  }
            1 => 1
            2 => 1
            3 => 1
            4 => 1
            5 => 1
            6 => 1
            7 => 3
            8 => 1
            9 => 2
            10 => 2
            12 => 1
            14 => 1
            15 => 2
            16 => 1
            17 => 2
            18 => 3
            19 => 1
            20 => 2
            23 => 1
            111 => 1

o83 : Tally</pre>
</td></tr>
</table>
<div>A line of the form</div>
<table class="examples"><tr><td><pre>            18 => 3</pre>
</td></tr>
</table>
<div>in the result means that a Collatz sequence of length 18 was seen 3 times. To see the successive &ldquo;record-breakers&rdquo;, that is, the numbers with longer Collatz sequences than any number before them, we might try:</div>
<table class="examples"><tr><td><pre>i84 : record = length Collatz 1

o84 = 0</pre>
</td></tr>
<tr><td><pre>i85 : L = for n from 2 to 1000 list (
              l = length Collatz n;
              if l > record
                then (record = l; (n,l))
                else continue)

o85 = {(2, 1), (3, 7), (6, 8), (7, 16), (9, 19), (18, 20), (25, 23), (27,
      -----------------------------------------------------------------------
      111), (54, 112), (73, 115), (97, 118), (129, 121), (171, 124), (231,
      -----------------------------------------------------------------------
      127), (313, 130), (327, 143), (649, 144), (703, 170), (871, 178)}

o85 : List</pre>
</td></tr>
</table>
<div>If you want to see a list of just the successive records, you can apply the function <a href="../../Macaulay2Doc/html/_last.html" title="last element of a list">last</a> to each element of the list <i>L</i>. A convenient way to do this is with this syntax:</div>
<table class="examples"><tr><td><pre>i86 : L/last

o86 = {1, 7, 8, 16, 19, 20, 23, 111, 112, 115, 118, 121, 124, 127, 130, 143,
      -----------------------------------------------------------------------
      144, 170, 178}

o86 : List</pre>
</td></tr>
</table>
<p></p>
<p>Note that in writing functions of more than one expression (usually there&rsquo;s one expression per line), the expressions must be separated by semicolons. For example in the &ldquo;for&rdquo; loop above, the first expression was &ldquo;<tt>l = length Collatz n</tt>&rdquo;. After the last expression of an input line or of a function body, a semicolon suppresses output, useful when the output would be large.</p>
<div>There are many packages of ready-made functions available for your use, many written by other users (perhaps you&rsquo;ll contribute one someday!) A list of &ldquo;installed&rdquo; packages can be found with:</div>
<table class="examples"><tr><td><pre>viewHelp</pre>
</td></tr>
</table>
<div>For example, there is a package called <a href="../../EdgeIdeals/html/index.html" title="A package for working with the edge ideals of (hyper)graphs">EdgeIdeals</a>. To load the package, use:</div>
<table class="examples"><tr><td><pre>i87 : loadPackage "EdgeIdeals"

o87 = EdgeIdeals

o87 : Package</pre>
</td></tr>
</table>
<div>After loading it, you can view its documentation with</div>
<table class="examples"><tr><td><pre>viewHelp EdgeIdeals</pre>
</td></tr>
</table>
<div>or you can call its functions, such as <a href="../../EdgeIdeals/html/_random__Graph.html" title="returns a random graph">randomGraph</a> and <a href="../../EdgeIdeals/html/_edge__Ideal.html" title="creates the edge ideal of a (hyper)graph">edgeIdeal</a>:</div>
<table class="examples"><tr><td><pre>i88 : R = kk[vars(0..10)]

o88 = R

o88 : PolynomialRing</pre>
</td></tr>
<tr><td><pre>i89 : G=randomGraph (R,20)

o89 = Graph{edges => {{a, c}, {c, d}, {d, g}, {d, i}, {g, j}, {g, k}, {c, e}, {d, j}, {f, g}, {f, i}, {c, k}, {g, i}, {i, j}, {c, h}, {e, g}, {a, g}, {e, i}, {e, h}, {b, f}, {d, h}}}
            ring => R
            vertices => {a, b, c, d, e, f, g, h, i, j, k}

o89 : Graph</pre>
</td></tr>
<tr><td><pre>i90 : K=edgeIdeal G

o90 = monomialIdeal (a*c, c*d, c*e, b*f, a*g, d*g, e*g, f*g, c*h, d*h, e*h,
      -----------------------------------------------------------------------
      d*i, e*i, f*i, g*i, d*j, g*j, i*j, c*k, g*k)

o90 : MonomialIdeal of R</pre>
</td></tr>
<tr><td><pre>i91 : hilbertSeries K

             2      3      4      5       6       7      8      9     10
      1 - 20T  + 60T  - 63T  - 14T  + 105T  - 120T  + 70T  - 22T  + 3T
o91 = ------------------------------------------------------------------
                                          11
                                   (1 - T)

o91 : Expression of class Divide</pre>
</td></tr>
<tr><td><pre>i92 : betti res K

             0  1  2   3   4   5  6  7 8
o92 = total: 1 20 77 153 190 153 78 23 3
          0: 1  .  .   .   .   .  .  . .
          1: . 20 60  80  59  26  7  1 .
          2: .  . 17  73 131 127 71 22 3

o92 : BettiTally</pre>
</td></tr>
</table>
<p></p>
<div>When testing a conjecture  one sometimes wants to run a large number of randomly chosen examples. Here&rsquo;s some typical code that one might use to study a random graph ideal.  First we use &ldquo;<tt>for ... list ...</tt>&rdquo; to construct a list <tt>L</tt> and suppress its printing by ending the line that creates it with a &ldquo;;&rdquo;.  Each entry of <tt>L</tt> is a triple consisting of the codimension, degree, and Betti table of a random graph ideal on 10 vertices having only 4 edges.</div>
<table class="examples"><tr><td><pre>i93 : R = ZZ/2[vars(0..10)]

o93 = R

o93 : PolynomialRing</pre>
</td></tr>
<tr><td><pre>i94 : L=for j from 1 to 100 list(
          I = edgeIdeal randomGraph (R,5);
          (codim I, degree I, betti res I));</pre>
</td></tr>
</table>
<div>We can use <a href="../../Macaulay2Doc/html/_tally.html" title="tally the elements of a list or sequence">tally</a> to find out how many examples were found with each combination of codimension and degree and Betti table.</div>
<table class="examples"><tr><td><pre>i95 : tally L

                           0 1 2 3 4
o95 = Tally{(4, 12, total: 1 5 9 7 2) => 16  }
                        0: 1 . . . .
                        1: . 5 2 . .
                        2: . . 7 4 .
                        3: . . . 3 2
                          0 1  2  3 4 5
            (2, 1, total: 1 5 10 10 5 1) => 6
                       0: 1 .  .  . . .
                       1: . 5  4  1 . .
                       2: . .  6  9 5 1
                          0 1  2  3 4 5
            (2, 2, total: 1 5 10 10 5 1) => 1
                       0: 1 .  .  . . .
                       1: . 5  6  4 1 .
                       2: . .  4  6 4 1
                          0 1  2  3 4 5
            (3, 2, total: 1 5 10 10 5 1) => 9
                       0: 1 .  .  . . .
                       1: . 5  2  . . .
                       2: . .  8  6 1 .
                       3: . .  .  4 4 1
                          0 1  2  3 4 5
            (3, 4, total: 1 5 10 10 5 1) => 5
                       0: 1 .  .  . . .
                       1: . 5  3  1 . .
                       2: . .  7  6 2 .
                       3: . .  .  3 3 1
                          0 1  2  3 4 5
            (4, 8, total: 1 5 10 10 5 1) => 7
                       0: 1 .  .  . . .
                       1: . 5  1  . . .
                       2: . .  9  3 . .
                       3: . .  .  7 3 .
                       4: . .  .  . 2 1
                          0 1 2 3
            (2, 1, total: 1 5 6 2) => 3
                       0: 1 . . .
                       1: . 5 6 2
                          0 1 2 3
            (3, 5, total: 1 5 6 2) => 4
                       0: 1 . . .
                       1: . 5 5 1
                       2: . . 1 1
                          0 1 2 3 4
            (2, 1, total: 1 5 7 4 1) => 2
                       0: 1 . . . .
                       1: . 5 5 1 .
                       2: . . 2 3 1
                          0 1 2 3 4
            (2, 2, total: 1 5 7 4 1) => 1
                       0: 1 . . . .
                       1: . 5 7 4 1
                          0 1 2 3 4
            (3, 2, total: 1 5 8 5 1) => 13
                       0: 1 . . . .
                       1: . 5 3 . .
                       2: . . 5 4 .
                       3: . . . 1 1
                          0 1 2 3 4
            (3, 3, total: 1 5 9 7 2) => 21
                       0: 1 . . . .
                       1: . 5 3 . .
                       2: . . 6 7 2
                          0 1 2 3 4
            (3, 4, total: 1 5 7 4 1) => 2
                       0: 1 . . . .
                       1: . 5 4 . .
                       2: . . 3 4 1
                          0 1 2 3 4
            (3, 4, total: 1 5 8 5 1) => 10
                       0: 1 . . . .
                       1: . 5 4 1 .
                       2: . . 4 4 1

o95 : Tally</pre>
</td></tr>
</table>
<div>We can determine how many distinct patterns were found:</div>
<table class="examples"><tr><td><pre>i96 : #tally L

o96 = 14</pre>
</td></tr>
</table>
<p></p>
<p></p>
<div/>
<h2>Ext, Tor, and cohomology</h2>
<div><em>Macaulay2</em> can compute the homology of complexes; for example, let&rsquo;s compute the homology of a Koszul complex that is not a resolution: <p align=center><i> <b>K</b>(x<sup>2</sup>, x y<sup>2</sup>):&nbsp;&nbsp;0 &rarr; S(-5) &rarr; S(-2)&oplus;S(-3) &rarr; S &rarr;0 </i></p> The free module <i>S(-2) &oplus; S(-3)</i> can be defined with this syntax:</div>
<table class="examples"><tr><td><pre>i97 : S^{-2,-3}

       2
o97 = S

o97 : S-module, free, degrees {2, 3}</pre>
</td></tr>
</table>
<div>Here is how we can define the maps in the Koszul complex:</div>
<table class="examples"><tr><td><pre>i98 : S = kk[x,y]

o98 = S

o98 : PolynomialRing</pre>
</td></tr>
<tr><td><pre>i99 : phi1 = map(S^1, S^{-2,-3}, matrix"x2,xy2")

o99 = | x2 xy2 |

              1       2
o99 : Matrix S  &lt;--- S</pre>
</td></tr>
<tr><td><pre>i100 : phi2 = map(S^{-2,-3}, S^{-5}, matrix"xy2;-x2")

o100 = {2} | xy2 |
       {3} | -x2 |

               2       1
o100 : Matrix S  &lt;--- S</pre>
</td></tr>
</table>
<div>Let&rsquo;s check that this is will really make a complex:</div>
<table class="examples"><tr><td><pre>i101 : phi1*phi2

o101 = 0

               1       1
o101 : Matrix S  &lt;--- S</pre>
</td></tr>
</table>
<div>To get the homology we can, for example compute:</div>
<table class="examples"><tr><td><pre>i102 : (ker phi1)/(image phi2)

o102 = subquotient ({2} | y2 |, {2} | xy2 |)
                    {3} | -x |  {3} | -x2 |

                                 2
o102 : S-module, subquotient of S</pre>
</td></tr>
</table>
<div>We could also use the data type <a href="../../Macaulay2Doc/html/___Chain__Complex.html" title="the class of all chain complexes">ChainComplex</a> and use a built-in facility to take homology (in our case <i>H<sub>1</sub></i>):</div>
<table class="examples"><tr><td><pre>i103 : FF = chainComplex(phi1,phi2)

        1      2      1
o103 = S  &lt;-- S  &lt;-- S
                      
       0      1      2

o103 : ChainComplex</pre>
</td></tr>
<tr><td><pre>i104 : FF.dd

            1                  2
o104 = 0 : S  &lt;-------------- S  : 1
                 | x2 xy2 |

            2                   1
       1 : S  &lt;--------------- S  : 2
                 {2} | xy2 |
                 {3} | -x2 |

o104 : ChainComplexMap</pre>
</td></tr>
<tr><td><pre>i105 : homology FF

o105 = 0 : cokernel | x2 xy2 |                  

       1 : subquotient ({2} | y2 |, {2} | xy2 |)
                        {3} | -x |  {3} | -x2 |

       2 : image 0                              

o105 : GradedModule</pre>
</td></tr>
<tr><td><pre>i106 : presentation (homology FF)_1

o106 = {4} | x |

               1       1
o106 : Matrix S  &lt;--- S</pre>
</td></tr>
</table>
<p>Either way, the first homology is <i>((x<sup>2</sup>):(xy<sup>2</sup>)) / (x<sup>2</sup>) &#8773; S/(x)</i>, in accord with general theory.</p>
<div>There are other ways to construct Koszul complexes.  One way is as the tensor product of chain complexes of length 1:</div>
<table class="examples"><tr><td><pre>i107 : FF = chainComplex matrix {{x^2}} ** chainComplex matrix {{x*y^2}}

        1      2      1
o107 = S  &lt;-- S  &lt;-- S
                      
       0      1      2

o107 : ChainComplex</pre>
</td></tr>
<tr><td><pre>i108 : FF.dd

            1                  2
o108 = 0 : S  &lt;-------------- S  : 1
                 | xy2 x2 |

            2                    1
       1 : S  &lt;---------------- S  : 2
                 {3} | x2   |
                 {2} | -xy2 |

o108 : ChainComplexMap</pre>
</td></tr>
</table>
<div>Another way is by using the function <a href="../../Macaulay2Doc/html/_koszul.html" title="Koszul complex or specific matrix in the Koszul complex">koszul</a>, designed for that purpose:</div>
<table class="examples"><tr><td><pre>i109 : FF = koszul matrix {{x^2, x*y^2}}

        1      2      1
o109 = S  &lt;-- S  &lt;-- S
                      
       0      1      2

o109 : ChainComplex</pre>
</td></tr>
<tr><td><pre>i110 : FF.dd

            1                  2
o110 = 0 : S  &lt;-------------- S  : 1
                 | x2 xy2 |

            2                    1
       1 : S  &lt;---------------- S  : 2
                 {2} | -xy2 |
                 {3} | x2   |

o110 : ChainComplexMap</pre>
</td></tr>
</table>
<p></p>
<div>Since <em>Macaulay2</em> can compute resolutions and homology, it can compute things such as <i>Ext</i>, <i>Tor</i> and sheaf cohomology, as in the following examples. The first uses Serre&rsquo;s formula to compute the multiplicity with which a 2-plane meets the union of two 2-planes in 4-space (this is the first case in which the length of the intersection scheme is NOT the right answer.) The notation &ldquo;<tt>M**N</tt>&rdquo; denotes the tensor product of the modules <i>M</i> and <i>N</i>. We use the syntactical forms &ldquo;<tt>for j from 0 to 4 list ...</tt>&rdquo; to list some results and &ldquo;<tt>sum(0..4, j -> ...)</tt>&rdquo; to sum some results.</div>
<table class="examples"><tr><td><pre>i111 : S=kk[a,b,c,d]

o111 = S

o111 : PolynomialRing</pre>
</td></tr>
<tr><td><pre>i112 : IX = intersect(ideal(a,b), ideal(c,d))

o112 = ideal (b*d, a*d, b*c, a*c)

o112 : Ideal of S</pre>
</td></tr>
<tr><td><pre>i113 : IY = ideal(a-c, b-d)

o113 = ideal (a - c, b - d)

o113 : Ideal of S</pre>
</td></tr>
<tr><td><pre>i114 : degree ((S^1/IX) ** (S^1/IY))

o114 = 3</pre>
</td></tr>
<tr><td><pre>i115 : for j from 0 to 4 list degree Tor_j(S^1/IX, S^1/IY)

o115 = {3, 1, 0, 0, 0}

o115 : List</pre>
</td></tr>
<tr><td><pre>i116 : sum(0..4, j-> (-1)^j * degree Tor_j(S^1/IX, S^1/IY))

o116 = 2</pre>
</td></tr>
</table>
<div>Similarly, we can compute Hom and Ext:</div>
<table class="examples"><tr><td><pre>i117 : Hom(IX, S^1/IX)

o117 = subquotient ({-2} | b d 0 0 |, {-2} | bd ad bc ac 0  0  0  0  0  0  0  0  0  0  0  0  |)
                    {-2} | a 0 d 0 |  {-2} | 0  0  0  0  bd ad bc ac 0  0  0  0  0  0  0  0  |
                    {-2} | 0 c 0 b |  {-2} | 0  0  0  0  0  0  0  0  bd ad bc ac 0  0  0  0  |
                    {-2} | 0 0 c a |  {-2} | 0  0  0  0  0  0  0  0  0  0  0  0  bd ad bc ac |

                                 4
o117 : S-module, subquotient of S</pre>
</td></tr>
<tr><td><pre>i118 : Ext^1(IX, S^1/IX)

o118 = cokernel {-2} | b a 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
                {-2} | 0 0 d c b a 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
                {-2} | 0 0 0 0 0 0 d c b a 0 0 0 0 0 0 0 0 0 0 |
                {-2} | 0 0 0 0 0 0 0 0 0 0 d c b a 0 0 0 0 0 0 |
                {-2} | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 d c b a 0 0 |
                {-2} | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 d c |

                              6
o118 : S-module, quotient of S</pre>
</td></tr>
</table>
<p>or the cohomology of the sheaf associated to a module.</p>
<div>Here is how to compute the first cohomology of the structure sheaf twisted by <i>-2</i> of the curve <i>Proj(S/IX)</i>, which in this case is the disjoint union of two lines in <i>&#x2119;<sup>3</sup></i>:</div>
<table class="examples"><tr><td><pre>i119 : HH^1 (sheaf (S^{-2}**(S^1/IX)))

         2
o119 = kk

o119 : kk-module, free</pre>
</td></tr>
</table>
</div>
</div>
<div class="single"><h2>Authors</h2>
<ul><li><div class="single"><a href="http://www.msri.org/~de">David Eisenbud</a><span> &lt;<a href="mailto:de@msri.org">de@msri.org</a>></span></div>
</li>
<li><div class="single"><a href="http://www.math.cornell.edu/~mike">Mike Stillman</a><span> &lt;<a href="mailto:mike@math.cornell.edu">mike@math.cornell.edu</a>></span></div>
</li>
</ul>
</div>
<div class="single"><h2>Version</h2>
This documentation describes version <b>1.0</b> of BeginningMacaulay2.</div>
<div class="single"><h2>Source code</h2>
The source code from which this documentation is derived is in the file <a href="../../../../Macaulay2/BeginningMacaulay2.m2">BeginningMacaulay2.m2</a>.  The auxiliary files accompanying it are in the directory <a href="../../../../Macaulay2/BeginningMacaulay2/">BeginningMacaulay2/</a>.</div>
</div>
</body>
</html>