Math-NumSeq
view release on metacpan or search on metacpan
xt/oeis/Fibbinary-oeis.t view on Meta::CPAN
# Math::NumSeq::FibonacciWord
MyOEIS::compare_values
(anum => 'A003849',
func => sub {
my ($count) = @_;
my $seq = Math::NumSeq::Fibbinary->new;
my @got;
for (my $n = 1; @got < $count; $n++) { # but it actually OFFSET=0
my $value = $seq->ith($n-1);
push @got, $value & 1;
}
return \@got;
});
# as values 1,2
MyOEIS::compare_values
(anum => 'A003842',
func => sub {
my ($count) = @_;
my $seq = Math::NumSeq::Fibbinary->new;
my @got;
for (my $n = 1; @got < $count; $n++) {
my $value = $seq->ith($n-1);
push @got, ($value & 1) + 1;
}
return \@got;
});
#--------
# A123740 -- characteristic of Wythoff AB,
# second lowest bit of Zeck(n-1)
MyOEIS::compare_values
(anum => 'A123740',
func => sub {
my ($count) = @_;
my $seq = Math::NumSeq::Fibbinary->new;
my @got;
for (my $n = 1; @got < $count; $n++) {
my $value = $seq->ith($n-1);
push @got, ($value >> 1) & 1;
}
return \@got;
});
# A123740 -- char func Wythoff AB numbers A003623
# second lowest bit of Zeck per comment by Franklin T. Adams-Watters
MyOEIS::compare_values
(anum => 'A123740',
func => sub {
my ($count) = @_;
my $seq = Math::NumSeq::Fibbinary->new;
my @got = (0);
for (my $n = 0; @got < $count; $n++) {
my $value = $seq->ith($n+1);
push @got, ($value >> 1) & 1;
}
return \@got;
});
# A188009 -- [nr]-[nr-kr]-[kr]
# second lowest bit of Zeck per Wolfdieter Lang formula A123740
MyOEIS::compare_values
(anum => 'A188009',
func => sub {
my ($count) = @_;
my $seq = Math::NumSeq::Fibbinary->new;
my @got = (0,0,0);
for (my $n = 0; @got < $count; $n++) {
my $value = $seq->ith($n+1);
push @got, ($value >> 1) & 1;
}
return \@got;
});
#------------------------------------------------------------------------------
# A003622 - odd Zeckendorfs, ending with 1
MyOEIS::compare_values
(anum => 'A003622',
func => sub {
my ($count) = @_;
my $seq = Math::NumSeq::Fibbinary->new;
my @got;
while (@got < $count) {
my ($i, $value) = $seq->next;
if ($value & 1) { push @got, $i; }
}
return \@got;
});
#------------------------------------------------------------------------------
# A022342 - Zeckendorf even, i where value is even
# floor(n*phi)-1
# "Fibonacci successor"
# shift up Zeckendorf base, new low 0
MyOEIS::compare_values
(anum => 'A022342',
func => sub {
my ($count) = @_;
my $seq = Math::NumSeq::Fibbinary->new;
my @got;
while (@got < $count) {
my ($i, $value) = $seq->next;
if (($value % 2) == 0) {
push @got, $i;
}
}
return \@got;
});
MyOEIS::compare_values # = Zeckendorf shift up 1 place
(anum => q{A022342},
func => sub {
my ($count) = @_;
my $seq = Math::NumSeq::Fibbinary->new;
my @got;
while (@got < $count) {
my ($i, $value) = $seq->next;
push @got, $seq->value_to_i($value<<1);
xt/oeis/Fibbinary-oeis.t view on Meta::CPAN
for (my $c = 1; @got < $count; $c++) {
my $str = ('10' x ($c-1)) . '1';
### $str
my @i;
for (my $pos = 1; $pos <= length($str); $pos += 2) {
my $v = $str;
substr($v,$pos,0) = '0';
### at: "pos=$pos v=$v"
push @i, Math::BigInt->new($v);
}
@i = sort {$a<=>$b} @i;
while (@i && @got < $count) {
push @got, shift @i;
}
}
return \@got;
});
#---------------------
# A346434 -- triangle all numbers with n 1s and n 0s in Zeckendorf,
# as decimal digits
# GP-DEFINE \\ mine, written in decimal digits, compact
# GP-DEFINE A346434_T(n,k) = {
# GP-DEFINE n>=1 || error();
# GP-DEFINE (1<=k && k<=n) || error();
# GP-DEFINE (10*100^n - 9*100^(n-k))\99;
# GP-DEFINE }
# GP-Test my(v=OEIS_data("A346434"),got=[]); \
# GP-Test for(n=1,oo, for(k=1,n, \
# GP-Test if(#got>=#v,break(2)); got=concat(got,A346434_T(n,k)))); \
# GP-Test got==v
# GP-Test /* whole row in data, triangular number */ \
# GP-Test my(len=#OEIS_data("A346434"),n); \
# GP-Test ispolygonal(len,3,&n) && Triangular(n) == len
# GP-Test vector(50,n, vector(n,k, A346434_T(n,k))) == \
# GP-Test vector(50,n, vector(n,k, \
# GP-Test fromdigits(Zeckendorf_digits(A210619_Zeckendorf_euqal_0s1s_T(n,k)))))
# GP-Test my(nk=3); (100^nk - 1)/99 == 010101
#
# cf ~/OEIS/b210619.txt is 49 rows to 1225, size 23853
# ~/OEIS/b346434.txt size 87093
# system("rm /tmp/new/b346434.txt"); \
# my(c=0); for(n=1,49, for(k=1,n, write("/tmp/new/b346434.txt",c++," ",A346434_T(n,k)))); \
# system("ls -l /tmp/new/b346434.txt");
# ,'bfile
# GP-Test my(v=OEIS_data("A346434"),got=[]); \
# GP-Test print("~/OEIS/b346434.txt size "#v); \
# GP-Test for(n=1,oo, \
# GP-Test got=concat(got,vector(n,k,A346434_T(n,k))); \
# GP-Test if(#got>=#v, print(" which is rows 1..",n); break)); \
# GP-Test got==v
#
# GP-DEFINE vector_reps(v,n) = if(n==0,[], concat(vector(n,i,v)));
# GP-Test /* comment 10s and 01s */ \
# GP-Test vector(5,n, vector(n,k, A346434_T(n,k))) == \
# GP-Test vector(5,n, vector(n,k, \
# GP-Test fromdigits(concat(vector_reps([1,0],k), vector_reps([0,1],n-k)))))
#
# GP-Test /* formula */ \
# GP-Test vector(50,n, vector(n,k, A346434_T(n,k))) == \
# GP-Test vector(50,n, vector(n,k, (10*100^n - 9*100^(n-k) - 1)/99 ))
#
# GP-Test /* formula */ \
# GP-Test vector(50,n, vector(n,k, A346434_T(n,k))) == \
# GP-Test vector(50,n, vector(n,k, A014417_to_Zeckendorf(A210619_Zeckendorf_euqal_0s1s_T(n,k)) ))
# GP-Test /* example table */ \
# GP-Test my(n=1); vector(1,k, A346434_T(n,k)) == [ 10 ]
# GP-Test my(n=2); vector(2,k, A346434_T(n,k)) == [ 1001, 1010 ]
# GP-Test my(n=3); vector(3,k, A346434_T(n,k)) == [ 100101, 101001, 101010 ]
# GP-Test my(n=4); vector(4,k, A346434_T(n,k)) == [ 10010101, 10100101, 10101001, 10101010 ]
# GP-Test A346434_T(5,3) == 1010100101
#
# diagonal
# GP-DEFINE A163662(n) = (10^(2*n) - 1)*10/99;
# GP-Test my(v=OEIS_data("A163662")); /* OFFSET=1 */ \
# GP-Test v == vector(#v,n, A163662(n))
# GP-Test vector(50,n, A346434_T(n,n)) == \
# GP-Test vector(50,n, A163662(n))
#
# GP-Test /* prev row is *100 + 1 */ \
# GP-Test vector(50,n,n++; vector(n-1,k, A346434_T(n,k))) == \
# GP-Test vector(50,n,n++; vector(n-1,k, 100*A346434_T(n-1,k) + 1 ))
# GP-DEFINE gA346434_limit(n_limit) = \
# GP-DEFINE sum(n=1,n_limit, sum(k=1,n, A346434_T(n,k)*x^n*y^k));
# GP-Test gA346434_limit(8) == 100*x*gA346434_limit(7) \
# GP-Test + sum(n=1,8, (y-y^n)/(1-y)*x^n + (100^n-1)*10/99*x^n*y^n)
# GP-Test my(k=5); (y-y^k)/(1-y) == y^4 + y^3 + y^2 + y
# GP-Test my(n_limit=50, g=gA346434_limit(n_limit)); \
# GP-Test matrix(n_limit,n_limit,n,k,n--;k--; gf2_term(g,n,k)) == \
# GP-Test matrix(n_limit,n_limit,n,k,n--;k--; \
# GP-Test if(n>=1 && k>=1 && k<=n, A346434_T(n,k)))
# GP-DEFINE gA346434 = \
# GP-DEFINE x*y*(10 - 9*x - 100*x^2*y) / ((1-x)*(1-100*x)*(1-x*y)*(1-100*x*y) );
# GP-Test my(n_limit=50); \
# GP-Test gA346434_limit(n_limit) == \
# GP-Test gA346434 + O(x^(n_limit+1)) + O(y^(n_limit+1))
# GP-Test my(n_limit=50); \
# GP-Test matrix(n_limit,n_limit,n,k,n--;k--; gf2_term(gA346434,n,k)) == \
# GP-Test matrix(n_limit,n_limit,n,k,n--;k--; \
# GP-Test if(n>=1 && k>=1 && k<=n, A346434_T(n,k)))
#
# GP-Test /* partial fractions, based on a y split */ \
# GP-Test gA346434 == \
# GP-Test -x/(1 - 101*x + 100*x^2) \
# GP-Test - (10-109*x)/(99 - 9999*x + 9900*x^2)/(1 - x*y) \
# GP-Test + 10/(99-9900*x)/(1-100*x*y)
#
# GP-Test /* partial fractions, based on an x split */ \
# GP-Test gA346434 == \
# GP-Test -y/(99 - 99*y)/(1 - x) \
# GP-Test + (991*y - y^2)/(9900 - 9999*y + 99*y^2)/(1 - 100*x) \
# GP-Test + (109*y - 10*y^2)/(9900 - 9999*y + 99*y^2)/(1 - y*x) \
# GP-Test - 10*y/(99 - 99*y)/(1 - 100*y*x)
# columns
# vector(6,n,n++; A346434_T(n,1))
# vector(6,n,n+=2; A346434_T(n,2))
# not in OEIS: 1001, 100101, 10010101, 1001010101, 100101010101, 10010101010101
# not in OEIS: 101001, 10100101, 1010010101, 101001010101, 10100101010101, 1010010101010101
#
# GP-Test gf_terms(y*(10 - 9*y)/((1 - y)*(1 - 100*y)), 10) == \
xt/oeis/Fibbinary-oeis.t view on Meta::CPAN
# GP-DEFINE + (v[#v]/2-1)*R_of_indices(e_indices(v1,v[#v]-2));
# GP-DEFINE }
# GP-Test my(v=OEIS_data("A000119")); \
# GP-Test vector(#v,n,n--; R(n)) == v
# vector(20,n,n--; R(n))
# R(13)
# GP-DEFINE R_pair_by_digits(n) = {
# GP-DEFINE my(v=Zeckendorf_digits(n+1),x=1,y=1,z=0);
# GP-DEFINE for(i=1,#v,
# GP-DEFINE \\ print("n="n" x,y="x","y" zeck ",v[i]);
# GP-DEFINE if(v[i], if(z, x+=y, x=y); z=0,
# GP-DEFINE if(z, y+=x); z=!z));
# GP-DEFINE [x,y];
# GP-DEFINE }
# vector(2000,n, R_pair_by_digits(n)[1]) == \
# vector(2000,n, R(n))
# log(2)/log(phi)
# bestappr(log(2)/log(phi),50)
# log(2)/log(phi) * 32
# GP-DEFINE R_pair(n) = {
# GP-DEFINE n++;
# GP-DEFINE my(k=floor(logint(n,2)*46>>5),x=1,y=1,z=0,f,g);
# GP-DEFINE [f,g]=Vec(lift(Mod('x,'x^2-'x-1)^k));
# GP-DEFINE while(g<n, [f,g]=[g,f+g]; print("n="n" k="k" up "f" "g));
# GP-DEFINE while(f>n, [f,g]=[g-f,f]; print("down"));
# GP-DEFINE while(g>=2,
# GP-DEFINE \\ print("n="n" f="f" g="g" x,y="x","y" zeck ",n>=f);
# GP-DEFINE if(n>=f, if(z, x+=y, x=y); z=0; n-=f,
# GP-DEFINE if(z, y+=x); z=!z);
# GP-DEFINE [f,g]=[g-f,f]);
# GP-DEFINE [x,y];
# GP-DEFINE }
# my(n=17); print(R_pair(17)); print(R_pair_by_digits(17)); print([R(n),R(n+1)]); print(Zeckendorf_digits(n))
# vector(20,n, R_pair(n)[1])
# vector(20,n, R(n))
#------------------------------------------------------------------------------
# A095903 - Fibonacci terms by tree descents
#------
# A255773 tree lower Wythoff
# 0 half of A095903
# / \
# 1 2 A255773 subtree 1 down
# / \ / \ A255774 subtree 2 down
# 1+2 1+3 2+3 2+5
# GP-DEFINE A255773(n) = {
# GP-DEFINE my(x=0,y=0);
# GP-DEFINE for(i=0,logint(n,2),
# GP-DEFINE [x,y]=[y,x+y+1];
# GP-DEFINE if(bittest(n,i), [x,y]=[y,x+y]));
# GP-DEFINE y;
# GP-DEFINE }
# GP-Test my(v=OEIS_data("A255773")); /* OFFSET=1 */ \
# GP-Test vector(#v,n, A255773(n)) == v
# GP-Test /* formula */ \
# GP-Test vector(1024,n, A255773(n)) == \
# GP-Test vector(1024,n, A095903(A092754(n)))
#
# GP-Test vector(1024,n, A255773(n)) == \
# GP-Test vector(1024,n, A095903(insert_highbit(n,0)-1))
# GP-Test vector(1024,n, A255773(n)) == \
# GP-Test vector(1024,n, A095903(A004754_insert_high_0(n)-1))
# GP-Test A095903(1) == 1
# GP-Test A095903(2) == 2
# GP-Test A095903(3) == 3
# GP-DEFINE A255774(n) = {
# GP-DEFINE my(x=0,y=0);
# GP-DEFINE for(i=0,logint(n,2),
# GP-DEFINE y++; [x,y]=[y,x+y];
# GP-DEFINE if(bittest(n,i), [x,y]=[y,x+y]));
# GP-DEFINE y;
# GP-DEFINE }
# GP-Test my(v=OEIS_data("A255774")); /* OFFSET=1 */ \
# GP-Test vector(#v,n, A255774(n)) == v
# GP-Test /* formula */ \
# GP-Test vector(1024,n, A255774(n)) == \
# GP-Test vector(1024,n, A095903(A206332(n)))
#
# GP-Test vector(1024,n, A255774(n)) == \
# GP-Test vector(1024,n, A095903(insert_highbit(n,1)-1))
# GP-Test vector(1024,n, A255774(n)) == \
# GP-Test vector(1024,n, A095903(A004755_insert_high_0(n)-1))
#------
# A345253 Fib tree = A095903+1
# GP-DEFINE A345253(n) = {
# GP-DEFINE my(ret=1,t=1);
# GP-DEFINE forstep(i=logint(n,2)-1,0,-1, t+=1+bittest(n,i); ret+=fibonacci(t)); ret;
# GP-DEFINE }
# GP-DEFINE A345253_indices(n) = \
# GP-DEFINE concat(1,if(n==1,[],A095903_indices(n-1)));
# GP-Test A345253_indices(1) == [1]
# GP-Test A345253_indices(2) == [1,2]
# GP-Test A345253_indices(3) == [1,3]
# GP-Test vector(1024,n, vecsum(apply(fibonacci,A345253_indices(n)))) == \
# GP-Test vector(1024,n, A345253(n))
# GP-DEFINE \\ like A095903 and final +1
# GP-DEFINE A345253_by_plus1(n) = {
# GP-DEFINE my(x=0,y=0);
# GP-DEFINE for(i=0,logint(n,2)-1,
# GP-DEFINE y++; [x,y]=[y,x+y];
# GP-DEFINE if(bittest(n,i), [x,y]=[y,x+y]));
# GP-DEFINE y+1;
# GP-DEFINE }
# GP-Test vector(1024,n, A345253_by_plus1(n)) == \
# GP-Test vector(1024,n, A345253(n))
# 1 2 3 5 8 13
# GP-Test A345253(16) == 1 +1+2+3+5
# GP-Test A345253(16+8) == 1 +2+3+5+8
# GP-Test A345253(16+1) == 1 +1+2+3 +8
# GP-Test apply(fibonacci,[-3,-2,-1, 0, 1, 2]) == \
# GP-Test [ 2,-1, 1, 0, 1, 1]
# GP-DEFINE A345253_by_all(n) = {
# GP-DEFINE my(x=0,y=0);
# GP-DEFINE for(i=0,logint(n,2),
# GP-DEFINE [x,y]=if(bittest(n,i),[x+y,x+2*y+1],[y+1,x+y]));
# GP-DEFINE y;
# GP-DEFINE }
# GP-DEFINE A345253_by_all(n) = {
# GP-DEFINE my(x=0,y=0);
# GP-DEFINE for(i=0,logint(n,2),
# GP-DEFINE if(bittest(n,i),x+=y;y+=x+1,[x,y]=[y+1,x+y]));
# GP-DEFINE y;
# GP-DEFINE }
# GP-DEFINE A345253_by_all(n) = {
# GP-DEFINE my(x=0,y=0);
# GP-DEFINE for(i=0,logint(n,2),
# GP-DEFINE [x,y]=[y+1,x+y];
# GP-DEFINE if(bittest(n,i), [x,y]=[y,x+y]));
# GP-DEFINE y;
( run in 0.941 second using v1.01-cache-2.11-cpan-e1769b4cff6 )