Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > 7ebd25ac536d248d499a3ce2acda963a > files > 4698

Macaulay2-1.3.1-8.fc15.i686.rpm

<?xml version="1.0" encoding="utf-8" ?>  <!-- for emacs: -*- coding: utf-8 -*- -->
<!-- Apache may like this line in the file .htaccess: AddCharset utf-8 .html -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"	 "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg-flat.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head><title>manipulating polynomials</title>
<link rel="stylesheet" type="text/css" href="../../../../Macaulay2/Style/doc.css"/>
</head>
<body>
<table class="buttons">
  <tr>
    <td><div><a href="_factoring_sppolynomials.html">next</a> | <a href="_quotient_springs.html">previous</a> | <a href="_factoring_sppolynomials.html">forward</a> | <a href="_quotient_springs.html">backward</a> | <a href="_rings.html">up</a> | <a href="index.html">top</a> | <a href="master.html">index</a> | <a href="toc.html">toc</a> | <a href="http://www.math.uiuc.edu/Macaulay2/">Macaulay2 web site</a></div>

    </td>
  </tr>
</table>
<div><a href="index.html" title="">Macaulay2Doc</a> > <a href="_rings.html" title="">rings</a> > <a href="_manipulating_sppolynomials.html" title="">manipulating polynomials</a></div>
<hr/>
<div><h1>manipulating polynomials</h1>
<div><ul><li><span><a href="__pl.html" title="a unary or binary operator, usually used for addition">+</a> -- a unary or binary operator, usually used for addition</span></li>
<li><span><a href="_-.html" title="a unary or binary operator, usually used for negation or subtraction">-</a> -- a unary or binary operator, usually used for negation or subtraction</span></li>
<li><span><a href="__st.html" title="a binary operator, usually used for multiplication">*</a> -- a binary operator, usually used for multiplication</span></li>
<li><span><a href="_^.html" title="a binary operator, usually used for powers">^</a> -- a binary operator, usually used for powers</span></li>
<li><span><a href="__sl_sl.html" title="a binary operator, usually used for quotient">//</a> -- a binary operator, usually used for quotient</span></li>
<li><span><a href="__pc.html" title="a binary operator, usually used for remainder and reduction">%</a> -- a binary operator, usually used for remainder and reduction</span></li>
<li><span><a href="_terms.html" title="provide a list of terms of a polynomial">terms</a> -- provide a list of terms of a polynomial</span></li>
<li><span><a href="_diff.html" title="differentiate or take difference">diff</a> -- differentiate or take difference</span></li>
<li><span><a href="_list__Form.html" title="convert to list form">listForm</a> -- convert to list form</span></li>
<li><span><a href="_degree.html" title="">degree</a></span></li>
<li><span><a href="_homogenize.html" title="homogenize with respect to a variable">homogenize</a> -- homogenize with respect to a variable</span></li>
<li><span><a href="_exponents.html" title="list the exponents in a polynomial">exponents</a> -- list the exponents in a polynomial</span></li>
<li><span><a href="_lead__Coefficient.html" title="the leading coefficient">leadCoefficient</a> -- the leading coefficient</span></li>
<li><span><a href="_lead__Term.html" title="get the greatest term">leadTerm</a> -- get the greatest term</span></li>
<li><span><a href="_size.html" title="the size of an object">size</a> -- the size of an object</span></li>
</ul>
Let's set up some polynomials.<table class="examples"><tr><td><pre>i1 : R = ZZ/10007[a,b];</pre>
</td></tr>
<tr><td><pre>i2 : f = (2*a+3)^4 + 5

        4      3       2
o2 = 16a  + 96a  + 216a  + 216a + 86

o2 : R</pre>
</td></tr>
<tr><td><pre>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</pre>
</td></tr>
</table>
The number of terms in a polynomial is obtained with <a href="_size.html" title="the size of an object">size</a>.<table class="examples"><tr><td><pre>i4 : size f, size g

o4 = (5, 10)

o4 : Sequence</pre>
</td></tr>
</table>
The degree of a polynomial is obtained with <a href="_degree.html" title="">degree</a>.<table class="examples"><tr><td><pre>i5 : degree f

o5 = {4}

o5 : List</pre>
</td></tr>
<tr><td><pre>i6 : degree g

o6 = {3}

o6 : List</pre>
</td></tr>
</table>
(Notice that the degree is a list containing one integer, rather than an integer.  The degree is actually a vector of integers, represented as a list, with one component by default.)<p/>
The list of terms of a polynomial is obtained with <a href="_terms.html" title="provide a list of terms of a polynomial">terms</a>.<table class="examples"><tr><td><pre>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</pre>
</td></tr>
</table>
We may combine that with <a href="_select.html" title="select from a list, hash table, or string">select</a> to select terms satisfying certain conditions.  Here we select the terms of degree 2, subsequently summing them, keeping in mind that the degree of a polynomial is always a list of integers.<table class="examples"><tr><td><pre>i8 : select(terms g, i -> degree i == {2})

         2           2
o8 = {12a , 12a*b, 3b }

o8 : List</pre>
</td></tr>
<tr><td><pre>i9 : sum oo

        2             2
o9 = 12a  + 12a*b + 3b

o9 : R</pre>
</td></tr>
</table>
Of course, if the list of selected terms is empty, the sum would turn out to be the zero integer, rather than the zero element of the ring <tt>R</tt>.  Fortunately, we have another way to select the elements of given degree or multi-degree (see <a href="_part.html" title="select terms of a polynomial by degree or weight">part</a>).<table class="examples"><tr><td><pre>i10 : part(0,g)

o10 = 1

o10 : R</pre>
</td></tr>
<tr><td><pre>i11 : part(1,g)

o11 = 6a + 3b

o11 : R</pre>
</td></tr>
<tr><td><pre>i12 : part(2,g)

         2             2
o12 = 12a  + 12a*b + 3b

o12 : R</pre>
</td></tr>
<tr><td><pre>i13 : part(3,g)

        3      2        2    3
o13 = 8a  + 12a b + 6a*b  + b

o13 : R</pre>
</td></tr>
</table>
A string representing the polynomial, suitable for entry into other programs, can be obtained with <a href="_to__String.html" title="convert to a string">toString</a>.<table class="examples"><tr><td><pre>i14 : toString f

o14 = 16*a^4+96*a^3+216*a^2+216*a+86</pre>
</td></tr>
<tr><td><pre>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</pre>
</td></tr>
</table>
<p/>
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 <tt>f</tt> by <tt>g</tt> proceeds by locating monomials in <tt>f</tt> divisible by the leading monomial of <tt>g</tt>, and substituting for it the negation of the rest of <tt>g</tt>.  The quotient is provided by the expression <tt>f//g</tt>, and the remainder is obtained with <tt>f%g</tt>.<table class="examples"><tr><td><pre>i16 : quot = f//g

o16 = 2a - 3b + 9

o16 : R</pre>
</td></tr>
<tr><td><pre>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</pre>
</td></tr>
<tr><td><pre>i18 : f == quot * g + rem

o18 = true</pre>
</td></tr>
</table>
Notice that as in the example above, comparison of polynomials is done with the operator <a href="__eq_eq.html" title="equality">==</a>.<p/>
Polynomials can be homogenized with respect to one of the variables in the ring with <a href="_homogenize.html" title="homogenize with respect to a variable">homogenize</a>.<table class="examples"><tr><td><pre>i19 : homogenize(f,b)

         4      3        2 2         3      4
o19 = 16a  + 96a b + 216a b  + 216a*b  + 86b

o19 : R</pre>
</td></tr>
</table>
<p/>
The ring containing a ring element can be obtained with <a href="_ring.html" title="get the associated ring of an object">ring</a>.<table class="examples"><tr><td><pre>i20 : ring f

o20 = R

o20 : PolynomialRing</pre>
</td></tr>
</table>
You can use this in a program to check whether two ring elements come from the same ring.<table class="examples"><tr><td><pre>i21 : ring f === ring g

o21 = true</pre>
</td></tr>
</table>
Notice that in the comparison above, the strict equality operator <a href="___Thing_sp_eq_eq_eq_sp__Thing.html" title="strict equality">===</a> is used.<p/>
The coefficient of a monomial in a polynomial can be obtained with <a href="__us.html" title="a binary operator, used for subscripting and access to elements">_</a>.<table class="examples"><tr><td><pre>i22 : part(1,f)

o22 = 216a

o22 : R</pre>
</td></tr>
<tr><td><pre>i23 : f_a

o23 = 216

        ZZ
o23 : -----
      10007</pre>
</td></tr>
<tr><td><pre>i24 : g_(a*b)

o24 = 12

        ZZ
o24 : -----
      10007</pre>
</td></tr>
</table>
(Notice that the coefficients are elements of the coefficient ring.)<p/>
We may get parts of the leading term of a polynomial as follows.<table class="examples"><tr><td><pre>i25 : leadTerm g

        3
o25 = 8a

o25 : R</pre>
</td></tr>
<tr><td><pre>i26 : leadCoefficient g

o26 = 8

        ZZ
o26 : -----
      10007</pre>
</td></tr>
<tr><td><pre>i27 : leadMonomial g

       3
o27 = a

o27 : R</pre>
</td></tr>
</table>
Notice that the lead monomial is an element of a monoid whose name is <tt>[a,b]</tt>.  Its exponents can be extracted with <a href="_exponents.html" title="list the exponents in a polynomial">exponents</a>.<table class="examples"><tr><td><pre>i28 : exponents leadMonomial g

o28 = {{3, 0}}

o28 : List</pre>
</td></tr>
</table>
We can get all of the coefficients at once, assembled a one-rowed matrix, along with a matrix containing the corresponding monomials.<table class="examples"><tr><td><pre>i29 : coefficients f

o29 = (| a4 a3 a2 a 1 |, {4} | 16  |)
                         {3} | 96  |
                         {2} | 216 |
                         {1} | 216 |
                         {0} | 86  |

o29 : Sequence</pre>
</td></tr>
<tr><td><pre>i30 : coefficients g

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

o30 : Sequence</pre>
</td></tr>
</table>
A list of lists of exponents appearing in a polynomial can be obtained with <a href="_exponents.html" title="list the exponents in a polynomial">exponents</a>.<table class="examples"><tr><td><pre>i31 : exponents f

o31 = {{4, 0}, {3, 0}, {2, 0}, {1, 0}, {0, 0}}

o31 : List</pre>
</td></tr>
<tr><td><pre>i32 : exponents g

o32 = {{3, 0}, {2, 1}, {1, 2}, {0, 3}, {2, 0}, {1, 1}, {0, 2}, {1, 0}, {0,
      -----------------------------------------------------------------------
      1}, {0, 0}}

o32 : List</pre>
</td></tr>
</table>
The entire structure of a polynomial can be provided in an accessible form based on lists with <a href="_list__Form.html" title="convert to list form">listForm</a>.<table class="examples"><tr><td><pre>i33 : listForm f

o33 = {({4, 0}, 16), ({3, 0}, 96), ({2, 0}, 216), ({1, 0}, 216), ({0, 0},
      -----------------------------------------------------------------------
      86)}

o33 : List</pre>
</td></tr>
<tr><td><pre>i34 : S = listForm g

o34 = {({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)}

o34 : List</pre>
</td></tr>
</table>
The lists above are lists of pairs, where the first member of each pair is a list of exponents in a monomial, and the second member is the corresponding coefficient.  Standard list operations can be used to manipulate the result.<table class="examples"><tr><td><pre>i35 : 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)</pre>
</td></tr>
</table>
The structure of a polynomial can also be provided in a form based on hash tables with <a href="_standard__Form.html" title="convert to standard form">standardForm</a>.<table class="examples"><tr><td><pre>i36 : S = standardForm f

o36 = HashTable{HashTable{} => 86       }
                HashTable{0 => 1} => 216
                HashTable{0 => 2} => 216
                HashTable{0 => 3} => 96
                HashTable{0 => 4} => 16

o36 : HashTable</pre>
</td></tr>
<tr><td><pre>i37 : standardForm g

o37 = HashTable{HashTable{} => 1       }
                HashTable{0 => 1} => 6
                HashTable{0 => 1} => 12
                          1 => 1
                HashTable{0 => 1} => 6
                          1 => 2
                HashTable{0 => 2} => 12
                HashTable{0 => 2} => 12
                          1 => 1
                HashTable{0 => 3} => 8
                HashTable{1 => 1} => 3
                HashTable{1 => 2} => 3
                HashTable{1 => 3} => 1

o37 : HashTable</pre>
</td></tr>
</table>
The hash tables above present the same information, except that only nonzero exponents need to be provided.  The information can be extracted with <a href="__sh.html" title="length, or access to elements">#</a>.<table class="examples"><tr><td><pre>i38 : S#(new HashTable from {0 => 2})

o38 = 216

        ZZ
o38 : -----
      10007</pre>
</td></tr>
</table>
<p/>
Comparison of polynomials is possible, and proceeds by simply examining the lead monomials and comparing them.<table class="examples"><tr><td><pre>i39 : f &lt; g

o39 = false</pre>
</td></tr>
<tr><td><pre>i40 : sort {b^2-1,a*b,a+1,a,b}

                     2
o40 = {b, a, a + 1, b  - 1, a*b}

o40 : List</pre>
</td></tr>
</table>
The comparison operator <a href="__qu.html" title="comparison operator">?</a> returns a symbol indicating how two polynomials, or rather, their lead monomials, stand with respect to each other in the monomial ordering.<table class="examples"><tr><td><pre>i41 : f ? g

o41 = >

o41 : Keyword</pre>
</td></tr>
</table>
</div>
</div>
</body>
</html>