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 <http://www.gnu.org/licenses/>.
10 */
11
12 #include "fmpq_mpoly.h"
13
14
15 int
main(void)16 main(void)
17 {
18 int i, j, k, result;
19 FLINT_TEST_INIT(state);
20
21 flint_printf("pow_ui....");
22 fflush(stdout);
23
24 /* Check against rmul */
25 for (i = 0; i < 10 * flint_test_multiplier(); i++)
26 {
27 fmpq_mpoly_ctx_t ctx;
28 fmpq_mpoly_t f, g, h;
29 slong len1, len2;
30 fmpz_t power;
31 flint_bitcnt_t coeff_bits, exp_bits1, exp_bits2;
32
33 fmpq_mpoly_ctx_init_rand(ctx, state, 20);
34 fmpq_mpoly_init(f, ctx);
35 fmpq_mpoly_init(g, ctx);
36 fmpq_mpoly_init(h, ctx);
37 fmpz_init(power);
38
39 len1 = n_randint(state, 10);
40 len2 = n_randint(state, 10);
41
42 exp_bits1 = n_randint(state, 200) + 2;
43 exp_bits2 = n_randint(state, 200) + 2;
44
45 coeff_bits = n_randint(state, 200);
46
47 for (j = 0; j < 10; j++)
48 {
49 fmpq_mpoly_randtest_bits(f, state, len1, coeff_bits, exp_bits1, ctx);
50 fmpq_mpoly_randtest_bits(g, state, len2, coeff_bits, exp_bits2, ctx);
51 fmpq_mpoly_randtest_bits(h, state, len2, coeff_bits, exp_bits2, ctx);
52
53 fmpq_mpoly_pow_ui(h, f, j, ctx);
54 fmpq_mpoly_assert_canonical(h, ctx);
55
56 fmpq_mpoly_one(g, ctx);
57 for (k = 0; k < j; k++)
58 fmpq_mpoly_mul(g, g, f, ctx);
59
60 result = fmpq_mpoly_equal(h, g, ctx);
61 if (!result)
62 {
63 printf("FAIL\n");
64 flint_printf("Check against rmul\ni = %wd, j = %wd\n", i ,j);
65 flint_abort();
66 }
67 }
68
69 fmpz_clear(power);
70 fmpq_mpoly_clear(f, ctx);
71 fmpq_mpoly_clear(g, ctx);
72 fmpq_mpoly_clear(h, ctx);
73 fmpq_mpoly_ctx_clear(ctx);
74 }
75
76
77 /* Check monomials against pow_fmpz */
78 for (i = 0; i < 20 * flint_test_multiplier(); i++)
79 {
80 fmpq_mpoly_ctx_t ctx;
81 fmpq_mpoly_t f, g, h;
82 slong len2;
83 fmpz_t power;
84 flint_bitcnt_t coeff_bits, exp_bits2;
85
86 fmpq_mpoly_ctx_init_rand(ctx, state, 20);
87 fmpq_mpoly_init(f, ctx);
88 fmpq_mpoly_init(g, ctx);
89 fmpq_mpoly_init(h, ctx);
90
91 fmpz_init(power);
92
93 len2 = n_randint(state, 10);
94 exp_bits2 = n_randint(state, 200) + 2;
95 coeff_bits = n_randint(state, 200);
96
97 for (j = 0; j < 10; j++)
98 {
99 /* make sure power is random ui */
100 fmpz_set_ui(power, n_randlimb(state));
101
102 /* set f to a random monomial */
103 fmpq_mpoly_one(f, ctx);
104 if (n_randint(state, 2))
105 {
106 fmpq_mpoly_neg(f, f, ctx);
107 }
108 for (k = 0; k < ctx->zctx->minfo->nvars; k++)
109 {
110 fmpq_mpoly_gen(h, n_randint(state, ctx->zctx->minfo->nvars), ctx);
111 fmpq_mpoly_mul(f, f, h, ctx);
112 }
113
114 fmpq_mpoly_randtest_bits(g, state, len2, coeff_bits, exp_bits2, ctx);
115 fmpq_mpoly_randtest_bits(h, state, len2, coeff_bits, exp_bits2, ctx);
116
117 fmpq_mpoly_pow_ui(g, f, fmpz_get_ui(power), ctx);
118 fmpq_mpoly_assert_canonical(h, ctx);
119
120 fmpq_mpoly_pow_fmpz(h, f, power, ctx);
121 fmpq_mpoly_assert_canonical(h, ctx);
122
123 result = fmpq_mpoly_equal(h, g, ctx);
124 if (!result)
125 {
126 printf("FAIL\n");
127 flint_printf("Check monomials against pow_fmpz\ni = %wd, j = %wd\n", i ,j);
128 flint_abort();
129 }
130 }
131
132 fmpz_clear(power);
133 fmpq_mpoly_clear(f, ctx);
134 fmpq_mpoly_clear(g, ctx);
135 fmpq_mpoly_clear(h, ctx);
136 fmpq_mpoly_ctx_clear(ctx);
137 }
138
139 FLINT_TEST_CLEANUP(state);
140
141 flint_printf("PASS\n");
142 return 0;
143 }
144
145