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