1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2011 Andy Novocin
Copyright (C) 2011 Sebastian Pancratz
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_poly.h"
void fmpz_poly_hensel_build_tree(slong *link, fmpz_poly_t *v, fmpz_poly_t *w,
const nmod_poly_factor_t fac)
{
const slong r = fac->num;
const nmod_t mod = (fac->p + 0)->mod;
slong i, j;
nmod_poly_t d;
nmod_poly_t *V = flint_malloc((2*r - 2)*sizeof(nmod_poly_t));
nmod_poly_t *W = flint_malloc((2*r - 2)*sizeof(nmod_poly_t));
nmod_poly_init_preinv(d, mod.n, mod.ninv);
for (i = 0; i < 2*r - 2; i++)
{
nmod_poly_init_preinv(V[i], mod.n, mod.ninv);
nmod_poly_init_preinv(W[i], mod.n, mod.ninv);
}
for (i = 0; i < r; i++)
{
nmod_poly_set(V[i], fac->p + i);
link[i] = - i - 1;
}
for (i = r, j = 0; j < 2*r - 4; i++, j += 2)
{
slong s;
slong minp, mind;
slong tmp;
minp = j;
mind = nmod_poly_degree(V[j]);
for (s = j+1; s < i; s++)
{
if (nmod_poly_degree(V[s]) < mind)
{
minp = s;
mind = nmod_poly_degree(V[s]);
}
}
nmod_poly_swap(V[j], V[minp]);
/* Swap link[j] and V[minp] */
tmp = link[j];
link[j] = link[minp];
link[minp] = tmp;
minp = j+1;
mind = nmod_poly_degree(V[j+1]);
for (s = j + 2; s < i; s++)
{
if (nmod_poly_degree(V[s]) < mind)
{
minp = s;
mind = nmod_poly_degree(V[s]);
}
}
nmod_poly_swap(V[j + 1], V[minp]);
/* Swap link[j+1] and V[minp] */
tmp = link[j + 1];
link[j+1] = link[minp];
link[minp] = tmp;
nmod_poly_mul(V[i], V[j], V[j+1]);
link[i] = j;
}
for (j = 0; j < 2*r - 2; j += 2)
{
/* N.B. d == 1 */
nmod_poly_xgcd(d, W[j], W[j+1], V[j], V[j+1]);
}
for (j = 0; j < 2*r - 2; j++)
{
fmpz_poly_set_nmod_poly(v[j], V[j]);
fmpz_poly_set_nmod_poly(w[j], W[j]);
}
for (i = 0; i < 2*r - 2; i++)
{
nmod_poly_clear(V[i]);
nmod_poly_clear(W[i]);
}
nmod_poly_clear(d);
flint_free(V);
flint_free(W);
}
|