| 1 | # Copyright 2011, 2012, 2013, 2014, 2016, 2017, 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 | # math-image --values=BaumSweet --path=ZOrderCurve | ||||||||||||||||||||
| 20 | # | ||||||||||||||||||||
| 21 | # radix parameter ? | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | package Math::NumSeq::BaumSweet; | ||||||||||||||||||||
| 25 | 1 | ▶ | use 5.004; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 26 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 1 | ▶ | use vars '$VERSION','@ISA'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 29 | 1 | $VERSION = 75; | |||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 1 | ▶ | use Math::NumSeq; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 32 | 1 | ▶ | use Math::NumSeq::Base::IterateIth; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 33 | 1 | @ISA = ('Math::NumSeq::Base::IterateIth', | |||||||||||||||||||
| 34 | 'Math::NumSeq'); | ||||||||||||||||||||
| 35 | 1 | *_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 | ▶ | use constant description => Math::NumSeq::__('Baum-Sweet sequence, 1 if i contains no odd-length run of 0-bits, 0 if it does.'); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 42 | 1 | ▶ | use constant default_i_start => 0; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 43 | 1 | ▶ | use constant values_min => 0; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 44 | 1 | ▶ | use constant values_max => 1; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 45 | 1 | ▶ | use constant characteristic_integer => 1; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | # cf A037011 "Baum Sweet cubic" | ||||||||||||||||||||
| 48 | # a(k)=1 iff k/3 is in A003714 fibbinary | ||||||||||||||||||||
| 49 | # | ||||||||||||||||||||
| 50 | # No longer A086747, it now has the first value wrong. | ||||||||||||||||||||
| 51 | # use constant oeis_anum => 'A086747'; # starting OFFSET=0 value 1 | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 141 | ▶ | sub ith { | ||||||||||||||||||
|
Subroutine
ith: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||
| 54 | 141 | my ($self, $i) = @_; | |||||||||||||||||||
| 55 | ### BaumSweet ith(): $i | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 141 | ▶ | if (_is_infinite($i)) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 58 | 0 | return $i; | |||||||||||||||||||
| 59 | } | ||||||||||||||||||||
| 60 | 141 | ▶ | while ($i >= 1) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 61 | 227 | ▶ | if (($i % 2) == 0) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 62 | 104 | my $oddzeros = 0; | |||||||||||||||||||
| 63 | 104 | ▶ | do { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 64 | 159 | $oddzeros ^= 1; | |||||||||||||||||||
| 65 | 159 | $i /= 2; | |||||||||||||||||||
| 66 | } until ($i % 2); | ||||||||||||||||||||
| 67 | 104 | ▶ | if ($oddzeros) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 68 | 77 | return 0; | |||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | } | ||||||||||||||||||||
| 71 | 150 | $i = int($i/2); | |||||||||||||||||||
| 72 | } | ||||||||||||||||||||
| 73 | 64 | return 1; | |||||||||||||||||||
| 74 | } | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 12 | ▶ | sub pred { | ||||||||||||||||||
|
Subroutine
pred: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||
| 77 | 12 | my ($self, $value) = @_; | |||||||||||||||||||
| 78 | 12 | ▶ | return ($value == 0 || $value == 1); | ||||||||||||||||||
|
Condition66%2/3
$value == 0 || $value == 1
MC/DC0%0/2
$value == 0 || $value == 1
$value == 0
$value == 1
Truth table66%2/3
A || B
A= $value == 0B= $value == 1
| |||||||||||||||||||||
| 79 | } | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 1 | 1; | |||||||||||||||||||
| 82 | __END__ | ||||||||||||||||||||