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 13 results. Next

A323783 a(n) = A134028(A323782(n)): Primes and negated primes such that the reverse of the balanced ternary representation is a prime.

Original entry on oeis.org

-2, -11, 7, -5, 13, -29, -17, 37, 31, 43, -83, -101, 61, -89, 73, -53, -71, -59, 103, -173, 313, -353, 241, -137, -263, 223, 331, 277, 181, -269, 163, -179, -233, 199, -347, 139, 193, -311, -149, 367, 853, 691, -929, -443, -983, 421, -389, -839, 457, -677
Offset: 1

Views

Author

Philippe Cochin, Jan 27 2019

Keywords

Comments

The "warp" operation is reversible between A323782 and this sequence.
Negating a number in balanced ternary notation is done by inverting the + and -.

Examples

			-17 is a term:
-17 is -+0+ in balanced ternary notation
-+0+ reversed is +0+-
+0+- is 29 in balanced ternary notation
29 is prime
Therefore -17 is "warped" to 29.
This operation is reversible: 29 "warps" to -17.
		

Crossrefs

Corresponding warp prime numbers to A323782.
Supersequence of A224502.

Programs

  • PARI
    d3(n) = if ((n%3)==2, n\3+1, n\3);
    m3(n) = if ((n%3)==2, -1, n % 3);
    t(n) = if (n==0, [0], if (abs(n) == 1, [n], concat(m3(n), t(d3(n)))));
    f(n) = subst(Pol(Vec(t(n))), x, 3);
    lista(nn) = {forprime(n=1, nn, if (isprime(abs(f(n))), print1(f(n), ", ")););} \\ Michel Marcus, Jan 29 2019
  • Python
    # See Github link.
    

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

A030102 Base-3 reversal of n (written in base 10).

Original entry on oeis.org

0, 1, 2, 1, 4, 7, 2, 5, 8, 1, 10, 19, 4, 13, 22, 7, 16, 25, 2, 11, 20, 5, 14, 23, 8, 17, 26, 1, 28, 55, 10, 37, 64, 19, 46, 73, 4, 31, 58, 13, 40, 67, 22, 49, 76, 7, 34, 61, 16, 43, 70, 25, 52, 79, 2, 29, 56, 11, 38, 65, 20, 47, 74, 5, 32, 59, 14, 41, 68, 23, 50, 77, 8, 35, 62, 17, 44, 71
Offset: 0

Views

Author

Keywords

Examples

			a(17) = 25 because 17 in base 3 is 122, and backwards that is 221, which is 25 in base 10.
a(18) = 2 because 18 in base 3 is 200, and backwards that is 2.
		

Crossrefs

Cf. A030341.
Cf. A263273 for a bijective variant.

Programs

  • Haskell
    a030102 = foldl (\v d -> 3 * v + d) 0 . a030341_row
    -- Reinhard Zumkeller, Dec 16 2013
  • Maple
    a030102:= proc(n) option remember;
      local y;
      y:= n mod 3;
      3^ilog[3](n)*y + procname((n-y)/3)
    end proc:
    for i from 0 to 2 do a030102(i):= i od:
    seq(a030102(i),i=0..100); # Robert Israel, Dec 24 2015
    # alternative
    A030102 := proc(n)
        local r ;
        r := ListTools[Reverse](convert(n,base,3)) ;
        add(op(i,r)*3^(i-1),i=1..nops(r)) ;
    end proc: # R. J. Mathar, May 28 2016
  • Mathematica
    A030102[n_] := FromDigits[Reverse@IntegerDigits[n, 3], 3] (* JungHwan Min, Dec 23 2015 *)
    FromDigits[#,3]&/@(Reverse/@IntegerDigits[Range[0,80],3]) (* Harvey P. Dale, Feb 05 2020 *)
  • PARI
    a(n,b=3)=subst(Polrev(base(n,b)),x,b) /* where */
    base(n,b)={my(a=[n%b]);while(0M. F. Hasler, Nov 04 2011
    
  • PARI
    a(n) = fromdigits(Vecrev(digits(n, 3)), 3); \\ Michel Marcus, Oct 10 2017
    

Formula

a(n) = t(n,0) with t(n,r) = if n=0 then r else t(floor(n/3),r*3+(n mod 3)). - Reinhard Zumkeller, Mar 04 2010
G.f. G(x) satisfies: G(x) = (1+x+x^2)*G(x^3) - (1+2*x)*(x + 2*Sum_{m>=0} 3^m*x^(3^(m+1)+1)/(x^3-1). - Robert Israel, Dec 24 2015

A134021 Length of n in balanced ternary representation.

Original entry on oeis.org

1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5
Offset: 0

Views

Author

Reinhard Zumkeller, Oct 19 2007

Keywords

Comments

Shifted variant of A064099.

Examples

			100 = 1*3^4+1*3^3-1*3^2+0*3^1+1*3^0: a(100) = |++-0+| = 5.
200 = 1*3^5-1*3^4+1*3^3+1*3^2+1*3^1-1*3^0: a(200) = |+-+++-| = 6.
300 = 1*3^5+1*3^4-1*3^3+0*3^2+1*3^1+0*3^0: a(300) = |++-0+0| = 6.
		

References

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

Crossrefs

Programs

  • Mathematica
    a[n_] := Ceiling[Log[3, 2*n+1]]; a[0] = 1; Array[a, 100, 0] (* Amiram Eldar, Apr 03 2025 *)
  • Python
    def a(n):
        if n==0: return 1
        s=0
        x=0
        while n>0:
            x=n%3
            n=n//3
            if x==2:
                x=-1
                n+=1
            s+=1
        return s
    print([a(n) for n in range(101)]) # Indranil Ghosh, Jun 07 2017

Formula

For n > 0: a(n) = ceiling(log(2*n+1)/log(3)).
a(n) = A134022(n) + A134023(n) + A134024(n).
0 <= a(n) - A081604(n) <= 1.
a(A134025(n)) = A081604(A134025(n)); a(A134026(n)) = A081604(A134026(n))+1.
a(A134027(n)) = a(n); a(abs(A134028(n))) <= a(n).
a(n) = A064099(n-1) for n>1.
n = Sum_{k=0..a(n)-1} (A059095(A134421(n)-2-k)*3^k), for n > 0. - Reinhard Zumkeller, Oct 25 2007
a(n) = A005812(n) + A134023(n).

A134027 Nonnegative numbers that are palindromes in balanced ternary representation.

Original entry on oeis.org

0, 1, 4, 7, 10, 13, 16, 28, 40, 43, 52, 61, 73, 82, 91, 103, 112, 121, 124, 160, 196, 208, 244, 280, 292, 328, 364, 367, 394, 421, 457, 484, 511, 547, 574, 601, 613, 640, 667, 703, 730, 757, 793, 820, 847, 859, 886, 913, 949, 976, 1003, 1039, 1066, 1093, 1096
Offset: 1

Views

Author

Reinhard Zumkeller, Oct 19 2007

Keywords

Comments

A134028(a(n)) = a(n).

Examples

			a(10) = 43 = 1*3^4 - 1*3^3 - 1*3^2 - 1*3^1 + 1*3^0 == '+---+';
a(11) = 52 = 1*3^4 - 1*3^3 + 0*3^2 - 1*3^1 + 1*3^0 == '+-0-+';
a(12) = 61 = 1*3^4 - 1*3^3 + 1*3^2 - 1*3^1 + 1*3^0 == '+-+-+';
a(13) = 73 = 1*3^4 + 0*3^3 - 1*3^2 + 0*3^1 + 1*3^0 == '+0-0+'.
		

References

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

Crossrefs

Cf. A014190.

Programs

  • Mathematica
    balTernDigits[0] := {0}; balTernDigits[n_ /; n > 0] := Module[{unParsed = n, currRem, currExp = 1, digitList = {}, nextDigit}, While[unParsed > 0, If[unParsed == 3^(currExp - 1), digitList = Append[digitList, 1]; unParsed = 0, currRem = Mod[unParsed, 3^currExp]/3^(currExp - 1); nextDigit = Switch[ currRem, 0, 0, 2, -1, 1, 1]; digitList = Append[ digitList, nextDigit]; unParsed = unParsed - nextDigit*3^(currExp - 1)]; currExp++]; digitList = Reverse[digitList]; Return[ digitList]]; balTernDigits[n_ /; n < 0] := (-1) balTernDigits[ Abs[ n]]; palQ[n_] := n == Reverse@ n; Select[ Range@ 1300, palQ@ balTernDigits@# &] (* Robert G. Wilson v, Jun 17 2014 *)

A030104 Base 5 reversal of n (written in base 10).

Original entry on oeis.org

0, 1, 2, 3, 4, 1, 6, 11, 16, 21, 2, 7, 12, 17, 22, 3, 8, 13, 18, 23, 4, 9, 14, 19, 24, 1, 26, 51, 76, 101, 6, 31, 56, 81, 106, 11, 36, 61, 86, 111, 16, 41, 66, 91, 116, 21, 46, 71, 96, 121, 2, 27, 52, 77, 102, 7, 32, 57, 82, 107, 12, 37, 62, 87, 112, 17, 42, 67, 92, 117, 22, 47, 72, 97
Offset: 0

Views

Author

Keywords

Crossrefs

Programs

  • Mathematica
    IntegerReverse[Range[0, 100], 5] (* Paolo Xausa, Aug 07 2024 *)
  • PARI
    a(n,b=5)=subst(Polrev(base(n,b)),x,b) /* where */
    base(n,b)={my(a=[n%b]);while(n\=b,a=concat(n%b,a));a}  \\ M. F. Hasler, Nov 04 2011

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));

A274107 (Balanced ternary representation of n) - (reversed balanced ternary representation of n).

Original entry on oeis.org

0, 0, 1, 2, 0, 13, -1, -9, 4, 8, 0, 13, 8, 0, 49, 17, -9, 34, -7, -33, 10, -13, -39, 28, -4, -30, 13, 26, 0, 43, 20, -6, 61, 29, 3, 46, 32, 6, 49, 26, 0, 157, 71, -9, 124, 29, -51, 82, 5, -75, 130, 44, -36, 97, -25, -105, 28, -49, -129, 76, -10, -90, 43, -25, -105, 28, -49, -129, 100, 14, -66
Offset: 0

Views

Author

N. J. A. Sloane, Jun 16 2016

Keywords

Comments

This is A117966(n) - A134028(n).
As the graph shows, there are large jumps at places where either A117966 or A134028 has a discontinuity, that is, at values of n which are a power of 3 times 1, 1.5, or 2. - N. J. A. Sloane, Jul 03 2016

Crossrefs

A160652 Express n in balanced ternary, then reverse the digits, leaving any trailing zeros alone.

Original entry on oeis.org

0, 1, -2, 3, 4, -11, -6, 7, -8, 9, 10, -5, 12, 13, -38, -33, 16, -29, -18, 25, -20, 21, 34, -35, -24, 19, -26, 27, 28, -17, 30, 37, -32, -15, 22, -23, 36, 31, -14, 39, 40, -119, -114, 43, -92, -99, 70, -65, 48, 97, -110, -87, 52, -83, -54, 79, -56, 75, 106, -101
Offset: 0

Views

Author

Keywords

Comments

This sequence, together with its negative extension a(-n) = -a(n) is a self-inverse permutation of the integers. The absolute values are a self-inverse permutation of the nonnegative integers.

Examples

			87 in balanced ternary is 101(-1)0; leaving the final 0 and reversing the remaining digits gives (-1)1010, which is -51; so a(87) = -51.
		

Crossrefs

Programs

  • PARI
    a(n)=local(r,dr,q);if(n==0,0,r=0;dr=1;while(n%3==0,dr*=3;n\=3);while(n!=0,q=(n+1)\3;r=3*r+dr*(n-3*q);n=q);r) \\ Franklin T. Adams-Watters, May 24 2009
    
  • Python
    def a(n):
        if n==0: return 0
        r=0
        dr=1
        while n%3==0:
            dr*=3
            n/=3
        while n!=0:
            q=(n + 1)/3
            r=3*r + dr*(n - 3*q)
            n=q
        return r
    ##print [a(n) for n in range(101)] # Indranil Ghosh, Jun 10 2017, after Franklin T. Adams-Watters

Formula

a(n) = A134028(n)*3^A007949(n). [Franklin T. Adams-Watters, May 24 2009]

A274601 a(n) = 2*3^(s-1) - n, where s is the number of trits of n in balanced ternary form.

Original entry on oeis.org

1, 4, 3, 2, 13, 12, 11, 10, 9, 8, 7, 6, 5, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 121, 120, 119, 118, 117, 116, 115, 114, 113, 112, 111, 110, 109, 108, 107, 106, 105, 104, 103, 102, 101, 100
Offset: 1

Views

Author

Lei Zhou, Nov 10 2016

Keywords

Comments

Analogous to a bit, a ternary digit is a trit.
Per the definition, n + a(n) = 2*3^(s-1), where s is the number of trits of n and a(n), n and a(n) form a decomposition of 2*3^(s-1).

Examples

			For n=1 the balanced ternary form of 1 is 1, which has 1 trits. 2*3^(1-1)-1 = 1, so a(1) = 1.
For n=2 the balanced ternary form of 2 is 1T, which has 2 trits. 2*3^(2-1)-2 = 4, so a(2) = 4.
For n=3 the balanced ternary form of 3 is 10, which has 2 trits. 2*3^(2-1)-3 = 3, so a(2) = 3.
...
For n=62 the balanced ternary form of 62 is 1T10T, which has 5 trits. 2*3^(5-1)-62 = 100, so a(62) = 100.
		

Crossrefs

Programs

  • Mathematica
    Table[2*3^(Floor[Log[3, 2*n - 1]]) - n, {n, 1, 62}]
  • PARI
    a(n) = 2*3^logint(2*n-1,3)-n \\ Jason Yuen, Nov 18 2024
  • Python
    from sympy import integer_log
    def a(n): return 2*3**(integer_log(2*n - 1, 3)[0]) - n
    print([a(n) for n in range(1, 101)]) # Indranil Ghosh, Jun 10 2017
    

Formula

a(n) = 2*3^(floor(log_3(2*n-1))) - n. [corrected by Jason Yuen, Nov 18 2024]
Showing 1-10 of 13 results. Next