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 <stdio.h>
13 #include <stdlib.h>
14 #include "fq_nmod_mpoly.h"
15
16 int
main(void)17 main(void)
18 {
19 slong i, v;
20 FLINT_TEST_INIT(state);
21
22 flint_printf("compose_fq_nmod_poly....");
23 fflush(stdout);
24
25 {
26 fq_nmod_poly_t A;
27 fq_nmod_mpoly_t B;
28 fq_nmod_poly_struct * Cp[3];
29 fq_nmod_poly_struct C[3];
30 fq_nmod_mpoly_ctx_t ctxB;
31 fmpz one = 1, two = 2, three = 3;
32
33 fq_nmod_mpoly_ctx_init_deg(ctxB, 3, ORD_LEX, 13, 3);
34
35 fq_nmod_mpoly_init(B, ctxB);
36 fq_nmod_poly_init(A, ctxB->fqctx);
37 for (i = 0; i < 3; i++)
38 {
39 Cp[i] = C + i;
40 fq_nmod_poly_init(C + i, ctxB->fqctx);
41 }
42
43 fq_nmod_mpoly_set_str_pretty(B,
44 "1 + x1*x2^2 + x2^9999999999999999999999999*x3^9", NULL, ctxB);
45
46 fq_nmod_poly_zero(C + 0, ctxB->fqctx);
47 fq_nmod_poly_zero(C + 1, ctxB->fqctx);
48 fq_nmod_poly_zero(C + 2, ctxB->fqctx);
49 fq_nmod_poly_set_coeff_fmpz(C + 0, 1, &one, ctxB->fqctx);
50 fq_nmod_poly_set_coeff_fmpz(C + 1, 2, &two, ctxB->fqctx);
51 fq_nmod_poly_set_coeff_fmpz(C + 2, 3, &three, ctxB->fqctx);
52 if (fq_nmod_mpoly_compose_fq_nmod_poly(A, B, Cp, ctxB))
53 {
54 printf("FAIL\n");
55 flint_printf("Check non-example 1\n", i);
56 flint_abort();
57 }
58
59 fq_nmod_poly_zero(C + 0, ctxB->fqctx);
60 fq_nmod_poly_zero(C + 1, ctxB->fqctx);
61 fq_nmod_poly_zero(C + 2, ctxB->fqctx);
62 fq_nmod_poly_set_coeff_fmpz(C + 0, 0, &one, ctxB->fqctx);
63 fq_nmod_poly_set_coeff_fmpz(C + 1, 0, &two, ctxB->fqctx);
64 fq_nmod_poly_set_coeff_fmpz(C + 2, 0, &three, ctxB->fqctx);
65 if (!fq_nmod_mpoly_compose_fq_nmod_poly(A, B, Cp, ctxB))
66 {
67 printf("FAIL\n");
68 flint_printf("Check example 2\n", i);
69 flint_abort();
70 }
71
72 if (!fq_nmod_poly_is_zero(A, ctxB->fqctx))
73 {
74 printf("FAIL\n");
75 flint_printf("Check example 2 equality\n", i);
76 flint_abort();
77 }
78
79 fq_nmod_mpoly_clear(B, ctxB);
80 fq_nmod_poly_clear(A, ctxB->fqctx);
81 for (i = 0; i < 3; i++)
82 fq_nmod_poly_clear(C + i, ctxB->fqctx);
83
84 fq_nmod_mpoly_ctx_clear(ctxB);
85 }
86
87 /* Check composition and evalall commute */
88 for (i = 0; i < 20*flint_test_multiplier(); i++)
89 {
90 fq_nmod_mpoly_ctx_t ctx;
91 fq_nmod_mpoly_t f;
92 fq_nmod_poly_t g;
93 fq_nmod_poly_struct ** vals1;
94 fq_nmod_t fe, ge;
95 fq_nmod_t vals2;
96 fq_nmod_struct ** vals3;
97 slong nvars1;
98 slong len1, len2;
99 slong exp_bound1;
100
101 fq_nmod_mpoly_ctx_init_rand(ctx, state, 20, FLINT_BITS, 10);
102 nvars1 = ctx->minfo->nvars;
103
104 fq_nmod_mpoly_init(f, ctx);
105 fq_nmod_poly_init(g, ctx->fqctx);
106 fq_nmod_init(fe, ctx->fqctx);
107 fq_nmod_init(ge, ctx->fqctx);
108
109 len1 = n_randint(state, 40/nvars1 + 1);
110 len2 = n_randint(state, 20);
111 exp_bound1 = n_randint(state, 100/nvars1 + 2) + 1;
112
113 fq_nmod_mpoly_randtest_bound(f, state, len1, exp_bound1, ctx);
114
115 vals1 = (fq_nmod_poly_struct **) flint_malloc(nvars1*
116 sizeof(fq_nmod_poly_struct *));
117 for (v = 0; v < nvars1; v++)
118 {
119 vals1[v] = (fq_nmod_poly_struct *) flint_malloc(
120 sizeof(fq_nmod_poly_struct));
121 fq_nmod_poly_init(vals1[v], ctx->fqctx);
122 fq_nmod_poly_randtest(vals1[v], state, len2, ctx->fqctx);
123 }
124
125 fq_nmod_init(vals2, ctx->fqctx);
126 fq_nmod_randtest(vals2, state, ctx->fqctx);
127
128 vals3 = (fq_nmod_struct **) flint_malloc(nvars1*sizeof(fq_nmod_struct *));
129 for (v = 0; v < nvars1; v++)
130 {
131 vals3[v] = (fq_nmod_struct *) flint_malloc(sizeof(fq_nmod_struct));
132 fq_nmod_init(vals3[v], ctx->fqctx);
133 fq_nmod_poly_evaluate_fq_nmod(vals3[v], vals1[v], vals2, ctx->fqctx);
134 }
135
136 if (fq_nmod_mpoly_total_degree_si(f, ctx) < 50)
137 {
138 if (!fq_nmod_mpoly_compose_fq_nmod_poly(g, f, vals1, ctx))
139 {
140 printf("FAIL\n");
141 flint_printf("Check composition success\ni: %wd\n", i);
142 flint_abort();
143 }
144
145 fq_nmod_mpoly_evaluate_all_fq_nmod(fe, f, vals3, ctx);
146 fq_nmod_poly_evaluate_fq_nmod(ge, g, vals2, ctx->fqctx);
147
148 if (!fq_nmod_equal(fe, ge, ctx->fqctx))
149 {
150 printf("FAIL\n");
151 flint_printf("Check composition and evalall commute\ni: %wd\n", i);
152 flint_abort();
153 }
154 }
155
156 for (v = 0; v < nvars1; v++)
157 {
158 fq_nmod_poly_clear(vals1[v], ctx->fqctx);
159 flint_free(vals1[v]);
160 }
161 flint_free(vals1);
162
163 fq_nmod_clear(vals2, ctx->fqctx);
164
165 for (v = 0; v < nvars1; v++)
166 {
167 fq_nmod_clear(vals3[v], ctx->fqctx);
168 flint_free(vals3[v]);
169 }
170 flint_free(vals3);
171
172 fq_nmod_mpoly_clear(f, ctx);
173 fq_nmod_poly_clear(g, ctx->fqctx);
174 fq_nmod_clear(fe, ctx->fqctx);
175 fq_nmod_clear(ge, ctx->fqctx);
176
177 fq_nmod_mpoly_ctx_clear(ctx);
178 }
179
180 printf("PASS\n");
181 FLINT_TEST_CLEANUP(state);
182
183 return 0;
184 }
185