ALL: Add flint

This commit is contained in:
2014-05-19 00:03:37 +02:00
parent a15ef46ea6
commit d51d8e3652
3752 changed files with 446416 additions and 0 deletions

View File

@@ -0,0 +1,468 @@
/*=============================================================================
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
=============================================================================*/
/******************************************************************************
NTL-interface.cpp: Functions for conversion between NTL and FLINT format
Copyright (C) 2007 William Hart
Copyright (C) 2011 Sebastian Pancratz
Copyright (C) 2013 Mike Hansen
******************************************************************************/
#include <cstdio>
#include <NTL/ZZ.h>
#include <NTL/ZZX.h>
#include <NTL/mat_ZZ.h>
#include <NTL/lip.h>
#include <NTL/ctools.h>
#include <NTL/g_lip.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_poly.h"
#include "NTL-interface.h"
#define ZZ_SIZE(p) (((slong *) (p))[1])
#define ZZ_DATA(p) ((mp_limb_t *) (((slong *) (p)) + 2))
NTL_CLIENT
static void fmpz_set_limbs(fmpz_t f, mp_srcptr x, mp_size_t limbs)
{
if (limbs == 0)
fmpz_zero(f);
else if (limbs == 1)
fmpz_set_ui(f, x[0]);
else
{
__mpz_struct *mpz_ptr = _fmpz_promote(f);
mpz_import(mpz_ptr, limbs, -1, sizeof(mp_limb_t), 0, 0, x);
}
}
void fmpz_set_ZZ(fmpz_t rop, const ZZ& op)
{
const _ntl_gbigint x = op.rep;
if (!x)
fmpz_zero(rop);
else
{
const mp_size_t lw = op.size();
const mp_limb_t *xp = ZZ_DATA(x);
fmpz_set_limbs(rop, xp, lw);
if (op < WORD(0))
fmpz_neg(rop, rop);
}
}
void fmpz_set_ZZ_p(fmpz_t rop, const ZZ_p& op)
{
fmpz_set_ZZ(rop, rep(op));
}
void fmpz_set_zz_p(fmpz_t rop, const zz_p& op)
{
fmpz_set_si(rop, rep(op));
}
void fmpz_get_ZZ(ZZ& rop, const fmpz_t op)
{
mp_limb_t *xp;
_ntl_gbigint *x = &rop.rep;
slong lw = fmpz_size(op);
fmpz c = *op;
if (lw == 0)
{
if (*x) ZZ_SIZE(*x) = 0;
return;
}
_ntl_gsetlength(x, lw);
xp = ZZ_DATA(*x);
if (COEFF_IS_MPZ(c))
{
__mpz_struct * m = COEFF_TO_PTR(c);
mpn_copyi(xp, m->_mp_d, lw);
} else
{
if (c < WORD(0))
xp[0] = -c;
else
xp[0] = c;
}
if (fmpz_sgn(op) < 0) ZZ_SIZE(*x) = -lw;
else ZZ_SIZE(*x) = lw;
}
void fmpz_get_ZZ_p(ZZ_p& rop, const fmpz_t op)
{
ZZ a;
fmpz_get_ZZ(a, op);
conv(rop, a);
}
void fmpz_get_zz_p(zz_p& rop, const fmpz_t op)
{
conv(rop, fmpz_get_si(op));
}
void fmpz_poly_get_ZZX(ZZX& rop, const fmpz_poly_t op)
{
const slong len = op->length;
if (len == 0)
{
rop = 0;
}
else
{
slong i;
ZZ *ap;
rop.rep.SetLength(len);
for (i = 0, ap = rop.rep.elts(); i < len; i++, ap++)
{
fmpz_get_ZZ(*ap, op->coeffs + i);
}
}
}
void fmpz_poly_set_ZZX(fmpz_poly_t rop, const ZZX& op)
{
const slong len = deg(op) + 1;
if (len == 0)
{
fmpz_poly_zero(rop);
}
else
{
slong i;
const ZZ *ap;
fmpz_poly_fit_length(rop, len);
_fmpz_poly_set_length(rop, len);
for (i = 0, ap = op.rep.elts(); i < len; i++, ap++)
{
fmpz_set_ZZ(rop->coeffs + i, *ap);
}
}
}
void fmpz_mod_poly_get_ZZ_pX(ZZ_pX& rop, const fmpz_mod_poly_t op)
{
const slong len = op->length;
if (len == 0)
{
rop = 0;
}
else
{
slong i;
ZZ_p *ap;
rop.rep.SetLength(len);
for (i = 0, ap = rop.rep.elts(); i < len; i++, ap++)
{
fmpz_get_ZZ_p(*ap, op->coeffs + i);
}
}
}
void fmpz_mod_poly_set_ZZ_pX(fmpz_mod_poly_t rop, const ZZ_pX& op)
{
const slong len = deg(op) + 1;
if (len == 0)
{
fmpz_mod_poly_zero(rop);
}
else
{
slong i;
const ZZ_p *ap;
fmpz_mod_poly_fit_length(rop, len);
_fmpz_mod_poly_set_length(rop, len);
for (i = 0, ap = op.rep.elts(); i < len; i++, ap++)
{
fmpz_set_ZZ_p(rop->coeffs + i, *ap);
}
}
}
void fmpz_mod_poly_get_zz_pX(zz_pX& rop, const fmpz_mod_poly_t op)
{
const slong len = op->length;
if (len == 0)
{
rop = 0;
}
else
{
slong i;
zz_p *ap;
rop.rep.SetLength(len);
for (i = 0, ap = rop.rep.elts(); i < len; i++, ap++)
{
fmpz_get_zz_p(*ap, op->coeffs + i);
}
}
}
void fmpz_mod_poly_set_zz_pX(fmpz_mod_poly_t rop, const zz_pX& op)
{
const slong len = deg(op) + 1;
if (len == 0)
{
fmpz_mod_poly_zero(rop);
}
else
{
slong i;
const zz_p *ap;
fmpz_mod_poly_fit_length(rop, len);
_fmpz_mod_poly_set_length(rop, len);
for (i = 0, ap = op.rep.elts(); i < len; i++, ap++)
{
fmpz_set_zz_p(rop->coeffs + i, *ap);
}
}
}
void fq_get_ZZ_pE(ZZ_pE& rop, const fq_t op, const fq_ctx_t ctx)
{
ZZ_pX p;
const slong len = op->length;
if (len == 0)
{
rop = 0;
}
else
{
slong i;
ZZ_p *ap;
p.rep.SetLength(len);
for (i = 0, ap = p.rep.elts(); i < len; i++, ap++)
{
fmpz_get_ZZ_p(*ap, op->coeffs + i);
}
conv(rop, p);
}
}
void fq_set_ZZ_pE(fq_t rop, const ZZ_pE& op, const fq_ctx_t ctx)
{
const slong len = deg(rep(op)) + 1;
if (len == 0)
{
fq_zero(rop, ctx);
}
else
{
slong i;
const ZZ_p *ap;
fmpz_poly_fit_length(rop, len);
_fmpz_poly_set_length(rop, len);
for (i = 0, ap = rep(op).rep.elts(); i < len; i++, ap++)
{
fmpz_set_ZZ_p(rop->coeffs + i, *ap);
}
_fmpz_poly_normalise(rop);
}
}
void fq_poly_get_ZZ_pEX(ZZ_pEX& rop, const fq_poly_t op, const fq_ctx_t ctx)
{
const slong len = op->length;
if (len == 0)
{
rop = 0;
}
else
{
slong i;
ZZ_pE *ap;
rop.rep.SetLength(len);
for (i = 0, ap = rop.rep.elts(); i < len; i++, ap++)
{
fq_get_ZZ_pE(*ap, op->coeffs + i, ctx);
}
}
}
void fq_poly_set_ZZ_pEX(fq_poly_t rop, const ZZ_pEX& op, const fq_ctx_t ctx)
{
const slong len = deg(op) + 1;
if (len == 0)
{
fq_poly_zero(rop, ctx);
}
else
{
slong i;
const ZZ_pE *ap;
fq_poly_fit_length(rop, len, ctx);
_fq_poly_set_length(rop, len, ctx);
for (i = 0, ap = op.rep.elts(); i < len; i++, ap++)
{
fq_set_ZZ_pE(rop->coeffs + i, *ap, ctx);
}
_fq_poly_normalise(rop, ctx);
}
}
/* ----------------------------------------- */
void fq_get_zz_pE(zz_pE& rop, const fq_t op, const fq_ctx_t ctx)
{
zz_pX p;
const slong len = op->length;
if (len == 0)
{
rop = 0;
}
else
{
slong i;
zz_p *ap;
p.rep.SetLength(len);
for (i = 0, ap = p.rep.elts(); i < len; i++, ap++)
{
fmpz_get_zz_p(*ap, op->coeffs + i);
}
conv(rop, p);
}
}
void fq_set_zz_pE(fq_t rop, const zz_pE& op, const fq_ctx_t ctx)
{
const slong len = deg(rep(op)) + 1;
if (len == 0)
{
fq_zero(rop, ctx);
}
else
{
slong i;
const zz_p *ap;
fmpz_poly_fit_length(rop, len);
_fmpz_poly_set_length(rop, len);
for (i = 0, ap = rep(op).rep.elts(); i < len; i++, ap++)
{
fmpz_set_zz_p(rop->coeffs + i, *ap);
}
_fmpz_poly_normalise(rop);
}
}
void fq_poly_get_zz_pEX(zz_pEX& rop, const fq_poly_t op, const fq_ctx_t ctx)
{
const slong len = op->length;
if (len == 0)
{
rop = 0;
}
else
{
slong i;
zz_pE *ap;
rop.rep.SetLength(len);
for (i = 0, ap = rop.rep.elts(); i < len; i++, ap++)
{
fq_get_zz_pE(*ap, op->coeffs + i, ctx);
}
}
}
void fq_poly_set_zz_pEX(fq_poly_t rop, const zz_pEX& op, const fq_ctx_t ctx)
{
const slong len = deg(op) + 1;
if (len == 0)
{
fq_poly_zero(rop, ctx);
}
else
{
slong i;
const zz_pE *ap;
fq_poly_fit_length(rop, len, ctx);
_fq_poly_set_length(rop, len, ctx);
for (i = 0, ap = op.rep.elts(); i < len; i++, ap++)
{
fq_set_zz_pE(rop->coeffs + i, *ap, ctx);
}
_fq_poly_normalise(rop, ctx);
}
}
#undef ZZ_SIZE
#undef ZZ_DATA

View File

@@ -0,0 +1,117 @@
/*=============================================================================
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) 2009 William Hart
Copyright (C) 2011 Sebastian Pancratz
Copyright (C) 2013 Mike Hansen
******************************************************************************/
*******************************************************************************
NTL Interface
The NTL interface allows conversion between NTL objects and FLINT objects
and vice versa. The interface is built using C$++$ and is not built as a
part of the FLINT library library by default. To build the NTL interface
one must specify the location of NTL with the \code{--with-ntl=path} option
to configure. NTL version 5.5.2 or later is required.
*******************************************************************************
void fmpz_set_ZZ(fmpz_t rop, const ZZ& op)
Converts an NTL \code{ZZ} to an \code{fmpz_t}.
Assumes the \code{fmpz_t} has already been allocated to have
sufficient space.
void fmpz_get_ZZ(ZZ& rop, const fmpz_t op)
Converts an \code{fmpz_t} to an NTL \code{ZZ}. Allocation is
automatically handled.
void fmpz_set_ZZ_p(fmpz_t rop, const ZZ_p& op)
Converts an NTL \code{ZZ_p} to an \code{fmpz_t}.
Assumes the \code{fmpz_t} has already been allocated to have
sufficient space.
void fmpz_get_ZZ_p(ZZ_p& rop, const fmpz_t op)
Converts an \code{fmpz_t} to an NTL \code{ZZ_p}. Allocation is
automatically handled. Requires that \code{ZZ_p::init()} has
already been called.
void fmpz_poly_get_ZZX(ZZX& rop, const fmpz_poly_t op)
Converts an \code{fmpz_poly_t} to an NTL \code{ZZX}.
void fmpz_poly_set_ZZX(fmpz_poly_t rop, const ZZX& op)
Converts an NTL \code{ZZX} to an \code{fmpz_poly_t}.
void fmpz_mod_poly_get_ZZ_pX(ZZ_pX& rop, const fmpz_mod_poly_t op)
Converts an \code{fmpz_mod_poly_t} to an NTL
\code{ZZ_pX}. Requires that \code{ZZ_p::init()} has already been
called.
void fmpz_mod_poly_set_ZZ_pX(fmpz_mod_poly_t rop, const ZZ_pX& op)
Converts an NTL \code{ZZ_pX} to an \code{fmpz_mod_poly_t}.
void fq_get_ZZ_pE(ZZ_pE& rop, const fq_t op, const fq_ctx_t ctx)
Converts an \code{fq_t} to an NTL \code{ZZ_pE}. Requires that
\code{ZZ_pE::init()} has already been called.
void fq_set_ZZ_pE(fq_t rop, const ZZ_pE& op, const fq_ctx_t ctx)
Converts and NTL \code{ZZ_pE} to an \code{fq_t}.
void fq_poly_get_ZZ_pEX(ZZ_pEX& rop, const fq_poly_t op, const fq_ctx_t ctx)
Converts an \code{fq_poly_t} to an NTL \code{ZZ_pEX}. Requires
that \code{ZZ_pE::init()} has already been called.
void fq_poly_set_ZZ_pE(fq_poly_t rop, const ZZ_pE& op, const fq_ctx_t ctx)
Converts and NTL \code{ZZ_pEX} to an \code{fq_poly_t}.
void fq_get_zz_pE(zz_pE& rop, const fq_t op, const fq_ctx_t ctx)
Converts an \code{fq_t} to an NTL \code{zz_pE}. Requires that
\code{zz_pE::init()} has already been called.
void fq_set_zz_pE(fq_t rop, const zz_pE& op, const fq_ctx_t ctx)
Converts and NTL \code{zz_pE} to an \code{fq_t}.
void fq_poly_get_zz_pEX(zz_pEX& rop, const fq_poly_t op, const fq_ctx_t ctx)
Converts an \code{fq_poly_t} to an NTL \code{zz_pEX}. Requires
that \code{zz_pE::init()} has already been called.
void fq_poly_set_zz_pE(fq_poly_t rop, const zz_pE& op, const fq_ctx_t ctx)
Converts and NTL \code{zz_pEX} to an \code{fq_poly_t}.

View File

@@ -0,0 +1,547 @@
/*=============================================================================
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 William Hart
Copyright (C) 2013 Mike Hansen
******************************************************************************/
#include <NTL/ZZ.h>
#include <NTL/ZZX.h>
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_poly.h"
#include "fmpz_mod_poly.h"
#include "ulong_extras.h"
#include "NTL-interface.h"
NTL_CLIENT
int test_ZZ_to_fmpz()
{
int i, result;
mp_bitcnt_t bits, randbits;
fmpz_t int1, int2;
ZZ z;
FLINT_TEST_INIT(state);
flint_printf("ZZ_to_fmpz....");
fflush(stdout);
/* Check conversion */
for (i = 0; i < 10000; i++)
{
bits = n_randint(state, 1000) + 1;
randbits = n_randint(state, bits);
fmpz_init(int1);
fmpz_init(int2);
fmpz_randbits(int1, state, randbits);
fmpz_get_ZZ(z, int1);
fmpz_set_ZZ(int2, z);
result = fmpz_equal(int1, int2);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("int1 = %wd ", *int1); fmpz_print(int1); flint_printf("\n");
flint_printf("int2 = %wd ", *int2); fmpz_print(int2); flint_printf("\n");
return 0;
}
fmpz_clear(int1);
fmpz_clear(int2);
}
FLINT_TEST_CLEANUP(state);
return 1;
}
int test_ZZX_to_fmpz_poly()
{
fmpz_poly_t f_poly1, f_poly2;
slong length;
mp_bitcnt_t bits;
int i, result;
FLINT_TEST_INIT(state);
flint_printf("ZZX_to_fmpz_poly....");
fflush(stdout);
/* Check aliasing of a and c */
for (i = 0; i < 10000; i++)
{
bits = n_randint(state, 1000) + 1;
length = n_randint(state, 1000);
fmpz_poly_init(f_poly1);
fmpz_poly_init(f_poly2);
ZZX ZZX_poly;
fmpz_poly_randtest(f_poly1, state, length, bits);
fmpz_poly_get_ZZX(ZZX_poly, f_poly1);
fmpz_poly_set_ZZX(f_poly2, ZZX_poly);
result = fmpz_poly_equal(f_poly1, f_poly2);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("f_poly1 = "); fmpz_poly_print(f_poly1); flint_printf("\n");
flint_printf("f_poly2 = "); fmpz_poly_print(f_poly2); flint_printf("\n");
return 0;
}
fmpz_poly_clear(f_poly1);
fmpz_poly_clear(f_poly2);
}
FLINT_TEST_CLEANUP(state);
return 1;
}
int test_ZZ_pX_to_fmpz_mod_poly()
{
fmpz_t p;
fmpz_mod_poly_t f_poly1, f_poly2;
slong length;
int i, result;
FLINT_TEST_INIT(state);
flint_printf("ZZ_pX_to_fmpz_mod_poly....");
fflush(stdout);
/* Check aliasing of a and c */
for (i = 0; i < 10000; i++)
{
ZZ_pX ZZ_pX_poly;
ZZ mod;
length = n_randint(state, 1000);
fmpz_init(p);
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
fmpz_add_ui(p, p, 2);
fmpz_get_ZZ(mod, p);
ZZ_p::init(mod);
fmpz_mod_poly_init(f_poly1, p);
fmpz_mod_poly_init(f_poly2, p);
fmpz_mod_poly_randtest(f_poly1, state, length);
fmpz_mod_poly_get_ZZ_pX(ZZ_pX_poly, f_poly1);
fmpz_mod_poly_set_ZZ_pX(f_poly2, ZZ_pX_poly);
result = fmpz_mod_poly_equal(f_poly1, f_poly2);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("f_poly1 = "); fmpz_mod_poly_print(f_poly1); flint_printf("\n");
flint_printf("f_poly2 = "); fmpz_mod_poly_print(f_poly2); flint_printf("\n");
return 0;
}
fmpz_clear(p);
fmpz_mod_poly_clear(f_poly1);
fmpz_mod_poly_clear(f_poly2);
}
FLINT_TEST_CLEANUP(state);
return 1;
}
int test_zz_pX_to_fmpz_mod_poly()
{
fmpz_t p;
fmpz_mod_poly_t f_poly1, f_poly2;
slong length;
int i, result;
FLINT_TEST_INIT(state);
flint_printf("zz_pX_to_fmpz_mod_poly....");
fflush(stdout);
/* Check aliasing of a and c */
for (i = 0; i < 10000; i++)
{
zz_pX zz_pX_poly;
length = n_randint(state, 1000);
fmpz_init(p);
fmpz_set_ui(p, n_randprime(state, 16, 1));
zz_p::init(fmpz_get_si(p));
fmpz_mod_poly_init(f_poly1, p);
fmpz_mod_poly_init(f_poly2, p);
fmpz_mod_poly_randtest(f_poly1, state, length);
fmpz_mod_poly_get_zz_pX(zz_pX_poly, f_poly1);
fmpz_mod_poly_set_zz_pX(f_poly2, zz_pX_poly);
result = fmpz_mod_poly_equal(f_poly1, f_poly2);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("f_poly1 = "); fmpz_mod_poly_print(f_poly1); flint_printf("\n");
flint_printf("f_poly2 = "); fmpz_mod_poly_print(f_poly2); flint_printf("\n");
return 0;
}
fmpz_clear(p);
fmpz_mod_poly_clear(f_poly1);
fmpz_mod_poly_clear(f_poly2);
}
FLINT_TEST_CLEANUP(state);
return 1;
}
int test_ZZ_pE_to_fq()
{
fmpz_t p;
fq_t f1, f2;
int i, result;
fq_ctx_t ctx;
FLINT_TEST_INIT(state);
flint_printf("ZZ_pE_to_fq....");
fflush(stdout);
/* Check aliasing of a and c */
for (i = 0; i < 10000; i++)
{
fmpz_mod_poly_t fmod;
slong d;
ZZ prime;
ZZ_pX mod;
fmpz_init(p);
fmpz_set_ui(p, n_randprime(state, 2 + n_randint(state, 6), 1));
d = n_randint(state, 10) + 1;
fmpz_get_ZZ(prime, p);
ZZ_p::init(prime);
BuildIrred(mod, d);
ZZ_pE::init(mod);
fmpz_mod_poly_init(fmod, p);
fmpz_mod_poly_set_ZZ_pX(fmod, mod);
fq_ctx_init_modulus(ctx, fmod, "a");
ZZ_pE zzpe;
fq_init(f1, ctx);
fq_init(f2, ctx);
fq_randtest(f1, state, ctx);
fq_get_ZZ_pE(zzpe, f1, ctx);
fq_set_ZZ_pE(f2, zzpe, ctx);
result = fq_equal(f1, f2, ctx);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("p = "); fmpz_print(p); flint_printf("\n");
flint_printf("mod = "); fmpz_mod_poly_print_pretty(fmod, "x"); flint_printf("\n");
flint_printf("f1 = "); fq_print_pretty(f1, ctx); flint_printf(" - %wd", f1->length); flint_printf("\n");
flint_printf("zzpe:"); cout << zzpe; flint_printf("\n");
flint_printf("f2 = "); fq_print_pretty(f2, ctx); flint_printf(" - %wd", f2->length); flint_printf("\n");
return 0;
}
fmpz_clear(p);
fq_clear(f1, ctx);
fq_clear(f2, ctx);
fmpz_mod_poly_clear(fmod);
fq_ctx_clear(ctx);
}
FLINT_TEST_CLEANUP(state);
return 1;
}
int test_ZZ_pEX_to_fq_poly()
{
fmpz_t p;
fq_poly_t f1, f2;
slong length;
int i, result;
fq_ctx_t ctx;
FLINT_TEST_INIT(state);
flint_printf("ZZ_pEX_to_fq_poly....");
fflush(stdout);
for (i = 0; i < 10000; i++)
{
fmpz_mod_poly_t fmod;
slong d;
ZZ prime;
ZZ_pX mod;
fmpz_init(p);
fmpz_set_ui(p, n_randprime(state, 2 + n_randint(state, 6), 1));
d = n_randint(state, 10) + 1;
fmpz_get_ZZ(prime, p);
ZZ_p::init(prime);
BuildIrred(mod, d);
ZZ_pE::init(mod);
fmpz_mod_poly_init(fmod, p);
fmpz_mod_poly_set_ZZ_pX(fmod, mod);
fq_ctx_init_modulus(ctx, fmod, "a");
ZZ_pEX zzpex;
fq_poly_init(f1, ctx);
fq_poly_init(f2, ctx);
length = n_randint(state, 1000);
fq_poly_randtest(f1, state, length, ctx);
fq_poly_get_ZZ_pEX(zzpex, f1, ctx);
fq_poly_set_ZZ_pEX(f2, zzpex, ctx);
result = fq_poly_equal(f1, f2, ctx);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("p = "); fmpz_print(p); flint_printf("\n");
flint_printf("mod = "); fmpz_mod_poly_print_pretty(fmod, "x"); flint_printf("\n");
flint_printf("f1 = "); fq_poly_print_pretty(f1, "x", ctx); flint_printf("\n");
flint_printf("zzpex:"); cout << zzpex; flint_printf("\n");
flint_printf("f2 = "); fq_poly_print_pretty(f2, "x", ctx); flint_printf("\n");
return 0;
}
fmpz_clear(p);
fq_poly_clear(f1, ctx);
fq_poly_clear(f2, ctx);
fmpz_mod_poly_clear(fmod);
fq_ctx_clear(ctx);
}
FLINT_TEST_CLEANUP(state);
return 1;
}
int test_zz_pE_to_fq()
{
fmpz_t p;
fq_t f1, f2;
int i, result;
fq_ctx_t ctx;
FLINT_TEST_INIT(state);
flint_printf("zz_pE_to_fq....");
fflush(stdout);
/* Check aliasing of a and c */
for (i = 0; i < 10000; i++)
{
fmpz_mod_poly_t fmod;
slong d;
zz_pX mod;
fmpz_init(p);
fmpz_set_ui(p, n_randprime(state, 2 + n_randint(state, 6), 1));
d = n_randint(state, 10) + 1;
zz_p::init(fmpz_get_si(p));
BuildIrred(mod, d);
zz_pE::init(mod);
fmpz_mod_poly_init(fmod, p);
fmpz_mod_poly_set_zz_pX(fmod, mod);
fq_ctx_init_modulus(ctx, fmod, "a");
zz_pE zzpe;
fq_init(f1, ctx);
fq_init(f2, ctx);
fq_randtest(f1, state, ctx);
fq_get_zz_pE(zzpe, f1, ctx);
fq_set_zz_pE(f2, zzpe, ctx);
result = fq_equal(f1, f2, ctx);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("p = "); fmpz_print(p); flint_printf("\n");
flint_printf("mod = "); fmpz_mod_poly_print_pretty(fmod, "x"); flint_printf("\n");
flint_printf("f1 = "); fq_print_pretty(f1, ctx); flint_printf(" - %wd", f1->length); flint_printf("\n");
flint_printf("zzpe:"); cout << zzpe; flint_printf("\n");
flint_printf("f2 = "); fq_print_pretty(f2, ctx); flint_printf(" - %wd", f2->length); flint_printf("\n");
return 0;
}
fmpz_clear(p);
fq_clear(f1, ctx);
fq_clear(f2, ctx);
fmpz_mod_poly_clear(fmod);
fq_ctx_clear(ctx);
}
FLINT_TEST_CLEANUP(state);
return 1;
}
int test_zz_pEX_to_fq_poly()
{
fmpz_t p;
fq_poly_t f1, f2;
slong length;
int i, result;
fq_ctx_t ctx;
FLINT_TEST_INIT(state);
flint_printf("zz_pEX_to_fq_poly....");
fflush(stdout);
for (i = 0; i < 10000; i++)
{
fmpz_mod_poly_t fmod;
slong d;
zz_pX mod;
fmpz_init(p);
fmpz_set_ui(p, n_randprime(state, 2 + n_randint(state, 6), 1));
d = n_randint(state, 10) + 1;
zz_p::init(fmpz_get_si(p));
BuildIrred(mod, d);
zz_pE::init(mod);
fmpz_mod_poly_init(fmod, p);
fmpz_mod_poly_set_zz_pX(fmod, mod);
fq_ctx_init_modulus(ctx, fmod, "a");
zz_pEX zzpex;
fq_poly_init(f1, ctx);
fq_poly_init(f2, ctx);
length = n_randint(state, 1000);
fq_poly_randtest(f1, state, length, ctx);
fq_poly_get_zz_pEX(zzpex, f1, ctx);
fq_poly_set_zz_pEX(f2, zzpex, ctx);
result = fq_poly_equal(f1, f2, ctx);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("p = "); fmpz_print(p); flint_printf("\n");
flint_printf("mod = "); fmpz_mod_poly_print_pretty(fmod, "x"); flint_printf("\n");
flint_printf("f1 = "); fq_poly_print_pretty(f1, "x", ctx); flint_printf("\n");
flint_printf("zzpex:"); cout << zzpex; flint_printf("\n");
flint_printf("f2 = "); fq_poly_print_pretty(f2, "x", ctx); flint_printf("\n");
return 0;
}
fmpz_clear(p);
fq_poly_clear(f1, ctx);
fq_poly_clear(f2, ctx);
fmpz_mod_poly_clear(fmod);
fq_ctx_clear(ctx);
}
FLINT_TEST_CLEANUP(state);
return 1;
}
int
main(void)
{
int r = 1;
if ((r &= test_ZZ_to_fmpz())) flint_printf("PASS\n");
if ((r &= test_ZZX_to_fmpz_poly())) flint_printf("PASS\n");
if ((r &= test_ZZ_pX_to_fmpz_mod_poly())) flint_printf("PASS\n");
if ((r &= test_ZZ_pE_to_fq())) flint_printf("PASS\n");
if ((r &= test_ZZ_pEX_to_fq_poly())) flint_printf("PASS\n");
if ((r &= test_zz_pX_to_fmpz_mod_poly())) flint_printf("PASS\n");
if ((r &= test_zz_pE_to_fq())) flint_printf("PASS\n");
if ((r &= test_zz_pEX_to_fq_poly())) flint_printf("PASS\n");
if (!r) abort();
return 0;
}