1 /*
2 Copyright (C) 2020 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 "fmpz_mod_mpoly.h"
15 #include "ulong_extras.h"
16
17 int
main(void)18 main(void)
19 {
20 int result;
21 slong i, j1, j2;
22 FLINT_TEST_INIT(state);
23
24 flint_printf("cmp....");
25 fflush(stdout);
26
27 /* check polynomial terms are in order */
28 for (i = 0; i < 10 * flint_test_multiplier(); i++)
29 {
30 fmpz_mod_mpoly_ctx_t ctx;
31 fmpz_mod_mpoly_t f, g, mf, mg;
32 slong len;
33 flint_bitcnt_t exp_bits;
34
35 fmpz_mod_mpoly_ctx_init_rand_bits(ctx, state, 20, 200);
36
37 fmpz_mod_mpoly_init(f, ctx);
38 fmpz_mod_mpoly_init(g, ctx);
39 fmpz_mod_mpoly_init(mf, ctx);
40 fmpz_mod_mpoly_init(mg, ctx);
41
42 len = n_randint(state, 100) + 1;
43 exp_bits = n_randint(state, 200) + 2;
44 exp_bits = n_randint(state, exp_bits) + 2;
45
46 fmpz_mod_mpoly_randtest_bits(f, state, len, exp_bits, ctx);
47 fmpz_mod_mpoly_repack_bits(g, f, f->bits + n_randint(state, FLINT_BITS), ctx);
48 fmpz_mod_mpoly_assert_canonical(f, ctx);
49 fmpz_mod_mpoly_assert_canonical(g, ctx);
50
51 for (j1 = 0; j1 < f->length; j1++)
52 for (j2 = 0; j2 < g->length; j2++)
53 {
54 fmpz_mod_mpoly_get_term_monomial(mf, f, j1, ctx);
55 fmpz_mod_mpoly_get_term_monomial(mg, g, j2, ctx);
56 result = fmpz_mod_mpoly_cmp(mf, mg, ctx);
57 if (!((result == 0 && j1 == j2) ||
58 (result == +1 && j1 < j2) ||
59 (result == -1 && j1 > j2)))
60 {
61 flint_printf("FAIL: check polynomial terms are in order\n"
62 "i = %wd, j1 = %wd, j2 = %wd\n", i, j1, j2);
63 flint_abort();
64 }
65 }
66
67 fmpz_mod_mpoly_clear(f, ctx);
68 fmpz_mod_mpoly_clear(g, ctx);
69 fmpz_mod_mpoly_clear(mf, ctx);
70 fmpz_mod_mpoly_clear(mg, ctx);
71 fmpz_mod_mpoly_ctx_clear(ctx);
72 }
73
74 for (i = 0; i < 100 * flint_test_multiplier(); i++)
75 {
76 fmpz_mod_mpoly_ctx_t ctx;
77 fmpz_mod_mpoly_t a, b, c, aa, bb, cc;
78 int a_a, a_b, a_c, a_aa, a_bb, a_cc;
79 int b_a, b_b, b_c, b_aa, b_bb, b_cc;
80 int c_a, c_b, c_c, c_aa, c_bb, c_cc;
81
82 fmpz_mod_mpoly_ctx_init_rand_bits(ctx, state, 20, 200);
83
84 fmpz_mod_mpoly_init(a, ctx);
85 fmpz_mod_mpoly_init(b, ctx);
86 fmpz_mod_mpoly_init(c, ctx);
87 fmpz_mod_mpoly_init(aa, ctx);
88 fmpz_mod_mpoly_init(bb, ctx);
89 fmpz_mod_mpoly_init(cc, ctx);
90
91 fmpz_mod_mpoly_randtest_bits(a, state, n_randint(state, 100) + 1,
92 n_randint(state, 200) + 2, ctx);
93
94 fmpz_mod_mpoly_randtest_bits(b, state, n_randint(state, 100) + 1,
95 n_randint(state, 200) + 2, ctx);
96
97 fmpz_mod_mpoly_randtest_bits(c, state, n_randint(state, 100) + 1,
98 n_randint(state, 200) + 2, ctx);
99
100 fmpz_mod_mpoly_repack_bits(aa, a, a->bits +
101 n_randint(state, 2*FLINT_BITS), ctx);
102
103 fmpz_mod_mpoly_repack_bits(bb, b, b->bits +
104 n_randint(state, 2*FLINT_BITS), ctx);
105
106 fmpz_mod_mpoly_repack_bits(cc, c, c->bits +
107 n_randint(state, 2*FLINT_BITS), ctx);
108
109 a_a = fmpz_mod_mpoly_cmp(a, a, ctx);
110 a_b = fmpz_mod_mpoly_cmp(a, b, ctx);
111 a_c = fmpz_mod_mpoly_cmp(a, c, ctx);
112 a_aa = fmpz_mod_mpoly_cmp(a, aa, ctx);
113 a_bb = fmpz_mod_mpoly_cmp(a, bb, ctx);
114 a_cc = fmpz_mod_mpoly_cmp(a, cc, ctx);
115
116 b_a = fmpz_mod_mpoly_cmp(b, a, ctx);
117 b_b = fmpz_mod_mpoly_cmp(b, b, ctx);
118 b_c = fmpz_mod_mpoly_cmp(b, c, ctx);
119 b_aa = fmpz_mod_mpoly_cmp(b, aa, ctx);
120 b_bb = fmpz_mod_mpoly_cmp(b, bb, ctx);
121 b_cc = fmpz_mod_mpoly_cmp(b, cc, ctx);
122
123 c_a = fmpz_mod_mpoly_cmp(c, a, ctx);
124 c_b = fmpz_mod_mpoly_cmp(c, b, ctx);
125 c_c = fmpz_mod_mpoly_cmp(c, c, ctx);
126 c_aa = fmpz_mod_mpoly_cmp(c, aa, ctx);
127 c_bb = fmpz_mod_mpoly_cmp(c, bb, ctx);
128 c_cc = fmpz_mod_mpoly_cmp(c, cc, ctx);
129
130 if (a_a != 0 || a_aa != 0 ||
131 b_b != 0 || b_bb != 0 ||
132 c_c != 0 || c_cc != 0)
133 {
134 flint_printf("FAIL: check polynomial compares equal to itself\n"
135 "i = %wd\n", i);
136 flint_abort();
137 }
138
139 if (a_b != a_bb || a_c != a_cc ||
140 b_a != b_aa || b_c != b_cc ||
141 c_a != c_aa || c_b != c_bb)
142 {
143 flint_printf("FAIL: check differing bits\n"
144 "i = %wd\n", i);
145 flint_abort();
146 }
147
148 if ((a_b*b_c == 0 && a_c != a_b + b_c) || (a_b*b_c > 0 && a_c != a_b))
149 {
150 flint_printf("FAIL: check transitivity\n"
151 "i = %wd\n", i);
152 flint_abort();
153 }
154
155 fmpz_mod_mpoly_clear(a, ctx);
156 fmpz_mod_mpoly_clear(b, ctx);
157 fmpz_mod_mpoly_clear(c, ctx);
158 fmpz_mod_mpoly_clear(aa, ctx);
159 fmpz_mod_mpoly_clear(bb, ctx);
160 fmpz_mod_mpoly_clear(cc, ctx);
161
162 fmpz_mod_mpoly_ctx_clear(ctx);
163 }
164
165 FLINT_TEST_CLEANUP(state);
166
167 flint_printf("PASS\n");
168 return 0;
169 }
170