next | previous | forward | backward | up | top | index | toc | home
Macaulay2 > 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
  • 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
This can have strange results, if the values are all integers, but fractions are present.
i12 : sub(1/3*a*b, {a=>1, b=>1, c=>1, d=>1})

o12 = 1
By changing one of the values to a rational number, we insure that the result will be rational.
i13 : sub(1/3*a*b, {a=>1_QQ, b=>1, c=>1, d=>1})       

      1
o13 = -
      3

o13 : 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!

i14 : use B;
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
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
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.
i17 : M' = prune M

o17 = cokernel {1} | 0  0  0  0  0  0  -b -c -d 0  0  0  |
               {1} | 0  0  -c -d 0  0  a  0  0  0  0  0  |
               {1} | -d 0  b  0  0  0  0  a  0  0  0  0  |
               {1} | c  0  0  b  0  0  0  0  a  0  0  0  |
               {1} | 0  0  0  0  0  0  0  0  0  -b -c -d |
               {1} | 0  0  0  0  -c -d 0  0  0  a  0  0  |
               {1} | 0  -d 0  0  b  0  0  0  0  0  a  0  |
               {1} | 0  c  0  0  0  b  0  0  0  0  0  a  |

                             8
o17 : B-module, quotient of B
i18 : N' = coker substitute(presentation M', {a=>b+c,c=>1})

o18 = cokernel {1} | 0  0  0  0  0  0  -b  -1  -d  0   0   0   |
               {1} | 0  0  -1 -d 0  0  b+c 0   0   0   0   0   |
               {1} | -d 0  b  0  0  0  0   b+c 0   0   0   0   |
               {1} | 1  0  0  b  0  0  0   0   b+c 0   0   0   |
               {1} | 0  0  0  0  0  0  0   0   0   -b  -1  -d  |
               {1} | 0  0  0  0  -1 -d 0   0   0   b+c 0   0   |
               {1} | 0  -d 0  0  b  0  0   0   0   0   b+c 0   |
               {1} | 0  1  0  0  0  b  0   0   0   0   0   b+c |

                             8
o18 : B-module, quotient of B

Unevaluated expressions (i.e. from hilbertSeries) may also have variables substituted in all of the ways mentioned so far.

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
i20 : hf1 = reduceHilbert hf

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

o20 : Expression of class Divide
i21 : use ring numerator hf;
i22 : sub(hf1, T => -1)

      1
o22 = -
      2

o22 : Expression of class Divide
Of course, we can change the ring too:
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
i24 : value oo

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

o24 : frac(B)
i25 : oo == value sub(hf1, T=>a)

o25 = true

If you plan on using the same substitution over and over, it is wise to create a ring map which 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.

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

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

o27 : RingMap B <--- B
i28 : G F

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

o28 : 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 :