NumSeq/LiouvilleFunction.pm

filter: Statementstmt 89.6% 52 / 58 Branchbran 100% 4 / 4 Conditioncond 22.2% 2 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 83.3% 15 / 18 Podpod 71.4% 5 / 7 totaltotal 76.4% 78 / 102 CC 6 SCAR 7.8
CC
6
Cov
82%
characteristic_integer
6.0
characteristic_pn1
6.0
pred
2.0
CRAP 2.2
« NumSeq/SqrtContinuedPeriod.pm ↑ Summary NumSeq/MephistoWaltz.pm »
1 # Copyright 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 package Math::NumSeq::LiouvilleFunction;
19 1 ▶use 5.004;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use List::Util 'max','min';
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 1 ▶use vars '$VERSION','@ISA';
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 $VERSION = 75;
25  
26 1 ▶use Math::NumSeq;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use Math::NumSeq::Base::IterateIth;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 @ISA = ('Math::NumSeq::Base::IterateIth',
29 'Math::NumSeq');
30  
31 1 ▶use Math::NumSeq::PrimeFactorCount;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 1 *_prime_factors = \&Math::NumSeq::PrimeFactorCount::_prime_factors;
33  
34 # uncomment this to run the ### lines
35 #use Smart::Comments;
36  
37  
38 # use constant name => Math::NumSeq::__('Liouville Function');
39 1 ▶use constant default_i_start => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 1 ▶use constant parameter_info_array =>
Subroutine BEGIN: called CC=1 SCAR=0.0
42 [ {
43 name => 'values_type',
44 share_key => 'values_type_1-1_01_10',
45 type => 'enum',
46 default => '1,-1',
47 choices => ['1,-1',
48 '0,1',
49 '1,0',
50 ],
51 # TRANSLATORS: "1,-1" offered for translation of the "," if that might look like a decimal point, otherwise can be left unchanged
52 choices_display => [Math::NumSeq::__('1,-1'),
53 Math::NumSeq::__('0,1'),
54 Math::NumSeq::__('1,0'),
55 ],
56 description => Math::NumSeq::__('The values to give for even or odd parity.'),
57 },
58 1 ];
59  
60 6 ▶sub description {
Subroutine description: called CC=2 SCAR=6.9
Pod documented
61 6 my ($self) = @_;
62 6 ▶ my ($even,$odd) = (ref $self ? @{$self->{'values'}} : (1,-1));
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 3 3 6
63 # ENHANCE-ME: use __x(), maybe
64 6 return sprintf(Math::NumSeq::__('The Liouville function, being %s for an even number of prime factors or %s for an odd number.'),
65 $even, $odd);
66 }
67  
68 1 ▶use constant characteristic_increasing => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
69 0 ▶sub characteristic_integer {
Subroutine characteristic_integer: not called CC=2 SCAR=17.9
Pod undocumented
70 0 my ($self) = @_;
71 return (_is_integer($self->{'values_min'})
72 0 ▶ && _is_integer($self->{'values_max'}));
Condition0%0/3
_is_integer($self->{'values_min'}) && _is_integer($self->{'values_max'})
!ll&&!rl&&r
000
MC/DC0%0/2
_is_integer($self->{'values_min'}) && _is_integer($self->{'values_max'})
_is_integer($self->{'values_min'}) _is_integer($self->{'values_max'})
Truth table0%0/3
A && B
A= _is_integer($self->{'values_min'})B= _is_integer($self->{'values_max'})
ABresult
0X0
100
111
73 }
74 0 ▶sub characteristic_pn1 {
Subroutine characteristic_pn1: not called CC=2 SCAR=17.9
Pod undocumented
75 0 my ($self) = @_;
76 0 ▶ return ($self->{'values_min'} == -1 && $self->{'values_max'} == 1);
Condition0%0/3
$self->{'values_min'} == -1 && $self->{'values_max'} == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{'values_min'} == -1 && $self->{'values_max'} == 1
$self->{'values_min'} == -1 $self->{'values_max'} == 1
Truth table0%0/3
A && B
A= $self->{'values_min'} == -1B= $self->{'values_max'} == 1
ABresult
0X0
100
111
77 }
78  
79 #------------------------------------------------------------------------------
80 # cf A026424 the -1 positions, odd number of primes
81 # A028260 the 1 positions, even number of primes
82 # A072203 cumulative +/-1
83 # A055038 cumulative 1=odd
84 # A028488 where cumulative==0
85 # A051470 first cumulative==n
86  
87 1 my %oeis_anum = ('1,-1' => 'A008836', # liouville 1,-1
88 '0,1' => 'A066829', # 0 and 1
89 '1,0' => 'A065043', # 1 and 0
90 # OEIS-Catalogue: A008836
91 # OEIS-Catalogue: A066829 values_type=0,1
92 # OEIS-Catalogue: A065043 values_type=1,0
93 );
94 3 ▶sub oeis_anum {
Subroutine oeis_anum: called CC=1 SCAR=0.0
Pod documented
95 3 my ($self) = @_;
96 3 return $oeis_anum{join(',',@{$self->{'values'}})};
97 }
98  
99  
100 #------------------------------------------------------------------------------
101  
102 3 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
103 3 my $self = shift->SUPER::new(@_);
104  
105 3 my @values = split /,/, $self->{'values_type'};
106 3 $self->{'values'} = \@values;
107 3 $self->{'values_min'} = min(@values);
108 3 $self->{'values_max'} = max(@values);
109 3 return $self;
110 }
111  
112 237 ▶sub ith {
Subroutine ith: called CC=2 SCAR=6.9
Pod documented
113 237 my ($self, $i) = @_;
114 ### LiouvilleFunction ith(): $i
115  
116 237 my ($good, @primes) = _prime_factors($i);
117 return ($good
118 237 ▶ ? $self->{'values'}->[scalar(@primes) & 1]
Branch: 1 branch
BranchTrueFalseTotal
$good ? : 228 9 237
119 : undef);
120 }
121  
122 24 ▶sub pred {
Subroutine pred: called CC=2 SCAR=7.1
Pod documented
123 24 my ($self, $value) = @_;
124 return ($value == $self->{'values'}->[0]
125 24 ▶ || $value == $self->{'values'}->[1]);
Condition66%2/3
$value == $self->{'values'}[0] || $value == $self->{'values'}[1]
l!l&&r!l&&!r
9150
MC/DC0%0/2
$value == $self->{'values'}[0] || $value == $self->{'values'}[1]
$value == $self->{'values'}[0] $value == $self->{'values'}[1]
Truth table66%2/3
A || B
A= $value == $self->{'values'}[0]B= $value == $self->{'values'}[1]
ABresult
1X1
011
000
126 }
127  
128 #------------------------------------------------------------------------------
129 # generic
130  
131 0 ▶sub _is_integer {
Subroutine _is_integer: not called CC=1 SCAR=6.9
132 0 my ($n) = @_;
133 0 return ($n == int($n));
134 }
135  
136 1 1;
137 __END__
« NumSeq/SqrtContinuedPeriod.pm ↑ Summary NumSeq/MephistoWaltz.pm »