<?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>substitute -- substituting values for variables</title> <link rel="stylesheet" type="text/css" href="../../../../Macaulay2/Style/doc.css"/> </head> <body> <table class="buttons"> <tr> <td><div><a href="_working_spwith_spmultiple_springs.html">next</a> | <a href="_substitution_spand_spmaps_spbetween_springs.html">previous</a> | <a href="_working_spwith_spmultiple_springs.html">forward</a> | backward | <a href="_substitution_spand_spmaps_spbetween_springs.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="_substitution_spand_spmaps_spbetween_springs.html" title="">substitution and maps between rings</a> > <a href="_substitute.html" title="substituting values for variables">substitute</a></div> <hr/> <div><h1>substitute -- substituting values for variables</h1> <div class="single"><h2>Synopsis</h2> <ul><li><div class="list"><dl class="element"><dt class="heading">Usage: </dt><dd class="value"><div><tt>substitute(f,v)</tt><br/><tt>sub(f,v)</tt></div> </dd></dl> </div> </li> <li><div class="single">Inputs:<ul><li><span><tt>f</tt>, <span>a <a href="___Ring__Element.html">ring element</a></span>, <span>a <a href="___Matrix.html">matrix</a></span>, <span>an <a href="___Ideal.html">ideal</a></span>, <span>a <a href="___Module.html">module</a></span>, <span>a <a href="___Vector.html">vector</a></span>, or <span>an <a href="___Expression.html">expression</a></span> over a ring <tt>R</tt></span></li> <li><span><tt>v</tt>, <span>a <a href="___Ring.html">ring</a></span>, <span>a <a href="___Matrix.html">matrix</a></span>, <span>an <a href="___Option.html">option</a></span>, or a list of options: variable => value</span></li> </ul> </div> </li> <li><div class="single">Outputs:<ul><li><span>An object of the same sort as <tt>f</tt>, obtained by substituting values for the variables in the ring <tt>R</tt> of <tt>f</tt> using <tt>v</tt>.</span></li> </ul> </div> </li> </ul> </div> <div class="single"><h2>Description</h2> <div>A convenient abbreviation for <a href="_substitute.html" title="substituting values for variables">substitute</a> is <tt>sub</tt>.<p/> This function allows you to substitute values for some variables. There are three ways to describe the kind of substitution, depending on the second argument <tt>v</tt>.<ul><li>give specific values for (some of) the variables</li> <li>give a matrix, the entries determines the values of each of the variables</li> <li>give a ring, the effect will be to substitute variables with variables of the same name, into this new ring</li> </ul> <p/> <table class="examples"><tr><td><pre>i1 : A = QQ[a..f]; B = QQ[a..d]; C = ZZ/101[x,y];</pre> </td></tr> <tr><td><pre>i4 : F = 3*a^2-b-d+101*c 2 o4 = 3a - b + 101c - d o4 : B</pre> </td></tr> </table> The following line substitutes values for a and b, and the result is in the same ring <tt>B</tt> of <tt>F</tt>.<table class="examples"><tr><td><pre>i5 : sub(F, {a=>1, b=>b^4}) 4 o5 = - b + 101c - d + 3 o5 : B</pre> </td></tr> </table> Substitute <tt>a</tt> by <tt>x</tt>, <tt>b</tt> by <tt>y</tt> and so on. The result is a polynomial in the ring <tt>C</tt>.<table class="examples"><tr><td><pre>i6 : sub(F, matrix{{x,y,1,0}}) 2 o6 = 3x - y o6 : C</pre> </td></tr> </table> Using a ring as the second argument substitutes variables with the same name. The following produces the polynomial <tt>F</tt> in the rings <tt>A</tt> and <tt>D</tt>.<table class="examples"><tr><td><pre>i7 : sub(F, A) 2 o7 = 3a - b + 101c - d o7 : A</pre> </td></tr> <tr><td><pre>i8 : D = B/(a*b*c*d);</pre> </td></tr> <tr><td><pre>i9 : sub(F,D) 2 o9 = 3a - b + 101c - d o9 : D</pre> </td></tr> </table> If the values of all of the variables are in a different ring, then the result will be in that ring.<table class="examples"><tr><td><pre>i10 : use ring F;</pre> </td></tr> <tr><td><pre>i11 : sub(F, {a=>1, b=>3, c=> 1, d=>13}) o11 = 88</pre> </td></tr> </table> This can have strange results, if the values are all integers, but fractions are present.<table class="examples"><tr><td><pre>i12 : sub(1/3*a*b, {a=>1, b=>1, c=>1, d=>1}) o12 = 1</pre> </td></tr> </table> By changing one of the values to a rational number, we insure that the result will be rational.<table class="examples"><tr><td><pre>i13 : sub(1/3*a*b, {a=>1_QQ, b=>1, c=>1, d=>1}) 1 o13 = - 3 o13 : QQ</pre> </td></tr> </table> <p/> If <tt>f</tt> is an ideal or a submodule of a free module over <tt>R</tt>, then substitution amounts to substitution in the matrix of generators of <tt>f</tt>. This is not the same as tensor product!<table class="examples"><tr><td><pre>i14 : use B;</pre> </td></tr> <tr><td><pre>i15 : M = image(vars B ++ vars B) o15 = image | a b c d 0 0 0 0 | | 0 0 0 0 a b c d | 2 o15 : B-module, submodule of B</pre> </td></tr> <tr><td><pre>i16 : N = substitute(M, {a=>b+c,c=>1}) o16 = image | b+c b 1 d 0 0 0 0 | | 0 0 0 0 b+c b 1 d | 2 o16 : B-module, submodule of B</pre> </td></tr> </table> Although we cannot use substitute directly on modules which are not submodules, here is a useful idiom for moving a cokernel module to another ring. One must be careful though: the degrees of the generators might not be the desired ones.<table class="examples"><tr><td><pre>i17 : M' = prune M o17 = cokernel {1} | -b 0 -c 0 0 -d 0 0 0 0 0 0 | {1} | a -c 0 0 -d 0 0 0 0 0 0 0 | {1} | 0 b a -d 0 0 0 0 0 0 0 0 | {1} | 0 0 0 c b a 0 0 0 0 0 0 | {1} | 0 0 0 0 0 0 -b 0 -c 0 0 -d | {1} | 0 0 0 0 0 0 a -c 0 0 -d 0 | {1} | 0 0 0 0 0 0 0 b a -d 0 0 | {1} | 0 0 0 0 0 0 0 0 0 c b a | 8 o17 : B-module, quotient of B</pre> </td></tr> <tr><td><pre>i18 : N' = coker substitute(presentation M', {a=>b+c,c=>1}) o18 = cokernel {1} | -b 0 -1 0 0 -d 0 0 0 0 0 0 | {1} | b+c -1 0 0 -d 0 0 0 0 0 0 0 | {1} | 0 b b+c -d 0 0 0 0 0 0 0 0 | {1} | 0 0 0 1 b b+c 0 0 0 0 0 0 | {1} | 0 0 0 0 0 0 -b 0 -1 0 0 -d | {1} | 0 0 0 0 0 0 b+c -1 0 0 -d 0 | {1} | 0 0 0 0 0 0 0 b b+c -d 0 0 | {1} | 0 0 0 0 0 0 0 0 0 1 b b+c | 8 o18 : B-module, quotient of B</pre> </td></tr> </table> <p/> Unevaluated expressions (i.e. from <a href="_hilbert__Series.html" title="compute the Hilbert series">hilbertSeries</a>) may also have variables substituted in all of the ways mentioned so far.<table class="examples"><tr><td><pre>i19 : hf = hilbertSeries coker matrix{{a,b^3,d^5}} 3 4 5 6 8 9 1 - T - T + T - T + T + T - T o19 = ----------------------------------- 4 (1 - T) o19 : Expression of class Divide</pre> </td></tr> <tr><td><pre>i20 : hf1 = reduceHilbert hf 2 3 4 5 6 1 + 2T + 3T + 3T + 3T + 2T + T o20 = ----------------------------------- (1 - T) o20 : Expression of class Divide</pre> </td></tr> <tr><td><pre>i21 : use ring numerator hf;</pre> </td></tr> <tr><td><pre>i22 : sub(hf1, T => -1) 1 o22 = - 2 o22 : Expression of class Divide</pre> </td></tr> </table> Of course, we can change the ring too:<table class="examples"><tr><td><pre>i23 : sub(hf, T => a) 9 8 6 5 4 3 - a + a + a - a + a - a - a + 1 o23 = ------------------------------------- 4 (- a + 1) o23 : Expression of class Divide</pre> </td></tr> <tr><td><pre>i24 : value oo 6 5 4 3 2 - a - 2a - 3a - 3a - 3a - 2a - 1 o24 = ------------------------------------- a - 1 o24 : frac(B)</pre> </td></tr> <tr><td><pre>i25 : oo == value sub(hf1, T=>a) o25 = true</pre> </td></tr> </table> <p/> If you plan on using the same substitution over and over, it is wise to create a ring map that will perform the same substitution.<p/> For example, in the first example above, we can make <span>a <a href="___Ring__Map.html">ring map</a></span> <tt>G</tt>, and then apply it to <tt>F</tt>.<table class="examples"><tr><td><pre>i26 : use B;</pre> </td></tr> <tr><td><pre>i27 : G = map(B,B,{a=>1, b=>b^4}) 4 o27 = map(B,B,{1, b , c, d}) o27 : RingMap B <--- B</pre> </td></tr> <tr><td><pre>i28 : G F 4 o28 = - b + 101c - d + 3 o28 : B</pre> </td></tr> </table> </div> </div> <div class="single"><h2>Caveat</h2> <div>The specified substitution is not checked to see whether the corresponding ring homomorphism is well-defined; this may produce surprising results, especially if rational coefficients are converted to integer coefficients.</div> </div> <div class="single"><h2>See also</h2> <ul><li><span><a href="___Ring__Map.html" title="the class of all ring maps">RingMap</a> -- the class of all ring maps</span></li> <li><span><a href="_hilbert__Series.html" title="compute the Hilbert series">hilbertSeries</a> -- compute the Hilbert series</span></li> <li><span><a href="_value.html" title="evaluate">value</a> -- evaluate</span></li> <li><span><a href="___Expression.html" title="the class of all expressions">Expression</a> -- the class of all expressions</span></li> </ul> </div> <div class="waystouse"><h2>Ways to use <tt>substitute</tt> :</h2> <ul><li>substitute(Divide,Thing)</li> <li>substitute(Ideal,List)</li> <li>substitute(Ideal,Matrix)</li> <li>substitute(Ideal,Option)</li> <li>substitute(Ideal,Ring)</li> <li>substitute(Ideal,RingFamily)</li> <li>substitute(Matrix,List)</li> <li>substitute(Matrix,Matrix)</li> <li>substitute(Matrix,Option)</li> <li>substitute(Matrix,Ring)</li> <li>substitute(Matrix,RingFamily)</li> <li>substitute(Matrix,ZZ)</li> <li>substitute(Module,List)</li> <li>substitute(Module,Matrix)</li> <li>substitute(Module,Option)</li> <li>substitute(Module,Ring)</li> <li>substitute(Module,RingFamily)</li> <li>substitute(Number,Ring)</li> <li>substitute(Number,RingFamily)</li> <li>substitute(Power,Thing)</li> <li>substitute(Product,Thing)</li> <li>substitute(RingElement,List)</li> <li>substitute(RingElement,Matrix)</li> <li>substitute(RingElement,Option)</li> <li>substitute(RingElement,Ring)</li> <li>substitute(RingElement,RingFamily)</li> <li>substitute(Sum,Thing)</li> <li>substitute(Vector,List)</li> <li>substitute(Vector,Matrix)</li> <li>substitute(Vector,Option)</li> <li>substitute(Vector,Ring)</li> <li>substitute(Vector,RingFamily)</li> </ul> </div> </div> </body> </html>