1 /*
2     Copyright (C) 2010 William Hart
3     Copyright (C) 2013 Martin Lee
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, result;
22     FLINT_TEST_INIT(state);
23 
24     flint_printf("div_newton_n_preinv....");
25     fflush(stdout);
26 
27     /* Check result of divrem */
28     for (i = 0; i < 50 * flint_test_multiplier(); i++)
29     {
30         TEMPLATE(T, poly_t) a, b, binv, q, r, test;
31 
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) (binv, ctx);
39         TEMPLATE(T, poly_init) (q, ctx);
40         TEMPLATE(T, poly_init) (r, ctx);
41         TEMPLATE(T, poly_init) (test, ctx);
42 
43         do
44             TEMPLATE(T, poly_randtest) (b, state, n_randint(state, 200), ctx);
45         while (b->length <= 2);
46         TEMPLATE(T, poly_randtest) (a, state, n_randint(state, 200), ctx);
47         if (a->length > 2 * (b->length) - 3)
48             TEMPLATE(T, poly_truncate) (a, 2 * (b->length) - 3, ctx);
49 
50         TEMPLATE(T, poly_reverse) (binv, b, b->length, ctx);
51         TEMPLATE(T, poly_inv_series_newton) (binv, binv, b->length, ctx);
52         TEMPLATE(T, poly_div_newton_n_preinv) (q, a, b, binv, ctx);
53         TEMPLATE(T, poly_divrem) (test, r, a, b, ctx);
54 
55         result = (TEMPLATE(T, poly_equal) (q, test, ctx));
56         if (!result)
57         {
58             flint_printf("FAIL:\n");
59             TEMPLATE(T, poly_print) (test, ctx), flint_printf("\n\n");
60             TEMPLATE(T, poly_print) (q, ctx), flint_printf("\n\n");
61             TEMPLATE(T, poly_print) (a, ctx), flint_printf("\n\n");
62             TEMPLATE(T, poly_print) (b, ctx), flint_printf("\n\n");
63             abort();
64         }
65 
66         TEMPLATE(T, poly_clear) (a, ctx);
67         TEMPLATE(T, poly_clear) (b, ctx);
68         TEMPLATE(T, poly_clear) (binv, ctx);
69         TEMPLATE(T, poly_clear) (q, ctx);
70         TEMPLATE(T, poly_clear) (r, ctx);
71         TEMPLATE(T, poly_clear) (test, ctx);
72         TEMPLATE(T, ctx_clear) (ctx);
73     }
74 
75     /* Check aliasing of a and q */
76     for (i = 0; i < 50 * flint_test_multiplier(); i++)
77     {
78         TEMPLATE(T, poly_t) a, b, binv, q;
79 
80         TEMPLATE(T, ctx_t) ctx;
81 
82         TEMPLATE(T, ctx_randtest) (ctx, state);
83 
84         TEMPLATE(T, poly_init) (a, ctx);
85         TEMPLATE(T, poly_init) (b, ctx);
86         TEMPLATE(T, poly_init) (binv, ctx);
87         TEMPLATE(T, poly_init) (q, ctx);
88 
89         do
90             TEMPLATE(T, poly_randtest) (b, state, n_randint(state, 200), ctx);
91         while (b->length <= 2);
92         TEMPLATE(T, poly_randtest) (a, state, n_randint(state, 200), ctx);
93         if (a->length > 2 * (b->length) - 3)
94             TEMPLATE(T, poly_truncate) (a, 2 * (b->length) - 3, ctx);
95 
96         TEMPLATE(T, poly_reverse) (binv, b, b->length, ctx);
97         TEMPLATE(T, poly_inv_series_newton) (binv, binv, b->length, ctx);
98 
99         TEMPLATE(T, poly_div_newton_n_preinv) (q, a, b, binv, ctx);
100         TEMPLATE(T, poly_div_newton_n_preinv) (a, a, b, binv, ctx);
101 
102         result = (TEMPLATE(T, poly_equal) (a, q, ctx));
103         if (!result)
104         {
105             flint_printf("FAIL:\n");
106             TEMPLATE(T, poly_print) (a, ctx), flint_printf("\n\n");
107             TEMPLATE(T, poly_print) (b, ctx), flint_printf("\n\n");
108             TEMPLATE(T, poly_print) (q, ctx), flint_printf("\n\n");
109             abort();
110         }
111 
112         TEMPLATE(T, poly_clear) (a, ctx);
113         TEMPLATE(T, poly_clear) (b, ctx);
114         TEMPLATE(T, poly_clear) (binv, ctx);
115         TEMPLATE(T, poly_clear) (q, ctx);
116         TEMPLATE(T, ctx_clear) (ctx);
117     }
118 
119     /* Check aliasing of b and q */
120     for (i = 0; i < 50 * flint_test_multiplier(); i++)
121     {
122         TEMPLATE(T, poly_t) a, b, binv, q;
123 
124         TEMPLATE(T, ctx_t) ctx;
125 
126         TEMPLATE(T, ctx_randtest) (ctx, state);
127 
128         TEMPLATE(T, poly_init) (a, ctx);
129         TEMPLATE(T, poly_init) (b, ctx);
130         TEMPLATE(T, poly_init) (binv, ctx);
131         TEMPLATE(T, poly_init) (q, ctx);
132 
133         do
134             TEMPLATE(T, poly_randtest) (b, state, n_randint(state, 200), ctx);
135         while (b->length <= 2);
136         TEMPLATE(T, poly_randtest) (a, state, n_randint(state, 200), ctx);
137         if (a->length > 2 * (b->length) - 3)
138             TEMPLATE(T, poly_truncate) (a, 2 * (b->length) - 3, ctx);
139 
140         TEMPLATE(T, poly_reverse) (binv, b, b->length, ctx);
141         TEMPLATE(T, poly_inv_series_newton) (binv, binv, b->length, ctx);
142 
143         TEMPLATE(T, poly_div_newton_n_preinv) (q, a, b, binv, ctx);
144         TEMPLATE(T, poly_div_newton_n_preinv) (b, a, b, binv, ctx);
145 
146         result = (TEMPLATE(T, poly_equal) (b, q, ctx));
147         if (!result)
148         {
149             flint_printf("FAIL:\n");
150             TEMPLATE(T, poly_print) (a, ctx), flint_printf("\n\n");
151             TEMPLATE(T, poly_print) (b, ctx), flint_printf("\n\n");
152             TEMPLATE(T, poly_print) (q, ctx), flint_printf("\n\n");
153             abort();
154         }
155 
156         TEMPLATE(T, poly_clear) (a, ctx);
157         TEMPLATE(T, poly_clear) (b, ctx);
158         TEMPLATE(T, poly_clear) (binv, ctx);
159         TEMPLATE(T, poly_clear) (q, ctx);
160         TEMPLATE(T, ctx_clear) (ctx);
161     }
162 
163     /* Check aliasing of binv and q */
164     for (i = 0; i < 50 * flint_test_multiplier(); i++)
165     {
166         TEMPLATE(T, poly_t) a, b, binv, q;
167 
168         TEMPLATE(T, ctx_t) ctx;
169 
170         TEMPLATE(T, ctx_randtest) (ctx, state);
171 
172         TEMPLATE(T, poly_init) (a, ctx);
173         TEMPLATE(T, poly_init) (b, ctx);
174         TEMPLATE(T, poly_init) (binv, ctx);
175         TEMPLATE(T, poly_init) (q, ctx);
176 
177 
178         do
179             TEMPLATE(T, poly_randtest) (b, state, n_randint(state, 200), ctx);
180         while (b->length <= 2);
181         TEMPLATE(T, poly_randtest) (a, state, n_randint(state, 200), ctx);
182         if (a->length > 2 * (b->length) - 3)
183             TEMPLATE(T, poly_truncate) (a, 2 * (b->length) - 3, ctx);
184 
185         TEMPLATE(T, poly_reverse) (binv, b, b->length, ctx);
186         TEMPLATE(T, poly_inv_series_newton) (binv, binv, b->length, ctx);
187 
188         TEMPLATE(T, poly_div_newton_n_preinv) (q, a, b, binv, ctx);
189         TEMPLATE(T, poly_div_newton_n_preinv) (binv, a, b, binv, ctx);
190 
191         result = (TEMPLATE(T, poly_equal) (binv, q, ctx));
192         if (!result)
193         {
194             flint_printf("FAIL:\n");
195             TEMPLATE(T, poly_print) (a, ctx), flint_printf("\n\n");
196             TEMPLATE(T, poly_print) (b, ctx), flint_printf("\n\n");
197             TEMPLATE(T, poly_print) (binv, ctx), flint_printf("\n\n");
198             TEMPLATE(T, poly_print) (q, ctx), flint_printf("\n\n");
199             abort();
200         }
201 
202         TEMPLATE(T, poly_clear) (a, ctx);
203         TEMPLATE(T, poly_clear) (b, ctx);
204         TEMPLATE(T, poly_clear) (binv, ctx);
205         TEMPLATE(T, poly_clear) (q, ctx);
206         TEMPLATE(T, ctx_clear) (ctx);
207     }
208 
209     FLINT_TEST_CLEANUP(state);
210     flint_printf("PASS\n");
211     return 0;
212 }
213 
214 
215 #endif
216