1 /*
2 Copyright (C) 2012 Sebastian Pancratz
3 Copyright (C) 2012 Andres Goens
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
21 #include "ulong_extras.h"
22 #include "long_extras.h"
23
24 int
main(void)25 main(void)
26 {
27 int i, result;
28 FLINT_TEST_INIT(state);
29
30 flint_printf("pow... ");
31 fflush(stdout);
32
33 /* Check aliasing */
34 for (i = 0; i < 20 * flint_test_multiplier(); i++)
35 {
36 slong len;
37 TEMPLATE(T, ctx_t) ctx;
38
39 TEMPLATE(T, poly_t) a, b, c;
40 ulong exp;
41
42 len = n_randint(state, 15) + 1;
43 TEMPLATE(T, ctx_randtest) (ctx, state);
44 TEMPLATE(T, poly_init) (a, ctx);
45 TEMPLATE(T, poly_init) (b, ctx);
46 TEMPLATE(T, poly_init) (c, ctx);
47
48 TEMPLATE(T, poly_randtest) (a, state, len, ctx);
49 exp = n_randtest(state) % UWORD(20);
50 TEMPLATE(T, poly_set) (b, a, ctx);
51 TEMPLATE(T, poly_pow) (c, b, exp, ctx);
52 TEMPLATE(T, poly_pow) (b, b, exp, ctx);
53
54 result = (TEMPLATE(T, poly_equal) (b, c, ctx));
55 if (!result)
56 {
57 flint_printf("FAIL:\n\n");
58 flint_printf("a = "), TEMPLATE(T, poly_print_pretty) (a, "X", ctx),
59 flint_printf("\n");
60 flint_printf("b = "), TEMPLATE(T, poly_print_pretty) (b, "X", ctx),
61 flint_printf("\n");
62 flint_printf("c = "), TEMPLATE(T, poly_print_pretty) (c, "X", ctx),
63 flint_printf("\n");
64 flint_printf("exp = %wu\n", exp);
65 abort();
66 }
67
68 TEMPLATE(T, poly_clear) (a, ctx);
69 TEMPLATE(T, poly_clear) (b, ctx);
70 TEMPLATE(T, poly_clear) (c, ctx);
71
72 TEMPLATE(T, ctx_clear) (ctx);
73 }
74
75 /* Compare with repeated multiplications by the base */
76 for (i = 0; i < 100 * flint_test_multiplier(); i++)
77 {
78 slong len;
79 TEMPLATE(T, ctx_t) ctx;
80
81 TEMPLATE(T, poly_t) a, b, c;
82 ulong exp;
83
84 len = n_randint(state, 15) + 1;
85 TEMPLATE(T, ctx_randtest) (ctx, state);
86 TEMPLATE(T, poly_init) (a, ctx);
87 TEMPLATE(T, poly_init) (b, ctx);
88 TEMPLATE(T, poly_init) (c, ctx);
89
90 TEMPLATE(T, poly_randtest) (b, state, len, ctx);
91 exp = n_randtest(state) % UWORD(20);
92
93 TEMPLATE(T, poly_pow) (a, b, exp, ctx);
94
95 if (exp == 0)
96 {
97 TEMPLATE(T, poly_one) (c, ctx);
98 }
99 else
100 {
101 slong j;
102
103 TEMPLATE(T, poly_set) (c, b, ctx);
104 for (j = 1; j < exp; j++)
105 TEMPLATE(T, poly_mul) (c, c, b, ctx);
106 }
107
108 result = (TEMPLATE(T, poly_equal) (a, c, ctx));
109 if (!result)
110 {
111 flint_printf("FAIL:\n\n");
112 flint_printf("a = "), TEMPLATE(T, poly_print_pretty) (a, "X", ctx),
113 flint_printf("\n");
114 flint_printf("b = "), TEMPLATE(T, poly_print_pretty) (b, "X", ctx),
115 flint_printf("\n");
116 flint_printf("c = "), TEMPLATE(T, poly_print_pretty) (c, "X", ctx),
117 flint_printf("\n");
118 flint_printf("exp = %wu\n", exp);
119 TEMPLATE(T, ctx_print) (ctx);
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
127 TEMPLATE(T, ctx_clear) (ctx);
128 }
129
130 FLINT_TEST_CLEANUP(state);
131 flint_printf("PASS\n");
132 return EXIT_SUCCESS;
133 }
134
135
136
137 #endif
138