Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Search: a006068 -id:a006068
     Sort: relevance | references | number | modified | created      Format: long | short | data
Permutation of natural numbers: a(0) = 0, a(n) = A003188(1+A006068(n-1)), where A003188 is binary Gray code and A006068 is its inverse.
+20
19
0, 1, 3, 6, 2, 12, 4, 7, 5, 24, 8, 11, 9, 13, 15, 10, 14, 48, 16, 19, 17, 21, 23, 18, 22, 25, 27, 30, 26, 20, 28, 31, 29, 96, 32, 35, 33, 37, 39, 34, 38, 41, 43, 46, 42, 36, 44, 47, 45, 49, 51, 54, 50, 60, 52, 55, 53, 40, 56, 59, 57, 61, 63, 58, 62, 192, 64, 67, 65, 69, 71, 66, 70, 73, 75, 78, 74, 68, 76, 79, 77, 81
OFFSET
0,3
FORMULA
a(n) = A003188(A066194(n)) = A003188(1+A006068(n-1)).
Other identities. For all n >= 0:
A101080(n,a(n+1)) = 1. [The Hamming distance between n and a(n+1) is always one.]
A268726(n) = A000523(A003987(n, a(n+1))). [A268726 gives the index of the toggled bit.]
MATHEMATICA
A003188[n_] := BitXor[n, Floor[n/2]]; A006068[n_] := If[n == 0, 0, BitXor @@ Table[Floor[n/2^m], {m, 0, Floor[Log[2, n]]}]]; a[n_] := If[n == 0, 0, A003188[1 + A006068[n-1]]]; Table[a[n], {n, 0, 100}] (* Jean-François Alcover, Feb 23 2016 *)
PROG
(Scheme) (define (A268717 n) (if (zero? n) n (A003188 (A066194 n))))
(PARI) A003188(n) = bitxor(n, floor(n/2));
A006068(n) = if(n<2, n, {my(m = A006068(floor(n/2))); 2*m + (n%2 + m%2)%2});
for(n=0, 100, print1(if(n<1, 0, A003188(1 + A006068(n - 1)))", ")) \\ Indranil Ghosh, Mar 31 2017
(Python)
def A003188(n): return n^(n//2)
def A006068(n):
if n<2: return n
m = A006068(n//2)
return 2*m + (n%2 + m%2)%2
def a(n): return 0 if n<1 else A003188(1 + A006068(n - 1))
print([a(n) for n in range(0, 101)]) # Indranil Ghosh, Mar 31 2017
(Python)
def A268717(n):
k, m = n-1, n-1>>1
while m > 0:
k ^= m
m >>= 1
return k+1^ k+1>>1 # Chai Wah Wu, Jun 29 2022
CROSSREFS
Inverse: A268718.
Row 1 and column 1 of array A268715 (without the initial zero).
Row 1 of array A268820.
Cf. A092246 (fixed points).
Cf. A268817 ("square" of this permutation).
Cf. A268821 ("shifted square"), A268823 ("shifted cube") and also A268825, A268827 and A268831 ("shifted higher powers").
KEYWORD
nonn
AUTHOR
Antti Karttunen, Feb 12 2016
STATUS
approved
Permutation of nonnegative integers: a(n) = A054429(A006068(n)).
+20
15
0, 1, 2, 3, 4, 5, 7, 6, 8, 9, 11, 10, 15, 14, 12, 13, 16, 17, 19, 18, 23, 22, 20, 21, 31, 30, 28, 29, 24, 25, 27, 26, 32, 33, 35, 34, 39, 38, 36, 37, 47, 46, 44, 45, 40, 41, 43, 42, 63, 62, 60, 61, 56, 57, 59, 58, 48, 49, 51, 50, 55, 54, 52, 53, 64, 65, 67, 66
OFFSET
0,3
COMMENTS
This permutation transforms the enumeration system of positive irreducible fractions A007305/A047679 (Stern-Brocot) into the enumeration system A071766/A229742 (HCS), and the enumeration system A162909/A162910 (Bird) into A245325/A245326. - Yosu Yurramendi, Jun 09 2015
FORMULA
a(n) = A054429(A006068(n)).
a(n) = A006068(A063946(n)).
a(n) = A154435(A054429(n)).
a(n) = A180200(A258746(n)) = A117120(A180200(n)), n > 0. - Yosu Yurramendi, Apr 10 2017
MATHEMATICA
Module[{nn = 6, s}, s = Flatten[Table[Range[2^(n + 1) - 1, 2^n, -1], {n, 0, nn}]]; Map[If[# == 0, 0, s[[#]]] &, Table[Fold[BitXor, n, Quotient[n, 2^Range[BitLength[n] - 1]]], {n, 0, 2^nn}]]] (* Michael De Vlieger, Apr 06 2017, after Harvey P. Dale at A054429 and Jan Mangaldan at A006068 *)
PROG
(Scheme) (define (A233279 n) (A054429 (A006068 n)))
(R)
maxrow <- 8 # by choice
a <- 1:3
for(m in 0:maxrow) for(k in 0:(2^m-1)){
a[2^(m+2)+ k] <- a[2^(m+1)+ k] + 2^(m+1)
a[2^(m+2)+ 2^m+k] <- a[2^(m+1)+2^m+k] + 2^(m+1)
a[2^(m+2)+2^(m+1)+ k] <- a[2^(m+1)+2^m+k] + 2^(m+2)
a[2^(m+2)+2^(m+1)+2^m+k] <- a[2^(m+1)+ +k] + 2^(m+2)
}
(a <- c(0, a))
# Yosu Yurramendi, Apr 05 2017
(R)
# Given n, compute a(n) by taking into account the binary representation of n
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
for(k in 2^(0:floor(log2(length(nbit)))) )
anbit <- bitwXor(anbit, c(anbit[-(1:k)], rep(0, k))) # ?bitwXor
anbit[0:(length(anbit) - 1)] <- 1 - anbit[0:(length(anbit)-1)]
a <- c(a, sum(anbit*2^(0:(length(anbit) - 1))))
}
(a <- c(0, a))
# Yosu Yurramendi, May 29 2021
(Python)
from sympy import floor
def a006068(n):
s=1
while True:
ns=n>>s
if ns==0: break
n=n^ns
s<<=1
return n
def a054429(n): return 1 if n==1 else 2*a054429(floor(n/2)) + 1 - n%2
def a(n): return 0 if n==0 else a054429(a006068(n)) # Indranil Ghosh, Jun 11 2017
CROSSREFS
Inverse permutation: A233280.
KEYWORD
nonn
AUTHOR
Antti Karttunen, Dec 18 2013
STATUS
approved
Permutation of natural numbers: a(0) = 0, a(n) = 1 + A003188(A006068(n)-1), where A003188 is binary Gray code and A006068 is its inverse.
+20
14
0, 1, 4, 2, 6, 8, 3, 7, 10, 12, 15, 11, 5, 13, 16, 14, 18, 20, 23, 19, 29, 21, 24, 22, 9, 25, 28, 26, 30, 32, 27, 31, 34, 36, 39, 35, 45, 37, 40, 38, 57, 41, 44, 42, 46, 48, 43, 47, 17, 49, 52, 50, 54, 56, 51, 55, 58, 60, 63, 59, 53, 61, 64, 62, 66, 68, 71, 67, 77, 69, 72, 70, 89, 73, 76, 74, 78, 80, 75, 79, 113, 81
OFFSET
0,3
FORMULA
a(0) = 0, and for n >= 1, a(n) = A105081(A006068(n)) = 1 + A003188(A006068(n)-1).
Other identities. For all n >= 1:
a(A128309(n)) = A128309(n)+2. [Maps any even odious number to that number + 2.]
MATHEMATICA
{0}~Join~Table[1 + BitXor[#, Floor[#/2]] &[BitXor @@ Table[Floor[n/2^m], {m, 0, Floor[Log[2, n]]}] - 1], {n, 81}] (* Michael De Vlieger, Feb 29 2016, after Jean-François Alcover at A006068 and Robert G. Wilson v at A003188 *)
PROG
(Scheme) (define (A268718 n) (if (zero? n) n (A105081 (A006068 n))))
(PARI)
a003188(n)=bitxor(n, n>>1);
a006068(n)= {
my( s=1, ns );
while ( 1,
ns = n >> s;
if ( 0==ns, break() );
n = bitxor(n, ns);
s <<= 1;
);
return (n);
} \\ by Joerg Arndt
a(n)=if(n==0, 0, 1 + a003188(a006068(n) - 1)); \\ Indranil Ghosh, Jun 07 2017
(Python)
def a003188(n): return n^(n>>1)
def a006068(n):
s=1
while True:
ns=n>>s
if ns==0: break
n=n^ns
s<<=1
return n
def a(n): return 0 if n==0 else 1 + a003188(a006068(n) - 1) # Indranil Ghosh, Jun 07 2017
CROSSREFS
Inverse: A268717.
Row 1 of array A268830.
Cf. A092246 (fixed points).
Cf. A268818 ("square" of this permutation).
Cf. A268822 ("shifted square"), A268824 ("shifted cube") and also A268826, A268828 and A268832 (higher "shifted powers").
KEYWORD
nonn
AUTHOR
Antti Karttunen, Feb 12 2016
STATUS
approved
Square array A(r,c): A(0,c) = c, A(r,0) = 0, A(r>=1,c>=1) = A003188(1+A006068(A(r-1,c-1))) = A268717(1+A(r-1,c-1)), read by descending antidiagonals as A(0,0), A(0,1), A(1,0), A(0,2), A(1,1), A(2,0), ...
+20
13
0, 1, 0, 2, 1, 0, 3, 3, 1, 0, 4, 6, 3, 1, 0, 5, 2, 2, 3, 1, 0, 6, 12, 7, 2, 3, 1, 0, 7, 4, 6, 6, 2, 3, 1, 0, 8, 7, 13, 5, 6, 2, 3, 1, 0, 9, 5, 12, 7, 7, 6, 2, 3, 1, 0, 10, 24, 5, 15, 4, 7, 6, 2, 3, 1, 0, 11, 8, 4, 13, 5, 5, 7, 6, 2, 3, 1, 0, 12, 11, 25, 4, 14, 12, 5, 7, 6, 2, 3, 1, 0, 13, 9, 24, 12, 15, 4, 4, 5, 7, 6, 2, 3, 1, 0, 14, 13, 9, 27, 12, 10, 13, 4, 5, 7, 6, 2, 3, 1, 0
OFFSET
0,4
FORMULA
For row zero: A(0,k) = k, for column zero: A(n,0) = 0, and in other cases: A(n,k) = A003188(1+A006068(A(n-1,k-1)))
Other identities. For all n >= 0:
A(n,n) = A003188(n).
A(A006068(n),A006068(n)) = n.
EXAMPLE
The top left [0 .. 16] x [0 .. 19] section of the array:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19
0, 1, 3, 6, 2, 12, 4, 7, 5, 24, 8, 11, 9, 13, 15, 10, 14, 48, 16, 19
0, 1, 3, 2, 7, 6, 13, 12, 5, 4, 25, 24, 9, 8, 15, 14, 11, 10, 49, 48
0, 1, 3, 2, 6, 5, 7, 15, 13, 4, 12, 27, 25, 8, 24, 14, 10, 9, 11, 51
0, 1, 3, 2, 6, 7, 4, 5, 14, 15, 12, 13, 26, 27, 24, 25, 10, 11, 8, 9
0, 1, 3, 2, 6, 7, 5, 12, 4, 10, 14, 13, 15, 30, 26, 25, 27, 11, 9, 24
0, 1, 3, 2, 6, 7, 5, 4, 13, 12, 11, 10, 15, 14, 31, 30, 27, 26, 9, 8
0, 1, 3, 2, 6, 7, 5, 4, 12, 15, 13, 9, 11, 14, 10, 29, 31, 26, 30, 8
0, 1, 3, 2, 6, 7, 5, 4, 12, 13, 14, 15, 8, 9, 10, 11, 28, 29, 30, 31
0, 1, 3, 2, 6, 7, 5, 4, 12, 13, 15, 10, 14, 24, 8, 11, 9, 20, 28, 31
0, 1, 3, 2, 6, 7, 5, 4, 12, 13, 15, 14, 11, 10, 25, 24, 9, 8, 21, 20
0, 1, 3, 2, 6, 7, 5, 4, 12, 13, 15, 14, 10, 9, 11, 27, 25, 8, 24, 23
0, 1, 3, 2, 6, 7, 5, 4, 12, 13, 15, 14, 10, 11, 8, 9, 26, 27, 24, 25
0, 1, 3, 2, 6, 7, 5, 4, 12, 13, 15, 14, 10, 11, 9, 24, 8, 30, 26, 25
0, 1, 3, 2, 6, 7, 5, 4, 12, 13, 15, 14, 10, 11, 9, 8, 25, 24, 31, 30
0, 1, 3, 2, 6, 7, 5, 4, 12, 13, 15, 14, 10, 11, 9, 8, 24, 27, 25, 29
0, 1, 3, 2, 6, 7, 5, 4, 12, 13, 15, 14, 10, 11, 9, 8, 24, 25, 26, 27
MATHEMATICA
A003188[n_]:=BitXor[n, Floor[n/2]]; A006068[n_]:=If[n<2, n, Block[{m=A006068[Floor[n/2]]}, 2m + Mod[Mod[n, 2] + Mod[m, 2], 2]]]; a[r_, 0]:= 0; a[0, c_]:=c; a[r_, c_]:= A003188[1 + A006068[a[r - 1, c - 1]]]; Table[a[c, r - c], {r, 0, 15}, {c, 0, r}] //Flatten (* Indranil Ghosh, Apr 02 2017 *)
PROG
(Scheme)
(define (A268820 n) (A268820bi (A002262 n) (A025581 n)))
(define (A268820bi row col) (cond ((zero? row) col) ((zero? col) 0) (else (A268717 (+ 1 (A268820bi (- row 1) (- col 1)))))))
(define (A268820bi row col) (cond ((zero? row) col) ((zero? col) 0) (else (A003188 (+ 1 (A006068 (A268820bi (- row 1) (- col 1))))))))
(PARI) A003188(n) = bitxor(n, n\2);
A006068(n) = if(n<2, n, {my(m = A006068(n\2)); 2*m + (n%2 + m%2)%2});
a(r, c) = if(r==0, c, if(c==0, 0, A003188(1 + A006068(a(r - 1, c - 1)))));
for(r=0, 15, for(c=0, r, print1(a(c, r - c), ", "); ); print(); ); \\ Indranil Ghosh, Apr 02 2017
(Python)
def A003188(n): return n^(n//2)
def A006068(n):
if n<2: return n
else:
m=A006068(n//2)
return 2*m + (n%2 + m%2)%2
def a(r, c): return c if r<1 else 0 if c<1 else A003188(1 + A006068(a(r - 1, c - 1)))
for r in range(16):
print([a(c, r - c) for c in range(r + 1)]) # Indranil Ghosh, Apr 02 2017
CROSSREFS
Inverses of these permutations can be found in table A268830.
Row 0: A001477, Row 1: A268717, Row 2: A268821, Row 3: A268823, Row 4: A268825, Row 5: A268827, Row 6: A268831, Row 7: A268933.
Rows converge towards A003188, which is also the main diagonal.
Cf. array A268715 (can be extracted from this one).
Cf. array A268833 (shows related Hamming distances with regular patterns).
KEYWORD
nonn,tabl
AUTHOR
Antti Karttunen, Feb 14 2016
STATUS
approved
Square array A(i,j) = A003188(A006068(i) + A006068(j)), read by antidiagonals as A(0,0), A(0,1), A(1,0), A(0,2), A(1,1), A(2,0), ...
+20
11
0, 1, 1, 2, 3, 2, 3, 6, 6, 3, 4, 2, 5, 2, 4, 5, 12, 7, 7, 12, 5, 6, 4, 15, 6, 15, 4, 6, 7, 7, 13, 13, 13, 13, 7, 7, 8, 5, 4, 12, 9, 12, 4, 5, 8, 9, 24, 12, 5, 11, 11, 5, 12, 24, 9, 10, 8, 27, 4, 14, 10, 14, 4, 27, 8, 10, 11, 11, 25, 25, 10, 15, 15, 10, 25, 25, 11, 11, 12, 9, 8, 24, 29, 14, 12, 14, 29, 24, 8, 9, 12, 13, 13, 24, 9, 31, 31, 13, 13, 31, 31, 9, 24, 13, 13
OFFSET
0,4
COMMENTS
Each row n is row A006068(n) of array A268820 without its A006068(n) initial terms.
FORMULA
A(i,j) = A003188(A006068(i) + A006068(j)) = A003188(A268714(i,j)).
A(row,col) = A268820(A006068(row), (A006068(row)+col)).
EXAMPLE
The top left [0 .. 15] x [0 .. 15] section of the array:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
1, 3, 6, 2, 12, 4, 7, 5, 24, 8, 11, 9, 13, 15, 10, 14
2, 6, 5, 7, 15, 13, 4, 12, 27, 25, 8, 24, 14, 10, 9, 11
3, 2, 7, 6, 13, 12, 5, 4, 25, 24, 9, 8, 15, 14, 11, 10
4, 12, 15, 13, 9, 11, 14, 10, 29, 31, 26, 30, 8, 24, 27, 25
5, 4, 13, 12, 11, 10, 15, 14, 31, 30, 27, 26, 9, 8, 25, 24
6, 7, 4, 5, 14, 15, 12, 13, 26, 27, 24, 25, 10, 11, 8, 9
7, 5, 12, 4, 10, 14, 13, 15, 30, 26, 25, 27, 11, 9, 24, 8
8, 24, 27, 25, 29, 31, 26, 30, 17, 19, 22, 18, 28, 20, 23, 21
9, 8, 25, 24, 31, 30, 27, 26, 19, 18, 23, 22, 29, 28, 21, 20
10, 11, 8, 9, 26, 27, 24, 25, 22, 23, 20, 21, 30, 31, 28, 29
11, 9, 24, 8, 30, 26, 25, 27, 18, 22, 21, 23, 31, 29, 20, 28
12, 13, 14, 15, 8, 9, 10, 11, 28, 29, 30, 31, 24, 25, 26, 27
13, 15, 10, 14, 24, 8, 11, 9, 20, 28, 31, 29, 25, 27, 30, 26
14, 10, 9, 11, 27, 25, 8, 24, 23, 21, 28, 20, 26, 30, 29, 31
15, 14, 11, 10, 25, 24, 9, 8, 21, 20, 29, 28, 27, 26, 31, 30
MATHEMATICA
A003188[n_] := BitXor[n, Floor[n/2]]; A006068[n_] := BitXor @@ Table[Floor[ n/2^m], {m, 0, Log[2, n]}]; A006068[0]=0; A[i_, j_] := A003188[A006068[i] + A006068[j]]; Table[A[i-j, j], {i, 0, 13}, {j, 0, i}] // Flatten (* Jean-François Alcover, Feb 17 2016 *)
PROG
(Scheme)
(define (A268715 n) (A268715bi (A002262 n) (A025581 n)))
(define (A268715bi row col) (A003188 (+ (A006068 row) (A006068 col))))
;; Alternatively, extracting data from array A268820:
(define (A268715bi row col) (A268820bi (A006068 row) (+ (A006068 row) col)))
(Python)
def a003188(n): return n^(n>>1)
def a006068(n):
s=1
while True:
ns=n>>s
if ns==0: break
n=n^ns
s<<=1
return n
def T(n, k): return a003188(a006068(n) + a006068(k))
for n in range(21): print([T(n - k, k) for k in range(n + 1)]) # Indranil Ghosh, Jun 07 2017
CROSSREFS
Main diagonal: A001969.
Row 0, column 0: A001477.
Row 1, column 1: A268717.
Antidiagonal sums: A268837.
Cf. A268719 (the lower triangular section).
Cf. also A268725.
KEYWORD
nonn,tabl
AUTHOR
Antti Karttunen, Feb 12 2016
STATUS
approved
A divisor-or-multiple permutation of natural numbers: a(n) = A052330(A006068(n)).
+20
10
1, 2, 6, 3, 24, 12, 4, 8, 120, 60, 20, 40, 5, 10, 30, 15, 840, 420, 140, 280, 35, 70, 210, 105, 7, 14, 42, 21, 168, 84, 28, 56, 7560, 3780, 1260, 2520, 315, 630, 1890, 945, 63, 126, 378, 189, 1512, 756, 252, 504, 9, 18, 54, 27, 216, 108, 36, 72, 1080, 540, 180, 360, 45, 90, 270, 135, 83160, 41580, 13860, 27720, 3465, 6930, 20790, 10395, 693
OFFSET
0,2
COMMENTS
Shares with A064736, A207901, A302781, A302350, etc. a property that a(n) is always either a divisor or a multiple of a(n+1). However, because multiple bits may change simultaneously when moving from A006068(n) to A006068(n+1) [with the restriction that the changing bits are all either toggled on or all toggled off], it means that also here the terms might be divided or multiplied by more than just a single Fermi-Dirac prime (A050376). E.g. a(3) = 3, while a(4) = A050376(1) * A050376(3) * 3 = 2*4*3 = 24. See also comments in A284003.
FORMULA
a(n) = A052330(A006068(n)).
a(n) = A207901(A064707(n)).
PROG
(PARI)
up_to_e = 13;
v050376 = vector(up_to_e);
A050376(n) = v050376[n];
A209229(n) = (n && !bitand(n, n-1));
A302777(n) = A209229(isprimepower(n));
i = 0; for(n=1, oo, if(A302777(n), i++; v050376[i] = n); if(i == up_to_e, break));
A052330(n) = { my(p=1, i=1); while(n>0, if(n%2, p *= A050376(i)); i++; n >>= 1); (p); };
A006068(n)= { my(s=1, ns); while(1, ns = n >> s; if(0==ns, break()); n = bitxor(n, ns); s <<= 1; ); return (n); } \\ From A006068
CROSSREFS
Cf. A302784 (inverse).
Cf. also A207901 and A284003 (a squarefree analog).
KEYWORD
nonn
AUTHOR
Antti Karttunen, Apr 16 2018
STATUS
approved
Square array A(r,c): A(0,c) = c, A(r,0) = 0, A(r>=1,c>=1) = 1+A(r-1,A268718(c)-1) = 1 + A(r-1, A003188(A006068(c)-1)), read by descending antidiagonals.
+20
9
0, 1, 0, 2, 1, 0, 3, 4, 1, 0, 4, 2, 3, 1, 0, 5, 6, 2, 3, 1, 0, 6, 8, 9, 2, 3, 1, 0, 7, 3, 8, 9, 2, 3, 1, 0, 8, 7, 5, 5, 6, 2, 3, 1, 0, 9, 10, 4, 4, 7, 8, 2, 3, 1, 0, 10, 12, 13, 6, 4, 6, 7, 2, 3, 1, 0, 11, 15, 12, 13, 5, 4, 6, 7, 2, 3, 1, 0, 12, 11, 17, 17, 18, 5, 4, 6, 7, 2, 3, 1, 0, 13, 5, 16, 16, 19, 20, 5, 4, 6, 7, 2, 3, 1, 0, 14, 13, 7, 18, 16, 18, 19, 5, 4, 6, 7, 2, 3, 1, 0
OFFSET
0,4
EXAMPLE
The top left [0 .. 16] x [0 .. 19] section of the array:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19
0, 1, 4, 2, 6, 8, 3, 7, 10, 12, 15, 11, 5, 13, 16, 14, 18, 20, 23, 19
0, 1, 3, 2, 9, 8, 5, 4, 13, 12, 17, 16, 7, 6, 15, 14, 21, 20, 25, 24
0, 1, 3, 2, 9, 5, 4, 6, 13, 17, 16, 18, 10, 8, 15, 7, 21, 25, 24, 26
0, 1, 3, 2, 6, 7, 4, 5, 18, 19, 16, 17, 10, 11, 8, 9, 26, 27, 24, 25
0, 1, 3, 2, 8, 6, 4, 5, 20, 18, 9, 17, 7, 11, 10, 12, 28, 26, 33, 25
0, 1, 3, 2, 7, 6, 4, 5, 19, 18, 11, 10, 9, 8, 13, 12, 27, 26, 35, 34
0, 1, 3, 2, 7, 6, 4, 5, 19, 11, 14, 12, 8, 10, 13, 9, 27, 35, 38, 36
0, 1, 3, 2, 7, 6, 4, 5, 12, 13, 14, 15, 8, 9, 10, 11, 36, 37, 38, 39
0, 1, 3, 2, 7, 6, 4, 5, 14, 16, 11, 15, 8, 9, 12, 10, 38, 40, 35, 39
0, 1, 3, 2, 7, 6, 4, 5, 17, 16, 13, 12, 8, 9, 11, 10, 41, 40, 37, 36
0, 1, 3, 2, 7, 6, 4, 5, 17, 13, 12, 14, 8, 9, 11, 10, 41, 37, 36, 38
0, 1, 3, 2, 7, 6, 4, 5, 14, 15, 12, 13, 8, 9, 11, 10, 38, 39, 36, 37
0, 1, 3, 2, 7, 6, 4, 5, 16, 14, 12, 13, 8, 9, 11, 10, 40, 38, 21, 37
0, 1, 3, 2, 7, 6, 4, 5, 15, 14, 12, 13, 8, 9, 11, 10, 39, 38, 23, 22
0, 1, 3, 2, 7, 6, 4, 5, 15, 14, 12, 13, 8, 9, 11, 10, 39, 23, 26, 24
0, 1, 3, 2, 7, 6, 4, 5, 15, 14, 12, 13, 8, 9, 11, 10, 24, 25, 26, 27
PROG
(Scheme)
(define (A268830 n) (A268830bi (A002262 n) (A025581 n))) ;; o=0: Square array of shifted powers of A268718.
(define (A268830bi row col) (cond ((zero? row) col) ((zero? col) 0) (else (+ 1 (A268830bi (- row 1) (- (A268718 col) 1))))))
(define (A268830bi row col) (cond ((zero? row) col) ((zero? col) 0) (else (+ 1 (A268830bi (- row 1) (A003188 (+ -1 (A006068 col))))))))
(Python)
def a003188(n): return n^(n>>1)
def a006068(n):
s=1
while True:
ns=n>>s
if ns==0: break
n=n^ns
s<<=1
return n
def a278618(n): return 0 if n==0 else 1 + a003188(a006068(n) - 1)
def A(r, c): return c if r==0 else 0 if c==0 else 1 + A(r - 1, a278618(c) - 1)
for r in range(21): print([A(c, r - c) for c in range(r + 1)]) # Indranil Ghosh, Jun 07 2017
CROSSREFS
Inverses of these permutations can be found in table A268820.
Row 0: A001477, Row 1: A268718, Row 2: A268822, Row 3: A268824, Row 4: A268826, Row 5: A268828, Row 6: A268832, Row 7: A268934.
Rows converge towards A006068.
KEYWORD
nonn,tabl
AUTHOR
Antti Karttunen, Feb 14 2016
STATUS
approved
Square array A(n, k) = A101080(k, A003188(n+A006068(k))), read by descending antidiagonals, where A003188 is the binary Gray code, A006068 is its inverse, and A101080(x,y) gives the Hamming distance between binary expansions of x and y.
+20
8
0, 0, 1, 0, 1, 2, 0, 1, 2, 1, 0, 1, 2, 3, 2, 0, 1, 2, 3, 2, 3, 0, 1, 2, 1, 2, 1, 2, 0, 1, 2, 3, 2, 3, 2, 1, 0, 1, 2, 1, 2, 3, 4, 3, 2, 0, 1, 2, 1, 2, 3, 4, 3, 2, 3, 0, 1, 2, 3, 2, 3, 4, 3, 2, 3, 4, 0, 1, 2, 3, 2, 3, 4, 3, 2, 1, 4, 3, 0, 1, 2, 1, 2, 1, 2, 3, 2, 3, 2, 3, 2, 0, 1, 2, 1, 2, 3, 2, 1, 2, 3, 2, 3, 2, 3, 0, 1, 2, 3, 2, 3, 4, 3, 2, 3, 4, 1, 2, 1, 2
OFFSET
0,6
COMMENTS
The entry at row n, column k, gives the Hamming distance between binary expansions of k and A003188(n+A006068(k)). When Gray code is viewed as a traversal of vertices of an infinite dimensional hypercube by bit-flipping (see the illustration "Visualized as a traversal of vertices of a tesseract" in the Wikipedia's "Gray code" article) the argument k is the "address" (the binary code given inside each vertex) of the starting vertex, and argument n tells how many edges forward along the Gray code path we should hop from it (to the direction that leads away from the vertex with code 0000...). A(n, k) gives then the Hamming distance between the starting and the ending vertex. For how this works with case n=3, see comments in A268676. - Antti Karttunen, Mar 11 2024
FORMULA
A(row,col) = A101080(col, A268820(row, row+col)).
A(n, k) = A101080(k, A003188(n+A006068(k))). - Antti Karttunen, Mar 11 2024
EXAMPLE
The top left [0 .. 24] X [0 .. 24] section of the array:
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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osh, Apr 02 2017 *)
PROG
(Scheme)
(define (A268833 n) (A268833bi (A002262 n) (A025581 n)))
(define (A268833bi row col) (A101080bi col (A268820bi row (+ row col))))
(PARI) b(n) = if(n<1, 0, b(n\2) + n%2);
A101080(n, k) = b(bitxor(n, k));
A003188(n) = bitxor(n, n\2);
A006068(n) = if(n<2, n, {my(m = A006068(n\2)); 2*m + (n%2 + m%2)%2});
A268820(r, c) = if(r==0, c, if(c==0, 0, A003188(1 + A006068(A268820(r - 1, c - 1)))));
A(r, c) = A101080(c, A268820(r, r + c));
for(r=0, 20, for(c=0, r, print1(A(c, r - c), ", "); ); print(); ) \\ Indranil Ghosh, Apr 02 2017
(PARI)
up_to = 32895; \\ = binomial(1+256, 2)-1.\\ A003188 and A006068 as above.
A268833sq(n, k) = hammingweight(bitxor(n, A003188(k+A006068(n))));
A268833list(up_to) = { my(v = vector(up_to), i=0); for(a=0, oo, for(col=0, a, i++; if(i > up_to, return(v)); v[i] = A268833sq(a-col, col))); (v); };
v268833 = A268833list(1+up_to);
A268833(n) = v268833[1+n]; \\ Antti Karttunen, Mar 11 2024
(Python)
def A101080(n, k): return bin(n^k)[2:].count("1")
def A003188(n): return n^(n//2)
def A006068(n):
if n<2: return n
else:
m=A006068(n//2)
return 2*m + (n%2 + m%2)%2
def A268820(r, c): return c if r<1 else 0 if c<1 else A003188(1 + A006068(A268820(r - 1, c - 1)))
def a(r, c): return A101080(c, A268820(r, r + c))
for r in range(21):
print([a(c, r - c) for c in range(r + 1)]) # Indranil Ghosh, Apr 02 2017
CROSSREFS
Transpose A268834.
Main diagonal: A268835.
Column 0: A005811.
Row 0: A000004, Row 1: A000012, Row 2: A007395, Row 3: A268676.
Cf. also A268726, A268727.
KEYWORD
nonn,tabl
AUTHOR
Antti Karttunen, Feb 15 2016
EXTENSIONS
Definition simplified by Antti Karttunen, Mar 11 2024
STATUS
approved
a(n) = A007913(A283477(n)) = A019565(A006068(n)).
+20
8
1, 2, 6, 3, 30, 15, 5, 10, 210, 105, 35, 70, 7, 14, 42, 21, 2310, 1155, 385, 770, 77, 154, 462, 231, 11, 22, 66, 33, 330, 165, 55, 110, 30030, 15015, 5005, 10010, 1001, 2002, 6006, 3003, 143, 286, 858, 429, 4290, 2145, 715, 1430, 13, 26, 78, 39, 390, 195, 65, 130, 2730, 1365, 455, 910, 91, 182, 546, 273, 510510, 255255, 85085, 170170, 17017
OFFSET
0,2
COMMENTS
A squarefree analog of A302783. Each term is either a divisor or a multiple of the next one. In contrast to A302033 at each step the previous term can be multiplied (or divided), not just by a single prime, but possibly by a product of several distinct ones, A019565(A000975(k)). E.g., a(3) = 3, a(4) = 2*5*a(3) = 30. - Antti Karttunen, Apr 17 2018
FORMULA
a(n) = A007913(A283477(n)).
Other identities. For all n >= 0:
A048675(a(n)) = A006068(n).
A046523(a(n)) = A284004(n).
It seems that A001222(a(n)) = A209281(n).
a(n) = A019565(A006068(n)) = A302033(A064707(n)). - Antti Karttunen, Apr 16 2018
MATHEMATICA
Table[Apply[Times, FactorInteger[#] /. {p_, e_} /; e > 0 :> Times @@ (p^Mod[e, 2])] &[Times @@ Map[#1^#2 & @@ # &, FactorInteger[#] /. {p_, e_} /; e == 1 :> {Times @@ Prime@ Range@ PrimePi@ p, e}] &[Times @@ Prime@ Flatten@ Position[#, 1] &@ Reverse@ IntegerDigits[n, 2]]], {n, 0, 52}] (* Michael De Vlieger, Mar 18 2017 *)
PROG
(PARI)
A007913(n) = core(n);
A034386(n) = prod(i=1, primepi(n), prime(i));
A108951(n) = { my(f=factor(n)); prod(i=1, #f~, A034386(f[i, 1])^f[i, 2]) }; \\ From Charles R Greathouse IV, Jun 28 2015
A019565(n) = {my(j, v); factorback(Mat(vector(if(n, #n=vecextract(binary(n), "-1..1")), j, [prime(j), n[j]])~))}; \\ This function from M. F. Hasler
(PARI)
A006068(n)= { my(s=1, ns); while(1, ns = n >> s; if(0==ns, break()); n = bitxor(n, ns); s <<= 1; ); return (n); } \\ From A006068
A284003(n) = A019565(A006068(n)); \\ (and use A019565 from above) - Antti Karttunen, Apr 16 2018
(Scheme) (define (A284003 n) (A007913 (A283477 n)))
KEYWORD
nonn,look
AUTHOR
Antti Karttunen, Mar 18 2017
EXTENSIONS
Name amended with a second formula by Antti Karttunen, Apr 16 2018
STATUS
approved
A permutation of the integers (a fractal sequence): a(n) = A006068(n-1) + 1.
+20
7
1, 2, 4, 3, 8, 7, 5, 6, 16, 15, 13, 14, 9, 10, 12, 11, 32, 31, 29, 30, 25, 26, 28, 27, 17, 18, 20, 19, 24, 23, 21, 22, 64, 63, 61, 62, 57, 58, 60, 59, 49, 50, 52, 51, 56, 55, 53, 54, 33, 34, 36, 35, 40, 39, 37, 38, 48, 47, 45, 46, 41, 42, 44, 43, 128, 127, 125, 126, 121, 122
OFFSET
1,2
COMMENTS
With an initial zero, inverse of the Gray Code (A003188). See also A006068. - Robert G. Wilson v, Jun 22 2014
I suspect the above comment refers to function A105081(n) = 1 + A003188(n - 1), n >= 1. - Antti Karttunen, Feb 15 2016
FORMULA
a(n) = A006068(n-1) + 1, n >= 1. - Philippe Deléham, Apr 29 2005
a(n) = A006068(A268717(n)), composition of related permutations. - Antti Karttunen, Feb 14 2016
a(n) = 1 + Sum_{j=1..n-1} (1/6)*(-3 + (-1)^A007814(j) + 2^(A007814(j) + 3))*(-1)^(A000120(j) + 1). - John Erickson, Oct 18 2018
EXAMPLE
Third nesting gives {1,2,4,3, 8,7,5,6} by means of joining the lists {1,2,4,3} = second nesting and {8,7,6,5} permuted by {1,2,4,3} giving {8,7,5,6}.
MATHEMATICA
Nest[ Join[ #, (Length[ #] + Range[ Length[ #], 1, -1 ])[[ # ]]] &, {1}, 7 ]
GrayCode[n_] := BitXor[n, Floor[n/2]]; t = Array[ GrayCode, 1000, 0]; Table[ Position[ t, n], {n, 0, 100}] // Flatten (* Robert G. Wilson v, Jun 22 2014 *)
PROG
(Scheme) (define (A066194 n) (+ 1 (A006068 (- n 1)))) ;; Antti Karttunen, Feb 14 2016
(Python)
def A066194(n):
k, m = n-1, n-1>>1
while m > 0:
k ^= m
m >>= 1
return k+1 # Chai Wah Wu, Jul 01 2022
CROSSREFS
Inverse: A105081.
KEYWORD
easy,nonn
AUTHOR
Wouter Meeussen, Dec 15 2001
EXTENSIONS
Deléham's formula added to the name by Antti Karttunen, Feb 14 2016
STATUS
approved

Search completed in 0.082 seconds