polynomial rings

A polynomial ring can be created with the usual mathematical notation.

i1 : ZZ[x,y,z]

o1 = ZZ[x,y,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, the ring knows its name, and the 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,b,c,d,e,f]

o5 : String

Subscript notation can be used to obtain the zero element and the unit element of a ring, or indeed, to obtain any multiple of the unit.

i6 : 0_R

o6 = 0

o6 : R
i7 : 1_R

o7 = 1

o7 : R
i8 : 11_R

o8 = 11

o8 : R

Subscript notation (the other way around) can be used to obtain the variables (generators) from the ring. The first available index is 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 : R_"a"^10+R_"b"^3+R_"c"

       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

The index corresponding to a given variable can be obtained with index.

i14 : index a, index f

o14 = (0, 5)

o14 : Sequence

The coefficient ring can be recovered with coefficientRing.

i15 : coefficientRing R

o15 = QQ

o15 : Field

'QQ' -- denotes the class of all rational numbers.

An element of the coefficient ring can be promoted to the polynomial ring.

i16 : promote(11/2,R)

      11
o16 = --
       2

o16 : R

Conversely, an element of the polynomial ring which is known to be a scalar can be lifted back to the coefficient ring.

i17 : sc = (a-2)^2-a^2+4*a

o17 = 4

o17 : R
i18 : lift(sc,QQ)

o18 = 4

o18 : QQ

In programs, the function liftable can be used to see whether this is possible.

i19 : liftable(sc,QQ)

o19 = true
i20 : liftable(c^3,QQ)

o20 = false

A random element of degree n can be obtained with random.

i21 : random(2,R)

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

o21 : R

We may construct polynomial rings over polynomial rings.

i22 : ZZ[a,b,c][d,e,f];

When displaying an element of an iterated polynomial ring, parentheses may be used to organize the coefficients, which may themselves be polynomials (sums).

i23 : (a+d+1)^2

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

o23 : ZZ[a,b,c][d,e,f]

Variables names may be words.

i24 : QQ[rho,sigma,tau];
i25 : (rho - sigma)^2

         2                     2
o25 = rho  - 2rho*sigma + sigma 

o25 : QQ[rho,sigma,tau]

There are various other ways to specify the variables to be used in a polynomial ring. A sequence of variables can be obtained as follows.

i26 : ZZ[b..k];

The single-letter variables can be obtained with vars.

i27 : vars (0..4)

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

o27 : Sequence
i28 : ZZ[vars (0..4),vars(26..30),vars 51]

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

o28 : PolynomialRing

Subscripted variables can be used, provided the base for the subscripted variable has not been used for something else.

i29 : ZZ[t,p_0,p_1,q_0,q_1];

Sequences of subscripted variables can be obtained.

i30 : ZZ[p_(0,0) .. p_(2,1),q_0..q_5]

o30 = 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

o30 : PolynomialRing
i31 : (p_(0,0)+q_2-1)^2

       2                 2
o31 = p    + 2*p   q  + q  - 2*p    - 2*q  + 1
       0,0      0,0 2    2      0,0      2

o31 : 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 which would interfere with your original use of them as symbols. Thus you should protect symbols which will be used in this way.

i32 : protect xx; protect yy; protect zz;
i35 : ZZ[ee_[xx],ee_[yy],ee_[zz]]

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

o35 : PolynomialRing

A basis of the part of the ring of a given degree can be obtained in matrix form with basis.

i36 : basis(2,R)

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

              1        21
o36 : Matrix R  <--- QQ

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.

i37 : hilbertSeries R

           1
o37 = -----------
                6
      (- $T + 1) 

o37 : Divide

We may use the option Degrees to produce rings where the generators have degrees other than 1.

i38 : S = ZZ/101[a,b,c,d,Degrees=>{1,2,3,4}]

o38 = S

o38 : PolynomialRing
i39 : random(5,S)

       5      3         2      2
o39 = a  - 45a b - 15a*b  + 15a c - 2b*c - 10a*d

o39 : S
i40 : hilbertSeries S

                           1
o40 = -------------------------------------------
                     2          3          4
      (- $T + 1)(- $T  + 1)(- $T  + 1)(- $T  + 1)

o40 : Divide


topindexpreviousupnext