A polynomial ring can be created with the usual mathematical notation.
i1 : ZZ[x,y,z] |
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] |
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] |
Notice that after assignment to a global variable, the ring knows its name, and the name is used when printing the ring.
i4 : R |
The original description of the ring can be recovered with describe.
i5 : describe R |
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 |
i7 : 1_R |
i8 : 11_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 |
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" |
The number of variables is provided by numgens.
i11 : numgens R |
i12 : apply(numgens R, i -> R_i^i) |
i13 : sum(numgens R, i -> R_i^i) |
The index corresponding to a given variable can be obtained with index.
i14 : index a, index f |
The coefficient ring can be recovered with coefficientRing.
i15 : coefficientRing R |
An element of the coefficient ring can be promoted to the polynomial ring.
i16 : promote(11/2,R) |
Conversely, an element of the polynomial ring that is known to be a scalar can be lifted back to the coefficient ring.
i17 : sc = (a-2)^2-a^2+4*a |
i18 : lift(sc,QQ) |
In programs, the function liftable can be used to see whether this is possible.
i19 : liftable(sc,QQ) |
i20 : liftable(c^3,QQ) |
A random homogeneous element can be obtained with random.
i21 : random(2,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 are used to organize the coefficients recursively, which may themselves be polynomials.
i23 : (a+d+1)^2 |
Variable names may be words.
i24 : QQ[rho,sigma,tau]; |
i25 : (rho - sigma)^2 |
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) |
i28 : 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.
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] |
i31 : (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.
i32 : protect xx; protect yy; protect zz; |
i35 : ZZ[ee_[xx],ee_[yy],ee_[zz]] |
A basis of the subspace of ring elements of a given degree can be obtained in matrix form with basis.
i36 : basis(2,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.
i37 : hilbertSeries R |
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}] |
i39 : random(5,S) |
i40 : hilbertSeries S |
See also: