Working with multiple rings is more subtle than simply replacing values of the variables in a ring. On the other hand it is particularly easy in Macaulay2. We define a sequence of rings below and move between each to show both the dangers and the convenience.
defining multiple rings
i1 : R1 = ZZ/101;

i2 : R2 = ZZ/101[s,t];

i3 : describe R2
o3 = R1[s..t, Degrees => {2:1}, Heft => {1}]

Notice that Macaulay2 sees the coefficient ring as R1, we could just as easily defined
R2 as
R1[s,t] . Movement and addition between these rings is easy.
i4 : I = ideal (s^4+t^2+1);
o4 : Ideal of R2

i5 : R3 = R2/I;

i6 : describe R3
R2
o6 = 
4 2
s + t + 1

Since
I is defined as an ideal in
R2 we cannot type
ZZ/101[s,t]/I as the computer sees
ZZ/101[s,t] as different from
R2 and so does not see
I as being in this ring. For more about defining rings see
rings. We now work with moving between
R2 and
R3.
moving between rings using use and substitute
i7 : f = s^4+1
2
o7 = t
o7 : R3

i8 : g = s^4+t^2+1
o8 = 0
o8 : R3

f and g are elements in
R3 now and this is shown by the fact that Macaulay2 sees them as
t^2 and 0. To recover these elements as polynomials in
R2 type
use R2 and define them again in
R2. The command substitute does not work well here, where as if we want to see the image of elements of
R2 in
R3 it does work well and without using the command
use. Macaulay2 always tells you which ring an element is in on the line after it prints the ring element.
i9 : use R2;

i10 : substitute(g,R2)
o10 = 0
o10 : R2

i11 : f = s^4+1
4
o11 = s + 1
o11 : R2

i12 : g = s^4+t^2+1
4 2
o12 = s + t + 1
o12 : R2

i13 : substitute(f,R3)
2
o13 = t
o13 : R3

subtleties of substitute and describe
Now we complicate things further by constructing a fraction field and then further constructing polynomial rings and quotient rings. First we see that while
describe helped us to see how we defined
R2 and
R3, the same does not hold when a fraction field is constructed. Note that R3 is a domain.
i14 : describe R3
R2
o14 = 
4 2
s + t + 1

i15 : R4 = frac R3;

i16 : describe R4
/ R2 \
o16 = frac
 4 2 
\s + t + 1/

The command
substitute works well to move elements from
R2 or
R3 to
R4. An alternative to substitute is to form the canonical injection of R3 into R4 (the same can be done for the canonical projection from R2 to R3 above  we do the example here). To move elements from
R4 back to
R3 an alternate method must be used. Also, the method of constructing a map does not work well in the reverse direction for the same reasons
substitute does not.
i17 : use R2;

i18 : f = s^4+1;

i19 : substitute(f,R4)
2
o19 = t
o19 : R4

i20 : use R3;

i21 : g = substitute(f,R3);

i22 : substitute(g,R4)
2
o22 = t
o22 : R4

i23 : F = map(R4,R3)
o23 = map (R4, R3, {s, t})
o23 : RingMap R4 < R3

i24 : F(f)
2
o24 = t
o24 : R4

nonstandard coefficient fields
We can go through the whole process again using R4 now as the field.
i25 : R5 = R4[u,v,w];

i26 : describe R5
o26 = R4[u..w, Degrees => {3:1}, Heft => {1}]

i27 : J = ideal(u^3v^2*w+w^3,v^2+w^2,u*vv*w+u*w)
3 2 3 2 2
o27 = ideal (u  v w + w , v + w , u*v + u*w  v*w)
o27 : Ideal of R5

i28 : R6 = R5/J;

i29 : describe R6
R5
o29 = 
3 2 3 2 2
(u  v w + w , v + w , u*v + u*w  v*w)

Notice that at each stage Macaulay2 only refers back to the last ring we defined. All of the methods above still work here in theory, but caution is advised. We give an example below to illustrate. Also, note that many other computations will no longer work, because Gröbner basis computations only work over
ZZ,
ZZ/n and
QQ at this time.
using maps to move between rings
i30 : map(R6,R2)
o30 = map (R6, R2, {s, t})
o30 : RingMap R6 < R2

i31 : substitute(f,R6)
2
o31 = t
o31 : R6

Macaulay2 claims this is the zero map, and that the image of
f is 1, but we know better. By forming a series of maps and composing them we see the map that makes sense. We also contrast the map with using
substitute.
i32 : use R2;

i33 : f = s^4+1;

i34 : F = map(R4,R2);
o34 : RingMap R4 < R2

i35 : G = map(R5,R4);
o35 : RingMap R5 < R4

i36 : H = map(R6,R5);
o36 : RingMap R6 < R5

i37 : H(G(F(f)))
2
o37 = t
o37 : R6

i38 : f1 = substitute(f,R4)
2
o38 = t
o38 : R4

i39 : f2 = substitute(f1,R5)
2
o39 = t
o39 : R5

i40 : substitute(f2,R6)
2
o40 = t
o40 : R6

elements versus matrices
Finally, note that everywhere we used the element
f we can place a matrix or an ideal and get similar results.
substitute(J,vars R)
We close this long example with a brief discussion of
substitute(J,vars R). This command is more sensitive than
substitute as it will give an error message when the variables involved do not match up.
i41 : substitute(f,vars R3)
2
o41 = t
o41 : R3

i42 : try substitute(f,vars R5) else "found error"
o42 = found error
