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.
i1 : R1 = ZZ/101; |
i2 : R2 = ZZ/101[s,t]; |
i3 : describe R2 |
Notice that Macaulay 2 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); |
i5 : R3 = R2/I; |
i6 : describe R3 |
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.
i7 : f = s^4+1 |
i8 : g = s^4+t^2+1 |
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) |
i11 : f = s^4+1 |
i12 : g = s^4+t^2+1 |
i13 : substitute(f,R3) |
i14 : describe R3 |
i15 : R4 = frac R3; |
i16 : describe R4 |
The command substitute works well to move elements from R2 or R3 to R4 substitute works well here. 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). For more on ring maps, see basic construction source and target of a ring map. Again 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) |
i20 : use R3; |
i21 : g = substitute(f,R3); |
i22 : substitute(g,R4) |
i23 : F = map(R4,R3) |
i24 : F(f) |
i25 : R5 = R4[u,v,w]; |
i26 : describe R5 |
i27 : J = ideal(u^3-v^2*w+w^3,v^2+w^2,u*v-v*w+u*w) |
i28 : R6 = R5/J; |
i29 : describe R6 |
Notice that at each stage Macaulay2 only refers back to the last ring we defined. All of the methods above work still 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 Groebner basis computations only work over ZZ, ZZ/n and QQ at this time.
i30 : map(R6,R2) |
i31 : substitute(f,R6) |
Macaulay 2 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); |
i35 : G = map(R5,R4); |
i36 : H = map(R6,R5); |
i37 : H(G(F(f))) |
i38 : f1 = substitute(f,R4) |
i39 : f2 = substitute(f1,R5) |
i40 : substitute(f2,R6) |
i41 : substitute(f,vars R3) |
i42 : try substitute(f,vars R5) else "found error" |