NumSeq/DedekindPsiSteps.pm

filter: Statementstmt 98.6% 71 / 72 Branchbran 78.5% 11 / 14 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 14 / 14 Podpod 100% 1 / 1 totaltotal 93.4% 99 / 106 CC 11 SCAR 17.3
CC
11
Cov
94%
ith
11.2
BEGIN
1.0
BEGIN
1.0
CRAP 5.7
« NumSeq/RepdigitAny.pm ↑ Summary NumSeq/Totient.pm »
1 # Copyright 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::DedekindPsiSteps;
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  
22 1 ▶use vars '$VERSION', '@ISA';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 $VERSION = 75;
24  
25 1 ▶use Math::NumSeq;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use Math::NumSeq::Base::IterateIth;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 @ISA = ('Math::NumSeq::Base::IterateIth',
28 'Math::NumSeq');
29 1 *_is_infinite = \&Math::NumSeq::_is_infinite;
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::__('Dedekind Psi Steps');
39 1 ▶use constant description => Math::NumSeq::__('Number of repeated applications of the Dedekind psi function to reach factors 2 and 3 only.');
Subroutine BEGIN: called CC=1 SCAR=0.0
40 1 ▶use constant default_i_start => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 1 ▶use constant characteristic_count => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 1 ▶use constant characteristic_smaller => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 1 ▶use constant characteristic_increasing => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 1 ▶use constant values_min => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
45  
46 # A001615 dedekind psi
47 # A019268 dedekind psi first requiring n steps
48 # A019269 number of steps
49 # A173290 dedekind psi cumulative
50 #
51 1 ▶use constant oeis_anum => 'A019269';
Subroutine BEGIN: called CC=1 SCAR=0.0
52  
53 108 ▶sub ith {
Subroutine ith: called CC=11 SCAR=24.1
Pod documented
54 108 my ($self, $i) = @_;
55 ### DedekindPsiSteps ith(): $i
56  
57 108 ▶ if (_is_infinite($i)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_infinite($i)) 0 108 108
58 0 return $i;
59 }
60 108 ▶ if ($i < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 0) 3 105 108
61 3 return undef;
62 }
63  
64 105 my ($good, @primes) = _prime_factors($i);
65 105 ▶ return undef unless $good;
Branch: 1 branch
BranchTrueFalseTotal
unless $good 0 105 105
66  
67 105 my %primes;
68 105 foreach my $p (@primes) {
69 176 $primes{$p}++;
70 }
71 105 my $count = 0;
72  
73 105 my %prime_factors;
74 105 for (;;) {
75 143 delete $primes{'2'};
76 143 delete $primes{'3'};
77 143 ▶ last unless %primes;
Branch: 1 branch
BranchTrueFalseTotal
unless %primes 105 38 143
78  
79 ### %primes
80 38 $count++;
81 38 my %next_primes;
82 38 ▶ while (my ($p, $e) = each %primes) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %primes) 38 38 76
83 38 ▶ if (--$e) {
Branch: 1 branch
BranchTrueFalseTotal
if (--$e) 1 37 38
84 1 $next_primes{$p} += $e;
85 }
86 38 ▶ my $prime_factors_aref = ($prime_factors{$p} ||= do {
Condition66%2/3
$prime_factors{$p} ||= do { () = _prime_factors($p + 1); return undef unless $good; \@primes }
l!l&&r!l&&!r
1370
MC/DC0%0/2
$prime_factors{$p} ||= do { () = _prime_factors($p + 1); return undef unless $good; \@primes }
$prime_factors{$p} do { () = _prime_factors($p + 1); return undef unless $good; \@primes }
Truth table66%2/3
A ||= B
A= $prime_factors{$p}B= do { () = _prime_factors($p + 1); return undef unless $good; \@primes }
ABresult
1X1
011
000
87 37 my ($good, @primes) = _prime_factors($p+1);
88 37 ▶ return undef unless $good;
Branch: 1 branch
BranchTrueFalseTotal
unless $good 0 37 37
89 \@primes
90 37 });
91 38 foreach my $f (@$prime_factors_aref) {
92 88 $next_primes{$f}++;
93 }
94 }
95 38 %primes = %next_primes;
96 }
97 105 return $count;
98 }
99  
100 # sub _psi_ex23 {
101 # my ($n) = @_;
102 # ### _psi(): $n
103 #
104 # my $prev = 0;
105 # my $ret = 1;
106 # foreach my $p (prime_factors($n)) {
107 # next if $p == 2 || $p == 3;
108 # if ($p == $prev) {
109 # $ret *= $p;
110 # } else {
111 # $ret *= $p+1;
112 # $prev = $p;
113 # }
114 # }
115 # return $ret;
116 #
117 # # my %primes;
118 # # @primes{prime_factors($n)} = (); # hash slice
119 # # delete $primes{2,3}; # hash slice
120 # # foreach my $p (keys %primes) {
121 # # $n /= $p;
122 # # $n *= $p+1;
123 # # }
124 # return $n;
125 # }
126  
127 # sub _is_2x3y {
128 # my ($n) = @_;
129 # until ($n % 2) {
130 # $n = int($n/2);
131 # }
132 # until ($n % 3) {
133 # $n = int($n/3);
134 # }
135 # return ($n == 1);
136 # }
137  
138 1 1;
139 __END__
« NumSeq/RepdigitAny.pm ↑ Summary NumSeq/Totient.pm »