1 /*
2 Copyright (C) 2021 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
16 int
main(void)17 main(void)
18 {
19 int i, j;
20 FLINT_TEST_INIT(state);
21
22 flint_printf("get_term_monomial....");
23 fflush(stdout);
24
25 /* Check getting a coeff by its monomial */
26 for (i = 0; i < 100 * flint_test_multiplier(); i++)
27 {
28 fmpz_t c, d;
29 fmpz_mod_mpoly_ctx_t ctx;
30 fmpz_mod_mpoly_t f, g, h;
31 flint_bitcnt_t exp_bits1, exp_bits2, exp_bits3;
32 slong len1, len2, len3;
33
34 fmpz_init(c);
35 fmpz_init(d);
36
37 fmpz_mod_mpoly_ctx_init_rand_bits(ctx, state, 20, 200);
38 fmpz_mod_mpoly_init(f, ctx);
39 fmpz_mod_mpoly_init(g, ctx);
40 fmpz_mod_mpoly_init(h, ctx);
41
42 len1 = n_randint(state, 100);
43 len2 = n_randint(state, 100);
44 len3 = n_randint(state, 100);
45
46 exp_bits1 = n_randint(state, 200) + 2;
47 exp_bits2 = n_randint(state, 200) + 2;
48 exp_bits3 = n_randint(state, 200) + 2;
49
50 fmpz_mod_mpoly_randtest_bits(f, state, len1, exp_bits1, ctx);
51 fmpz_mod_mpoly_randtest_bits(g, state, len2, exp_bits2, ctx);
52 fmpz_mod_mpoly_randtest_bits(h, state, len3, exp_bits3, ctx);
53
54 fmpz_mod_mpoly_repack_bits(h, f,
55 f->bits + n_randint(state, 2*FLINT_BITS), ctx);
56
57 for (j = fmpz_mod_mpoly_length(f, ctx) - 1; j >= 0; j--)
58 {
59 fmpz_mod_mpoly_get_term_monomial(g, f, j, ctx);
60 fmpz_mod_mpoly_repack_bits(g, g,
61 g->bits + n_randint(state, FLINT_BITS), ctx);
62 fmpz_mod_mpoly_get_term_coeff_fmpz(d, f, j, ctx);
63 fmpz_mod_mpoly_get_coeff_fmpz_monomial(c, h, g, ctx);
64
65 if (!fmpz_equal(c, d))
66 {
67 flint_printf("FAIL\nCheck getting a coeff by its monomial\n");
68 flint_printf("i = %wd\n", i);
69 flint_abort();
70 }
71 }
72
73 fmpz_clear(c);
74 fmpz_clear(d);
75
76 fmpz_mod_mpoly_clear(f, ctx);
77 fmpz_mod_mpoly_clear(g, ctx);
78 fmpz_mod_mpoly_clear(h, ctx);
79 fmpz_mod_mpoly_ctx_clear(ctx);
80 }
81
82 FLINT_TEST_CLEANUP(state);
83
84 flint_printf("PASS\n");
85 return 0;
86 }
87
88