Macaulay2 » Documentation
Packages » Macaulay2Doc :: substituting values for variables
next | previous | forward | backward | up | index | toc

substituting values for variables

Once a ring is defined that has variables, values can be given to these variables using substitute. We give an example.
i1 : R = ZZ/101[x,y,z];
i2 : f = x^3+3*y^2*z+2*z^3;
i3 : substitute(f,matrix{{-1,2,5}})

o3 = 309
i4 : substitute(f,{x=>-1,y=>2,z=>5})

o4 = 6

      ZZ
o4 : ---
     101
The same command works for putting values into ideals or matrices. Also, it is not required that the values be elements from the coefficient ring, nor do you have to give a value for every variable.
i5 : M = matrix{{x^2,x-y},{x-z,z^2},{y-z,y^2}}

o5 = | x2  x-y |
     | x-z z2  |
     | y-z y2  |

             3      2
o5 : Matrix R  <-- R
i6 : substitute(M,matrix{{-1,2,x+y}})

o6 = | 1      -3        |
     | -x-y-1 x2+2xy+y2 |
     | -x-y+2 4         |

             3      2
o6 : Matrix R  <-- R
i7 : I = ideal M

             2                        2   2
o7 = ideal (x , x - z, y - z, x - y, z , y )

o7 : Ideal of R
i8 : substitute(I,{x=>-1,y=>2})

                                      2
o8 = ideal (1, - z - 1, - z + 2, -3, z , 4)

o8 : Ideal of R