File: pari-totient-moebius.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 (36 lines) | stat: -rwxr-xr-x 1,104 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
use warnings;
$| = 1;  # fast pipes

use Math::Prime::Util qw/urandomm/;
use Math::Pari;

my $nlinear = 100000;
my $nrandom = shift || 100000;
my $randmax = 10**16;

# Moebius and euler_phi seem about 2-4x faster than Pari.  Also, we have
# ranged versions that run much faster.
#
print "OK for first 1";
my $dig = 1;
my $i = 9;
foreach my $n (2 .. $nlinear) {
  die "failure for eulerphi($n)" unless Math::Prime::Util::euler_phi($n) == Math::Pari::eulerphi($n);
  die "failure for moebius($n)" unless Math::Prime::Util::moebius($n) == Math::Pari::moebius($n);
  if (--$i == 0) {
    print "0";
    $dig++;
    $i = (10 ** $dig) - (10 ** ($dig-1));
  }
}
print " numbers\n";
print "Testing random numbers from $nlinear to ", $randmax, "\n";
my $mod = int($nrandom / 80);

while ($nrandom-- > 0) {
  my $n = $nlinear + 1 + urandomm($randmax-$nlinear);
  die "failure for eulerphi($n)" unless Math::Prime::Util::euler_phi($n) == Math::Pari::eulerphi($n);
  die "failure for moebius($n)" unless Math::Prime::Util::moebius($n) == Math::Pari::moebius($n);
  print "." if ($nrandom % $mod) == 0;
}
print "\n";