next | previous | forward | backward | up | top | index | toc | Macaulay2 web site
Macaulay2Doc > substitution and maps between rings > substitute

substitute -- substituting values for variables

Synopsis

Description

A convenient abbreviation for substitute is sub.

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 v.
  • give specific values for (some of) the variables. An option x=>r specifies that a generator x should be replaced by the ring element r. Generators not mentioned will be preserved.
  • give a matrix, the entries determines the values of each of the variables
  • give a ring, the effect will be to substitute variables with variables of the same name, into this new ring
i1 : A = QQ[a..f]; B = QQ[a..d]; C = ZZ/101[x,y];
i4 : F = 3*a^2-b-d+101*c

       2
o4 = 3a  - b + 101c - d

o4 : B
The following line substitutes values for a and b, and the result is in the same ring B of F.
i5 : sub(F, {a=>1, b=>b^4})

        4
o5 = - b  + 101c - d + 3

o5 : B
Substitute a by x, b by y and so on. The result is a polynomial in the ring C.
i6 : sub(F, matrix{{x,y,1,0}})

       2
o6 = 3x  - y

o6 : C
Using a ring as the second argument substitutes variables with the same name. The following produces the polynomial F in the rings A and D.
i7 : sub(F, A)

       2
o7 = 3a  - b + 101c - d

o7 : A
i8 : D = B/(a*b*c*d);
i9 : sub(F,D)

       2
o9 = 3a  - b + 101c - d

o9 : D
If the values of all of the variables are in a different ring, then the result will be in that ring.
i10 : use ring F;
i11 : sub(F, {a=>1, b=>3, c=> 1, d=>13})

o11 = 88

o11 : QQ
If f is an ideal or a submodule of a free module over R, then substitution amounts to substitution in the matrix of generators of f. This is not the same as tensor product!
i12 : use B;
i13 : M = image(vars B ++ vars B)

o13 = image | a b c d 0 0 0 0 |
            | 0 0 0 0 a b c d |

                              2
o13 : B-module, submodule of B
i14 : N = substitute(M, {a=>b+c,c=>1})

o14 = image | b+c b 1 d 0   0 0 0 |
            | 0   0 0 0 b+c b 1 d |

                              2
o14 : B-module, submodule of B
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.
i15 : M' = prune M

o15 = 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
o15 : B-module, quotient of B
i16 : N' = coker substitute(presentation M', {a=>b+c,c=>1})

o16 = 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
o16 : B-module, quotient of B
Unevaluated expressions (i.e. from hilbertSeries) may also have variables substituted in all of the ways mentioned so far.
i17 : hf = hilbertSeries coker matrix{{a,b^3,d^5}}

               3    4    5    6    8    9
      1 - T - T  + T  - T  + T  + T  - T
o17 = -----------------------------------
                           4
                    (1 - T)

o17 : Expression of class Divide
i18 : hf1 = reduceHilbert hf

                 2     3     4     5    6
      1 + 2T + 3T  + 3T  + 3T  + 2T  + T
o18 = -----------------------------------
                    (1 - T)

o18 : Expression of class Divide
i19 : use ring numerator hf;
i20 : sub(hf1, T => -1)

      1
o20 = -
      2

o20 : Expression of class Divide
Of course, we can change the ring too:
i21 : sub(hf, T => a)

         9    8    6    5    4    3
      - a  + a  + a  - a  + a  - a  - a + 1
o21 = -------------------------------------
                             4
                    (- a + 1)

o21 : Expression of class Divide
i22 : value oo

         6     5     4     3     2
      - a  - 2a  - 3a  - 3a  - 3a  - 2a - 1
o22 = -------------------------------------
                      a - 1

o22 : frac B
i23 : oo == value sub(hf1, T=>a)

o23 = true

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.

For example, in the first example above, we can make a ring map G, and then apply it to F.

i24 : use B;
i25 : G = map(B,B,{a=>1, b=>b^4})

                   4
o25 = map(B,B,{1, b , c, d})

o25 : RingMap B <--- B
i26 : G F

         4
o26 = - b  + 101c - d + 3

o26 : B

Caveat

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.

See also

Ways to use substitute :