[top][index]
search for:

polynomial rings

Create a polynomial ring using the usual mathematical notation.

i1 : R = QQ[x,y,z];
i2 : R

o2 = R

o2 : PolynomialRing

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

o3 = QQ [x, y, z]

Use the following subscript notation to obtain 0,1, or any multiple of 1, as elements in the ring.

i4 : 0_R

o4 = 0

o4 : R
i5 : 1_R

o5 = 1

o5 : R
i6 : 11_R

o6 = 11

o6 : 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

      10    3
o7 = x   + y  + z

o7 : R

The number of variables is provided by numgens.

i8 : numgens R

o8 = 3
i9 : apply(numgens R, i -> R_i^i)

             2
o9 = {1, y, z }

o9 : List
i10 : sum(numgens R, i -> R_i^i)

       2
o10 = z  + y + 1

o10 : R

(for more information, see apply and sum.Use generators to obtain a list of the variables of the ring.

i11 : gens R

o11 = {x, y, z}

o11 : List

A (one row) matrix containing the variables of the ring can be obtained using (vars,Ring).

i12 : vars R

o12 = | x y z |

              1       3
o12 : Matrix R  <--- R

The index of a variable:

i13 : index x, index y, index z

o13 = (0, 1, 2)

o13 : Sequence

The coefficient ring can be recovered with coefficientRing.

i14 : coefficientRing R

o14 = QQ

o14 : Ring

  --  the class of all rational numbers

A random homogeneous element can be obtained with random.

i15 : random(2,R)

      5             8       2  2
o15 = -*x*y + x*z - -*y*z - -*z
      2             9       5

o15 : 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)

o16 = | x2 xy xz y2 yz z2 |

              1       6
o16 : Matrix R  <--- 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

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

o18 : (ZZ [a, b, c])[d, e, f]

Variable names may be words.

i19 : QQ[rho,sigma,tau];
i20 : (rho - sigma)^2

         2                     2
o20 = rho  - 2rho*sigma + sigma

o20 : 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.

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)

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

o23 : Sequence
i24 : ZZ[vars (0..4),vars(26..30),vars 51]

o24 = ZZ [a, b, c, d, e, A, B, C, D, E, Z]

o24 : PolynomialRing

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]

o26 = ZZ [p   , p   , p   , p   , p   , p   , q , q , q , q , q , q ]
           0,0   0,1   1,0   1,1   2,0   2,1   0   1   2   3   4   5

o26 : PolynomialRing
i27 : (p_(0,0)+q_2-1)^2

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

o27 : ZZ [p   , p   , p   , p   , p   , p   , q , q , q , q , q , q ]
           0,0   0,1   1,0   1,1   2,0   2,1   0   1   2   3   4   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.

i28 : protect xx; protect yy; protect zz;
i31 : ZZ[ee_[xx],ee_[yy],ee_[zz]]

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

o31 : PolynomialRing

Some things to watch out for when using polynomial rings:

  • Defining a ring twice gives different rings, as far as Macaulay 2 is concerned: We use the strict comparison operator === to demonstrate this.

    i32 : ZZ[a,b,c] === ZZ[a,b,c]

    o32 = false

    Thus it is a good idea to assign a new ring to a variable for future reference.

  • Variables in monomials are compacted into a smaller space in the machine, for efficiency reasons. If your exponents will be larger than 127, then use the MonomialSize option to increase the amount of space.

    i33 : R = QQ[a..d];
    i34 : a^127

           127
    o34 = a

    o34 : R
    i35 : S = QQ[a..d,MonomialSize=>16];
    i36 : a^32767

           32767
    o36 = a

    o36 : S

    The value 16 is the largest value that you may currently give. Giving the value k to MonomialSize, allows exponents with maximum value 2^(k-1)-1.

  • Polynomial rings whose coefficient rings are polynomial rings can be very useful for organizing and extracting coefficients easily, but currently most computations cannot be done for these rings. This includes Groebner bases, and therefore all of the applications of Groebner bases.

  • [top][index]
    search for: