cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

Showing 1-6 of 6 results.

A059893 Reverse the order of all but the most significant bit in binary expansion of n: if n = 1ab..yz then a(n) = 1zy..ba.

Original entry on oeis.org

1, 2, 3, 4, 6, 5, 7, 8, 12, 10, 14, 9, 13, 11, 15, 16, 24, 20, 28, 18, 26, 22, 30, 17, 25, 21, 29, 19, 27, 23, 31, 32, 48, 40, 56, 36, 52, 44, 60, 34, 50, 42, 58, 38, 54, 46, 62, 33, 49, 41, 57, 37, 53, 45, 61, 35, 51, 43, 59, 39, 55, 47, 63, 64, 96, 80, 112, 72, 104, 88, 120
Offset: 1

Views

Author

Marc LeBrun, Feb 06 2001

Keywords

Comments

A self-inverse permutation of the natural numbers.
a(n)=n if and only if A081242(n) is a palindrome. - Clark Kimberling, Mar 12 2003
a(n) is the position in B of the reversal of the n-th term of B, where B is the left-to-right binary enumeration sequence (A081242 with the empty word attached as first term). - Clark Kimberling, Mar 12 2003
From Antti Karttunen, Oct 28 2001: (Start)
When certain Stern-Brocot tree-related permutations are conjugated with this permutation, they induce a permutation on Z (folded to N), which is an infinite siteswap permutation (see, e.g., figure 7 in the Buhler and Graham paper, which is permutation A065174). We get:
A065260(n) = a(A057115(a(n))),
A065266(n) = a(A065264(a(n))),
A065272(n) = a(A065270(a(n))),
A065278(n) = a(A065276(a(n))),
A065284(n) = a(A065282(a(n))),
A065290(n) = a(A065288(a(n))). (End)
Every nonnegative integer has a unique representation c(1) + c(2)*2 + c(3)*2^2 + c(4)*2^3 + ..., where every c(i) is 0 or 1. Taking tuples of coefficients in lexical order (i.e., 0, 1; 01,11; 001,011,101,111; ...) yields A059893. - Clark Kimberling, Mar 15 2015
From Ed Pegg Jr, Sep 09 2015: (Start)
The reduced rationals can be ordered either as the Calkin-Wilf tree A002487(n)/A002487(n+1) or the Stern-Brocot tree A007305(n+2)/A047679(n). The present sequence gives the order of matching rationals in the other sequence.
For reference, the Calkin-Wilf tree is 1, 1/2, 2, 1/3, 3/2, 2/3, 3, 1/4, 4/3, 3/5, 5/2, 2/5, 5/3, 3/4, 4, 1/5, 5/4, 4/7, 7/3, 3/8, 8/5, 5/7, 7/2, 2/7, 7/5, 5/8, 8/3, 3/7, 7/4, 4/5, ..., which is A002487(n)/A002487(n+1).
The Stern-Brocot tree is 1, 1/2, 2, 1/3, 2/3, 3/2, 3, 1/4, 2/5, 3/5, 3/4, 4/3, 5/3, 5/2, 4, 1/5, 2/7, 3/8, 3/7, 4/7, 5/8, 5/7, 4/5, 5/4, 7/5, 8/5, 7/4, 7/3, 8/3, 7/2, ..., which is A007305(n+2)/A047679(n).
There is a great little OEIS-is-useful story here. I had code for the position of fractions in the Calkin-Wilf tree. The best I had for positions of fractions in the Stern-Brocot tree was the paper "Locating terms in the Stern-Brocot tree" by Bruce Bates, Martin Bunder, Keith Tognetti. The method was opaque to me, so I used my Calkin-Wilf code on the Stern-Brocot fractions, and got A059893. And thus the problem was solved. (End)

Examples

			a(11) = a(1011) = 1110 = 14.
With empty word e prefixed, A081242 becomes (e,1,2,11,21,12,22,111,211,121,221,112,...); (reversal of term #9) = (term #12); i.e., a(9)=12 and a(12)=9. - _Clark Kimberling_, Mar 12 2003
From _Philippe Deléham_, Jun 02 2015: (Start)
This sequence regarded as a triangle with rows of lengths 1, 2, 4, 8, 16, ...:
   1;
   2,  3;
   4,  6,  5,  7;
   8, 12, 10, 14,  9,  13,  11,  15;
  16, 24, 20, 28, 18,  26,  22,  30,  17,  25,  21,  29,  19,  27,  23,  31;
  32, 48, 40, 56, 36,  52,  44, ...
Row sums = A010036. (End)
		

Crossrefs

{A000027, A054429, A059893, A059894} form a 4-group.
The set of permutations {A059893, A080541, A080542} generates an infinite dihedral group.
In other bases: A351702 (balanced ternary), A343150 (Zeckendorf), A343152 (lazy Fibonacci).

Programs

  • Haskell
    a059893 = foldl (\v b -> v * 2 + b) 1 . init . a030308_row
    -- Reinhard Zumkeller, May 01 2013
    (Scheme, with memoization-macro definec)
    (definec (A059893 n) (if (<= n 1) n (let* ((k (- (A000523 n) 1)) (r (A059893 (- n (A000079 k))))) (if (= 2 (floor->exact (/ n (A000079 k)))) (* 2 r) (+ 1 r)))))
    ;; Antti Karttunen, May 16 2015
    
  • Maple
    # Implements Bottomley's formula
    A059893 := proc(n) option remember; local k; if(1 = n) then RETURN(1); fi; k := floor_log_2(n)-1; if(2 = floor(n/(2^k))) then RETURN(2*A059893(n-(2^k))); else RETURN(1+A059893(n-(2^k))); fi; end;
    floor_log_2 := proc(n) local nn,i; nn := n; for i from -1 to n do if(0 = nn) then RETURN(i); fi; nn := floor(nn/2); od; end;
    # second Maple program:
    a:= proc(n) local i, m, r; m, r:= n, 0;
          for i from 0 while m>1 do r:= 2*r +irem(m,2,'m') od;
          r +2^i
        end:
    seq(a(n), n=1..100);  # Alois P. Heinz, Feb 28 2015
  • Mathematica
    A059893 = Reap[ For[n=1, n <= 100, n++, a=1; b=n; While[b > 1, a = 2*a + 2*FractionalPart[b/2]; b=Floor[b/2]]; Sow[a]]][[2, 1]] (* Jean-François Alcover, Jul 16 2012, after Harry J. Smith *)
    ro[n_]:=Module[{idn=IntegerDigits[n,2]},FromDigits[Join[{First[idn]}, Reverse[ Rest[idn]]],2]]; Array[ro,80] (* Harvey P. Dale, Oct 24 2012 *)
  • PARI
    a(n) = my(b=binary(n)); fromdigits(concat(b[1], Vecrev(vector(#b-1, k, b[k+1]))), 2); \\ Michel Marcus, Sep 29 2021
    
  • Python
    def a(n): return int('1' + bin(n)[3:][::-1], 2)
    print([a(n) for n in range(1, 101)]) # Indranil Ghosh, Mar 21 2017
  • R
    maxrow <- 6 # by choice
    a <- 1
    for(m in 0:maxrow) for(k in 0:(2^m-1)) {
      a[2^(m+1)+    k] <- 2*a[2^m+k]
      a[2^(m+1)+2^m+k] <- 2*a[2^m+k] + 1
    }
    a
    # Yosu Yurramendi, Mar 20 2017
    
  • R
    maxblock <- 7 # by choice
    a <- 1
    for(n in 2:2^maxblock){
      ones <- which(as.integer(intToBits(n)) == 1)
      nbit <- as.integer(intToBits(n))[1:tail(ones, n = 1)]
      anbit <- nbit
      anbit[1:(length(anbit) - 1)] <- anbit[rev(1:(length(anbit)-1))]
      a <- c(a, sum(anbit*2^(0:(length(anbit) - 1))))
    }
    a
    # Yosu Yurramendi, Apr 25 2021
    

Formula

a(n) = A030109(n) + A053644(n). If 2*2^k <= n < 3*2^k then a(n) = 2*a(n-2^k); if 3*2^k <= n < 4*2^k then a(n) = 1 + a(n-2^k) starting with a(1)=1. - Henry Bottomley, Sep 13 2001

A343150 Reverse the order of all but the most significant bits in the minimal Fibonacci expansion of n.

Original entry on oeis.org

1, 2, 3, 4, 5, 7, 6, 8, 11, 10, 9, 12, 13, 18, 16, 15, 20, 14, 19, 17, 21, 29, 26, 24, 32, 23, 31, 28, 22, 30, 27, 25, 33, 34, 47, 42, 39, 52, 37, 50, 45, 36, 49, 44, 41, 54, 35, 48, 43, 40, 53, 38, 51, 46, 55, 76, 68, 63, 84, 60, 81, 73, 58, 79, 71, 66, 87
Offset: 1

Views

Author

J. Parker Shectman, Apr 07 2021

Keywords

Comments

A self-inverse permutation of the natural numbers.
Analogous to A059893 with binary expansion replaced by minimal Fibonacci expansion.
Analogous to A343152 with maximal Fibonacci expansion replaced by minimal Fibonacci expansion.
The expansion of n equals A014417(n) with a 0 appended (see reference in link, p. 144).
Write the sequence as a (left-justified) "tetrangle" or "irregular triangle" tableau with F(t) (Fibonacci number) entries on each row, for t=1,2,3,.... Then, columns of the tableau equal rows of the Wythoff array, A035513 (see reference in link, p. 131):
1
2
3, 4
5, 7, 6
8, 11, 10, 9, 12
13, 18, 16, 15, 20, 14, 19, 17
...

Examples

			For an example of calculation by reversing Fibonacci binary digits, see reference in link, p. 144:
On the basis (1,1,2,3,5,8,13) n=13 is written as 0000001. Reversing all but the most significant digit gives 0000001, which evaluates to 13, so a(13)=13.
On the basis (1,1,2,3,5,8,13) n=14 is written as 0100001. Reversing all but the most significant digit gives 0000101, which evaluates to 18, so a(14)=18.
Note: The permutation can also be accomplished using the basis (1,2,3,5,8,13), by holding fixed the TWO most significant digits and reversing the remaining digits.
		

Crossrefs

In other bases: A344682 (lazy Fibonacci), A343152 (variation), A059893 (binary), A351702 (balanced ternary).

Programs

  • Mathematica
    (*Produce indices of minimal Fibonacci representation (recursively)*)
    MinFibInd[n_] := Module[{t = Floor[Log[GoldenRatio, Sqrt[5]*n + 1]] - 1}, Piecewise[{{{2}, n == 1}, {Append[MinFibInd[n - Fibonacci[t + 1]], t + 1], n > 1 && n - Fibonacci[t + 1] >= Fibonacci[t - 1]}, {Append[Most[MinFibInd[n - Fibonacci[t - 1]]], t + 1], n > 1 && n - Fibonacci[t + 1] < Fibonacci[t - 1]}},]];
    (*Define a(n)*)
    a[n_] := Module[{MFI = MinFibInd[n]}, Apply[Plus, Fibonacci[Append[Last[MFI] - Most[MFI], Last[MFI]]]]];
    (*Generate DATA*)
    Array[a, 67]

A353654 Numbers whose binary expansion has the same number of trailing 0 bits as other 0 bits.

Original entry on oeis.org

1, 3, 7, 10, 15, 22, 26, 31, 36, 46, 54, 58, 63, 76, 84, 94, 100, 110, 118, 122, 127, 136, 156, 172, 180, 190, 204, 212, 222, 228, 238, 246, 250, 255, 280, 296, 316, 328, 348, 364, 372, 382, 392, 412, 428, 436, 446, 460, 468, 478, 484, 494, 502, 506, 511, 528, 568
Offset: 1

Views

Author

Mikhail Kurkov, Jul 15 2022

Keywords

Comments

Numbers k such that A007814(k) = A086784(k).
To reproduce the sequence through itself, use the following rule: if binary 1xyz is a term then so are 11xyz and 10xyz0 (except for 1 alone where 100 is not a term).
The number of terms with bit length k is equal to Fibonacci(k-1) for k > 1.
Conjecture: 2*A247648(n-1) + 1 with rewrite 1 -> 1, 01 -> 0 applied to binary expansion is the same as a(n) without trailing 0 bits in binary.
Odd terms are positive Mersenne numbers (A000225), because there is no 0 in their binary expansion. - Bernard Schott, Oct 12 2022

Crossrefs

Cf. A356385 (first differences).
Subsequences with same number k of trailing 0 bits and other 0 bits: A000225 (k=0), 2*A190620 (k=1), 4*A357773 (k=2), 8*A360573 (k=3).

Programs

  • Maple
    N:= 10: # for terms <= 2^N
    S:= {1};
    for d from 1 to N do
      for k from 0 to d/2-1 do
        B:= combinat:-choose([$k+1..d-2],k);
        S:= S union convert(map(proc(t) local s; 2^d - 2^k - add(2^(s),s=t) end proc,B),set);
    od od:
    sort(convert(S,list)); # Robert Israel, Sep 21 2023
  • Mathematica
    Join[{1}, Select[Range[2, 600], IntegerExponent[#, 2] == Floor[Log2[# - 1]] - DigitCount[# - 1, 2, 1] &]] (* Amiram Eldar, Jul 16 2022 *)
  • PARI
    isok(k) = if (k==1, 1, (logint(k-1, 2)-hammingweight(k-1) == valuation(k, 2))); \\ Michel Marcus, Jul 16 2022
    
  • Python
    from itertools import islice, count
    def A353654_gen(startvalue=1): # generator of terms >= startvalue
        return filter(lambda n:(m:=(~n & n-1).bit_length()) == bin(n>>m)[2:].count('0'),count(max(startvalue,1)))
    A353654_list = list(islice(A353654_gen(),30)) # Chai Wah Wu, Oct 14 2022

Formula

a(n) = a(n-1) + A356385(n-1) for n > 1 with a(1) = 1.
Conjectured formulas: (Start)
a(n) = 2^g(n-1)*(h(n-1) + 2^A000523(h(n-1))*(2 - g(n-1))) for n > 2 with a(1) = 1, a(2) = 3 where f(n) = n - A130312(n), g(n) = [n > 2*f(n)] and where h(n) = a(f(n) + 1).
a(n) = 1 + 2^r(n-1) + Sum_{k=1..r(n-1)} (1 - g(s(n-1, k)))*2^(r(n-1) - k) for n > 1 with a(1) = 1 where r(n) = A072649(n) and where s(n, k) = f(s(n, k-1)) for n > 0, k > 1 with s(n, 1) = n.
a(n) = 2*(2 + Sum_{k=1..n-2} 2^(A213911(A280514(k)-1) + 1)) - 2^A200650(n) for n > 1 with a(1) = 1.
A025480(a(n)-1) = A348366(A343152(n-1)) for n > 1.
a(A000045(n)) = 2^(n-1) - 1 for n > 1. (End)

A358654 a(n) = A025480(A353654(n+1) - 1).

Original entry on oeis.org

0, 1, 3, 2, 7, 5, 6, 15, 4, 11, 13, 14, 31, 9, 10, 23, 12, 27, 29, 30, 63, 8, 19, 21, 22, 47, 25, 26, 55, 28, 59, 61, 62, 127, 17, 18, 39, 20, 43, 45, 46, 95, 24, 51, 53, 54, 111, 57, 58, 119, 60, 123, 125, 126, 255, 16, 35, 37, 38, 79, 41, 42, 87, 44, 91, 93
Offset: 0

Views

Author

Mikhail Kurkov, Nov 25 2022

Keywords

Comments

Permutation of the nonnegative integers.
Conjecture: A247648(n) with rewrite 1 -> 1, 01 -> 0 applied to binary expansion is the same as a(n).

Crossrefs

Formula

Conjecture: a(n) = A348366(A343152(n)) for n > 0 with a(0) = 1.

A345253 Maximal Fibonacci tree: Arrangement of the positive integers as labels of a complete binary tree.

Original entry on oeis.org

1, 2, 3, 4, 5, 6, 8, 7, 9, 10, 13, 11, 14, 16, 21, 12, 15, 17, 22, 18, 23, 26, 34, 19, 24, 27, 35, 29, 37, 42, 55, 20, 25, 28, 36, 30, 38, 43, 56, 31, 39, 44, 57, 47, 60, 68, 89, 32, 40, 45, 58, 48, 61, 69, 90, 50, 63, 71, 92, 76, 97, 110, 144, 33, 41, 46, 59, 49
Offset: 1

Views

Author

J. Parker Shectman, Jun 12 2021

Keywords

Comments

Every positive integer occurs exactly once, so that, as a sequence, a(n) is a permutation of the positive integers.
Descending from the root node 1, generate tree by outer composition of L(n) = n + F(Finv(n)) and R(n) = n + F(Finv(n) + 1), respectively, according to left or right branching, where F(n) = A000045(n) are the Fibonacci numbers and Finv(n) = A130233(n) is the 'lower' Fibonacci inverse. This produces each number by maximal Fibonacci expansion (cf. example below of Method 2, entry A343152, and links).
(Level of tree): The number of terms in this expansion of n is the level of the tree on which n appears, A112310(n-1) + 1 = A200648(n+1). The number of terms in the expansion of a(n) is floor(log_2(n)) + 1 = A113473(n) = A070939(n) = A029837(n+1).
"Maximal Fibonacci expansion" maximizes the sum of coefficients over all Fibonacci numbers (of positive index), allowing both F(1) = 1 and F(2) = 1. Thus, it is just an expansion and not a representation (like "greedy" and "lazy"), as it "breaks the rule" by using two bits that correspond to elements of equal value, rather than using distinct basis elements (link). This reveals connections to the cf. sequences: Binary strings that emerge in lexicographic order from "maximal Fibonacci gaps" (example), binary trees of the positive integers, and I-D arrays "harvested" from the trees. To define the expansion uniquely, always include F(1), so that the expansion of positive integer n equals F(1) for n = 1 and F(1) prepended to the lazy Fibonacci representation of n-1 for n > 1. Hence, a(1) = 1, and for n > 1, a(n) = A095903(n-1) + 1. The "redundant" expansion arranges the positive integers in the single binary tree {T(n,k)}, rather than the two trees at A255773 and A255774 that result from representation (see link).
(Left-to-right order in tree): Each F(t)-sized block (F(t+1), ..., F(t+2) - 1) of successive positive integers ("Fibonacci cohort" t) appears in right-to-left order in the tree as reordered in A343152, where elements of each cohort appear consecutively (see link).
Descending from the root node 1, generate tree by the inner composition of A026351 and A026352, that is, one plus the sequences of lower and upper Wythoff numbers, A000201 and A001950, respectively, according to left or right branching (see example below of Method 1 and links).
Generate tree from (one plus) the number of (initial) zeros on the positive integers for the outer composition of sequences, A060143 and A060144, respectively, according to left or right branching descending from the identity (c.f example below of Method 3 and links).
The lower Wythoff numbers, A000201, appear exclusively in the 1st, 3rd, 5th, ... right clades of the tree, while the upper Wythoff numbers A001950, appear exclusively in the 2nd, 4th, 6th, ... right clades of the tree. Here, the k-th right clade comprises the nodes at positions 2^(k+1) and 2^k + 1, together with all descendants of the latter (link).
(Duality with tree A232560, and related arrays): Consider the labeled binary trees a(n) = A232560(A059893(n)) and A232560(n) = a(A059893(n)). Labels along maximal straight paths that always branch left in a(n) give rows of array A345252, while labels along maximal straight paths that always branch left in A232560 give rows of array A083047.
Sorting the labels from each successive right clade of the binary tree a(n) gives the successive columns of A083047, while sorting labels from each successive right clade of A232560 gives each successive column of A345252. This makes the trees a(n) and A232560 "blade-duals," blade being a contraction of branch-clade (see entry for A345254 and link). A200648(n)+1 gives the level of the tree on which elements of array first-columns A345252(n,1) and A083047(n,1) appear.
(Palindromes and coincidence of elements): Trees a(n) and A232560 coincide when the sequence of left and right branching is a palindrome: a(A329395(n)) = A232560(A329395(n)). As Kimberling notes (cf. A059893), this happens at fixed points of A059893(n) or, equivalently, at n for which A081242(n) is a palindrome.
The inverse permutation of a(n) as a sequence can be read from a "tetrangle" or "irregular triangle" tableau with F(t) (Fibonacci number) entries on each row t, for t = 1, 2, 3, ..., in which an entry on row t is 2*x the entry x immediately above it on row t-1, if such exists, or otherwise 2*x + 1 the entry x in the corresponding position on row t-2 (thus generating new rows as in A243571 but without sorting the numbers into increasing order, linked reference):
1,
2,
3, 4,
5, 6, 8,
7, 9, 10, 12, 16,
11, 13, 17, 14, 18, 20, 24, 32,
...
With the right-justified tableau substituted by a left-justified tableau, the same procedure yields the inverse permutation for the "minimal Fibonacci tree," A048680(A059893(n)), the "cohort-dual" tree of a(n), where "cohort" t is the F(t)-sized block of successive entries in the tableau (see entry for A345252, linked reference).
(Coincidence of elements): a(A020988(n)) = A048680(A059893(A020988(n))) = A099919(n) and a(A020989(n)) = A048680(A059893(A020989(n))) = A049651(n). Collectively, a(A061547(n)) = A048680(A059893(A061547(n))) = union(A049651(n), A099919(n)).
With two types of duality, the tree forms a quartet of binary-tree arrangements of the positive integers, together with its blade dual A232560, its cohort dual A048680(A059893), and blade dual A048680 of the latter.
Order in the tree is "memory-less": Let a(n) and a(m) label nodes at positions n and m, respectively. Let d1 and d2 be two descending paths, i.e., sequences branching left or right from a starting node. (Nodal positions for the left and right children of the node at position p are given by 2*p and 2*p + 1, resp., and d1 and d2 are compositions of these.) Then a(d1(n)) < a(d2(n)) if and only if a(d1(m)) < a(d2(m)) (linked reference).

Examples

			As a complete binary tree:
                    1
           /                 \
          2                   3
      /       \          /        \
     4         5        6          8
    / \       / \      / \        / \
   7    9    10   13   11   14   16   21
  / \  / \  /  \ /  \ /  \ /  \ /  \ /  \
  ...
By maximal Fibonacci expansion:
                                        F(1)
                      /                                       \
                F(1) + F(2)                               F(1) + F(3)
           /                    \                    /                  \
  F(1) + F(2) + F(3)   F(1) + F(2) + F(4)   F(1) + F(3) + F(4)   F(1) + F(3) + F(5)
  ...
"Fibonacci gaps," or differences between successive indices in maximal Fibonacci expansion above, are A007931(n-1) for n > 1 (see link):
                   *
          /                  \
         1                    2
     /       \           /        \
    11        12        21        22
   /  \      /  \      /  \      /  \
  111  112  121  122  211  212  221  222
  / \  / \  / \  / \  / \  / \  / \  / \
  ...
In examples of the three methods below:
Branch left-right-right down the tree to arrive at nodal position n = 2*(2*(2*1) + 1) + 1 = 11;
Branch right-left-left down the tree to arrive at nodal position n = 2*(2*(2*1 + 1)) = 12.
Tree by inner composition of (one plus) the lower and upper Wythoff sequences, A000201 and A001950 (Method 1):
a(11) = A000201(A001950(A001950(1) + 1) + 1) + 1 = 13.
a(12) = A001950(A000201(A000201(1) + 1) + 1) + 1 = 11.
Tree by (outer) composition of branching functions L(n) = n + F(Finv(n)) and R(n) = n + F(Finv(n) + 1), where F(n) = A000045(n) and Finv(n) = A130233(n) (Method 2):
a(11) = R(R(L(1))) = 13.
a(12) = L(R(R(1))) = 11.
Tree by outer composition of A060143 and A060144 (Wythoff inverse sequences) (Method 3):
a(11) = 13, position of first nonzero in A060144(A060144(A060143(m))) = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, ..., for m = 1, 2, 3, ....
a(12) = 11, position of first nonzero in A060143(A060143(A060144(m))) = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, ..., for m = 1, 2, 3, ....
		

Crossrefs

Programs

  • Mathematica
    (* For binary tree implementations, see supporting file under LINKS *)
    a[n_] := (x = 0; y = 0; BDn = Reverse[IntegerDigits[n, 2]]; imax = Length[BDn] - 1; For[i = 0, i <= imax, i++, {x, y} = {y + 1, x + y}; If[BDn[[i + 1]] == 1, {x, y} = {y, x + y}]]; y);
    (* Adapted from PARI code of Kevin Ryde *)
  • PARI
    a(n) = my(x=0,y=0); for(i=0,logint(n,2), [x,y]=[y+1,x+y]; if(bittest(n,i), [x,y]=[y,x+y])); y; \\ Kevin Ryde, Jun 19 2021

Formula

a(1) = 1 and for n > 1, a(n) = A095903(n-1) + 1.
a(n) = A232560(A059893(n)).

A351702 In the balanced ternary representation of n, reverse the order of digits other than the most significant.

Original entry on oeis.org

0, 1, 2, 3, 4, 5, 8, 11, 6, 9, 12, 7, 10, 13, 14, 23, 32, 17, 26, 35, 20, 29, 38, 15, 24, 33, 18, 27, 36, 21, 30, 39, 16, 25, 34, 19, 28, 37, 22, 31, 40, 41, 68, 95, 50, 77, 104, 59, 86, 113, 44, 71, 98, 53, 80, 107, 62, 89, 116, 47, 74, 101, 56, 83, 110, 65, 92
Offset: 0

Views

Author

Kevin Ryde, Feb 19 2022

Keywords

Comments

Self-inverse permutation with swaps confined to terms of a given digit length (A134021) so within blocks n = (3^k+1)/2 .. (3^(k+1)-1)/2.
Can extend to negative n by a(-n) = -a(n).
A072998 is balanced ternary coded in decimal digits so that reversal except first digit of A072998(n) is at A072998(a(n)). Similarly its ternary equivalent A157671, and also A132141 ternary starting with 1.
These sequences all have a fixed initial digit followed by all ternary strings which is the reversed part. A007932 is such strings as decimal digits 1,2,3 but it omits the empty string so the whole reversal of A007932(n) is at A007932(a(n+1)-1).
Fixed points a(n) = n are where n in balanced ternary is a palindrome apart from its initial 1. These are the full balanced ternary palindromes with their least significant 1 removed, so all n = (A134027(m)-1)/3 for m>=2.

Examples

			n    = 224 = balanced ternary 1,  0, -1, 1,  0, -1
                      reverse     ^^^^^^^^^^^^^^^^
a(n) = 168 = balanced ternary 1, -1,  0, 1, -1,  0
		

Crossrefs

Cf. A059095 (balanced ternary), A134028 (full reverse), A134027 (palindromes).
In other bases: A059893 (binary), A343150 (Zeckendorf), A343152 (lazy Fibonacci).

Programs

  • PARI
    a(n) = if(n==0,0, my(k=if(n,logint(n<<1,3)), s=(3^k+1)>>1); s + fromdigits(Vec(Vecrev(digits(n-s,3)),k),3));
Showing 1-6 of 6 results.