ALL: Add flint
This commit is contained in:
50
external/flint-2.4.3/fmpz_poly_factor/clear.c
vendored
Normal file
50
external/flint-2.4.3/fmpz_poly_factor/clear.c
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <gmp.h>
|
||||
#include <stdlib.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_poly.h"
|
||||
|
||||
void fmpz_poly_factor_clear(fmpz_poly_factor_t fac)
|
||||
{
|
||||
if (fac->alloc)
|
||||
{
|
||||
slong i;
|
||||
|
||||
for (i = 0; i < fac->alloc; i++)
|
||||
{
|
||||
fmpz_poly_clear(fac->p + i);
|
||||
}
|
||||
|
||||
fmpz_clear(&(fac->c));
|
||||
flint_free(fac->p);
|
||||
flint_free(fac->exp);
|
||||
fac->p = NULL;
|
||||
fac->exp = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
43
external/flint-2.4.3/fmpz_poly_factor/concat.c
vendored
Normal file
43
external/flint-2.4.3/fmpz_poly_factor/concat.c
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
/*=============================================================================
|
||||
|
||||
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) 2007 David Howden
|
||||
Copyright (C) 2007, 2008, 2009, 2010 William Hart
|
||||
Copyright (C) 2008 Richard Howell-Peak
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
Copyright (C) 2011 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz_poly.h"
|
||||
|
||||
void
|
||||
fmpz_poly_factor_concat(fmpz_poly_factor_t res, const fmpz_poly_factor_t fac)
|
||||
{
|
||||
slong i;
|
||||
|
||||
fmpz_mul(&(res->c), &(res->c), &(fac->c));
|
||||
|
||||
for (i = 0; i < fac->num; i++)
|
||||
fmpz_poly_factor_insert(res, fac->p + i, fac->exp[i]);
|
||||
}
|
||||
151
external/flint-2.4.3/fmpz_poly_factor/doc/fmpz_poly_factor.txt
vendored
Normal file
151
external/flint-2.4.3/fmpz_poly_factor/doc/fmpz_poly_factor.txt
vendored
Normal file
@@ -0,0 +1,151 @@
|
||||
/*=============================================================================
|
||||
|
||||
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
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
Memory management
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
void fmpz_poly_factor_init(fmpz_poly_factor_t fac)
|
||||
|
||||
Initialises a new factor structure.
|
||||
|
||||
void fmpz_poly_factor_init2(fmpz_poly_factor_t fac, slong alloc)
|
||||
|
||||
Initialises a new factor structure, providing space for
|
||||
at least \code{alloc} factors.
|
||||
|
||||
void fmpz_poly_factor_realloc(fmpz_poly_factor_t fac, slong alloc)
|
||||
|
||||
Reallocates the factor structure to provide space for
|
||||
precisely \code{alloc} factors.
|
||||
|
||||
void fmpz_poly_factor_fit_length(fmpz_poly_factor_t fac, slong len)
|
||||
|
||||
Ensures that the factor structure has space for at
|
||||
least \code{len} factors. This functions takes care
|
||||
of the case of repeated calls by always at least
|
||||
doubling the number of factors the structure can hold.
|
||||
|
||||
void fmpz_poly_factor_clear(fmpz_poly_factor_t fac)
|
||||
|
||||
Releases all memory occupied by the factor structure.
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
Manipulating factors
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
void fmpz_poly_factor_set(fmpz_poly_factor_t res, const fmpz_poly_factor_t fac)
|
||||
|
||||
Sets \code{res} to the same factorisation as \code{fac}.
|
||||
|
||||
void fmpz_poly_factor_insert(fmpz_poly_factor_t fac,
|
||||
const fmpz_poly_t p, slong e)
|
||||
|
||||
Adds the primitive polynomial $p^e$ to the factorisation \code{fac}.
|
||||
|
||||
Assumes that $\deg(p) \geq 2$ and $e \neq 0$.
|
||||
|
||||
void fmpz_poly_factor_concat(fmpz_poly_factor_t res,
|
||||
const fmpz_poly_factor_t fac)
|
||||
|
||||
Concatenates two factorisations.
|
||||
|
||||
This is equivalent to calling \code{fmpz_poly_factor_insert()}
|
||||
repeatedly with the individual factors of \code{fac}.
|
||||
|
||||
Does not support aliasing between \code{res} and \code{fac}.
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
Input and output
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
void fmpz_poly_factor_print(const fmpz_poly_factor_t fac)
|
||||
|
||||
Prints the entries of \code{fac} to standard output.
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
Factoring algorithms
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
void fmpz_poly_factor_squarefree(fmpz_poly_factor_t fac, fmpz_poly_t F)
|
||||
|
||||
Takes as input a polynomial $F$ and a freshly initialized factor
|
||||
structure \code{fac}. Updates \code{fac} to contain a factorization
|
||||
of $F$ into (not necessarily irreducible) factors that themselves
|
||||
have no repeated factors. None of the returned factors will have
|
||||
the same exponent. That is we return $g_i$ and unique $e_i$ such that
|
||||
\begin{equation*}
|
||||
F = c \prod_{i} g_i^{e_i}
|
||||
\end{equation*}
|
||||
where $c$ is the signed content of $F$ and $\gcd(g_i, g_i') = 1$.
|
||||
|
||||
void fmpz_poly_factor_zassenhaus_recombination(fmpz_poly_factor_t
|
||||
final_fac, const fmpz_poly_factor_t lifted_fac,
|
||||
const fmpz_poly_t F, const fmpz_t P, slong exp)
|
||||
|
||||
Takes as input a factor structure \code{lifted_fac} containing a
|
||||
squarefree factorization of the polynomial $F \bmod p$. The algorithm
|
||||
does a brute force search for irreducible factors of $F$ over the
|
||||
integers, and each factor is raised to the power \code{exp}.
|
||||
|
||||
The impact of the algorithm is to augment a factorization of
|
||||
\code{F^exp} to the factor structure \code{final_fac}.
|
||||
|
||||
void _fmpz_poly_factor_zassenhaus(fmpz_poly_factor_t final_fac,
|
||||
slong exp, fmpz_poly_t f, slong cutoff)
|
||||
|
||||
This is the internal wrapper of Zassenhaus.
|
||||
|
||||
It will attempt to find a small prime such that $f$ modulo $p$ has
|
||||
a minimal number of factors. If it cannot find a prime giving less
|
||||
than \code{cutoff} factors it aborts. Then it decides a $p$-adic
|
||||
precision to lift the factors to, hensel lifts, and finally calls
|
||||
Zassenhaus recombination.
|
||||
|
||||
Assumes that $\len(f) \geq 2$.
|
||||
|
||||
Assumes that $f$ is primitive.
|
||||
|
||||
Assumes that the constant coefficient of $f$ is non-zero. Note that
|
||||
this can be easily achieved by taking out factors of the form $x^k$
|
||||
before calling this routine.
|
||||
|
||||
void fmpz_poly_factor_zassenhaus(fmpz_poly_factor_t final_fac, fmpz_poly_t F)
|
||||
|
||||
A wrapper of the Zassenhaus factoring algorithm, which takes as input
|
||||
any polynomial $F$, and stores a factorization in \code{final_fac}.
|
||||
|
||||
The complexity will be exponential in the number of local factors
|
||||
we find for the components of a squarefree factorization of $F$.
|
||||
|
||||
96
external/flint-2.4.3/fmpz_poly_factor/factor_squarefree.c
vendored
Normal file
96
external/flint-2.4.3/fmpz_poly_factor/factor_squarefree.c
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_poly.h"
|
||||
|
||||
void fmpz_poly_factor_squarefree(fmpz_poly_factor_t fac, const fmpz_poly_t F)
|
||||
{
|
||||
fmpz_poly_content(&(fac->c), F);
|
||||
if (fmpz_sgn(fmpz_poly_lead(F)) < 0)
|
||||
fmpz_neg(&(fac->c), &(fac->c));
|
||||
|
||||
if (F->length > 1)
|
||||
{
|
||||
fmpz_poly_t f, d, t1;
|
||||
|
||||
fmpz_poly_init(f);
|
||||
fmpz_poly_init(d);
|
||||
fmpz_poly_init(t1);
|
||||
|
||||
fmpz_poly_scalar_divexact_fmpz(f, F, &(fac->c));
|
||||
|
||||
fmpz_poly_derivative(t1, f);
|
||||
fmpz_poly_gcd(d, f, t1);
|
||||
|
||||
if (d->length == 1)
|
||||
{
|
||||
fmpz_poly_factor_insert(fac, f, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
fmpz_poly_t v, w, s;
|
||||
slong i;
|
||||
|
||||
fmpz_poly_init(v);
|
||||
fmpz_poly_init(w);
|
||||
fmpz_poly_init(s);
|
||||
|
||||
fmpz_poly_div(v, f, d);
|
||||
fmpz_poly_div(w, t1, d);
|
||||
|
||||
for (i = 1; ; i++)
|
||||
{
|
||||
fmpz_poly_derivative(t1, v);
|
||||
fmpz_poly_sub(s, w, t1);
|
||||
|
||||
if (s->length == 0)
|
||||
{
|
||||
if (v->length > 1)
|
||||
fmpz_poly_factor_insert(fac, v, i);
|
||||
break;
|
||||
}
|
||||
|
||||
fmpz_poly_gcd(d, v, s);
|
||||
fmpz_poly_div(v, v, d);
|
||||
fmpz_poly_div(w, s, d);
|
||||
|
||||
if (d->length > 1)
|
||||
fmpz_poly_factor_insert(fac, d, i);
|
||||
}
|
||||
|
||||
fmpz_poly_clear(v);
|
||||
fmpz_poly_clear(w);
|
||||
fmpz_poly_clear(s);
|
||||
}
|
||||
fmpz_poly_clear(f);
|
||||
fmpz_poly_clear(d);
|
||||
fmpz_poly_clear(t1);
|
||||
}
|
||||
}
|
||||
290
external/flint-2.4.3/fmpz_poly_factor/factor_zassenhaus.c
vendored
Normal file
290
external/flint-2.4.3/fmpz_poly_factor/factor_zassenhaus.c
vendored
Normal file
@@ -0,0 +1,290 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 <stdlib.h>
|
||||
#include "fmpz_poly.h"
|
||||
|
||||
#define TRACE_ZASSENHAUS 0
|
||||
|
||||
/*
|
||||
Let $f$ be a polynomial of degree $m = \deg(f) \geq 2$.
|
||||
If another polynomial $g$ divides $f$ then, for all
|
||||
$0 \leq j \leq \deg(g)$,
|
||||
\begin{equation*}
|
||||
\abs{b_j} \leq \binom{n-1}{j} \abs{f} + \binom{n-1}{j-1} \abs{a_m}
|
||||
\end{equation*}
|
||||
where $\abs{f}$ denotes the $2$-norm of $f$. This bound
|
||||
is due to Mignotte, see e.g., Cohen p.\ 134.
|
||||
|
||||
This function sets $B$ such that, for all $0 \leq j \leq \deg(g)$,
|
||||
$\abs{b_j} \leq B$.
|
||||
|
||||
Consequently, when proceeding with Hensel lifting, we
|
||||
proceed to choose an $a$ such that $p^a \geq 2 B + 1$,
|
||||
e.g., $a = \ceil{\log_p(2B + 1)}$.
|
||||
|
||||
Note that the formula degenerates for $j = 0$ and $j = n$
|
||||
and so in this case we use that the leading (resp.\ constant)
|
||||
term of $g$ divides the leading (resp.\ constant) term of $f$.
|
||||
*/
|
||||
static void _fmpz_poly_factor_mignotte(fmpz_t B, const fmpz *f, slong m)
|
||||
{
|
||||
slong j;
|
||||
fmpz_t b, f2, lc, s, t;
|
||||
|
||||
fmpz_init(b);
|
||||
fmpz_init(f2);
|
||||
fmpz_init(lc);
|
||||
fmpz_init(s);
|
||||
fmpz_init(t);
|
||||
|
||||
for (j = 0; j <= m; j++)
|
||||
fmpz_addmul(f2, f + j, f + j);
|
||||
fmpz_sqrt(f2, f2);
|
||||
fmpz_add_ui(f2, f2, 1);
|
||||
|
||||
fmpz_abs(lc, f + m);
|
||||
|
||||
fmpz_abs(B, f + 0);
|
||||
|
||||
/* We have $b = \binom{m-1}{j-1}$ on loop entry and
|
||||
$b = \binom{m-1}{j}$ on exit. */
|
||||
fmpz_set_ui(b, m-1);
|
||||
for (j = 1; j < m; j++)
|
||||
{
|
||||
fmpz_mul(t, b, lc);
|
||||
|
||||
fmpz_mul_ui(b, b, m - j);
|
||||
fmpz_divexact_ui(b, b, j);
|
||||
|
||||
fmpz_mul(s, b, f2);
|
||||
fmpz_add(s, s, t);
|
||||
if (fmpz_cmp(B, s) < 0)
|
||||
fmpz_set(B, s);
|
||||
}
|
||||
|
||||
if (fmpz_cmp(B, lc) < 0)
|
||||
fmpz_set(B, lc);
|
||||
|
||||
fmpz_clear(b);
|
||||
fmpz_clear(f2);
|
||||
fmpz_clear(lc);
|
||||
fmpz_clear(s);
|
||||
fmpz_clear(t);
|
||||
}
|
||||
|
||||
static void fmpz_poly_factor_mignotte(fmpz_t B, const fmpz_poly_t f)
|
||||
{
|
||||
_fmpz_poly_factor_mignotte(B, f->coeffs, f->length - 1);
|
||||
}
|
||||
|
||||
void _fmpz_poly_factor_zassenhaus(fmpz_poly_factor_t final_fac,
|
||||
slong exp, const fmpz_poly_t f, slong cutoff)
|
||||
{
|
||||
const slong lenF = f->length;
|
||||
|
||||
#if TRACE_ZASSENHAUS == 1
|
||||
flint_printf("\n[Zassenhaus]\n");
|
||||
flint_printf("|f = "), fmpz_poly_print(f), flint_printf("\n");
|
||||
#endif
|
||||
|
||||
if (lenF == 2)
|
||||
{
|
||||
fmpz_poly_factor_insert(final_fac, f, exp);
|
||||
}
|
||||
else
|
||||
{
|
||||
slong i;
|
||||
slong r = lenF;
|
||||
mp_limb_t p = 2;
|
||||
nmod_poly_t d, g, t;
|
||||
nmod_poly_factor_t fac;
|
||||
|
||||
nmod_poly_factor_init(fac);
|
||||
nmod_poly_init_preinv(t, 1, 0);
|
||||
nmod_poly_init_preinv(d, 1, 0);
|
||||
nmod_poly_init_preinv(g, 1, 0);
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
for ( ; ; p = n_nextprime(p, 0))
|
||||
{
|
||||
nmod_t mod;
|
||||
|
||||
nmod_init(&mod, p);
|
||||
d->mod = mod;
|
||||
g->mod = mod;
|
||||
t->mod = mod;
|
||||
|
||||
fmpz_poly_get_nmod_poly(t, f);
|
||||
if (t->length == lenF)
|
||||
{
|
||||
nmod_poly_derivative(d, t);
|
||||
nmod_poly_gcd(g, t, d);
|
||||
|
||||
if (nmod_poly_is_one(g))
|
||||
{
|
||||
nmod_poly_factor_t temp_fac;
|
||||
|
||||
nmod_poly_factor_init(temp_fac);
|
||||
nmod_poly_factor(temp_fac, t);
|
||||
|
||||
if (temp_fac->num <= r)
|
||||
{
|
||||
r = temp_fac->num;
|
||||
nmod_poly_factor_set(fac, temp_fac);
|
||||
}
|
||||
nmod_poly_factor_clear(temp_fac);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
p = n_nextprime(p, 0);
|
||||
}
|
||||
nmod_poly_clear(d);
|
||||
nmod_poly_clear(g);
|
||||
nmod_poly_clear(t);
|
||||
|
||||
if (r > cutoff)
|
||||
{
|
||||
flint_printf("Exception (fmpz_poly_factor_zassenhaus). r > cutoff.\n");
|
||||
nmod_poly_factor_clear(fac);
|
||||
abort();
|
||||
}
|
||||
else if (r == 1)
|
||||
{
|
||||
fmpz_poly_factor_insert(final_fac, f, exp);
|
||||
}
|
||||
else
|
||||
{
|
||||
slong a;
|
||||
fmpz_poly_factor_t lifted_fac;
|
||||
fmpz_poly_factor_init(lifted_fac);
|
||||
|
||||
p = (fac->p + 0)->mod.n;
|
||||
{
|
||||
fmpz_t B;
|
||||
fmpz_init(B);
|
||||
fmpz_poly_factor_mignotte(B, f);
|
||||
fmpz_mul_ui(B, B, 2);
|
||||
fmpz_add_ui(B, B, 1);
|
||||
a = fmpz_clog_ui(B, p);
|
||||
fmpz_clear(B);
|
||||
}
|
||||
|
||||
/* TODO: Check if use_Hoeij_Novocin and try smaller a. */
|
||||
fmpz_poly_hensel_lift_once(lifted_fac, f, fac, a);
|
||||
|
||||
#if TRACE_ZASSENHAUS == 1
|
||||
flint_printf("|p = %wd, a = %wd\n", p, a);
|
||||
flint_printf("|Pre hensel lift factorisation (nmod_poly):\n");
|
||||
nmod_poly_factor_print(fac);
|
||||
flint_printf("|Post hensel lift factorisation (fmpz_poly):\n");
|
||||
fmpz_poly_factor_print(lifted_fac);
|
||||
#endif
|
||||
|
||||
/* Recombination */
|
||||
{
|
||||
fmpz_t P;
|
||||
fmpz_init(P);
|
||||
fmpz_set_ui(P, p);
|
||||
fmpz_pow_ui(P, P, a);
|
||||
|
||||
fmpz_poly_factor_zassenhaus_recombination(final_fac, lifted_fac, f, P, exp);
|
||||
|
||||
fmpz_clear(P);
|
||||
}
|
||||
|
||||
fmpz_poly_factor_clear(lifted_fac);
|
||||
}
|
||||
nmod_poly_factor_clear(fac);
|
||||
}
|
||||
}
|
||||
|
||||
void fmpz_poly_factor_zassenhaus(fmpz_poly_factor_t fac, const fmpz_poly_t G)
|
||||
{
|
||||
const slong lenG = G->length;
|
||||
fmpz_poly_t g;
|
||||
|
||||
if (lenG == 0)
|
||||
{
|
||||
fmpz_set_ui(&fac->c, 0);
|
||||
return;
|
||||
}
|
||||
if (lenG == 1)
|
||||
{
|
||||
fmpz_set(&fac->c, G->coeffs);
|
||||
return;
|
||||
}
|
||||
|
||||
fmpz_poly_init(g);
|
||||
|
||||
if (lenG == 2)
|
||||
{
|
||||
fmpz_poly_content(&fac->c, G);
|
||||
if (fmpz_sgn(fmpz_poly_lead(G)) < 0)
|
||||
fmpz_neg(&fac->c, &fac->c);
|
||||
fmpz_poly_scalar_divexact_fmpz(g, G, &fac->c);
|
||||
fmpz_poly_factor_insert(fac, g, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
slong j, k;
|
||||
fmpz_poly_factor_t sq_fr_fac;
|
||||
|
||||
/* Does a presearch for a factor of form x^k */
|
||||
for (k = 0; fmpz_is_zero(G->coeffs + k); k++) ;
|
||||
|
||||
if (k != 0)
|
||||
{
|
||||
fmpz_poly_t t;
|
||||
|
||||
fmpz_poly_init(t);
|
||||
fmpz_poly_set_coeff_ui(t, 1, 1);
|
||||
fmpz_poly_factor_insert(fac, t, k);
|
||||
fmpz_poly_clear(t);
|
||||
}
|
||||
|
||||
fmpz_poly_shift_right(g, G, k);
|
||||
|
||||
/* Could make other tests for x-1 or simple things
|
||||
maybe take advantage of the composition algorithm */
|
||||
fmpz_poly_factor_init(sq_fr_fac);
|
||||
fmpz_poly_factor_squarefree(sq_fr_fac, g);
|
||||
|
||||
fmpz_set(&fac->c, &sq_fr_fac->c);
|
||||
|
||||
/* Factor each square-free part */
|
||||
for (j = 0; j < sq_fr_fac->num; j++)
|
||||
_fmpz_poly_factor_zassenhaus(fac, sq_fr_fac->exp[j], sq_fr_fac->p + j, 10);
|
||||
|
||||
fmpz_poly_factor_clear(sq_fr_fac);
|
||||
}
|
||||
fmpz_poly_clear(g);
|
||||
}
|
||||
|
||||
#undef TRACE_ZASSENHAUS
|
||||
|
||||
146
external/flint-2.4.3/fmpz_poly_factor/factor_zassenhaus_recombination.c
vendored
Normal file
146
external/flint-2.4.3/fmpz_poly_factor/factor_zassenhaus_recombination.c
vendored
Normal file
@@ -0,0 +1,146 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 William Hart
|
||||
Copyright (C) 2011 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "fmpz_poly.h"
|
||||
|
||||
#define TRACE 0
|
||||
|
||||
void fmpz_poly_factor_zassenhaus_recombination(fmpz_poly_factor_t final_fac,
|
||||
const fmpz_poly_factor_t lifted_fac,
|
||||
const fmpz_poly_t F, const fmpz_t P, slong exp)
|
||||
{
|
||||
const slong r = lifted_fac->num;
|
||||
|
||||
slong k, *used_arr, *sub_arr;
|
||||
fmpz_poly_t f, Q, R, tryme;
|
||||
fmpz *leadF;
|
||||
|
||||
used_arr = flint_calloc(2 * r, sizeof(slong));
|
||||
sub_arr = used_arr + r;
|
||||
|
||||
fmpz_poly_init(f);
|
||||
fmpz_poly_init(Q);
|
||||
fmpz_poly_init(R);
|
||||
fmpz_poly_init(tryme);
|
||||
fmpz_poly_set(f, F);
|
||||
|
||||
#if TRACE == 1
|
||||
fmpz_poly_factor_print(lifted_fac); flint_printf(" lifted_fac\n");
|
||||
#endif
|
||||
|
||||
leadF = fmpz_poly_lead(F);
|
||||
|
||||
for (k = 1; k < r; k++)
|
||||
{
|
||||
slong count = 0, indx = k - 1, l;
|
||||
|
||||
for(l = 0; l < k; l++)
|
||||
sub_arr[l] = l;
|
||||
|
||||
sub_arr[indx]--;
|
||||
while ((indx >= 0))
|
||||
{
|
||||
sub_arr[indx] = sub_arr[indx] + 1;
|
||||
|
||||
for (l = indx + 1; l < k; l++)
|
||||
sub_arr[l] = sub_arr[l - 1] + 1;
|
||||
|
||||
if (sub_arr[k - 1] > r - 1)
|
||||
indx--;
|
||||
else
|
||||
{
|
||||
for(l = 0; l < k; l++)
|
||||
{
|
||||
if (used_arr[sub_arr[l]] == 1)
|
||||
break;
|
||||
}
|
||||
|
||||
/* Need to involve leadF, perhaps set coeff 0 to leadF and do
|
||||
leadF * rest and check if under M_bits... here I'm using a
|
||||
trial division... */
|
||||
fmpz_poly_set_fmpz(tryme, leadF);
|
||||
|
||||
for(l = 0; l < k; l++)
|
||||
fmpz_poly_mul(tryme, tryme, lifted_fac->p + (sub_arr[l]));
|
||||
|
||||
fmpz_poly_scalar_smod_fmpz(tryme, tryme, P);
|
||||
fmpz_poly_primitive_part(tryme, tryme);
|
||||
fmpz_poly_divrem(Q, R, f, tryme);
|
||||
|
||||
#if TRACE == 1
|
||||
fmpz_poly_print(tryme); flint_printf(" is tryme\n");
|
||||
fmpz_poly_print(R); flint_printf(" is R\n");
|
||||
#endif
|
||||
|
||||
if (fmpz_poly_is_zero(R))
|
||||
{
|
||||
fmpz_poly_factor_insert(final_fac, tryme, exp);
|
||||
|
||||
for(l = 0; l < k; l++)
|
||||
{
|
||||
used_arr[sub_arr[l]] = 1;
|
||||
count++;
|
||||
}
|
||||
|
||||
fmpz_poly_set(f, Q);
|
||||
leadF = fmpz_poly_lead(f);
|
||||
/* If r - count = k then the rest are irreducible.
|
||||
TODO: Add a test for that case */
|
||||
}
|
||||
|
||||
indx = k - 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* This is where we switch to the next loop for k. So we will have
|
||||
found all factors using <= k local factors. We should/could update
|
||||
f to be the rest divided away (or multiply the remaining), could
|
||||
also adjust r. It is the number of remaining factors so if you
|
||||
update then test if r = k or k+1 in which case the remaining f is
|
||||
irreducible. */
|
||||
}
|
||||
|
||||
{
|
||||
slong test = 0;
|
||||
|
||||
for (k = 0; k < r; k++)
|
||||
test = test + used_arr[k];
|
||||
|
||||
if (test == 0)
|
||||
fmpz_poly_factor_insert(final_fac, f, exp);
|
||||
}
|
||||
|
||||
fmpz_poly_clear(f);
|
||||
fmpz_poly_clear(tryme);
|
||||
fmpz_poly_clear(Q);
|
||||
fmpz_poly_clear(R);
|
||||
flint_free(used_arr);
|
||||
}
|
||||
|
||||
#undef TRACE
|
||||
|
||||
39
external/flint-2.4.3/fmpz_poly_factor/fit_length.c
vendored
Normal file
39
external/flint-2.4.3/fmpz_poly_factor/fit_length.c
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 Sebastian Pancratz
|
||||
Copyright (C) 2008, 2009 William Hart
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "fmpz_poly.h"
|
||||
|
||||
void fmpz_poly_factor_fit_length(fmpz_poly_factor_t fac, slong len)
|
||||
{
|
||||
if (len > fac->alloc)
|
||||
{
|
||||
/* At least double number of allocated coeffs */
|
||||
if (len < 2 * fac->alloc)
|
||||
len = 2 * fac->alloc;
|
||||
fmpz_poly_factor_realloc(fac, len);
|
||||
}
|
||||
}
|
||||
|
||||
67
external/flint-2.4.3/fmpz_poly_factor/init.c
vendored
Normal file
67
external/flint-2.4.3/fmpz_poly_factor/init.c
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <gmp.h>
|
||||
#include <stdlib.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_poly.h"
|
||||
|
||||
void fmpz_poly_factor_init(fmpz_poly_factor_t fac)
|
||||
{
|
||||
fmpz_init_set_ui(&(fac->c), 1);
|
||||
fac->p = NULL;
|
||||
fac->exp = NULL;
|
||||
fac->num = 0;
|
||||
fac->alloc = 0;
|
||||
}
|
||||
|
||||
void fmpz_poly_factor_init2(fmpz_poly_factor_t fac, slong alloc)
|
||||
{
|
||||
fmpz_init_set_ui(&(fac->c), 1);
|
||||
|
||||
if (alloc)
|
||||
{
|
||||
slong i;
|
||||
|
||||
fac->p = flint_malloc(alloc * sizeof(fmpz_poly_struct));
|
||||
fac->exp = flint_malloc(alloc * sizeof(slong));
|
||||
|
||||
for (i = 0; i < alloc; i++)
|
||||
{
|
||||
fmpz_poly_init(fac->p + i);
|
||||
fac->exp[i] = WORD(0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fac->p = NULL;
|
||||
fac->exp = NULL;
|
||||
}
|
||||
|
||||
fac->num = 0;
|
||||
fac->alloc = alloc;
|
||||
}
|
||||
|
||||
54
external/flint-2.4.3/fmpz_poly_factor/insert.c
vendored
Normal file
54
external/flint-2.4.3/fmpz_poly_factor/insert.c
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
/*=============================================================================
|
||||
|
||||
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) 2007 David Howden
|
||||
Copyright (C) 2007, 2008, 2009, 2010 William Hart
|
||||
Copyright (C) 2008 Richard Howell-Peak
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
Copyright (C) 2011 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz_poly.h"
|
||||
|
||||
void
|
||||
fmpz_poly_factor_insert(fmpz_poly_factor_t fac, const fmpz_poly_t p, slong exp)
|
||||
{
|
||||
slong i;
|
||||
|
||||
for (i = 0; i < fac->num; i++)
|
||||
{
|
||||
if (fmpz_poly_equal(p, fac->p + i))
|
||||
{
|
||||
fac->exp[i] += exp;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
fmpz_poly_factor_fit_length(fac, i + 1);
|
||||
|
||||
fmpz_poly_set(fac->p + i, p);
|
||||
fac->exp[i] = exp;
|
||||
fac->num = i + 1;
|
||||
}
|
||||
45
external/flint-2.4.3/fmpz_poly_factor/print.c
vendored
Normal file
45
external/flint-2.4.3/fmpz_poly_factor/print.c
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
/*=============================================================================
|
||||
|
||||
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) 2007 David Howden
|
||||
Copyright (C) 2007, 2008, 2009, 2010 William Hart
|
||||
Copyright (C) 2008 Richard Howell-Peak
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
Copyright (C) 2011 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz_poly.h"
|
||||
|
||||
void fmpz_poly_factor_print(const fmpz_poly_factor_t fac)
|
||||
{
|
||||
slong i;
|
||||
|
||||
fmpz_print(&(fac->c));
|
||||
flint_printf("\n");
|
||||
for (i = 0; i < fac->num; i++)
|
||||
{
|
||||
fmpz_poly_print(fac->p + i);
|
||||
flint_printf(" ^ %wd\n", fac->exp[i]);
|
||||
}
|
||||
}
|
||||
80
external/flint-2.4.3/fmpz_poly_factor/realloc.c
vendored
Normal file
80
external/flint-2.4.3/fmpz_poly_factor/realloc.c
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <gmp.h>
|
||||
#include <stdlib.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_poly.h"
|
||||
|
||||
void fmpz_poly_factor_realloc(fmpz_poly_factor_t fac, slong alloc)
|
||||
{
|
||||
if (alloc == 0) /* Clear up, reinitialise */
|
||||
{
|
||||
fmpz_poly_factor_clear(fac);
|
||||
fmpz_poly_factor_init(fac);
|
||||
}
|
||||
else if (fac->alloc) /* Realloc */
|
||||
{
|
||||
if (fac->alloc > alloc)
|
||||
{
|
||||
slong i;
|
||||
|
||||
for (i = alloc; i < fac->num; i++)
|
||||
fmpz_poly_clear(fac->p + i);
|
||||
|
||||
fac->p = flint_realloc(fac->p, alloc * sizeof(fmpz_poly_struct));
|
||||
fac->exp = flint_realloc(fac->exp, alloc * sizeof(slong));
|
||||
fac->alloc = alloc;
|
||||
}
|
||||
else if (fac->alloc < alloc)
|
||||
{
|
||||
slong i;
|
||||
|
||||
fac->p = flint_realloc(fac->p, alloc * sizeof(fmpz_poly_struct));
|
||||
fac->exp = flint_realloc(fac->exp, alloc * sizeof(slong));
|
||||
|
||||
for (i = fac->alloc; i < alloc; i++)
|
||||
{
|
||||
fmpz_poly_init(fac->p + i);
|
||||
fac->exp[i] = WORD(0);
|
||||
}
|
||||
fac->alloc = alloc;
|
||||
}
|
||||
}
|
||||
else /* Nothing allocated already so do it now */
|
||||
{
|
||||
slong i;
|
||||
|
||||
fac->p = flint_malloc(alloc * sizeof(fmpz_poly_struct));
|
||||
fac->exp = flint_calloc(alloc, sizeof(slong));
|
||||
|
||||
for (i = 0; i < alloc; i++)
|
||||
fmpz_poly_init(fac->p + i);
|
||||
fac->num = 0;
|
||||
fac->alloc = alloc;
|
||||
}
|
||||
}
|
||||
|
||||
58
external/flint-2.4.3/fmpz_poly_factor/set.c
vendored
Normal file
58
external/flint-2.4.3/fmpz_poly_factor/set.c
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "flint.h"
|
||||
#include "fmpz_poly.h"
|
||||
|
||||
void fmpz_poly_factor_set(fmpz_poly_factor_t res, const fmpz_poly_factor_t fac)
|
||||
{
|
||||
if (res != fac)
|
||||
{
|
||||
if (fac->num == 0)
|
||||
{
|
||||
fmpz_poly_factor_clear(res);
|
||||
fmpz_poly_factor_init(res);
|
||||
}
|
||||
else
|
||||
{
|
||||
slong i;
|
||||
|
||||
fmpz_poly_factor_fit_length(res, fac->num);
|
||||
fmpz_set(&(res->c), &(fac->c));
|
||||
for (i = 0; i < fac->num; i++)
|
||||
{
|
||||
fmpz_poly_set(res->p + i, fac->p + i);
|
||||
res->exp[i] = fac->exp[i];
|
||||
}
|
||||
for ( ; i < res->num; i++)
|
||||
{
|
||||
fmpz_poly_zero(res->p + i);
|
||||
res->exp[i] = 0;
|
||||
}
|
||||
res->num = fac->num;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
114
external/flint-2.4.3/fmpz_poly_factor/test/t-factor_squarefree.c
vendored
Normal file
114
external/flint-2.4.3/fmpz_poly_factor/test/t-factor_squarefree.c
vendored
Normal file
@@ -0,0 +1,114 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_poly.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("squarefree....");
|
||||
fflush(stdout);
|
||||
|
||||
|
||||
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
fmpz_poly_t f, g[10], h, t;
|
||||
fmpz_poly_factor_t fac;
|
||||
slong k, l, n = n_randint(state, 10) + 1;
|
||||
|
||||
fmpz_poly_init(f);
|
||||
fmpz_poly_init(h);
|
||||
fmpz_poly_init(t);
|
||||
fmpz_poly_factor_init(fac);
|
||||
|
||||
fmpz_poly_one(f);
|
||||
for (k = 0; k < n; k++)
|
||||
{
|
||||
fmpz_poly_init(g[k]);
|
||||
fmpz_poly_randtest_not_zero(g[k], state, n_randint(state, 40)+1, 20);
|
||||
l = n_randint(state, 2) + 1;
|
||||
while (l--)
|
||||
fmpz_poly_mul(f, f, g[k]);
|
||||
}
|
||||
fmpz_poly_factor_squarefree(fac, f);
|
||||
|
||||
/* Squarefree? */
|
||||
result = 1;
|
||||
for (k = 0; k < fac->num && result; k++)
|
||||
{
|
||||
fmpz_poly_derivative(h, fac->p + k);
|
||||
fmpz_poly_gcd(t, h, fac->p + k);
|
||||
result &= fmpz_poly_is_one(t);
|
||||
}
|
||||
|
||||
/* Product? */
|
||||
fmpz_poly_set_fmpz(h, &(fac->c));
|
||||
for (k = 0; k < fac->num; k++)
|
||||
{
|
||||
if (fac->exp[k] == 1)
|
||||
fmpz_poly_mul(h, h, fac->p + k);
|
||||
else
|
||||
{
|
||||
fmpz_poly_pow(t, fac->p + k, fac->exp[k]);
|
||||
fmpz_poly_mul(h, h, t);
|
||||
}
|
||||
}
|
||||
|
||||
result &= fmpz_poly_equal(f, h);
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("f = "), fmpz_poly_print_pretty(f, "x"), flint_printf("\n\n");
|
||||
for (k = 0; k < n; k++)
|
||||
{
|
||||
flint_printf("g[%wd] = ", k), fmpz_poly_print_pretty(g[k], "x"), flint_printf("\n\n");
|
||||
}
|
||||
flint_printf("h = "), fmpz_poly_print_pretty(h, "x"), flint_printf("\n\n");
|
||||
fmpz_poly_factor_print(fac);
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_poly_clear(f);
|
||||
for (k = 0; k < n; k++)
|
||||
fmpz_poly_clear(g[k]);
|
||||
fmpz_poly_clear(h);
|
||||
fmpz_poly_clear(t);
|
||||
fmpz_poly_factor_clear(fac);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
102
external/flint-2.4.3/fmpz_poly_factor/test/t-factor_zassenhaus.c
vendored
Normal file
102
external/flint-2.4.3/fmpz_poly_factor/test/t-factor_zassenhaus.c
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
/*=============================================================================
|
||||
|
||||
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) 2010 Andy Novocin
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz_poly.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("zassenhaus....");
|
||||
fflush(stdout);
|
||||
|
||||
|
||||
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
fmpz_t c;
|
||||
fmpz_poly_t f, g, h, t;
|
||||
fmpz_poly_factor_t fac;
|
||||
slong j, n = n_randint(state, 5);
|
||||
|
||||
fmpz_init(c);
|
||||
fmpz_poly_init(f);
|
||||
fmpz_poly_init(g);
|
||||
fmpz_poly_init(h);
|
||||
fmpz_poly_init(t);
|
||||
fmpz_poly_factor_init(fac);
|
||||
|
||||
fmpz_randtest_not_zero(c, state, n_randint(state, 10) + 1);
|
||||
fmpz_poly_set_fmpz(f, c);
|
||||
|
||||
for (j = 0; j < n; j++)
|
||||
{
|
||||
fmpz_poly_randtest(g, state, n_randint(state, 5) + 2, n_randint(state, 40));
|
||||
fmpz_poly_mul(f, f, g);
|
||||
}
|
||||
/* fmpz_poly_set_str(f, "6 0 -1 0 0 0 1");*/
|
||||
|
||||
fmpz_poly_factor_zassenhaus(fac, f);
|
||||
|
||||
fmpz_poly_set_fmpz(h, &fac->c);
|
||||
for (j = 0; j < fac->num; j++)
|
||||
{
|
||||
if (fac->exp[j] == 1)
|
||||
fmpz_poly_mul(h, h, fac->p + j);
|
||||
else
|
||||
{
|
||||
fmpz_poly_pow(t, fac->p + j, fac->exp[j]);
|
||||
fmpz_poly_mul(h, h, t);
|
||||
}
|
||||
}
|
||||
|
||||
result = fmpz_poly_equal(f, h);
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("f = "), fmpz_poly_print(f), flint_printf("\n\n");
|
||||
flint_printf("h = "), fmpz_poly_print(h), flint_printf("\n\n");
|
||||
flint_printf("fac = "), fmpz_poly_factor_print(fac), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(c);
|
||||
fmpz_poly_clear(f);
|
||||
fmpz_poly_clear(g);
|
||||
fmpz_poly_clear(h);
|
||||
fmpz_poly_clear(t);
|
||||
fmpz_poly_factor_clear(fac);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user