arb/partitions/leading_fmpz.c

63 lines
1.8 KiB
C

/*=============================================================================
This file is part of ARB.
ARB 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.
ARB 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 ARB; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2016 Fredrik Johansson
******************************************************************************/
#include "partitions.h"
void
partitions_leading_fmpz(arb_t res, const fmpz_t n, slong prec)
{
arb_t t;
fmpz_t c;
slong eprec;
arb_init(t);
fmpz_init(c);
eprec = prec + fmpz_bits(n) / 2;
/* c = 24n-1 */
fmpz_mul_ui(c, n, 24);
fmpz_sub_ui(c, c, 1);
/* t = pi sqrt(24n-1) / 6 */
arb_sqrt_fmpz(t, c, eprec);
arb_const_pi(res, eprec);
arb_mul(t, t, res, eprec);
arb_div_ui(t, t, 6, eprec);
/* res = exp(t) - exp(t) / t */
/* todo: eprec only needed for argument reduction */
arb_exp(res, t, eprec);
arb_div(t, res, t, prec);
arb_sub(res, res, t, prec);
arb_sqrt_ui(t, 12, prec);
arb_mul(res, res, t, prec);
arb_div_fmpz(res, res, c, prec);
arb_clear(t);
fmpz_clear(c);
}