1 /*
2 Copyright (C) 2017 William Hart
3 Copyright (C) 2018 Daniel Schultz
4
5 This file is part of FLINT.
6
7 FLINT is free software: you can redistribute it and/or modify it under
8 the terms of the GNU Lesser General Public License (LGPL) as published
9 by the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version. See <https://www.gnu.org/licenses/>.
11 */
12
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include "fmpz_mpoly.h"
16 #include "ulong_extras.h"
17
18 int
main(void)19 main(void)
20 {
21 int i, j, result;
22 FLINT_TEST_INIT(state);
23
24 flint_printf("mul_array....");
25 fflush(stdout);
26
27 /* Check mul_array matches mul_johnson */
28 for (i = 0; i < 50 * flint_test_multiplier(); i++)
29 {
30 fmpz_mpoly_ctx_t ctx;
31 fmpz_mpoly_t f, g, h, k;
32 slong len, len1, len2, exp_bound, exp_bound1, exp_bound2;
33 slong coeff_bits, max_bound;
34
35 fmpz_mpoly_ctx_init_rand(ctx, state, 5);
36 fmpz_mpoly_init(f, ctx);
37 fmpz_mpoly_init(g, ctx);
38 fmpz_mpoly_init(h, ctx);
39 fmpz_mpoly_init(k, ctx);
40
41 len = n_randint(state, 100);
42 len1 = n_randint(state, 100);
43 len2 = n_randint(state, 100);
44
45 max_bound = ctx->minfo->ord == ORD_LEX ? 200 : 100;
46 max_bound = max_bound/ctx->minfo->nvars/ctx->minfo->nvars;
47 exp_bound = n_randint(state, max_bound) + 1;
48 exp_bound1 = n_randint(state, max_bound) + 1;
49 exp_bound2 = n_randint(state, max_bound) + 1;
50
51 coeff_bits = n_randint(state, 100);
52
53 for (j = 0; j < 4; j++)
54 {
55 fmpz_mpoly_randtest_bound(f, state, len1, coeff_bits, exp_bound1, ctx);
56 fmpz_mpoly_randtest_bound(g, state, len2, coeff_bits, exp_bound2, ctx);
57 fmpz_mpoly_randtest_bound(h, state, len, coeff_bits, exp_bound, ctx);
58 fmpz_mpoly_randtest_bound(k, state, len, coeff_bits, exp_bound, ctx);
59
60 fmpz_mpoly_mul_johnson(h, f, g, ctx);
61 fmpz_mpoly_assert_canonical(h, ctx);
62 result = fmpz_mpoly_mul_array(k, f, g, ctx);
63 if (!result)
64 {
65 continue;
66 }
67 fmpz_mpoly_assert_canonical(k, ctx);
68 result = fmpz_mpoly_equal(h, k, ctx);
69 if (!result)
70 {
71 printf("FAIL\n");
72 flint_printf("Check mul_array matches mul_johnson\ni = %wd, j = %wd\n", i, j);
73 flint_abort();
74 }
75 }
76
77 fmpz_mpoly_clear(f, ctx);
78 fmpz_mpoly_clear(g, ctx);
79 fmpz_mpoly_clear(h, ctx);
80 fmpz_mpoly_clear(k, ctx);
81 }
82
83 /* Check aliasing first argument */
84 for (i = 0; i < 20 * flint_test_multiplier(); i++)
85 {
86 fmpz_mpoly_ctx_t ctx;
87 fmpz_mpoly_t f, g, h;
88 slong len, len1, len2, exp_bound, exp_bound1, exp_bound2;
89 slong coeff_bits, max_bound;
90
91 fmpz_mpoly_ctx_init_rand(ctx, state, 10);
92 fmpz_mpoly_init(f, ctx);
93 fmpz_mpoly_init(g, ctx);
94 fmpz_mpoly_init(h, ctx);
95
96 len = n_randint(state, 50);
97 len1 = n_randint(state, 50);
98 len2 = n_randint(state, 50);
99
100 max_bound = 200/ctx->minfo->nvars/ctx->minfo->nvars;
101 exp_bound = n_randint(state, max_bound) + 1;
102 exp_bound1 = n_randint(state, max_bound) + 1;
103 exp_bound2 = n_randint(state, max_bound) + 1;
104
105 coeff_bits = n_randint(state, 200);
106
107 for (j = 0; j < 4; j++)
108 {
109 fmpz_mpoly_randtest_bound(f, state, len1, coeff_bits, exp_bound1, ctx);
110 fmpz_mpoly_randtest_bound(g, state, len2, coeff_bits, exp_bound2, ctx);
111 fmpz_mpoly_randtest_bound(h, state, len, coeff_bits, exp_bound, ctx);
112
113 fmpz_mpoly_mul_johnson(h, f, g, ctx);
114 fmpz_mpoly_assert_canonical(h, ctx);
115 result = fmpz_mpoly_mul_array(f, f, g, ctx);
116 if (!result)
117 continue;
118
119 fmpz_mpoly_assert_canonical(f, ctx);
120 result = fmpz_mpoly_equal(h, f, ctx);
121 if (!result)
122 {
123 printf("FAIL\n");
124 flint_printf("Check aliasing first argument\ni = %wd, j = %wd\n", i, j);
125 flint_abort();
126 }
127 }
128
129 fmpz_mpoly_clear(f, ctx);
130 fmpz_mpoly_clear(g, ctx);
131 fmpz_mpoly_clear(h, ctx);
132 }
133
134 /* Check aliasing second argument */
135 for (i = 0; i < 20 * flint_test_multiplier(); i++)
136 {
137 fmpz_mpoly_ctx_t ctx;
138 fmpz_mpoly_t f, g, h;
139 slong len, len1, len2, exp_bound, exp_bound1, exp_bound2;
140 slong coeff_bits, max_bound;
141
142 fmpz_mpoly_ctx_init_rand(ctx, state, 10);
143 fmpz_mpoly_init(f, ctx);
144 fmpz_mpoly_init(g, ctx);
145 fmpz_mpoly_init(h, ctx);
146
147 len = n_randint(state, 50);
148 len1 = n_randint(state, 50);
149 len2 = n_randint(state, 50);
150
151 max_bound = 200/ctx->minfo->nvars/ctx->minfo->nvars;
152 exp_bound = n_randint(state, max_bound) + 1;
153 exp_bound1 = n_randint(state, max_bound) + 1;
154 exp_bound2 = n_randint(state, max_bound) + 1;
155
156 coeff_bits = n_randint(state, 200);
157
158 for (j = 0; j < 4; j++)
159 {
160 fmpz_mpoly_randtest_bound(f, state, len1, coeff_bits, exp_bound1, ctx);
161 fmpz_mpoly_randtest_bound(g, state, len2, coeff_bits, exp_bound2, ctx);
162 fmpz_mpoly_randtest_bound(h, state, len, coeff_bits, exp_bound, ctx);
163
164 fmpz_mpoly_mul_johnson(h, f, g, ctx);
165 fmpz_mpoly_assert_canonical(h, ctx);
166 result = fmpz_mpoly_mul_array(g, f, g, ctx);
167 if (!result)
168 continue;
169
170 fmpz_mpoly_assert_canonical(g, ctx);
171 result = fmpz_mpoly_equal(h, g, ctx);
172 if (!result)
173 {
174 printf("FAIL\n");
175 flint_printf("Check aliasing second argument\ni = %wd, j = %wd\n", i, j);
176 flint_abort();
177 }
178 }
179
180 fmpz_mpoly_clear(f, ctx);
181 fmpz_mpoly_clear(g, ctx);
182 fmpz_mpoly_clear(h, ctx);
183 }
184
185 FLINT_TEST_CLEANUP(state);
186
187 flint_printf("PASS\n");
188 return 0;
189 }
190
191