-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_fib_prime.pl
142 lines (111 loc) · 2.9 KB
/
test_fib_prime.pl
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/perl
#!/usr/bin/perl
use 5.020;
use strict;
use warnings;
use experimental qw(signatures);
use Math::GMPz;
use Math::AnyNum qw(fibmod lucasmod);
use ntheory qw(is_prime powmod kronecker);
# Base-2 Fermat pseudoprimes:
# http://www.cecm.sfu.ca/Pseudoprimes/index-2-to-64.html
# http://www.cecm.sfu.ca/Pseudoprimes/psps-below-2-to-64.txt.bz2
foreach my $n (1 .. 3219781) {
#is_fermat_fibonacci_prime($n) && do {warn "error: $n\n";
# last;
#};
my $eF = 0;
my $eL = 0;
my $mod = $n % 5;
my $r = $n - 2;
if ($mod == 1 or $mod == 4) {
$eF = 1;
$eL = 1;
$r = 2;
}
elsif ($mod == 2 or $mod == 3) {
$eF = -1;
$eL = -1;
}
#if ($mod == 1) {
# $eL = $mod-5;
# $r = 11;
#}
#is_prime($n) || next;
#say "[$mod] $n -> ", lucasmod($n-$e, $n);
if (powmod(2, $n - 1, $n) == 1 and fibmod($n - $eF, $n) == 0) {
my $t = fibmod($n, $n);
$t == 1 or $t == $n - 1 or do {
if (is_prime($n)) {
warn "[#1] Missed prime: $n\n";
}
next;
};
if ($mod == 1) {
#fibmod($n-1, $n+1) == 1 and do {
lucasmod($n, $n) == 1 or do {
if (is_prime($n)) {
warn "[#2] Missed prime: $n\n";
}
next;
};
}
#say "First counter example: $n -> ", is_prime($n);
if (not is_prime($n)) {
say "Counter-example: $n -> ", $n % 5;
}
#sleep 1;
}
elsif (is_prime($n)) {
say "Missed a prime: $n -> ", lucasmod($n - $eL, $n), ' -> ', $n % 5;
}
}
__END__
my %seen;
my @nums;
while(<>) {
next if /^\h*#/;
/\S/ or next;
my (undef, $n) = split(' ');
$n || next;
next if $seen{$n}++;
#say $. if $. % 10000 == 0;
#if ($n >= (~0 >> 1)) {
$n = Math::GMPz->new("$n");
#}
#($n % 2 == 2) or ($n % 5 == 3) or next;
push @nums, $n;
#is_provable_prime($n) && die "error: $n\n";
#ntheory::is_prime($n) && die "error: $n\n";
#ntheory::is_aks_prime($n) && die "error: $n\n";
#ntheory::miller_rabin_random($n, 7) && die "error: $n\n";
}
@nums = sort {$a <=> $b} @nums;
foreach my $n(@nums) {
#is_fermat_fibonacci_prime($n) && do {warn "error: $n\n";
# last;
#};
my $e = 0;
my $mod = $n%5;
my $r = $n-2;
if ($mod == 1 or $mod == 4) {
$e = 1;
$r = 2;
}
elsif ($mod == 2 or $mod == 3) {
$e = -1;
}
#is_prime($n) || next;
#say "[$mod] $n -> ", lucasmod($n-$e, $n);
if (powmod(2, $n-1, $n) == 1 and lucasmod($n-$e, $n) == $r) {
#say "First counter example: $n -> ", is_prime($n);
if (not is_prime($n)) {
say "Counter-example: $n";
sleep 1;
}
#sleep 1;
}
elsif (is_prime($n)) {
say "Missed a prime: $n";
}
}