1 /*
2 Copyright (C) 2012 Sebastian Pancratz
3 Copyright (C) 2013 Mike Hansen
4
5 This file is part of FLINT.
6
7 FLINT is free software: you can redistribute it and/or modify it under
8 the terms of the GNU Lesser General Public License (LGPL) as published
9 by the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version. See <https://www.gnu.org/licenses/>.
11 */
12
13 #ifdef T
14
15 #include "templates.h"
16
17 int
main(void)18 main(void)
19 {
20 int i, result;
21 FLINT_TEST_INIT(state);
22
23 flint_printf("xgcd_euclidean_f....");
24 fflush(stdout);
25
26 /* Generic case, most likely co-prime arguments ***************************** */
27
28 /* Compare with result from GCD and check correctness */
29 for (i = 0; i < 5 * flint_test_multiplier(); i++)
30 {
31 TEMPLATE(T, ctx_t) ctx;
32 TEMPLATE(T, t) f1, f2;
33 TEMPLATE(T, poly_t) a, b, d, g, s, t, v, w;
34
35 TEMPLATE(T, ctx_randtest_reducible) (ctx, state);
36
37 TEMPLATE(T, init) (f1, ctx);
38 TEMPLATE(T, init) (f2, ctx);
39 TEMPLATE(T, poly_init) (a, ctx);
40 TEMPLATE(T, poly_init) (b, ctx);
41 TEMPLATE(T, poly_init) (d, ctx);
42 TEMPLATE(T, poly_init) (g, ctx);
43 TEMPLATE(T, poly_init) (s, ctx);
44 TEMPLATE(T, poly_init) (t, ctx);
45 TEMPLATE(T, poly_init) (v, ctx);
46 TEMPLATE(T, poly_init) (w, ctx);
47 TEMPLATE(T, poly_randtest) (a, state, n_randint(state, 100), ctx);
48 TEMPLATE(T, poly_randtest) (b, state, n_randint(state, 100), ctx);
49
50 TEMPLATE(T, poly_gcd_euclidean_f) (f1, d, a, b, ctx);
51 TEMPLATE(T, poly_xgcd_euclidean_f) (f2, g, s, t, a, b, ctx);
52
53 if (!TEMPLATE(T, is_one) (f2, ctx) || !TEMPLATE(T, is_one) (f1, ctx))
54 {
55 result = TEMPLATE(T, equal) (f1, f2, ctx);
56 }
57 else
58 {
59 TEMPLATE(T, poly_mul) (v, s, a, ctx);
60 TEMPLATE(T, poly_mul) (w, t, b, ctx);
61 TEMPLATE(T, poly_add) (w, v, w, ctx);
62
63 result = (TEMPLATE(T, poly_equal) (d, g, ctx) &&
64 TEMPLATE(T, poly_equal) (g, w, ctx));
65 }
66
67 if (!result)
68 {
69 flint_printf("FAIL:\n");
70 TEMPLATE(T, ctx_print) (ctx);
71 TEMPLATE(T, print_pretty) (f1, ctx), flint_printf("\n\n");
72 TEMPLATE(T, print_pretty) (f2, ctx), flint_printf("\n\n");
73 TEMPLATE(T, poly_print_pretty) (a, "x", ctx), flint_printf("\n\n");
74 TEMPLATE(T, poly_print_pretty) (b, "x", ctx), flint_printf("\n\n");
75 TEMPLATE(T, poly_print_pretty) (d, "x", ctx), flint_printf("\n\n");
76 TEMPLATE(T, poly_print_pretty) (g, "x", ctx), flint_printf("\n\n");
77 TEMPLATE(T, poly_print_pretty) (s, "x", ctx), flint_printf("\n\n");
78 TEMPLATE(T, poly_print_pretty) (t, "x", ctx), flint_printf("\n\n");
79 TEMPLATE(T, poly_print_pretty) (v, "x", ctx), flint_printf("\n\n");
80 TEMPLATE(T, poly_print_pretty) (w, "x", ctx), flint_printf("\n\n");
81 abort();
82 }
83
84 TEMPLATE(T, clear) (f1, ctx);
85 TEMPLATE(T, clear) (f2, ctx);
86 TEMPLATE(T, poly_clear) (a, ctx);
87 TEMPLATE(T, poly_clear) (b, ctx);
88 TEMPLATE(T, poly_clear) (d, ctx);
89 TEMPLATE(T, poly_clear) (g, ctx);
90 TEMPLATE(T, poly_clear) (s, ctx);
91 TEMPLATE(T, poly_clear) (t, ctx);
92 TEMPLATE(T, poly_clear) (v, ctx);
93 TEMPLATE(T, poly_clear) (w, ctx);
94 TEMPLATE(T, ctx_clear) (ctx);
95 }
96
97 /* Special case, arguments share a factor ******************************* */
98
99 /* Compare with result from GCD and check correctness */
100 for (i = 0; i < 50 * flint_test_multiplier(); i++)
101 {
102 TEMPLATE(T, ctx_t) ctx;
103 TEMPLATE(T, t) f1, f2;
104 TEMPLATE(T, poly_t) a, b, d, f, g, s, t, v, w;
105
106 TEMPLATE(T, ctx_randtest_reducible) (ctx, state);
107
108 TEMPLATE(T, init) (f1, ctx);
109 TEMPLATE(T, init) (f2, ctx);
110
111 TEMPLATE(T, poly_init) (a, ctx);
112 TEMPLATE(T, poly_init) (b, ctx);
113 TEMPLATE(T, poly_init) (d, ctx);
114 TEMPLATE(T, poly_init) (f, ctx);
115 TEMPLATE(T, poly_init) (g, ctx);
116 TEMPLATE(T, poly_init) (s, ctx);
117 TEMPLATE(T, poly_init) (t, ctx);
118 TEMPLATE(T, poly_init) (v, ctx);
119 TEMPLATE(T, poly_init) (w, ctx);
120 TEMPLATE(T, poly_randtest) (s, state, n_randint(state, 10), ctx);
121 TEMPLATE(T, poly_randtest) (t, state, n_randint(state, 10), ctx);
122 TEMPLATE(T, poly_randtest) (a, state, n_randint(state, 10), ctx);
123 TEMPLATE(T, poly_randtest) (b, state, n_randint(state, 10), ctx);
124 TEMPLATE(T, poly_randtest) (f, state, n_randint(state, 5), ctx);
125 TEMPLATE(T, poly_mul) (a, a, f, ctx);
126 TEMPLATE(T, poly_mul) (b, b, f, ctx);
127
128 TEMPLATE(T, poly_gcd_euclidean_f) (f1, d, a, b, ctx);
129 TEMPLATE(T, poly_xgcd_euclidean_f) (f2, g, s, t, a, b, ctx);
130
131 if (!TEMPLATE(T, is_one) (f2, ctx))
132 {
133 result = TEMPLATE(T, equal) (f1, f2, ctx);
134 }
135 else
136 {
137 TEMPLATE(T, poly_mul) (v, s, a, ctx);
138 TEMPLATE(T, poly_mul) (w, t, b, ctx);
139 TEMPLATE(T, poly_add) (w, v, w, ctx);
140
141 result = (TEMPLATE(T, poly_equal) (d, g, ctx) &&
142 TEMPLATE(T, poly_equal) (g, w, ctx));
143 }
144
145 if (!result)
146 {
147 flint_printf("FAIL:\n");
148 TEMPLATE(T, print_pretty) (f1, ctx), flint_printf("\n\n");
149 TEMPLATE(T, print_pretty) (f2, ctx), flint_printf("\n\n");
150 TEMPLATE(T, poly_print_pretty) (a, "x", ctx);
151 flint_printf("\n\n");
152 TEMPLATE(T, poly_print_pretty) (b, "x", ctx);
153 flint_printf("\n\n");
154 TEMPLATE(T, poly_print_pretty) (d, "x", ctx);
155 flint_printf("\n\n");
156 TEMPLATE(T, poly_print_pretty) (f, "x", ctx);
157 flint_printf("\n\n");
158 TEMPLATE(T, poly_print_pretty) (g, "x", ctx);
159 flint_printf("\n\n");
160 TEMPLATE(T, poly_print_pretty) (s, "x", ctx);
161 flint_printf("\n\n");
162 TEMPLATE(T, poly_print_pretty) (t, "x", ctx);
163 flint_printf("\n\n");
164 TEMPLATE(T, poly_print_pretty) (v, "x", ctx);
165 flint_printf("\n\n");
166 TEMPLATE(T, poly_print_pretty) (w, "x", ctx);
167 flint_printf("\n\n");
168 abort();
169 }
170
171 TEMPLATE(T, clear) (f1, ctx);
172 TEMPLATE(T, clear) (f2, ctx);
173 TEMPLATE(T, poly_clear) (a, ctx);
174 TEMPLATE(T, poly_clear) (b, ctx);
175 TEMPLATE(T, poly_clear) (d, ctx);
176 TEMPLATE(T, poly_clear) (f, ctx);
177 TEMPLATE(T, poly_clear) (g, ctx);
178 TEMPLATE(T, poly_clear) (s, ctx);
179 TEMPLATE(T, poly_clear) (t, ctx);
180 TEMPLATE(T, poly_clear) (v, ctx);
181 TEMPLATE(T, poly_clear) (w, ctx);
182 TEMPLATE(T, ctx_clear) (ctx);
183 }
184
185 /* test aliasing of g and a */
186 for (i = 0; i < 5 * flint_test_multiplier(); i++)
187 {
188 TEMPLATE(T, ctx_t) ctx;
189 TEMPLATE(T, t) f1, f2;
190 TEMPLATE(T, poly_t) a, b, g, s, t, v, w;
191
192 TEMPLATE(T, ctx_randtest) (ctx, state);
193
194 TEMPLATE(T, poly_init) (a, ctx);
195 TEMPLATE(T, poly_init) (b, ctx);
196 TEMPLATE(T, poly_init) (g, ctx);
197 TEMPLATE(T, poly_init) (s, ctx);
198 TEMPLATE(T, poly_init) (t, ctx);
199 TEMPLATE(T, poly_init) (v, ctx);
200 TEMPLATE(T, poly_init) (w, ctx);
201 TEMPLATE(T, init) (f1, ctx);
202 TEMPLATE(T, init) (f2, ctx);
203 TEMPLATE(T, poly_randtest) (a, state, n_randint(state, 100), ctx);
204 TEMPLATE(T, poly_randtest) (b, state, n_randint(state, 100), ctx);
205
206 TEMPLATE(T, poly_xgcd_euclidean_f) (f1, g, s, t, a, b, ctx);
207 TEMPLATE(T, poly_xgcd_euclidean_f) (f2, a, v, w, a, b, ctx);
208
209 result = (TEMPLATE(T, poly_equal) (s, v, ctx) &&
210 TEMPLATE(T, poly_equal) (t, w, ctx) &&
211 TEMPLATE(T, poly_equal) (g, a, ctx) &&
212 TEMPLATE(T, equal) (f1, f2, ctx));
213
214 if (!result)
215 {
216 flint_printf("FAIL:\n");
217 TEMPLATE(T, poly_print_pretty) (a, "x", ctx), flint_printf("\n\n");
218 TEMPLATE(T, poly_print_pretty) (b, "x", ctx), flint_printf("\n\n");
219 TEMPLATE(T, poly_print_pretty) (g, "x", ctx), flint_printf("\n\n");
220 TEMPLATE(T, poly_print_pretty) (s, "x", ctx), flint_printf("\n\n");
221 TEMPLATE(T, poly_print_pretty) (t, "x", ctx), flint_printf("\n\n");
222 TEMPLATE(T, poly_print_pretty) (v, "x", ctx), flint_printf("\n\n");
223 TEMPLATE(T, poly_print_pretty) (w, "x", ctx), flint_printf("\n\n");
224 abort();
225 }
226
227 TEMPLATE(T, poly_clear) (a, ctx);
228 TEMPLATE(T, poly_clear) (b, ctx);
229 TEMPLATE(T, poly_clear) (g, ctx);
230 TEMPLATE(T, poly_clear) (s, ctx);
231 TEMPLATE(T, poly_clear) (t, ctx);
232 TEMPLATE(T, poly_clear) (v, ctx);
233 TEMPLATE(T, poly_clear) (w, ctx);
234 TEMPLATE(T, clear) (f1, ctx);
235 TEMPLATE(T, clear) (f2, ctx);
236 TEMPLATE(T, ctx_clear) (ctx);
237 }
238
239 /* test aliasing of g and b */
240 for (i = 0; i < 5 * flint_test_multiplier(); i++)
241 {
242 TEMPLATE(T, ctx_t) ctx;
243 TEMPLATE(T, t) f1, f2;
244 TEMPLATE(T, poly_t) a, b, g, s, t, v, w;
245
246 TEMPLATE(T, ctx_randtest) (ctx, state);
247
248 TEMPLATE(T, poly_init) (a, ctx);
249 TEMPLATE(T, poly_init) (b, ctx);
250 TEMPLATE(T, poly_init) (g, ctx);
251 TEMPLATE(T, poly_init) (s, ctx);
252 TEMPLATE(T, poly_init) (t, ctx);
253 TEMPLATE(T, poly_init) (v, ctx);
254 TEMPLATE(T, poly_init) (w, ctx);
255 TEMPLATE(T, init) (f1, ctx);
256 TEMPLATE(T, init) (f2, ctx);
257 TEMPLATE(T, poly_randtest) (a, state, n_randint(state, 100), ctx);
258 TEMPLATE(T, poly_randtest) (b, state, n_randint(state, 100), ctx);
259
260 TEMPLATE(T, poly_xgcd_euclidean_f) (f1, g, s, t, a, b, ctx);
261 TEMPLATE(T, poly_xgcd_euclidean_f) (f2, b, v, w, a, b, ctx);
262
263 result = (TEMPLATE(T, poly_equal) (s, v, ctx) &&
264 TEMPLATE(T, poly_equal) (t, w, ctx) &&
265 TEMPLATE(T, poly_equal) (g, b, ctx) &&
266 TEMPLATE(T, equal) (f1, f2, ctx));
267
268 if (!result)
269 {
270 flint_printf("FAIL:\n");
271 TEMPLATE(T, poly_print_pretty) (a, "x", ctx), flint_printf("\n\n");
272 TEMPLATE(T, poly_print_pretty) (b, "x", ctx), flint_printf("\n\n");
273 TEMPLATE(T, poly_print_pretty) (g, "x", ctx), flint_printf("\n\n");
274 TEMPLATE(T, poly_print_pretty) (s, "x", ctx), flint_printf("\n\n");
275 TEMPLATE(T, poly_print_pretty) (t, "x", ctx), flint_printf("\n\n");
276 TEMPLATE(T, poly_print_pretty) (v, "x", ctx), flint_printf("\n\n");
277 TEMPLATE(T, poly_print_pretty) (w, "x", ctx), flint_printf("\n\n");
278 abort();
279 }
280
281 TEMPLATE(T, poly_clear) (a, ctx);
282 TEMPLATE(T, poly_clear) (b, ctx);
283 TEMPLATE(T, poly_clear) (g, ctx);
284 TEMPLATE(T, poly_clear) (s, ctx);
285 TEMPLATE(T, poly_clear) (t, ctx);
286 TEMPLATE(T, poly_clear) (v, ctx);
287 TEMPLATE(T, poly_clear) (w, ctx);
288 TEMPLATE(T, clear) (f1, ctx);
289 TEMPLATE(T, clear) (f2, ctx);
290 TEMPLATE(T, ctx_clear) (ctx);
291 }
292
293 /* test aliasing of s and a */
294 for (i = 0; i < 5 * flint_test_multiplier(); i++)
295 {
296 TEMPLATE(T, ctx_t) ctx;
297 TEMPLATE(T, t) f1, f2;
298 TEMPLATE(T, poly_t) a, b, d, g, s, t, w;
299
300 TEMPLATE(T, ctx_randtest) (ctx, state);
301
302 TEMPLATE(T, poly_init) (a, ctx);
303 TEMPLATE(T, poly_init) (b, ctx);
304 TEMPLATE(T, poly_init) (g, ctx);
305 TEMPLATE(T, poly_init) (s, ctx);
306 TEMPLATE(T, poly_init) (t, ctx);
307 TEMPLATE(T, poly_init) (d, ctx);
308 TEMPLATE(T, poly_init) (w, ctx);
309 TEMPLATE(T, init) (f1, ctx);
310 TEMPLATE(T, init) (f2, ctx);
311 TEMPLATE(T, poly_randtest) (a, state, n_randint(state, 100), ctx);
312 TEMPLATE(T, poly_randtest) (b, state, n_randint(state, 100), ctx);
313
314 TEMPLATE(T, poly_xgcd_euclidean_f) (f1, g, s, t, a, b, ctx);
315 TEMPLATE(T, poly_xgcd_euclidean_f) (f2, d, a, w, a, b, ctx);
316
317 result = (TEMPLATE(T, poly_equal) (s, a, ctx) &&
318 TEMPLATE(T, poly_equal) (t, w, ctx) &&
319 TEMPLATE(T, poly_equal) (g, d, ctx) &&
320 TEMPLATE(T, equal) (f1, f2, ctx));
321
322 if (!result)
323 {
324 flint_printf("FAIL:\n");
325 TEMPLATE(T, poly_print_pretty) (a, "x", ctx), flint_printf("\n\n");
326 TEMPLATE(T, poly_print_pretty) (b, "x", ctx), flint_printf("\n\n");
327 TEMPLATE(T, poly_print_pretty) (g, "x", ctx), flint_printf("\n\n");
328 TEMPLATE(T, poly_print_pretty) (s, "x", ctx), flint_printf("\n\n");
329 TEMPLATE(T, poly_print_pretty) (t, "x", ctx), flint_printf("\n\n");
330 TEMPLATE(T, poly_print_pretty) (d, "x", ctx), flint_printf("\n\n");
331 TEMPLATE(T, poly_print_pretty) (w, "x", ctx), flint_printf("\n\n");
332 abort();
333 }
334
335 TEMPLATE(T, poly_clear) (a, ctx);
336 TEMPLATE(T, poly_clear) (b, ctx);
337 TEMPLATE(T, poly_clear) (g, ctx);
338 TEMPLATE(T, poly_clear) (s, ctx);
339 TEMPLATE(T, poly_clear) (t, ctx);
340 TEMPLATE(T, poly_clear) (d, ctx);
341 TEMPLATE(T, poly_clear) (w, ctx);
342 TEMPLATE(T, clear) (f1, ctx);
343 TEMPLATE(T, clear) (f2, ctx);
344 TEMPLATE(T, ctx_clear) (ctx);
345 }
346
347 /* test aliasing of s and b */
348 for (i = 0; i < 5 * flint_test_multiplier(); i++)
349 {
350 TEMPLATE(T, ctx_t) ctx;
351 TEMPLATE(T, t) f1, f2;
352 TEMPLATE(T, poly_t) a, b, d, g, s, t, w;
353
354 TEMPLATE(T, ctx_randtest) (ctx, state);
355
356 TEMPLATE(T, poly_init) (a, ctx);
357 TEMPLATE(T, poly_init) (b, ctx);
358 TEMPLATE(T, poly_init) (g, ctx);
359 TEMPLATE(T, poly_init) (s, ctx);
360 TEMPLATE(T, poly_init) (t, ctx);
361 TEMPLATE(T, poly_init) (d, ctx);
362 TEMPLATE(T, poly_init) (w, ctx);
363 TEMPLATE(T, init) (f1, ctx);
364 TEMPLATE(T, init) (f2, ctx);
365 TEMPLATE(T, poly_randtest) (a, state, n_randint(state, 100), ctx);
366 TEMPLATE(T, poly_randtest) (b, state, n_randint(state, 100), ctx);
367
368 TEMPLATE(T, poly_xgcd_euclidean_f) (f1, g, s, t, a, b, ctx);
369 TEMPLATE(T, poly_xgcd_euclidean_f) (f2, d, b, w, a, b, ctx);
370
371 result = (TEMPLATE(T, poly_equal) (s, b, ctx) &&
372 TEMPLATE(T, poly_equal) (t, w, ctx) &&
373 TEMPLATE(T, poly_equal) (g, d, ctx) &&
374 TEMPLATE(T, equal) (f1, f2, ctx));
375
376 if (!result)
377 {
378 flint_printf("FAIL:\n");
379 TEMPLATE(T, poly_print_pretty) (a, "x", ctx), flint_printf("\n\n");
380 TEMPLATE(T, poly_print_pretty) (b, "x", ctx), flint_printf("\n\n");
381 TEMPLATE(T, poly_print_pretty) (g, "x", ctx), flint_printf("\n\n");
382 TEMPLATE(T, poly_print_pretty) (s, "x", ctx), flint_printf("\n\n");
383 TEMPLATE(T, poly_print_pretty) (t, "x", ctx), flint_printf("\n\n");
384 TEMPLATE(T, poly_print_pretty) (d, "x", ctx), flint_printf("\n\n");
385 TEMPLATE(T, poly_print_pretty) (w, "x", ctx), flint_printf("\n\n");
386 abort();
387 }
388
389 TEMPLATE(T, poly_clear) (a, ctx);
390 TEMPLATE(T, poly_clear) (b, ctx);
391 TEMPLATE(T, poly_clear) (g, ctx);
392 TEMPLATE(T, poly_clear) (s, ctx);
393 TEMPLATE(T, poly_clear) (t, ctx);
394 TEMPLATE(T, poly_clear) (d, ctx);
395 TEMPLATE(T, poly_clear) (w, ctx);
396 TEMPLATE(T, clear) (f1, ctx);
397 TEMPLATE(T, clear) (f2, ctx);
398 TEMPLATE(T, ctx_clear) (ctx);
399 }
400
401 /* test aliasing of s and a */
402 for (i = 0; i < 5 * flint_test_multiplier(); i++)
403 {
404 TEMPLATE(T, ctx_t) ctx;
405 TEMPLATE(T, t) f1, f2;
406 TEMPLATE(T, poly_t) a, b, d, g, s, t, w;
407
408 TEMPLATE(T, ctx_randtest) (ctx, state);
409
410 TEMPLATE(T, poly_init) (a, ctx);
411 TEMPLATE(T, poly_init) (b, ctx);
412 TEMPLATE(T, poly_init) (g, ctx);
413 TEMPLATE(T, poly_init) (s, ctx);
414 TEMPLATE(T, poly_init) (t, ctx);
415 TEMPLATE(T, poly_init) (d, ctx);
416 TEMPLATE(T, poly_init) (w, ctx);
417 TEMPLATE(T, init) (f1, ctx);
418 TEMPLATE(T, init) (f2, ctx);
419 TEMPLATE(T, poly_randtest) (a, state, n_randint(state, 100), ctx);
420 TEMPLATE(T, poly_randtest) (b, state, n_randint(state, 100), ctx);
421
422 TEMPLATE(T, poly_xgcd_euclidean_f) (f1, g, s, t, a, b, ctx);
423 TEMPLATE(T, poly_xgcd_euclidean_f) (f2, d, w, a, a, b, ctx);
424
425 result = (TEMPLATE(T, poly_equal) (s, w, ctx) &&
426 TEMPLATE(T, poly_equal) (t, a, ctx) &&
427 TEMPLATE(T, poly_equal) (g, d, ctx) &&
428 TEMPLATE(T, equal) (f1, f2, ctx));
429
430 if (!result)
431 {
432 flint_printf("FAIL:\n");
433 TEMPLATE(T, poly_print_pretty) (a, "x", ctx), flint_printf("\n\n");
434 TEMPLATE(T, poly_print_pretty) (b, "x", ctx), flint_printf("\n\n");
435 TEMPLATE(T, poly_print_pretty) (g, "x", ctx), flint_printf("\n\n");
436 TEMPLATE(T, poly_print_pretty) (s, "x", ctx), flint_printf("\n\n");
437 TEMPLATE(T, poly_print_pretty) (t, "x", ctx), flint_printf("\n\n");
438 TEMPLATE(T, poly_print_pretty) (d, "x", ctx), flint_printf("\n\n");
439 TEMPLATE(T, poly_print_pretty) (w, "x", ctx), flint_printf("\n\n");
440 abort();
441 }
442
443 TEMPLATE(T, poly_clear) (a, ctx);
444 TEMPLATE(T, poly_clear) (b, ctx);
445 TEMPLATE(T, poly_clear) (g, ctx);
446 TEMPLATE(T, poly_clear) (s, ctx);
447 TEMPLATE(T, poly_clear) (t, ctx);
448 TEMPLATE(T, poly_clear) (d, ctx);
449 TEMPLATE(T, poly_clear) (w, ctx);
450 TEMPLATE(T, clear) (f1, ctx);
451 TEMPLATE(T, clear) (f2, ctx);
452 TEMPLATE(T, ctx_clear) (ctx);
453 }
454
455 /* test aliasing of t and b */
456 for (i = 0; i < 5 * flint_test_multiplier(); i++)
457 {
458 TEMPLATE(T, ctx_t) ctx;
459 TEMPLATE(T, t) f1, f2;
460 TEMPLATE(T, poly_t) a, b, d, g, s, t, w;
461
462 TEMPLATE(T, ctx_randtest) (ctx, state);
463
464 TEMPLATE(T, poly_init) (a, ctx);
465 TEMPLATE(T, poly_init) (b, ctx);
466 TEMPLATE(T, poly_init) (g, ctx);
467 TEMPLATE(T, poly_init) (s, ctx);
468 TEMPLATE(T, poly_init) (t, ctx);
469 TEMPLATE(T, poly_init) (d, ctx);
470 TEMPLATE(T, poly_init) (w, ctx);
471 TEMPLATE(T, init) (f1, ctx);
472 TEMPLATE(T, init) (f2, ctx);
473 TEMPLATE(T, poly_randtest) (a, state, n_randint(state, 100), ctx);
474 TEMPLATE(T, poly_randtest) (b, state, n_randint(state, 100), ctx);
475
476 TEMPLATE(T, poly_xgcd_euclidean_f) (f1, g, s, t, a, b, ctx);
477 TEMPLATE(T, poly_xgcd_euclidean_f) (f2, d, w, b, a, b, ctx);
478
479 result = (TEMPLATE(T, poly_equal) (s, w, ctx) &&
480 TEMPLATE(T, poly_equal) (t, b, ctx) &&
481 TEMPLATE(T, poly_equal) (g, d, ctx) &&
482 TEMPLATE(T, equal) (f1, f2, ctx));
483
484 if (!result)
485 {
486 flint_printf("FAIL:\n");
487 TEMPLATE(T, poly_print_pretty) (a, "x", ctx), flint_printf("\n\n");
488 TEMPLATE(T, poly_print_pretty) (b, "x", ctx), flint_printf("\n\n");
489 TEMPLATE(T, poly_print_pretty) (g, "x", ctx), flint_printf("\n\n");
490 TEMPLATE(T, poly_print_pretty) (s, "x", ctx), flint_printf("\n\n");
491 TEMPLATE(T, poly_print_pretty) (t, "x", ctx), flint_printf("\n\n");
492 TEMPLATE(T, poly_print_pretty) (d, "x", ctx), flint_printf("\n\n");
493 TEMPLATE(T, poly_print_pretty) (w, "x", ctx), flint_printf("\n\n");
494 abort();
495 }
496
497 TEMPLATE(T, poly_clear) (a, ctx);
498 TEMPLATE(T, poly_clear) (b, ctx);
499 TEMPLATE(T, poly_clear) (g, ctx);
500 TEMPLATE(T, poly_clear) (s, ctx);
501 TEMPLATE(T, poly_clear) (t, ctx);
502 TEMPLATE(T, poly_clear) (d, ctx);
503 TEMPLATE(T, poly_clear) (w, ctx);
504 TEMPLATE(T, clear) (f1, ctx);
505 TEMPLATE(T, clear) (f2, ctx);
506 TEMPLATE(T, ctx_clear) (ctx);
507 }
508
509 FLINT_TEST_CLEANUP(state);
510
511 flint_printf("PASS\n");
512 return 0;
513 }
514
515 #endif
516