• You can input any command and execute it by pressing enter. Try running the following commands. The semicolon ; will suppress the printing of the output.
Examples:

1+2

4^2

5^3;

sqrt(9)

1/3

0..4

  • The i lines denote the input lines while the o lines denote the output lines. Frequently, the output has two lines:
o1 : the actual answer
o2 : the type of the output answer

  • Assignment is done by =, and the value of an object is displayed by typing its name.
  • Two dashes  -- are used to indicate a comment and any text following them is disregarded when executing the line.
Examples:
i1 : a = 2*100 -- this is a comment
i2 : b = 1/3

  • Comparison is done by the symbols == and != , returning true or false. Comparison can only be done between comparable elements, otherwise we will get an error message.
Examples:
i3 : a == b
i4 : a != b

  • The last output can always be accessed by typing two o’s as in oo. The values of the lines before the last one can also be accessed by typing ooo and oooo. Alternatively, the symbol labelling an output line can be used to retrieve the value; for instance, if we want to access the output of line 5 (i.e. 4 factorial), we would type o4 as in the following example.
Examples:
i5 : 4!;
i6: oo
i7 : o5

  • A list of expressions can be formed with braces. The number of elements is obtained by placing the symbol # before the list. The elements in a list are internally numbered by integer numbers starting from 0. You can access an element by placing the symbol # after the list followed by the element number.
Examples:
i8 : L = {1, 2, 3,t,u}
i9 : #L
i10 : L#1

  • To calculate with objects such as ideals and polynomials, a polynomial ring has to be defined first.  When typing a polynomial, the software automatically consider it as a ring element and the ring is displayed in the second output line.
Examples:
i11 : R1 = QQ[x,y]
i12 : f = (x+y)ˆ3

  • Notation for some most commonly used rings/fields:
    • QQ - the field of rational numbers
    • ZZ - the ring of integers
    • RR - the field of real numbers
    • CC - the field of complex numbers
    • ZZ/2021 - the ring of characteristic 2021
  • Macaulay2 also works for specific monomial orderings.
Examples:
i13 : R2 = QQ[x..z, MonomialOrder=> Lex]

  • Notation for some most commonly monomial orders:
    • Lex - the lexicographic order
    • RevLex - the reverse lexicographic order
    • GRevLex - the graded reverse lexicographic order
  • The ideal of a ring can be created by the following commands. The command gens is used to get the generator of an ideal as a matrix. Applying first entries to this matrix converts it to a list. The command numgens is used to get the number of generator of an ideal. To obtain a minimal generating set of a homogeneous ideal,  use mingens to get the minimal generators as a matrix.
Examples:
i14 : restart
i1 : R = QQ[x..z]
i2 : I = ideal(x+y+z-7/4,x^2+y^2+z^2-21/16)
i3 :  gens I
i4 : first entries gens I
i4 : numgens I
i5 : mingens I

  • Defining a ring makes it the current working ring, so each time we define a ring we switch to a new ring. If you write a polynomial, it will automatically be regarded as an element of the last ring. You can switch back to a previously defined ring with the command  use R, where R is the ring you want to use.
  • Macaulay2 creates a matrix from a nested list of lists, which the software interprets as a list of rows, each of which is in turn a list of ring elements. Once you declare a matrix, you can use basic matrix operations.
Examples:
i6 : M = matrix {{1,0,3},{4,5,6},{7,8,0}}
i7 : 4*M
i8 : M^2
i9 : trace M
i10 : transpose M
i11 : det M
i12 : inverse M
i13 : promote(M, QQ)
i14 : inverse oo
  • Finally, if you need more info about some stuff (for example about monomial order), you can access it by using viewHelp MonomialOrder.


Last modified: Thursday, 14 January 2021, 11:40 AM