1 /*
2 Copyright (C) 2011 Fredrik Johansson
3 Copyright (C) 2012 Lina Kulakova
4 Copyright (C) 2013 Mike Hansen
5
6 This file is part of FLINT.
7
8 FLINT is free software: you can redistribute it and/or modify it under
9 the terms of the GNU Lesser General Public License (LGPL) as published
10 by the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version. See <https://www.gnu.org/licenses/>.
12 */
13
14 #ifdef T
15
16 #include "templates.h"
17
18 int
main(void)19 main(void)
20 {
21 int i;
22 FLINT_TEST_INIT(state);
23
24 flint_printf("compose_mod_horner_preinv....");
25 fflush(stdout);
26
27 for (i = 0; i < 20 * flint_test_multiplier(); i++)
28 {
29 TEMPLATE(T, ctx_t) ctx;
30 TEMPLATE(T, poly_t) a, b, c, cinv, d, e;
31
32 TEMPLATE(T, ctx_randtest) (ctx, state);
33
34 TEMPLATE(T, poly_init) (a, ctx);
35 TEMPLATE(T, poly_init) (b, ctx);
36 TEMPLATE(T, poly_init) (c, ctx);
37 TEMPLATE(T, poly_init) (cinv, ctx);
38 TEMPLATE(T, poly_init) (d, ctx);
39 TEMPLATE(T, poly_init) (e, ctx);
40
41 TEMPLATE(T, poly_randtest) (a, state, n_randint(state, 20) + 1, ctx);
42 TEMPLATE(T, poly_randtest) (b, state, n_randint(state, 20) + 1, ctx);
43 TEMPLATE(T, poly_randtest_not_zero) (c, state,
44 n_randint(state, 20) + 1, ctx);
45
46 TEMPLATE(T, poly_reverse) (cinv, c, c->length, ctx);
47 TEMPLATE(T, poly_inv_series_newton) (cinv, cinv, c->length, ctx);
48
49 TEMPLATE(T, poly_rem) (a, a, c, ctx);
50 TEMPLATE(T, poly_compose_mod_horner_preinv) (d, a, b, c, cinv, ctx);
51 TEMPLATE(T, poly_compose) (e, a, b, ctx);
52 TEMPLATE(T, poly_rem) (e, e, c, ctx);
53
54 if (!TEMPLATE(T, poly_equal) (d, e, ctx))
55 {
56 flint_printf("FAIL (composition):\n");
57 flint_printf("a:\n");
58 TEMPLATE(T, poly_print) (a, ctx);
59 flint_printf("\n");
60 flint_printf("b:\n");
61 TEMPLATE(T, poly_print) (b, ctx);
62 flint_printf("\n");
63 flint_printf("c:\n");
64 TEMPLATE(T, poly_print) (c, ctx);
65 flint_printf("\n");
66 flint_printf("d:\n");
67 TEMPLATE(T, poly_print) (d, ctx);
68 flint_printf("\n");
69 flint_printf("e:\n");
70 TEMPLATE(T, poly_print) (e, ctx);
71 flint_printf("\n");
72 abort();
73 }
74
75 TEMPLATE(T, poly_clear) (a, ctx);
76 TEMPLATE(T, poly_clear) (b, ctx);
77 TEMPLATE(T, poly_clear) (c, ctx);
78 TEMPLATE(T, poly_clear) (cinv, ctx);
79 TEMPLATE(T, poly_clear) (d, ctx);
80 TEMPLATE(T, poly_clear) (e, ctx);
81
82 TEMPLATE(T, ctx_clear) (ctx);
83 }
84
85 /* Test aliasing of res and a */
86 for (i = 0; i < 20 * flint_test_multiplier(); i++)
87 {
88 TEMPLATE(T, ctx_t) ctx;
89 TEMPLATE(T, poly_t) a, b, c, cinv, d;
90
91 TEMPLATE(T, ctx_randtest) (ctx, state);
92
93 TEMPLATE(T, poly_init) (a, ctx);
94 TEMPLATE(T, poly_init) (b, ctx);
95 TEMPLATE(T, poly_init) (c, ctx);
96 TEMPLATE(T, poly_init) (cinv, ctx);
97 TEMPLATE(T, poly_init) (d, ctx);
98
99 TEMPLATE(T, poly_randtest) (a, state, n_randint(state, 20) + 1, ctx);
100 TEMPLATE(T, poly_randtest) (b, state, n_randint(state, 20) + 1, ctx);
101 TEMPLATE(T, poly_randtest_not_zero) (c, state,
102 n_randint(state, 20) + 1, ctx);
103
104 TEMPLATE(T, poly_reverse) (cinv, c, c->length, ctx);
105 TEMPLATE(T, poly_inv_series_newton) (cinv, cinv, c->length, ctx);
106
107 TEMPLATE(T, poly_rem) (a, a, c, ctx);
108 TEMPLATE(T, poly_compose_mod_horner_preinv) (d, a, b, c, cinv, ctx);
109 TEMPLATE(T, poly_compose_mod_horner_preinv) (a, a, b, c, cinv, ctx);
110
111 if (!TEMPLATE(T, poly_equal) (d, a, ctx))
112 {
113 flint_printf("FAIL (aliasing a):\n");
114 flint_printf("a:\n");
115 TEMPLATE(T, poly_print) (a, ctx);
116 flint_printf("\n");
117 flint_printf("b:\n");
118 TEMPLATE(T, poly_print) (b, ctx);
119 flint_printf("\n");
120 flint_printf("c:\n");
121 TEMPLATE(T, poly_print) (c, ctx);
122 flint_printf("\n");
123 flint_printf("d:\n");
124 TEMPLATE(T, poly_print) (d, ctx);
125 flint_printf("\n");
126 abort();
127 }
128
129 TEMPLATE(T, poly_clear) (a, ctx);
130 TEMPLATE(T, poly_clear) (b, ctx);
131 TEMPLATE(T, poly_clear) (c, ctx);
132 TEMPLATE(T, poly_clear) (cinv, ctx);
133 TEMPLATE(T, poly_clear) (d, ctx);
134
135 TEMPLATE(T, ctx_clear) (ctx);
136 }
137
138 /* Test aliasing of res and b */
139 for (i = 0; i < 20 * flint_test_multiplier(); i++)
140 {
141 TEMPLATE(T, ctx_t) ctx;
142 TEMPLATE(T, poly_t) a, b, c, cinv, d;
143
144 TEMPLATE(T, ctx_randtest) (ctx, state);
145
146 TEMPLATE(T, poly_init) (a, ctx);
147 TEMPLATE(T, poly_init) (b, ctx);
148 TEMPLATE(T, poly_init) (c, ctx);
149 TEMPLATE(T, poly_init) (cinv, ctx);
150 TEMPLATE(T, poly_init) (d, ctx);
151
152 TEMPLATE(T, poly_randtest) (a, state, n_randint(state, 20) + 1, ctx);
153 TEMPLATE(T, poly_randtest) (b, state, n_randint(state, 20) + 1, ctx);
154 TEMPLATE(T, poly_randtest_not_zero) (c, state,
155 n_randint(state, 20) + 1, ctx);
156
157 TEMPLATE(T, poly_reverse) (cinv, c, c->length, ctx);
158 TEMPLATE(T, poly_inv_series_newton) (cinv, cinv, c->length, ctx);
159
160 TEMPLATE(T, poly_rem) (a, a, c, ctx);
161 TEMPLATE(T, poly_compose_mod_horner_preinv) (d, a, b, c, cinv, ctx);
162 TEMPLATE(T, poly_compose_mod_horner_preinv) (b, a, b, c, cinv, ctx);
163
164 if (!TEMPLATE(T, poly_equal) (d, b, ctx))
165 {
166 flint_printf("FAIL (aliasing b)\n");
167 flint_printf("a:\n");
168 TEMPLATE(T, poly_print) (a, ctx);
169 flint_printf("\n");
170 flint_printf("b:\n");
171 TEMPLATE(T, poly_print) (b, ctx);
172 flint_printf("\n");
173 flint_printf("c:\n");
174 TEMPLATE(T, poly_print) (c, ctx);
175 flint_printf("\n");
176 flint_printf("d:\n");
177 TEMPLATE(T, poly_print) (d, ctx);
178 flint_printf("\n");
179 abort();
180 }
181
182 TEMPLATE(T, poly_clear) (a, ctx);
183 TEMPLATE(T, poly_clear) (b, ctx);
184 TEMPLATE(T, poly_clear) (c, ctx);
185 TEMPLATE(T, poly_clear) (cinv, ctx);
186 TEMPLATE(T, poly_clear) (d, ctx);
187
188 TEMPLATE(T, ctx_clear) (ctx);
189 }
190
191 /* Test aliasing of res and c */
192 for (i = 0; i < 20 * flint_test_multiplier(); i++)
193 {
194 TEMPLATE(T, ctx_t) ctx;
195 TEMPLATE(T, poly_t) a, b, c, cinv, d;
196
197 TEMPLATE(T, ctx_randtest) (ctx, state);
198
199 TEMPLATE(T, poly_init) (a, ctx);
200 TEMPLATE(T, poly_init) (b, ctx);
201 TEMPLATE(T, poly_init) (c, ctx);
202 TEMPLATE(T, poly_init) (cinv, ctx);
203 TEMPLATE(T, poly_init) (d, ctx);
204
205 TEMPLATE(T, poly_randtest) (a, state, n_randint(state, 20) + 1, ctx);
206 TEMPLATE(T, poly_randtest) (b, state, n_randint(state, 20) + 1, ctx);
207 TEMPLATE(T, poly_randtest_not_zero) (c, state,
208 n_randint(state, 20) + 1, ctx);
209
210 TEMPLATE(T, poly_reverse) (cinv, c, c->length, ctx);
211 TEMPLATE(T, poly_inv_series_newton) (cinv, cinv, c->length, ctx);
212
213 TEMPLATE(T, poly_rem) (a, a, c, ctx);
214 TEMPLATE(T, poly_compose_mod_horner_preinv) (d, a, b, c, cinv, ctx);
215 TEMPLATE(T, poly_compose_mod_horner_preinv) (c, a, b, c, cinv, ctx);
216
217 if (!TEMPLATE(T, poly_equal) (d, c, ctx))
218 {
219 flint_printf("FAIL (aliasing c)\n");
220 flint_printf("a:\n");
221 TEMPLATE(T, poly_print) (a, ctx);
222 flint_printf("\n");
223 flint_printf("b:\n");
224 TEMPLATE(T, poly_print) (b, ctx);
225 flint_printf("\n");
226 flint_printf("c:\n");
227 TEMPLATE(T, poly_print) (c, ctx);
228 flint_printf("\n");
229 flint_printf("d:\n");
230 TEMPLATE(T, poly_print) (d, ctx);
231 flint_printf("\n");
232 abort();
233 }
234
235 TEMPLATE(T, poly_clear) (a, ctx);
236 TEMPLATE(T, poly_clear) (b, ctx);
237 TEMPLATE(T, poly_clear) (c, ctx);
238 TEMPLATE(T, poly_clear) (cinv, ctx);
239 TEMPLATE(T, poly_clear) (d, ctx);
240
241 TEMPLATE(T, ctx_clear) (ctx);
242 }
243
244 FLINT_TEST_CLEANUP(state);
245 flint_printf("PASS\n");
246 return 0;
247 }
248
249
250 #endif
251