# nice new sequences, flipping and sliding.

Antti Karttunen karttu at megabaud.fi
Sat Feb 3 23:26:02 CET 2001

```N. J. A. Sloane wrote:
-------------- next part --------------

> Gregory Allen (jukebox_999 at hotmail.com) sent in these two seqs:
> %N A059458 A binary sequence: a(1) = 10 (2 in decimal), and a(n+1)
> is obtained by trying to complement just one bit of a(n), starting
> with the least significant bit, until a new prime is reached.

I think the definition is a bit too vague. I would suggest the following
clarification:

%N A059458 This is the lexicographically least (in positions of the flipped bits) such sequence.

Here are few more terms (I could extend the sequence upto
the 104th term 151115727453207491916143 using the bit-flip-limit 128):

%S A059459 2,3,7,5,13,29,31,23,19,17,8209,8273,10321,2129,2131,83,67,71,79,1103,1039,1031,1063,1061,1069,
%T A059459 263213,263209,263201,265249,265313,264289,280673,280681,280697,280699,280703,280639,280607,
%U A059459 280603,280859,280843,281867,265483,265547,265579,265571,266083,266081,266089,266093,266029
%p A059459 E.g., call as: A059459search([2],128,200);
%p A059459 A059459search := proc(a,upto_bit,upto_length) local i,n,t;
%p A059459   if(nops(a) >= upto_length) then RETURN(a); fi;
%p A059459   t := a[nops(a)];
%p A059459   for i from 0 to upto_bit
%p A059459    do
%p A059459       n := XORnos(t,(2^i));
%p A059459       if(isprime(n) and (not member(n,a))) then print([op(a),n]); RETURN(A059459search([op(a),n],upto_bit,upto_length)); fi;
%p A059459    od;
%p A059459   RETURN([op(a),`and no more`]);
%p A059459 end;
%Y A059459 Cf. A059458 (for this sequence written in binary), A059471. Similar, but strictly ascending sequence: A059661, the positions of the flipped bits: A059663.

This inspired me to concoct another variant, and extract the positions of
the flipped bits from both, so here are three new sequences to EIS:

%I A059661
%S A059661 2,3,7,23,31,4127,4159,20543,134238271,134238527,167792959,1241534783,3389018431,72108495167,
%T A059661 72108503359,72108765503,2722258935367507707706996859526254457151,2722258935367507707708149781030861304127,
%U A059661 13611294676837538538536137218847444070719,744282853678701455922507579277316643178128753343813693728245963960974631028119473486019635930893904745515498962355104740076650915145478463
%N A059661 Like A059459, but each term must be greater than the previous ones.
%R A059661
%H A059661 <A HREF="http://www.research.att.com/%7Enjas/sequences/transforms.txt">Maple implementations of XORnos and DIFF</A>
%O A059661 1,1
%K A059661 nonn,base
%A A059661 Antti.Karttunen at iki.fi Feb 03 2001
%D A059661
%p A059661 E.g., call as: flip_primes_asc_search([2],512,21);
%p A059661 flip_primes_asc_search := proc(a,upto_bit,upto_length) local i,n,t;
%p A059661   if(nops(a) >= upto_length) then RETURN(a); fi;
%p A059661   t := a[nops(a)];
%p A059661   for i from 0 to upto_bit
%p A059661    do
%p A059661       n := XORnos(t,(2^i));
%p A059661       if(isprime(n) and (n > t)) then print([op(a),n]); RETURN(flip_primes_asc_search([op(a),n],upto_bit,upto_length)); fi;
%p A059661    od;
%p A059661   RETURN([op(a),`and no more`]);
%p A059661 end;

%I A059662
%S A059662 0,2,4,3,12,5,14,27,8,25,30,31,36,13,18,131,60,133,458,247
%N A059662 Positions of the flipped bits (here they are always set from 0 to 1) in the sequence A059661.
%C A059662 E.g. starting from A059661[1] = 2, flip (set) bit 0, gives A059661[2] = 3 (= 2+2^0), set bit 2, gives A059661[3] = 7 (3+2^2), set bit 4, gives A059661[4] = 23 (7+2^4), etc.
%C A059662 Question: If A059661 could be extended infinitely, would all the natural numbers eventually appear here once, or would some still be missing (1,6,7, ?)
%R A059662
%O A059662 1,2
%K A059662 nonn,more
%A A059662 Antti.Karttunen at iki.fi Feb 03 2001
%D A059662
%p A059662 map(floor_log_2,map(abs,DIFF(A059661))); # For floor_log_2, which essentially computes log[2](x) here, see A054429

%I A059663
%S A059663 0,2,1,3,4,1,3,2,1,13,6,11,13,1,11,4,2,3,10,6,3,5,1,3,18,2,3,11,6,10,14,3,4,1,2,6,5,2,8,4,
%T A059663 10,14,6,5,3,9,1,3,2,6,14,2,5,10,2,18,9,13,10,1,6,7,1,9,7,6,38,23,3,27,4,8,12,1,6,2,13,14,24,
%U A059663 12,9,3,11,17,32,37,12,33,17,10,2,5,37,6,33,17,8,13,40,77,6,4,20
%N A059663 Positions of the flipped bits in the sequence A059459
%C A059663 E.g. starting from A059459[1] = 2, flip (set) bit 0, gives A059459[2] = 3 (= 2+2^0), then flip (set) bit 2, gives A059459[3] = 7 (3+2^2), then flip (clear) bit 1, gives A059459[4] = 5 (7-2^1), etc.
%R A059663
%O A059663 1,2
%K A059663 nonn
%A A059663 Antti.Karttunen at iki.fi Feb 03 2001
%D A059663
%p A059663 map(floor_log_2,map(abs,DIFF(A059459))); # For floor_log_2, see A054429

Terveisin,

Antti Karttunen
```