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....");
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_compose_mod) (d, a, b, c, 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) (d, ctx);
79 TEMPLATE(T, poly_clear) (e, ctx);
80
81 TEMPLATE(T, ctx_clear) (ctx);
82 }
83
84 /* Test aliasing of res and a */
85 for (i = 0; i < 20 * flint_test_multiplier(); i++)
86 {
87 TEMPLATE(T, ctx_t) ctx;
88 TEMPLATE(T, poly_t) a, b, c, d;
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) (c, ctx);
95 TEMPLATE(T, poly_init) (d, ctx);
96
97 TEMPLATE(T, poly_randtest) (a, state, n_randint(state, 20) + 1, ctx);
98 TEMPLATE(T, poly_randtest) (b, state, n_randint(state, 20) + 1, ctx);
99 TEMPLATE(T, poly_randtest_not_zero) (c, state,
100 n_randint(state, 20) + 1, ctx);
101
102 TEMPLATE(T, poly_compose_mod) (d, a, b, c, ctx);
103 TEMPLATE(T, poly_compose_mod) (a, a, b, c, ctx);
104
105 if (!TEMPLATE(T, poly_equal) (d, a, ctx))
106 {
107 flint_printf("FAIL (aliasing a):\n");
108 flint_printf("a:\n");
109 TEMPLATE(T, poly_print) (a, ctx);
110 flint_printf("\n");
111 flint_printf("b:\n");
112 TEMPLATE(T, poly_print) (b, ctx);
113 flint_printf("\n");
114 flint_printf("c:\n");
115 TEMPLATE(T, poly_print) (c, ctx);
116 flint_printf("\n");
117 flint_printf("d:\n");
118 TEMPLATE(T, poly_print) (d, ctx);
119 flint_printf("\n");
120 abort();
121 }
122
123 TEMPLATE(T, poly_clear) (a, ctx);
124 TEMPLATE(T, poly_clear) (b, ctx);
125 TEMPLATE(T, poly_clear) (c, ctx);
126 TEMPLATE(T, poly_clear) (d, ctx);
127
128 TEMPLATE(T, ctx_clear) (ctx);
129 }
130
131 /* Test aliasing of res and b */
132 for (i = 0; i < 20 * flint_test_multiplier(); i++)
133 {
134 TEMPLATE(T, ctx_t) ctx;
135 TEMPLATE(T, poly_t) a, b, c, d;
136
137 TEMPLATE(T, ctx_randtest) (ctx, state);
138
139 TEMPLATE(T, poly_init) (a, ctx);
140 TEMPLATE(T, poly_init) (b, ctx);
141 TEMPLATE(T, poly_init) (c, ctx);
142 TEMPLATE(T, poly_init) (d, ctx);
143
144 TEMPLATE(T, poly_randtest) (a, state, n_randint(state, 20) + 1, ctx);
145 TEMPLATE(T, poly_randtest) (b, state, n_randint(state, 20) + 1, ctx);
146 TEMPLATE(T, poly_randtest_not_zero) (c, state,
147 n_randint(state, 20) + 1, ctx);
148
149 TEMPLATE(T, poly_compose_mod) (d, a, b, c, ctx);
150 TEMPLATE(T, poly_compose_mod) (b, a, b, c, ctx);
151
152 if (!TEMPLATE(T, poly_equal) (d, b, ctx))
153 {
154 flint_printf("FAIL (aliasing b)\n");
155 flint_printf("a:\n");
156 TEMPLATE(T, poly_print) (a, ctx);
157 flint_printf("\n");
158 flint_printf("b:\n");
159 TEMPLATE(T, poly_print) (b, ctx);
160 flint_printf("\n");
161 flint_printf("c:\n");
162 TEMPLATE(T, poly_print) (c, ctx);
163 flint_printf("\n");
164 flint_printf("d:\n");
165 TEMPLATE(T, poly_print) (d, ctx);
166 flint_printf("\n");
167 abort();
168 }
169
170 TEMPLATE(T, poly_clear) (a, ctx);
171 TEMPLATE(T, poly_clear) (b, ctx);
172 TEMPLATE(T, poly_clear) (c, ctx);
173 TEMPLATE(T, poly_clear) (d, ctx);
174
175 TEMPLATE(T, ctx_clear) (ctx);
176 }
177
178 /* Test aliasing of res and c */
179 for (i = 0; i < 20 * flint_test_multiplier(); i++)
180 {
181 TEMPLATE(T, ctx_t) ctx;
182 TEMPLATE(T, poly_t) a, b, c, d;
183
184 TEMPLATE(T, ctx_randtest) (ctx, state);
185
186 TEMPLATE(T, poly_init) (a, ctx);
187 TEMPLATE(T, poly_init) (b, ctx);
188 TEMPLATE(T, poly_init) (c, ctx);
189 TEMPLATE(T, poly_init) (d, ctx);
190
191 TEMPLATE(T, poly_randtest) (a, state, n_randint(state, 20) + 1, ctx);
192 TEMPLATE(T, poly_randtest) (b, state, n_randint(state, 20) + 1, ctx);
193 TEMPLATE(T, poly_randtest_not_zero) (c, state,
194 n_randint(state, 20) + 1, ctx);
195
196 TEMPLATE(T, poly_compose_mod) (d, a, b, c, ctx);
197 TEMPLATE(T, poly_compose_mod) (c, a, b, c, ctx);
198
199 if (!TEMPLATE(T, poly_equal) (d, c, ctx))
200 {
201 flint_printf("FAIL (aliasing c)\n");
202 flint_printf("a:\n");
203 TEMPLATE(T, poly_print) (a, ctx);
204 flint_printf("\n");
205 flint_printf("b:\n");
206 TEMPLATE(T, poly_print) (b, ctx);
207 flint_printf("\n");
208 flint_printf("c:\n");
209 TEMPLATE(T, poly_print) (c, ctx);
210 flint_printf("\n");
211 flint_printf("d:\n");
212 TEMPLATE(T, poly_print) (d, ctx);
213 flint_printf("\n");
214 abort();
215 }
216
217 TEMPLATE(T, poly_clear) (a, ctx);
218 TEMPLATE(T, poly_clear) (b, ctx);
219 TEMPLATE(T, poly_clear) (c, ctx);
220 TEMPLATE(T, poly_clear) (d, ctx);
221
222 TEMPLATE(T, ctx_clear) (ctx);
223 }
224
225 FLINT_TEST_CLEANUP(state);
226 flint_printf("PASS\n");
227 return 0;
228 }
229
230
231 #endif
232