NumSeq.pm

filter: Statementstmt 91.8% 79 / 86 Branchbran 72.2% 13 / 18 Conditioncond 56.0% 14 / 25 MC/DCmcdc 20.0% 3 / 15 Subroutinesub 96.6% 29 / 30 Podpod 56.2% 9 / 16 totaltotal 77.3% 147 / 190 CC 20 SCAR 9.3
CC
20
Cov
82%
characteristic
6.7
BEGIN
4.1
can
3.3
CRAP 2.5
« NumSeq/RadixConversion.pm ↑ Summary NumSeq/Modulo.pm »
1 # Copyright 2010, 2011, 2012, 2013, 2014, 2016, 2019, 2020 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 63 ▶use 5.004;
Subroutine BEGIN: called CC=1 SCAR=0.0
60 63 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
61  
62 63 ▶use vars '$VERSION', '@ISA';
Subroutine BEGIN: called CC=1 SCAR=0.0
63 63 $VERSION = 75;
64  
65 # uncomment this to run the ### lines
66 #use Smart::Comments;
67  
68 63 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=14.2
69 63 ▶ eval "\n#line ".(__LINE__+1)." \"".__FILE__."\"\n" . <<'HERE'
Branch: 1 branch
BranchTrueFalseTotal
eval "\n#line 70 \"/home/cpancover/.cpan/build/Math-NumSeq-75-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-75-0/blib/lib/Math/NumSeq.pm\"\n# print \"fallback definition of __\\n\";\nsub __ { \$_[0] };\n1;\n" or die $@ 63 0 63
Condition33%1/3
eval "\n#line 70 \"/home/cpancover/.cpan/build/Math-NumSeq-75-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-75-0/blib/lib/Math/NumSeq.pm\"\n# print \"fallback definition of __\\n\";\nsub __ { \$_[0] };\n1;\n"
l!l&&r!l&&!r
0630
MC/DC0%0/2
eval "\n#line 70 \"/home/cpancover/.cpan/build/Math-NumSeq-75-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-75-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-75-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-75-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-75-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-75-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 0 ▶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 746 ▶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 63 ▶use constant description => undef;
Subroutine BEGIN: called CC=1 SCAR=0.0
91 19 ▶sub oeis_anum {
Subroutine oeis_anum: called CC=2 SCAR=6.9
Pod documented
92 19 my ($self) = @_;
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 63 ▶use constant default_i_start => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
97 3609 ▶sub i_start {
Subroutine i_start: called CC=2 SCAR=6.9
Pod documented
98 3609 my ($self) = @_;
99 return (defined $self->{'i_start'}
100 3609 ▶ ? $self->{'i_start'}
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'i_start'} ? : 181 3428 3609
101 : $self->default_i_start);
102 }
103 38 ▶sub values_min {
Subroutine values_min: called CC=1 SCAR=0.0
Pod documented
104 38 my ($self) = @_;
105 38 return $self->{'values_min'};
106 }
107 0 ▶sub values_max {
Subroutine values_max: not called CC=1 SCAR=6.9
Pod documented
108 0 my ($self) = @_;
109 0 return $self->{'values_max'};
110 }
111  
112 63 ▶use constant parameter_info_array => [];
Subroutine BEGIN: called CC=1 SCAR=0.0
113 1020 ▶sub parameter_info_list {
Subroutine parameter_info_list: called CC=1 SCAR=0.0
Pod documented
114 1020 return @{$_[0]->parameter_info_array};
115 }
116  
117 # not documented yet
118 63 my %parameter_info_hash;
119 10 ▶sub parameter_info_hash {
Subroutine parameter_info_hash: called CC=3 SCAR=11.3
Pod undocumented
120 10 my ($class_or_self) = @_;
121 10 ▶ my $class = (ref $class_or_self || $class_or_self);
Condition33%1/3
ref $class_or_self || $class_or_self
l!l&&r!l&&!r
0100
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 10 ▶ ||= { map { $_->{'name'} => $_ }
Condition100%2/2
$parameter_info_hash{$class} ||= {map({$_->{"name"}, $_;} $class_or_self->parameter_info_list)}
l!l
55
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 3 ▶sub parameter_default {
Subroutine parameter_default: called CC=2 SCAR=7.6
Pod undocumented
129 3 my ($class_or_self, $name) = @_;
130 ### Values parameter_default: @_
131 ### info: $class_or_self->parameter_info_hash->{$name}
132 3 my $info;
133 return (($info = $class_or_self->parameter_info_hash->{$name})
134 3 ▶ && $info->{'default'});
Condition33%1/3
($info = $class_or_self->parameter_info_hash->{$name}) && $info->{'default'}
!ll&&!rl&&r
003
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 table33%1/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 861 ▶sub characteristic {
Subroutine characteristic: called CC=5 SCAR=19.1
Pod documented
143 861 my $self = shift;
144 861 my $type = shift;
145 861 ▶ if (ref $self
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self and my $href = $self->{"characteristic"}) 0 861 861
Condition33%1/3
ref $self and my $href = $self->{"characteristic"}
!ll&&!rl&&r
08610
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 861 ▶ if (my $subr = $self->can("characteristic_${type}")) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $subr = $self->can("characteristic_$type")) 553 308 861
152 553 return $self->$subr (@_);
153 }
154 308 return undef;
155 }
156  
157 # default i_start if "increasing"
158 16 ▶sub characteristic_increasing_from_i {
Subroutine characteristic_increasing_from_i: called CC=2 SCAR=6.9
Pod undocumented
159 16 my ($self) = @_;
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 29 ▶sub characteristic_non_decreasing {
Subroutine characteristic_non_decreasing: called CC=1 SCAR=0.0
Pod undocumented
167 29 my ($self) = @_;
168 29 return $self->characteristic('increasing');
169 }
170 17 ▶sub characteristic_non_decreasing_from_i {
Subroutine characteristic_non_decreasing_from_i: called CC=2 SCAR=6.9
Pod undocumented
171 17 my ($self) = @_;
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 4 ▶sub characteristic_integer {
Subroutine characteristic_integer: called CC=1 SCAR=0.0
Pod undocumented
179 4 my ($self) = @_;
180 4 return $self->characteristic_count;
181 }
182 63 ▶use constant characteristic_count => undef; # don't know
Subroutine BEGIN: called CC=1 SCAR=0.0
183  
184  
185 #------------------------------------------------------------------------------
186  
187 975 ▶sub new {
Subroutine new: called CC=3 SCAR=11.0
Pod documented
188 975 my ($class, %self) = @_;
189 ### Sequence new(): $class
190 975 my $self = bless \%self, $class;
191  
192 975 foreach my $pinfo ($self->parameter_info_list) {
193 936 my $pname = $pinfo->{'name'};
194 936 ▶ if (! defined $self->{$pname}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{$pname}) 176 760 936
195 ### default: $pname
196 176 $self->{$pname} = $pinfo->{'default'};
197 }
198 }
199 975 $self->rewind;
200 974 return $self;
201 }
202  
203 456 ▶sub tell_i {
Subroutine tell_i: called CC=1 SCAR=0.0
Pod documented
204 456 my ($self) = @_;
205 456 return $self->{'i'};
206 }
207  
208 2722 ▶sub ith_pair {
Subroutine ith_pair: called CC=1 SCAR=0.0
Pod documented
209 2722 my ($self, $i) = @_;
210 2722 return ($self->ith($i), $self->ith($i+1));
211 }
212  
213 48679 ▶sub can {
Subroutine can: called CC=3 SCAR=12.0
Pod undocumented
214 48679 my ($class, $method) = @_;
215 48679 ▶ 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 48451 48451
Condition66%2/3
$method eq "ith_pair" and not +(return $class->can("ith"))
!ll&&!rl&&r
484512280
MC/DC0%0/2
$method eq "ith_pair" and not +(return $class->can("ith"))
$method eq "ith_pair" not +(return $class->can("ith"))
Truth table66%2/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 48451 return $class->SUPER::can($method);
219 }
220  
221 #------------------------------------------------------------------------------
222 # shared internals
223  
224 # cf Data::Float, but it might not handle BigFloat
225 237006 ▶sub _is_infinite {
Subroutine _is_infinite: called CC=3 SCAR=11.4
226 237006 my ($x) = @_;
227 237006 ▶ return ($x != $x # nan
Condition66%4/6
$x != $x || $x != 0 && $x == 2 * $x
l!l&&r!l&&!r
60237000
$x != 0 and $x == 2 * $x
!ll&&!rl&&r
5932364070
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 63 ▶use constant::defer _bigint => sub {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
233 # no selection of back-end here, leave that to an application
234 14 require Math::BigInt;
235 14 return 'Math::BigInt';
236 63 };
237  
238 1659 ▶sub _to_bigint {
Subroutine _to_bigint: called CC=1 SCAR=0.0
239 1659 my ($n) = @_;
240 # stringize to avoid UV->BigInt bug in Math::BigInt::GMP version 1.37
241 1659 return _bigint()->new("$n");
242 }
243  
244 63 1;
245 __END__
« NumSeq/RadixConversion.pm ↑ Summary NumSeq/Modulo.pm »