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
mpoly_monomials_deflation(fmpz * shift,fmpz * stride,const ulong * Aexps,flint_bitcnt_t Abits,slong Alength,const mpoly_ctx_t mctx)15 void mpoly_monomials_deflation(fmpz * shift, fmpz * stride,
16 const ulong * Aexps, flint_bitcnt_t Abits, slong Alength,
17 const mpoly_ctx_t mctx)
18 {
19 slong i, j;
20 slong NA;
21 slong nvars = mctx->nvars;
22 fmpz_t d;
23 fmpz * exps;
24 TMP_INIT;
25
26 for (j = 0; j < nvars; j++)
27 fmpz_zero(stride + j);
28
29 if (Alength == 0)
30 {
31 /* undefined case */
32 for (j = 0; j < nvars; j++)
33 fmpz_zero(shift + j);
34 return;
35 }
36
37 TMP_START;
38
39 exps = (fmpz *) TMP_ALLOC(nvars*sizeof(fmpz));
40 for (j = 0; j < nvars; j++)
41 fmpz_init(exps + j);
42
43 fmpz_init(d);
44
45 NA = mpoly_words_per_exp(Abits, mctx);
46
47 i = Alength - 1;
48 mpoly_get_monomial_ffmpz(shift, Aexps + NA*i, Abits, mctx);
49
50 for (i--; i >= 0; i--)
51 {
52 mpoly_get_monomial_ffmpz(exps, Aexps + NA*i, Abits, mctx);
53 for (j = 0; j < nvars; j++)
54 {
55 fmpz_sub(d, exps + j, shift + j);
56 fmpz_gcd(stride + j, stride + j, d);
57 if (fmpz_sgn(d) < 0)
58 fmpz_swap(shift + j, exps + j);
59 }
60 }
61
62 for (j = 0; j < nvars; j++)
63 fmpz_clear(exps + j);
64
65 fmpz_clear(d);
66
67 TMP_END;
68 }
69
70