File: check-nth-bounds.pl

package info (click to toggle)
libmath-prime-util-perl 0.73-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 2,796 kB
  • sloc: perl: 24,676; ansic: 11,471; makefile: 26; python: 24
file content (49 lines) | stat: -rw-r--r-- 1,158 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env perl
use warnings;
use strict;
use v5.16;
use ntheory ":all";

my $small_nth = 1e7;
my $small_rnth = 1e6;
my $rp_inc = 1e9;

print "Verifying nth prime bounds up to $small_nth\n";
{
  my $n = 1;
  forprimes {
    my $p = $_;
    my($l,$u) = (nth_prime_lower($n),nth_prime_upper($n));
    die "$n: $l $p $u" unless $l <= $p && $u >= $p;
    $n++;
  } $small_nth;
}

print "Verifying nth Ramanujan prime bounds to $small_rnth\n";
{
  my $r = ramanujan_primes($small_rnth);
  for (0 .. $#$r) {
    my $n = $_+1;
    my $rn = $r->[$_];
    my($l,$u) = (nth_ramanujan_prime_lower($n),nth_ramanujan_prime_upper($n));
    die "$n: $l $rn $u" unless $l <= $rn && $u >= $rn;
  }
}

print "Verifying nth Ramanujan prime bounds:\n";
{
  my $s = 0;
  my $n = 1;
  while ($s < 1e12) {
    my $r = ramanujan_primes($s, $s + $rp_inc - 1);
    for (0 .. $#$r) {
      my $rn = $r->[$_];
      my($l,$u) = (nth_ramanujan_prime_lower($n),nth_ramanujan_prime_upper($n));
      die "$n: $l $rn $u" unless $l <= $rn && $u >= $rn;
      #die "$n: $rn" unless $rn == nth_ramanujan_prime($n);
      $n++;
    }
    print "   $s + $rp_inc\n";
    $s += $rp_inc;
  }
}