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.

A007302 Optimal cost function between two processors at distance n.

Original entry on oeis.org

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

Views

Author

Keywords

Comments

Also the number of nonzero digits in the symmetric signed digit expansion of n with q=2 (i.e., the representation of n in the (-1,0,1)2 number system). - _Ralf Stephan, Jun 30 2003
Volger (1985) proves that a(n) <= ceiling(log_2(3n/2) / 2) and uses a(n) to derive an upper bound on the length of the minimum addition-subtraction chain for n. - Steven G. Johnson (stevenj(AT)math.mit.edu), May 01 2007
Starting from 0, the smallest number of steps to reach n, where each step involves moving a power of 2 in either direction. - Dmitry Kamenetsky, Jul 04 2023

References

  • N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).

Crossrefs

Subtracting 1 gives A280737.
Cf. A007583 (indices of record highs).

Programs

  • Haskell
    import Data.Bits (xor)
    a007302 n = a000120 $ xor n (3 * n) :: Integer
    -- Reinhard Zumkeller, Jun 17 2012
  • Mathematica
    a[n_] := Count[ BitXor[ b1 = IntegerDigits[n, 2]; b3 = IntegerDigits[3*n, 2]; PadLeft[b1, Length[b3]], b3], 1]; Table[a[n], {n, 0, 100}] (* Jean-François Alcover, May 20 2014, after Ramasamy Chandramouli *)
  • PARI
    ep(r,n)=local(t=n/2^(r+2));floor(t+5/6)-floor(t+4/6)-floor(t+2/6)+floor(t+1/6)
    a(n)=sum(r=0,log(3*n)\log(2)-1,!!ep(r,n))
    for(n=1,100,print1(a(n)", "))
    /* corrected by Charles R Greathouse IV, Jun 16 2012 */
    
  • PARI
    a(n)=hammingweight(bitxor(n,3*n)) \\ Charles R Greathouse IV, Jan 03 2017
    

Formula

a(0) = 0; a(n) = 1 if n is a power of 2; a(n) = 1 + min { a(n-2^k), a(2^(k+1)-n) } if 2^k < n < 2^(k+1).
a(n) = 0 if n = 0, = 1 if n = 1, = a(n/2) if n > 1 and n even and = min(a(n-1), a(n+1))+1 if n > 1 and n odd. - David W. Wilson, Dec 28 2005
a(n) = hammingweight( XOR(n, 3*n) ). - Ramasamy Chandramouli, Aug 20 2010
A007302(n) = A000120(n) - sum (A213629(n,A136412(k))). - Reinhard Zumkeller, Jun 17 2012
a(0) = 0; a(2n) = a(n); a(4n-1) = a(n) + 1; a(4n+1) = a(n) + 1. - Nathan Fox, Mar 12 2013