1#!/usr/bin/env perl 2use warnings; 3use strict; 4use v5.16; 5use ntheory ":all"; 6 7my $small_nth = 1e7; 8my $small_rnth = 1e6; 9my $rp_inc = 1e9; 10 11print "Verifying nth prime bounds up to $small_nth\n"; 12{ 13 my $n = 1; 14 forprimes { 15 my $p = $_; 16 my($l,$u) = (nth_prime_lower($n),nth_prime_upper($n)); 17 die "$n: $l $p $u" unless $l <= $p && $u >= $p; 18 $n++; 19 } $small_nth; 20} 21 22print "Verifying nth Ramanujan prime bounds to $small_rnth\n"; 23{ 24 my $r = ramanujan_primes($small_rnth); 25 for (0 .. $#$r) { 26 my $n = $_+1; 27 my $rn = $r->[$_]; 28 my($l,$u) = (nth_ramanujan_prime_lower($n),nth_ramanujan_prime_upper($n)); 29 die "$n: $l $rn $u" unless $l <= $rn && $u >= $rn; 30 } 31} 32 33print "Verifying nth Ramanujan prime bounds:\n"; 34{ 35 my $s = 0; 36 my $n = 1; 37 while ($s < 1e12) { 38 my $r = ramanujan_primes($s, $s + $rp_inc - 1); 39 for (0 .. $#$r) { 40 my $rn = $r->[$_]; 41 my($l,$u) = (nth_ramanujan_prime_lower($n),nth_ramanujan_prime_upper($n)); 42 die "$n: $l $rn $u" unless $l <= $rn && $u >= $rn; 43 #die "$n: $rn" unless $rn == nth_ramanujan_prime($n); 44 $n++; 45 } 46 print " $s + $rp_inc\n"; 47 $s += $rp_inc; 48 } 49} 50