Debian Codegraph @

texmf-dist/tex/lualatex/luacas/test/rings/luacas-conversion.lua

raw
1 local a = Integer(12)
2 local b = Integer(3) / Integer(2)
3 local c = IntegerModN(Integer(4), Integer(7))
4 local d = IntegerModN(Integer(8), Integer(14))
5 local e = PolynomialRing({Integer(6), Integer(0), Integer(3)}, SymbolExpression("x"))
6 local f = PolynomialRing({Integer(4)/Integer(5), Integer(12)}, SymbolExpression("x"))
7 local g = PolynomialRing({
8 PolynomialRing({
9 PolynomialRing({Integer(-4), Integer(12), Integer(1)}, SymbolExpression("x")),
10 PolynomialRing({Integer(0)}, SymbolExpression("x")),
11 PolynomialRing({Integer(8)}, SymbolExpression("x"))
12 },
13 SymbolExpression("y")),
14 PolynomialRing({
15 PolynomialRing({Integer(8), Integer(7), Integer(6), Integer(5)}, SymbolExpression("x")),
16 PolynomialRing({Integer(-1)}, SymbolExpression("x")),
17 },
18 SymbolExpression("y")),
19 PolynomialRing({
20 PolynomialRing({Integer(0)}, SymbolExpression("x")),
21 PolynomialRing({Integer(2), Integer(8), Integer(1)}, SymbolExpression("x")),
22 PolynomialRing({Integer(-16), Integer(4)}, SymbolExpression("x")),
23 PolynomialRing({Integer(1)}, SymbolExpression("x"))
24 },
25 SymbolExpression("y")),
26 PolynomialRing({
27 PolynomialRing({Integer(1)}, SymbolExpression("x"))
28 },
29 SymbolExpression("y"))
30 }, SymbolExpression("z"))
31 local h = PolynomialRing({
32 PolynomialRing({
33 PolynomialRing({Integer(-4), Integer(4)/Integer(5), Integer(1)}, SymbolExpression("z")),
34 PolynomialRing({Integer(0)}, SymbolExpression("z")),
35 PolynomialRing({Integer(8)}, SymbolExpression("z"))
36 },
37 SymbolExpression("y")),
38 PolynomialRing({
39 PolynomialRing({Integer(8), Integer(7), Integer(6), Integer(5)}, SymbolExpression("z")),
40 PolynomialRing({Integer(-1)}, SymbolExpression("z")),
41 },
42 SymbolExpression("y")),
43 PolynomialRing({
44 PolynomialRing({Integer(0)}, SymbolExpression("z")),
45 PolynomialRing({Integer(2), Integer(8), Integer(1)}, SymbolExpression("z")),
46 PolynomialRing({Integer(-16), Integer(1)/Integer(9)}, SymbolExpression("z")),
47 PolynomialRing({Integer(1)}, SymbolExpression("z"))
48 },
49 SymbolExpression("y")),
50 PolynomialRing({
51 PolynomialRing({Integer(1)}, SymbolExpression("z"))
52 },
53 SymbolExpression("y"))
54 }, SymbolExpression("x"))
55 local i = Rational(PolynomialRing({-Integer(2), Integer(1)}, SymbolExpression("x")),
56 PolynomialRing({Integer(3), Integer(3), Integer(1)}, SymbolExpression("x")))
57 local j = Rational(PolynomialRing({-Integer(2), Integer(1)}, SymbolExpression("x")),
58 PolynomialRing({Integer(3)/Integer(4), Integer(3)/Integer(8), Integer(1)}, SymbolExpression("x")))
59 local k = PolynomialRing({IntegerModN(Integer(0), Integer(5)),
60 IntegerModN(Integer(1), Integer(5)),
61 IntegerModN(Integer(3), Integer(5)),
62 IntegerModN(Integer(1), Integer(5))}, SymbolExpression("x"))
63
64 local l = PolynomialRing({Rational(
65 PolynomialRing({Integer(4), Integer(1)}, SymbolExpression("x")),
66 PolynomialRing({Integer(0), Integer(4)}, SymbolExpression("x"))
67 ),
68 Rational(
69 PolynomialRing({Integer(3)/Integer(2)}, SymbolExpression("x")),
70 PolynomialRing({Integer(6), Integer(1)/Integer(2), Integer(8), Integer(1)}, SymbolExpression("x"))
71 ),
72 Rational(
73 PolynomialRing({Integer(6), Integer(6), Integer(4)}, SymbolExpression("x")),
74 PolynomialRing({Integer(3), Integer(1)}, SymbolExpression("x"))
75 ),
76 Rational(
77 PolynomialRing({Integer(7)/Integer(6)}, SymbolExpression("x")),
78 PolynomialRing({Integer(2), Integer(1)}, SymbolExpression("x"))
79 )
80 }, SymbolExpression("y"))
81
82 local aring = a:getring() -- ZZ
83 local bring = b:getring() -- QQ
84 local cring = c:getring() -- ZZ_7
85 local dring = d:getring() -- ZZ_14
86 local ering = e:getring() -- ZZ[x]
87 local fring = f:getring() -- QQ[x]
88 local gring = g:getring() -- ZZ[x][y][z]
89 local hring = h:getring() -- QQ[z][y][x]
90 local iring = i:getring() -- ZZ(x)
91 local jring = j:getring() -- QQ(x)
92 local kring = k:getring() -- ZZ_5[x]
93 local lring = l:getring() -- QQ(x)[y]
94
95 starttest("ring construction")
96 testeq(aring, "ZZ")
97 testeq(bring, "QQ")
98 testeq(cring, "Z/Z7")
99 testeq(dring, "Z/Z14")
100 testeq(ering, "ZZ[x]")
101 testeq(fring, "QQ[x]")
102 testeq(gring, "ZZ[x][y][z]")
103 testeq(hring, "QQ[z][y][x]")
104 testeq(iring, "ZZ(x)")
105 testeq(jring, "QQ(x)")
106 testeq(kring, "Z/Z5[x]")
107 testeq(lring, "QQ(x)[y]")
108 endtest()
109
110 starttest("ring conversion")
111
112 -- Commented-out tests denote elements whos rings are not subrings of the ring that is being converted to
113
114 testringconvert(a, aring, "12", "ZZ")
115 testringconvert(a, bring, "12/1", "QQ")
116 testringconvert(a, cring, "5", "Z/Z7")
117 testringconvert(a, dring, "12", "Z/Z14")
118 testringconvert(a, ering, "12x^0", "ZZ[x]")
119 testringconvert(a, fring, "12/1x^0", "QQ[x]")
120 testringconvert(a, gring, "((12x^0)y^0)z^0", "ZZ[x][y][z]")
121 testringconvert(a, hring, "((12/1z^0)y^0)x^0", "QQ[z][y][x]")
122 testringconvert(a, iring, "(12x^0)/(1x^0)", "ZZ(x)")
123 testringconvert(a, jring, "(12/1x^0)/(1/1x^0)", "QQ(x)")
124 testringconvert(a, kring, "2x^0", "Z/Z5[x]")
125 testringconvert(a, lring, "((12/1x^0)/(1/1x^0))y^0", "QQ(x)[y]")
126
127 -- testringconvert(b, aring, "3/2", "ZZ")
128 testringconvert(b, bring, "3/2", "QQ")
129 -- testringconvert(b, cring, "3/2", "Z/Z7")
130 -- testringconvert(b, dring, "3/2", "Z/Z14")
131 -- testringconvert(b, ering, "3/2", "ZZ[x]")
132 testringconvert(b, fring, "3/2x^0", "QQ[x]")
133 -- testringconvert(b, gring, "3/2", "ZZ[x][y][z]")
134 testringconvert(b, hring, "((3/2z^0)y^0)x^0", "QQ[z][y][x]")
135 -- testringconvert(b, iring, "3/2", "ZZ(x)")
136 testringconvert(b, jring, "(3/2x^0)/(1/1x^0)", "QQ(x)")
137 -- testringconvert(b, kring, "3/2", "Z/Z5[x]")
138 testringconvert(b, lring, "((3/2x^0)/(1/1x^0))y^0", "QQ(x)[y]")
139
140 testringconvert(c, aring, "4", "ZZ")
141 -- testringconvert(c, bring, "4", "QQ")
142 testringconvert(c, cring, "4", "Z/Z7")
143 testringconvert(c, dring, "4", "Z/Z14")
144 testringconvert(c, ering, "4x^0", "ZZ[x]")
145 -- testringconvert(c, fring, "4x", "QQ[x]")
146 testringconvert(c, gring, "((4x^0)y^0)z^0", "ZZ[x][y][z]")
147 -- testringconvert(c, hring, "4", "QQ[z][y][x]")
148 testringconvert(c, iring, "(4x^0)/(1x^0)", "ZZ(x)")
149 -- testringconvert(c, jring, "12/1x^0/1/1x^0", "QQ(x)")
150 testringconvert(c, kring, "4x^0", "Z/Z5[x]")
151 -- testringconvert(c, lring, "4", "QQ(x)[y]")
152
153 testringconvert(d, aring, "8", "ZZ")
154 -- testringconvert(d, bring, "8", "QQ")
155 testringconvert(d, cring, "1", "Z/Z7")
156 testringconvert(d, dring, "8", "Z/Z14")
157 testringconvert(d, ering, "8x^0", "ZZ[x]")
158 -- testringconvert(d, fring, "8", "QQ[x]")
159 testringconvert(d, gring, "((8x^0)y^0)z^0", "ZZ[x][y][z]")
160 -- testringconvert(d, hring, "8", "QQ[z][y][x]")
161 testringconvert(d, iring, "(8x^0)/(1x^0)", "ZZ(x)")
162 -- testringconvert(d, jring, "8", "QQ(x)")
163 testringconvert(d, kring, "3x^0", "Z/Z5[x]")
164 -- testringconvert(d, lring, "8", "QQ(x)[y]")
165
166 -- testringconvert(e, aring, "3x^2+0x^1+6x^0", "ZZ")
167 -- testringconvert(e, bring, "3x^2+0x^1+6x^0", "QQ")
168 -- testringconvert(e, cring, "3x^2+0x^1+6x^0", "Z/Z7")
169 -- testringconvert(e, dring, "3x^2+0x^1+6x^0", "Z/Z14")
170 testringconvert(e, ering, "3x^2+0x^1+6x^0", "ZZ[x]")
171 testringconvert(e, fring, "3/1x^2+0/1x^1+6/1x^0", "QQ[x]")
172 testringconvert(e, gring, "((3x^2+0x^1+6x^0)y^0)z^0", "ZZ[x][y][z]")
173 testringconvert(e, hring, "((3/1z^0)y^0)x^2+((0/1z^0)y^0)x^1+((6/1z^0)y^0)x^0", "QQ[z][y][x]")
174 testringconvert(e, iring, "(3x^2+0x^1+6x^0)/(1x^0)", "ZZ(x)")
175 testringconvert(e, jring, "(3/1x^2+0/1x^1+6/1x^0)/(1/1x^0)", "QQ(x)")
176 testringconvert(e, kring, "3x^2+0x^1+1x^0", "Z/Z5[x]")
177 testringconvert(e, lring, "((3/1x^2+0/1x^1+6/1x^0)/(1/1x^0))y^0", "QQ(x)[y]")
178
179 -- testringconvert(f, aring, "12x^1+4/5x^0", "ZZ")
180 -- testringconvert(f, bring, "12x^1+4/5x^0", "QQ")
181 -- testringconvert(f, cring, "12x^1+4/5x^0", "Z/Z7")
182 -- testringconvert(f, dring, "12x^1+4/5x^0", "Z/Z14")
183 -- testringconvert(f, ering, "12x^1+4/5x^0", "ZZ[x]")
184 testringconvert(f, fring, "12x^1+4/5x^0", "QQ[x]")
185 -- testringconvert(f, gring, "12x^1+4/5x^0", "ZZ[x][y][z]")
186 testringconvert(f, hring, "((12/1z^0)y^0)x^1+((4/5z^0)y^0)x^0", "QQ[z][y][x]")
187 -- testringconvert(f, iring, "12x^1+4/5x^0", "ZZ(x)")
188 testringconvert(f, jring, "(12x^1+4/5x^0)/(1/1x^0)", "QQ(x)")
189 -- testringconvert(f, kring, "12x^1+4/5x^0", "Z/Z5[x]")
190 testringconvert(f, lring, "((12x^1+4/5x^0)/(1/1x^0))y^0", "QQ(x)[y]")
191
192 -- testringconvert(g, aring, "", "ZZ")
193 -- testringconvert(g, bring, "", "QQ")
194 -- testringconvert(g, cring, "", "Z/Z7")
195 -- testringconvert(g, dring, "", "Z/Z14")
196 -- testringconvert(g, ering, "", "ZZ[x]")
197 -- testringconvert(g, fring, "", "QQ[x]")
198 testringconvert(g, gring, "((1x^0)y^0)z^3+((1x^0)y^3+(4x^1+-16x^0)y^2+(1x^2+8x^1+2x^0)y^1+(0x^0)y^0)z^2+((-1x^0)y^1+(5x^3+6x^2+7x^1+8x^0)y^0)z^1+((8x^0)y^2+(0x^0)y^1+(1x^2+12x^1+-4x^0)y^0)z^0", "ZZ[x][y][z]")
199 -- testringconvert(g, hring, "", "QQ[z][y][x]")
200 -- testringconvert(g, iring, "", "ZZ(x)")
201 -- testringconvert(g, jring, "", "QQ(x)")
202 -- testringconvert(g, kring, "", "Z/Z5[x]")
203 -- testringconvert(g, lring, "", "QQ(x)[y]")
204
205 -- testringconvert(h, aring, "", "ZZ")
206 -- testringconvert(h, bring, "", "QQ")
207 -- testringconvert(h, cring, "", "Z/Z7")
208 -- testringconvert(h, dring, "", "Z/Z14")
209 -- testringconvert(h, ering, "", "ZZ[x]")
210 -- testringconvert(h, fring, "", "QQ[x]")
211 -- testringconvert(h, gring, "", "ZZ[x][y][z]")
212 testringconvert(h, hring, "((1z^0)y^0)x^3+((1z^0)y^3+(1/9z^1+-16z^0)y^2+(1z^2+8z^1+2z^0)y^1+(0z^0)y^0)x^2+((-1z^0)y^1+(5z^3+6z^2+7z^1+8z^0)y^0)x^1+((8z^0)y^2+(0z^0)y^1+(1z^2+4/5z^1+-4z^0)y^0)x^0", "QQ[z][y][x]")
213 -- testringconvert(h, iring, "", "ZZ(x)")
214 -- testringconvert(h, jring, "", "QQ(x)")
215 -- testringconvert(h, kring, "", "Z/Z5[x]")
216 -- testringconvert(h, lring, "", "QQ(x)[y]")
217
218 -- testringconvert(i, aring, "", "ZZ")
219 -- testringconvert(i, bring, "", "QQ")
220 -- testringconvert(i, cring, "", "Z/Z7")
221 -- testringconvert(i, dring, "", "Z/Z14")
222 -- testringconvert(i, ering, "", "ZZ[x]")
223 -- testringconvert(i, fring, "", "QQ[x]")
224 -- testringconvert(i, gring, "", "ZZ[x][y][z]")
225 -- testringconvert(i, hring, "", "QQ[z][y][x]")
226 testringconvert(i, iring, "(1x^1+-2x^0)/(1x^2+3x^1+3x^0)", "ZZ(x)")
227 testringconvert(i, jring, "(1/1x^1+-2/1x^0)/(1/1x^2+3/1x^1+3/1x^0)", "QQ(x)")
228 -- testringconvert(i, kring, "", "Z/Z5[x]")
229 testringconvert(i, lring, "((1/1x^1+-2/1x^0)/(1/1x^2+3/1x^1+3/1x^0))y^0", "QQ(x)[y]")
230
231 -- testringconvert(j, aring, "", "ZZ")
232 -- testringconvert(j, bring, "", "QQ")
233 -- testringconvert(j, cring, "", "Z/Z7")
234 -- testringconvert(j, dring, "", "Z/Z14")
235 -- testringconvert(j, ering, "", "ZZ[x]")
236 -- testringconvert(j, fring, "", "QQ[x]")
237 -- testringconvert(j, gring, "", "ZZ[x][y][z]")
238 -- testringconvert(j, hring, "", "QQ[z][y][x]")
239 -- testringconvert(j, iring, "", "ZZ(x)")
240 testringconvert(j, jring, "(1x^1+-2x^0)/(1x^2+3/8x^1+3/4x^0)", "QQ(x)")
241 -- testringconvert(j, kring, "", "Z/Z5[x]")
242 testringconvert(j, lring, "((1x^1+-2x^0)/(1x^2+3/8x^1+3/4x^0))y^0", "QQ(x)[y]")
243
244 -- testringconvert(k, aring, "", "ZZ")
245 -- testringconvert(k, bring, "", "QQ")
246 -- testringconvert(k, cring, "", "Z/Z7")
247 -- testringconvert(k, dring, "", "Z/Z14")
248 testringconvert(k, ering, "1x^3+3x^2+1x^1+0x^0", "ZZ[x]")
249 -- testringconvert(k, fring, "", "QQ[x]")
250 testringconvert(k, gring, "((1x^3+3x^2+1x^1+0x^0)y^0)z^0", "ZZ[x][y][z]")
251 -- testringconvert(k, hring, "", "QQ[z][y][x]")
252 testringconvert(k, iring, "(1x^3+3x^2+1x^1+0x^0)/(1x^0)", "ZZ(x)")
253 -- testringconvert(k, jring, "", "QQ(x)")
254 testringconvert(k, kring, "1x^3+3x^2+1x^1+0x^0", "Z/Z5[x]")
255 -- testringconvert(k, lring, "", "QQ(x)[y]")
256
257 -- testringconvert(l, aring, "", "ZZ")
258 -- testringconvert(l, bring, "", "QQ")
259 -- testringconvert(l, cring, "", "Z/Z7")
260 -- testringconvert(l, dring, "", "Z/Z14")
261 -- testringconvert(l, ering, "", "ZZ[x]")
262 -- testringconvert(l, fring, "", "QQ[x]")
263 -- testringconvert(l, gring, "", "ZZ[x][y][z]")
264 -- testringconvert(l, hring, "", "QQ[z][y][x]")
265 -- testringconvert(l, iring, "", "ZZ(x)")
266 -- testringconvert(l, jring, "", "QQ(x)")
267 -- testringconvert(j, kring, "", "Z/Z5[x]")
268 testringconvert(l, lring, "((7/6x^0)/(1x^1+2x^0))y^3+((4x^2+6x^1+6x^0)/(1x^1+3x^0))y^2+((3/2x^0)/(1x^3+8x^2+1/2x^1+6x^0))y^1+((1/4x^1+1x^0)/(1x^1+0x^0))y^0", "QQ(x)[y]")
269
270
271
272
273 endtest()