File Coverage

blib/lib/Math/NumSeq/BaumSweet.pm
Criterion Covered Total %
statement 47 48 97.9
branch 5 6 83.3
condition 2 3 66.6
subroutine 13 13 100.0
pod 2 2 100.0
total 69 72 95.8


line stmt bran cond sub pod time code
1             # Copyright 2011, 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              
19             # math-image --values=BaumSweet --path=ZOrderCurve
20             #
21             # radix parameter ?
22              
23              
24             package Math::NumSeq::BaumSweet;
25 1     1   11513 use 5.004;
  1         6  
  1         50  
26 1     1   7 use strict;
  1         1  
  1         51  
27              
28 1     1   7 use vars '$VERSION','@ISA';
  1         2  
  1         93  
29             $VERSION = 71;
30              
31 1     1   7 use Math::NumSeq;
  1         2  
  1         21  
32 1     1   6 use Math::NumSeq::Base::IterateIth;
  1         3  
  1         73  
33             @ISA = ('Math::NumSeq::Base::IterateIth',
34             'Math::NumSeq');
35             *_is_infinite = \&Math::NumSeq::_is_infinite;
36              
37             # uncomment this to run the ### lines
38             #use Smart::Comments;
39              
40             # use constant name => Math::NumSeq::__('Baum-Sweet');
41 1     1   6 use constant description => Math::NumSeq::__('Baum-Sweet sequence, 1 if i contains no odd-length run of 0-bits, 0 if it does.');
  1         1  
  1         6  
42 1     1   5 use constant default_i_start => 0;
  1         1  
  1         65  
43 1     1   6 use constant values_min => 0;
  1         3  
  1         42  
44 1     1   6 use constant values_max => 1;
  1         3  
  1         46  
45 1     1   4 use constant characteristic_integer => 1;
  1         2  
  1         36  
46              
47             # cf A037011 "Baum Sweet cubic"
48             # a(k)=1 iff k/3 is in A003714 fibbinary
49             #
50 1     1   4 use constant oeis_anum => 'A086747'; # starting OFFSET=0 value 1
  1         2  
  1         210  
51              
52             sub ith {
53 141     141 1 775 my ($self, $i) = @_;
54             ### BaumSweet ith(): $i
55              
56 141 50       405 if (_is_infinite($i)) {
57 0         0 return $i;
58             }
59 141         349 while ($i >= 1) {
60 227 100       907 if (($i % 2) == 0) {
61 104         129 my $oddzeros = 0;
62 104         114 do {
63 159         170 $oddzeros ^= 1;
64 159         478 $i /= 2;
65             } until ($i % 2);
66 104 100       206 if ($oddzeros) {
67 77         493 return 0;
68             }
69             }
70 150         436 $i = int($i/2);
71             }
72 64         220 return 1;
73             }
74              
75             sub pred {
76 12     12 1 71 my ($self, $value) = @_;
77 12   66     57 return ($value == 0 || $value == 1);
78             }
79              
80             1;
81             __END__