Skip to main content

Section B.3 Macaulay2

Subsection What is Macaulay2?

There are several computer algebra systems dedicated to algebraic geometry and commutative algebra computations, such as
  • Singular
     1 
    https://www.singular.uni-kl.de/
    (more popular among algebraic geometers),
  • CoCoA
     2 
    https://cocoa.dima.unige.it/cocoa/
    (which is more popular with european commutative algebraists, having originated in Genova, Italy), and
  • Macaulay2
     3 
    https://faculty.math.illinois.edu/Macaulay2/
    .
There are many computations you could run on any of these systems (and others), but we will focus on Macaulay2 since it’s the most popular computer algebra system among US based commutative algebraists.
Macaulay2, as the name suggests, is a successor of a previous computer algebra system named Macaulay. Macaulay was first developed in 1983 by Dave Bayer and Mike Stillman, and while some still use it today, the system has not been updated since its final release in 2000. In 1993, Daniel Grayson and Mike Stillman released the first version of Macaulay2, and the current stable version of Macaulay2 1.16.
Macaulay2, or M2 for short, is an open-source project, with many contributors writing packages that are then released with the newest Macaulay2 version. Journals like the Journal of Software for Algebra and Geometry publish peer-refereed short articles that describe and explain the functionality of new packages, with the package source code being peer reviewed as well.
The National Science Foundation has funded Macaulay2 since 1992. Besides funding the project through direct grants, the NSF has also funded several Macaulay2 workshops — conferences where Macaulay2 package developers gather to work on new packages, and to share updates to the Macaulay2 core code and recent packages.

Subsection Commands in Macaulay2

A Macaulay2 session often starts with defining some ambient ring we will be doing computations over. Common rings such as the rationals and the integers can be defined using the commands QQ and ZZ; one can easily take quotients or build polynomial rings (in finitely many variables) over these. For example,
and
both store the ring \(\Z/(101)\) as \(R\text{,}\) with the small difference that in the second example Macaulay2 has named the coefficient field \(k\text{.}\) One quirk that might make a difference later is that if we use the first option and later set \(k\) to be the field \(\Z/(101)\text{,}\) our ring \(R\) is not a polynomial ring over \(k\text{.}\) Also, in the second example we ended each line with a ;, which tells Macaulay2 to run the command but not display the result of the computation — which is in this case was simply an assignment, so the result is not relevant.
We can now do all sorts of computations over our ring \(R\text{.}\) For example, we can define an ideal in \(R\) as follows:
Above we have set \(I\) to be the ideal in \(R\) that is generated by \(x^2, y^2, xy\text{.}\) The notation ideal( ) requires the usage of ^ for powers and * for products; alternatively, we can define the exact same ideal with the notation ideal" ", as follows:
Now we can use this ideal \(I\) to either define a quotient ring \(S=R/I\) or the \(R\)-module \(M=R/I\text{,}\) as follows:
It’s important to note that while \(R\) is a ring, \(R^1\) is the \(R\)-module \(R\) — this is a very important difference for Macaulay2, since these two objects have different types. So \(S\) defined above is a ring, while \(M\) is a module. Notice that Macaulay2 stored the module \(M\) as the cokernel of the map
\begin{equation*} R^3\xrightarrow {[x^2\;\;y^2\;\;xy]} R. \end{equation*}
When you make a new definition in Macaulay2, you might want to pay attention to what ring your new object is defined over. For example, now that we defined this ring \(S\text{,}\) Macaulay2 has automatically taken \(S\) to be our current ambient ring, and any calculation or definition we run next will be considered over \(S\) and not \(R\text{.}\) If you want to return to the original ring \(R\text{,}\) you must first run the command use R
If you want to work over a finitely generated algebra over one of the basic rings you can define in Macaulay2, and your ring is not a quotient of a polynomial ring, you want to rewrite this algebra as a quotient of a polynomial ring. For example, suppose you want to work over the second Veronese in \(2\) variables over our field \(k\) from before, meaning the algebra \(k[x^2, xy, y^2]\text{.}\) We need \(3\) algebra generators, which we will call \(a, b, c,\) corresponding to \(x^2, x^y,\) and \(y^2\text{:}\)
Our ring \(T\) at the end is isomorphic to the 2nd Veronese of \(R\text{,}\) which is the ring we wanted. Note the syntax order in map: first target, then source, then a list with the images of each algebra generator.
As you’re learning how to use Macaulay2, you will often find yourself needing some help. Luckily, Macaulay2 can help you directly! For example, suppose you know the name of a command, but do not remember the syntax to use it. You can ask ?command, and Macaulay2 will show you the different usages of the command you want to know about.
If instead you’d rather read the complete Macaulay2 documentation on the command you are interested in, you can use the viewHelp command, which will open an html page with the documentation you asked for. So running
will open an html page dedicate to the method primaryDecomposition, which includes examples and links to related methods.
Many Macaulay2 commands are easy to guess, and named exactly what you would expect them to be named. Often, googling “Macaulay2” followed by a few descriptive words will easily land you on the documentation for whatever you are trying to do.
Here are some basic commands you will likely use:
  • ideal (f_1, \dots , f_n) will return the ideal generated by \(f_1, \dots , f_n\text{.}\) Here products should be indicated by *, and powers with ^. If you’d rather not use ^ (this might be nice if you have lots of powers), you can write ideal (f_1, \dots , f_n) instead.
  • map S, R, (f_1, \dots , f_n) gives a ring map \(R \to S\) if \(R\) and \(S\) are rings, and \(R\) is a quotient of \(k[x_1, \dots , x_n]\text{.}\) The resulting ring map will send \(x_i \mapsto f_i\text{.}\) There are many variations of map — for example, you can use it to define \(R\)-module homomorphisms — but you should carefully input the information in the required format. Try viewHelp map in Macaulay2 for more details.
  • ker\((f)\) returns the kernel of the map \(f\) .
  • I + J and I*J return the sum and product of the ideals \(I\) and \(J\text{,}\) respectively.
  • A = matrix\{\{a_1,1, \dots , a_1,n}, \dots , {a_m,1, \dots , a_m,n\}\} returns the matrix
    \begin{equation*} A= \begin{pmatrix} a_{1,1} & \dots & a_{1,n} \\ & \ddots & \\ a_{m,1} & \dots & a_{m,n} \end{pmatrix} \end{equation*}
As in most programming languages, Macaulay2 follows the convention that the first position in a list is the \(0\)th position.
The method primaryDecomposition returns a list of primary ideals whose intersection is the input ideal, and associatedPrimes returns the list of associated primes of the given ideal or module. Operations on lists are often intuitive. For example, let’s say we want to find the primary component of an ideal with a particular radical.
            i1 : R = QQ[x,y];

            i2 : I = ideal"x2,xy";

            o2 : Ideal of R

            i3 : prim = primaryDecomposition I
                                      2
            o3 = {ideal x, ideal (y, x )}

            o3 : List

            i4 : L = select(prim, Q -> radical(Q) == ideal"x,y")
                              2
            o4 = {ideal (y, x )}

            o4 : List
The method select returns a list of all the elements in our list with the required properties. In this case, if we actually want the primary ideal we just selected, as opposed to a list containing it, we need to extract the first component of our list \(L\text{.}\)
            i5 : L_0
                            2
            o5 = ideal (y, x )

            o5 : Ideal of R