pqc/external/flint-2.4.3/arith/test/t-bernoulli_polynomial.c

90 lines
2.4 KiB
C
Raw Normal View History

2014-05-18 22:03:37 +00:00
/*=============================================================================
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 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include <mpfr.h>
#include "flint.h"
#include "arith.h"
#include "profiler.h"
#include "fmpz.h"
#include "fmpz_mat.h"
#include "fmpq_poly.h"
int main()
{
fmpq_poly_t P, Q;
mpz_t t;
slong k, n;
FLINT_TEST_INIT(state);
flint_printf("bernoulli_polynomial....");
fflush(stdout);
for (n = 0; n <= 100; n++)
{
fmpq_poly_init(P);
fmpq_poly_init(Q);
mpz_init(t);
for (k = 0; k <= n; k++)
{
arith_bernoulli_polynomial(P, k);
flint_mpz_bin_uiui(t, n+1, k);
fmpq_poly_scalar_mul_mpz(P, P, t);
fmpq_poly_add(Q, Q, P);
}
fmpq_poly_scalar_div_ui(Q, Q, n+1);
mpz_clear(t);
fmpq_poly_zero(P);
fmpq_poly_set_coeff_ui(P, n, UWORD(1));
if (!fmpq_poly_equal(P, Q))
{
flint_printf("ERROR: sum up to n = %wd did not add to x^n\n", n);
flint_printf("Sum: ");
fmpq_poly_print_pretty(Q, "x");
flint_printf("\nExpected: ");
fmpq_poly_print_pretty(P, "x");
flint_printf("\n");
abort();
}
fmpq_poly_clear(P);
fmpq_poly_clear(Q);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}