- + -- a unary or binary operator, usually used for addition
- - -- a unary or binary operator, usually used for negation or subtraction
- * -- a binary operator, usually used for multiplication
- ^ -- a binary operator, usually used for powers
- // -- a binary operator, usually used for quotient
- % -- a binary operator, usually used for remainder and reduction
- terms -- provide a list of terms of a polynomial
- diff -- differentiate or take difference
- listForm -- convert to list form
- degree
- homogenize -- homogenize with respect to a variable
- exponents -- the exponents of a polynomial
- leadCoefficient -- the coefficient of the leading term
- leadTerm -- get the greatest term
- size -- the size of an object

i1 : R = ZZ/10007[a,b]; |

i2 : f = (2*a+3)^4 + 5 4 3 2 o2 = 16a + 96a + 216a + 216a + 86 o2 : R |

i3 : g = (2*a+b+1)^3 3 2 2 3 2 2 o3 = 8a + 12a b + 6a*b + b + 12a + 12a*b + 3b + 6a + 3b + 1 o3 : R |

i4 : size f, size g o4 = (5, 10) o4 : Sequence |

i5 : degree f o5 = {4} o5 : List |

i6 : degree g o6 = {3} o6 : List |

The list of terms of a polynomial is obtained with terms.

i7 : terms g 3 2 2 3 2 2 o7 = {8a , 12a b, 6a*b , b , 12a , 12a*b, 3b , 6a, 3b, 1} o7 : List |

i8 : select(terms g, i -> degree i == {2}) 2 2 o8 = {12a , 12a*b, 3b } o8 : List |

i9 : sum oo 2 2 o9 = 12a + 12a*b + 3b o9 : R |

i10 : part(0,g) o10 = 1 o10 : R |

i11 : part(1,g) o11 = 6a + 3b o11 : R |

i12 : part(2,g) 2 2 o12 = 12a + 12a*b + 3b o12 : R |

i13 : part(3,g) 3 2 2 3 o13 = 8a + 12a b + 6a*b + b o13 : R |

i14 : toString f o14 = 16*a^4+96*a^3+216*a^2+216*a+86 |

i15 : toString g o15 = 8*a^3+12*a^2*b+6*a*b^2+b^3+12*a^2+12*a*b+3*b^2+6*a+3*b+1 |

The usual algebraic operations on polynomials are available, but there are some special remarks to make about division. The result of division depends on the ordering of monomials chosen when the ring is created, for division of `f` by `g` proceeds by locating monomials in `f` divisible by the leading monomial of `g`, and substituting for it the negation of the rest of `g`. The quotient is provided by the expression `f//g`, and the remainder is obtained with `f%g`.

i16 : quot = f//g o16 = 2a - 3b + 9 o16 : R |

i17 : rem = f%g 2 2 3 4 2 2 2 2 o17 = 24a b + 16a*b + 3b - 96a b - 24a*b + 96a - 96a*b - 18b + 160a - ----------------------------------------------------------------------- 24b + 77 o17 : R |

i18 : f == quot * g + rem o18 = true |

Polynomials can be homogenized with respect to one of the variables in the ring with homogenize.

i19 : homogenize(f,b) 4 3 2 2 3 4 o19 = 16a + 96a b + 216a b + 216a*b + 86b o19 : R |

The ring containing a ring element can be obtained with ring.

i20 : ring f o20 = R o20 : PolynomialRing |

i21 : ring f === ring g o21 = true |

The coefficient of a monomial in a polynomial can be obtained with _.

i22 : part(1,f) o22 = 216a o22 : R |

i23 : f_a o23 = 216 ZZ o23 : ----- 10007 |

i24 : g_(a*b) o24 = 12 ZZ o24 : ----- 10007 |

We may get parts of the leading term of a polynomial as follows.

i25 : leadTerm g 3 o25 = 8a o25 : R |

i26 : leadCoefficient g o26 = 8 ZZ o26 : ----- 10007 |

i27 : leadMonomial g 3 o27 = a o27 : R |

i28 : exponents leadMonomial g o28 = {{3, 0}} o28 : List |

i29 : exponents leadTerm g o29 = {{3, 0}} o29 : List |

i30 : coefficients f o30 = (| a4 a3 a2 a 1 |, {4} | 16 |) {3} | 96 | {2} | 216 | {1} | 216 | {0} | 86 | o30 : Sequence |

i31 : coefficients g o31 = (| a3 a2b ab2 b3 a2 ab b2 a b 1 |, {3} | 8 |) {3} | 12 | {3} | 6 | {3} | 1 | {2} | 12 | {2} | 12 | {2} | 3 | {1} | 6 | {1} | 3 | {0} | 1 | o31 : Sequence |

i32 : exponents f o32 = {{4, 0}, {3, 0}, {2, 0}, {1, 0}, {0, 0}} o32 : List |

i33 : exponents g o33 = {{3, 0}, {2, 1}, {1, 2}, {0, 3}, {2, 0}, {1, 1}, {0, 2}, {1, 0}, {0, ----------------------------------------------------------------------- 1}, {0, 0}} o33 : List |

i34 : listForm f o34 = {({4, 0}, 16), ({3, 0}, 96), ({2, 0}, 216), ({1, 0}, 216), ({0, 0}, ----------------------------------------------------------------------- 86)} o34 : List |

i35 : S = listForm g o35 = {({3, 0}, 8), ({2, 1}, 12), ({1, 2}, 6), ({0, 3}, 1), ({2, 0}, 12), ----------------------------------------------------------------------- ({1, 1}, 12), ({0, 2}, 3), ({1, 0}, 6), ({0, 1}, 3), ({0, 0}, 1)} o35 : List |

i36 : S / print; ({3, 0}, 8) ({2, 1}, 12) ({1, 2}, 6) ({0, 3}, 1) ({2, 0}, 12) ({1, 1}, 12) ({0, 2}, 3) ({1, 0}, 6) ({0, 1}, 3) ({0, 0}, 1) |

i37 : S = standardForm f o37 = HashTable{HashTable{} => 86 } HashTable{0 => 1} => 216 HashTable{0 => 2} => 216 HashTable{0 => 3} => 96 HashTable{0 => 4} => 16 o37 : HashTable |

i38 : standardForm g o38 = HashTable{HashTable{} => 1 } HashTable{0 => 1} => 12 1 => 1 HashTable{0 => 1} => 6 1 => 2 HashTable{0 => 1} => 6 HashTable{0 => 2} => 12 1 => 1 HashTable{0 => 2} => 12 HashTable{0 => 3} => 8 HashTable{1 => 1} => 3 HashTable{1 => 2} => 3 HashTable{1 => 3} => 1 o38 : HashTable |

i39 : S#(new HashTable from {0 => 2}) o39 = 216 ZZ o39 : ----- 10007 |

Comparison of polynomials is possible, and proceeds by simply examining the lead monomials and comparing them.

i40 : f < g o40 = false |

i41 : sort {b^2-1,a*b,a+1,a,b} 2 o41 = {b, a, a + 1, b - 1, a*b} o41 : List |

i42 : f ? g o42 = > o42 : Keyword |