Intro to Macaulay 2 Math 676 (Computational Algebraic Geometry) Dan Bates, CSU, Spring 2009 The point of today’s lab is to interact a bit with Macaulay 2. I am no expert with M2, so much of this is ripped from other sources (as indicated as we move forward). Where to find help The command line help in M2 seems pretty nice. Just type help TOPIC, e.g., help solve or help poly. This provides a nice description and several examples of I/O. I haven’t seen an online help/user guide as with Singular, but the command line help seems to be adequate (at least so far). Getting started As with Singular, Zube kindly installed Macaulay 2 on the latest nine machines in the math lab (WB 205). These are the nine machines with silver trim around the monitor (computer numbers *...*O##, rather than *..*M##, for example). I am not sure how to run Macaulay 2 (M2) on these machines as I write this, but, on my machine, I open Cygwin and type M2. It may be in the start menu on your machine. If not, open a terminal (cmd), type cd ../cygwin and then Cygwin. After that, typing M2 should work. We’ll figure this one out together.... As with Singular, there is a nicer emacs interface. Again, as with Singular, I don’t have emacs on my machine, so I’ll describe how to use the command line version. Messing around (ripped from the Stillman–Grayson chapter of Computations in Algebraic Geometry with Macaulay 2, edited by Eisenbud, Grayson, Stillman, and Sturmfels) M2 is interactive – you type in a command and it spits out a result. There’s a little extra structure here, though – input lines are labeled i# and output lines are labeled o#. This makes it easy to refer to this I/O later. I’ll neglect the input line labels and just give you the input to try. First, notice the format of the output: w This tells you what is being stored and the type (two bits of output). Assignment is normal: w=2*3^2 w Yep, it worked. Strings are easy to manipulate: x="abcd" y=x|x z=x||x 1 This last one is handy for polynomial output (not so important for you, probably). There are various data types for lists (as in Maple) – lists, sets, arrays, sequences.... Here’s a list containing a list, a sequence, and an array: l1 = {{a,1},(bob,3,cat),[eat,at,joes]} We can tell how many items are in our list using #l1. Also, use l1#0 to grab the first (zeroth) elementin the list. Try grabbing each of the three elements in l1. Now try grabbing just “joes.” You can use append(l1,l2) to concatenate lists, and sum{1,2,3} and product{1,2,3} might also be handy. Here’s a function (very Maplesque!) and the way to evaluate it: f=(x,y)->3*x^2-12*y+7 f(5,2) Notice that M2’s notation for exponents is a bit more natural than Singular’s (at least to me). M2 will squawk if you put variables and numbers beside one another – try it. You can loop in Macaulay 2, too: i=1; while i<50 do {print i; i=2*i} i from 1 to 10 list i^3 Take the output line from that last command, say o9, and see where o9#3 gets you. Now for some I/O: (1..5) / print << ‘‘I am ’’ << 3^3-8 << ‘‘ years old.’’ ‘‘file1’’ << ‘‘I am ’’ << 3^3-8 << ‘‘ years old.’’ << close This last one should have created a file named “file1,” though it’s possible that there are read/write issues with these machines. Supposing this file was created, we can read it (as a string) using: get ‘‘file1’’ or execute all commands in it using load ‘‘file1’’ Now we can define a ring – as with Singular, Macaulay 2 likes to know what ring we are using: R=QQ[x,y,z] This is the ring of polynomials in three variables with rational coefficients (as you may have guessed!). Just for kicks, check out help QQ. It lists everything that M2 can do with a rational number – very handy! ZZ, RR, and CC might also be handy. Notice that RR and CC are inexact of (default) precision 53 digits. Finite fields have the form ZZ/p, e.g., ZZ/7. Now here’s a polynomial in that ring. f=(x+y)^2 Typing f gives you the nice 2-line output that humans like to read. Machines aren’t so happy with this, though, so try: toString f 2 One last thing before digging on to ideals/varieties: vars R This reminds you of the current list of variables and indicates that the variables can be though of as a mapping R3 → R1 (i.e., multiply the 1 × 3 matrix of variables by a 3 × 1 matrix of polynomials, and you’ll end up with something in the ring). This is of course nowhere near a full tutorial, but it at least gets your hands a bit dirty.... Solving polynomial systems (ripped from the Sottile chapter of the book from the previous section) Here’s how we define an ideal: R=QQ[x,y,z] I=ideal (x^2-y-z-1, x-y^2-z-1, x-y-z^2-1) Now we can check the dimension and degree of the variety corresponding to this ideal: dim I degree I This tells us that our variety is zero-dimensional (just points) and consists of 8 points. For kicks, try the above set of four commands over CC. OK, go back to QQ please. Now try this: J=eliminate(x,I) K=eliminate(y,J) It would be nice to solve these, of course. To do so, we could load the package “realroots.m2” and use SturmSequence, for example. Unfortunately, I am presently having trouble loading packages.... By the way, try code COMMAND for your favorite command COMMAND. Depending on the function, this may display the source code (a great learning tool!). One last thing before moving on – I haven’t mentioned how to compute Gröbner bases yet. For that, just check out help gb – there is a decent example there. If you figure out how to use a different term order, please let me know. It shouldn’t be hard, but I haven’t looked into this yet.... Solving polynomial systems in Singular (back to that) (ripped from Sturmfels’ aptly-named Solving systems of polynomial equations) Singular does something nice that I was not aware of when we covered Singular. Pop singular open (if you want) and try this: ring R=0,(x,y,z),dp; ideal I = (x^2-y-z-1, x-y^2-z-1, x-y-z^2-1); ideal G = groebner(I); G; LIB "solve.lib"; solve(G,6); 3 This will find all isolated solutions in the variety defined by I, to 6 digits. Cool, huh? While we are in Singular, try this: ring R=0,(x,y),dp; ideal I = x*y, x^3-x^2, x^2*y-x*y; LIB "primdec.lib"; primdecGTZ(I); This ideal has as solution set the y-axis, some point, and the origin as an embedded point in the y-axis. Can you spot this in the output? Note that this function (an implementation of the GTZ primary decomposition method) reports primary ideals (and their radicals) which, when intersected, yield the original ideal. Primary decomposition (ripped from 1.3 of Schenck’s Computational Algebraic Geometry and Sturmfels’ book from the previous section) Now let’s try primary decomposition in Macaulay 2. The ideal < x2 , xy > has two (well, more) primary decompositions – one is the intersection of < x2 , y > with < x > while another just replaces the first primary with < x2 , xy, y 2 >. We can use Macaulay 2 to check whether these things are primary and whether the intersections are correct: R=QQ[x,y] intersect(ideal(x), ideal(x^2,x*y,y^2)) intersect(ideal(x), ideal(x^2,y)) Now you can compare whether these two ideals are the same by typing o3==o4 (replacing o3 and o4 with the appropriate output line numbers). You can also take the radical (using radical o3) of some output line (or ideal) and check whether the ideal equals its radical. This is a way to check whether an ideal is prime, of course. Recall that the radical of an ideal can always be written as the intersection of a bunch of prime ideals. Let’s look into this in Macaulay 2 for a specific example: R=QQ[x1,x2,x3,x4] I=ideal(x1*x4+x2*x3, x1*x3, x2*x4) ass(I) ass(I) is just the set of associated primes, i.e., the radicals of the primaries for any given primary decomposition. (Recall that these primes are uniquely determined even though the primary decomposition is not.) radical(I)==I This indicates that I is not radical, so let’s take the radical: radical(I) Now, intersecting the associated primes, we should get this, right? intersect(ass(I)) Now what? Here are some chapters (in no particular order) to check out if you have the time left over, either for personal interest or to start thinking about your talk. Each includes some computation (in 4 Macualay 2 or otherwise), making it a nice choice for a talk in this class: • Ch. 2 of Schenck – Hilbert polynomials and functions • Ch. 3 of Schenck – Free resolutions, Betti numbers • Ch. 9 of Schenck – Sheaves and cohomology • Ch. 3 of Sturmfels – Convex geometry, toric deformations • Ch. 4 of Sturmfels – Resultants • Ch. 9 of Sturmfels – Tropical algebraic geometry • §4.4 of the Macaulay book (by Sottile) – Schubert problems If none of this sounds good to you, try solving some adjacent minor systems. These are just ideals generated by the set of all k × k minors of an m × n matrix. The nice thing about this class of problems is that it is parameterized (good for checking how performance scales as ideal size changes) and has known solutions.... Sturmfels discusses these systems on pages 63–67. 5