1 /*
2 Copyright (C) 2009 William Hart
3 Copyright (C) 2011 Fredrik Johansson
4 Copyright (C) 2013 Martin Lee
5 Copyright (C) 2013 Mike Hansen
6
7 This file is part of FLINT.
8
9 FLINT is free software: you can redistribute it and/or modify it under
10 the terms of the GNU Lesser General Public License (LGPL) as published
11 by the Free Software Foundation; either version 2.1 of the License, or
12 (at your option) any later version. See <http://www.gnu.org/licenses/>.
13 */
14
15 #ifdef T
16
17 #include "templates.h"
18
19 int
main(void)20 main(void)
21 {
22 int i, result;
23 FLINT_TEST_INIT(state);
24
25 flint_printf("mulmod_preinv....");
26 fflush(stdout);
27
28 /* Aliasing res and a */
29 for (i = 0; i < 50 * flint_test_multiplier(); i++)
30 {
31 TEMPLATE(T, poly_t) a, b, res, t, f, finv;
32 TEMPLATE(T, ctx_t) ctx;
33
34 TEMPLATE(T, ctx_randtest) (ctx, state);
35
36 TEMPLATE(T, poly_init) (a, ctx);
37 TEMPLATE(T, poly_init) (b, ctx);
38 TEMPLATE(T, poly_init) (f, ctx);
39 TEMPLATE(T, poly_init) (finv, ctx);
40 TEMPLATE(T, poly_init) (res, ctx);
41 TEMPLATE(T, poly_init) (t, ctx);
42
43 TEMPLATE(T, poly_randtest) (a, state, n_randint(state, 50), ctx);
44 TEMPLATE(T, poly_randtest) (b, state, n_randint(state, 50), ctx);
45 do
46 {
47 TEMPLATE(T, poly_randtest) (f, state, n_randint(state, 50), ctx);
48 } while (TEMPLATE(T, poly_is_zero) (f, ctx));
49 if (a->length >= f->length)
50 TEMPLATE(T, poly_rem) (a, a, f, ctx);
51 if (b->length >= f->length)
52 TEMPLATE(T, poly_rem) (b, b, f, ctx);
53
54 TEMPLATE(T, poly_reverse) (finv, f, f->length, ctx);
55 TEMPLATE(T, poly_inv_series_newton) (finv, finv, f->length, ctx);
56
57 TEMPLATE(T, poly_mulmod_preinv) (res, a, b, f, finv, ctx);
58 TEMPLATE(T, poly_mulmod_preinv) (a, a, b, f, finv, ctx);
59
60 result = (TEMPLATE(T, poly_equal) (res, a, ctx));
61 if (!result)
62 {
63 flint_printf("FAIL:\n");
64 flint_printf("a:\n");
65 TEMPLATE(T, poly_print) (a, ctx), flint_printf("\n\n");
66 flint_printf("b:\n");
67 TEMPLATE(T, poly_print) (b, ctx), flint_printf("\n\n");
68 flint_printf("f:\n");
69 TEMPLATE(T, poly_print) (f, ctx), flint_printf("\n\n");
70 flint_printf("res1:\n");
71 TEMPLATE(T, poly_print) (res, ctx), flint_printf("\n\n");
72 abort();
73 }
74
75 TEMPLATE(T, poly_clear) (a, ctx);
76 TEMPLATE(T, poly_clear) (b, ctx);
77 TEMPLATE(T, poly_clear) (f, ctx);
78 TEMPLATE(T, poly_clear) (finv, ctx);
79 TEMPLATE(T, poly_clear) (res, ctx);
80 TEMPLATE(T, poly_clear) (t, ctx);
81 TEMPLATE(T, ctx_clear) (ctx);
82 }
83
84 /* Aliasing res and b */
85 for (i = 0; i < 50 * flint_test_multiplier(); i++)
86 {
87 TEMPLATE(T, poly_t) a, b, res, t, f, finv;
88 TEMPLATE(T, ctx_t) ctx;
89
90 TEMPLATE(T, ctx_randtest) (ctx, state);
91
92 TEMPLATE(T, poly_init) (a, ctx);
93 TEMPLATE(T, poly_init) (b, ctx);
94 TEMPLATE(T, poly_init) (f, ctx);
95 TEMPLATE(T, poly_init) (finv, ctx);
96 TEMPLATE(T, poly_init) (res, ctx);
97 TEMPLATE(T, poly_init) (t, ctx);
98
99 TEMPLATE(T, poly_randtest) (a, state, n_randint(state, 50), ctx);
100 TEMPLATE(T, poly_randtest) (b, state, n_randint(state, 50), ctx);
101 do
102 {
103 TEMPLATE(T, poly_randtest) (f, state, n_randint(state, 50), ctx);
104 } while (TEMPLATE(T, poly_is_zero) (f, ctx));
105 if (a->length >= f->length)
106 TEMPLATE(T, poly_rem) (a, a, f, ctx);
107 if (b->length >= f->length)
108 TEMPLATE(T, poly_rem) (b, b, f, ctx);
109
110 TEMPLATE(T, poly_reverse) (finv, f, f->length, ctx);
111 TEMPLATE(T, poly_inv_series_newton) (finv, finv, f->length, ctx);
112
113 TEMPLATE(T, poly_mulmod_preinv) (res, a, b, f, finv, ctx);
114 TEMPLATE(T, poly_mulmod_preinv) (b, a, b, f, finv, ctx);
115
116 result = (TEMPLATE(T, poly_equal) (res, b, ctx));
117 if (!result)
118 {
119 flint_printf("FAIL:\n");
120 flint_printf("a:\n");
121 TEMPLATE(T, poly_print) (a, ctx), flint_printf("\n\n");
122 flint_printf("b:\n");
123 TEMPLATE(T, poly_print) (b, ctx), flint_printf("\n\n");
124 flint_printf("f:\n");
125 TEMPLATE(T, poly_print) (f, ctx), flint_printf("\n\n");
126 flint_printf("res1:\n");
127 TEMPLATE(T, poly_print) (res, ctx), flint_printf("\n\n");
128 abort();
129 }
130
131 TEMPLATE(T, poly_clear) (a, ctx);
132 TEMPLATE(T, poly_clear) (b, ctx);
133 TEMPLATE(T, poly_clear) (f, ctx);
134 TEMPLATE(T, poly_clear) (finv, ctx);
135 TEMPLATE(T, poly_clear) (res, ctx);
136 TEMPLATE(T, poly_clear) (t, ctx);
137 TEMPLATE(T, ctx_clear) (ctx);
138 }
139
140 /* Aliasing res and f */
141 for (i = 0; i < 50 * flint_test_multiplier(); i++)
142 {
143 TEMPLATE(T, poly_t) a, b, res, t, f, finv;
144 TEMPLATE(T, ctx_t) ctx;
145
146 TEMPLATE(T, ctx_randtest) (ctx, state);
147
148 TEMPLATE(T, poly_init) (a, ctx);
149 TEMPLATE(T, poly_init) (b, ctx);
150 TEMPLATE(T, poly_init) (f, ctx);
151 TEMPLATE(T, poly_init) (finv, ctx);
152 TEMPLATE(T, poly_init) (res, ctx);
153 TEMPLATE(T, poly_init) (t, ctx);
154
155 TEMPLATE(T, poly_randtest) (a, state, n_randint(state, 50), ctx);
156 TEMPLATE(T, poly_randtest) (b, state, n_randint(state, 50), ctx);
157 do
158 {
159 TEMPLATE(T, poly_randtest) (f, state, n_randint(state, 50), ctx);
160 } while (TEMPLATE(T, poly_is_zero) (f, ctx));
161 if (a->length >= f->length)
162 TEMPLATE(T, poly_rem) (a, a, f, ctx);
163 if (b->length >= f->length)
164 TEMPLATE(T, poly_rem) (b, b, f, ctx);
165
166 TEMPLATE(T, poly_reverse) (finv, f, f->length, ctx);
167 TEMPLATE(T, poly_inv_series_newton) (finv, finv, f->length, ctx);
168
169 TEMPLATE(T, poly_mulmod_preinv) (res, a, b, f, finv, ctx);
170 TEMPLATE(T, poly_mulmod_preinv) (f, a, b, f, finv, ctx);
171
172 result = (TEMPLATE(T, poly_equal) (res, f, ctx));
173 if (!result)
174 {
175 flint_printf("FAIL:\n");
176 flint_printf("a:\n");
177 TEMPLATE(T, poly_print) (a, ctx), flint_printf("\n\n");
178 flint_printf("b:\n");
179 TEMPLATE(T, poly_print) (b, ctx), flint_printf("\n\n");
180 flint_printf("f:\n");
181 TEMPLATE(T, poly_print) (f, ctx), flint_printf("\n\n");
182 flint_printf("res1:\n");
183 TEMPLATE(T, poly_print) (res, ctx), flint_printf("\n\n");
184 abort();
185 }
186
187 TEMPLATE(T, poly_clear) (a, ctx);
188 TEMPLATE(T, poly_clear) (b, ctx);
189 TEMPLATE(T, poly_clear) (f, ctx);
190 TEMPLATE(T, poly_clear) (finv, ctx);
191 TEMPLATE(T, poly_clear) (res, ctx);
192 TEMPLATE(T, poly_clear) (t, ctx);
193 TEMPLATE(T, ctx_clear) (ctx);
194 }
195
196 /* Aliasing res and finv */
197 for (i = 0; i < 50 * flint_test_multiplier(); i++)
198 {
199 TEMPLATE(T, poly_t) a, b, res, t, f, finv;
200 TEMPLATE(T, ctx_t) ctx;
201
202 TEMPLATE(T, ctx_randtest) (ctx, state);
203
204 TEMPLATE(T, poly_init) (a, ctx);
205 TEMPLATE(T, poly_init) (b, ctx);
206 TEMPLATE(T, poly_init) (f, ctx);
207 TEMPLATE(T, poly_init) (finv, ctx);
208 TEMPLATE(T, poly_init) (res, ctx);
209 TEMPLATE(T, poly_init) (t, ctx);
210
211 TEMPLATE(T, poly_randtest) (a, state, n_randint(state, 50), ctx);
212 TEMPLATE(T, poly_randtest) (b, state, n_randint(state, 50), ctx);
213 do
214 {
215 TEMPLATE(T, poly_randtest) (f, state, n_randint(state, 50), ctx);
216 } while (TEMPLATE(T, poly_is_zero) (f, ctx));
217 if (a->length >= f->length)
218 TEMPLATE(T, poly_rem) (a, a, f, ctx);
219 if (b->length >= f->length)
220 TEMPLATE(T, poly_rem) (b, b, f, ctx);
221
222 TEMPLATE(T, poly_reverse) (finv, f, f->length, ctx);
223 TEMPLATE(T, poly_inv_series_newton) (finv, finv, f->length, ctx);
224
225 TEMPLATE(T, poly_mulmod_preinv) (res, a, b, f, finv, ctx);
226 TEMPLATE(T, poly_mulmod_preinv) (finv, a, b, f, finv, ctx);
227
228 result = (TEMPLATE(T, poly_equal) (res, finv, ctx));
229 if (!result)
230 {
231 flint_printf("FAIL:\n");
232 flint_printf("a:\n");
233 TEMPLATE(T, poly_print) (a, ctx), flint_printf("\n\n");
234 flint_printf("b:\n");
235 TEMPLATE(T, poly_print) (b, ctx), flint_printf("\n\n");
236 flint_printf("f:\n");
237 TEMPLATE(T, poly_print) (f, ctx), flint_printf("\n\n");
238 flint_printf("finv:\n");
239 TEMPLATE(T, poly_print) (finv, ctx), flint_printf("\n\n");
240 flint_printf("res1:\n");
241 TEMPLATE(T, poly_print) (res, ctx), flint_printf("\n\n");
242 abort();
243 }
244
245 TEMPLATE(T, poly_clear) (a, ctx);
246 TEMPLATE(T, poly_clear) (b, ctx);
247 TEMPLATE(T, poly_clear) (f, ctx);
248 TEMPLATE(T, poly_clear) (finv, ctx);
249 TEMPLATE(T, poly_clear) (res, ctx);
250 TEMPLATE(T, poly_clear) (t, ctx);
251 TEMPLATE(T, ctx_clear) (ctx);
252 }
253
254 /* No aliasing */
255 for (i = 0; i < 100 * flint_test_multiplier(); i++)
256 {
257 TEMPLATE(T, poly_t) a, b, res1, res2, t, f, finv;
258
259 TEMPLATE(T, ctx_t) ctx;
260
261 TEMPLATE(T, ctx_randtest) (ctx, state);
262
263 TEMPLATE(T, poly_init) (a, ctx);
264 TEMPLATE(T, poly_init) (b, ctx);
265 TEMPLATE(T, poly_init) (f, ctx);
266 TEMPLATE(T, poly_init) (finv, ctx);
267 TEMPLATE(T, poly_init) (res1, ctx);
268 TEMPLATE(T, poly_init) (res2, ctx);
269 TEMPLATE(T, poly_init) (t, ctx);
270
271 TEMPLATE(T, poly_randtest) (a, state, n_randint(state, 50), ctx);
272 TEMPLATE(T, poly_randtest) (b, state, n_randint(state, 50), ctx);
273 do
274 {
275 TEMPLATE(T, poly_randtest) (f, state, n_randint(state, 50), ctx);
276 } while (TEMPLATE(T, poly_is_zero) (f, ctx));
277 if (a->length >= f->length)
278 TEMPLATE(T, poly_rem) (a, a, f, ctx);
279 if (b->length >= f->length)
280 TEMPLATE(T, poly_rem) (b, b, f, ctx);
281
282 TEMPLATE(T, poly_reverse) (finv, f, f->length, ctx);
283 TEMPLATE(T, poly_inv_series_newton) (finv, finv, f->length, ctx);
284
285 TEMPLATE(T, poly_mulmod_preinv) (res1, a, b, f, finv, ctx);
286
287 TEMPLATE(T, poly_mul) (res2, a, b, ctx);
288 TEMPLATE(T, poly_divrem) (t, res2, res2, f, ctx);
289
290 result = (TEMPLATE(T, poly_equal) (res1, res2, ctx));
291 if (!result)
292 {
293 flint_printf("FAIL:\n");
294 flint_printf("a:\n");
295 TEMPLATE(T, poly_print) (a, ctx), flint_printf("\n\n");
296 flint_printf("b:\n");
297 TEMPLATE(T, poly_print) (b, ctx), flint_printf("\n\n");
298 flint_printf("f:\n");
299 TEMPLATE(T, poly_print) (f, ctx), flint_printf("\n\n");
300 flint_printf("res1:\n");
301 TEMPLATE(T, poly_print) (res1, ctx), flint_printf("\n\n");
302 flint_printf("res2:\n");
303 TEMPLATE(T, poly_print) (res2, ctx), flint_printf("\n\n");
304 abort();
305 }
306
307 TEMPLATE(T, poly_clear) (a, ctx);
308 TEMPLATE(T, poly_clear) (b, ctx);
309 TEMPLATE(T, poly_clear) (f, ctx);
310 TEMPLATE(T, poly_clear) (finv, ctx);
311 TEMPLATE(T, poly_clear) (res1, ctx);
312 TEMPLATE(T, poly_clear) (res2, ctx);
313 TEMPLATE(T, poly_clear) (t, ctx);
314 TEMPLATE(T, ctx_clear) (ctx);
315 }
316
317 FLINT_TEST_CLEANUP(state);
318 flint_printf("PASS\n");
319 return 0;
320 }
321
322
323 #endif
324