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,54 @@
SOURCES = $(wildcard *.c)
OBJS = $(patsubst %.c, $(BUILD_DIR)/$(MOD_DIR)_%.o, $(SOURCES))
LOBJS = $(patsubst %.c, $(BUILD_DIR)/%.lo, $(SOURCES))
MOD_LOBJ = $(BUILD_DIR)/../$(MOD_DIR).lo
TEST_SOURCES = $(wildcard test/*.c)
PROF_SOURCES = $(wildcard profile/*.c)
TUNE_SOURCES = $(wildcard tune/*.c)
TESTS = $(patsubst %.c, $(BUILD_DIR)/%, $(TEST_SOURCES))
TESTS_RUN = $(patsubst %, %_RUN, $(TESTS))
PROFS = $(patsubst %.c, %, $(PROF_SOURCES))
TUNE = $(patsubst %.c, %, $(TUNE_SOURCES))
all: shared static
shared: $(MOD_LOBJ)
static: $(OBJS)
profile: $(PROF_SOURCES)
$(foreach prog, $(PROFS), $(CC) $(ABI_FLAG) -O2 -std=c99 $(INCS) $(prog).c ../profiler.o -o $(BUILD_DIR)/$(prog) $(LIBS) || exit $$?;)
tune: $(TUNE_SOURCES)
$(foreach prog, $(TUNE), $(CC) $(ABI_FLAG) -O2 -std=c99 $(INCS) $(prog).c -o $(BUILD_DIR)/$(prog) $(LIBS) || exit $$?;)
$(BUILD_DIR)/$(MOD_DIR)_%.o: %.c
$(CC) $(CFLAGS) -c $(INCS) $< -o $@
$(MOD_LOBJ): $(LOBJS)
$(CC) $(ABI_FLAG) -Wl,-r $^ -o $@ -nostdlib
$(BUILD_DIR)/%.lo: %.c
$(CC) $(PICFLAG) $(CFLAGS) $(INCS) -c $< -o $@
clean:
rm -rf $(BUILD_DIR) $(MOD_LOBJ)
check: $(TESTS) $(TESTS_RUN)
$(BUILD_DIR)/test/%: test/%.c
$(CC) $(CFLAGS) $(INCS) $< ../test_helpers.o -o $@ $(LIBS)
%_RUN: %
@$<
.PHONY: profile tune clean check all shared static %_RUN

147
external/flint-2.4.3/padic_poly/add.c vendored Normal file
View File

@@ -0,0 +1,147 @@
/*============================================================================
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, 2012 Sebastian Pancratz
******************************************************************************/
#include "fmpz_mod_poly.h"
#include "padic_poly.h"
void _padic_poly_add(fmpz *rop, slong *val, slong N,
const fmpz *op1, slong val1, slong len1, slong N1,
const fmpz *op2, slong val2, slong len2, slong N2,
const padic_ctx_t ctx)
{
const slong len = FLINT_MAX(len1, len2);
*val = FLINT_MIN(val1, val2);
if (val1 == val2)
{
_fmpz_poly_add(rop, op1, len1, op2, len2);
_padic_poly_canonicalise(rop, val, len, ctx->p);
}
else /* => (op1 != op2) */
{
fmpz_t x;
fmpz_init(x);
if (val1 < val2) /* F := p^g (G + p^{h-g} H) */
{
fmpz_pow_ui(x, ctx->p, val2 - val1);
if (rop == op1)
{
_fmpz_vec_zero(rop + len1, len2 - len1);
_fmpz_vec_scalar_addmul_fmpz(rop, op2, len2, x);
}
else
{
_fmpz_vec_scalar_mul_fmpz(rop, op2, len2, x);
_fmpz_poly_add(rop, op1, len1, rop, len2);
}
}
else /* F := p^h (p^{g-h} G + H) */
{
fmpz_pow_ui(x, ctx->p, val1 - val2);
if (rop == op2)
{
_fmpz_vec_zero(rop + len2, len1 - len2);
_fmpz_vec_scalar_addmul_fmpz(rop, op1, len1, x);
}
else
{
_fmpz_vec_scalar_mul_fmpz(rop, op1, len1, x);
_fmpz_poly_add(rop, rop, len1, op2, len2);
}
}
fmpz_clear(x);
}
/* Reduce */
if (N - *val > 0)
{
fmpz_t pow;
int alloc;
alloc = _padic_ctx_pow_ui(pow, N - *val, ctx);
if (N >= N1 && N >= N2)
{
slong i;
for (i = 0; i < len; i++)
if (fmpz_cmpabs(rop + i, pow) >= 0)
fmpz_sub(rop + i, rop + i, pow);
}
else
{
_fmpz_vec_scalar_mod_fmpz(rop, rop, len, pow);
}
if (_fmpz_vec_is_zero(rop, len))
*val = 0;
if (alloc)
fmpz_clear(pow);
}
else
{
_fmpz_vec_zero(rop, len);
*val = 0;
}
}
void padic_poly_add(padic_poly_t f,
const padic_poly_t g, const padic_poly_t h,
const padic_ctx_t ctx)
{
const slong lenG = g->length;
const slong lenH = h->length;
const slong lenF = FLINT_MAX(lenG, lenH);
if (lenG == 0)
{
padic_poly_set(f, h, ctx);
return;
}
if (lenH == 0)
{
padic_poly_set(f, g, ctx);
return;
}
if ((lenG == 0 && lenH == 0) || (FLINT_MIN(g->val, h->val) >= f->N))
{
padic_poly_zero(f);
return;
}
padic_poly_fit_length(f, lenF);
_padic_poly_add(f->coeffs, &(f->val), f->N,
g->coeffs, g->val, lenG, g->N,
h->coeffs, h->val, lenH, h->N, ctx);
_padic_poly_set_length(f, lenF);
_padic_poly_normalise(f);
}

View 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) 2011 Sebastian Pancratz
******************************************************************************/
#include "padic_poly.h"
void _padic_poly_canonicalise(fmpz *poly, slong *v, slong len, const fmpz_t p)
{
const slong min = _fmpz_vec_ord_p(poly, len, p);
if (min == 0)
{
if (_fmpz_vec_is_zero(poly, len))
*v = 0;
}
else /* min > 0 */
{
fmpz_t pow;
fmpz_init(pow);
fmpz_pow_ui(pow, p, min);
_fmpz_vec_scalar_divexact_fmpz(poly, poly, len, pow);
fmpz_clear(pow);
*v += min;
}
}
void padic_poly_canonicalise(padic_poly_t poly, const fmpz_t p)
{
_padic_poly_canonicalise(poly->coeffs, &(poly->val), poly->length, p);
}

42
external/flint-2.4.3/padic_poly/clear.c vendored Normal file
View File

@@ -0,0 +1,42 @@
/*=============================================================================
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) 2008, 2009 William Hart
Copyright (C) 2010, 2011 Sebastian Pancratz
******************************************************************************/
#include <stdlib.h>
#include "fmpz.h"
#include "padic_poly.h"
void padic_poly_clear(padic_poly_t poly)
{
if (poly->coeffs)
{
slong i;
for (i = 0; i < poly->alloc; i++)
_fmpz_demote(poly->coeffs + i);
flint_free(poly->coeffs);
}
}

View File

@@ -0,0 +1,195 @@
/*============================================================================
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) 2012 Sebastian Pancratz
******************************************************************************/
#include "fmpz_mod_poly.h"
#include "padic_poly.h"
/*
TODO: Move this bit of code into "padic".
*/
static void __padic_reduce(fmpz_t u, slong *v, slong N, const padic_ctx_t ctx)
{
if (!fmpz_is_zero(u))
{
if (*v < N)
{
int alloc;
fmpz_t pow;
alloc = _padic_ctx_pow_ui(pow, N - *v, ctx);
fmpz_mod(u, u, pow);
if (alloc)
fmpz_clear(pow);
}
else
{
fmpz_zero(u);
*v = 0;
}
}
}
/* Assumes that len1 > 0. */
void _padic_poly_compose(fmpz *rop, slong *rval, slong N,
const fmpz *op1, slong val1, slong len1,
const fmpz *op2, slong val2, slong len2,
const padic_ctx_t ctx)
{
const slong lenr = (len1 - 1) * (len2 - 1) + 1;
if (len1 == 1 || len2 == 0)
{
fmpz_set(rop, op1);
*rval = val1;
__padic_reduce(rop, rval, N, ctx);
}
else if (val2 >= 0)
{
if (val1 >= N)
{
_fmpz_vec_zero(rop, lenr);
*rval = 0;
}
else
{
fmpz *vec2;
fmpz_t f;
fmpz_t pow;
int alloc;
vec2 = _fmpz_vec_init(len2);
fmpz_init(f);
fmpz_pow_ui(f, ctx->p, val2);
_fmpz_vec_scalar_mul_fmpz(vec2, op2, len2, f);
alloc = _padic_ctx_pow_ui(pow, N - val1, ctx);
_fmpz_mod_poly_compose(rop, op1, len1, vec2, len2, pow);
*rval= val1;
_padic_poly_canonicalise(rop, rval, lenr, ctx->p);
_fmpz_vec_clear(vec2, len2);
fmpz_clear(f);
if (alloc)
fmpz_clear(pow);
}
}
else /* val2 < 0 */
{
const slong n = len1 - 1;
if (val1 + n*val2 >= N)
{
_fmpz_vec_zero(rop, lenr);
*rval = 0;
}
else
{
fmpz_t pow;
int alloc;
fmpz *vec1;
fmpz_t s, t;
slong i;
vec1 = _fmpz_vec_init(len1);
fmpz_init(s);
fmpz_init(t);
alloc = _padic_ctx_pow_ui(pow, N - val1 - n*val2, ctx);
fmpz_pow_ui(s, ctx->p, -val2);
fmpz_one(t);
fmpz_set(vec1 + (len1 - 1), op1 + (len1 - 1));
for (i = len1 - 2; i >= 0; i--)
{
fmpz_mul(t, t, s);
fmpz_mul(vec1 + i, op1 + i, t);
}
_fmpz_mod_poly_compose(rop, vec1, len1, op2, len2, pow);
*rval = val1 + n*val2;
_padic_poly_canonicalise(rop, rval, lenr, ctx->p);
_fmpz_vec_clear(vec1, len1);
fmpz_clear(s);
fmpz_clear(t);
if (alloc)
fmpz_clear(pow);
}
}
}
void padic_poly_compose(padic_poly_t rop,
const padic_poly_t op1, const padic_poly_t op2,
const padic_ctx_t ctx)
{
const slong len1 = op1->length, len2 = op2->length;
if (len1 == 0)
{
padic_poly_zero(rop);
}
else if (len1 == 1 || len2 == 0)
{
padic_poly_fit_length(rop, 1);
fmpz_set(rop->coeffs, op1->coeffs);
rop->val = op1->val;
_padic_poly_set_length(rop, 1);
padic_poly_canonicalise(rop, ctx->p);
padic_poly_reduce(rop, ctx);
}
else
{
const slong lenr = (len1 - 1) * (len2 - 1) + 1;
if (rop != op1 && rop != op2)
{
padic_poly_fit_length(rop, lenr);
_padic_poly_compose(rop->coeffs, &(rop->val), rop->N,
op1->coeffs, op1->val, op1->length,
op2->coeffs, op2->val, op2->length, ctx);
_padic_poly_set_length(rop, lenr);
}
else
{
fmpz *t = _fmpz_vec_init(lenr);
_padic_poly_compose(t, &(rop->val), rop->N,
op1->coeffs, op1->val, op1->length,
op2->coeffs, op2->val, op2->length, ctx);
_fmpz_vec_clear(rop->coeffs, rop->alloc);
rop->coeffs = t;
rop->alloc = lenr;
rop->length = lenr;
}
_padic_poly_normalise(rop);
}
}

View File

@@ -0,0 +1,106 @@
/*============================================================================
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) 2012 Sebastian Pancratz
******************************************************************************/
#include "fmpz_mod_poly.h"
#include "padic_poly.h"
/*
TODO: Move this bit of code into "padic".
*/
static void __padic_reduce(fmpz_t u, slong *v, slong N, const padic_ctx_t ctx)
{
if (!fmpz_is_zero(u))
{
if (*v < N)
{
int alloc;
fmpz_t pow;
alloc = _padic_ctx_pow_ui(pow, N - *v, ctx);
fmpz_mod(u, u, pow);
if (alloc)
fmpz_clear(pow);
}
else
{
fmpz_zero(u);
*v = 0;
}
}
}
void _padic_poly_compose_pow(fmpz *rop, slong *rval, slong N,
const fmpz *op, slong val, slong len, slong k,
const padic_ctx_t ctx)
{
if (k == 1)
{
if (rop != op)
{
_fmpz_vec_set(rop, op, len);
*rval = val;
}
}
else if (len == 1)
{
fmpz_set(rop, op);
*rval = val;
__padic_reduce(rop, rval, N, ctx);
}
else
{
slong i, j, h;
for (i = len - 1, j = (len - 1) * k ; i >= 0; i--, j -= k)
{
fmpz_set(rop + j, op + i);
if (i)
for (h = 1; h < k; h++)
fmpz_zero(rop + (j - h));
}
*rval = val;
}
}
void padic_poly_compose_pow(padic_poly_t rop, const padic_poly_t op, slong k,
const padic_ctx_t ctx)
{
const slong len = op->length;
const slong lenr = (len - 1) * k + 1;
if (len == 0)
{
padic_poly_zero(rop);
}
else
{
padic_poly_fit_length(rop, lenr);
_padic_poly_compose_pow(rop->coeffs, &(rop->val), rop->N,
op->coeffs, op->val, op->length, k, ctx);
_padic_poly_set_length(rop, lenr);
}
}

View File

@@ -0,0 +1,66 @@
/*============================================================================
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) 2012 Sebastian Pancratz
******************************************************************************/
#include "fmpz_mod_poly.h"
#include "padic_poly.h"
void _padic_poly_derivative(fmpz *rop, slong *rval, slong N,
const fmpz *op, slong val, slong len,
const padic_ctx_t ctx)
{
fmpz_t pow;
int alloc;
_fmpz_poly_derivative(rop, op, len);
*rval = val;
alloc = _padic_ctx_pow_ui(pow, N - *rval, ctx);
_fmpz_vec_scalar_mod_fmpz(rop, rop, len - 1, pow);
_padic_poly_canonicalise(rop, rval, len - 1, ctx->p);
if (alloc)
fmpz_clear(pow);
}
void padic_poly_derivative(padic_poly_t rop,
const padic_poly_t op, const padic_ctx_t ctx)
{
const slong len = op->length;
if (len < 2 || op->val >= rop->N)
{
padic_poly_zero(rop);
}
else
{
padic_poly_fit_length(rop, len - 1);
_padic_poly_derivative(rop->coeffs, &(rop->val), rop->N,
op->coeffs, op->val, len, ctx);
_padic_poly_set_length(rop, len - 1);
_padic_poly_normalise(rop);
}
}

View File

@@ -0,0 +1,662 @@
/*=============================================================================
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, 2012 Sebastian Pancratz
******************************************************************************/
*******************************************************************************
Module documentation
We represent a polynomial in $\mathbf{Q}_p[x]$ as a
product $p^v f(x)$, where $p$ is a prime number,
$v \in \mathbf{Z}$ and $f(x) \in \mathbf{Z}[x]$.
As a data structure, we call this polynomial \emph{normalised}
if the polynomial $f(x)$ is \emph{normalised}, that is, if the top
coefficient is non-zero.
We say this polynomial is in \emph{canonical form} if one of the
coefficients of $f(x)$ is a $p$-adic unit. If $f(x)$ is the zero
polynomial, we require that $v = 0$.
We say this polynomial is \emph{reduced} modulo $p^N$ if it is
canonical form and if all coefficients lie in the range $[0, p^N)$.
*******************************************************************************
*******************************************************************************
Memory management
*******************************************************************************
void padic_poly_init(padic_poly_t poly)
Initialises \code{poly} for use, setting its length to zero.
The precision of the polynomial is set to \code{PADIC_DEFAULT_PREC}.
A corresponding call to \code{padic_poly_clear()} must be made
after finishing with the \code{padic_poly_t} to free the memory
used by the polynomial.
void padic_poly_init2(padic_poly_t poly, slong alloc, slong prec)
Initialises \code{poly} with space for at least \code{alloc} coefficients
and sets the length to zero. The allocated coefficients are all set to
zero. The precision is set to \code{prec}.
void padic_poly_realloc(padic_poly_t poly, slong alloc, const fmpz_t p)
Reallocates the given polynomial to have space for \code{alloc}
coefficients. If \code{alloc} is zero the polynomial is cleared
and then reinitialised. If the current length is greater than
\code{alloc} the polynomial is first truncated to length \code{alloc}.
void padic_poly_fit_length(padic_poly_t poly, slong len)
If \code{len} is greater than the number of coefficients currently
allocated, then the polynomial is reallocated to have space for at
least \code{len} coefficients. No data is lost when calling this
function.
The function efficiently deals with the case where \code{fit_length} is
called many times in small increments by at least doubling the number
of allocated coefficients when length is larger than the number of
coefficients currently allocated.
void _padic_poly_set_length(padic_poly_t poly, slong len)
Demotes the coefficients of \code{poly} beyond \code{len} and sets
the length of \code{poly} to \code{len}.
Note that if the current length is greater than \code{len} the
polynomial may no slonger be in canonical form.
void padic_poly_clear(padic_poly_t poly)
Clears the given polynomial, releasing any memory used. It must
be reinitialised in order to be used again.
void _padic_poly_normalise(padic_poly_t poly)
Sets the length of \code{poly} so that the top coefficient is non-zero.
If all coefficients are zero, the length is set to zero. This function
is mainly used internally, as all functions guarantee normalisation.
void _padic_poly_canonicalise(fmpz *poly, slong *v, slong len, const fmpz_t p)
void padic_poly_canonicalise(padic_poly_t poly, const fmpz_t p)
Brings the polynomial \code{poly} into canonical form,
assuming that it is normalised already. Does \emph{not}
carry out any reduction.
void padic_poly_reduce(padic_poly_t poly, const padic_ctx_t ctx)
Reduces the polynomial \code{poly} modulo $p^N$, assuming
that it is in canonical form already.
void padic_poly_truncate(padic_poly_t poly, slong n, const fmpz_t p)
Truncates the polynomial to length at most~$n$.
*******************************************************************************
Polynomial parameters
*******************************************************************************
slong padic_poly_degree(padic_poly_t poly)
Returns the degree of the polynomial \code{poly}.
slong padic_poly_length(padic_poly_t poly)
Returns the length of the polynomial \code{poly}.
slong padic_poly_val(padic_poly_t poly)
Returns the valuation of the polynomial \code{poly},
which is defined to be the minimum valuation of all
its coefficients.
The valuation of the zero polynomial is~$0$.
Note that this is implemented as a macro and can be
used as either a \code{lvalue} or a \code{rvalue}.
slong padic_poly_prec(padic_poly_t poly)
Returns the precision of the polynomial \code{poly}.
Note that this is implemented as a macro and can be
used as either a \code{lvalue} or a \code{rvalue}.
Note that increasing the precision might require
a call to \code{padic_poly_reduce()}.
*******************************************************************************
Randomisation
*******************************************************************************
void padic_poly_randtest(padic_poly_t f, flint_rand_t state,
slong len, const padic_ctx_t ctx)
Sets $f$ to a random polynomial of length at most \code{len}
with entries reduced modulo $p^N$.
void padic_poly_randtest_not_zero(padic_poly_t f, flint_rand_t state,
slong len, const padic_ctx_t ctx)
Sets $f$ to a non-zero random polynomial of length at most \code{len}
with entries reduced modulo $p^N$.
void padic_poly_randtest_val(padic_poly_t f, flint_rand_t state,
slong val, slong len, const padic_ctx_t ctx)
Sets $f$ to a random polynomial of length at most \code{len}
with at most the prescribed valuation \code{val} and entries
reduced modulo $p^N$.
Specifically, we aim to set the valuation to be exactly equal
to \code{val}, but do not check for additional cancellation
when creating the coefficients.
*******************************************************************************
Assignment and basic manipulation
*******************************************************************************
void padic_poly_set_padic(padic_poly_t poly, const padic_t x,
const padic_ctx_t ctx)
Sets the polynomial \code{poly} to the $p$-adic number $x$,
reduced to the precision of the polynomial.
void padic_poly_set(padic_poly_t poly1, const padic_poly_t poly2,
const padic_ctx_t ctx)
Sets the polynomial \code{poly1} to the polynomial \code{poly2},
reduced to the precision of \code{poly1}.
void padic_poly_set_si(padic_poly_t poly, slong x, const padic_ctx_t ctx)
Sets the polynomial \code{poly} to the \code{signed slong}
integer $x$ reduced to the precision of the polynomial.
void padic_poly_set_ui(padic_poly_t poly, ulong x, const padic_ctx_t ctx)
Sets the polynomial \code{poly} to the \code{unsigned slong}
integer $x$ reduced to the precision of the polynomial.
void padic_poly_set_fmpz(padic_poly_t poly, const fmpz_t x,
const padic_ctx_t ctx)
Sets the polynomial \code{poly} to the integer $x$
reduced to the precision of the polynomial.
void padic_poly_set_fmpq(padic_poly_t poly, const fmpq_t x,
const padic_ctx_t ctx)
Sets the polynomial \code{poly} to the value of the rational $x$,
reduced to the precision of the polynomial.
void padic_poly_set_fmpz_poly(padic_poly_t rop, const fmpz_poly_t op,
const padic_ctx_t ctx)
Sets the polynomial \code{rop} to the integer polynomial \code{op}
reduced to the precision of the polynomial.
void padic_poly_set_fmpq_poly(padic_poly_t rop,
const fmpq_poly_t op, const padic_ctx_t ctx)
Sets the polynomial \code{rop} to the value of the rational
polynomial \code{op}, reduced to the precision of the polynomial.
int padic_poly_get_fmpz_poly(fmpz_poly_t rop, const padic_poly_t op,
const padic_ctx_t ctx)
Sets the integer polynomial \code{rop} to the value of the $p$-adic
polynomial \code{op} and returns $1$ if the polynomial is $p$-adically
integral. Otherwise, returns $0$.
void padic_poly_get_fmpq_poly(fmpq_poly_t rop,
const padic_poly_t op, const padic_ctx_t ctx)
Sets \code{rop} to the rational polynomial corresponding to
the $p$-adic polynomial \code{op}.
void padic_poly_zero(padic_poly_t poly)
Sets \code{poly} to the zero polynomial.
void padic_poly_one(padic_poly_t poly)
Sets \code{poly} to the constant polynomial $1$,
reduced to the precision of the polynomial.
void padic_poly_swap(padic_poly_t poly1, padic_poly_t poly2)
Swaps the two polynomials \code{poly1} and \code{poly2},
including their precisions.
This is done efficiently by swapping pointers.
*******************************************************************************
Getting and setting coefficients
*******************************************************************************
void padic_poly_get_coeff_padic(padic_t c, const padic_poly_t poly, slong n,
const padic_ctx_t ctx)
Sets $c$ to the coefficient of $x^n$ in the polynomial,
reduced modulo the precision of $c$.
void padic_poly_set_coeff_padic(padic_poly_t f, slong n, const padic_t c,
const padic_ctx_t ctx)
Sets the coefficient of $x^n$ in the polynomial $f$ to $c$,
reduced to the precision of the polynomial $f$.
Note that this operation can take linear time in the length
of the polynomial.
*******************************************************************************
Comparison
*******************************************************************************
int padic_poly_equal(const padic_poly_t poly1, const padic_poly_t poly2)
Returns whether the two polynomials \code{poly1} and \code{poly2}
are equal.
int padic_poly_is_zero(const padic_poly_t poly)
Returns whether the polynomial \code{poly} is the zero polynomial.
int padic_poly_is_one(const padic_poly_t poly, const padic_ctx_t ctx)
Returns whether the polynomial \code{poly} is equal
to the constant polynomial~$1$, taking the precision
of the polynomial into account.
*******************************************************************************
Addition and subtraction
*******************************************************************************
void _padic_poly_add(fmpz *rop, slong *rval, slong N,
const fmpz *op1, slong val1, slong len1, slong N1,
const fmpz *op2, slong val2, slong len2, slong N2,
const padic_ctx_t ctx)
Sets \code{(rop, *val, FLINT_MAX(len1, len2)} to the sum of
\code{(op1, val1, len1)} and \code{(op2, val2, len2)}.
Assumes that the input is reduced and guarantees that this is
also the case for the output.
Assumes that $\min\{v_1, v_2\} < N$.
Supports aliasing between the output and input arguments.
void padic_poly_add(padic_poly_t f,
const padic_poly_t g, const padic_poly_t h,
const padic_ctx_t ctx);
Sets $f$ to the sum $g + h$.
void _padic_poly_sub(fmpz *rop, slong *rval,
const fmpz *op1, slong val1, slong len1,
const fmpz *op2, slong val2, slong len2,
const padic_ctx_t ctx);
Sets \code{(rop, *val, FLINT_MAX(len1, len2)} to the difference of
\code{(op1, val1, len1)} and \code{(op2, val2, len2)}.
Assumes that the input is reduced and guarantees that this is
also the case for the output.
Assumes that $\min\{v_1, v_2\} < N$.
Support aliasing between the output and input arguments.
void padic_poly_sub(padic_poly_t f,
const padic_poly_t g, const padic_poly_t h,
const padic_ctx_t ctx);
Sets $f$ to the difference $g - h$.
void padic_poly_neg(padic_poly_t f, const padic_poly_t g,
const padic_ctx_t ctx);
Sets $f$ to $-g$.
*******************************************************************************
Scalar multiplication
*******************************************************************************
void _padic_poly_scalar_mul_padic(fmpz *rop, slong *rval,
const fmpz *op, slong val, slong len,
const padic_t c, const padic_ctx_t ctx)
Sets \code{(rop, *rval, len)} to \code{(op, val, len)} multiplied
by the scalar $c$.
The result will only be correctly reduced if the polynomial
is non-zero. Otherwise, the array \code{(rop, len)} will be
set to zero but the valuation \code{*rval} might be wrong.
void padic_poly_scalar_mul_padic(padic_poly_t rop, const padic_poly_t op,
const padic_t c, const padic_ctx_t ctx)
Sets the polynomial \code{rop} to the product of the
polynomial \code{op} and the $p$-adic number $c$,
reducing the result modulo $p^N$.
*******************************************************************************
Multiplication
*******************************************************************************
void _padic_poly_mul(fmpz *rop, slong *rval, slong N,
const fmpz *op1, slong val1, slong len1,
const fmpz *op2, slong val2, slong len2,
const padic_ctx_t ctx)
Sets \code{(rop, *rval, len1 + len2 - 1)} to the product of
\code{(op1, val1, len1)} and \code{(op2, val2, len2)}.
Assumes that the resulting valuation \code{*rval}, which is
the sum of the valuations \code{val1} and \code{val2}, is less
than the precision~$N$ of the context.
Assumes that \code{len1 >= len2 > 0}.
void padic_poly_mul(padic_poly_t res,
const padic_poly_t poly1, const padic_poly_t poly2,
const padic_ctx_t ctx)
Sets the polynomial \code{res} to the product of the two polynomials
\code{poly1} and \code{poly2}, reduced modulo $p^N$.
*******************************************************************************
Powering
*******************************************************************************
void _padic_poly_pow(fmpz *rop, slong *rval, slong N,
const fmpz *op, slong val, slong len, ulong e,
const padic_ctx_t ctx)
Sets the polynomial \code{(rop, *rval, e (len - 1) + 1)} to the
polynomial \code{(op, val, len)} raised to the power~$e$.
Assumes that $e > 1$ and \code{len > 0}.
Does not support aliasing between the input and output arguments.
void padic_poly_pow(padic_poly_t rop, const padic_poly_t op, ulong e,
const padic_ctx_t ctx)
Sets the polynomial \code{rop} to the polynomial \code{op} raised
to the power~$e$, reduced to the precision in \code{rop}.
In the special case $e = 0$, sets \code{rop} to the constant
polynomial one reduced to the precision of \code{rop}.
Also note that when $e = 1$, this operation sets \code{rop} to
\code{op} and then reduces \code{rop}.
When the valuation of the input polynomial is negative,
this results in a loss of $p$-adic precision. Suppose
that the input polynomial is given to precision~$N$ and
has valuation~$v < 0$. The result then has valuation
$e v < 0$ but is only correct to precision $N + (e - 1) v$.
*******************************************************************************
Series inversion
*******************************************************************************
void padic_poly_inv_series(padic_poly_t g, const padic_poly_t f, slong n,
const padic_ctx_t ctx)
Computes the power series inverse $g$ of $f$ modulo $X^n$,
where $n \geq 1$.
Given the polynomial $f \in \mathbf{Q}[X] \subset \mathbf{Q}_p[X]$,
there exists a unique polynomial $f^{-1} \in \mathbf{Q}[X]$ such that
$f f^{-1} = 1$ modulo $X^n$. This function sets $g$ to $f^{-1}$
reduced modulo $p^N$.
Assumes that the constant coefficient of $f$ is non-zero.
Moreover, assumes that the valuation of the constant coefficient
of $f$ is minimal among the coefficients of $f$.
Note that the result $g$ is zero if and only if $- \ord_p(f) \geq N$.
*******************************************************************************
Derivative
*******************************************************************************
void _padic_poly_derivative(fmpz *rop, slong *rval, slong N,
const fmpz *op, slong val, slong len,
const padic_ctx_t ctx)
Sets \code{(rop, rval)} to the derivative of \code{(op, val)} reduced
modulo $p^N$.
Supports aliasing of the input and the output parameters.
void padic_poly_derivative(padic_poly_t rop,
const padic_poly_t op, const padic_ctx_t ctx)
Sets \code{rop} to the derivative of \code{op}, reducing the
result modulo the precision of \code{rop}.
*******************************************************************************
Shifting
*******************************************************************************
void padic_poly_shift_left(padic_poly_t rop, const padic_poly_t op, slong n,
const padic_ctx_t ctx)
Notationally, sets the polynomial \code{rop} to the polynomial \code{op}
multiplied by $x^n$, where $n \geq 0$, and reduces the result.
void padic_poly_shift_right(padic_poly_t rop, const padic_poly_t op, slong n)
Notationally, sets the polynomial \code{rop} to the polynomial
\code{op} after floor division by $x^n$, where $n \geq 0$, ensuring
the result is reduced.
*******************************************************************************
Evaluation
*******************************************************************************
void _padic_poly_evaluate_padic(fmpz_t u, slong *v, slong N,
const fmpz *poly, slong val, slong len,
const fmpz_t a, slong b, const padic_ctx_t ctx)
void padic_poly_evaluate_padic(padic_t y, const padic_poly_t poly,
const padic_t a, const padic_ctx_t ctx)
Sets the $p$-adic number \code{y} to \code{poly} evaluated at $a$,
reduced in the given context.
Suppose that the polynomial can be written as $F(X) = p^w f(X)$
with $\ord_p(f) = 1$, that $\ord_p(a) = b$ and that both are
defined to precision~$N$. Then $f$ is defined to precision
$N-w$ and so $f(a)$ is defined to precision $N-w$ when $a$ is
integral and $N-w+(n-1)b$ when $b < 0$, where $n = \deg(f)$. Thus,
$y = F(a)$ is defined to precision $N$ when $a$ is integral and
$N+(n-1)b$ when $b < 0$.
*******************************************************************************
Composition
*******************************************************************************
void _padic_poly_compose(fmpz *rop, slong *rval, slong N,
const fmpz *op1, slong val1, slong len1,
const fmpz *op2, slong val2, slong len2,
const padic_ctx_t ctx)
Sets \code{(rop, *rval, (len1-1)*(len2-1)+1)} to the composition
of the two input polynomials, reducing the result modulo $p^N$.
Assumes that \code{len1} is non-zero.
Does not support aliasing.
void padic_poly_compose(padic_poly_t rop,
const padic_poly_t op1, const padic_poly_t op2,
const padic_ctx_t ctx)
Sets \code{rop} to the composition of \code{op1} and \code{op2},
reducing the result in the given context.
To be clear about the order of composition, let $f(X)$ and $g(X)$
denote the polynomials \code{op1} and \code{op2}, respectively.
Then \code{rop} is set to $f(g(X))$.
void _padic_poly_compose_pow(fmpz *rop, slong *rval, slong N,
const fmpz *op, slong val, slong len, slong k,
const padic_ctx_t ctx)
Sets \code{(rop, *rval, (len - 1)*k + 1)} to the composition of
\code{(op, val, len)} and the monomial $x^k$, where $k \geq 1$.
Assumes that \code{len} is positive.
Supports aliasing between the input and output polynomials.
void padic_poly_compose_pow(padic_poly_t rop, const padic_poly_t op, slong k,
const padic_ctx_t ctx)
Sets \code{rop} to the composition of \code{op} and the monomial $x^k$,
where $k \geq 1$.
Note that no reduction takes place.
*******************************************************************************
Input and output
*******************************************************************************
int padic_poly_debug(const padic_poly_t poly)
Prints the data defining the $p$-adic polynomial \code{poly}
in a simple format useful for debugging purposes.
In the current implementation, always returns $1$.
int _padic_poly_fprint(FILE *file, const fmpz *poly, slong val, slong len,
const padic_ctx_t ctx)
int padic_poly_fprint(FILE *file, const padic_poly_t poly,
const padic_ctx_t ctx)
Prints a simple representation of the polynomial \code{poly}
to the stream \code{file}.
A non-zero polynomial is represented by the number of coeffients,
two spaces, followed by a list of the coefficients, which are printed
in a way depending on the print mode,
\begin{itemize}
\item In the \code{PADIC_TERSE} mode, the coefficients are printed as
rational numbers.
\item The \code{PADIC_SERIES} mode is currently not supported and will
raise an abort signal.
\item In the \code{PADIC_VAL_UNIT} mode, the coefficients are printed
in the form $p^v u$.
\end{itemize}
The zero polynomial is represented by \code{"0"}.
In the current implementation, always returns $1$.
int _padic_poly_print(const fmpz *poly, slong val, slong len,
const padic_ctx_t ctx)
int padic_poly_print(const padic_poly_t poly, const padic_ctx_t ctx)
Prints a simple representation of the polynomial \code{poly}
to \code{stdout}.
In the current implementation, always returns $1$.
int _padic_poly_fprint_pretty(FILE *file,
const fmpz *poly, slong val, slong len,
const char *var,
const padic_ctx_t ctx)
int padic_poly_fprint_pretty(FILE *file,
const padic_poly_t poly, const char *var,
const padic_ctx_t ctx)
int _padic_poly_print_pretty(FILE *file,
const fmpz *poly, slong val, slong len,
const char *var,
const padic_ctx_t ctx)
int padic_poly_print_pretty(const padic_poly_t poly, const char *var,
const padic_ctx_t ctx)
*******************************************************************************
Testing
*******************************************************************************
int _padic_poly_is_canonical(const fmpz *op, slong val, slong len,
const padic_ctx_t ctx);
int padic_poly_is_canonical(const padic_poly_t op, const padic_ctx_t ctx);
int _padic_poly_is_reduced(const fmpz *op, slong val, slong len, slong N,
const padic_ctx_t ctx);
int padic_poly_is_reduced(const padic_poly_t op, const padic_ctx_t ctx);

42
external/flint-2.4.3/padic_poly/equal.c vendored Normal file
View File

@@ -0,0 +1,42 @@
/*============================================================================
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 "padic_poly.h"
int padic_poly_equal(const padic_poly_t f, const padic_poly_t g)
{
if (f == g)
{
return 1;
}
if (f->length != g->length || f->val != g->val)
{
return 0;
}
return _fmpz_vec_equal(f->coeffs, g->coeffs, f->length);
}

View File

@@ -0,0 +1,188 @@
/*============================================================================
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) 2012 Sebastian Pancratz
******************************************************************************/
#include "fmpz_mod_poly.h"
#include "padic_poly.h"
/*
TODO: Move this bit of code into "padic".
*/
static void __padic_reduce(fmpz_t u, slong *v, slong N, const padic_ctx_t ctx)
{
if (!fmpz_is_zero(u))
{
if (*v < N)
{
int alloc;
fmpz_t pow;
alloc = _padic_ctx_pow_ui(pow, N - *v, ctx);
fmpz_mod(u, u, pow);
if (alloc)
fmpz_clear(pow);
}
else
{
fmpz_zero(u);
*v = 0;
}
}
}
/*
Evaluates the polynomial $F(x) = p^w f(x)$ at $x = p^b a$, setting
$y = p^v u$ to the result reduced modulo $p^N$.
Suppose first that $b \geq 0$, in which case we can quickly relay
the call to the \code{fmpz_mod_poly} module. Namely, we need to
compute $f(x) \bmod {p^{N-w}}$ where we know $f(x)$ to be integral.
Otherwise, suppose now that $b < 0$ and we still wish to evaluate
$f(x) \bmod {p^{N-w}}$.
\begin{align*}
f(x) & = \sum_{i = 0}^{n} a_i x^i \\
& = \sum_{i = 0}^{n} a_i p^{i b} a^i \\
\intertext{Multiplying through by $p^{- n b} \in \mathbf{Z}$, }
p^{-nb} f(x) & = \sum_{i = 0}^{n} a_i p^{-(n-i)b} a
\end{align*}
which leaves the right hand side integral. As we want to
compute $f(x)$ to precision $N-w$, we have to compute
$p^{-nb} f(x)$ to precision $N-w-nb$.
*/
void _padic_poly_evaluate_padic(fmpz_t u, slong *v, slong N,
const fmpz *poly, slong val, slong len,
const fmpz_t a, slong b, const padic_ctx_t ctx)
{
if (len == 0)
{
fmpz_zero(u);
*v = 0;
}
else if (len == 1)
{
fmpz_set(u, poly);
*v = val;
__padic_reduce(u, v, N, ctx);
}
else if (b >= 0)
{
if (val >= N)
{
fmpz_zero(u);
*v = 0;
}
else
{
fmpz_t x;
fmpz_t pow;
int alloc;
fmpz_init(x);
alloc = _padic_ctx_pow_ui(pow, N - val, ctx);
fmpz_pow_ui(x, ctx->p, b);
fmpz_mul(x, x, a);
_fmpz_mod_poly_evaluate_fmpz(u, poly, len, x, pow);
if (!fmpz_is_zero(u))
*v = val + _fmpz_remove(u, ctx->p, ctx->pinv);
else
*v = 0;
fmpz_clear(x);
if (alloc)
fmpz_clear(pow);
}
}
else /* b < 0 */
{
const slong n = len - 1;
if (val + n*b >= N)
{
fmpz_zero(u);
*v = 0;
}
else
{
fmpz_t pow;
int alloc;
slong i;
fmpz_t s, t;
fmpz *vec = _fmpz_vec_init(len);
fmpz_init(s);
fmpz_init(t);
alloc = _padic_ctx_pow_ui(pow, N - val - n*b, ctx);
fmpz_pow_ui(s, ctx->p, -b);
fmpz_one(t);
fmpz_set(vec + (len - 1), poly + (len - 1));
for (i = len - 2; i >= 0; i--)
{
fmpz_mul(t, t, s);
fmpz_mul(vec + i, poly + i, t);
}
_fmpz_mod_poly_evaluate_fmpz(u, vec, len, a, pow);
if (!fmpz_is_zero(u))
*v = val + n*b + _fmpz_remove(u, ctx->p, ctx->pinv);
else
*v = 0;
if (alloc)
fmpz_clear(pow);
fmpz_clear(s);
fmpz_clear(t);
_fmpz_vec_clear(vec, len);
}
}
}
void padic_poly_evaluate_padic(padic_t y, const padic_poly_t poly,
const padic_t x, const padic_ctx_t ctx)
{
if (y == x)
{
padic_t t;
padic_init2(t, padic_prec(y));
_padic_poly_evaluate_padic(padic_unit(t), &padic_val(t), padic_prec(t),
poly->coeffs, poly->val, poly->length,
padic_unit(x), padic_val(x), ctx);
padic_swap(y, t);
padic_clear(t);
}
else
{
_padic_poly_evaluate_padic(padic_unit(y), &padic_val(y), padic_prec(y),
poly->coeffs, poly->val, poly->length,
padic_unit(x), padic_val(x), ctx);
}
}

View File

@@ -0,0 +1,52 @@
/*=============================================================================
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) 2008, 2009 William Hart
Copyright (C) 2011 Sebastian Pancratz
******************************************************************************/
#include <stdlib.h>
#include "fmpz.h"
#include "padic_poly.h"
void padic_poly_fit_length(padic_poly_t poly, slong len)
{
if (len > poly->alloc)
{
if (len < 2 * poly->alloc)
len = 2 * poly->alloc;
if (poly->alloc) /* Realloc */
{
poly->coeffs = (fmpz *) flint_realloc(poly->coeffs, len * sizeof(fmpz));
mpn_zero((mp_ptr) (poly->coeffs + poly->alloc), len - poly->alloc);
}
else /* Nothing allocated already so do it now */
{
poly->coeffs = (fmpz *) flint_calloc(len, sizeof(fmpz));
}
poly->alloc = len;
}
}

View File

@@ -0,0 +1,75 @@
/*=============================================================================
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, 2012 Sebastian Pancratz
******************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include "padic_poly.h"
int _padic_poly_fprint(FILE *file, const fmpz *poly, slong val, slong len,
const padic_ctx_t ctx)
{
slong i, v;
fmpz_t u;
if (len == 0)
{
flint_fprintf(file, "0");
return 1;
}
fmpz_init(u);
flint_fprintf(file, "%wd ", len);
for (i = 0; i < len; i++)
{
flint_fprintf(file, " ");
if (fmpz_is_zero(poly + i))
{
flint_fprintf(file, "0");
}
else
{
v = val + fmpz_remove(u, poly + i, ctx->p);
_padic_fprint(file, u, v, ctx);
}
}
fmpz_clear(u);
return 1;
}
int padic_poly_fprint(FILE *file, const padic_poly_t poly,
const padic_ctx_t ctx)
{
_padic_poly_fprint(file, poly->coeffs, poly->val, poly->length, ctx);
return 1;
}

View File

@@ -0,0 +1,174 @@
/*============================================================================
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 "padic_poly.h"
int _padic_poly_fprint_pretty(FILE *file,
const fmpz *poly, slong len, slong val,
const char *var,
const padic_ctx_t ctx)
{
slong i;
padic_t x;
padic_init(x); /* Precision is not used anywhere! */
if (len == 0)
{
fputc('0', file);
}
else if (len == 1)
{
_padic_fprint(file, poly + 0, val, ctx);
}
else if (len == 2)
{
fmpz_set(padic_unit(x), poly + 1);
padic_val(x) = val;
_padic_canonicalise(x, ctx);
if (padic_is_one(x))
{
flint_fprintf(file, "%s", var);
}
else if (*(padic_unit(x)) == WORD(-1) && padic_val(x) == 0)
{
flint_fprintf(file, "-%s", var);
}
else
{
fputc('(', file);
padic_fprint(file, x, ctx);
fputc(')', file);
flint_fprintf(file, "*%s", var);
}
fmpz_abs(padic_unit(x), poly);
padic_val(x) = val;
_padic_canonicalise(x, ctx);
if (fmpz_sgn(poly) > 0)
{
fputc('+', file);
}
else if (fmpz_sgn(poly) < 0)
{
fputc('-', file);
}
fputc('(', file);
padic_fprint(file, x, ctx);
fputc(')', file);
}
else /* len >= 3 */
{
i = len - 1; /* i >= 2 */
{
fmpz_set(padic_unit(x), poly + i);
padic_val(x) = val;
_padic_canonicalise(x, ctx);
if (padic_is_one(x))
flint_fprintf(file, "%s^%wd", var, i);
else if (*(padic_unit(x)) == WORD(-1) && padic_val(x) == 0)
flint_fprintf(file, "-%s^%wd", var, i);
else
{
fputc('(', file);
padic_fprint(file, x, ctx);
fputc(')', file);
flint_fprintf(file, "*%s^%wd", var, i);
}
--i;
}
for (; i > 1; --i)
{
if (*(poly + i) == 0)
continue;
fmpz_abs(padic_unit(x), poly + i);
padic_val(x) = val;
_padic_canonicalise(x, ctx);
if (fmpz_sgn(poly + i) > 0)
fputc('+', file);
else
fputc('-', file);
if (padic_is_one(x))
flint_fprintf(file, "%s^%wd", var, i);
else
{
fputc('(', file);
padic_fprint(file, x, ctx);
fputc(')', file);
flint_fprintf(file, "*%s^%wd", var, i);
}
}
if (*(poly + 1))
{
fmpz_abs(padic_unit(x), poly + 1);
padic_val(x) = val;
_padic_canonicalise(x, ctx);
fputc(fmpz_sgn(poly + 1) > 0 ? '+' : '-', file);
if (padic_is_one(x))
fputs(var, file);
else
{
fputc('(', file);
padic_fprint(file, x, ctx);
fputc(')', file);
fputc('*', file);
fputs(var, file);
}
}
if (*(poly))
{
fmpz_abs(padic_unit(x), poly);
padic_val(x) = val;
_padic_canonicalise(x, ctx);
fputc(fmpz_sgn(poly) > 0 ? '+' : '-', file);
fputc('(', file);
padic_fprint(file, x, ctx);
fputc(')', file);
}
}
padic_clear(x);
return 1;
}
int padic_poly_fprint_pretty(FILE *file,
const padic_poly_t poly, const char *var,
const padic_ctx_t ctx)
{
return _padic_poly_fprint_pretty(file,
poly->coeffs, poly->length, poly->val, var, ctx);
}

View File

@@ -0,0 +1,42 @@
/*============================================================================
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, 2012 Sebastian Pancratz
******************************************************************************/
#include "padic_poly.h"
void padic_poly_get_coeff_padic(padic_t x, const padic_poly_t f, slong n,
const padic_ctx_t ctx)
{
if (n < f->length && !fmpz_is_zero(f->coeffs + n))
{
fmpz_set(padic_unit(x), f->coeffs + n);
padic_val(x) = f->val;
padic_reduce(x, ctx);
}
else
{
padic_zero(x);
}
}

View File

@@ -0,0 +1,83 @@
/*============================================================================
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, 2012 Sebastian Pancratz
******************************************************************************/
#include "fmpq_poly.h"
#include "padic_poly.h"
/*
Assumes that len > 0.
*/
static void _padic_poly_get_fmpq_poly(fmpz *rop, fmpz_t den,
const fmpz *op, slong val, slong len,
const fmpz_t p)
{
if (val == 0)
{
_fmpz_vec_set(rop, op, len);
fmpz_one(den);
}
else if (val == 1)
{
_fmpz_vec_scalar_mul_fmpz(rop, op, len, p);
fmpz_one(den);
}
else if (val > 1)
{
fmpz_t t;
fmpz_init(t);
fmpz_pow_ui(t, p, val);
_fmpz_vec_scalar_mul_fmpz(rop, op, len, t);
fmpz_one(den);
fmpz_clear(t);
}
else
{
_fmpz_vec_set(rop, op, len);
fmpz_pow_ui(den, p, -val);
}
}
void padic_poly_get_fmpq_poly(fmpq_poly_t rop,
const padic_poly_t op, const padic_ctx_t ctx)
{
const slong len = op->length;
if (len == 0)
{
fmpq_poly_zero(rop);
}
else
{
fmpq_poly_fit_length(rop, len);
_padic_poly_get_fmpq_poly(rop->coeffs, rop->den,
op->coeffs, op->val, op->length, ctx->p);
_fmpq_poly_set_length(rop, len);
}
}

View File

@@ -0,0 +1,63 @@
/*============================================================================
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 "padic_poly.h"
int padic_poly_get_fmpz_poly(fmpz_poly_t rop, const padic_poly_t op,
const padic_ctx_t ctx)
{
const slong len = op->length;
if (op->val < 0)
{
return 0;
}
if (padic_poly_is_zero(op))
{
fmpz_poly_zero(rop);
return 1;
}
fmpz_poly_fit_length(rop, len);
_fmpz_poly_set_length(rop, len);
if (op->val == 0)
{
_fmpz_vec_set(rop->coeffs, op->coeffs, len);
}
else /* op->val > 0 */
{
fmpz_t pow;
fmpz_init(pow);
fmpz_pow_ui(pow, ctx->p, op->val);
_fmpz_vec_scalar_mul_fmpz(rop->coeffs, op->coeffs, len, pow);
fmpz_clear(pow);
}
return 1;
}

50
external/flint-2.4.3/padic_poly/init.c vendored Normal file
View 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) 2008, 2009 William Hart
Copyright (C) 2011, 2012 Sebastian Pancratz
******************************************************************************/
#include <gmp.h>
#include <stdlib.h>
#include "flint.h"
#include "fmpz.h"
#include "padic_poly.h"
void padic_poly_init(padic_poly_t poly)
{
poly->coeffs = NULL;
poly->alloc = 0;
poly->length = 0;
poly->val = 0;
poly->N = PADIC_DEFAULT_PREC;
}
void padic_poly_init2(padic_poly_t poly, slong alloc, slong prec)
{
poly->coeffs = alloc ? (fmpz *) flint_calloc(alloc, sizeof(fmpz)) : NULL;
poly->alloc = alloc;
poly->length = 0;
poly->val = 0;
poly->N = prec;
}

View File

@@ -0,0 +1,108 @@
/*============================================================================
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, 2012 Sebastian Pancratz
******************************************************************************/
#include "fmpz_mod_poly.h"
#include "padic_poly.h"
void padic_poly_inv_series(padic_poly_t Qinv, const padic_poly_t Q, slong n,
const padic_ctx_t ctx)
{
fmpz_t cinv;
fmpz_t pow;
int palloc;
fmpz *Qcopy;
int Qalloc;
if (Q->length == 0 || fmpz_is_zero(Q->coeffs + 0))
{
flint_printf("Exception (padic_poly_inv_series): Constant term is zero.\n");
abort();
}
if (fmpz_divisible(Q->coeffs + 0, ctx->p))
{
flint_printf("Exception (padic_poly_inv_series):\n");
flint_printf("Valuation of constant term is not minimal.\n");
abort();
}
if (- Q->val >= Qinv->N)
{
padic_poly_zero(Qinv);
return;
}
if (Q->length >= n)
{
Qcopy = Q->coeffs;
Qalloc = 0;
}
else
{
slong i;
Qcopy = (fmpz *) flint_malloc(n * sizeof(fmpz));
for (i = 0; i < Q->length; i++)
Qcopy[i] = Q->coeffs[i];
mpn_zero((mp_ptr) Qcopy + i, n - i);
Qalloc = 1;
}
fmpz_init(cinv);
fmpz_init(pow);
_padic_inv(cinv, Q->coeffs, ctx->p, Qinv->N + Q->val);
palloc = _padic_ctx_pow_ui(pow, Qinv->N + Q->val, ctx);
if (Qinv != Q)
{
padic_poly_fit_length(Qinv, n);
_fmpz_mod_poly_inv_series_newton(Qinv->coeffs, Qcopy, n, cinv, pow);
}
else
{
fmpz *t = _fmpz_vec_init(n);
_fmpz_mod_poly_inv_series_newton(t, Qcopy, n, cinv, pow);
_fmpz_vec_clear(Qinv->coeffs, Qinv->alloc);
Qinv->coeffs = t;
Qinv->alloc = n;
Qinv->length = n;
}
Qinv->val = - Q->val;
_padic_poly_set_length(Qinv, n);
_padic_poly_normalise(Qinv);
fmpz_clear(cinv);
if (palloc)
fmpz_clear(pow);
if (Qalloc)
flint_free(Qcopy);
}

View File

@@ -0,0 +1,47 @@
/*============================================================================
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) 2012 Sebastian Pancratz
******************************************************************************/
#include "padic_poly.h"
int _padic_poly_is_canonical(const fmpz *op, slong val, slong len,
const padic_ctx_t ctx)
{
if (len == 0)
{
return (val == 0);
}
else
{
slong w = _fmpz_vec_ord_p(op, len, ctx->p);
return (w == 0);
}
}
int padic_poly_is_canonical(const padic_poly_t op, const padic_ctx_t ctx)
{
return _padic_poly_is_canonical(op->coeffs, op->val, op->length, ctx);
}

View File

@@ -0,0 +1,68 @@
/*============================================================================
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) 2012 Sebastian Pancratz
******************************************************************************/
#include "padic_poly.h"
int _padic_poly_is_reduced(const fmpz *op, slong val, slong len, slong N,
const padic_ctx_t ctx)
{
slong w;
if (len == 0)
{
return (val == 0);
}
w = _fmpz_vec_ord_p(op, len, ctx->p);
if (w != 0 || val >= N)
{
return 0;
}
{
fmpz_t pow;
int r, alloc;
slong i;
alloc = _padic_ctx_pow_ui(pow, N - val, ctx);
r = 1;
for (i = 0; (i < len) && (r); i++)
if (fmpz_sgn(op + i) < 0 || fmpz_cmp(op + i, pow) >= 0)
r = 0;
if (alloc)
fmpz_clear(pow);
return r;
}
}
int padic_poly_is_reduced(const padic_poly_t op, const padic_ctx_t ctx)
{
return _padic_poly_is_reduced(op->coeffs, op->val, op->length, op->N, ctx);
}

91
external/flint-2.4.3/padic_poly/mul.c vendored Normal file
View File

@@ -0,0 +1,91 @@
/*============================================================================
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, 2012 Sebastian Pancratz
******************************************************************************/
#include "padic_poly.h"
void _padic_poly_mul(fmpz *rop, slong *rval, slong N,
const fmpz *op1, slong val1, slong len1,
const fmpz *op2, slong val2, slong len2,
const padic_ctx_t ctx)
{
fmpz_t pow;
int alloc;
*rval = val1 + val2;
alloc = _padic_ctx_pow_ui(pow, N - *rval, ctx);
_fmpz_poly_mul(rop, op1, len1, op2, len2);
_fmpz_vec_scalar_mod_fmpz(rop, rop, len1 + len2 - 1, pow);
if (alloc)
fmpz_clear(pow);
}
void padic_poly_mul(padic_poly_t f,
const padic_poly_t g, const padic_poly_t h,
const padic_ctx_t ctx)
{
const slong lenG = g->length;
const slong lenH = h->length;
const slong lenF = lenG + lenH - 1;
if (lenG == 0 || lenH == 0 || g->val + h->val >= f->N)
{
padic_poly_zero(f);
}
else
{
fmpz *t;
if (f == g || f == h)
{
t = _fmpz_vec_init(lenF);
}
else
{
padic_poly_fit_length(f, lenF);
t = f->coeffs;
}
if (lenG >= lenH)
_padic_poly_mul(t, &(f->val), f->N, g->coeffs, g->val, lenG,
h->coeffs, h->val, lenH, ctx);
else
_padic_poly_mul(t, &(f->val), f->N, h->coeffs, h->val, lenH,
g->coeffs, g->val, lenG, ctx);
if (f == g || f == h)
{
_fmpz_vec_clear(f->coeffs, f->alloc);
f->coeffs = t;
f->alloc = lenF;
}
_padic_poly_set_length(f, lenF);
_padic_poly_normalise(f);
}
}

64
external/flint-2.4.3/padic_poly/neg.c vendored Normal file
View File

@@ -0,0 +1,64 @@
/*============================================================================
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, 2012 Sebastian Pancratz
******************************************************************************/
#include "fmpz_mod_poly.h"
#include "padic_poly.h"
void padic_poly_neg(padic_poly_t f, const padic_poly_t g,
const padic_ctx_t ctx)
{
const slong len = g->length;
if (len == 0 || g->val >= padic_poly_prec(f))
{
padic_poly_zero(f);
}
else
{
fmpz_t pow;
int alloc;
padic_poly_fit_length(f, len);
_padic_poly_set_length(f, len);
f->val = g->val;
alloc = _padic_ctx_pow_ui(pow, padic_poly_prec(f) - f->val, ctx);
if (padic_poly_prec(f) >= padic_poly_prec(g)) /* No reduction */
{
_fmpz_mod_poly_neg(f->coeffs, g->coeffs, len, pow);
}
else /* Reduction necessary? */
{
_fmpz_vec_scalar_mod_fmpz(f->coeffs, g->coeffs, len, pow);
_fmpz_mod_poly_neg(f->coeffs, f->coeffs, len, pow);
_padic_poly_normalise(f);
}
if (alloc)
fmpz_clear(pow);
}
}

View File

@@ -0,0 +1,38 @@
/*=============================================================================
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) 2008, 2009 William Hart
Copyright (C) 2011 Sebastian Pancratz
******************************************************************************/
#include "fmpz_vec.h"
#include "padic_poly.h"
void _padic_poly_normalise(padic_poly_t poly)
{
slong len = poly->length;
FMPZ_VEC_NORM(poly->coeffs, len);
poly->length = len;
}

89
external/flint-2.4.3/padic_poly/pow.c vendored Normal file
View File

@@ -0,0 +1,89 @@
/*============================================================================
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) 2012 Sebastian Pancratz
******************************************************************************/
#include "fmpz_mod_poly.h"
#include "padic_poly.h"
void _padic_poly_pow(fmpz *rop, slong *rval, slong N,
const fmpz *op, slong val, slong len, ulong e,
const padic_ctx_t ctx)
{
fmpz_t pow;
int alloc;
*rval = (slong) e * val;
alloc = _padic_ctx_pow_ui(pow, N - *rval, ctx);
_fmpz_mod_poly_pow(rop, op, len, e, pow);
if (alloc)
fmpz_clear(pow);
}
void padic_poly_pow(padic_poly_t rop, const padic_poly_t op, ulong e,
const padic_ctx_t ctx)
{
if (e == 0)
{
padic_poly_one(rop);
}
else if (op->length == 0 || (slong) e * op->val >= rop->N)
{
padic_poly_zero(rop);
}
else if (e == 1)
{
padic_poly_set(rop, op, ctx);
}
else
{
const slong rlen = (slong) e * (op->length - 1) + 1;
fmpz *t;
if (rop == op)
{
t = _fmpz_vec_init(rlen);
}
else
{
padic_poly_fit_length(rop, rlen);
t = rop->coeffs;
}
_padic_poly_pow(t, &(rop->val), rop->N,
op->coeffs, op->val, op->length, e, ctx);
if (rop == op)
{
_fmpz_vec_clear(rop->coeffs, rop->alloc);
rop->coeffs = t;
rop->alloc = rlen;
}
_padic_poly_set_length(rop, rlen);
_padic_poly_normalise(rop);
}
}

View File

@@ -0,0 +1,127 @@
/*=============================================================================
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, 2012 Sebastian Pancratz
Copyright (C) 2009 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "flint.h"
#include "padic_poly.h"
void padic_poly_randtest_val(padic_poly_t f, flint_rand_t state,
slong val, slong len, const padic_ctx_t ctx)
{
const slong N = padic_poly_prec(f);
if (len == 0)
return;
if (val >= N)
{
padic_poly_zero(f);
}
else
{
slong i;
fmpz_t pow;
int alloc;
f->val = val;
padic_poly_fit_length(f, len);
alloc = _padic_ctx_pow_ui(pow, N - f->val, ctx);
for (i = 0; i < len; i++)
fmpz_randm(f->coeffs + i, state, pow);
if (alloc)
fmpz_clear(pow);
for (i = 0; i < len; i++)
if (!fmpz_divisible(f->coeffs + i, ctx->p))
break;
if (i == len)
fmpz_one(f->coeffs + n_randint(state, len));
_padic_poly_set_length(f, len);
_padic_poly_normalise(f);
padic_poly_reduce(f, ctx);
}
}
void padic_poly_randtest(padic_poly_t f, flint_rand_t state,
slong len, const padic_ctx_t ctx)
{
const slong N = padic_poly_prec(f);
slong min, max, val;
if (N > 0)
{
min = - ((N + 9) / 10);
max = N;
}
else if (N < 0)
{
min = N - ((-N + 9) / 10);
max = N;
}
else /* N == 0 */
{
min = -10;
max = 0;
}
val = n_randint(state, max - min) + min;
padic_poly_randtest_val(f, state, val, len, ctx);
}
void padic_poly_randtest_not_zero(padic_poly_t f, flint_rand_t state,
slong len, const padic_ctx_t ctx)
{
slong i;
if (len == 0)
{
flint_printf("Exception (padic_poly_randtest_not_zero). len == 0.\n");
abort();
}
padic_poly_randtest(f, state, len, ctx);
for (i = 0; !padic_poly_is_zero(f) && (i < 10); i++)
padic_poly_randtest(f, state, len, ctx);
if (padic_poly_is_zero(f))
{
padic_poly_fit_length(f, 1);
_padic_poly_set_length(f, 1);
fmpz_one(f->coeffs + 0);
f->val = f->N - 1;
}
}

View File

@@ -0,0 +1,57 @@
/*=============================================================================
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) 2008, 2009 William Hart
Copyright (C) 2011 Sebastian Pancratz
******************************************************************************/
#include <gmp.h>
#include <stdlib.h>
#include "flint.h"
#include "fmpz.h"
#include "padic_poly.h"
void padic_poly_realloc(padic_poly_t poly, slong alloc, const fmpz_t p)
{
if (alloc == 0) /* Clear up, reinitialise */
{
padic_poly_clear(poly);
padic_poly_init(poly);
return;
}
if (poly->alloc) /* Realloc */
{
padic_poly_truncate(poly, alloc, p);
poly->coeffs = (fmpz *) flint_realloc(poly->coeffs, alloc * sizeof(fmpz));
if (alloc > poly->alloc)
mpn_zero((mp_ptr) (poly->coeffs + poly->alloc),
alloc - poly->alloc);
}
else /* Nothing allocated already so do it now */
{
poly->coeffs = (fmpz *) flint_calloc(alloc, sizeof(fmpz));
}
poly->alloc = alloc;
}

View File

@@ -0,0 +1,59 @@
/*============================================================================
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, 2012 Sebastian Pancratz
******************************************************************************/
#include "padic_poly.h"
void padic_poly_reduce(padic_poly_t poly, const padic_ctx_t ctx)
{
const slong N = padic_poly_prec(poly);
if (poly->length > 0)
{
if (poly->val >= N)
{
padic_poly_zero(poly);
}
else
{
fmpz_t pow;
int alloc;
alloc = _padic_ctx_pow_ui(pow, N - poly->val, ctx);
_fmpz_vec_scalar_mod_fmpz(poly->coeffs, poly->coeffs, poly->length, pow);
if (alloc)
fmpz_clear(pow);
_padic_poly_normalise(poly);
if (poly->length == 0)
{
poly->val = 0;
}
}
}
}

View File

@@ -0,0 +1,72 @@
/*============================================================================
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, 2012 Sebastian Pancratz
******************************************************************************/
#include "padic_poly.h"
void _padic_poly_scalar_mul_padic(fmpz *rop, slong *rval, slong N,
const fmpz *op, slong val, slong len,
const padic_t c, const padic_ctx_t ctx)
{
if (padic_is_zero(c) || val + padic_val(c) >= N)
{
_fmpz_vec_zero(rop, len);
*rval = 0;
}
else
{
fmpz_t pow;
int alloc;
*rval = val + padic_val(c);
alloc = _padic_ctx_pow_ui(pow, N - *rval, ctx);
_fmpz_vec_scalar_mul_fmpz(rop, op, len, padic_unit(c));
_fmpz_vec_scalar_mod_fmpz(rop, rop, len, pow);
if (alloc)
fmpz_clear(pow);
}
}
void padic_poly_scalar_mul_padic(padic_poly_t rop, const padic_poly_t op,
const padic_t c, const padic_ctx_t ctx)
{
if (padic_poly_is_zero(op) || padic_is_zero(c) ||
op->val + padic_val(c) >= rop->N)
{
padic_poly_zero(rop);
}
else
{
padic_poly_fit_length(rop, op->length);
_padic_poly_set_length(rop, op->length);
_padic_poly_scalar_mul_padic(rop->coeffs, &(rop->val), rop->N,
op->coeffs, op->val, op->length, c, ctx);
}
}

69
external/flint-2.4.3/padic_poly/set.c vendored Normal file
View File

@@ -0,0 +1,69 @@
/*============================================================================
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, 2012 Sebastian Pancratz
******************************************************************************/
#include "padic_poly.h"
void padic_poly_set(padic_poly_t poly1,
const padic_poly_t poly2, const padic_ctx_t ctx)
{
if (poly1 != poly2) /* Aliasing is trivial */
{
slong len2 = poly2->length, N1 = padic_poly_prec(poly1);
if (len2 == 0 || poly2->val >= N1)
{
padic_poly_zero(poly1);
}
else
{
padic_poly_fit_length(poly1, len2);
_padic_poly_set_length(poly1, len2);
poly1->val = poly2->val;
if (N1 >= padic_poly_prec(poly2)) /* No reduction */
{
_fmpz_vec_set(poly1->coeffs, poly2->coeffs, len2);
}
else /* Reduction necessary */
{
fmpz_t pow;
int alloc;
alloc = _padic_ctx_pow_ui(pow, N1 - poly1->val, ctx);
_fmpz_vec_scalar_mod_fmpz(poly1->coeffs, poly2->coeffs, len2, pow);
if (alloc)
fmpz_clear(pow);
_padic_poly_normalise(poly1);
/* Length cannot be zero, so no need to check */
/* if (poly->length == 0) */
/* poly->val = 0; */
}
}
}
}

View File

@@ -0,0 +1,89 @@
/*============================================================================
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, 2012 Sebastian Pancratz
******************************************************************************/
#include "padic_poly.h"
void padic_poly_set_coeff_padic(padic_poly_t poly, slong n, const padic_t x,
const padic_ctx_t ctx)
{
if (padic_is_zero(x) || padic_val(x) >= padic_poly_prec(poly))
{
if (n < poly->length)
{
fmpz_zero(poly->coeffs + n);
padic_poly_canonicalise(poly, ctx->p);
}
return;
}
padic_poly_fit_length(poly, n + 1);
if (n + 1 > poly->length)
{
mpn_zero((mp_ptr) (poly->coeffs + poly->length), n - poly->length);
poly->length = n + 1;
}
if (padic_val(x) == poly->val)
{
fmpz_set(poly->coeffs + n, padic_unit(x));
}
else if (poly->val < padic_val(x))
{
fmpz_t y;
fmpz_init(y);
fmpz_pow_ui(y, ctx->p, padic_val(x) - poly->val);
fmpz_mul(poly->coeffs + n, padic_unit(x), y);
fmpz_clear(y);
padic_poly_canonicalise(poly, ctx->p);
}
else /* poly->val > x->val */
{
fmpz_t pow;
fmpz_init(pow);
fmpz_pow_ui(pow, ctx->p, poly->val - padic_val(x));
_fmpz_vec_scalar_mul_fmpz(poly->coeffs,
poly->coeffs, poly->length, pow);
fmpz_set(poly->coeffs + n, padic_unit(x));
fmpz_clear(pow);
poly->val = padic_val(x);
}
if (padic_poly_prec(poly) < padic_prec(x)) /* Reduction? */
{
int c;
fmpz_t pow;
c = _padic_ctx_pow_ui(pow, padic_poly_prec(poly) - padic_poly_val(poly), ctx);
fmpz_mod(poly->coeffs + n, poly->coeffs + n, pow);
if (c)
fmpz_clear(pow);
}
_padic_poly_normalise(poly);
}

View File

@@ -0,0 +1,38 @@
/*============================================================================
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, 2012 Sebastian Pancratz
******************************************************************************/
#include "padic_poly.h"
void padic_poly_set_fmpq(padic_poly_t poly, const fmpq_t x,
const padic_ctx_t ctx)
{
padic_t y;
padic_init2(y, padic_poly_prec(poly));
padic_set_fmpq(y, x, ctx);
padic_poly_set_padic(poly, y, ctx);
padic_clear(y);
}

View File

@@ -0,0 +1,68 @@
/*============================================================================
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 "fmpz_vec.h"
#include "fmpq_poly.h"
#include "padic_poly.h"
void padic_poly_set_fmpq_poly(padic_poly_t f,
const fmpq_poly_t g, const padic_ctx_t ctx)
{
const slong len = g->length;
if (len == 0)
{
padic_poly_zero(f);
}
else
{
const slong N = padic_poly_prec(f);
fmpz_t t;
fmpz_init(t);
f->val = - fmpz_remove(t, g->den, ctx->p);
if (f->val < N)
{
padic_poly_fit_length(f, len);
_padic_poly_set_length(f, len);
_padic_inv(t, t, ctx->p, N - f->val);
_fmpz_vec_scalar_mul_fmpz(f->coeffs, g->coeffs, len, t);
if (f->val == 0)
padic_poly_canonicalise(f, ctx->p);
padic_poly_reduce(f, ctx);
}
else
{
padic_poly_zero(f);
}
fmpz_clear(t);
}
}

View File

@@ -0,0 +1,38 @@
/*============================================================================
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, 2012 Sebastian Pancratz
******************************************************************************/
#include "padic_poly.h"
void padic_poly_set_fmpz(padic_poly_t poly, const fmpz_t x,
const padic_ctx_t ctx)
{
padic_t y;
padic_init2(y, padic_poly_prec(poly));
padic_set_fmpz(y, x, ctx);
padic_poly_set_padic(poly, y, ctx);
padic_clear(y);
}

View File

@@ -0,0 +1,42 @@
/*============================================================================
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 "fmpz_poly.h"
#include "padic_poly.h"
void padic_poly_set_fmpz_poly(padic_poly_t f, const fmpz_poly_t g,
const padic_ctx_t ctx)
{
const slong len = g->length;
padic_poly_fit_length(f, len);
_padic_poly_set_length(f, len);
_fmpz_vec_set(f->coeffs, g->coeffs, len);
f->val = 0;
padic_poly_canonicalise(f, ctx->p);
padic_poly_reduce(f, ctx);
}

View File

@@ -0,0 +1,61 @@
/*============================================================================
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, 2012 Sebastian Pancratz
******************************************************************************/
#include "padic_poly.h"
void padic_poly_set_padic(padic_poly_t poly,
const padic_t x, const padic_ctx_t ctx)
{
slong N1 = padic_poly_prec(poly);
if (padic_is_zero(x) || padic_val(x) >= N1)
{
padic_poly_zero(poly);
}
else
{
padic_poly_fit_length(poly, 1);
_padic_poly_set_length(poly, 1);
poly->val = padic_val(x);
if (N1 >= padic_prec(x)) /* No reduction */
{
fmpz_set(poly->coeffs, padic_unit(x));
}
else /* Reduction */
{
fmpz_t pow;
int alloc;
alloc = _padic_ctx_pow_ui(pow, N1 - padic_val(x), ctx);
fmpz_mod(poly->coeffs, padic_unit(x), pow);
if (alloc)
fmpz_clear(pow);
}
}
}

View File

@@ -0,0 +1,37 @@
/*============================================================================
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, 2012 Sebastian Pancratz
******************************************************************************/
#include "padic_poly.h"
void padic_poly_set_si(padic_poly_t poly, slong x, const padic_ctx_t ctx)
{
padic_t y;
padic_init2(y, padic_poly_prec(poly));
padic_set_si(y, x, ctx);
padic_poly_set_padic(poly, y, ctx);
padic_clear(y);
}

View File

@@ -0,0 +1,37 @@
/*============================================================================
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, 2012 Sebastian Pancratz
******************************************************************************/
#include "padic_poly.h"
void padic_poly_set_ui(padic_poly_t poly, ulong x, const padic_ctx_t ctx)
{
padic_t y;
padic_init2(y, padic_poly_prec(poly));
padic_set_ui(y, x, ctx);
padic_poly_set_padic(poly, y, ctx);
padic_clear(y);
}

View 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) 2012 Sebastian Pancratz
******************************************************************************/
#include "padic_poly.h"
void padic_poly_shift_left(padic_poly_t rop, const padic_poly_t op, slong n,
const padic_ctx_t ctx)
{
if (rop->N < op->N)
{
flint_printf("Exception (padic_poly_shift_left). rop->N < op->N.\n");
abort();
}
if (n == 0)
{
padic_poly_set(rop, op, ctx);
}
else if (op->length == 0)
{
padic_poly_zero(rop);
}
else
{
padic_poly_fit_length(rop, op->length + n);
_fmpz_poly_shift_left(rop->coeffs, op->coeffs, op->length, n);
rop->val = op->val;
_padic_poly_set_length(rop, op->length + n);
/* TODO: Reduce */
}
}

View 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) 2012 Sebastian Pancratz
******************************************************************************/
#include "padic_poly.h"
void padic_poly_shift_right(padic_poly_t rop, const padic_poly_t op, slong n,
const padic_ctx_t ctx)
{
if (n == 0)
{
padic_poly_set(rop, op, ctx);
}
else if (op->length <= n)
{
padic_poly_zero(rop);
}
else
{
padic_poly_fit_length(rop, op->length - n);
_fmpz_poly_shift_right(rop->coeffs, op->coeffs, op->length, n);
rop->val = op->val;
_padic_poly_set_length(rop, op->length - n);
_padic_poly_normalise(rop);
padic_poly_canonicalise(rop, ctx->p);
/* TODO: Reduce */
}
}

146
external/flint-2.4.3/padic_poly/sub.c vendored Normal file
View 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, 2012 Sebastian Pancratz
******************************************************************************/
#include "fmpz_mod_poly.h"
#include "padic_poly.h"
void _padic_poly_sub(fmpz *rop, slong *val, slong N,
const fmpz *op1, slong val1, slong len1, slong N1,
const fmpz *op2, slong val2, slong len2, slong N2,
const padic_ctx_t ctx)
{
const slong len = FLINT_MAX(len1, len2);
*val = FLINT_MIN(val1, val2);
if (val1 == val2)
{
_fmpz_poly_sub(rop, op1, len1, op2, len2);
_padic_poly_canonicalise(rop, val, len, ctx->p);
}
else
{
fmpz_t x;
fmpz_init(x);
if (val1 < val2) /* F := p^g (G - p^{h-g} H) */
{
fmpz_pow_ui(x, ctx->p, val2 - val1);
if (rop == op1)
{
_fmpz_vec_zero(rop + len1, len2 - len1);
_fmpz_vec_scalar_submul_fmpz(rop, op2, len2, x);
}
else
{
_fmpz_vec_scalar_mul_fmpz(rop, op2, len2, x);
_fmpz_vec_neg(rop, rop, len2);
_fmpz_poly_add(rop, op1, len1, rop, len2);
}
}
else /* F := p^h (p^(g-h) G - H) */
{
fmpz_pow_ui(x, ctx->p, val1 - val2);
if (rop == op2)
{
_fmpz_vec_neg(rop, op2, len2);
_fmpz_vec_zero(rop + len2, len1 - len2);
_fmpz_vec_scalar_addmul_fmpz(rop, op1, len1, x);
}
else
{
_fmpz_vec_scalar_mul_fmpz(rop, op1, len1, x);
_fmpz_poly_sub(rop, rop, len1, op2, len2);
}
}
fmpz_clear(x);
}
/* Reduce */
if (N - *val > 0)
{
fmpz_t pow;
int alloc;
alloc = _padic_ctx_pow_ui(pow, N - *val, ctx);
if (N >= N1 && N >= N2)
{
slong i;
for (i = 0; i < len; i++)
if (fmpz_sgn(rop + i) < 0)
fmpz_add(rop + i, rop + i, pow);
}
else
{
_fmpz_vec_scalar_mod_fmpz(rop, rop, len, pow);
}
if (alloc)
fmpz_clear(pow);
}
else
{
_fmpz_vec_zero(rop, len);
*val = 0;
}
}
void padic_poly_sub(padic_poly_t f,
const padic_poly_t g, const padic_poly_t h,
const padic_ctx_t ctx)
{
const slong lenG = g->length;
const slong lenH = h->length;
const slong lenF = FLINT_MAX(lenG, lenH);
if (lenG == 0)
{
padic_poly_neg(f, h, ctx);
return;
}
if (lenH == 0)
{
padic_poly_set(f, g, ctx);
return;
}
if ((lenG == 0 && lenH == 0) || (FLINT_MIN(g->val, h->val) >= f->N))
{
padic_poly_zero(f);
return;
}
padic_poly_fit_length(f, lenF);
_padic_poly_sub(f->coeffs, &(f->val), f->N,
g->coeffs, g->val, lenG, g->N,
h->coeffs, h->val, lenH, h->N, ctx);
_padic_poly_set_length(f, lenF);
_padic_poly_normalise(f);
}

56
external/flint-2.4.3/padic_poly/swap.c vendored Normal file
View File

@@ -0,0 +1,56 @@
/*=============================================================================
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, 2012 Sebastian Pancratz
******************************************************************************/
#include "padic_poly.h"
void padic_poly_swap(padic_poly_t poly1, padic_poly_t poly2)
{
if (poly1 != poly2)
{
slong t;
fmpz *c;
t = poly1->length;
poly1->length = poly2->length;
poly2->length = t;
t = poly1->alloc;
poly1->alloc = poly2->alloc;
poly2->alloc = t;
t = poly1->val;
poly1->val = poly2->val;
poly2->val = t;
t = poly1->N;
poly1->N = poly2->N;
poly2->N = t;
c = poly1->coeffs;
poly1->coeffs = poly2->coeffs;
poly2->coeffs = c;
}
}

View File

@@ -0,0 +1,193 @@
/*=============================================================================
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, 2012 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_poly.h"
#include "long_extras.h"
#include "ulong_extras.h"
#include "padic_poly.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("add... ");
fflush(stdout);
/* Check aliasing of a and c */
for (i = 0; i < 10000; i++)
{
fmpz_t p;
slong N;
padic_ctx_t ctx;
padic_poly_t a, b, c;
fmpz_init_set_ui(p, n_randtest_prime(state, 0));
N = n_randint(state, PADIC_TEST_PREC_MAX - PADIC_TEST_PREC_MIN)
+ PADIC_TEST_PREC_MIN;
padic_ctx_init(ctx, p, FLINT_MAX(0, N-10), FLINT_MAX(0, N+10), PADIC_SERIES);
padic_poly_init2(a, 0, N);
padic_poly_init2(b, 0, N);
padic_poly_init2(c, 0, N);
padic_poly_randtest(a, state, n_randint(state, 100), ctx);
padic_poly_randtest(b, state, n_randint(state, 100), ctx);
padic_poly_add(c, a, b, ctx);
padic_poly_add(a, a, b, ctx);
result = (padic_poly_equal(a, c) && padic_poly_is_reduced(a, ctx));
if (!result)
{
flint_printf("FAIL (alias a, c):\n");
flint_printf("a = "), padic_poly_print(a, ctx), flint_printf("\n\n");
flint_printf("b = "), padic_poly_print(b, ctx), flint_printf("\n\n");
flint_printf("c = "), padic_poly_print(c, ctx), flint_printf("\n\n");
abort();
}
padic_poly_clear(a);
padic_poly_clear(b);
padic_poly_clear(c);
padic_ctx_clear(ctx);
fmpz_clear(p);
}
/* Check aliasing of b and c */
for (i = 0; i < 10000; i++)
{
fmpz_t p;
slong N;
padic_ctx_t ctx;
padic_poly_t a, b, c;
fmpz_init_set_ui(p, n_randtest_prime(state, 0));
N = n_randint(state, PADIC_TEST_PREC_MAX - PADIC_TEST_PREC_MIN)
+ PADIC_TEST_PREC_MIN;
padic_ctx_init(ctx, p, FLINT_MAX(0, N-10), FLINT_MAX(0, N+10), PADIC_SERIES);
padic_poly_init2(a, 0, N);
padic_poly_init2(b, 0, N);
padic_poly_init2(c, 0, N);
padic_poly_randtest(a, state, n_randint(state, 100), ctx);
padic_poly_randtest(b, state, n_randint(state, 100), ctx);
padic_poly_add(c, a, b, ctx);
padic_poly_add(b, a, b, ctx);
result = (padic_poly_equal(b, c) && padic_poly_is_reduced(b, ctx));
if (!result)
{
flint_printf("FAIL (alias b, c):\n");
padic_poly_print(a, ctx), flint_printf("\n\n");
padic_poly_print(b, ctx), flint_printf("\n\n");
padic_poly_print(c, ctx), flint_printf("\n\n");
abort();
}
padic_poly_clear(a);
padic_poly_clear(b);
padic_poly_clear(c);
padic_ctx_clear(ctx);
fmpz_clear(p);
}
/* Compare with Q */
for (i = 0; i < 10000; i++)
{
fmpz_t p;
slong N;
padic_ctx_t ctx;
padic_poly_t a, b, c, d;
fmpq_poly_t x, y, z;
fmpz_init_set_ui(p, n_randtest_prime(state, 0));
N = n_randint(state, PADIC_TEST_PREC_MAX - PADIC_TEST_PREC_MIN)
+ PADIC_TEST_PREC_MIN;
padic_ctx_init(ctx, p, FLINT_MAX(0, N-10), FLINT_MAX(0, N+10), PADIC_SERIES);
padic_poly_init2(a, 0, N);
padic_poly_init2(b, 0, N);
padic_poly_init2(c, 0, N);
padic_poly_init2(d, 0, N);
fmpq_poly_init(x);
fmpq_poly_init(y);
fmpq_poly_init(z);
padic_poly_randtest(b, state, n_randint(state, 50), ctx);
padic_poly_randtest(c, state, n_randint(state, 50), ctx);
padic_poly_add(a, b, c, ctx);
padic_poly_get_fmpq_poly(y, b, ctx);
padic_poly_get_fmpq_poly(z, c, ctx);
fmpq_poly_add(x, y, z);
padic_poly_set_fmpq_poly(d, x, ctx);
result = (padic_poly_equal(a, d) && padic_poly_is_reduced(a, ctx));
if (!result)
{
flint_printf("FAIL (cmp with Q):\n");
flint_printf("N = %wd, val(b) = %wd, val(c) = %wd\n", N, b->val, c->val);
padic_poly_print(c, ctx), flint_printf("\n\n");
padic_poly_print(d, ctx), flint_printf("\n\n");
abort();
}
padic_poly_clear(a);
padic_poly_clear(b);
padic_poly_clear(c);
padic_poly_clear(d);
fmpq_poly_clear(x);
fmpq_poly_clear(y);
fmpq_poly_clear(z);
padic_ctx_clear(ctx);
fmpz_clear(p);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,138 @@
/*=============================================================================
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, 2012 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "long_extras.h"
#include "ulong_extras.h"
#include "padic_poly.h"
int
main(void)
{
int i, result;
padic_ctx_t ctx;
fmpz_t p;
slong N;
FLINT_TEST_INIT(state);
flint_printf("compose... ");
fflush(stdout);
/* Compare with the computation over QQ */
for (i = 0; i < 100; i++)
{
padic_poly_t f, g, h, h2;
fmpq_poly_t fQQ, gQQ, hQQ;
fmpz_init_set_ui(p, n_randtest_prime(state, 0));
N = n_randint(state, PADIC_TEST_PREC_MAX - PADIC_TEST_PREC_MIN)
+ PADIC_TEST_PREC_MIN;
padic_ctx_init(ctx, p, FLINT_MAX(0, N-10), FLINT_MAX(0, N+10), PADIC_SERIES);
padic_poly_init2(f, 0, N);
padic_poly_init2(g, 0, N);
padic_poly_init2(h, 0, N);
padic_poly_init2(h2, 0, N);
fmpq_poly_init(fQQ);
fmpq_poly_init(gQQ);
fmpq_poly_init(hQQ);
padic_poly_randtest(f, state, n_randint(state, 40), ctx);
padic_poly_randtest(g, state, n_randint(state, 15), ctx);
padic_poly_get_fmpq_poly(fQQ, f, ctx);
padic_poly_get_fmpq_poly(gQQ, g, ctx);
padic_poly_compose(h, f, g, ctx);
fmpq_poly_compose(hQQ, fQQ, gQQ);
padic_poly_set_fmpq_poly(h2, hQQ, ctx);
if (padic_poly_val(g) >= 0)
{
result = (padic_poly_equal(h, h2) && padic_poly_is_reduced(h, ctx));
if (!result)
{
flint_printf("FAIL (cmp with QQ, ord_p(g) >= 0):\n");
flint_printf("f = "), padic_poly_print(f, ctx), flint_printf("\n\n");
flint_printf("g = "), padic_poly_print(g, ctx), flint_printf("\n\n");
flint_printf("h = "), padic_poly_debug(h), flint_printf("\n\n");
flint_printf("h2 = "), padic_poly_debug(h2), flint_printf("\n\n");
flint_printf("p = "), fmpz_print(p), flint_printf("\n\n");
flint_printf("N = %wd\n\n", N);
abort();
}
}
else
{
slong N2 = N + (f->length - 1) * padic_poly_val(g);
padic_poly_t hX, h2X;
padic_poly_init2(hX, 0, N2);
padic_poly_init2(h2X, 0, N2);
padic_poly_set(hX, h, ctx);
padic_poly_set(h2X, h2, ctx);
result = (padic_poly_equal(hX, h2X) && padic_poly_is_reduced(hX, ctx));
if (!result)
{
flint_printf("FAIL (cmp with QQ, ord_p(g) < 0):\n");
flint_printf("f = "), padic_poly_print(f, ctx), flint_printf("\n\n");
flint_printf("g = "), padic_poly_print(g, ctx), flint_printf("\n\n");
flint_printf("h = "), padic_poly_print(h, ctx), flint_printf("\n\n");
flint_printf("h2 = "), padic_poly_print(h2, ctx), flint_printf("\n\n");
flint_printf("hX = "), padic_poly_print(hX, ctx), flint_printf("\n\n");
flint_printf("h2X = "), padic_poly_print(h2X, ctx), flint_printf("\n\n");
flint_printf("p = "), fmpz_print(p), flint_printf("\n\n");
flint_printf("N = %wd\n\n", N);
flint_printf("N2 = %wd\n\n", N2);
abort();
}
padic_poly_clear(hX);
padic_poly_clear(h2X);
}
padic_poly_clear(f);
padic_poly_clear(g);
padic_poly_clear(h);
padic_poly_clear(h2);
fmpq_poly_clear(fQQ);
fmpq_poly_clear(gQQ);
fmpq_poly_clear(hQQ);
padic_ctx_clear(ctx);
fmpz_clear(p);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,140 @@
/*=============================================================================
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, 2012 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "long_extras.h"
#include "ulong_extras.h"
#include "padic_poly.h"
int
main(void)
{
int i, result;
padic_ctx_t ctx;
fmpz_t p;
slong N;
FLINT_TEST_INIT(state);
flint_printf("compose_pow... ");
fflush(stdout);
/* Aliasing */
for (i = 0; i < 1000; i++)
{
padic_poly_t a, b, c;
slong k;
fmpz_init_set_ui(p, n_randtest_prime(state, 0));
N = n_randint(state, PADIC_TEST_PREC_MAX - PADIC_TEST_PREC_MIN)
+ PADIC_TEST_PREC_MIN;
padic_ctx_init(ctx, p, FLINT_MAX(0, N-10), FLINT_MAX(0, N+10), PADIC_SERIES);
padic_poly_init2(a, 0, N);
padic_poly_init2(b, 0, N);
padic_poly_init2(c, 0, N);
padic_poly_randtest(a, state, n_randint(state, 100), ctx);
padic_poly_set(b, a, ctx);
k = n_randint(state, 20) + 1;
padic_poly_compose_pow(c, b, k, ctx);
padic_poly_compose_pow(b, b, k, ctx);
result = (padic_poly_equal(b, c) && padic_poly_is_reduced(b, ctx));
if (!result)
{
flint_printf("FAIL (aliasing):\n");
padic_poly_print(a, ctx), flint_printf("\n\n");
padic_poly_print(b, ctx), flint_printf("\n\n");
padic_poly_print(c, ctx), flint_printf("\n\n");
abort();
}
padic_poly_clear(a);
padic_poly_clear(b);
padic_poly_clear(c);
padic_ctx_clear(ctx);
fmpz_clear(p);
}
/* Compare with usual composition */
for (i = 0; i < 1000; i++)
{
padic_poly_t f, g, h1, h2;
slong k;
padic_t one;
fmpz_init_set_ui(p, n_randtest_prime(state, 0));
N = n_randint(state, PADIC_TEST_PREC_MAX - PADIC_TEST_PREC_MIN)
+ PADIC_TEST_PREC_MIN;
padic_ctx_init(ctx, p, FLINT_MAX(0, N-10), FLINT_MAX(0, N+10), PADIC_SERIES);
padic_poly_init2(f, 0, N);
padic_poly_init2(g, 0, WORD_MAX); /* TODO: Check this is OK */
padic_poly_init2(h1, 0, N);
padic_poly_init2(h2, 0, N);
padic_poly_randtest(f, state, n_randint(state, 40), ctx);
k = n_randint(state, 20) + 1;
padic_poly_compose_pow(h1, f, k, ctx);
padic_init(one);
padic_one(one);
padic_poly_set_coeff_padic(g, k, one, ctx);
padic_clear(one);
padic_poly_compose(h2, f, g, ctx);
result = (padic_poly_equal(h1, h2) && padic_poly_is_reduced(h1, ctx));
if (!result)
{
flint_printf("FAIL (cmp with composition):\n");
flint_printf("f = "), padic_poly_print(f, ctx), flint_printf("\n\n");
flint_printf("g = "), padic_poly_print(g, ctx), flint_printf("\n\n");
flint_printf("h1 = "), padic_poly_print(h1, ctx), flint_printf("\n\n");
flint_printf("h2 = "), padic_poly_print(h2, ctx), flint_printf("\n\n");
flint_printf("p = "), fmpz_print(p), flint_printf("\n\n");
flint_printf("N = %wd\n\n", N);
abort();
}
padic_poly_clear(f);
padic_poly_clear(g);
padic_poly_clear(h1);
padic_poly_clear(h2);
padic_ctx_clear(ctx);
fmpz_clear(p);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,138 @@
/*=============================================================================
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) 2012 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "padic_poly.h"
#include "ulong_extras.h"
#include "long_extras.h"
int
main(void)
{
int i, result;
padic_ctx_t ctx;
fmpz_t p;
slong N;
FLINT_TEST_INIT(state);
flint_printf("derivative... ");
fflush(stdout);
/* Aliasing */
for (i = 0; i < 10000; i++)
{
padic_poly_t a, b, c;
fmpz_init_set_ui(p, n_randtest_prime(state, 0));
N = n_randint(state, PADIC_TEST_PREC_MAX - PADIC_TEST_PREC_MIN)
+ PADIC_TEST_PREC_MIN;
padic_ctx_init(ctx, p, FLINT_MAX(0, N-10), FLINT_MAX(0, N+10), PADIC_SERIES);
padic_poly_init2(a, 0, N);
padic_poly_init2(b, 0, N);
padic_poly_init2(c, 0, N);
padic_poly_randtest(a, state, n_randint(state, 100), ctx);
padic_poly_set(b, a, ctx);
padic_poly_derivative(c, b, ctx);
padic_poly_derivative(b, b, ctx);
result = (padic_poly_equal(b, c) && padic_poly_is_reduced(b, ctx));
if (!result)
{
flint_printf("FAIL (alias):\n");
flint_printf("a = "), padic_poly_print(a, ctx), flint_printf("\n\n");
flint_printf("b = "), padic_poly_print(b, ctx), flint_printf("\n\n");
flint_printf("c = "), padic_poly_print(c, ctx), flint_printf("\n\n");
abort();
}
padic_poly_clear(a);
padic_poly_clear(b);
padic_poly_clear(c);
padic_ctx_clear(ctx);
fmpz_clear(p);
}
/* Compare with derivative over QQ */
for (i = 0; i < 10000; i++)
{
padic_poly_t a, b, c;
fmpq_poly_t aQQ, bQQ;
fmpz_init_set_ui(p, n_randtest_prime(state, 0));
N = n_randint(state, PADIC_TEST_PREC_MAX - PADIC_TEST_PREC_MIN)
+ PADIC_TEST_PREC_MIN;
padic_ctx_init(ctx, p, FLINT_MAX(0, N-10), FLINT_MAX(0, N+10), PADIC_SERIES);
padic_poly_init2(a, 0, N);
padic_poly_init2(b, 0, N);
padic_poly_init2(c, 0, N);
padic_poly_randtest(a, state, n_randint(state, 100), ctx);
fmpq_poly_init(aQQ);
fmpq_poly_init(bQQ);
padic_poly_derivative(b, a, ctx);
padic_poly_get_fmpq_poly(aQQ, a, ctx);
fmpq_poly_derivative(bQQ, aQQ);
padic_poly_set_fmpq_poly(c, bQQ, ctx);
result = (padic_poly_equal(b, c) && padic_poly_is_reduced(b, ctx));
if (!result)
{
flint_printf("FAIL (cmp with QQ):\n");
flint_printf("a = "), padic_poly_print(a, ctx), flint_printf("\n\n");
flint_printf("b = "), padic_poly_print(b, ctx), flint_printf("\n\n");
flint_printf("c = "), padic_poly_print(c, ctx), flint_printf("\n\n");
flint_printf("aQQ = "), fmpq_poly_print(aQQ), flint_printf("\n\n");
flint_printf("bQQ = "), fmpq_poly_print(bQQ), flint_printf("\n\n");
abort();
}
padic_poly_clear(a);
padic_poly_clear(b);
padic_poly_clear(c);
fmpq_poly_clear(aQQ);
fmpq_poly_clear(bQQ);
padic_ctx_clear(ctx);
fmpz_clear(p);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,135 @@
/*=============================================================================
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, 2012 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "long_extras.h"
#include "ulong_extras.h"
#include "padic_poly.h"
int
main(void)
{
int i, result;
padic_ctx_t ctx;
fmpz_t p;
slong N;
FLINT_TEST_INIT(state);
flint_printf("evaluate_padic... ");
fflush(stdout);
/* Compare with the computation over QQ */
for (i = 0; i < 200; i++)
{
padic_poly_t f;
fmpq_poly_t fQQ;
padic_t a, y, z;
fmpq_t aQQ, yQQ;
fmpz_init_set_ui(p, n_randtest_prime(state, 0));
N = n_randint(state, PADIC_TEST_PREC_MAX - PADIC_TEST_PREC_MIN)
+ PADIC_TEST_PREC_MIN;
padic_ctx_init(ctx, p, FLINT_MAX(0, N-10), FLINT_MAX(0, N+10), PADIC_SERIES);
padic_poly_init2(f, 0, N);
fmpq_poly_init(fQQ);
padic_init2(a, N);
padic_init2(y, N);
padic_init2(z, N);
fmpq_init(aQQ);
fmpq_init(yQQ);
padic_poly_randtest(f, state, n_randint(state, 80), ctx);
padic_randtest(a, state, ctx);
padic_poly_get_fmpq_poly(fQQ, f, ctx);
padic_get_fmpq(aQQ, a, ctx);
padic_poly_evaluate_padic(y, f, a, ctx);
fmpq_poly_evaluate_fmpq(yQQ, fQQ, aQQ);
padic_set_fmpq(z, yQQ, ctx);
if (padic_val(a) >= 0)
{
result = (padic_equal(y, z));
if (!result)
{
flint_printf("FAIL (cmp with QQ):\n");
flint_printf("f = "), padic_poly_print(f, ctx), flint_printf("\n\n");
flint_printf("a = "), padic_print(a, ctx), flint_printf("\n\n");
flint_printf("y = "), padic_print(y, ctx), flint_printf("\n\n");
flint_printf("z = "), padic_print(z, ctx), flint_printf("\n\n");
abort();
}
}
else
{
slong N2 = N + (f->length - 1) * padic_val(a);
padic_t y2, z2;
padic_init2(y2, N2);
padic_init2(z2, N2);
padic_set(y2, y, ctx);
padic_set(z2, z, ctx);
result = (padic_equal(y2, z2));
if (!result)
{
flint_printf("FAIL (cmp with QQ):\n");
flint_printf("f = "), padic_poly_print(f, ctx), flint_printf("\n\n");
flint_printf("a = "), padic_print(a, ctx), flint_printf("\n\n");
flint_printf("y = "), padic_print(y, ctx), flint_printf("\n\n");
flint_printf("z = "), padic_print(z, ctx), flint_printf("\n\n");
flint_printf("y2 = "), padic_print(y2, ctx), flint_printf("\n\n");
flint_printf("z2 = "), padic_print(z2, ctx), flint_printf("\n\n");
abort();
}
padic_clear(y2);
padic_clear(z2);
}
padic_poly_clear(f);
fmpq_poly_clear(fQQ);
padic_clear(a);
padic_clear(y);
padic_clear(z);
fmpq_clear(aQQ);
fmpq_clear(yQQ);
padic_ctx_clear(ctx);
fmpz_clear(p);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,90 @@
/*=============================================================================
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, 2012 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "flint.h"
#include "long_extras.h"
#include "ulong_extras.h"
#include "padic_poly.h"
int
main(void)
{
int i, result;
padic_ctx_t ctx;
fmpz_t p;
slong N;
FLINT_TEST_INIT(state);
flint_printf("get/set_fmpq_poly... ");
fflush(stdout);
/* Qp -> Q -> Qp */
for (i = 0; i < 10000; i++)
{
padic_poly_t a, b;
fmpq_poly_t c;
fmpz_init_set_ui(p, n_randtest_prime(state, 0));
N = n_randint(state, PADIC_TEST_PREC_MAX - PADIC_TEST_PREC_MIN)
+ PADIC_TEST_PREC_MIN;
padic_ctx_init(ctx, p, FLINT_MAX(0, N-10), FLINT_MAX(0, N+10), PADIC_SERIES);
padic_poly_init2(a, 0, N);
padic_poly_init2(b, 0, N);
fmpq_poly_init(c);
padic_poly_randtest(a, state, n_randint(state, 10), ctx);
padic_poly_get_fmpq_poly(c, a, ctx);
padic_poly_set_fmpq_poly(b, c, ctx);
result = (padic_poly_equal(a, b) && padic_poly_is_reduced(a, ctx));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a = "), padic_poly_debug(a), flint_printf("\n\n");
flint_printf("b = "), padic_poly_debug(b), flint_printf("\n\n");
flint_printf("c = "), fmpq_poly_print(c), flint_printf("\n\n");
abort();
}
padic_poly_clear(a);
padic_poly_clear(b);
fmpq_poly_clear(c);
padic_ctx_clear(ctx);
fmpz_clear(p);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,98 @@
/*=============================================================================
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, 2012 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_poly.h"
#include "long_extras.h"
#include "ulong_extras.h"
#include "padic_poly.h"
int
main(void)
{
int i;
FLINT_TEST_INIT(state);
flint_printf("init/init2/realloc/clear... ");
fflush(stdout);
for (i = 0; i < 10000; i++)
{
padic_poly_t a;
padic_poly_init2(a, n_randint(state, 100), PADIC_DEFAULT_PREC);
padic_poly_clear(a);
}
for (i = 0; i < 10000; i++)
{
slong N;
fmpz_t p;
padic_poly_t a;
fmpz_init_set_ui(p, 7);
N = n_randint(state, PADIC_TEST_PREC_MAX - PADIC_TEST_PREC_MIN)
+ PADIC_TEST_PREC_MIN;
padic_poly_init2(a, n_randint(state, 100), N);
padic_poly_realloc(a, n_randint(state, 100), p);
padic_poly_clear(a);
fmpz_clear(p);
}
for (i = 0; i < 10000; i++)
{
padic_ctx_t ctx;
fmpz_t p;
slong N;
padic_poly_t a;
fmpz_init_set_ui(p, n_randtest_prime(state, 0));
N = n_randint(state, PADIC_TEST_PREC_MAX - PADIC_TEST_PREC_MIN)
+ PADIC_TEST_PREC_MIN;
padic_ctx_init(ctx, p, FLINT_MAX(0, N-10), FLINT_MAX(0, N+10), PADIC_SERIES);
padic_poly_init2(a, 0, N);
padic_poly_randtest(a, state, n_randint(state, 100), ctx);
padic_poly_clear(a);
padic_ctx_clear(ctx);
fmpz_clear(p);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,170 @@
/*=============================================================================
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, 2012 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "long_extras.h"
#include "ulong_extras.h"
#include "padic_poly.h"
int
main(void)
{
int i, result;
padic_ctx_t ctx;
fmpz_t p;
slong N;
FLINT_TEST_INIT(state);
flint_printf("inv_series... ");
fflush(stdout);
/* Check aliasing */
for (i = 0; i < 1000; i++)
{
padic_poly_t a, b, c;
slong n;
fmpz_init_set_ui(p, n_randtest_prime(state, 0));
N = n_randint(state, PADIC_TEST_PREC_MAX - PADIC_TEST_PREC_MIN)
+ PADIC_TEST_PREC_MIN;
padic_ctx_init(ctx, p, FLINT_MAX(0, N-10), FLINT_MAX(0, N+10), PADIC_SERIES);
padic_poly_init2(a, 0, N);
padic_poly_init2(b, 0, N);
padic_poly_init2(c, 0, N);
padic_poly_randtest(a, state, n_randint(state, 100) + 1, ctx);
if (fmpz_is_zero(a->coeffs))
{
fmpz_randtest_not_zero(a->coeffs, state, 20);
fmpz_remove(a->coeffs, a->coeffs, p);
padic_poly_reduce(a, ctx);
} else
fmpz_remove(a->coeffs, a->coeffs, p);
padic_poly_set(b, a, ctx);
n = n_randint(state, 100) + 1;
padic_poly_inv_series(c, b, n, ctx);
padic_poly_inv_series(b, b, n, ctx);
result = (padic_poly_equal(b, c) && padic_poly_is_reduced(b, ctx));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a = "), padic_poly_print(a, ctx), flint_printf("\n\n");
flint_printf("b = "), padic_poly_print(b, ctx), flint_printf("\n\n");
flint_printf("c = "), padic_poly_print(c, ctx), flint_printf("\n\n");
abort();
}
padic_poly_clear(a);
padic_poly_clear(b);
padic_poly_clear(c);
padic_ctx_clear(ctx);
fmpz_clear(p);
}
/*
Check correctness:
If ord_p(a) = v then we can compute b = a^{-1} mod p^N
and we will have a b = 1 mod p^{N-|v|}. Thus, require
that N - |v| > 0.
*/
for (i = 0; i < 1000; i++)
{
padic_poly_t a, b, c;
slong n, N2;
fmpz_init_set_ui(p, n_randtest_prime(state, 0));
N = n_randint(state, PADIC_TEST_PREC_MAX - 1) + 1;
padic_ctx_init(ctx, p, FLINT_MAX(0, N-10), FLINT_MAX(0, N+10), PADIC_SERIES);
padic_poly_init2(a, 0, N);
padic_poly_init2(b, 0, N);
{
slong i, len = n_randint(state, 10) + 1;
int alloc;
fmpz_t pow;
padic_poly_fit_length(a, len);
_padic_poly_set_length(a, len);
a->val = n_randint(state, N);
if (n_randint(state, 2))
a->val = - a->val;
alloc = _padic_ctx_pow_ui(pow, N - a->val, ctx);
for (i = 0; i < len; i++)
fmpz_randm(a->coeffs + i, state, pow);
while (fmpz_is_zero(a->coeffs))
fmpz_randm(a->coeffs, state, pow);
fmpz_remove(a->coeffs, a->coeffs, p);
_padic_poly_normalise(a);
if (alloc)
fmpz_clear(pow);
}
n = n_randint(state, 100) + 1;
N2 = N - FLINT_ABS(a->val);
padic_poly_init2(c, 0, N2);
padic_poly_inv_series(b, a, n, ctx);
padic_poly_mul(c, a, b, ctx);
padic_poly_truncate(c, n, p);
result = (padic_poly_is_one(c) && padic_poly_is_reduced(b, ctx));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a = "), padic_poly_print(a, ctx), flint_printf("\n\n");
flint_printf("b = "), padic_poly_print(b, ctx), flint_printf("\n\n");
flint_printf("c = "), padic_poly_print(c, ctx), flint_printf("\n\n");
flint_printf("N = %wd\n", N);
flint_printf("N2 = %wd\n", N2);
abort();
}
padic_poly_clear(a);
padic_poly_clear(b);
padic_poly_clear(c);
padic_ctx_clear(ctx);
fmpz_clear(p);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,247 @@
/*=============================================================================
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, 2011 Sebastian Pancratz
Copyright (C) 2009 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "padic_poly.h"
#include "ulong_extras.h"
#include "long_extras.h"
int
main(void)
{
int i, result;
padic_ctx_t ctx;
fmpz_t p;
slong N;
FLINT_TEST_INIT(state);
flint_printf("mul... ");
fflush(stdout);
/* Check aliasing of a and b */
for (i = 0; i < 1000; i++)
{
padic_poly_t a, b, c;
fmpz_init_set_ui(p, n_randtest_prime(state, 0));
N = n_randint(state, PADIC_TEST_PREC_MAX - PADIC_TEST_PREC_MIN)
+ PADIC_TEST_PREC_MIN;
padic_ctx_init(ctx, p, FLINT_MAX(0, N-10), FLINT_MAX(0, N+10), PADIC_SERIES);
padic_poly_init2(a, 0, N);
padic_poly_init2(b, 0, N);
padic_poly_init2(c, 0, N);
padic_poly_randtest(b, state, n_randint(state, 50), ctx);
padic_poly_randtest(c, state, n_randint(state, 50), ctx);
padic_poly_mul(a, b, c, ctx);
padic_poly_mul(b, b, c, ctx);
result = (padic_poly_equal(a, b) && padic_poly_is_reduced(a, ctx));
if (!result)
{
flint_printf("FAIL (aliasing a and b):\n");
padic_poly_print(a, ctx), flint_printf("\n\n");
padic_poly_print(b, ctx), flint_printf("\n\n");
abort();
}
padic_poly_clear(a);
padic_poly_clear(b);
padic_poly_clear(c);
padic_ctx_clear(ctx);
fmpz_clear(p);
}
/* Check aliasing of a and c */
for (i = 0; i < 1000; i++)
{
padic_poly_t a, b, c;
fmpz_init_set_ui(p, n_randtest_prime(state, 0));
N = n_randint(state, PADIC_TEST_PREC_MAX - PADIC_TEST_PREC_MIN)
+ PADIC_TEST_PREC_MIN;
padic_ctx_init(ctx, p, FLINT_MAX(0, N-10), FLINT_MAX(0, N+10), PADIC_SERIES);
padic_poly_init2(a, 0, N);
padic_poly_init2(b, 0, N);
padic_poly_init2(c, 0, N);
padic_poly_randtest(b, state, n_randint(state, 50), ctx);
padic_poly_randtest(c, state, n_randint(state, 50), ctx);
padic_poly_mul(a, b, c, ctx);
padic_poly_mul(c, b, c, ctx);
result = (padic_poly_equal(a, c) && padic_poly_is_reduced(a, ctx));
if (!result)
{
flint_printf("FAIL (aliasing a and c):\n");
padic_poly_print(a, ctx), flint_printf("\n\n");
padic_poly_print(c, ctx), flint_printf("\n\n");
abort();
}
padic_poly_clear(a);
padic_poly_clear(b);
padic_poly_clear(c);
padic_ctx_clear(ctx);
fmpz_clear(p);
}
/* Check (b * c) + (b * d) = b * (c + d) */
for (i = 0; i < 1000; i++)
{
padic_poly_t a1, a2, b, c, d, t;
slong v;
fmpz_init_set_ui(p, n_randtest_prime(state, 0));
N = n_randint(state, PADIC_TEST_PREC_MAX - PADIC_TEST_PREC_MIN)
+ PADIC_TEST_PREC_MIN;
padic_ctx_init(ctx, p, FLINT_MAX(0, N-10), FLINT_MAX(0, N+10), PADIC_SERIES);
padic_poly_init2(b, 0, N);
padic_poly_init2(c, 0, N);
padic_poly_init2(d, 0, N);
padic_poly_init2(t, 0, N);
padic_poly_randtest(b, state, n_randint(state, 100), ctx);
padic_poly_randtest(c, state, n_randint(state, 100), ctx);
padic_poly_randtest(d, state, n_randint(state, 100), ctx);
v = FLINT_MIN(b->val, c->val);
v = FLINT_MIN(v, d->val);
v = FLINT_MIN(v, 0);
if (v >= 0 || -v < N) /* Otherwise, no precision left */
{
slong N2 = (v >= 0) ? N : N + v;
padic_poly_init2(a1, 0, N2);
padic_poly_init2(a2, 0, N2);
padic_poly_mul(a1, b, c, ctx);
padic_poly_mul(t, b, d, ctx);
padic_poly_add(a1, a1, t, ctx); /* Lower precision */
padic_poly_add(t, c, d, ctx);
padic_poly_mul(a2, b, t, ctx); /* Lower precision */
result = (padic_poly_equal(a1, a2) && padic_poly_is_reduced(a1, ctx));
if (!result)
{
flint_printf("FAIL (distributivity):\n");
flint_printf("p = "), fmpz_print(ctx->p), flint_printf("\n\n");
flint_printf("N = %wd\n\n", N);
flint_printf("b = "), padic_poly_print(b, ctx), flint_printf("\n\n");
flint_printf("c = "), padic_poly_print(c, ctx), flint_printf("\n\n");
flint_printf("d = "), padic_poly_print(d, ctx), flint_printf("\n\n");
flint_printf("a1 = "), padic_poly_print(a1, ctx), flint_printf("\n\n");
flint_printf("a2 = "), padic_poly_print(a2, ctx), flint_printf("\n\n");
abort();
}
padic_poly_clear(a1);
padic_poly_clear(a2);
}
padic_poly_clear(b);
padic_poly_clear(c);
padic_poly_clear(d);
padic_ctx_clear(ctx);
fmpz_clear(p);
}
/* Compare with Q */
for (i = 0; i < 10000; i++)
{
padic_poly_t a, b, c, d;
fmpq_poly_t x, y, z;
fmpz_init_set_ui(p, n_randtest_prime(state, 0));
N = n_randint(state, PADIC_TEST_PREC_MAX - PADIC_TEST_PREC_MIN)
+ PADIC_TEST_PREC_MIN;
padic_ctx_init(ctx, p, FLINT_MAX(0, N-10), FLINT_MAX(0, N+10), PADIC_SERIES);
padic_poly_init2(a, 0, N);
padic_poly_init2(b, 0, N);
padic_poly_init2(c, 0, N);
padic_poly_init2(d, 0, N);
fmpq_poly_init(x);
fmpq_poly_init(y);
fmpq_poly_init(z);
padic_poly_randtest(b, state, n_randint(state, 50), ctx);
padic_poly_randtest(c, state, n_randint(state, 50), ctx);
padic_poly_mul(a, b, c, ctx);
padic_poly_get_fmpq_poly(y, b, ctx);
padic_poly_get_fmpq_poly(z, c, ctx);
fmpq_poly_mul(x, y, z);
padic_poly_set_fmpq_poly(d, x, ctx);
result = (padic_poly_equal(a, d) && padic_poly_is_reduced(a, ctx));
if (!result)
{
flint_printf("FAIL (cmp with Q):\n");
flint_printf("N = %wd, val(b) = %wd, val(c) = %wd\n", N, b->val, c->val);
padic_poly_print(c, ctx), flint_printf("\n\n");
padic_poly_print(d, ctx), flint_printf("\n\n");
abort();
}
padic_poly_clear(a);
padic_poly_clear(b);
padic_poly_clear(c);
padic_poly_clear(d);
fmpq_poly_clear(x);
fmpq_poly_clear(y);
fmpq_poly_clear(z);
padic_ctx_clear(ctx);
fmpz_clear(p);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,126 @@
/*=============================================================================
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) 2012 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "padic_poly.h"
#include "ulong_extras.h"
#include "long_extras.h"
int
main(void)
{
int i, result;
fmpz_t p;
slong N;
padic_ctx_t ctx;
FLINT_TEST_INIT(state);
flint_printf("neg... ");
fflush(stdout);
/* Aliasing */
for (i = 0; i < 10000; i++)
{
padic_poly_t a, b, c;
fmpz_init_set_ui(p, n_randtest_prime(state, 0));
N = n_randint(state, PADIC_TEST_PREC_MAX - PADIC_TEST_PREC_MIN)
+ PADIC_TEST_PREC_MIN;
padic_ctx_init(ctx, p, FLINT_MAX(0, N-10), FLINT_MAX(0, N+10), PADIC_SERIES);
padic_poly_init2(a, 0, N);
padic_poly_init2(b, 0, N);
padic_poly_init2(c, 0, N);
padic_poly_randtest(a, state, n_randint(state, 100), ctx);
padic_poly_set(b, a, ctx);
padic_poly_neg(c, b, ctx);
padic_poly_neg(b, b, ctx);
result = (padic_poly_equal(b, c) && padic_poly_is_reduced(b, ctx));
if (!result)
{
flint_printf("FAIL:\n");
padic_poly_print(a, ctx), flint_printf("\n\n");
padic_poly_print(b, ctx), flint_printf("\n\n");
padic_poly_print(c, ctx), flint_printf("\n\n");
abort();
}
padic_poly_clear(a);
padic_poly_clear(b);
padic_poly_clear(c);
padic_ctx_clear(ctx);
fmpz_clear(p);
}
/* Check that --a = a */
for (i = 0; i < 10000; i++)
{
padic_poly_t a, b, c;
fmpz_init_set_ui(p, n_randtest_prime(state, 0));
N = n_randint(state, PADIC_TEST_PREC_MAX - PADIC_TEST_PREC_MIN)
+ PADIC_TEST_PREC_MIN;
padic_ctx_init(ctx, p, FLINT_MAX(0, N-10), FLINT_MAX(0, N+10), PADIC_SERIES);
padic_poly_init2(a, 0, N);
padic_poly_init2(b, 0, N);
padic_poly_init2(c, 0, N);
padic_poly_randtest(a, state, n_randint(state, 100), ctx);
padic_poly_neg(b, a, ctx);
padic_poly_neg(c, b, ctx);
result = (padic_poly_equal(a, c) && padic_poly_is_reduced(a, ctx));
if (!result)
{
flint_printf("FAIL:\n");
padic_poly_print(a, ctx), flint_printf("\n\n");
padic_poly_print(b, ctx), flint_printf("\n\n");
padic_poly_print(c, ctx), flint_printf("\n\n");
abort();
}
padic_poly_clear(a);
padic_poly_clear(b);
padic_poly_clear(c);
padic_ctx_clear(ctx);
fmpz_clear(p);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,83 @@
/*=============================================================================
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, 2011 Sebastian Pancratz
Copyright (C) 2009 William Hart
******************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "padic_poly.h"
#include "ulong_extras.h"
#include "long_extras.h"
int
main(void)
{
int i, result;
padic_ctx_t ctx;
fmpz_t p;
slong N;
FLINT_TEST_INIT(state);
flint_printf("one....");
fflush(stdout);
for (i = 0; i < 10000; i++)
{
padic_poly_t a;
fmpz_init_set_ui(p, n_randtest_prime(state, 0));
N = n_randint(state, PADIC_TEST_PREC_MAX - PADIC_TEST_PREC_MIN)
+ PADIC_TEST_PREC_MIN;
padic_ctx_init(ctx, p, FLINT_MAX(0, N-10), FLINT_MAX(0, N+10), PADIC_SERIES);
padic_poly_init2(a, 0, N);
padic_poly_randtest(a, state, n_randint(state, 100), ctx);
padic_poly_one(a);
result = (padic_poly_is_one(a) || N <= 0);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a = "), padic_poly_print(a, ctx), flint_printf("\n\n");
flint_printf("N = %wd\n\n", N);
abort();
}
padic_poly_clear(a);
padic_ctx_clear(ctx);
fmpz_clear(p);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,172 @@
/*=============================================================================
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) 2012 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "padic_poly.h"
#include "ulong_extras.h"
#include "long_extras.h"
int
main(void)
{
int i, result;
padic_ctx_t ctx;
fmpz_t p;
slong N;
FLINT_TEST_INIT(state);
flint_printf("pow... ");
fflush(stdout);
/* Aliasing */
for (i = 0; i < 1000; i++)
{
padic_poly_t a, b, c;
slong e;
fmpz_init_set_ui(p, n_randtest_prime(state, 0));
N = n_randint(state, PADIC_TEST_PREC_MAX - PADIC_TEST_PREC_MIN)
+ PADIC_TEST_PREC_MIN;
padic_ctx_init(ctx, p, FLINT_MAX(0, N-10), FLINT_MAX(0, N+10), PADIC_SERIES);
padic_poly_init2(a, 0, N);
padic_poly_init2(b, 0, N);
padic_poly_init2(c, 0, N);
padic_poly_randtest(a, state, n_randint(state, 100), ctx);
padic_poly_set(b, a, ctx);
e = n_randint(state, 10);
padic_poly_pow(c, b, e, ctx);
padic_poly_pow(b, b, e, ctx);
result = (padic_poly_equal(b, c) && padic_poly_is_reduced(b, ctx));
if (!result)
{
flint_printf("FAIL:\n");
padic_poly_print(a, ctx), flint_printf("\n\n");
padic_poly_print(b, ctx), flint_printf("\n\n");
padic_poly_print(c, ctx), flint_printf("\n\n");
flint_printf("e = %wd\n\n", e);
abort();
}
padic_poly_clear(a);
padic_poly_clear(b);
padic_poly_clear(c);
padic_ctx_clear(ctx);
fmpz_clear(p);
}
/* Compare with the computation over QQ */
for (i = 0; i < 1000; i++)
{
padic_poly_t a, b, c;
fmpq_poly_t aQQ, bQQ;
slong e;
fmpz_init_set_ui(p, n_randtest_prime(state, 0));
N = n_randint(state, PADIC_TEST_PREC_MAX - PADIC_TEST_PREC_MIN)
+ PADIC_TEST_PREC_MIN;
padic_ctx_init(ctx, p, FLINT_MAX(0, N-10), FLINT_MAX(0, N+10), PADIC_SERIES);
padic_poly_init2(a, 0, N);
padic_poly_init2(b, 0, N);
padic_poly_init2(c, 0, N);
fmpq_poly_init(aQQ);
fmpq_poly_init(bQQ);
padic_poly_randtest(a, state, n_randint(state, 10), ctx);
e = n_randint(state, 10);
padic_poly_pow(b, a, e, ctx);
padic_poly_get_fmpq_poly(aQQ, a, ctx);
fmpq_poly_pow(bQQ, aQQ, e);
padic_poly_set_fmpq_poly(c, bQQ, ctx);
if (e == 0)
{
result = (padic_poly_equal(b, c) && padic_poly_is_reduced(b, ctx));
if (!result)
{
flint_printf("FAIL (cmp with QQ):\n");
padic_poly_print(a, ctx), flint_printf("\n\n");
padic_poly_print(b, ctx), flint_printf("\n\n");
padic_poly_print(c, ctx), flint_printf("\n\n");
abort();
}
}
else
{
padic_poly_t blo, clo;
slong N2 = N + (e - 1) * a->val;
padic_poly_init2(blo, 0, N2);
padic_poly_init2(clo, 0, N2);
padic_poly_set(blo, b, ctx);
padic_poly_set(clo, c, ctx);
result = (padic_poly_equal(blo, clo) && padic_poly_is_reduced(blo, ctx));
if (!result)
{
flint_printf("FAIL (cmp with QQ):\n");
flint_printf("a = "), padic_poly_print(a, ctx), flint_printf("\n\n");
flint_printf("b = "), padic_poly_print(b, ctx), flint_printf("\n\n");
flint_printf("c = "), padic_poly_print(c, ctx), flint_printf("\n\n");
flint_printf("blo = "), padic_poly_print(blo, ctx), flint_printf("\n\n");
flint_printf("clo = "), padic_poly_print(clo, ctx), flint_printf("\n\n");
flint_printf("N = %wd\n\n", N);
flint_printf("e = %wd\n\n", e);
flint_printf("N + (e - 1) v = %wd\n\n", N + (e - 1) * a->val);
abort();
}
padic_poly_clear(blo);
padic_poly_clear(clo);
}
padic_poly_clear(a);
padic_poly_clear(b);
padic_poly_clear(c);
fmpq_poly_clear(aQQ);
fmpq_poly_clear(bQQ);
padic_ctx_clear(ctx);
fmpz_clear(p);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,167 @@
/*=============================================================================
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) 2012 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "padic_poly.h"
#include "ulong_extras.h"
#include "long_extras.h"
int
main(void)
{
int i, result;
padic_ctx_t ctx;
fmpz_t p;
slong N;
FLINT_TEST_INIT(state);
flint_printf("shift_left/right... ");
fflush(stdout);
/* Aliasing for left shift */
for (i = 0; i < 10000; i++)
{
padic_poly_t a, b, c;
slong shift = n_randint(state, 100);
fmpz_init_set_ui(p, n_randtest_prime(state, 0));
N = n_randint(state, PADIC_TEST_PREC_MAX - PADIC_TEST_PREC_MIN)
+ PADIC_TEST_PREC_MIN;
padic_ctx_init(ctx, p, FLINT_MAX(0, N-10), FLINT_MAX(0, N+10), PADIC_SERIES);
padic_poly_init2(a, 0, N);
padic_poly_init2(b, 0, N);
padic_poly_init2(c, 0, N);
padic_poly_randtest(a, state, n_randint(state, 100), ctx);
padic_poly_set(b, a, ctx);
padic_poly_shift_left(c, b, shift, ctx);
padic_poly_shift_left(b, b, shift, ctx);
result = (padic_poly_equal(b, c) && padic_poly_is_reduced(b, ctx));
if (!result)
{
flint_printf("FAIL:\n");
padic_poly_print(a, ctx), flint_printf("\n\n");
padic_poly_print(b, ctx), flint_printf("\n\n");
padic_poly_print(c, ctx), flint_printf("\n\n");
abort();
}
padic_poly_clear(a);
padic_poly_clear(b);
padic_poly_clear(c);
padic_ctx_clear(ctx);
fmpz_clear(p);
}
/* Aliasing for shift right */
for (i = 0; i < 10000; i++)
{
padic_poly_t a, b, c;
slong shift = n_randint(state, 100);
fmpz_init_set_ui(p, n_randtest_prime(state, 0));
N = n_randint(state, PADIC_TEST_PREC_MAX - PADIC_TEST_PREC_MIN)
+ PADIC_TEST_PREC_MIN;
padic_ctx_init(ctx, p, FLINT_MAX(0, N-10), FLINT_MAX(0, N+10), PADIC_SERIES);
padic_poly_init2(a, 0, N);
padic_poly_init2(b, 0, N);
padic_poly_init2(c, 0, N);
padic_poly_randtest(a, state, n_randint(state, 100), ctx);
padic_poly_set(b, a, ctx);
padic_poly_shift_right(c, b, shift, ctx);
padic_poly_shift_right(b, b, shift, ctx);
result = (padic_poly_equal(b, c) && padic_poly_is_reduced(b, ctx));
if (!result)
{
flint_printf("FAIL:\n");
padic_poly_print(a, ctx), flint_printf("\n\n");
padic_poly_print(b, ctx), flint_printf("\n\n");
padic_poly_print(c, ctx), flint_printf("\n\n");
abort();
}
padic_poly_clear(a);
padic_poly_clear(b);
padic_poly_clear(c);
padic_ctx_clear(ctx);
fmpz_clear(p);
}
/* Check shift left then right does nothing */
for (i = 0; i < 10000; i++)
{
padic_poly_t a, b, c;
slong shift = n_randint(state, 100);
fmpz_init_set_ui(p, n_randtest_prime(state, 0));
N = n_randint(state, PADIC_TEST_PREC_MAX - PADIC_TEST_PREC_MIN)
+ PADIC_TEST_PREC_MIN;
padic_ctx_init(ctx, p, FLINT_MAX(0, N-10), FLINT_MAX(0, N+10), PADIC_SERIES);
padic_poly_init2(a, 0, N);
padic_poly_init2(b, 0, N);
padic_poly_init2(c, 0, N);
padic_poly_randtest(a, state, n_randint(state, 100), ctx);
padic_poly_shift_left(b, a, shift, ctx);
padic_poly_shift_right(c, b, shift, ctx);
result = (padic_poly_equal(a, c) && padic_poly_is_reduced(a, ctx));
if (!result)
{
flint_printf("FAIL:\n");
padic_poly_print(a, ctx), flint_printf("\n\n");
padic_poly_print(b, ctx), flint_printf("\n\n");
padic_poly_print(c, ctx), flint_printf("\n\n");
abort();
}
padic_poly_clear(a);
padic_poly_clear(b);
padic_poly_clear(c);
padic_ctx_clear(ctx);
fmpz_clear(p);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,170 @@
/*=============================================================================
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) 2009 Bill Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "ulong_extras.h"
#include "long_extras.h"
#include "padic_poly.h"
int
main(void)
{
int i, result;
fmpz_t p;
slong N;
padic_ctx_t ctx;
FLINT_TEST_INIT(state);
flint_printf("sub... ");
fflush(stdout);
/* Check a - b = a + neg(b) */
for (i = 0; i < 10000; i++)
{
padic_poly_t a, b, c, d;
fmpz_init_set_ui(p, n_randtest_prime(state, 0));
N = n_randint(state, PADIC_TEST_PREC_MAX - PADIC_TEST_PREC_MIN)
+ PADIC_TEST_PREC_MIN;
padic_ctx_init(ctx, p, FLINT_MAX(0, N-10), FLINT_MAX(0, N+10), PADIC_SERIES);
padic_poly_init2(a, 0, N);
padic_poly_init2(b, 0, N);
padic_poly_init2(c, 0, N);
padic_poly_init2(d, 0, N);
padic_poly_randtest(a, state, n_randint(state, 100), ctx);
padic_poly_randtest(b, state, n_randint(state, 100), ctx);
padic_poly_sub(c, a, b, ctx);
padic_poly_neg(b, b, ctx);
padic_poly_add(d, a, b, ctx);
result = (padic_poly_equal(c, d) && padic_poly_is_reduced(c, ctx));
if (!result)
{
flint_printf("FAIL:\n");
padic_poly_print(a, ctx), flint_printf("\n\n");
padic_poly_print(b, ctx), flint_printf("\n\n");
padic_poly_print(c, ctx), flint_printf("\n\n");
padic_poly_print(d, ctx), flint_printf("\n\n");
abort();
}
padic_poly_clear(a);
padic_poly_clear(b);
padic_poly_clear(c);
padic_poly_clear(d);
fmpz_clear(p);
padic_ctx_clear(ctx);
}
/* Check aliasing of a and c */
for (i = 0; i < 10000; i++)
{
padic_poly_t a, b, c;
fmpz_init_set_ui(p, n_randtest_prime(state, 0));
N = n_randint(state, PADIC_TEST_PREC_MAX - PADIC_TEST_PREC_MIN)
+ PADIC_TEST_PREC_MIN;
padic_ctx_init(ctx, p, FLINT_MAX(0, N-10), FLINT_MAX(0, N+10), PADIC_SERIES);
padic_poly_init2(a, 0, N);
padic_poly_init2(b, 0, N);
padic_poly_init2(c, 0, N);
padic_poly_randtest(a, state, n_randint(state, 100), ctx);
padic_poly_randtest(b, state, n_randint(state, 100), ctx);
padic_poly_sub(c, a, b, ctx);
padic_poly_sub(a, a, b, ctx);
result = (padic_poly_equal(a, c) && padic_poly_is_reduced(a, ctx));
if (!result)
{
flint_printf("FAIL:\n");
padic_poly_print(a, ctx), flint_printf("\n\n");
padic_poly_print(b, ctx), flint_printf("\n\n");
padic_poly_print(c, ctx), flint_printf("\n\n");
abort();
}
padic_poly_clear(a);
padic_poly_clear(b);
padic_poly_clear(c);
fmpz_clear(p);
padic_ctx_clear(ctx);
}
/* Check aliasing of b and c */
for (i = 0; i < 10000; i++)
{
padic_poly_t a, b, c;
fmpz_init_set_ui(p, n_randtest_prime(state, 0));
N = n_randint(state, PADIC_TEST_PREC_MAX - PADIC_TEST_PREC_MIN)
+ PADIC_TEST_PREC_MIN;
padic_ctx_init(ctx, p, FLINT_MAX(0, N-10), FLINT_MAX(0, N+10), PADIC_SERIES);
padic_poly_init2(a, 0, N);
padic_poly_init2(b, 0, N);
padic_poly_init2(c, 0, N);
padic_poly_randtest(a, state, n_randint(state, 100), ctx);
padic_poly_randtest(b, state, n_randint(state, 100), ctx);
padic_poly_sub(c, a, b, ctx);
padic_poly_sub(b, a, b, ctx);
result = (padic_poly_equal(b, c) && padic_poly_is_reduced(b, ctx));
if (!result)
{
flint_printf("FAIL:\n");
padic_poly_print(a, ctx), flint_printf("\n\n");
padic_poly_print(b, ctx), flint_printf("\n\n");
padic_poly_print(c, ctx), flint_printf("\n\n");
abort();
}
padic_poly_clear(a);
padic_poly_clear(b);
padic_poly_clear(c);
fmpz_clear(p);
padic_ctx_clear(ctx);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,142 @@
/*=============================================================================
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"
#include "long_extras.h"
#include "ulong_extras.h"
#include "padic_poly.h"
int
main(void)
{
int i, result;
padic_ctx_t ctx;
fmpz_t p;
slong N;
FLINT_TEST_INIT(state);
flint_printf("truncate... ");
fflush(stdout);
/* Check repeated truncating */
for (i = 0; i < 10000; i++)
{
padic_poly_t a, b, c;
slong m, n;
fmpz_init_set_ui(p, n_randtest_prime(state, 0));
N = n_randint(state, PADIC_TEST_PREC_MAX - PADIC_TEST_PREC_MIN)
+ PADIC_TEST_PREC_MIN;
padic_ctx_init(ctx, p, FLINT_MAX(0, N-10), FLINT_MAX(0, N+10), PADIC_SERIES);
padic_poly_init2(a, 0, N);
padic_poly_init2(b, 0, N);
padic_poly_init2(c, 0, N);
padic_poly_randtest(a, state, n_randint(state, 100), ctx);
padic_poly_set(b, a, ctx);
padic_poly_set(c, a, ctx);
m = n_randint(state, 100);
n = n_randint(state, m + 1);
padic_poly_truncate(b, m, ctx->p);
padic_poly_truncate(b, n, ctx->p);
padic_poly_truncate(c, n, ctx->p);
result = (padic_poly_equal(b, c) && padic_poly_is_reduced(b, ctx));
if (!result)
{
flint_printf("FAIL:\n");
padic_poly_print(a, ctx), flint_printf("\n\n");
padic_poly_print(b, ctx), flint_printf("\n\n");
padic_poly_print(c, ctx), flint_printf("\n\n");
abort();
}
padic_poly_clear(a);
padic_poly_clear(b);
padic_poly_clear(c);
padic_ctx_clear(ctx);
fmpz_clear(p);
}
/* Compare with Q */
for (i = 0; i < 10000; i++)
{
padic_poly_t a;
fmpq_poly_t b, c;
slong n;
fmpz_init_set_ui(p, n_randtest_prime(state, 0));
N = n_randint(state, PADIC_TEST_PREC_MAX - PADIC_TEST_PREC_MIN)
+ PADIC_TEST_PREC_MIN;
padic_ctx_init(ctx, p, FLINT_MAX(0, N-10), FLINT_MAX(0, N+10), PADIC_SERIES);
padic_poly_init2(a, 0, N);
fmpq_poly_init(b);
fmpq_poly_init(c);
padic_poly_randtest(a, state, n_randint(state, 100), ctx);
n = n_randint(state, 100);
padic_poly_get_fmpq_poly(b, a, ctx);
fmpq_poly_truncate(b, n);
padic_poly_truncate(a, n, ctx->p);
padic_poly_get_fmpq_poly(c, a, ctx);
result = (fmpq_poly_equal(b, c) && padic_poly_is_reduced(a, ctx));
if (!result)
{
flint_printf("FAIL:\n");
padic_poly_print(a, ctx), flint_printf("\n\n");
fmpq_poly_print(b), flint_printf("\n\n");
fmpq_poly_print(c), flint_printf("\n\n");
abort();
}
padic_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(c);
padic_ctx_clear(ctx);
fmpz_clear(p);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,82 @@
/*=============================================================================
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, 2011 Sebastian Pancratz
Copyright (C) 2009 William Hart
******************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "padic_poly.h"
#include "ulong_extras.h"
#include "long_extras.h"
int
main(void)
{
int i, result;
padic_ctx_t ctx;
fmpz_t p;
slong N;
FLINT_TEST_INIT(state);
flint_printf("zero....");
fflush(stdout);
for (i = 0; i < 10000; i++)
{
padic_poly_t a;
fmpz_init_set_ui(p, n_randtest_prime(state, 0));
N = n_randint(state, PADIC_TEST_PREC_MAX - PADIC_TEST_PREC_MIN)
+ PADIC_TEST_PREC_MIN;
padic_ctx_init(ctx, p, FLINT_MAX(0, N-10), FLINT_MAX(0, N+10), PADIC_SERIES);
padic_poly_init2(a, 0, N);
padic_poly_randtest(a, state, n_randint(state, 100), ctx);
padic_poly_zero(a);
result = (padic_poly_is_zero(a));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a = "), padic_poly_print(a, ctx), flint_printf("\n\n");
abort();
}
padic_poly_clear(a);
padic_ctx_clear(ctx);
fmpz_clear(p);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return EXIT_SUCCESS;
}