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 #include <stdio.h>
19 #include <stdlib.h>
20 #include <gmp.h>
21 #include "flint.h"
22 #include "ulong_extras.h"
23 int
main(void)24 main(void)
25 {
26 int i;
27 FLINT_TEST_INIT(state);
28
29 flint_printf("compose_mod_brent_kung....");
30 fflush(stdout);
31
32 for (i = 0; i < 20 * flint_test_multiplier(); i++)
33 {
34 TEMPLATE(T, ctx_t) ctx;
35 TEMPLATE(T, poly_t) a, b, c, d, e;
36
37 TEMPLATE(T, ctx_randtest) (ctx, state);
38
39 TEMPLATE(T, poly_init) (a, ctx);
40 TEMPLATE(T, poly_init) (b, ctx);
41 TEMPLATE(T, poly_init) (c, ctx);
42 TEMPLATE(T, poly_init) (d, ctx);
43 TEMPLATE(T, poly_init) (e, ctx);
44
45 TEMPLATE(T, poly_randtest) (a, state, n_randint(state, 20) + 1, ctx);
46 TEMPLATE(T, poly_randtest) (b, state, n_randint(state, 20) + 1, ctx);
47 TEMPLATE(T, poly_randtest_not_zero) (c, state,
48 n_randint(state, 20) + 1, ctx);
49
50 TEMPLATE(T, poly_rem) (a, a, c, ctx);
51 TEMPLATE(T, poly_compose_mod_brent_kung) (d, a, b, c, ctx);
52 TEMPLATE(T, poly_compose) (e, a, b, ctx);
53 TEMPLATE(T, poly_rem) (e, e, c, ctx);
54
55 if (!TEMPLATE(T, poly_equal) (d, e, ctx))
56 {
57 flint_printf("FAIL (composition):\n");
58 flint_printf("a:\n");
59 TEMPLATE(T, poly_print) (a, ctx);
60 flint_printf("\n");
61 flint_printf("b:\n");
62 TEMPLATE(T, poly_print) (b, ctx);
63 flint_printf("\n");
64 flint_printf("c:\n");
65 TEMPLATE(T, poly_print) (c, ctx);
66 flint_printf("\n");
67 flint_printf("d:\n");
68 TEMPLATE(T, poly_print) (d, ctx);
69 flint_printf("\n");
70 flint_printf("e:\n");
71 TEMPLATE(T, poly_print) (e, ctx);
72 flint_printf("\n");
73 abort();
74 }
75
76 TEMPLATE(T, poly_clear) (a, ctx);
77 TEMPLATE(T, poly_clear) (b, ctx);
78 TEMPLATE(T, poly_clear) (c, 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, 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) (d, ctx);
97
98 TEMPLATE(T, poly_randtest) (a, state, n_randint(state, 20) + 1, ctx);
99 TEMPLATE(T, poly_randtest) (b, state, n_randint(state, 20) + 1, ctx);
100 TEMPLATE(T, poly_randtest_not_zero) (c, state,
101 n_randint(state, 20) + 1, ctx);
102
103 TEMPLATE(T, poly_rem) (a, a, c, ctx);
104 TEMPLATE(T, poly_compose_mod_brent_kung) (d, a, b, c, ctx);
105 TEMPLATE(T, poly_compose_mod_brent_kung) (a, a, b, c, ctx);
106
107 if (!TEMPLATE(T, poly_equal) (d, a, ctx))
108 {
109 flint_printf("FAIL (aliasing a):\n");
110 flint_printf("a:\n");
111 TEMPLATE(T, poly_print) (a, ctx);
112 flint_printf("\n");
113 flint_printf("b:\n");
114 TEMPLATE(T, poly_print) (b, ctx);
115 flint_printf("\n");
116 flint_printf("c:\n");
117 TEMPLATE(T, poly_print) (c, ctx);
118 flint_printf("\n");
119 flint_printf("d:\n");
120 TEMPLATE(T, poly_print) (d, ctx);
121 flint_printf("\n");
122 abort();
123 }
124
125 TEMPLATE(T, poly_clear) (a, ctx);
126 TEMPLATE(T, poly_clear) (b, ctx);
127 TEMPLATE(T, poly_clear) (c, ctx);
128 TEMPLATE(T, poly_clear) (d, ctx);
129
130 TEMPLATE(T, ctx_clear) (ctx);
131 }
132
133 /* Test aliasing of res and b */
134 for (i = 0; i < 20 * flint_test_multiplier(); i++)
135 {
136 TEMPLATE(T, ctx_t) ctx;
137 TEMPLATE(T, poly_t) a, b, c, d;
138
139 TEMPLATE(T, ctx_randtest) (ctx, state);
140
141 TEMPLATE(T, poly_init) (a, ctx);
142 TEMPLATE(T, poly_init) (b, ctx);
143 TEMPLATE(T, poly_init) (c, ctx);
144 TEMPLATE(T, poly_init) (d, ctx);
145
146 TEMPLATE(T, poly_randtest) (a, state, n_randint(state, 20) + 1, ctx);
147 TEMPLATE(T, poly_randtest) (b, state, n_randint(state, 20) + 1, ctx);
148 TEMPLATE(T, poly_randtest_not_zero) (c, state,
149 n_randint(state, 20) + 1, ctx);
150
151 TEMPLATE(T, poly_rem) (a, a, c, ctx);
152 TEMPLATE(T, poly_compose_mod_brent_kung) (d, a, b, c, ctx);
153 TEMPLATE(T, poly_compose_mod_brent_kung) (b, a, b, c, ctx);
154
155 if (!TEMPLATE(T, poly_equal) (d, b, ctx))
156 {
157 flint_printf("FAIL (aliasing b)\n");
158 flint_printf("a:\n");
159 TEMPLATE(T, poly_print) (a, ctx);
160 flint_printf("\n");
161 flint_printf("b:\n");
162 TEMPLATE(T, poly_print) (b, ctx);
163 flint_printf("\n");
164 flint_printf("c:\n");
165 TEMPLATE(T, poly_print) (c, ctx);
166 flint_printf("\n");
167 flint_printf("d:\n");
168 TEMPLATE(T, poly_print) (d, ctx);
169 flint_printf("\n");
170 abort();
171 }
172
173 TEMPLATE(T, poly_clear) (a, ctx);
174 TEMPLATE(T, poly_clear) (b, ctx);
175 TEMPLATE(T, poly_clear) (c, ctx);
176 TEMPLATE(T, poly_clear) (d, ctx);
177
178 TEMPLATE(T, ctx_clear) (ctx);
179 }
180
181 /* Test aliasing of res and c */
182 for (i = 0; i < 20 * flint_test_multiplier(); i++)
183 {
184 TEMPLATE(T, ctx_t) ctx;
185 TEMPLATE(T, poly_t) a, b, c, d;
186
187 TEMPLATE(T, ctx_randtest) (ctx, state);
188
189 TEMPLATE(T, poly_init) (a, ctx);
190 TEMPLATE(T, poly_init) (b, ctx);
191 TEMPLATE(T, poly_init) (c, ctx);
192 TEMPLATE(T, poly_init) (d, ctx);
193
194 TEMPLATE(T, poly_randtest) (a, state, n_randint(state, 20) + 1, ctx);
195 TEMPLATE(T, poly_randtest) (b, state, n_randint(state, 20) + 1, ctx);
196 TEMPLATE(T, poly_randtest_not_zero) (c, state,
197 n_randint(state, 20) + 1, ctx);
198
199 TEMPLATE(T, poly_rem) (a, a, c, ctx);
200 TEMPLATE(T, poly_compose_mod_brent_kung) (d, a, b, c, ctx);
201 TEMPLATE(T, poly_compose_mod_brent_kung) (c, a, b, c, ctx);
202
203 if (!TEMPLATE(T, poly_equal) (d, c, ctx))
204 {
205 flint_printf("FAIL (aliasing c)\n");
206 flint_printf("a:\n");
207 TEMPLATE(T, poly_print) (a, ctx);
208 flint_printf("\n");
209 flint_printf("b:\n");
210 TEMPLATE(T, poly_print) (b, ctx);
211 flint_printf("\n");
212 flint_printf("c:\n");
213 TEMPLATE(T, poly_print) (c, ctx);
214 flint_printf("\n");
215 flint_printf("d:\n");
216 TEMPLATE(T, poly_print) (d, ctx);
217 flint_printf("\n");
218 abort();
219 }
220
221 TEMPLATE(T, poly_clear) (a, ctx);
222 TEMPLATE(T, poly_clear) (b, ctx);
223 TEMPLATE(T, poly_clear) (c, ctx);
224 TEMPLATE(T, poly_clear) (d, ctx);
225
226 TEMPLATE(T, ctx_clear) (ctx);
227 }
228
229 FLINT_TEST_CLEANUP(state);
230 flint_printf("PASS\n");
231 return 0;
232 }
233
234
235 #endif
236