Skip to content

Commit

Permalink
Comments in prime_nth_count and BENCH_SEGCOUNT changes segment prime …
Browse files Browse the repository at this point in the history
…count
  • Loading branch information
danaj committed Feb 8, 2018
1 parent f7354b2 commit 9d09280
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
17 changes: 15 additions & 2 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@
- polymul, polyadd, polydiv, polyneg, polyeval, polyorder, polygcd, polylcm, polyroots, ...
A lot of our ops do these mod n, we could make ..mod versions of each.

- poly_is_reducible

- use word-based for-sieve for non-segment.

- remove start/end partial word tests from inner loop in for-sieve.
Expand All @@ -128,9 +130,14 @@
- compare wheel_t with primes separated and possibly cached.

- urandomm with bigints could be faster.
8.2s my $f=factorial(144); urandomm($f) for 1..5e5;
7.7s my $f=factorial(144); urandomm($f) for 1..5e5;
6.2s my $f=factorial(144); urandomm("$f") for 1..5e5;
4.8s my $f="".factorial(144); urandomm($f) for 1..5e5;
5.3s use Math::GMP qw/:constant/; my $f=factorial(144); urandomm($f) for 1..5e5;
1.8s my $f=Math::Prime::Util::GMP::factorial(144); Math::Prime::Util::GMP::urandomm($f) for 1..5e5;
1.7s my $f=Math::Prime::Util::GMP::factorial(144); Math::Prime::Util::GMP::urandomm($f) for 1..5e5;
In the first case, we're calling ""->bstr->_str once for validation in MPU
and and once for use in MPU::GMP.
The last case is all strings with no read/write bigint objects anywhere.

- Destroy csprng context on thread destruction.

Expand Down Expand Up @@ -158,3 +165,9 @@
- update prime count lower/upper from https://arxiv.org/pdf/1703.08032.pdf

- urandomr

- circular primes ... just use repdigits after 1M? https://oeis.org/A068652

- forfactored and forsquarefree. Consider setting $_ and @_.
Would formoebius make more sense?
We have ranged_moebius which is efficient, but not segmented so must be careful.
15 changes: 14 additions & 1 deletion prime_nth_count.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,10 @@ UV prime_count(UV lo, UV hi)
if (lo > hi || hi < 2)
return 0;

#if defined(BENCH_SEGCOUNT)
return segment_prime_count(lo, hi);
#endif

/* We use table acceleration so this is preferable for small inputs */
if (hi < 66000000) return segment_prime_count(lo, hi);

Expand Down Expand Up @@ -399,6 +403,9 @@ UV prime_count_lower(UV n)
fl1 = logl(n);
fl2 = fl1 * fl1;

/* Axler 2014: https://arxiv.org/abs/1409.1780 (v7 2016), Cor 3.6
* show variations of this. */

if (n <= 300000) { /* Quite accurate and avoids calling Li for speed. */
a = (n < 70200) ? 947 : (n < 176000) ? 904 : 829;
lower = fn / (fl1 - 1 - 1/fl1 - 2.85/fl2 - 13.15/(fl1*fl2) + a/(fl2*fl2));
Expand Down Expand Up @@ -463,6 +470,12 @@ UV prime_count_upper(UV n)
fl1 = logl(n);
fl2 = fl1 * fl1;

/* Axler 2014: https://arxiv.org/abs/1409.1780 (v7 2016), Cor 3.5
*
* upper = fn/(fl1-1.0L-1.0L/fl1-3.35L/fl2-12.65L/(fl2*fl1)-89.6L/(fl2*fl2));
* return (UV) floorl(upper);
*/

if (BITS_PER_WORD == 32 || fn <= 821800000.0) { /* Dusart 2010, page 2 */
for (i = 0; i < (int)NUPPER_THRESH; i++)
if (n < _upper_thresh[i].thresh)
Expand Down Expand Up @@ -514,7 +527,7 @@ UV nth_prime_upper(UV n)
/* Dusart 2010 page 2 */
upper = fn * (flogn + flog2n - 1.0 + ((flog2n-2.00)/flogn));
if (n >= 46254381) {
/* Axler 2017 http//arxiv.org/pdf/1706.03651.pdf Corollary 1.2 */
/* Axler 2017 http://arxiv.org/pdf/1706.03651.pdf Corollary 1.2 */
upper -= fn * ((flog2n*flog2n-6*flog2n+10.667)/(2*flogn*flogn));
} else if (n >= 8009824) {
/* Axler 2013 page viii Korollar G */
Expand Down

0 comments on commit 9d09280

Please sign in to comment.