Sophie

Sophie

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

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>diff and contract</title>
<link rel="stylesheet" type="text/css" href="../../../../Macaulay2/Style/doc.css"/>
</head>
<body>
<table class="buttons">
  <tr>
    <td><div><a href="_diff_sq_lp__Matrix_cm__Matrix_rp.html">next</a> | <a href="_diff_lp__Projective__Hilbert__Polynomial_cm__Z__Z_rp.html">previous</a> | <a href="_diff_sq_lp__Matrix_cm__Matrix_rp.html">forward</a> | <a href="_diff.html">backward</a> | up | <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>
<hr/>
<div><h1>diff and contract</h1>
<div>We may use the function <a href="_diff.html" title="differentiate or take difference">diff</a> to differentiate polynomials: the first argument is the variable to differentiate with respect to, and the second argument is the polynomial to be differentiated.<table class="examples"><tr><td><pre>i1 : R = QQ[a,b,t,x,y,z];</pre>
</td></tr>
<tr><td><pre>i2 : f = x^7 * y^11;</pre>
</td></tr>
<tr><td><pre>i3 : diff(x,f)

       6 11
o3 = 7x y

o3 : R</pre>
</td></tr>
<tr><td><pre>i4 : diff(y,f)

        7 10
o4 = 11x y

o4 : R</pre>
</td></tr>
</table>
We indicate higher derivatives by simply multiplying the variables to differentiate by.<table class="examples"><tr><td><pre>i5 : diff(x^2,f)

        5 11
o5 = 42x y

o5 : R</pre>
</td></tr>
<tr><td><pre>i6 : diff(x*y,f)

        6 10
o6 = 77x y

o6 : R</pre>
</td></tr>
<tr><td><pre>i7 : diff(y^2,f)

         7 9
o7 = 110x y

o7 : R</pre>
</td></tr>
</table>
The first argument can also be a sum, in which case the sum of the answers provided by each of its terms is returned.<table class="examples"><tr><td><pre>i8 : diff(x+y,f)

        7 10     6 11
o8 = 11x y   + 7x y

o8 : R</pre>
</td></tr>
<tr><td><pre>i9 : diff(x^2+x*y+y^2,f)

         7 9      6 10      5 11
o9 = 110x y  + 77x y   + 42x y

o9 : R</pre>
</td></tr>
</table>
Remark: the operation <tt>diff</tt> is useful, but it's not a natural one: it's not invariant under linear coordinate changes; in effect, we've identified the a free module with its dual.<p/>
The second argument can be a matrix, in which case each of its entries gets differentiated.<table class="examples"><tr><td><pre>i10 : m = matrix {{x^3, x^4},{x^5,x^6}}

o10 = | x3 x4 |
      | x5 x6 |

              2       2
o10 : Matrix R  &lt;--- R</pre>
</td></tr>
<tr><td><pre>i11 : diff(x,m)

o11 = | 3x2 4x3 |
      | 5x4 6x5 |

              2       2
o11 : Matrix R  &lt;--- R</pre>
</td></tr>
<tr><td><pre>i12 : diff(x^2,m)

o12 = | 6x   12x2 |
      | 20x3 30x4 |

              2       2
o12 : Matrix R  &lt;--- R</pre>
</td></tr>
</table>
The first argument can also be a matrix, in which case the matrices obtained from each of its entries, acting upon the second argument, are concatenated.  Thus the shape of the first matrix plays the major role.<table class="examples"><tr><td><pre>i13 : diff(matrix {{x,x^2,x^3,x^4}}, m)

o13 = | 3x2 4x3 6x   12x2 6    24x   0    24    |
      | 5x4 6x5 20x3 30x4 60x2 120x3 120x 360x2 |

              2       8
o13 : Matrix R  &lt;--- R</pre>
</td></tr>
<tr><td><pre>i14 : diff(matrix {{x,x^2},{x^3,x^4}}, m)

o14 = | 3x2  4x3   6x   12x2  |
      | 5x4  6x5   20x3 30x4  |
      | 6    24x   0    24    |
      | 60x2 120x3 120x 360x2 |

              4       4
o14 : Matrix R  &lt;--- R</pre>
</td></tr>
</table>
<p/>
Perhaps the most common usage of <a href="_diff.html" title="differentiate or take difference">diff</a> is when one argument has a single column and the other column has a single row.  For example, the Jacobian matrix can be computed as follows.<table class="examples"><tr><td><pre>i15 : diff(matrix {{x},{y}}, matrix {{x^2, x*y, y^2}})

o15 = | 2x y 0  |
      | 0  x 2y |

              2       3
o15 : Matrix R  &lt;--- R</pre>
</td></tr>
</table>
<hr/>
We can also compute the Hessian matrix of a quadratic form using <a href="_diff.html" title="differentiate or take difference">diff</a>, as follows.<table class="examples"><tr><td><pre>i16 : v = matrix {{x,y}}

o16 = | x y |

              1       2
o16 : Matrix R  &lt;--- R</pre>
</td></tr>
<tr><td><pre>i17 : diff(v ** transpose v, 3*x^2 + 5*x*y + 11*y^2)

o17 = {1} | 6 5  |
      {1} | 5 22 |

              2       2
o17 : Matrix R  &lt;--- R</pre>
</td></tr>
</table>
<hr/>
As another example, we show how to compute the Wronskian of a polynomial <tt>f</tt>.<table class="examples"><tr><td><pre>i18 : f = x^3 + y^3 + z^3 - t*x*y*z

                   3    3    3
o18 = - t*x*y*z + x  + y  + z

o18 : R</pre>
</td></tr>
<tr><td><pre>i19 : v = matrix {{x,y,z}}

o19 = | x y z |

              1       3
o19 : Matrix R  &lt;--- R</pre>
</td></tr>
<tr><td><pre>i20 : det diff(transpose v * v, f)

          3          2 3     2 3     2 3
o20 = - 2t x*y*z - 6t x  - 6t y  - 6t z  + 216x*y*z

o20 : R</pre>
</td></tr>
</table>
<hr/>
The function <a href="_contract.html" title="contract one matrix by another">contract</a> is the same as <a href="_diff.html" title="differentiate or take difference">diff</a>, except the multiplication by integers that occurs during differentiation is omitted.<table class="examples"><tr><td><pre>i21 : contract(x,m)

o21 = | x2 x3 |
      | x4 x5 |

              2       2
o21 : Matrix R  &lt;--- R</pre>
</td></tr>
<tr><td><pre>i22 : contract(x^2,m)

o22 = | x  x2 |
      | x3 x4 |

              2       2
o22 : Matrix R  &lt;--- R</pre>
</td></tr>
<tr><td><pre>i23 : contract(matrix {{x,x^2,x^3,x^4}}, m)

o23 = | x2 x3 x  x2 1  x  0 1  |
      | x4 x5 x3 x4 x2 x3 x x2 |

              2       8
o23 : Matrix R  &lt;--- R</pre>
</td></tr>
<tr><td><pre>i24 : contract(matrix {{x,x^2},{x^3,x^4}}, m)

o24 = | x2 x3 x  x2 |
      | x4 x5 x3 x4 |
      | 1  x  0  1  |
      | x2 x3 x  x2 |

              4       4
o24 : Matrix R  &lt;--- R</pre>
</td></tr>
</table>
One use is for picking out coefficients of homogeneous polynomials.<table class="examples"><tr><td><pre>i25 : f

                   3    3    3
o25 = - t*x*y*z + x  + y  + z

o25 : R</pre>
</td></tr>
<tr><td><pre>i26 : v3 = symmetricPower(3,matrix{{x,y,z}})

o26 = | x3 x2y x2z xy2 xyz xz2 y3 y2z yz2 z3 |

              1       10
o26 : Matrix R  &lt;--- R</pre>
</td></tr>
<tr><td><pre>i27 : contract(v3, f)

o27 = | 1 0 0 0 -t 0 1 0 0 1 |

              1       10
o27 : Matrix R  &lt;--- R</pre>
</td></tr>
</table>
<hr/>
As an example, the Sylvester resultant between homogeneous polynomials <tt>f(x,y)</tt> and <tt>g(x,y)</tt> can be found in the following way.<table class="examples"><tr><td><pre>i28 : f = a * x^3 + b * x^2 * y + y^3

         3      2     3
o28 = a*x  + b*x y + y

o28 : R</pre>
</td></tr>
<tr><td><pre>i29 : g = b * x^3 + a * x * y^2 + y^3

         3        2    3
o29 = b*x  + a*x*y  + y

o29 : R</pre>
</td></tr>
</table>
Multiply each of these by all quadrics, obtaining a set of elements in degree 5.<table class="examples"><tr><td><pre>i30 : n = matrix {{f,g}} ** symmetricPower(2,matrix {{x,y}})

o30 = | ax5+bx4y+x2y3 ax4y+bx3y2+xy4 ax3y2+bx2y3+y5 bx5+ax3y2+x2y3
      -----------------------------------------------------------------------
      bx4y+ax2y3+xy4 bx3y2+axy4+y5 |

              1       6
o30 : Matrix R  &lt;--- R</pre>
</td></tr>
</table>
Now create the matrix of coefficients by using contract against all monomials of degree 5 in <tt>x</tt> and <tt>y</tt>, and compute its determinant.<table class="examples"><tr><td><pre>i31 : M = contract(transpose symmetricPower(5,matrix {{x,y}}), n)

o31 = {5} | a 0 0 b 0 0 |
      {5} | b a 0 0 b 0 |
      {5} | 0 b a a 0 b |
      {5} | 1 0 b 1 a 0 |
      {5} | 0 1 0 0 1 a |
      {5} | 0 0 1 0 0 1 |

              6       6
o31 : Matrix R  &lt;--- R</pre>
</td></tr>
<tr><td><pre>i32 : det M

         5    2 3    3     2 2       3    4    3     2        2    3
o32 = - a  - a b  - a b - a b  + 2a*b  - b  + a  - 3a b + 3a*b  - b

o32 : R</pre>
</td></tr>
</table>
<hr/>
The function <a href="_diff_sq_lp__Matrix_cm__Matrix_rp.html" title="differentiate a matrix by a matrix, the dual notion">diff'</a> is the same as <a href="_diff.html" title="differentiate or take difference">diff</a>, except that the first argument is differentiated by the second; the shape of the first argument still plays the major role.<table class="examples"><tr><td><pre>i33 : diff'(m, matrix {{x,x^2,x^3,x^4}})

o33 = | 3x2 6x   6    0    4x3 12x2 24x   24    |
      | 5x4 20x3 60x2 120x 6x5 30x4 120x3 360x2 |

              2       8
o33 : Matrix R  &lt;--- R</pre>
</td></tr>
<tr><td><pre>i34 : diff'(m, matrix {{x,x^2},{x^3,x^4}})

o34 = | 3x2  6x   4x3   12x2  |
      | 6    0    24x   24    |
      | 5x4  20x3 6x5   30x4  |
      | 60x2 120x 120x3 360x2 |

              4       4
o34 : Matrix R  &lt;--- R</pre>
</td></tr>
</table>
The function <a href="_contract_sq_lp__Matrix_cm__Matrix_rp.html" title="contract a matrix by a matrix, the dual notion">contract'</a> is the same as <a href="_contract.html" title="contract one matrix by another">contract</a>, except that the first argument is contracted by the second; the shape of the first argument still plays the major role.<table class="examples"><tr><td><pre>i35 : contract'(m, matrix {{x,x^2,x^3,x^4}})

o35 = | x2 x  1  0 x3 x2 x  1  |
      | x4 x3 x2 x x5 x4 x3 x2 |

              2       8
o35 : Matrix R  &lt;--- R</pre>
</td></tr>
<tr><td><pre>i36 : contract'(m, matrix {{x,x^2},{x^3,x^4}})

o36 = | x2 x  x3 x2 |
      | 1  0  x  1  |
      | x4 x3 x5 x4 |
      | x2 x  x3 x2 |

              4       4
o36 : Matrix R  &lt;--- R</pre>
</td></tr>
</table>
<hr/>
All four of these operators are engineered so that the result is a homogeneous matrix if the arguments are.  The operations <a href="_diff.html" title="differentiate or take difference">diff</a> and <a href="_contract.html" title="contract one matrix by another">contract</a> are essentially partially defined division operations, so it should come as no surprise that the source and target of <tt>diff(m,n)</tt> are the same as those we would get from the tensor product <tt>transpose m^-1 ** n</tt>, if only <tt>m</tt> were invertible.</div>
<div class="single"><h2>See also</h2>
<ul><li><span><a href="_diff_lp__Matrix_cm__Matrix_rp.html" title="differentiate a matrix by a matrix">diff(Matrix,Matrix)</a> -- differentiate a matrix by a matrix</span></li>
<li><span><a href="_contract_lp__Matrix_cm__Matrix_rp.html" title="contract a matrix by a matrix">contract(Matrix,Matrix)</a> -- contract a matrix by a matrix</span></li>
<li><span><a href="_reshape_lp__Module_cm__Module_cm__Matrix_rp.html" title="reshape a matrix">reshape</a> -- reshape a matrix</span></li>
<li><span><a href="_adjoint_lp__Matrix_cm__Module_cm__Module_rp.html" title="an adjoint map">adjoint</a> -- an adjoint map</span></li>
</ul>
</div>
</div>
</body>
</html>