Macaulay2 » Documentation
Packages » Macaulay2Doc » rings » polynomial rings
next | previous | forward | backward | up | index | toc

polynomial rings

A polynomial ring can be created with the usual mathematical notation.
i1 : ZZ[x,y,z]

o1 = ZZ[x..z]

o1 : PolynomialRing
If you try to construct this ring again, you will get a different answer. We use the strict comparison operator === to demonstrate this.
i2 : ZZ[x,y,z]===ZZ[x,y,z]

o2 = false
Thus it is a good idea to assign a new ring to a variable for future reference.
i3 : R = QQ[a,b,c,d,e,f]

o3 = R

o3 : PolynomialRing
Notice that after assignment to a global variable, Macaulay2 knows the ring's name, and this name is used when printing the ring.
i4 : R

o4 = R

o4 : PolynomialRing
The original description of the ring can be recovered with describe.
i5 : describe R

o5 = QQ[a..f, Degrees => {6:1}, Heft => {1}]
Use the following subscript notation to obtain 0,1, or any multiple of 1, as elements in the ring.
i6 : 0_R

o6 = 0

o6 : R
i7 : 1_R

o7 = 1

o7 : R
i8 : 11_R

o8 = 11

o8 : R
Obtain the variables (generators) of the ring by subscripting the name of the ring. As always in Macaulay2, indexing starts at 0.
i9 : R_0^10+R_1^3+R_2

      10    3
o9 = a   + b  + c

o9 : R
It is also possible to obtain the variables in a ring from strings containing their names.
i10 : "a"_R^10+"b"_R^3+"c"_R

       10    3
o10 = a   + b  + c

o10 : R
The number of variables is provided by numgens.
i11 : numgens R

o11 = 6
i12 : apply(numgens R, i -> R_i^i)

              2   3   4   5
o12 = {1, b, c , d , e , f }

o12 : List
i13 : sum(numgens R, i -> R_i^i)

       5    4    3    2
o13 = f  + e  + d  + c  + b + 1

o13 : R
(See apply and sum.) Use generators to obtain a list of the variables of the ring.
i14 : gens R

o14 = {a, b, c, d, e, f}

o14 : List
A matrix (with one row) containing the variables of the ring can be obtained using vars(Ring).
i15 : vars R

o15 = | a b c d e f |

              1      6
o15 : Matrix R  <-- R
The index of a variable:
i16 : index x, index y, index z

o16 = (0, 1, 2)

o16 : Sequence
The coefficient ring can be recovered with coefficientRing.
i17 : coefficientRing R

o17 = QQ

o17 : Ring
An element of the coefficient ring can be promoted to the polynomial ring.
i18 : promote(11/2,R)

      11
o18 = --
       2

o18 : R
Conversely, an element of the polynomial ring that is known to be a scalar can be lifted back to the coefficient ring.
i19 : sc = (a-2)^2-a^2+4*a

o19 = 4

o19 : R
i20 : lift(sc,QQ)

o20 = 4

o20 : QQ
In programs, the function liftable can be used to see whether this is possible.
i21 : liftable(sc,QQ)

o21 = true
i22 : liftable(c^3,QQ)

o22 = false
A random homogeneous element can be obtained with random.
i23 : random(2,R)

      9 2   9       7 2   3      7        2   7             5      3 2   7   
o23 = -a  + -a*b + --b  + -a*c + -b*c + 6c  + -a*d + 7b*d + -c*d + -d  + -a*e
      2     4      10     4      3            4             4      7     9   
      -----------------------------------------------------------------------
        3      2                2    7      6       3      10      3      7 2
      + -b*e + -c*e + 5d*e + 10e  + --a*f + -b*f + --c*f + --d*f + -e*f + -f
        7      9                    10      7      10       9      2      8

o23 : R
A basis of the subspace of ring elements of a given degree can be obtained in matrix form with basis.
i24 : basis(2,R)

o24 = | a2 ab ac ad ae af b2 bc bd be bf c2 cd ce cf d2 de df e2 ef f2 |

              1      21
o24 : Matrix R  <-- R
We may construct polynomial rings over polynomial rings.
i25 : R = 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.
i26 : (a+d+1)^2

       2                2
o26 = d  + (2a + 2)d + a  + 2a + 1

o26 : R
Internally, the polynomials in such towers are expressed in terms of a flattened monoid containing all the variables, obtainable with the key FlatMonoid.
i27 : R.FlatMonoid

o27 = monoid[d..f, a..c, Degrees => {3:{1}, 3:{0}}, Heft => {2:1}, MonomialOrder => {MonomialSize => 32}]
                                       {0}    {1}                                   {GRevLex => {3:1}  }
                                                                                    {Position => Up    }
                                                                                    {GRevLex => {3:1}  }

o27 : GeneralOrderedMonoid
Variable names may be words.
i28 : QQ[rho,sigma,tau];
i29 : (rho - sigma)^2

         2                     2
o29 = rho  - 2rho*sigma + sigma

o29 : QQ[rho, sigma, tau]
There are various other ways to specify the variables in a polynomial ring. A sequence of variables can be obtained as follows.
i30 : ZZ[b..k];
In this example, if you had previously assigned either b or k a value that was not a ring generator, then Macaulay2 would complain about this: it would no longer understand what variables you wanted. To get around this, we could either do
i31 : ZZ[symbol b .. symbol k];
or we may obtain the single-letter variables with vars.
i32 : vars (0..4)

o32 = (a, b, c, d, e)

o32 : Sequence
i33 : ZZ[vars (0..4),vars(26..30),vars 51]

o33 = ZZ[a..e, A..E, Z]

o33 : PolynomialRing
Subscripted variables can be used, provided the base for the subscripted variable has not been used for something else.
i34 : ZZ[t,p_0,p_1,q_0,q_1];
Sequences of subscripted variables can also be used.
i35 : ZZ[p_(0,0) .. p_(2,1),q_0..q_5]

o35 = ZZ[p   ..p   , q ..q ]
          0,0   2,1   0   5

o35 : PolynomialRing
i36 : (p_(0,0)+q_2-1)^2

       2                2
o36 = p    + 2p   q  + q  - 2p    - 2q  + 1
       0,0     0,0 2    2     0,0     2

o36 : ZZ[p   ..p   , q ..q ]
          0,0   2,1   0   5
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.
i37 : protect xx; protect yy; protect zz;
i40 : ZZ[ee_[xx],ee_[yy],ee_[zz]]

o40 = ZZ[ee    , ee    , ee    ]
           [xx]    [yy]    [zz]

o40 : PolynomialRing
A basis of the subspace of ring elements of a given degree can be obtained in matrix form with basis.
i41 : R = QQ[a,b,c,d,e,f];
i42 : basis(2,R)

o42 = | a2 ab ac ad ae af b2 bc bd be bf c2 cd ce cf d2 de df e2 ef f2 |

              1      21
o42 : Matrix R  <-- R
The Hilbert series of a polynomial ring can be obtained. Its power series expansion is the generating function for the dimensions of the degree n parts.
i43 : hilbertSeries R

          1
o43 = --------
             6
      (1 - T)

o43 : Expression of class Divide
We may use the option Degrees to produce rings where the generators have degrees other than 1.
i44 : S = ZZ/101[a,b,c,d,Degrees=>{1,2,3,4}]

o44 = S

o44 : PolynomialRing
i45 : random(5,S)

         3         2      2
o45 = 33a b - 33a*b  - 49a c + 17b*c - 19a*d

o45 : S
i46 : hilbertSeries S

                     1
o46 = -------------------------------
            4       3       2
      (1 - T )(1 - T )(1 - T )(1 - T)

o46 : Expression of class Divide
Some things to watch out for when using polynomial rings:

See also

Menu


The source of this document is in Macaulay2Doc/ov_rings.m2:767:0.