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 "fmpz_mpoly.h"
13
14 /* evaluate B(xbar) at xbar = C */
fmpz_mpoly_compose_fmpz_mpoly_geobucket(fmpz_mpoly_t A,const fmpz_mpoly_t B,fmpz_mpoly_struct * const * C,const fmpz_mpoly_ctx_t ctxB,const fmpz_mpoly_ctx_t ctxAC)15 int fmpz_mpoly_compose_fmpz_mpoly_geobucket(fmpz_mpoly_t A,
16 const fmpz_mpoly_t B, fmpz_mpoly_struct * const * C,
17 const fmpz_mpoly_ctx_t ctxB, const fmpz_mpoly_ctx_t ctxAC)
18 {
19 int success = 1;
20 slong i, j;
21 slong Blen = B->length;
22 const fmpz * Bcoeff = B->coeffs;
23 const ulong * Bexp = B->exps;
24 flint_bitcnt_t Bbits = B->bits;
25 slong BN = mpoly_words_per_exp(Bbits, ctxB->minfo);
26 fmpz_mpoly_t U, V, W;
27 fmpz_mpoly_geobucket_t T;
28 fmpz * e;
29
30 fmpz_mpoly_init(U, ctxAC);
31 fmpz_mpoly_init(V, ctxAC);
32 fmpz_mpoly_init(W, ctxAC);
33 fmpz_mpoly_geobucket_init(T, ctxAC);
34 e = _fmpz_vec_init(ctxB->minfo->nvars);
35
36 for (i = 0; success && i < Blen; i++)
37 {
38 fmpz_mpoly_set_fmpz(U, Bcoeff + i, ctxAC);
39 mpoly_get_monomial_ffmpz(e, Bexp + BN*i, Bbits, ctxB->minfo);
40 for (j = 0; j < ctxB->minfo->nvars; j++)
41 {
42 success = success && fmpz_mpoly_pow_fmpz(V, C[j], e + j, ctxAC);
43 fmpz_mpoly_mul(W, U, V, ctxAC);
44 fmpz_mpoly_swap(U, W, ctxAC);
45 }
46 fmpz_mpoly_geobucket_add(T, U, ctxAC);
47 }
48
49 if (success)
50 fmpz_mpoly_geobucket_empty(A, T, ctxAC);
51
52 fmpz_mpoly_clear(U, ctxAC);
53 fmpz_mpoly_clear(V, ctxAC);
54 fmpz_mpoly_clear(W, ctxAC);
55 fmpz_mpoly_geobucket_clear(T, ctxAC);
56 _fmpz_vec_clear(e, ctxB->minfo->nvars);
57
58 return success;
59 }
60
61