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-2 of 2 results.

A117966 Balanced ternary enumeration (based on balanced ternary representation) of integers; write n in ternary and then replace 2's with (-1)'s.

Original entry on oeis.org

0, 1, -1, 3, 4, 2, -3, -2, -4, 9, 10, 8, 12, 13, 11, 6, 7, 5, -9, -8, -10, -6, -5, -7, -12, -11, -13, 27, 28, 26, 30, 31, 29, 24, 25, 23, 36, 37, 35, 39, 40, 38, 33, 34, 32, 18, 19, 17, 21, 22, 20, 15, 16, 14, -27, -26, -28, -24, -23, -25, -30, -29, -31, -18, -17, -19, -15, -14, -16, -21, -20, -22, -36
Offset: 0

Views

Author

Keywords

Comments

As the graph demonstrates, there are large discontinuities in the sequence between terms 3^i-1 and 3^i, and between terms 2*3^i-1 and 2*3^i. - N. J. A. Sloane, Jul 03 2016

Examples

			7 in base 3 is 21; changing the 2 to a (-1) gives (-1)*3+1 = -2, so a(7) = -2. I.e., the number of -2 according to the balanced ternary enumeration is 7, which can be obtained by replacing every -1 by 2 in the balanced ternary representation (or expansion) of -2, which is -1,1.
		

References

  • D. E. Knuth, The Art of Computer Programming. Addison-Wesley, Reading, MA, Vol. 2, pp. 173-175; 2nd. ed. pp. 190-193.

Crossrefs

Programs

  • Maple
    f:= proc(n) local L,i;
       L:= subs(2=-1,convert(n,base,3));
       add(L[i]*3^(i-1),i=1..nops(L))
    end proc:
    map(f, [$0..100]);
    # alternate:
    N:= 100: # to get a(0) to a(N)
    g:= 0:
    for n from 1 to ceil(log[3](N+1)) do
    g:= convert(series(3*subs(x=x^3,g)*(1+x+x^2)+x/(1+x+x^2),x,3^n+1),polynom);
    od:
    seq(coeff(g,x,j),j=0..N); # Robert Israel, Nov 17 2015
    # third Maple program:
    a:= proc(n) option remember; `if`(n=0, 0,
          3*a(iquo(n, 3, 'r'))+`if`(r=2, -1, r))
        end:
    seq(a(n), n=0..3^4-1);  # Alois P. Heinz, Aug 14 2019
  • Mathematica
    Map[FromDigits[#, 3] &, IntegerDigits[#, 3] /. 2 -> -1 & /@ Range@ 80] (* Michael De Vlieger, Nov 17 2015 *)
  • PARI
    a(n) = subst(Pol(apply(x->if(x == 2, -1, x), digits(n,3)), 'x), 'x, 3)
    vector(73, i, a(i-1))  \\ Gheorghe Coserea, Nov 17 2015
    
  • Python
    def a(n):
        if n==0: return 0
        if n%3==0: return 3*a(n//3)
        elif n%3==1: return 3*a((n - 1)//3) + 1
        else: return 3*a((n - 2)//3) - 1
    print([a(n) for n in range(101)]) # Indranil Ghosh, Jun 06 2017

Formula

a(0) = 0, a(3n) = 3a(n), a(3n+1) = 3a(n)+1, a(3n+2) = 3a(n)-1.
G.f. satisfies A(x) = 3*A(x^3)*(1+x+x^2) + x/(1+x+x^2). - corrected by Robert Israel, Nov 17 2015
A004488(n) = a(n)^{-1}(-a(n)). I.e., if a(n) <= 0, A004488(n) = A117967(-a(n)) and if a(n) > 0, A004488(n) = A117968(a(n)).
a(n) = n - 3 * A005836(A289814(n) + 1). - Andrey Zabolotskiy, Nov 11 2019

Extensions

Name corrected by Andrey Zabolotskiy, Nov 10 2019

A134028 Reversal of n in balanced ternary representation.

Original entry on oeis.org

0, 1, -2, 1, 4, -11, -2, 7, -8, 1, 10, -5, 4, 13, -38, -11, 16, -29, -2, 25, -20, 7, 34, -35, -8, 19, -26, 1, 28, -17, 10, 37, -32, -5, 22, -23, 4, 31, -14, 13, 40, -119, -38, 43, -92, -11, 70, -65, 16, 97, -110, -29, 52, -83, -2, 79, -56, 25, 106, -101, -20, 61, -74, 7, 88, -47, 34, 115, -116, -35, 46, -89, -8, 73, -62, 19, 100
Offset: 0

Views

Author

Reinhard Zumkeller, Oct 19 2007

Keywords

Comments

As the graph demonstrates, the sequence makes large negative steps at terms (3^i+1)/2. These steps divide the graph into conspicuous blocks. - N. J. A. Sloane, Jul 03 2016

Examples

			20 = 1*3^3 - 1*3^2 + 1*3^1 - 1*3^0 == '+-+-'
=> a(20) = -1*3^3 + 1*3^2 - 1*3^1 + 1*3^0 = -20;
21 = 1*3^3 - 1*3^2 + 1*3^1 + 0*3^0 == '+-+0'
=> a(21) = 0*3^3 + 1*3^2 - 1*3^1 + 1*3^0 = 7;
22 = 1*3^3 - 1*3^2 + 1*3^1 + 1*3^0 == '+-++'
=> a(22) = 1*3^3 + 1*3^2 - 1*3^1 + 1*3^0 = 34;
23 = 1*3^3 + 0*3^2 - 1*3^1 - 1*3^0 == '+0--'
=> a(23) = -1*3^3 - 1*3^2 + 0*3^1 + 1*3^0 = -35;
24 = 1*3^3 + 0*3^2 - 1*3^1 + 0*3^0 == '+0-0'
=> a(24) = 0*3^3 - 1*3^2 + 0*3^1 + 1*3^0 = -8;
25 = 1*3^3 + 0*3^2 - 1*3^1 + 1*3^0 == '+0-+'
=> a(25) = 1*3^3 - 1*3^2 + 0*3^1 + 1*3^0 = 19.
		

References

  • D. E. Knuth, The Art of Computer Programming, Addison-Wesley, Reading, MA, Vol 2, pp 173-175.

Crossrefs

Cf. A117966 (balanced ternary representation), A030102, A134021, A274107.
A134027 gives the numbers whose balanced ternary representation is palindromic.

Programs

  • Python
    def a(n):
        if n==0: return 0
        s=[]
        x=0
        while n>0:
            x=n%3
            n=n//3
            if x==2:
                x=-1
                n+=1
            s.append(x)
        l=s[::-1]
        return sum(l[i]*3**i for i in range(len(l)))
    print([a(n) for n in range(101)]) # Indranil Ghosh, Jun 10 2017

Formula

a(A134027(n)) = A134027(n);
A134021(ABS(a(n))) <= A134021(n).
Showing 1-2 of 2 results.