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 slong i, j, k;
20 FLINT_TEST_INIT(state);
21
22 flint_printf("used_vars....");
23 fflush(stdout);
24
25 for (i = 0; i < 20 * flint_test_multiplier(); i++)
26 {
27 fmpz_mod_mpoly_ctx_t ctx;
28 fmpz_mod_mpoly_t f;
29 fmpz_t one, fdeg;
30 slong len, var;
31 flint_bitcnt_t exp_bits;
32 int * used;
33
34 fmpz_mod_mpoly_ctx_init_rand_bits(ctx, state, 20, 200);
35 fmpz_mod_mpoly_init(f, ctx);
36 fmpz_init(fdeg);
37 fmpz_init_set_ui(one, 1);
38 used = FLINT_ARRAY_ALLOC(ctx->minfo->nvars, int);
39
40 for (j = 0; j < ctx->minfo->nvars; j++)
41 {
42 len = n_randint(state, 200);
43 exp_bits = n_randint(state, 150) + 2;
44
45 fmpz_mod_mpoly_randtest_bits(f, state, len, exp_bits, ctx);
46
47 for (k = n_randint(state, ctx->minfo->nvars); k > 0; k--)
48 {
49 var = n_randint(state, ctx->minfo->nvars);
50 fmpz_mod_mpoly_evaluate_one_fmpz(f, f, var, one, ctx);
51 }
52
53 fmpz_mod_mpoly_used_vars(used, f, ctx);
54
55 for (var = 0; var < ctx->minfo->nvars; var++)
56 {
57 fmpz_mod_mpoly_degree_fmpz(fdeg, f, var, ctx);
58 if ((fmpz_sgn(fdeg) <= 0) != !used[var])
59 {
60 flint_printf("FAIL: checked used matches degree\n");
61 flint_printf("var = %wd\n", var);
62 flint_printf("deg: "); fmpz_print(fdeg); flint_printf("\n");
63 flint_abort();
64 }
65 }
66 }
67
68 flint_free(used);
69 fmpz_clear(one);
70 fmpz_clear(fdeg);
71 fmpz_mod_mpoly_clear(f, ctx);
72 fmpz_mod_mpoly_ctx_clear(ctx);
73 }
74
75 FLINT_TEST_CLEANUP(state);
76
77 flint_printf("PASS\n");
78 return 0;
79 }
80
81