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 <https://www.gnu.org/licenses/>.
10 */
11
12 #include "nmod_mpoly.h"
13
14 /* evaluate B(xbar) at xbar = C */
nmod_mpoly_compose_nmod_mpoly_geobucket(nmod_mpoly_t A,const nmod_mpoly_t B,nmod_mpoly_struct * const * C,const nmod_mpoly_ctx_t ctxB,const nmod_mpoly_ctx_t ctxAC)15 int nmod_mpoly_compose_nmod_mpoly_geobucket(nmod_mpoly_t A,
16 const nmod_mpoly_t B, nmod_mpoly_struct * const * C,
17 const nmod_mpoly_ctx_t ctxB, const nmod_mpoly_ctx_t ctxAC)
18 {
19 int success = 1;
20 slong i, j;
21 slong Blen = B->length;
22 const mp_limb_t * 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 nmod_mpoly_t U, V, W;
27 nmod_mpoly_geobucket_t T;
28 fmpz * e;
29
30 nmod_mpoly_init(U, ctxAC);
31 nmod_mpoly_init(V, ctxAC);
32 nmod_mpoly_init(W, ctxAC);
33 nmod_mpoly_geobucket_init(T, ctxAC);
34 e = _fmpz_vec_init(ctxB->minfo->nvars);
35
36 for (i = 0; success && i < Blen; i++)
37 {
38 nmod_mpoly_set_ui(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 && nmod_mpoly_pow_fmpz(V, C[j], e + j, ctxAC);
43 nmod_mpoly_mul(W, U, V, ctxAC);
44 nmod_mpoly_swap(U, W, ctxAC);
45 }
46 nmod_mpoly_geobucket_add(T, U, ctxAC);
47 }
48
49 if (success)
50 nmod_mpoly_geobucket_empty(A, T, ctxAC);
51
52 nmod_mpoly_clear(U, ctxAC);
53 nmod_mpoly_clear(V, ctxAC);
54 nmod_mpoly_clear(W, ctxAC);
55 nmod_mpoly_geobucket_clear(T, ctxAC);
56 _fmpz_vec_clear(e, ctxB->minfo->nvars);
57
58 return success;
59 }
60
61