line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright 2012, 2013, 2014 Kevin Ryde |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# This file is part of Math-NumSeq. |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# Math-NumSeq is free software; you can redistribute it and/or modify |
6
|
|
|
|
|
|
|
# it under the terms of the GNU General Public License as published by the |
7
|
|
|
|
|
|
|
# Free Software Foundation; either version 3, or (at your option) any later |
8
|
|
|
|
|
|
|
# version. |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# Math-NumSeq is distributed in the hope that it will be useful, but |
11
|
|
|
|
|
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
12
|
|
|
|
|
|
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
13
|
|
|
|
|
|
|
# for more details. |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License along |
16
|
|
|
|
|
|
|
# with Math-NumSeq. If not, see . |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
package Math::NumSeq::ErdosSelfridgeClass; |
19
|
2
|
|
|
2
|
|
7173
|
use 5.004; |
|
2
|
|
|
|
|
6
|
|
20
|
2
|
|
|
2
|
|
7
|
use strict; |
|
2
|
|
|
|
|
1
|
|
|
2
|
|
|
|
|
35
|
|
21
|
2
|
|
|
2
|
|
325
|
use Math::NumSeq::Primes; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
39
|
|
22
|
|
|
|
|
|
|
|
23
|
2
|
|
|
2
|
|
7
|
use vars '$VERSION', '@ISA'; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
92
|
|
24
|
|
|
|
|
|
|
$VERSION = 72; |
25
|
|
|
|
|
|
|
|
26
|
2
|
|
|
2
|
|
7
|
use Math::NumSeq; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
40
|
|
27
|
|
|
|
|
|
|
@ISA = ('Math::NumSeq'); |
28
|
|
|
|
|
|
|
|
29
|
2
|
|
|
2
|
|
368
|
use Math::NumSeq::PrimeFactorCount;; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
68
|
|
30
|
|
|
|
|
|
|
*_prime_factors = \&Math::NumSeq::PrimeFactorCount::_prime_factors; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# uncomment this to run the ### lines |
33
|
|
|
|
|
|
|
#use Smart::Comments; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# use constant name => Math::NumSeq::__('Erdos-Selfridge Class'); |
37
|
2
|
|
|
2
|
|
8
|
use constant description => Math::NumSeq::__('Erdos-Selfridge class of a prime.'); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
6
|
|
38
|
2
|
|
|
2
|
|
6
|
use constant default_i_start => 1; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
69
|
|
39
|
2
|
|
|
2
|
|
6
|
use constant characteristic_integer => 1; |
|
2
|
|
|
|
|
1
|
|
|
2
|
|
|
|
|
60
|
|
40
|
2
|
|
|
2
|
|
6
|
use constant characteristic_increasing => 0; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
63
|
|
41
|
2
|
|
|
2
|
|
5
|
use constant characteristic_non_decreasing => 0; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
63
|
|
42
|
2
|
|
|
2
|
|
6
|
use constant characteristic_smaller => 1; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
58
|
|
43
|
2
|
|
|
2
|
|
6
|
use constant values_min => 0; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
356
|
|
44
|
|
|
|
|
|
|
|
45
|
2
|
|
|
|
|
6
|
use constant parameter_info_array => |
46
|
|
|
|
|
|
|
[ |
47
|
|
|
|
|
|
|
{ name => 'p_or_m', |
48
|
|
|
|
|
|
|
display => Math::NumSeq::__('+/-'), |
49
|
|
|
|
|
|
|
type => 'enum', |
50
|
|
|
|
|
|
|
default => '+', |
51
|
|
|
|
|
|
|
choices => ['+','-'], |
52
|
|
|
|
|
|
|
choices_display => [Math::NumSeq::__('+'), |
53
|
|
|
|
|
|
|
Math::NumSeq::__('-')], |
54
|
|
|
|
|
|
|
description => Math::NumSeq::__('Class + or -, factorizing p+1 or p-1 respectively in the classification.'), |
55
|
|
|
|
|
|
|
}, |
56
|
|
|
|
|
|
|
{ name => 'on_values', |
57
|
|
|
|
|
|
|
share_key => 'on_values_primes', |
58
|
|
|
|
|
|
|
display => Math::NumSeq::__('On Values'), |
59
|
|
|
|
|
|
|
type => 'enum', |
60
|
|
|
|
|
|
|
default => 'all', |
61
|
|
|
|
|
|
|
choices => ['all','primes'], |
62
|
|
|
|
|
|
|
choices_display => [Math::NumSeq::__('All'), |
63
|
|
|
|
|
|
|
Math::NumSeq::__('Primes')], |
64
|
|
|
|
|
|
|
description => Math::NumSeq::__('Values to classify, either all integers or just the primes.'), |
65
|
|
|
|
|
|
|
}, |
66
|
2
|
|
|
2
|
|
10
|
]; |
|
2
|
|
|
|
|
2
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# cf A098661 cumulative class+ |
71
|
|
|
|
|
|
|
# A005109 1-, Pierpont |
72
|
|
|
|
|
|
|
# A005110 2- |
73
|
|
|
|
|
|
|
# A005111 3- |
74
|
|
|
|
|
|
|
# A005112 4- |
75
|
|
|
|
|
|
|
# A081424 5- |
76
|
|
|
|
|
|
|
# A081425 6- |
77
|
|
|
|
|
|
|
# A081640 12- |
78
|
|
|
|
|
|
|
# A129248 14- |
79
|
|
|
|
|
|
|
# A129249 15- |
80
|
|
|
|
|
|
|
# A129250 16- |
81
|
|
|
|
|
|
|
# A005105 1+ |
82
|
|
|
|
|
|
|
# A005106 2+ |
83
|
|
|
|
|
|
|
# A005107 3+ |
84
|
|
|
|
|
|
|
# A005108 4+ |
85
|
|
|
|
|
|
|
# A081633 5+ |
86
|
|
|
|
|
|
|
# ... |
87
|
|
|
|
|
|
|
# A081639 11+ |
88
|
|
|
|
|
|
|
# A084071 12+ |
89
|
|
|
|
|
|
|
# A090468 13+ |
90
|
|
|
|
|
|
|
# A129474 14+ |
91
|
|
|
|
|
|
|
# A129475 15+ |
92
|
|
|
|
|
|
|
# A178382 in both k+ and k- for some k |
93
|
|
|
|
|
|
|
# A005113 least prime in class n+ |
94
|
|
|
|
|
|
|
# A056637 least prime of class n- |
95
|
|
|
|
|
|
|
# A129470 where largest factor of p+1 isn't largest class |
96
|
|
|
|
|
|
|
# A129469 first prime of class n+ in A129470 |
97
|
|
|
|
|
|
|
# A129471 3+ with largest factor of p+1 not in 2+ |
98
|
|
|
|
|
|
|
# A129472 4+ with largest factor of p+1 not in 3+ |
99
|
|
|
|
|
|
|
# |
100
|
|
|
|
|
|
|
my %oeis_anum = ('+' => { 'primes' => 'A126433', # class+ of primes |
101
|
|
|
|
|
|
|
'all' => 'A078442', |
102
|
|
|
|
|
|
|
}, |
103
|
|
|
|
|
|
|
'-' => { 'primes' => 'A126805', # class- of primes |
104
|
|
|
|
|
|
|
}); |
105
|
|
|
|
|
|
|
# OEIS-Catalogue: A126433 on_values=primes |
106
|
|
|
|
|
|
|
# OEIS-Catalogue: A126805 on_values=primes p_or_m=- |
107
|
|
|
|
|
|
|
sub oeis_anum { |
108
|
3
|
|
|
3
|
1
|
10
|
my ($self) = @_; |
109
|
3
|
|
|
|
|
8
|
return $oeis_anum{$self->{'p_or_m'}}->{$self->{'on_values'}}; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub rewind { |
115
|
11
|
|
|
11
|
1
|
1351
|
my ($self) = @_; |
116
|
11
|
|
|
|
|
33
|
$self->{'i'} = $self->i_start; |
117
|
11
|
100
|
|
|
|
88
|
if ($self->{'on_values'} eq 'primes') { |
118
|
3
|
|
|
|
|
11
|
$self->{'seq'} = Math::NumSeq::Primes->new; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
sub next { |
122
|
126
|
|
|
126
|
1
|
1156
|
my ($self) = @_; |
123
|
126
|
|
|
|
|
119
|
my $i = $self->{'i'}++; |
124
|
126
|
|
|
|
|
66
|
my $value; |
125
|
126
|
100
|
|
|
|
145
|
if (my $seq = $self->{'seq'}) { |
126
|
42
|
|
|
|
|
67
|
(undef, $value) = $self->{'seq'}->next; |
127
|
|
|
|
|
|
|
} else { |
128
|
84
|
|
|
|
|
65
|
$value = $i; |
129
|
|
|
|
|
|
|
} |
130
|
126
|
|
|
|
|
134
|
return ($i, _classify($self,$value)); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub ith { |
134
|
134
|
|
|
134
|
1
|
180
|
my ($self, $i) = @_; |
135
|
134
|
50
|
|
|
|
163
|
if ($self->{'on_values'} eq 'primes') { |
136
|
0
|
|
|
|
|
0
|
return undef; # no i'th prime yet |
137
|
|
|
|
|
|
|
} |
138
|
134
|
|
|
|
|
106
|
return _classify($self,$i); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
sub can { |
141
|
500
|
|
|
500
|
0
|
12075
|
my ($class_or_self, $method) = @_; |
142
|
500
|
100
|
100
|
|
|
1459
|
if (($method eq 'ith' || $method eq 'seek_to_i') |
|
|
|
66
|
|
|
|
|
|
|
|
100
|
|
|
|
|
143
|
|
|
|
|
|
|
&& ref $class_or_self |
144
|
|
|
|
|
|
|
&& $class_or_self->{'on_values'} eq 'primes') { |
145
|
4
|
|
|
|
|
6
|
return undef; |
146
|
|
|
|
|
|
|
} |
147
|
496
|
|
|
|
|
653
|
return $class_or_self->SUPER::can($method); |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub _classify { |
151
|
260
|
|
|
260
|
|
183
|
my ($self, $i) = @_; |
152
|
|
|
|
|
|
|
|
153
|
260
|
100
|
|
|
|
375
|
Math::NumSeq::Primes->pred($i) |
154
|
|
|
|
|
|
|
or return 0; |
155
|
|
|
|
|
|
|
|
156
|
124
|
100
|
|
|
|
176
|
my $offset = ($self->{'p_or_m'} eq '+' ? 1 : -1); |
157
|
124
|
|
|
|
|
69
|
my $ret = 0; |
158
|
124
|
|
|
|
|
121
|
my @this = ($i); |
159
|
124
|
|
|
|
|
154
|
while (@this) { |
160
|
171
|
|
|
|
|
118
|
$ret++; |
161
|
171
|
|
|
|
|
92
|
my %next; |
162
|
171
|
|
|
|
|
144
|
foreach my $prime (@this) { |
163
|
175
|
|
|
|
|
295
|
my ($good, @primes) = _prime_factors($prime + $offset); |
164
|
175
|
50
|
|
|
|
230
|
return undef unless $good; |
165
|
|
|
|
|
|
|
|
166
|
175
|
|
|
|
|
356
|
@next{@primes} = (); # hash slice, for uniq |
167
|
|
|
|
|
|
|
} |
168
|
171
|
|
|
|
|
177
|
delete @next{2,3}; # hash slice, not 2 or 3 |
169
|
171
|
|
|
|
|
326
|
@this = keys %next; |
170
|
|
|
|
|
|
|
} |
171
|
124
|
|
|
|
|
177
|
return $ret; |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
sub pred { |
175
|
63
|
|
|
63
|
1
|
150
|
my ($self, $value) = @_; |
176
|
63
|
|
33
|
|
|
161
|
return ($value >= 0 |
177
|
|
|
|
|
|
|
&& $value == int($value)); |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
1; |
181
|
|
|
|
|
|
|
__END__ |