reorg zeta related functions

This commit is contained in:
Fredrik Johansson 2013-03-27 15:54:05 +01:00
parent 43f542ba35
commit 475bb2c8f3
35 changed files with 330 additions and 189 deletions

View file

@ -26,7 +26,7 @@
#include "bernoulli.h"
#include "zeta.h"
void fmprb_zeta_inv_ui_euler_product(fmprb_t z, ulong s, long prec);
void zeta_inv_ui_euler_product(fmprb_t z, ulong s, long prec);
void
bernoulli_fmprb_ui_zeta(fmprb_t b, ulong n, long prec)
@ -52,12 +52,12 @@ bernoulli_fmprb_ui_zeta(fmprb_t b, ulong n, long prec)
if (n > 0.7 * wp)
{
fmprb_zeta_ui_asymp(u, n, wp);
zeta_ui_asymp(u, n, wp);
fmprb_mul(b, b, u, wp);
}
else
{
fmprb_zeta_inv_ui_euler_product(u, n, wp);
zeta_inv_ui_euler_product(u, n, wp);
fmprb_mul(t, t, u, wp);
}

View file

@ -428,3 +428,7 @@ Special functions
Sets `y = \psi(x) = (\log \Gamma(x))' = \Gamma'(x) / \Gamma(x)`.
.. function:: void fmpcb_zeta(fmpcb_t z, const fmpcb_t s, long prec)
Sets *z* to the value of the Riemann zeta function `\zeta(s)`.

View file

@ -749,6 +749,35 @@ Constants
C = \sum_{k=0}^{\infty} \frac{(-1)^k 4^{4 k+1}
\left(40 k^2+56 k+19\right) [(k+1)!]^2 [(2k+2)!]^3}{(k+1)^3 (2 k+1) [(4k+4)!]^2}
.. function:: void fmprb_const_khinchin(fmprb_t res, long prec)
Sets *res* to Khinchin's constant `K_0`, computed as
.. math ::
\log K_0 = \frac{1}{\log 2} \left[
\sum_{k=2}^{N-1} \log \left(\frac{k-1}{k} \right) \log \left(\frac{k+1}{k} \right)
+ \sum_{n=1}^\infty
\frac {\zeta (2n,N)}{n} \sum_{k=1}^{2n-1} \frac{(-1)^{k+1}}{k}
\right]
where `N \ge 2` is a free parameter that can be used for tuning [BBC1997]_.
If the infinite series is truncated after `n = M`, the remainder
is smaller in absolute value than
.. math ::
\sum_{n=M+1}^{\infty} \zeta(2n, N) =
\sum_{n=M+1}^{\infty} \sum_{k=0}^{\infty} (k+N)^{-2n} \le
\sum_{n=M+1}^{\infty} \left( N^{-2n} + \int_0^{\infty} (t+N)^{-2n} dt \right)
= \sum_{n=M+1}^{\infty} \frac{1}{N^{2n}} \left(1 + \frac{N}{2n-1}\right)
\le \sum_{n=M+1}^{\infty} \frac{N+1}{N^{2n}} = \frac{1}{N^{2M} (N-1)}
\le \frac{1}{N^{2M}}.
Thus, for an error of at most `2^{-p}` in the series,
it is sufficient to choose `M \ge p / (2 \log_2 N)`.
.. function:: void fmprb_const_log_sqrt2pi(fmprb_t x, long prec)
Sets *x* to `\log \sqrt{2 \pi}`. The value is cached for repeated use.

View file

@ -4,19 +4,19 @@
Integer zeta values
-------------------------------------------------------------------------------
.. function:: void fmprb_const_zeta3_bsplit(fmprb_t x, long prec)
.. function:: void zeta_apery_bsplit(fmprb_t x, long prec)
Sets *x* to Apery's constant `\zeta(3)`, computed by applying binary
splitting to a hypergeometric series.
.. function:: void fmprb_zeta_ui_asymp(fmprb_t z, ulong s, long prec)
.. function:: void zeta_ui_asymp(fmprb_t z, ulong s, long prec)
Assuming `s \ge 2`, approximates `\zeta(s)` by `1 + 2^{-s}` along with
a correct error bound. We use the following bounds: for `s > b`,
`\zeta(s) - 1 < 2^{-b}`, and generally,
`\zeta(s) - (1 + 2^{-s}) < 2^{2-\lfloor 3 s/2 \rfloor}`.
.. function:: void fmprb_zeta_ui_euler_product(fmprb_t z, ulong s, long prec)
.. function:: void zeta_ui_euler_product(fmprb_t z, ulong s, long prec)
Computes `\zeta(s)` using the Euler product. This is fast only if *s*
is large compared to the precision.
@ -35,11 +35,11 @@ Integer zeta values
the geometric series allows us to conclude that
`\epsilon(M) \le f(s,M)`.
.. function:: void fmprb_zeta_ui_bernoulli(fmprb_t x, ulong n, long prec)
.. function:: void zeta_ui_bernoulli(fmprb_t x, ulong n, long prec)
Computes `\zeta(n)` for even *n* via the corresponding Bernoulli number.
.. function:: void fmprb_zeta_ui_vec_borwein(fmprb_struct * z, ulong start, long num, ulong step, long prec)
.. function:: void zeta_ui_vec_borwein(fmprb_struct * z, ulong start, long num, ulong step, long prec)
Evaluates `\zeta(s)` at `\mathrm{num}` consecutive integers *s* beginning
with *start* and proceeding in increments of *step*.
@ -67,7 +67,7 @@ Integer zeta values
additional rounding error, so by induction, the error per term
is always smaller than 2 units.
.. function:: void fmprb_zeta_ui_bsplit(fmprb_t x, ulong s, long prec)
.. function:: void zeta_ui_borwein_bsplit(fmprb_t x, ulong s, long prec)
Computes `\zeta(s)` for arbitrary `s \ge 2` using a binary splitting
implementation of Borwein's algorithm. This has quasilinear complexity
@ -154,61 +154,28 @@ Integer zeta values
Thus `(1 / d_n) \sum_k (-1)^k (k+1)^{-s} (d_n - d_k)` is given by
`A/Q_3 - (B/Q_3) / (C/Q_1) = (A C - B Q_1) / (Q_3 C)`.
.. function:: void fmprb_zeta_ui(fmprb_t x, ulong s, long prec)
.. function:: void zeta_ui(fmprb_t x, ulong s, long prec)
Computes `\zeta(s)` for nonnegative integer `s \ne 1`, automatically
choosing an appropriate algorithm.
.. function:: void fmprb_zeta_ui_vec(fmprb_struct * x, ulong start, long num, long prec)
.. function:: void zeta_ui_vec(fmprb_struct * x, ulong start, long num, long prec)
.. function:: void fmprb_zeta_ui_vec_even(fmprb_struct * x, ulong start, long num, long prec)
.. function:: void zeta_ui_vec_even(fmprb_struct * x, ulong start, long num, long prec)
.. function:: void fmprb_zeta_ui_vec_odd(fmprb_struct * x, ulong start, long num, long prec)
.. function:: void zeta_ui_vec_odd(fmprb_struct * x, ulong start, long num, long prec)
Computes `\zeta(s)` at num consecutive integers (respectively num
even or num odd integers) beginning with `s = \mathrm{start} \ge 2`,
automatically choosing an appropriate algorithm.
Related constants
-------------------------------------------------------------------------------
.. function:: void fmprb_const_khinchin(fmprb_t res, long prec)
Sets *res* to Khinchin's constant `K_0`, computed as
.. math ::
\log K_0 = \frac{1}{\log 2} \left[
\sum_{k=2}^{N-1} \log \left(\frac{k-1}{k} \right) \log \left(\frac{k+1}{k} \right)
+ \sum_{n=1}^\infty
\frac {\zeta (2n,N)}{n} \sum_{k=1}^{2n-1} \frac{(-1)^{k+1}}{k}
\right]
where `N \ge 2` is a free parameter that can be used for tuning [BBC1997]_.
If the infinite series is truncated after `n = M`, the remainder
is smaller in absolute value than
.. math ::
\sum_{n=M+1}^{\infty} \zeta(2n, N) =
\sum_{n=M+1}^{\infty} \sum_{k=0}^{\infty} (k+N)^{-2n} \le
\sum_{n=M+1}^{\infty} \left( N^{-2n} + \int_0^{\infty} (t+N)^{-2n} dt \right)
= \sum_{n=M+1}^{\infty} \frac{1}{N^{2n}} \left(1 + \frac{N}{2n-1}\right)
\le \sum_{n=M+1}^{\infty} \frac{N+1}{N^{2n}} = \frac{1}{N^{2M} (N-1)}
\le \frac{1}{N^{2M}}.
Thus, for an error of at most `2^{-p}` in the series,
it is sufficient to choose `M \ge p / (2 \log_2 N)`.
Euler-Maclaurin summation
-------------------------------------------------------------------------------
.. function:: void fmpcb_zeta_series_em_sum(fmpcb_struct * z, const fmpcb_t s, const fmpcb_t a, int deflate, ulong N, ulong M, long d, long prec)
.. function:: void zeta_series_em_sum(fmpcb_struct * z, const fmpcb_t s, const fmpcb_t a, int deflate, ulong N, ulong M, long d, long prec)
.. function:: void fmpcb_zeta_series(fmpcb_struct * z, const fmpcb_t s, const fmpcb_t a, int deflate, long d, long prec)
.. function:: void zeta_series(fmpcb_struct * z, const fmpcb_t s, const fmpcb_t a, int deflate, long d, long prec)
Evaluates the truncated Euler-Maclaurin sum of order `N, M` for the
length-*d* truncated Taylor series of the Hurwitz zeta function
@ -354,13 +321,8 @@ Euler-Maclaurin summation
where `L_0 = 1`, `L_k = k L_{k-1} + D^k` and `D = (B-1) (C + \log A)`.
.. function:: void fmpcb_zeta_series_em_choose_param(fmpr_t bound, ulong * N, ulong * M, const fmpcb_t s, const fmpcb_t a, long d, long target, long prec)
.. function:: void zeta_series_em_choose_param(fmpr_t bound, ulong * N, ulong * M, const fmpcb_t s, const fmpcb_t a, long d, long target, long prec)
Chooses *N* and *M* using a default algorithm.
.. function:: void fmpcb_zeta(fmpcb_t z, const fmpcb_t s, long prec)
Sets *z* to the value of the Riemann zeta function `\zeta(s)`.

View file

@ -534,6 +534,7 @@ void fmpcb_digamma(fmpcb_t y, const fmpcb_t x, long prec);
void fmpcb_rising_ui(fmpcb_t y, const fmpcb_t x, ulong n, long prec);
void fmpcb_zeta(fmpcb_t z, const fmpcb_t s, long prec);
static __inline__ void

74
fmpcb/test/t-zeta.c Normal file
View file

@ -0,0 +1,74 @@
/*=============================================================================
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) 2012, 2013 Fredrik Johansson
******************************************************************************/
#include "fmpcb.h"
int main()
{
long iter;
flint_rand_t state;
printf("zeta....");
fflush(stdout);
flint_randinit(state);
for (iter = 0; iter < 3000; iter++)
{
fmpcb_t a, b, c;
long prec1, prec2;
prec1 = 2 + n_randint(state, 500);
prec2 = prec1 + 30;
fmpcb_init(a);
fmpcb_init(b);
fmpcb_init(c);
fmprb_randtest_precise(fmpcb_realref(a), state, 1 + n_randint(state, 500), 3);
fmprb_randtest_precise(fmpcb_imagref(a), state, 1 + n_randint(state, 500), 3);
fmpcb_zeta(b, a, prec1);
fmpcb_zeta(c, a, prec2);
if (!fmpcb_overlaps(b, c))
{
printf("FAIL: overlap\n\n");
printf("a = "); fmpcb_print(a); printf("\n\n");
printf("b = "); fmpcb_print(b); printf("\n\n");
printf("c = "); fmpcb_print(c); printf("\n\n");
abort();
}
fmpcb_clear(a);
fmpcb_clear(b);
fmpcb_clear(c);
}
flint_randclear(state);
_fmpz_cleanup();
printf("PASS\n");
return EXIT_SUCCESS;
}

View file

@ -23,6 +23,7 @@
******************************************************************************/
#include "fmpcb.h"
#include "zeta.h"
void
@ -31,7 +32,7 @@ fmpcb_zeta(fmpcb_t z, const fmpcb_t s, long prec)
fmpcb_t a;
fmpcb_init(a);
fmpcb_one(a);
fmpcb_zeta_series(z, s, a, 0, 1, prec);
zeta_series(z, s, a, 0, 1, prec);
fmpcb_clear(a);
}

View file

@ -323,6 +323,7 @@ void fmprb_const_log10(fmprb_t s, long prec);
void fmprb_const_euler(fmprb_t s, long prec);
void fmprb_const_catalan(fmprb_t s, long prec);
void fmprb_const_e(fmprb_t s, long prec);
void fmprb_const_khinchin(fmprb_t K, long prec);
void fmprb_agm(fmprb_t z, const fmprb_t x, const fmprb_t y, long prec);

View file

@ -69,7 +69,7 @@ fmprb_const_khinchin_eval_param(fmprb_t s, ulong N, ulong M, long prec)
for (n = 1; n <= M; n++)
{
/* zeta(2n,N) / n */
fmprb_zeta_ui(t, 2 * n, prec);
zeta_ui(t, 2 * n, prec);
fmprb_sub_ui(t, t, 1, prec);
for (k = 0; k < N - 2; k++)
{

View file

@ -24,7 +24,7 @@
******************************************************************************/
#include "fmprb_poly.h"
#include "zeta.h"
/* series expansion for log(gamma(1-x)) at x = 0 */
@ -38,7 +38,7 @@ fmprb_poly_log_gamma_series(fmprb_poly_t z, long n, long prec)
if (n > 0) fmprb_zero(z->coeffs);
if (n > 1) fmprb_const_euler(z->coeffs + 1, prec);
if (n > 2) fmprb_zeta_ui_vec(z->coeffs + 2, 2, n - 2, prec);
if (n > 2) zeta_ui_vec(z->coeffs + 2, 2, n - 2, prec);
for (i = 2; i < n; i++)
fmprb_div_ui(z->coeffs + i, z->coeffs + i, i, prec);

33
zeta.h
View file

@ -31,27 +31,24 @@
#include "fmprb.h"
#include "fmpcb.h"
void fmprb_const_zeta3_bsplit(fmprb_t x, long prec);
void zeta_apery_bsplit(fmprb_t x, long prec);
void fmprb_const_khinchin(fmprb_t K, long prec);
void zeta_ui_asymp(fmprb_t x, ulong s, long prec);
void zeta_ui_borwein_bsplit(fmprb_t x, ulong s, long prec);
void zeta_ui_euler_product(fmprb_t z, ulong s, long prec);
void zeta_ui_bernoulli(fmprb_t x, ulong n, long prec);
void zeta_ui_vec_borwein(fmprb_struct * z, ulong start, long num, ulong step, long prec);
void zeta_ui(fmprb_t x, ulong n, long prec);
void fmprb_zeta_ui_asymp(fmprb_t x, ulong s, long prec);
void fmprb_zeta_ui_bsplit(fmprb_t x, ulong s, long prec);
void fmprb_zeta_ui_euler_product(fmprb_t z, ulong s, long prec);
void fmprb_zeta_ui_bernoulli(fmprb_t x, ulong n, long prec);
void fmprb_zeta_ui_vec_borwein(fmprb_struct * z, ulong start, long num, ulong step, long prec);
void fmprb_zeta_ui(fmprb_t x, ulong n, long prec);
void zeta_ui_vec_even(fmprb_struct * x, ulong start, long num, long prec);
void zeta_ui_vec_odd(fmprb_struct * x, ulong start, long num, long prec);
void zeta_ui_vec(fmprb_struct * x, ulong start, long num, long prec);
void fmprb_zeta_ui_vec_even(fmprb_struct * x, ulong start, long num, long prec);
void fmprb_zeta_ui_vec_odd(fmprb_struct * x, ulong start, long num, long prec);
void fmprb_zeta_ui_vec(fmprb_struct * x, ulong start, long num, long prec);
void fmpcb_zeta_series_em_sum(fmpcb_struct * z, const fmpcb_t s, const fmpcb_t a, int deflate, ulong N, ulong M, long d, long prec);
void fmpcb_zeta_series_em_choose_param(fmpr_t bound, ulong * N, ulong * M, const fmpcb_t s, const fmpcb_t a, long d, long target, long prec);
void fmpcb_zeta_series_em_bound(fmpr_t bound, const fmpcb_t s, const fmpcb_t a, long N, long M, long d, long wp);
void fmpcb_zeta_series_em_vec_bound(fmprb_struct * vec, const fmpcb_t s, const fmpcb_t a, ulong N, ulong M, long d, long wp);
void fmpcb_zeta_series(fmpcb_struct * z, const fmpcb_t s, const fmpcb_t a, int deflate, long d, long prec);
void fmpcb_zeta(fmpcb_t z, const fmpcb_t s, long prec);
void zeta_series_em_sum(fmpcb_struct * z, const fmpcb_t s, const fmpcb_t a, int deflate, ulong N, ulong M, long d, long prec);
void zeta_series_em_choose_param(fmpr_t bound, ulong * N, ulong * M, const fmpcb_t s, const fmpcb_t a, long d, long target, long prec);
void zeta_series_em_bound(fmpr_t bound, const fmpcb_t s, const fmpcb_t a, long N, long M, long d, long wp);
void zeta_series_em_vec_bound(fmprb_struct * vec, const fmpcb_t s, const fmpcb_t a, ulong N, ulong M, long d, long wp);
void zeta_series(fmpcb_struct * z, const fmpcb_t s, const fmpcb_t a, int deflate, long d, long prec);
#endif

View file

@ -27,7 +27,7 @@
#include "hypgeom.h"
void
fmprb_const_zeta3_bsplit(fmprb_t s, long prec)
zeta_apery_bsplit(fmprb_t s, long prec)
{
hypgeom_t series;
fmprb_t t;

View file

@ -26,7 +26,7 @@
#include "zeta.h"
void
fmpcb_zeta_series(fmpcb_struct * z, const fmpcb_t s, const fmpcb_t a, int deflate, long d, long prec)
zeta_series(fmpcb_struct * z, const fmpcb_t s, const fmpcb_t a, int deflate, long d, long prec)
{
ulong M, N;
long i;
@ -39,10 +39,10 @@ fmpcb_zeta_series(fmpcb_struct * z, const fmpcb_t s, const fmpcb_t a, int deflat
fmpr_init(bound);
vb = _fmprb_vec_init(d);
fmpcb_zeta_series_em_choose_param(bound, &N, &M, s, a, d, prec, FMPRB_RAD_PREC);
fmpcb_zeta_series_em_vec_bound(vb, s, a, N, M, d, 2 * prec);
zeta_series_em_choose_param(bound, &N, &M, s, a, d, prec, FMPRB_RAD_PREC);
zeta_series_em_vec_bound(vb, s, a, N, M, d, 2 * prec);
fmpcb_zeta_series_em_sum(z, s, a, deflate, N, M, d, prec);
zeta_series_em_sum(z, s, a, deflate, N, M, d, prec);
for (i = 0; i < d; i++)
{

View file

@ -176,7 +176,7 @@ bound_rfac(fmprb_struct * F, const fmpcb_t s, ulong n, long len, long wp)
}
void
fmpcb_zeta_series_em_vec_bound(fmprb_struct * bound, const fmpcb_t s, const fmpcb_t a, ulong N, ulong M, long len, long wp)
zeta_series_em_vec_bound(fmprb_struct * bound, const fmpcb_t s, const fmpcb_t a, ulong N, ulong M, long len, long wp)
{
fmprb_t K, C, AN, S2M;
fmprb_struct *F, *R;
@ -251,11 +251,11 @@ fmpcb_zeta_series_em_vec_bound(fmprb_struct * bound, const fmpcb_t s, const fmpc
}
void
fmpcb_zeta_series_em_bound(fmpr_t bound,
zeta_series_em_bound(fmpr_t bound,
const fmpcb_t s, const fmpcb_t a, long N, long M, long len, long wp)
{
fmprb_struct * vec = _fmprb_vec_init(len);
fmpcb_zeta_series_em_vec_bound(vec, s, a, N, M, len, wp);
zeta_series_em_vec_bound(vec, s, a, N, M, len, wp);
_fmprb_vec_get_abs_ubound_fmpr(bound, vec, len, wp);
_fmprb_vec_clear(vec, len);
}

View file

@ -31,7 +31,7 @@ static ulong choose_M(ulong N, long target)
}
void
fmpcb_zeta_series_em_choose_param(fmpr_t bound, ulong * N, ulong * M, const fmpcb_t s, const fmpcb_t a, long d, long target, long prec)
zeta_series_em_choose_param(fmpr_t bound, ulong * N, ulong * M, const fmpcb_t s, const fmpcb_t a, long d, long target, long prec)
{
ulong A, B, C;
fmpr_t Abound, Bbound, Cbound, tol;
@ -46,7 +46,7 @@ fmpcb_zeta_series_em_choose_param(fmpr_t bound, ulong * N, ulong * M, const fmpc
A = 1;
B = 2;
fmpcb_zeta_series_em_bound(Bbound, s, a, B, choose_M(B, target), d, prec);
zeta_series_em_bound(Bbound, s, a, B, choose_M(B, target), d, prec);
if (fmpr_cmp(Bbound, tol) > 0)
{
@ -58,7 +58,7 @@ fmpcb_zeta_series_em_choose_param(fmpr_t bound, ulong * N, ulong * M, const fmpc
if (B == 0) abort();
fmpcb_zeta_series_em_bound(Bbound, s, a, B, choose_M(B, target), d, prec);
zeta_series_em_bound(Bbound, s, a, B, choose_M(B, target), d, prec);
}
/* bisect (-A, B] */
@ -66,7 +66,7 @@ fmpcb_zeta_series_em_choose_param(fmpr_t bound, ulong * N, ulong * M, const fmpc
{
C = A + (B - A) / 2;
fmpcb_zeta_series_em_bound(Cbound, s, a, C, choose_M(C, target), d, prec);
zeta_series_em_bound(Cbound, s, a, C, choose_M(C, target), d, prec);
if (fmpr_cmp(Cbound, tol) < 0)
{

View file

@ -114,7 +114,7 @@ _fmpcb_vec_scalar_div_fmprb(fmpcb_struct * res, const fmpcb_struct * vec, long l
}
void
fmpcb_zeta_series_em_sum(fmpcb_struct * z, const fmpcb_t s, const fmpcb_t a, int deflate, ulong N, ulong M, long d, long prec)
zeta_series_em_sum(fmpcb_struct * z, const fmpcb_t s, const fmpcb_t a, int deflate, ulong N, ulong M, long d, long prec)
{
fmpcb_struct *t, *u, *v, *term, *sum;
fmpcb_t splus, Na, rec;

View file

@ -30,7 +30,7 @@ int main()
long iter;
flint_rand_t state;
printf("const_zeta3_bsplit....");
printf("apery_bsplit....");
fflush(stdout);
flint_randinit(state);
@ -45,7 +45,7 @@ int main()
fmprb_init(r);
mpfr_init2(s, prec + 1000);
fmprb_const_zeta3_bsplit(r, prec);
zeta_apery_bsplit(r, prec);
mpfr_zeta_ui(s, 3, MPFR_RNDN);
if (!fmprb_contains_mpfr(r, s))

View file

@ -30,12 +30,12 @@ int main()
long iter;
flint_rand_t state;
printf("zeta_series....");
printf("series....");
fflush(stdout);
flint_randinit(state);
for (iter = 0; iter < 500; iter++)
for (iter = 0; iter < 1000; iter++)
{
fmpcb_t s, a;
fmpcb_struct *z1, *z2;
@ -78,8 +78,8 @@ int main()
z1 = _fmpcb_vec_init(len);
z2 = _fmpcb_vec_init(len);
fmpcb_zeta_series(z1, s, a, deflate, len, prec1);
fmpcb_zeta_series(z2, s, a, deflate, len, prec2);
zeta_series(z1, s, a, deflate, len, prec1);
zeta_series(z2, s, a, deflate, len, prec2);
for (i = 0; i < len; i++)
{

View file

@ -30,11 +30,10 @@ int main()
long iter;
flint_rand_t state;
printf("zeta_ui....");
printf("ui....");
fflush(stdout);
flint_randinit(state);
for (iter = 0; iter < 1000; iter++)
{
fmprb_t r;
@ -49,7 +48,7 @@ int main()
do { n = n_randint(state, 1 << n_randint(state, 10)); } while (n == 1);
fmprb_zeta_ui(r, n, prec);
zeta_ui(r, n, prec);
mpfr_zeta_ui(s, n, MPFR_RNDN);
if (!fmprb_contains_mpfr(r, s))

View file

@ -30,7 +30,7 @@ int main()
long iter;
flint_rand_t state;
printf("zeta_ui_asymp....");
printf("ui_asymp....");
fflush(stdout);
flint_randinit(state);
@ -48,7 +48,7 @@ int main()
n = 2 + n_randint(state, 1 << n_randint(state, 10));
fmprb_zeta_ui_asymp(r, n, prec);
zeta_ui_asymp(r, n, prec);
mpfr_zeta_ui(s, n, MPFR_RNDN);
if (!fmprb_contains_mpfr(r, s))

View file

@ -30,11 +30,10 @@ int main()
long iter;
flint_rand_t state;
printf("zeta_ui_bernoulli....");
printf("ui_bernoulli....");
fflush(stdout);
flint_randinit(state);
for (iter = 0; iter < 1000; iter++)
{
fmprb_t r;
@ -50,7 +49,7 @@ int main()
do { n = n_randint(state, 1 << n_randint(state, 10)); }
while (n % 2 || n == 0);
fmprb_zeta_ui_bernoulli(r, n, prec);
zeta_ui_bernoulli(r, n, prec);
mpfr_zeta_ui(s, n, MPFR_RNDN);
if (!fmprb_contains_mpfr(r, s))

View file

@ -30,11 +30,10 @@ int main()
long iter;
flint_rand_t state;
printf("zeta_ui_bsplit....");
printf("ui_borwein_bsplit....");
fflush(stdout);
flint_randinit(state);
for (iter = 0; iter < 1000; iter++)
{
fmprb_t r;
@ -49,7 +48,7 @@ int main()
do { n = n_randint(state, 1 << n_randint(state, 10)); } while (n == 1);
fmprb_zeta_ui_bsplit(r, n, prec);
zeta_ui_borwein_bsplit(r, n, prec);
mpfr_zeta_ui(s, n, MPFR_RNDN);
if (!fmprb_contains_mpfr(r, s))

View file

@ -30,11 +30,10 @@ int main()
long iter;
flint_rand_t state;
printf("zeta_ui_euler_product....");
printf("ui_euler_product....");
fflush(stdout);
flint_randinit(state);
for (iter = 0; iter < 1000; iter++)
{
fmprb_t r;
@ -49,7 +48,7 @@ int main()
fmprb_init(r);
mpfr_init2(s, prec + 100);
fmprb_zeta_ui_euler_product(r, n, prec);
zeta_ui_euler_product(r, n, prec);
mpfr_zeta_ui(s, n, MPFR_RNDN);
if (!fmprb_contains_mpfr(r, s))

View file

@ -30,11 +30,10 @@ int main()
long iter;
flint_rand_t state;
printf("zeta_ui_vec....");
printf("ui_vec....");
fflush(stdout);
flint_randinit(state);
for (iter = 0; iter < 100; iter++)
{
fmprb_struct * r;
@ -51,7 +50,7 @@ int main()
do { n = n_randint(state, 1 << n_randint(state, 10)); } while (n < 2);
fmprb_zeta_ui_vec(r, n, num, prec);
zeta_ui_vec(r, n, num, prec);
for (i = 0; i < num; i++)
{

View file

@ -30,11 +30,10 @@ int main()
long iter;
flint_rand_t state;
printf("zeta_ui_vec_borwein....");
printf("ui_vec_borwein....");
fflush(stdout);
flint_randinit(state);
for (iter = 0; iter < 100; iter++)
{
fmprb_struct * r;
@ -52,7 +51,7 @@ int main()
do { n = n_randint(state, 1 << n_randint(state, 10)); } while (n < 2);
fmprb_zeta_ui_vec_borwein(r, n, num, step, prec);
zeta_ui_vec_borwein(r, n, num, step, prec);
for (i = 0; i < num; i++)
{

View file

@ -28,7 +28,7 @@
#include "zeta.h"
void
fmprb_zeta_ui(fmprb_t x, ulong n, long prec)
zeta_ui(fmprb_t x, ulong n, long prec)
{
if (n == 0)
{
@ -43,7 +43,7 @@ fmprb_zeta_ui(fmprb_t x, ulong n, long prec)
/* fast detection of asymptotic case */
else if (n > 0.7 * prec)
{
fmprb_zeta_ui_asymp(x, n, prec);
zeta_ui_asymp(x, n, prec);
}
else
{
@ -53,87 +53,35 @@ fmprb_zeta_ui(fmprb_t x, ulong n, long prec)
if (((prec < 10000) && (n < 40 + 0.11*prec)) ||
((prec >= 10000) && (arith_bernoulli_number_size(n) * 0.9 < prec)))
{
fmprb_zeta_ui_bernoulli(x, n, prec);
zeta_ui_bernoulli(x, n, prec);
}
else
{
fmprb_zeta_ui_euler_product(x, n, prec);
zeta_ui_euler_product(x, n, prec);
}
}
else
{
if (n == 3)
{
fmprb_const_zeta3_bsplit(x, prec);
zeta_apery_bsplit(x, prec);
}
else if (n < prec * 0.0006)
{
/* small odd n, extremely high precision */
fmprb_zeta_ui_bsplit(x, n, prec);
zeta_ui_borwein_bsplit(x, n, prec);
}
else if (prec > 20 && n > 6 && n > 0.4 * pow(prec, 0.8))
{
/* large n */
fmprb_zeta_ui_euler_product(x, n, prec);
zeta_ui_euler_product(x, n, prec);
}
else
{
/* fallback */
fmprb_zeta_ui_vec_borwein(x, n, 1, 0, prec);
zeta_ui_vec_borwein(x, n, 1, 0, prec);
}
}
}
}
void
fmprb_zeta_ui_vec_even(fmprb_struct * x, ulong start, long num, long prec)
{
long i;
for (i = 0; i < num; i++)
fmprb_zeta_ui(x + i, start + 2 * i, prec);
}
void
fmprb_zeta_ui_vec_odd(fmprb_struct * x, ulong start, long num, long prec)
{
long i, num_borwein;
ulong cutoff;
cutoff = 40 + 0.3 * prec;
if (cutoff > start)
{
num_borwein = 1 + (cutoff - start) / 2;
num_borwein = FLINT_MIN(num_borwein, num);
}
else
num_borwein = 0;
fmprb_zeta_ui_vec_borwein(x, start, num_borwein, 2, prec);
for (i = num_borwein; i < num; i++)
fmprb_zeta_ui(x + i, start + 2 * i, prec);
}
void
fmprb_zeta_ui_vec(fmprb_struct * x, ulong start, long num, long prec)
{
long i, num_odd, num_even, start_odd;
fmprb_struct * tmp;
num_odd = num / 2 + (start & num & 1);
num_even = num - num_odd;
start_odd = start % 2;
fmprb_zeta_ui_vec_even(x, start + start_odd, num_even, prec);
fmprb_zeta_ui_vec_odd(x + num_even, start + !start_odd, num_odd, prec);
/* interleave */
tmp = flint_malloc(sizeof(fmprb_struct) * num);
for (i = 0; i < num_even; i++) tmp[i] = x[i];
for (i = 0; i < num_odd; i++) tmp[num_even + i] = x[num_even + i];
for (i = 0; i < num_even; i++) x[start_odd + 2 * i] = tmp[i];
for (i = 0; i < num_odd; i++) x[!start_odd + 2 * i] = tmp[num_even + i];
flint_free(tmp);
}

View file

@ -26,7 +26,7 @@
#include "zeta.h"
void
fmprb_zeta_ui_asymp(fmprb_t x, ulong s, long prec)
zeta_ui_asymp(fmprb_t x, ulong s, long prec)
{
fmprb_set_ui(x, 1UL);

View file

@ -27,7 +27,7 @@
#include "bernoulli.h"
void
fmprb_zeta_ui_bernoulli(fmprb_t x, ulong n, long prec)
zeta_ui_bernoulli(fmprb_t x, ulong n, long prec)
{
fmpq_t b;
fmprb_t t, f;
@ -60,3 +60,4 @@ fmprb_zeta_ui_bernoulli(fmprb_t x, ulong n, long prec)
fmprb_clear(f);
fmpq_clear(b);
}

View file

@ -148,7 +148,7 @@ borwein_error(fmpr_t err, long n)
}
void
fmprb_zeta_ui_bsplit(fmprb_t x, ulong s, long prec)
zeta_ui_borwein_bsplit(fmprb_t x, ulong s, long prec)
{
zeta_bsplit_t sum;
fmpr_t err;
@ -164,7 +164,7 @@ fmprb_zeta_ui_bsplit(fmprb_t x, ulong s, long prec)
if (s == 1)
{
printf("fmprb_zeta_ui_bsplit: zeta(1)");
printf("zeta_ui_borwein_bsplit: zeta(1)");
abort();
}

View file

@ -57,7 +57,7 @@ add_error(fmprb_t z, ulong M, ulong s)
}
void
fmprb_zeta_inv_ui_euler_product(fmprb_t z, ulong s, long prec)
zeta_inv_ui_euler_product(fmprb_t z, ulong s, long prec)
{
long wp, powprec;
double powmag;
@ -111,13 +111,9 @@ fmprb_zeta_inv_ui_euler_product(fmprb_t z, ulong s, long prec)
}
void
fmprb_zeta_ui_euler_product(fmprb_t z, ulong s, long prec)
zeta_ui_euler_product(fmprb_t z, ulong s, long prec)
{
fmprb_t one;
fmprb_init(one);
fmprb_set_ui(one, 1);
fmprb_zeta_inv_ui_euler_product(z, s, prec);
fmprb_div(z, one, z, prec);
fmprb_clear(one);
zeta_inv_ui_euler_product(z, s, prec);
fmprb_ui_div(z, 1, z, prec);
}

50
zeta/ui_vec.c Normal file
View file

@ -0,0 +1,50 @@
/*=============================================================================
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) 2012, 2013 Fredrik Johansson
******************************************************************************/
#include "zeta.h"
void
zeta_ui_vec(fmprb_struct * x, ulong start, long num, long prec)
{
long i, num_odd, num_even, start_odd;
fmprb_struct * tmp;
num_odd = num / 2 + (start & num & 1);
num_even = num - num_odd;
start_odd = start % 2;
zeta_ui_vec_even(x, start + start_odd, num_even, prec);
zeta_ui_vec_odd(x + num_even, start + !start_odd, num_odd, prec);
/* interleave */
tmp = flint_malloc(sizeof(fmprb_struct) * num);
for (i = 0; i < num_even; i++) tmp[i] = x[i];
for (i = 0; i < num_odd; i++) tmp[num_even + i] = x[num_even + i];
for (i = 0; i < num_even; i++) x[start_odd + 2 * i] = tmp[i];
for (i = 0; i < num_odd; i++) x[!start_odd + 2 * i] = tmp[num_even + i];
flint_free(tmp);
}

View file

@ -32,8 +32,7 @@
void borwein_error(fmpr_t err, long n);
void
fmprb_zeta_ui_vec_borwein(fmprb_struct * z, ulong start, long num,
ulong step, long prec)
zeta_ui_vec_borwein(fmprb_struct * z, ulong start, long num, ulong step, long prec)
{
long j, k, s, n, wp;
fmpz_t c, d, t, u;

36
zeta/ui_vec_even.c Normal file
View file

@ -0,0 +1,36 @@
/*=============================================================================
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) 2012, 2013 Fredrik Johansson
******************************************************************************/
#include "zeta.h"
void
zeta_ui_vec_even(fmprb_struct * x, ulong start, long num, long prec)
{
long i;
for (i = 0; i < num; i++)
zeta_ui(x + i, start + 2 * i, prec);
}

48
zeta/ui_vec_odd.c Normal file
View file

@ -0,0 +1,48 @@
/*=============================================================================
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) 2012, 2013 Fredrik Johansson
******************************************************************************/
#include "zeta.h"
void
zeta_ui_vec_odd(fmprb_struct * x, ulong start, long num, long prec)
{
long i, num_borwein;
ulong cutoff;
cutoff = 40 + 0.3 * prec;
if (cutoff > start)
{
num_borwein = 1 + (cutoff - start) / 2;
num_borwein = FLINT_MIN(num_borwein, num);
}
else
num_borwein = 0;
zeta_ui_vec_borwein(x, start, num_borwein, 2, prec);
for (i = num_borwein; i < num; i++)
zeta_ui(x + i, start + 2 * i, prec);
}