1 | // |
---|
2 | // gcd0_s.tst - short tests for gcd calculations in Z. |
---|
3 | // |
---|
4 | // All univariate non-trivial examples come from gcdUniv0Std.fex or |
---|
5 | // gcdUniv0Alpha.fex. Some of the examples are multiplied with elements |
---|
6 | // from Q to test clearing of denominators. |
---|
7 | // |
---|
8 | // The examples in variables `u' and `v' came from `coprasse(2/0/1)' |
---|
9 | // in stdMultiv0Gcd.in. |
---|
10 | // |
---|
11 | // To Do: |
---|
12 | // |
---|
13 | // o multivariate gcd calculations with parameters |
---|
14 | // o algrebraic extensions of char 0 not implemented yet |
---|
15 | // (but tests already exist) |
---|
16 | // |
---|
17 | |
---|
18 | LIB "tst.lib"; |
---|
19 | tst_init(); |
---|
20 | |
---|
21 | // |
---|
22 | // - ring r1=0,x,dp. |
---|
23 | // |
---|
24 | |
---|
25 | tst_ignore( "ring r1=0,x,dp;" ); |
---|
26 | ring r1=0,x,dp; |
---|
27 | |
---|
28 | poly f=(-9554*x^4-12895*x^3-10023*x^2-6213*x); |
---|
29 | poly g; |
---|
30 | |
---|
31 | // some trivial examples |
---|
32 | gcd(0, 0); |
---|
33 | gcd(0, 3123); |
---|
34 | gcd(4353, 0); |
---|
35 | |
---|
36 | gcd(0, f); |
---|
37 | gcd(f, 0); |
---|
38 | |
---|
39 | gcd(23123, f); |
---|
40 | gcd(f, 13123); |
---|
41 | |
---|
42 | // some trivial examples involving rational numbers |
---|
43 | f=11/47894*19*(-9554*x^4-12895*x^3-10023*x^2-6213*x); |
---|
44 | |
---|
45 | gcd(0, 3123/123456); |
---|
46 | gcd(4353/8798798, 0); |
---|
47 | |
---|
48 | gcd(0, f); |
---|
49 | gcd(f, 0); |
---|
50 | |
---|
51 | gcd(23123/3, f); |
---|
52 | gcd(f, 13123/2); |
---|
53 | |
---|
54 | // some less trivial examples |
---|
55 | f=(2*x^3+2*x^2+2*x); |
---|
56 | g=(x^3+2*x^2+2*x+1); |
---|
57 | gcd(f, g); |
---|
58 | |
---|
59 | f=(-x^9-6*x^8-11*x^7-17*x^6-14*x^5-14*x^4-8*x^3-6*x^2-2*x-1); |
---|
60 | g=(-x^9-2*x^8-2*x^7-3*x^4-6*x^3-6*x^2-3*x-1); |
---|
61 | gcd(f, g); |
---|
62 | |
---|
63 | f=(4*x^9+12*x^8+29*x^7+42*x^6+54*x^5+48*x^4+35*x^3+17*x^2+6*x+1); |
---|
64 | g=(x^11+6*x^10+11*x^9+17*x^8+14*x^7+14*x^6+8*x^5+6*x^4+2*x^3+x^2); |
---|
65 | gcd(f, g); |
---|
66 | gcd(1/13*f, 1/4*g); |
---|
67 | |
---|
68 | f=(1412500*x^6+6218750*x^5-6910000*x^4-1201250*x^3-19470000*x^2-27277500*x); |
---|
69 | g=(156600000*x^5-1363865625*x^4+2627604000*x^3-2727731250*x^2+4628808000*x); |
---|
70 | gcd(f, g); |
---|
71 | |
---|
72 | // |
---|
73 | // - ring r2=(0,a),x,dp; minpoly=a^4+a^3+a^2+a+1. |
---|
74 | // |
---|
75 | |
---|
76 | tst_ignore( "ring r2=(0,a),x,dp;" ); |
---|
77 | ring r2=(0,a),x,dp; |
---|
78 | minpoly=a^4+a^3+a^2+a+1; |
---|
79 | |
---|
80 | poly f=(-9554*x^4-12895*x^3-10023*x^2-6213*x); |
---|
81 | poly g; |
---|
82 | |
---|
83 | // first, some of the r1 examples (slightly modified) |
---|
84 | gcd(0, 0); |
---|
85 | gcd(0, 3123*a); |
---|
86 | gcd(4353, 0); |
---|
87 | |
---|
88 | gcd(0, f); |
---|
89 | gcd(f, 0); |
---|
90 | |
---|
91 | gcd(23123, f); |
---|
92 | gcd(f, 13123); |
---|
93 | |
---|
94 | // some trivial examples involving rational numbers |
---|
95 | f=11/47894*19*(-9554*x^4-12895*x^3-10023*x^2-6213*x); |
---|
96 | |
---|
97 | gcd(0, 3123/(123456*a)); |
---|
98 | gcd(4353/8798798, 0); |
---|
99 | |
---|
100 | gcd(0, f/a); |
---|
101 | gcd(f, 0); |
---|
102 | |
---|
103 | gcd(23123/(3*a), f); |
---|
104 | gcd(f, 13123/2); |
---|
105 | |
---|
106 | // some less trivial examples |
---|
107 | f=(2*x^3+2*x^2+2*x); |
---|
108 | g=(x^3+2*x^2+2*x+1); |
---|
109 | gcd(f, g); |
---|
110 | |
---|
111 | // we go on with modified variable names |
---|
112 | tst_ignore( "ring r2=(0,v),u,dp;" ); |
---|
113 | kill r2; |
---|
114 | ring r2=(0,v),u,dp; |
---|
115 | minpoly=v^4+v^3+v^2+v+1; |
---|
116 | |
---|
117 | poly f; |
---|
118 | poly g; |
---|
119 | |
---|
120 | // last not least, some less trivial examples |
---|
121 | // involving the algebraic variable. Examples |
---|
122 | // are from r3. |
---|
123 | f=(-8*u^2*v+8*u*v^2-24*u); |
---|
124 | g=(-64*u^2*v+16*u*v^2); |
---|
125 | gcd(f, g); |
---|
126 | |
---|
127 | f=(192*u^6*v^4-240*u^5*v^5+384*u^5*v^3+48*u^4*v^6+96*u^4*v^4-576*u^4*v^2-48*u^3*v^5+144*u^3*v^3); |
---|
128 | g=(1536*u^6*v^4-768*u^5*v^5-1536*u^5*v^3+96*u^4*v^6+768*u^4*v^4-96*u^3*v^5); |
---|
129 | gcd(f, g); |
---|
130 | |
---|
131 | f=(-256*u^3*v+128*u^2*v^2-16*u*v^3); |
---|
132 | g=(-64*u^3+48*u^2*v^2+32*u^2*v-192*u^2-12*u*v^3-4*u*v^2+48*u*v); |
---|
133 | gcd(f, g); |
---|
134 | |
---|
135 | // |
---|
136 | // - ring r3=(0,t),x,dp. |
---|
137 | // |
---|
138 | |
---|
139 | tst_ignore( "ring r3=(0,t),x,dp;" ); |
---|
140 | ring r3=(0,t),x,dp; |
---|
141 | |
---|
142 | poly f=(-9554*x^4-12895*x^3-10023*x^2-6213*x); |
---|
143 | poly g; |
---|
144 | |
---|
145 | // first, some of the r1 examples (slightly modified) |
---|
146 | gcd(0, 0); |
---|
147 | gcd(0, 3123*t); |
---|
148 | gcd(4353, 0); |
---|
149 | |
---|
150 | gcd(0, f); |
---|
151 | gcd(f, 0); |
---|
152 | |
---|
153 | gcd(23123, f); |
---|
154 | gcd(f, 13123); |
---|
155 | |
---|
156 | // some trivial examples involving rational numbers |
---|
157 | f=11/47894*19*(-9554*x^4-12895*x^3-10023*x^2-6213*x); |
---|
158 | |
---|
159 | gcd(0, 3123/(123456*t)); |
---|
160 | gcd(4353/8798798, 0); |
---|
161 | |
---|
162 | gcd(0, f/t); |
---|
163 | gcd(f, 0); |
---|
164 | |
---|
165 | gcd(23123/(3*t), f); |
---|
166 | gcd(f, 13123/2); |
---|
167 | |
---|
168 | // some less trivial examples |
---|
169 | f=(2*x^3+2*x^2+2*x); |
---|
170 | g=(x^3+2*x^2+2*x+1); |
---|
171 | gcd(f, g); |
---|
172 | |
---|
173 | // we go on with modified variable names |
---|
174 | tst_ignore( "ring r3=(0,u),v,dp;" ); |
---|
175 | kill r3; |
---|
176 | ring r3=(0,u),v,dp; |
---|
177 | |
---|
178 | poly f; |
---|
179 | poly g; |
---|
180 | |
---|
181 | // last not least, some less trivial examples |
---|
182 | // involving the transcendental variable |
---|
183 | f=(-8*u^2*v+8*u*v^2-24*u); |
---|
184 | g=(-64*u^2*v+16*u*v^2); |
---|
185 | gcd(f, g); |
---|
186 | |
---|
187 | f=(192*u^6*v^4-240*u^5*v^5+384*u^5*v^3+48*u^4*v^6+96*u^4*v^4-576*u^4*v^2-48*u^3*v^5+144*u^3*v^3); |
---|
188 | g=(1536*u^6*v^4-768*u^5*v^5-1536*u^5*v^3+96*u^4*v^6+768*u^4*v^4-96*u^3*v^5); |
---|
189 | gcd(f, g); |
---|
190 | |
---|
191 | f=(-256*u^3*v+128*u^2*v^2-16*u*v^3); |
---|
192 | g=(-64*u^3+48*u^2*v^2+32*u^2*v-192*u^2-12*u*v^3-4*u*v^2+48*u*v); |
---|
193 | gcd(f, g); |
---|
194 | |
---|
195 | // |
---|
196 | // - ring r4=0,(t,x),dp. |
---|
197 | // |
---|
198 | // The examples from r4 are those from r3 with parameters |
---|
199 | // changed to ring variables. |
---|
200 | // |
---|
201 | |
---|
202 | tst_ignore( "ring r4=0,(t,x),dp;" ); |
---|
203 | ring r4=0,(t,x),dp; |
---|
204 | |
---|
205 | poly f=(-9554*x^4-12895*x^3-10023*x^2-6213*x); |
---|
206 | poly g; |
---|
207 | |
---|
208 | // first, some of the r1 examples (slightly modified) |
---|
209 | gcd(0, 0); |
---|
210 | gcd(0, 3123*t); |
---|
211 | gcd(4353, 0); |
---|
212 | |
---|
213 | gcd(0, f); |
---|
214 | gcd(f, 0); |
---|
215 | |
---|
216 | gcd(23123, f); |
---|
217 | gcd(f, 13123); |
---|
218 | |
---|
219 | // some trivial examples involving rational numbers |
---|
220 | f=11/47894*19*(-9554*x^4-12895*x^3-10023*x^2-6213*x); |
---|
221 | |
---|
222 | gcd(0, 3123/123456*t); |
---|
223 | gcd(4353/8798798, 0); |
---|
224 | |
---|
225 | gcd(23123/3*t, f); |
---|
226 | gcd(f, 13123/2); |
---|
227 | |
---|
228 | // some less trivial examples |
---|
229 | f=(2*x^3+2*x^2+2*x); |
---|
230 | g=(x^3+2*x^2+2*x+1); |
---|
231 | gcd(f, g); |
---|
232 | |
---|
233 | // we go on with modified variable names |
---|
234 | tst_ignore( "ring r4=0,(u,v),dp;" ); |
---|
235 | kill r4; |
---|
236 | ring r4=0,(u,v),dp; |
---|
237 | |
---|
238 | poly f; |
---|
239 | poly g; |
---|
240 | |
---|
241 | // last not least, some less trivial examples |
---|
242 | // involving both variables |
---|
243 | f=(-8*u^2*v+8*u*v^2-24*u); |
---|
244 | g=(-64*u^2*v+16*u*v^2); |
---|
245 | gcd(f, g); |
---|
246 | |
---|
247 | f=(192*u^6*v^4-240*u^5*v^5+384*u^5*v^3+48*u^4*v^6+96*u^4*v^4-576*u^4*v^2-48*u^3*v^5+144*u^3*v^3); |
---|
248 | g=(1536*u^6*v^4-768*u^5*v^5-1536*u^5*v^3+96*u^4*v^6+768*u^4*v^4-96*u^3*v^5); |
---|
249 | gcd(f, g); |
---|
250 | |
---|
251 | f=(-256*u^3*v+128*u^2*v^2-16*u*v^3); |
---|
252 | g=(-64*u^3+48*u^2*v^2+32*u^2*v-192*u^2-12*u*v^3-4*u*v^2+48*u*v); |
---|
253 | gcd(f, g); |
---|
254 | |
---|
255 | ring r=0,(x,y),dp; |
---|
256 | poly f1; poly f2; |
---|
257 | for (int i=0; i<1000; i++) |
---|
258 | { |
---|
259 | f1=f1+x^(10000-i)*y^i; |
---|
260 | f2=f2+y^(10000-i)*x^i; |
---|
261 | } |
---|
262 | tst_status(); |
---|
263 | poly p=gcd(f1,f2); |
---|
264 | tst_status(); |
---|
265 | ideal I = f1,f2; |
---|
266 | matrix M=syz(I); |
---|
267 | tst_status(); |
---|
268 | poly q=f2/M[1,1]; |
---|
269 | tst_status(); |
---|
270 | |
---|
271 | simplify(p,1)-simplify(q,1); |
---|
272 | |
---|
273 | tst_status(1);$ |
---|