Skip to main content
Logo image

Chapter 8 Macaulay 2

This chapter is co-authored by Francesca Gandini, Sumner Strom, Al Ashir Intisar

Section 8.1 Creating a M2 Codespace

A turn-key repository for creating a Codespace (Section 3.1) for Macaulay2 is available at fragandi/M2-codespace
 1 
github.com/fragandi/M2-codespace
. Below we provide detailed instructions. If you are familiar with GitHub Codespaces, you may be able to follow the instructions in the README directly. Otherwise, follow the steps below for a smoother setup.
Step 1: Fork the Repository: Navigate to fragandi/M2-codespace
 2 
github.com/fragandi/M2-codespace
and click the Fork button in the top-right corner of the page.
screenshot of M2-codespace with forking instructions.
Figure 8.1.1. Select "Create a new fork" next to the plus icon.
Step 2: Create a Codespace: Open your forked repository, click the green Code button, and select Create codespace on main.
screenshot of creating codespace on forked GitHub repository.
Figure 8.1.2. Creating codespace on forked GitHub repository.
Step 3: Reload VS Code: Once the Codespace starts, open the Command Palette (Ctrl+Shift+P or Cmd+Shift+P), then type:
Reload Window
Step 4: Check Macaulay2 Executable Path: If you receive an error like “Cannot find Macaulay2 executable,” open the extension settings for Macaulay2 for Codespace and verify the executable path.
screenshot of Macaulay2 for Codespace extension settings.
Figure 8.1.3. Go to the Macaulay2 for Codespace extension settings as shown in the image above.
screenshot of Macaulay2 for Codespace extension settings correct executable path.
Figure 8.1.4. If your path is different than what it shows in the image above try the steps below:
Fix: Open the Command Palette and disable VS Code Settings Sync:
Settings Sync: Turn Off
Then reload the window again as in Step 3. If problems persist, you may delete and recreate the Codespace.
Step 5: Verify Installation: To confirm Macaulay2 installed correctly, open the Command Palette again and run:
Codespaces: View Creation Log
Look for confirmation lines like:
✅ Macaulay2 installed successfully!
✅ Following all these steps ensures that Macaulay2 is ready to use inside your Codespace and only the correct environment settings are applied.
Alternative: If you want to create your own repository with Macaulay2 support from scratch, copy the .devcontainer/ directory and optionally the M2codes/, image_files/, and README.md from the original repo. Push to GitHub and launch your own Codespace.
For more information on using Macaulay2, visit the official documentation
 3 
macaulay2.com/doc/Macaulay2/share/doc/Macaulay2/Macaulay2Doc/html/___The_sp__Macaulay2_splanguage.html
.

Section 8.2 Basic M2 Commands

Section 8.2.1 Arithmetic, Strings, and Lists

Make sure you run the code cells sequentially since some functions defined in earlier cells are used in later cells. You can also chnage the code in the block to evaluate any valid Macaulay2 code.
This block introduces basic arithmetic operations in Macaulay2, including exponentiation.
Here we compute large factorials, demonstrate how multiple expressions are separated by semicolons, and how to access the previous output using `oo`.
Strings are created using double quotes, assigned to variables, and concatenated horizontally with `|` or vertically with `||`.
Lists are constructed with curly braces. Indexing starts at 0, and element-wise arithmetic works like vector math.

Section 8.2.2 Functions, Apply, and Loops

Functions are created using the arrow operator `->`. This block defines a cube function `f` and a two-variable multiplication function `g`.
The `apply` function maps a function over a list or range. We also demonstrate a `for` loop to print values and their cubes.

Section 8.2.3 Rings, Matrices, Ideals

This block defines a quotient ring and a free module over it. It also explores indexing of basis vectors and ring metadata using `describe`.
We define a homomorphism using a matrix and investigate its image, ideal, kernel, and related algebraic information like rank and Poincaré polynomial.
This segment combines kernel and cokernel into a subquotient module, and explores its generators, relations, and a simplified (pruned) form.

Section 8.2.4 Homological Algebra and Gröbner Bases

We compute a projective resolution of a module, verify that it is a complex, and examine its Betti table for structure.
We construct a generic matrix, compute its resolution, and build polynomial rings with indexed variables. We generate and analyze a Gröbner basis.

Section 8.3 InvariantRings package

Section 8.3.1 InvariantRing Library Demos

The InvariantRing package in Macaulay2 provides tools to study and compute invariant rings of group actions. To get started, install the package:
Section 8.3.1.1 SL₂ Actions on C² and Variants
A classical example: the standard action of SL₂ on ℂ². The ring R carries a linearly reductive action from SL₂ defined via the matrix SL2std. The invariants and Hilbert ideal are then computed:
Section 8.3.1.2 Diagonal Actions of Abelian Groups
This example demonstrates a diagonal action of the abelian group ℂ₃ × ℂ₃ on a polynomial ring. After defining the diagonal weights, we compute the invariant ring and its Hilbert series:
Section 8.3.1.3 Linearly Reductive Actions: Permutations and Binary Forms
Here’s how the symmetric group S₂ acts via a matrix of projection operators. We identify which polynomials are invariant under the group action:
Now we compute the invariants of binary quadratics and quartics using SL₂ actions. These involve basis substitutions in a ring of forms and are more computationally demanding:
Section 8.3.1.4 Matrix Invariants and Conjugation Actions
We define SL₂ actions on 2×2 and 3×3 matrices of binary or ternary forms. The conjugation action creates sophisticated invariants under change of basis:
The same process is repeated for 3×3 matrices. This involves 9-dimensional vector spaces and is more computationally demanding:
Section 8.3.1.5 Finite Group Actions: S₄ Example
Finally, we examine the symmetric group S₄ acting on 4 variables. We use both King’s algorithm and a slower linear algebra method to compute primary and secondary invariants: