Create a polynomial ring using the usual mathematical notation.
i1 : R = QQ[x,y,z]; |
i2 : R |
Notice that after assignment to a global variable, Macaulay 2 knows the ring's name, and this name is used when printing the ring.The original description of the ring can be recovered with describe.
i3 : describe R |
Use the following subscript notation to obtain 0,1, or any multiple of 1, as elements in the ring.
i4 : 0_R |
i5 : 1_R |
i6 : 11_R |
Obtain the variables (generators) of the ring by subscripting the name of the ring. As always in Macaulay 2, indexing starts at 0.
i7 : R_0^10+R_1^3+R_2 |
The number of variables is provided by numgens.
i8 : numgens R |
i9 : apply(numgens R, i -> R_i^i) |
i10 : sum(numgens R, i -> R_i^i) |
(for more information, see apply and sum.Use generators to obtain a list of the variables of the ring.
i11 : gens R |
A (one row) matrix containing the variables of the ring can be obtained using (vars,Ring).
i12 : vars R |
The index of a variable:
i13 : index x, index y, index z |
The coefficient ring can be recovered with coefficientRing.
i14 : coefficientRing R |
A random homogeneous element can be obtained with random.
i15 : random(2,R) |
A basis of the subspace of ring elements of a given degree can be obtained in matrix form with basis.
i16 : basis(2,R) |
We may construct polynomial rings over polynomial rings.
i17 : ZZ[a,b,c][d,e,f]; |
When displaying an element of an iterated polynomial ring, parentheses are used to organize the coefficients recursively, which may themselves be polynomials.
i18 : (a+d+1)^2 |
Variable names may be words.
i19 : QQ[rho,sigma,tau]; |
i20 : (rho - sigma)^2 |
There are various other ways to specify the variables in a polynomial ring. A sequence of variables can be obtained as follows.
i21 : ZZ[b..k]; |
In this example, if you had previously assigned either b or k a value that was not a ring generator, then Macaulay 2 would complain about this: it would no longer understand what variables you wanted. To get around this, we could either do
i22 : ZZ[symbol b .. symbol k]; |
or we may obtain the single-letter variables with vars.
i23 : vars (0..4) |
i24 : ZZ[vars (0..4),vars(26..30),vars 51] |
Subscripted variables can be used, provided the base for the subscripted variable has not been used for something else.
i25 : ZZ[t,p_0,p_1,q_0,q_1]; |
Sequences of subscripted variables can also be used.
i26 : ZZ[p_(0,0) .. p_(2,1),q_0..q_5] |
i27 : (p_(0,0)+q_2-1)^2 |
The subscripts can be much more general, but care is required when using symbols as subscripts, for the symbols may acquire values later that would interfere with your original use of them as symbols. Thus you should protect symbols that will be used in this way.
i28 : protect xx; protect yy; protect zz; |
i31 : ZZ[ee_[xx],ee_[yy],ee_[zz]] |
Some things to watch out for when using polynomial rings: