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-10 of 23 results. Next

A140263 Permutation of nonnegative integers obtained by interleaving A117967 and A117968.

Original entry on oeis.org

0, 1, 2, 5, 7, 3, 6, 4, 8, 17, 22, 15, 21, 16, 23, 11, 19, 9, 18, 10, 20, 14, 25, 12, 24, 13, 26, 53, 67, 51, 66, 52, 68, 47, 64, 45, 63, 46, 65, 50, 70, 48, 69, 49, 71, 35, 58, 33, 57, 34, 59, 29, 55, 27, 54, 28, 56, 32, 61, 30, 60, 31, 62, 44, 76, 42, 75, 43, 77, 38, 73, 36
Offset: 0

Views

Author

Antti Karttunen, May 19 2008, originally described in a posting at the SeqFan mailing list on Sep 15 2005

Keywords

Crossrefs

Inverse: A140264. Bisections: A117967 & A117968. a(n) = A140265(n+1)-1.

Programs

  • Python
    from sympy import ceiling
    from sympy.ntheory.factor_ import digits
    def a004488(n): return int("".join([str((3 - i)%3) for i in digits(n, 3)[1:]]), 3)
    def a117968(n):
        if n==1: return 2
        if n%3==0: return 3*a117968(n/3)
        elif n%3==1: return 3*a117968((n - 1)/3) + 2
        else: return 3*a117968((n + 1)/3) + 1
    def a117967(n): return 0 if n==0 else a117968(-n) if n<0 else a004488(a117968(n))
    def a001057(n): return -(-1)**n*ceiling(n/2)
    def a(n): return a117967(a001057(n)) # Indranil Ghosh, Jun 07 2017

Formula

a(n) = A117967(A001057(n)). (Assuming that the domain of A117967 is the whole Z line.)

A246207 Permutation of nonnegative integers: a(0) = 0, a(1) = 1, a(2n) = A117968(a(n)), a(2n+1) = A117967(1+a(n)).

Original entry on oeis.org

0, 1, 2, 5, 7, 3, 22, 15, 23, 11, 6, 4, 71, 35, 66, 52, 58, 33, 25, 12, 21, 16, 8, 17, 172, 99, 73, 36, 213, 148, 194, 137, 197, 152, 75, 43, 59, 29, 24, 13, 69, 49, 68, 47, 19, 9, 64, 45, 587, 419, 225, 127, 173, 104, 72, 37, 516, 304, 620, 431, 643, 447, 601, 462, 640, 441, 577, 423, 177, 103, 203, 155, 211, 150, 61, 30, 57, 34, 26, 53
Offset: 0

Views

Author

Antti Karttunen, Aug 19 2014

Keywords

Comments

This is an instance of entanglement permutation, where complementary pair A005843/A005408 (even and odd numbers respectively) is entangled with complementary pair A117968/A117967 (negative and positive part of inverse of balanced ternary enumeration of integers, respectively), with a(0) set to 0 and a(1) set to 1.
Thus this shares with A140263 the property that after a(0)=0, the even positions contain only terms of A117968 and the odd positions contain only terms of A117967.

Crossrefs

Inverse: A246208.
Related permutations: A140263, A054429, A246209, A246211.

Programs

  • Python
    from sympy.ntheory.factor_ import digits
    def a004488(n): return int("".join([str((3 - i)%3) for i in digits(n, 3)[1:]]), 3)
    def a117968(n):
        if n==1: return 2
        if n%3==0: return 3*a117968(n/3)
        elif n%3==1: return 3*a117968((n - 1)/3) + 2
        else: return 3*a117968((n + 1)/3) + 1
    def a117967(n): return 0 if n==0 else a117968(-n) if n<0 else a004488(a117968(n))
    def a(n): return n if n<2 else a117968(a(n/2)) if n%2==0 else a117967(1 + a((n - 1)/2)) # Indranil Ghosh, Jun 07 2017

Formula

As a composition of related permutations:
a(n) = A246209(A054429(n)).
a(n) = A246211(A246209(n)).

A246211 Self-inverse permutation of natural numbers: a(0) = 0, a(1) = 1, and for n > 1, if A117966(n) < 0, a(n) = A117967(1+a(-(A117966(n)))), otherwise a(n) = A117968(a(A117966(n)-1)).

Original entry on oeis.org

0, 1, 5, 22, 71, 2, 35, 15, 99, 225, 531, 66, 213, 516, 1899, 7, 73, 172, 307, 127, 1369, 36, 3, 52, 304, 148, 1246, 5408, 17461, 620, 1567, 5321, 41591, 194, 698, 6, 21, 69, 1489, 5165, 16975, 174, 142234, 643, 17287, 587, 695, 173, 5195, 72, 605, 4770, 23, 1761, 12051, 4175, 24134, 389, 137, 431, 3758, 945, 11964, 392, 419, 482, 11, 2872, 104, 37, 3830, 4, 49, 16
Offset: 0

Views

Author

Antti Karttunen, Aug 19 2014

Keywords

Comments

This is an instance of entanglement permutation, where complementary pair A117967/A117968 (positive and negative part of inverse of balanced ternary enumeration of integers, respectively) is entangled with the same pair in the opposite order: A117967/A117968, with a(0) set to 0 and a(1) set to 1.

Crossrefs

Related or similar permutations: A246207, A246208, A246209, A246210, A004488, A245812, A054429.

Formula

a(0) = 0, a(1) = 1, and for n > 1, if A117966(n) < 0, a(n) = A117967(1+a(-(A117966(n)))), otherwise a(n) = A117968(a(A117966(n)-1)).

A246209 Permutation of nonnegative integers: a(0) = 0, a(1) = 1, a(2n) = A117967(1+a(n)), a(2n+1) = A117968(a(n)).

Original entry on oeis.org

0, 1, 5, 2, 15, 22, 3, 7, 52, 66, 35, 71, 4, 6, 11, 23, 137, 194, 148, 213, 36, 73, 99, 172, 17, 8, 16, 21, 12, 25, 33, 58, 462, 601, 447, 643, 431, 620, 304, 516, 37, 72, 104, 173, 127, 225, 419, 587, 45, 64, 9, 19, 47, 68, 49, 69, 13, 24, 29, 59, 43, 75, 152, 197, 1273, 1734, 1334, 1940, 1294, 1740, 899, 1556, 1404, 1837, 945, 1567, 389, 698, 1246, 1761, 41
Offset: 0

Views

Author

Antti Karttunen, Aug 19 2014

Keywords

Comments

This is an instance of entanglement permutation, where complementary pair A005843/A005408 (even and odd numbers respectively) is entangled with complementary pair A117967/A117968 (positive and negative part of inverse of balanced ternary enumeration of integers, respectively), with a(0) set to 0 and a(1) set to 1.
This implies that the even positions contain only terms of A117967 and apart from a(1) = 1, the odd positions contain only terms of A117968.

Crossrefs

Inverse: A246210.
Related permutations: A054429, A246207, A246211.

Programs

  • Python
    from sympy.ntheory.factor_ import digits
    def a004488(n): return int("".join(str((3 - i)%3) for i in digits(n, 3)[1:]), 3)
    def a117968(n):
        if n==1: return 2
        if n%3==0: return 3*a117968(n//3)
        elif n%3==1: return 3*a117968((n - 1)//3) + 2
        else: return 3*a117968((n + 1)//3) + 1
    def a117967(n): return 0 if n==0 else a117968(-n) if n<0 else a004488(a117968(n))
    def a(n): return n if n<2 else a117967(1 + a(n//2)) if n%2==0 else a117968(a((n - 1)//2))
    print([a(n) for n in range(101)]) # Indranil Ghosh, Jun 07 2017

Formula

a(0) = 0, a(1) = 1, a(2n) = A117967(1+a(n)), a(2n+1) = A117968(a(n)).
As a composition of related permutations:
a(n) = A246207(A054429(n)).
a(n) = A246211(A246207(n)).

A246205 Permutation of natural numbers: a(1) = 1, a(A014580(n)) = A117968(a(n)), a(A091242(n)) = A117967(1+a(n)), where A117967 and A117968 give positive and negative parts of inverse of balanced ternary enumeration of integers, and A014580 resp. A091242 are the binary coded irreducible resp. reducible polynomials over GF(2).

Original entry on oeis.org

1, 2, 7, 5, 3, 11, 23, 15, 4, 12, 22, 33, 6, 52, 17, 13, 35, 43, 25, 16, 137, 45, 53, 36, 58, 155, 29, 47, 462, 154, 66, 135, 37, 152, 426, 30, 8, 156, 1273, 428, 24, 148, 460, 41, 423, 1426, 71, 31, 9, 427, 4283, 1410, 34, 431, 75, 1274, 159, 1423, 21, 3707, 194, 99, 44, 10, 1412, 11115, 64, 3850, 38, 1404, 103, 4281, 26, 412, 3722, 49
Offset: 1

Views

Author

Antti Karttunen, Aug 19 2014

Keywords

Crossrefs

Inverse: A246206.
Similar or related entanglement permutations: A246163, A245701, A246201, A246207, A246209.

Formula

a(1) = 1, and for n > 1, if A091225(n) = 1 [i.e. n is in A014580], a(n) = A117968(a(A091226(n))), otherwise a(n) = A117967(1+a(A091245(n))).
As a composition of related permutations:
a(n) = A246207(A245701(n)).
a(n) = A246209(A246201(n)).

A004488 Tersum n + n.

Original entry on oeis.org

0, 2, 1, 6, 8, 7, 3, 5, 4, 18, 20, 19, 24, 26, 25, 21, 23, 22, 9, 11, 10, 15, 17, 16, 12, 14, 13, 54, 56, 55, 60, 62, 61, 57, 59, 58, 72, 74, 73, 78, 80, 79, 75, 77, 76, 63, 65, 64, 69, 71, 70, 66, 68, 67, 27, 29, 28, 33, 35, 34, 30, 32, 31, 45, 47, 46, 51
Offset: 0

Views

Author

Keywords

Comments

Could also be described as "Write n in base 3, then replace each digit with its base-3 negative" as with A048647 for base 4. - Henry Bottomley, Apr 19 2000
a(a(n)) = n, a self-inverse permutation of the nonnegative integers. - Reinhard Zumkeller, Dec 19 2003
First 3^n terms of the sequence form a permutation s(n) of 0..3^n-1, n>=1; the number of inversions of s(n) is A016142(n-1). - Gheorghe Coserea, Apr 23 2018

Crossrefs

Programs

  • Haskell
    a004488 0 = 0
    a004488 n = if d == 0 then 3 * a004488 n' else 3 * a004488 n' + 3 - d
                where (n', d) = divMod n 3
    -- Reinhard Zumkeller, Mar 12 2014
    
  • Maple
    a:= proc(n) local t, r, i;
          t, r:= n, 0;
          for i from 0 while t>0 do
            r:= r+3^i *irem(2*irem(t, 3, 't'), 3)
          od; r
        end:
    seq(a(n), n=0..80);  # Alois P. Heinz, Sep 07 2011
  • Mathematica
    a[n_] := FromDigits[Mod[3-IntegerDigits[n, 3], 3], 3]; Table[a[n], {n, 0, 66}] (* Jean-François Alcover, Mar 03 2014 *)
  • PARI
    a(n) = my(b=3); fromdigits(apply(d->(b-d)%b, digits(n, b)), b);
    vector(67, i, a(i-1))  \\ Gheorghe Coserea, Apr 23 2018
    
  • Python
    from sympy.ntheory.factor_ import digits
    def a(n): return int("".join([str((3 - i)%3) for i in digits(n, 3)[1:]]), 3) # Indranil Ghosh, Jun 06 2017

Formula

Tersum m + n: write m and n in base 3 and add mod 3 with no carries, e.g., 5 + 8 = "21" + "22" = "10" = 1.
a(n) = Sum(3-d(i)-3*0^d(i): n=Sum(d(i)*3^d(i): 0<=d(i)<3)). - Reinhard Zumkeller, Dec 19 2003
a(3*n) = 3*a(n), a(3*n+1) = 3*a(n)+2, a(3*n+2) = 3*a(n)+1. - Robert Israel, May 09 2014

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

A117968 Negative part of inverse of A117966; write -n in balanced ternary and then replace (-1)'s with 2's.

Original entry on oeis.org

2, 7, 6, 8, 22, 21, 23, 19, 18, 20, 25, 24, 26, 67, 66, 68, 64, 63, 65, 70, 69, 71, 58, 57, 59, 55, 54, 56, 61, 60, 62, 76, 75, 77, 73, 72, 74, 79, 78, 80, 202, 201, 203, 199, 198, 200, 205, 204, 206, 193, 192, 194, 190, 189, 191, 196, 195, 197, 211, 210, 212, 208, 207
Offset: 1

Views

Author

Keywords

Examples

			-7 in balanced ternary is (-1)1(-1), changing to 212 ternary is 23, so a(7)=23.
		

References

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

Crossrefs

Cf. A117966. a(n) = A004488(A117967(n)). Bisection of A140263. A140268 gives the same sequence in ternary.

Programs

  • Python
    def a(n):
        if n==1: return 2
        if n%3==0: return 3*a(n//3)
        elif n%3==1: return 3*a((n - 1)//3) + 2
        else: return 3*a((n + 1)//3) + 1
    print([a(n) for n in range(1, 101)]) # Indranil Ghosh, Jun 06 2017

Formula

a(1) = 2, a(3n) = 3a(n), a(3n+1) = 3a(n)+2, a(3n-1) = 3a(n)+1.

A140267 Nonnegative integers in balanced ternary representation (with 2 standing for -1 digit).

Original entry on oeis.org

0, 1, 12, 10, 11, 122, 120, 121, 102, 100, 101, 112, 110, 111, 1222, 1220, 1221, 1202, 1200, 1201, 1212, 1210, 1211, 1022, 1020, 1021, 1002, 1000, 1001, 1012, 1010, 1011, 1122, 1120, 1121, 1102, 1100, 1101, 1112, 1110, 1111, 12222, 12220, 12221
Offset: 0

Views

Author

Antti Karttunen, May 19 2008, prompted by Eric Angelini's posting on SeqFan mailing list on Sep 15 2005

Keywords

Comments

Sequence A117967 in ternary. (See there for more references.)
From Daniel Forgues, Mar 22 2010: (Start)
The balanced ternary digits {-1, 0, +1} (balanced trits) of a(n) are being represented by {2, 0, 1} respectively in this sequence.
The sign of a(n) is given by the sign of its leading trit.
The number k, k >= 0, of trailing "0"s of a(n) indicates that a(n) is divisible by 3^k.
a(n) is even/odd if it has an even/odd count of nonzero trits. (End)

Examples

			For example a(2) = 12, as 1*3 + -1*1 = 2. Similarly, a(19) = 1201, as 1*27 + -1*9 + 0*3 + 1*1 = 19.
		

Crossrefs

a(n) = A007089(A117967(n)). Cf. A140268.

Programs

  • Python
    from sympy.ntheory.factor_ import digits
    def a004488(n): return int("".join([str((3 - i)%3) for i in digits(n, 3)[1:]]), 3)
    def a117968(n):
        if n==1: return 2
        if n%3==0: return 3*a117968(n/3)
        elif n%3==1: return 3*a117968((n - 1)/3) + 2
        else: return 3*a117968((n + 1)/3) + 1
    def a117967(n): return 0 if n==0 else a004488(a117968(n))
    def a(n): return int("".join(map(str, digits(a117967(n), 3)[1:]))) # Indranil Ghosh, Jun 06 2017

Extensions

Definition edited by Daniel Forgues, Mar 24 2010

A295882 Balanced ternary representation of the deficiency of n, A033879(n).

Original entry on oeis.org

1, 1, 5, 1, 4, 0, 15, 1, 17, 5, 10, 8, 12, 4, 15, 1, 52, 6, 45, 7, 10, 11, 49, 24, 46, 10, 53, 0, 28, 24, 30, 1, 45, 53, 49, 65, 36, 52, 49, 20, 40, 24, 159, 4, 12, 50, 154, 56, 161, 16, 30, 15, 142, 24, 41, 19, 43, 29, 139, 204, 150, 28, 49, 1, 154, 24, 147, 10, 159, 8, 106, 192, 99, 43, 29, 12, 139, 24, 87, 55
Offset: 1

Views

Author

Antti Karttunen, Dec 04 2017

Keywords

Crossrefs

Cf. A000396 (gives the positions of zeros).

Programs

Formula

If A033879(n) >= 0, then a(n) = A117967(A033879(n)), otherwise a(n) = A117968(-A033879(n)).
For all n >= 1, A117966(a(n)) = A033879(n).
Showing 1-10 of 23 results. Next