-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use binary splitting to compute consecutive logarithms faster at high…
… precision
- Loading branch information
1 parent
2689439
commit fea196d
Showing
4 changed files
with
169 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/*============================================================================= | ||
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) 2013 Fredrik Johansson | ||
******************************************************************************/ | ||
|
||
#include "zeta.h" | ||
#include "hypgeom.h" | ||
|
||
static void | ||
atanh_bsplit(fmprb_t s, ulong p, ulong q, long prec) | ||
{ | ||
fmprb_t t; | ||
hypgeom_t series; | ||
hypgeom_init(series); | ||
fmprb_init(t); | ||
|
||
fmpz_poly_set_ui(series->A, 1); | ||
fmpz_poly_set_str(series->B, "2 1 2"); | ||
fmpz_poly_set_ui(series->P, p); | ||
fmpz_mul(series->P->coeffs, series->P->coeffs, series->P->coeffs); | ||
fmpz_poly_set_ui(series->Q, q); | ||
fmpz_mul(series->Q->coeffs, series->Q->coeffs, series->Q->coeffs); | ||
|
||
fmprb_hypgeom_infsum(s, t, series, prec, prec); | ||
fmprb_mul_ui(s, s, p, prec); | ||
fmprb_mul_ui(t, t, q, prec); | ||
fmprb_div(s, s, t, prec); | ||
|
||
fmprb_clear(t); | ||
hypgeom_clear(series); | ||
} | ||
|
||
void | ||
zeta_log_ui_from_prev(fmprb_t s, ulong k, fmprb_t log_prev, ulong prev, long prec) | ||
{ | ||
if (k > 200 && prec > 5000) | ||
{ | ||
fmprb_t t; | ||
fmprb_init(t); | ||
|
||
atanh_bsplit(t, k - prev, k + prev, prec); | ||
fmprb_mul_2exp_si(t, t, 1); | ||
fmprb_add(s, log_prev, t, prec); | ||
|
||
fmprb_clear(t); | ||
} | ||
else | ||
{ | ||
fmprb_log_ui(s, k, prec); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/*============================================================================= | ||
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 Fredrik Johansson | ||
******************************************************************************/ | ||
|
||
#include "zeta.h" | ||
|
||
int main() | ||
{ | ||
long iter; | ||
flint_rand_t state; | ||
|
||
printf("log_ui_from_prev...."); | ||
fflush(stdout); | ||
flint_randinit(state); | ||
|
||
for (iter = 0; iter < 1000; iter++) | ||
{ | ||
fmprb_t z1, z2, z3; | ||
ulong n1, n2; | ||
long prec, accuracy; | ||
|
||
prec = 2 + n_randint(state, 20000); | ||
n1 = n_randint(state, 100000); | ||
n2 = n1 + 1 + n_randint(state, 10); | ||
|
||
fmprb_init(z1); | ||
fmprb_init(z2); | ||
fmprb_init(z3); | ||
|
||
fmprb_log_ui(z1, n1, prec); | ||
fmprb_log_ui(z2, n2, prec); | ||
|
||
zeta_log_ui_from_prev(z3, n2, z1, n1, prec); | ||
|
||
if (!fmprb_overlaps(z2, z3)) | ||
{ | ||
printf("FAIL: overlap\n\n"); | ||
printf("prec = %ld, n1 = %lu, n2 = %lu\n\n", prec, n1, n2); | ||
printf("z1 = "); fmprb_printd(z1, prec / 3.33); printf("\n\n"); | ||
printf("z2 = "); fmprb_printd(z2, prec / 3.33); printf("\n\n"); | ||
printf("z3 = "); fmprb_printd(z3, prec / 3.33); printf("\n\n"); | ||
abort(); | ||
} | ||
|
||
accuracy = fmprb_rel_accuracy_bits(z3); | ||
|
||
if (accuracy < prec - 4) | ||
{ | ||
printf("FAIL: accuracy = %ld, prec = %ld\n\n", accuracy, prec); | ||
printf("n1 = %lu, n2 = %lu\n\n", n1, n2); | ||
printf("z3 = "); fmprb_printd(z3, prec / 3.33); printf("\n\n"); | ||
abort(); | ||
} | ||
|
||
fmprb_clear(z1); | ||
fmprb_clear(z2); | ||
fmprb_clear(z3); | ||
} | ||
|
||
flint_randclear(state); | ||
flint_cleanup(); | ||
printf("PASS\n"); | ||
return EXIT_SUCCESS; | ||
} |