NumSeq.pm

filter: Statementstmt 88.3% 76 / 86 Branchbran 72.2% 13 / 18 Conditioncond 52.0% 13 / 25 MC/DCmcdc 20.0% 3 / 15 Subroutinesub 93.3% 28 / 30 Podpod 56.2% 9 / 16 totaltotal 74.7% 142 / 190 CC 20 SCAR 9.9
CC
20
Cov
79%
characteristic
6.7
parameter_default
6.0
BEGIN
4.1
CRAP 2.7
« NumSeq/ErdosSelfridgeClass.pm ↑ Summary NumSeq/HofstadterFigure.pm »
1 # Copyright 2010, 2011, 2012, 2013, 2014, 2016, 2019 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 <http://www.gnu.org/licenses/>.
17  
18  
19 # ($value1,$value2) = $self->ith_pair($i);
20 # Return values for $i and $i+1, possibly undefs.
21 # Same as ($self->ith($i), $self->ith($i+1)) but some classes faster.
22 # SternDiatomic
23 # Fibonacci -- with ith() being sans last bit
24 # ith_pair_from_bits_hightolow()
25 # LucasNumbers -- F,L then last step L,L
26 # ith_FL_from_bits_hightolow()
27  
28 # $value = $seq->value_floor($value)
29 # $value = $seq->value_ceil($value)
30 # $value = $seq->value_next($value)
31 # characteristic('distinct')
32 # characteristic('geometric') geometric progression constant multipler
33 # characteristic('arithmetic') arithmetic progression constant add
34 # characteristic('primitive') no term divisible by any other
35 # characteristic('mult_prev') each term multiple of previous
36  
37 # $seq->i_end last i if finite, and if known ??
38 # characteristic('i_end')
39 # characteristic('i_finite') boolean
40  
41 # ->add ->sub of sequence or constant
42 # ->mul
43 # ->mod($k) of constant
44 # overloads
45 # ->shift
46 # ->inverse some with known ways to calculate
47 # ->is_subset_of
48  
49 # lo,hi i or value
50 # lo_value,hi_value
51  
52 # Sequence::Array from arrayref
53 # Derived::Interleave
54  
55  
56  
57  
58 package Math::NumSeq;
59 62 ▶use 5.004;
Subroutine BEGIN: called CC=1 SCAR=0.0
60 62 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
61  
62 62 ▶use vars '$VERSION', '@ISA';
Subroutine BEGIN: called CC=1 SCAR=0.0
63 62 $VERSION = 74;
64  
65 # uncomment this to run the ### lines
66 #use Smart::Comments;
67  
68 BEGIN {
69 62 ▶ eval "\n#line ".(__LINE__+1)." \"".__FILE__."\"\n" . <<'HERE'
Subroutine BEGIN: called CC=3 SCAR=14.2
Branch: 1 branch
BranchTrueFalseTotal
eval "\n#line 70 \"/home/cpancover/.cpan/build/Math-NumSeq-74-0/blib/lib/Math/NumSeq.pm\"\n# print \"attempt Locale::Messages for __\\n\";\nuse Locale::Messages ();\nsub __ { Locale::Messages::dgettext('Math-NumSeq',\$_[0]) }\n1;\n" or eval "\n#line 76 \"/home/cpancover/.cpan/build/Math-NumSeq-74-0/blib/lib/Math/NumSeq.pm\"\n# print \"fallback definition of __\\n\";\nsub __ { \$_[0] };\n1;\n" or die $@ 0 62 62
Condition33%1/3
eval "\n#line 70 \"/home/cpancover/.cpan/build/Math-NumSeq-74-0/blib/lib/Math/NumSeq.pm\"\n# print \"attempt Locale::Messages for __\\n\";\nuse Locale::Messages ();\nsub __ { Locale::Messages::dgettext('Math-NumSeq',\$_[0]) }\n1;\n" or eval "\n#line 76 \"/home/cpancover/.cpan/build/Math-NumSeq-74-0/blib/lib/Math/NumSeq.pm\"\n# print \"fallback definition of __\\n\";\nsub __ { \$_[0] };\n1;\n"
l!l&&r!l&&!r
0620
MC/DC0%0/2
eval "\n#line 70 \"/home/cpancover/.cpan/build/Math-NumSeq-74-0/blib/lib/Math/NumSeq.pm\"\n# print \"attempt Locale::Messages for __\\n\";\nuse Locale::Messages ();\nsub __ { Locale::Messages::dgettext('Math-NumSeq',\$_[0]) }\n1;\n" or eval "\n#line 76 \"/home/cpancover/.cpan/build/Math-NumSeq-74-0/blib/lib/Math/NumSeq.pm\"\n# print \"fallback definition of __\\n\";\nsub __ { \$_[0] };\n1;\n"
eval "\n#line 70 \"/home/cpancover/.cpan/build/Math-NumSeq-74-0/blib/lib/Math/NumSeq.pm\"\n# print \"attempt Locale::Messages for __\\n\";\nuse Locale::Messages ();\nsub __ { Locale::Messages::dgettext('Math-NumSeq',\$_[0]) }\n1;\n" eval "\n#line 76 \"/home/cpancover/.cpan/build/Math-NumSeq-74-0/blib/lib/Math/NumSeq.pm\"\n# print \"fallback definition of __\\n\";\nsub __ { \$_[0] };\n1;\n"
Truth table33%1/3
A or B
A= eval "\n#line 70 \"/home/cpancover/.cpan/build/Math-NumSeq-74-0/blib/lib/Math/NumSeq.pm\"\n# print \"attempt Locale::Messages for __\\n\";\nuse Locale::Messages ();\nsub __ { Locale::Messages::dgettext('Math-NumSeq',\$_[0]) }\n1;\n"B= eval "\n#line 76 \"/home/cpancover/.cpan/build/Math-NumSeq-74-0/blib/lib/Math/NumSeq.pm\"\n# print \"fallback definition of __\\n\";\nsub __ { \$_[0] };\n1;\n"
ABresult
1X1
011
000
70 # print "attempt Locale::Messages for __\n";
71 62 ▶use Locale::Messages ();
Subroutine BEGIN: called CC=1 SCAR=2.6
72 sub __ { Locale::Messages::dgettext('Math-NumSeq',$_[0]) }
73 1;
74 HERE
75 || eval "\n#line ".(__LINE__+1)." \"".__FILE__."\"\n" . <<'HERE'
76 # print "fallback definition of __\n";
77 740 ▶sub __ { $_[0] };
Subroutine __: called CC=1 SCAR=0.0
78 1;
79 HERE
80 || die $@;
81 }
82  
83 # sub name {
84 # my ($self) = @_;
85 # my $name = ref($self) || $self;
86 # $name =~ s/^Math::NumSeq:://;
87 # return $name;
88 # }
89  
90 62 ▶use constant description => undef;
Subroutine BEGIN: called CC=1 SCAR=0.0
91 sub oeis_anum {
92 19 ▶ my ($self) = @_;
Subroutine oeis_anum: called CC=2 SCAR=6.9
Pod documented
93 19 ▶ return $self->{'oeis_anum'} || undef;
Condition100%2/2
$self->{'oeis_anum'} || undef
l!l
154
MC/DC100%1/1
$self->{'oeis_anum'} || undef
$self->{'oeis_anum'}
Truth table100%2/2
A
A= $self->{'oeis_anum'}
Aresult
11
00
94 }
95  
96 62 ▶use constant default_i_start => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
97 sub i_start {
98 3607 ▶ my ($self) = @_;
Subroutine i_start: called CC=2 SCAR=6.9
Pod documented
99 return (defined $self->{'i_start'}
100 3607 ▶ ? $self->{'i_start'}
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'i_start'} ? : 181 3426 3607
101 : $self->default_i_start);
102 }
103 sub values_min {
104 38 ▶ my ($self) = @_;
Subroutine values_min: called CC=1 SCAR=0.0
Pod documented
105 38 return $self->{'values_min'};
106 }
107 sub values_max {
108 0 ▶ my ($self) = @_;
Subroutine values_max: not called CC=1 SCAR=6.9
Pod documented
109 0 return $self->{'values_max'};
110 }
111  
112 62 ▶use constant parameter_info_array => [];
Subroutine BEGIN: called CC=1 SCAR=0.0
113 sub parameter_info_list {
114 1017 ▶ return @{$_[0]->parameter_info_array};
Subroutine parameter_info_list: called CC=1 SCAR=0.0
Pod documented
115 }
116  
117 # not documented yet
118 62 my %parameter_info_hash;
119 sub parameter_info_hash {
120 5 ▶ my ($class_or_self) = @_;
Subroutine parameter_info_hash: called CC=3 SCAR=11.3
Pod undocumented
121 5 ▶ my $class = (ref $class_or_self || $class_or_self);
Condition33%1/3
ref $class_or_self || $class_or_self
l!l&&r!l&&!r
050
MC/DC0%0/2
ref $class_or_self || $class_or_self
ref $class_or_self $class_or_self
Truth table33%1/3
A || B
A= ref $class_or_selfB= $class_or_self
ABresult
1X1
011
000
122 return ($parameter_info_hash{$class}
123 5 ▶ ||= { map { $_->{'name'} => $_ }
Condition100%2/2
$parameter_info_hash{$class} ||= {map({$_->{"name"}, $_;} $class_or_self->parameter_info_list)}
l!l
14
MC/DC100%1/1
$parameter_info_hash{$class} ||= {map({$_->{"name"}, $_;} $class_or_self->parameter_info_list)}
$parameter_info_hash{$class}
Truth table100%2/2
A
A= $parameter_info_hash{$class}
Aresult
11
00
124 $class_or_self->parameter_info_list });
125 }
126  
127 # not documented yet
128 sub parameter_default {
129 0 ▶ my ($class_or_self, $name) = @_;
Subroutine parameter_default: not called CC=2 SCAR=17.9
Pod undocumented
130 ### Values parameter_default: @_
131 ### info: $class_or_self->parameter_info_hash->{$name}
132 0 my $info;
133 return (($info = $class_or_self->parameter_info_hash->{$name})
134 0 ▶ && $info->{'default'});
Condition0%0/3
($info = $class_or_self->parameter_info_hash->{$name}) && $info->{'default'}
!ll&&!rl&&r
000
MC/DC0%0/2
($info = $class_or_self->parameter_info_hash->{$name}) && $info->{'default'}
($info = $class_or_self->parameter_info_hash->{$name}) $info->{'default'}
Truth table0%0/3
A && B
A= ($info = $class_or_self->parameter_info_hash->{$name})B= $info->{'default'}
ABresult
0X0
100
111
135 }
136  
137  
138 # pn1 values +1, -1, 0
139 # permutation
140 # delta
141 # boolean ?
142 sub characteristic {
143 860 ▶ my $self = shift;
Subroutine characteristic: called CC=5 SCAR=19.1
Pod documented
144 860 my $type = shift;
145 860 ▶ if (ref $self
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self and my $href = $self->{"characteristic"}) 0 860 860
Condition33%1/3
ref $self and my $href = $self->{"characteristic"}
!ll&&!rl&&r
08600
MC/DC0%0/2
ref $self and my $href = $self->{"characteristic"}
ref $self my $href = $self->{"characteristic"}
Truth table33%1/3
A and B
A= ref $selfB= my $href = $self->{"characteristic"}
ABresult
0X0
100
111
146 && (my $href = $self->{'characteristic'})) {
147 0 ▶ if (exists $href->{$type}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $href->{$type}) 0 0 0
148 0 return $href->{$type};
149 }
150 }
151 860 ▶ if (my $subr = $self->can("characteristic_${type}")) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $subr = $self->can("characteristic_$type")) 552 308 860
152 552 return $self->$subr (@_);
153 }
154 308 return undef;
155 }
156  
157 # default i_start if "increasing"
158 sub characteristic_increasing_from_i {
159 16 ▶ my ($self) = @_;
Subroutine characteristic_increasing_from_i: called CC=2 SCAR=6.9
Pod undocumented
160 16 ▶ return ($self->characteristic('increasing')
Branch: 1 branch
BranchTrueFalseTotal
$self->characteristic('increasing') ? : 6 10 16
161 ? $self->i_start
162 : undef);
163 }
164  
165 # default from the stronger condition "increasing"
166 sub characteristic_non_decreasing {
167 29 ▶ my ($self) = @_;
Subroutine characteristic_non_decreasing: called CC=1 SCAR=0.0
Pod undocumented
168 29 return $self->characteristic('increasing');
169 }
170 sub characteristic_non_decreasing_from_i {
171 17 ▶ my ($self) = @_;
Subroutine characteristic_non_decreasing_from_i: called CC=2 SCAR=6.9
Pod undocumented
172 17 ▶ return ($self->characteristic('non_decreasing')
Branch: 1 branch
BranchTrueFalseTotal
$self->characteristic('non_decreasing') ? : 9 8 17
173 ? $self->i_start
174 : undef);
175 }
176  
177 # default "count" is integer
178 sub characteristic_integer {
179 4 ▶ my ($self) = @_;
Subroutine characteristic_integer: called CC=1 SCAR=0.0
Pod undocumented
180 4 return $self->characteristic_count;
181 }
182 62 ▶use constant characteristic_count => undef; # don't know
Subroutine BEGIN: called CC=1 SCAR=0.0
183  
184  
185 #------------------------------------------------------------------------------
186  
187 sub new {
188 973 ▶ my ($class, %self) = @_;
Subroutine new: called CC=3 SCAR=11.0
Pod documented
189 ### Sequence new(): $class
190 973 my $self = bless \%self, $class;
191  
192 973 foreach my $pinfo ($self->parameter_info_list) {
193 935 my $pname = $pinfo->{'name'};
194 935 ▶ if (! defined $self->{$pname}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{$pname}) 177 758 935
195 ### default: $pname
196 177 $self->{$pname} = $pinfo->{'default'};
197 }
198 }
199 973 $self->rewind;
200 972 return $self;
201 }
202  
203 sub tell_i {
204 456 ▶ my ($self) = @_;
Subroutine tell_i: called CC=1 SCAR=0.0
Pod documented
205 456 return $self->{'i'};
206 }
207  
208 sub ith_pair {
209 2722 ▶ my ($self, $i) = @_;
Subroutine ith_pair: called CC=1 SCAR=0.0
Pod documented
210 2722 return ($self->ith($i), $self->ith($i+1));
211 }
212  
213 sub can {
214 48678 ▶ my ($class, $method) = @_;
Subroutine can: called CC=3 SCAR=12.0
Pod undocumented
215 48678 ▶ if ($method eq 'ith_pair' && ! return $class->can('ith')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($method eq "ith_pair" and not +(return $class->can("ith"))) 0 48450 48450
Condition66%2/3
$method eq "ith_pair" and not +(return $class->can("ith"))
!ll&&!rl&&r
484502280
MC/DC0%0/2
$method eq "ith_pair" and not +(return $class->can("ith"))
$method eq "ith_pair" not +(return $class->can("ith"))
Truth table33%1/3
A and not(B)
A= $method eq "ith_pair"B= not +(return $class->can("ith"))
ABresult
0X0
100
111
216 0 return undef;
217 }
218 48450 return $class->SUPER::can($method);
219 }
220  
221 #------------------------------------------------------------------------------
222 # shared internals
223  
224 # cf Data::Float, but it might not handle BigFloat
225 sub _is_infinite {
226 236986 ▶ my ($x) = @_;
Subroutine _is_infinite: called CC=3 SCAR=11.4
227 236986 ▶ return ($x != $x # nan
Condition66%4/6
$x != $x || $x != 0 && $x == 2 * $x
l!l&&r!l&&!r
30236983
$x != 0 and $x == 2 * $x
!ll&&!rl&&r
5922363910
MC/DC33%1/3
$x != $x || $x != 0 && $x == 2 * $x
$x != $x $x != 0 $x == 2 * $x
Truth table75%3/4
A || B and C
A= $x != $xB= $x != 0C= $x == 2 * $x
ABCresult
1XX1
0111
00X0
0100
228 || ($x != 0 && $x == 2*$x)); # inf
229 }
230  
231 # or maybe check for new enough for uv->mpz fix
232 use constant::defer _bigint => sub {
233 # no selection of back-end here, leave that to an application
234 14 ▶ require Math::BigInt;
Subroutine __ANON__: called CC=1 SCAR=0.0
235 14 return 'Math::BigInt';
236 62 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
237  
238 sub _to_bigint {
239 1659 ▶ my ($n) = @_;
Subroutine _to_bigint: called CC=1 SCAR=0.0
240 # stringize to avoid UV->BigInt bug in Math::BigInt::GMP version 1.37
241 1659 return _bigint()->new("$n");
242 }
243  
244 62 1;
245 __END__
« NumSeq/ErdosSelfridgeClass.pm ↑ Summary NumSeq/HofstadterFigure.pm »