Sloping Binary Numbers: A New Sequence Related to the Binary Numbers

David Applegate

Internet and Network Systems Research Center

AT&T Shannon Labs

180 Park Avenue Florham Park, NJ 07932–0971

USA

david@research.att.com

Benoit Cloitre 13 rue Pinaigrier

Tours 3700 FRANCE

abmt@wanadoo.fr

Philippe Deléham Lycée Polyvalent des Iles

BP 887 98820 Wé Lifou

NEW CALEDONIA kolotoko@lagoon.nc N. J. A. Sloane^{1}

Internet and Network Systems Research Center

AT&T Shannon Labs

180 Park Avenue Florham Park, NJ 07932–0971

USA njas@research.att.com

1All correspondence should be directed to this author.

Abstract

If the list of binary numbers is read by upward-sloping diagonals, the resulting “sloping binary numbers” 0, 11, 110, 101, 100, 1111, 1010, … (or 0, 3, 6, 5, 4, 15, 10, …) have some surprising properties. We give formulae for the n-th term and the n-th missing term, and discuss a number of related sequences.

1. Introduction

We start by writing the binary expansions of the numbers 0, 1, 2, … in an array:

0 1

1 0
1 1
1 0 0
1 0 1
1 1 0
1 1 1
1 0 0 0
1 0 0 1
⋯

By reading this array along diagonals that slope upwards to the right we obtain the sequence

0, 11, 110, 101, 100, 1111, 1010, 1001, 1000, 1011, …

of sloping binary numbers, which we denote by s(0), s(1), . . .. Written in base 10, s(0), s(1), s(2), … are

0, 3, 6, 5, 4, 15, 10, 9, 8, 11, … (A102370)^{†}.

Our goal is to study those numbers as well as several related sequences. Table 1 shows s(0), …, s(32) both in binary and decimal, together with the corresponding values of (s(n)− n)/2. Not every nonnegative number occurs as an s(n) value: in particular, the numbers 1, 2, 7, 12, 29, 62, 123, 248, 505, … (A102371) never appear. We denote the omitted numbers by t(1), t(2), t(3), . . ..

In Section 2 we state our main theorems, which give formulae and recurrences for s(n) and t(n), as well as for a downward-sloping version d(n). In Section 3 we discuss some further properties of these numbers, namely the trajectories under repeated application of the map n ↦ s(n) (it is interesting that the trajectory of 2, for example, follows a simple rule for at least the first 400 million terms, but eventually this rule breaks down); the fixed points (numbers n such that s(n) = n); the number of terms in the summations in (3) and (13) (two number-theoretic functions that may be of independent interest); and the average order of s(n). In the final section, Section 4, we give two related sequences σ(n) and δ(n) which are permutations of the nonnegative integers, and a second downward-sloping sequence which is obtained by left-adjusting the array of binary numbers.

†Six-digit numbers prefixed by ‘A’ indicate the corresponding entry in [4].

It is worth mentioning that this work has given rise to an unusually large number of new sequences—see the list at the end of this paper. Only the most important of these will be mentioned in the paper. Conversely, we were surprised to find very few points of contact with sequences already present in [4], sequence A034797 being one of the few exceptions.

2. The main theorems

The first theorem gives the basic properties of the sloping binary numbers s(n).

Theorem 2.1. (i) Let n > 0. Then for any m > log_{2} n,

s(n) = 2^{m} − \frac{1}{2} − \frac{1}{2} ∑_{k=0}^{m}(−1)^{⌊^{\frac{n+k}{2^{k}}}⌋}2^{k} .  (1)

(ii) s(n) satisfies the recurrence s(0) = 0 and, for i ≥ 0, 0 ≤ j ≤ 2^{i} − 1,

s(2^{i} + j) = \{ \begin{matrix}2^{i} + s(j) & if j ≠ 2^{i} − i − 1 \\ 3 · 2^{i} + s(j) & if j = 2^{i} − i − 1 . \end{matrix}  (2)

(iii)

s(n) = n + ∑_{{k≥1, \atop n+k ≡ 0 (mod 2^{k})}} 2^{k} .  (3)

(iv) The values of s(n) are distinct, and s(n) ≥ n for all n ≥ 0.

Proof. We first establish some notation. If the binary expansion of a nonnegative number n is

n = a_{0} + a_{1}2 + a_{2}2^{2} + ... + a_{m}2^{m} ,

where a_{k} ∈ {0, 1}, then we call a_{k} the 2^{k}’s bit of n. For future reference we note that

a_{k} = \frac{1 − (−1)^{⌊^{\frac{n}{2^{k}}} ⌋}}{2} , k ≥ 0 ,  (4)

and so

n = ∑_{k=0}^{∞} \frac{1 − (−1)^{⌊^{\frac{n}{2^{k}}} ⌋}}{2} 2^{k} ,  (5)

where the upper limit in the summation can be replaced by ⌊log_{2} n⌋. In Theorem 2.3 we will use the 2’s-complement binary expansion for numbers n < 0. This is obtained by writing the binary expansion of the nonnegative number −(n + 1) as a string beginning with infinitely many 0’s, and replacing all 0’s by 1’s and all 1’s by 0’s. Thus the binary expansion of a negative number begins with infinitely many 1’s (see Table 2 below).

(i) Let L denote the infinite, right-adjusted, array formed from the binary expansions of the nonnegative numbers (as on the left of Table 1), and let R be the corresponding array formed by the binary expansions of s(0), s(1), … (as in the central column of the table). It follows at once from the definition of s(n) that the right-hand columns (the 1’s bits) of L and R agree, the second column from the right in R (the 2’s bits) is obtained by shifting the 2’s column of L upwards by one place, the 4’s column of R is obtained by shifting the 4’s column of L upwards by two places, the 8’s column by three places, and so on.

We also see from Table 1 that while there are 2^{k} vectors u ∈ {0, 1}^{k} in L, there are only 2^{k} − 1 such vectors in R. Exactly one vector u ∈ {0, 1}^{k} is missing from each set of 2^{k}: this is t(k).

Because of the way the columns of L are shifted to form R, we have (compare (5)):

s(n) = ∑_{k=0}^{∞} \frac{1 − (−1)^{⌊^{\frac{n+k}{2^{k}}}⌋}}{2} 2^{k} ,  (6)

where now the upper limit in the summation can be replaced by any number m > log_{2} n. Therefore, for such an m, we have

s(n) = \frac{2^{m+1} − 1}{2} − \frac{1}{2} ∑_{k=0}^{m} (−1)^{⌊^{\frac{n+k}{2^{k}}}⌋} 2^{k} ,

which proves (1).

(ii) We will prove (2) for i ≥ 2, the cases i = 0 and 1 being trivial. Let n = 2^{i} + j. We consider three subcases.

(a) If 2^{i} ≤ n < 2^{i+1} − (i + 1), then the diagonal for n is identical to the diagonal for j, except that the 2^{i}’s bit is 1, so s(n) = 2^{i} + s(j).

(b) If n = 2^{i+1} − (i + 1), then the diagonal for n is identical to the diagonal for j, except that the 2^{i}’s and 2^{i+1}’s bits are 1, so s(n) = 2^{i+1} + 2^{i} + s(j).

(c) If 2^{i+1} − (i + 1) < n < 2^{i+1}, then the diagonal for n is identical to the diagonal for j, except that it has a 0 in the 2^{i}’s bit and a 1 in the 2^{i+1}’s bit, whereas the diagonal for j has a 1 in the 2^{i}’s bit and a 0 in the 2^{i+1}’s bit. Therefore s(n) = 2^{i+1} − 2^{i} + s(j). In each case (2) holds.

(iii) The starred values of n in the first column of Table 1 indicate where the 2^{k}’s bit of s(n) is equal to 1 for the first time. Let p_{k} = 2^{k} − k. Then the 2^{k}’s bit (k ≥ 1) of s(n) is 1, and is the highest order bit that is 1, precisely for n ∈ {p_{k}, p_{k} + 1, …, p_{k+1} − 1}.

The effect of the upwards shift of the columns of L can be expressed in another way. Consider the values (s(n) − n)/2 (see the final column of Table 1). Each such term is a sum. Starting with the empty sum, if n is odd we add 1 to the sum, if n is in the arithmetic progression 2, 6, 10, 14, … we add 2, and in general, for k ≥ 1, if n is in the arithmetic progression p_{k} + i2^{k} (i ≥ 0) we add 2^{k−1}. But n is in this arithmetic progression precisely when n + k ≡ 0 (mod 2^{k}). Thus

\frac{s(n) − n}{2} = ∑_{{k≥1, \atop n+k≡0 ( mod 2^{k})}} 2^{k−1} ,

which proves (3). Equation (3) can also be deduced from (2), using induction on i.

(iv) Equation (3) implies that s(n) ≥ n. It remains to show that the values s(n) are distinct. Suppose n ≠ m. Let 2^{i} be the highest power of 2 which divides n − m. Then n − m = 2^{i} + j2^{i+1}, for some integer j, and

⌊\frac{n + i}{2^{i}}⌋ = ⌊\frac{m + 2^{i} + j2^{i+1} + i}{2^{i}}⌋ = ⌊\frac{m + i}{2^{i}}⌋ + 1 + 2j .

From (6), this means that the coefficients of 2^{i} in the binary expansions of s(n) and s(m) are different, so s(n) ≠ s(m). This completes the proof of (iv) and of the theorem. Remarks. 1. The argument in the final paragraph of the proof shows that if n is not congruent to m mod 2^{k}, then s(n) is not congruent to s(m) mod 2^{k} (since n not congruent to m mod 2^{k} means i ≤ k in that argument). Therefore all 2^{k} congruence classes of n mod 2^{k} correspond to distinct congruence classes of s(n) mod 2^{k}. That is, s(n) is odd if and only if n is odd,

s(n) ends in: if and only if n ends in:
0 0  0 0
0 1  1 1
1 0  1 0
1 1  0 1

respectively,

s(n) ends in: if and only if n ends in:
0 0 0  0 0 0
0 0 1  1 1 1
0 1 0  1 1 0
0 1 1  0 0 1
1 0 0  1 0 0
1 0 1  0 1 1
1 1 0  0 1 0
1 1 1  1 0 1

respectively, and so on. In other words, for each k = 1, 2, …, there is a permutation π_{k} of the 2^{k} binary vectors of length k such that the binary expansion of s(n) ends in u ∈ {0, 1}^{k} if and only if the binary expansion of n ends in π_{k}(u).

2. For the summation in (3), if n ≥ 3, we need only consider values of k ≤ ⌈log_{2} n⌉. Before studying the missing numbers t(n), it is convenient to introduce a downward-

sloping analogue of s(n). If we read the array L by downward-sloping diagonals, we obtain the sequence d(n), n ≥ 0, with initial values 0, 1, 0, 11, 10, 1, 100, 111, 110, 101, 0, 1011, …, or in base 10,

0; 1; 0, 3, 2; 1, 4, 7, 6, 5; 0, 11, 10, 9, 12, 15, 14, 13, 8; 3, 18, 17, …,  (A105033) . (7)

Unlike s(n), d(n) is manifestly not one-to-one. However, there are several similarities between the two sequences.

Theorem 2.2. (i) Let m = ⌊log_{2} n⌋. Then for n > 0,

d(n) = 2^{m} − \frac{1}{2} − \frac{1}{2} ∑_{k=0}^{m}(−1)^{⌊^{\frac{n−k}{2^{k}}}⌋}2^{k} .  (8)

(ii) d(n) satisfies the recurrence d(0) = 0, d(1) = 1 and, for i ≥ 1, −1 ≤ j ≤ 2^{i} − 1,

d(2^{i} + i + j) = \{ \begin{matrix}d(i − 1) & if j = −1 \\ 2^{i} + d(i + j) & if 0 ≤ j ≤ 2^{i} − 1 . \end{matrix}  (9)

(iii)

d(n) = n − ∑_{{1≤k≤log_{2} n, \atop n≡k−1 ( mod 2^{k})}} 2^{k} .  (10)

Proof. The proof is parallel to that of Theorem 2.1 and we omit the details.

The recurrence (9) shows that the d(n) sequence has a natural division into blocks, where the indices of the blocks run from 2^{i} + i − 1 to 2^{i+1} + (i + 1) − 2 (i ≥ 1). The blocks are separated by semicolons in (7).

We can now identify the missing numbers t(n).

Theorem 2.3. (i) For n ≥ 0,

t(n + 1) = 2^{n} − \frac{1}{2} + \frac{1}{2} ∑_{k=0}^{n}(−1)^{⌊^{\frac{n−k}{2^{k}}}⌋}2^{k} .  (11)

(ii) t(n) satisfies the recurrence t(1) = 1, t(2) = 2 and, for i ≥ 1, i ≤ j ≤ 2^{i} + i,

t(2^{i} + j) = \{ \begin{matrix}2^{2^{i}+i} − 2^{i} + t(i) & if j = i \\ 2^{2^{i}+j} − 2^{i} − 2^{j} + t(j) & if i < j ≤ 2^{i} + i . \end{matrix}  (12)

(iii) For n ≥ 1,

t(n) = − n + ∑_{{k≥1, \atop n−k ≡ 0 (mod 2^{k})}} 2^{k} .  (13)

(iv) For n ≥ 1,

t(n) = 2^{n} − 1 − d(n − 1).  (14)

(v) If we define s(n) for all n ∈ ℤ by (3), we have

t(n) = s(−n) for n ≥ 1 .  (15)

Proof. We have arranged these formulae in the same order as those in Theorems 2.1 and 2.2. But it is convenient to prove them in a different order. (iii) Continuing from the proof of Part (iii) of Theorem 2.1, we observe that the missing numbers are missing precisely because s(n) for a starred value of n has the 2^{k} bit equal to 1; that is, the k-th missing number is found by erasing the 2^{k} bit from s(2^{k} − k), or in other words,

t(k) = s(2^{k} − k) − 2^{k}  (k ≥ 1) ,  (16)

from which (13) follows immediately. In the sum in (13), the largest contribution is always from k = n. For the remaining summands, 1 ≤ k ≤ ⌊log_{2} n⌋.

(iv) now follows from (10) and (13), (ii) from (9) and (14), and (v) from (3) and (13). Note that, from (14), t(n) can be obtained by taking the binary expansion of d(n − 1)

(written with no leading zeros) and exchanging 0’s and 1’s. This leads to a second way to interpret s(−n). Let us write the binary expansions of the negative numbers (using the 2’s-complement notation) above the binary expansions of the nonnegative numbers, as in Table 2. If we define s(n) for all n by reading along upward-sloping diagonals, we see that s(−1), s(−2), s(−3), … are 1, 10, 111, 1100, …, or in base 10, the numbers 1, 2, 7, 12, .... That these numbers really are the missing numbers t(1), t(2), t(3), … follows from the fact that reading the upper half of Table 2 along upward-sloping diagonals is the same as reversing the order of the rows in the upper half of the table, exchanging 0’s and 1’s, and reading downwards. That is, s(−n) = 2^{n} − 1 − d(n − 1) = t(n), which we know to be true from (iv) and (v).

(i) Finally, we obtain (11) by considering how the columns in the upper half of Table 2 have been shifted, just as we obtained (1) by considering how the columns in the lower half of the table were shifted. This completes the proof of the theorem. Remarks. 1. Since the values {s(−n) = t(n) : n ≥ 1} are the numbers missing from the sequence {s(n) : n ≥ 0}, s is a bijection from the integers ℤ to the nonnegative integers ℕ. The inverse map s^{−1} is a bijection from ℕ to ℤ, with initial values s^{−1}(0), s^{−1}(1), s^{−1}(2), … given by

\begin{matrix}0, −1, −2, 1, 4, 3, 2, −3, 8, 7, 6, 9, −4, 11, 10, 5, 16, 15, 14, 17, 20, 19, \\ 18, 13, 24, 23, 22, 25, 12, −5, 26, … (A103122) \end{matrix}

2. The periodicity of the columns of Table 2 shows that the permutations π_{k} relating the final k bits of n and s(n) also relate the final k bits of n and t(n).

3. It is worth mentioning the coincidence which led us to discover (13). We considered the sequence

R(k) := s(p_{k}) = 2^{k} − k + ∑_{{l≥1, \atop k ≡ l (mod 2^{l})}} 2^{l} , k ≥ 1  (17)

(the values of s(n) which exceed a new power of 2, see Table 1), which begins 3, 6, 15, 28, 61, 126, … (A103529). Both R(k) and t(k) are just less than powers of 2, and to our surprise it appeared from the numerical data that

2^{k+1} − R(k) = 2^{k} − t(k), k ≥ 1 ,  (18)

taking the values

1, 2, 1, 4, 3, 2, 5, 8, 7, 6, …,  (A103530) ,  (19)

and this coincidence (which is a consequence of Theorem 2.3) suggested (13).

We end this section with two further formulae relating these numbers. They follow easily from the above theorems.

(i) For n ≥ 0 and any j with j ≤ n < 2^{j},

d(n) = 2^{j} − 1 − s(2^{j} − 1 − n) .  (20)

(ii) For n ≥ 0 and any j with 0 ≤ n < 2^{j} − j,

s(n) = 2^{j} − 1 − d(2^{j} − 1 − n) .  (21)

3. Further properties

In this section we discuss some further properties of these sequences.

3.1. Trajectories

Let T_{m} = {m, s(m), s(s(m)), s(s(s(m))), …} denote the trajectory of m under repeated application of the map n ↦ s(n). The initial terms of T_{m} appear to follow simple rules. For example,

T_{1} = 1, 3, 5, 15, 17, 19, 21, 31, 33, 35, 37, 47, …, (A103192) ,

appears to agree with the increasing sequence T̂_{1} of numbers that are congruent to −1, 1, 3 or 5 mod 16 (A103127). In fact these two sequences agree precisely for the first 511 terms:

n T_{1}(n) T̂_{1}(n) Difference
0  1  1  0
1  3  3  0
2  5  5  0
· · · · · · · · ·  ⋯
510 2037 2037  0
511 4095 2047  2048
512 4097 2049  2048
· · · · · · · · ·  ⋯

The explanation for this lies in the following theorem.

Theorem 3.1. For n in any arithmetic progression {aj + b : j ≥ 0}, where a ≥ 1 and b are integers, the values s(n) − n are unbounded.

Proof. Let a = c2^{d} with c odd. For any m such that m ≥ d and 2^{m} > b + d, let k = 2^{m} − b and choose j ≥ 1 so that

cj ≡ −2^{m−d} mod 2^{2^{m}−b−d}

(this has a solution since c is odd). Then for n = aj + b it is easy to check that n + k ≡ 0 (mod 2^{k}), and so s(n) ≥ n + 2^{k}.

This phenomenon is shown more dramatically in T_{2}, which begins

2, 6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 126, 130, 134, … (A103747)

The initial terms match the sequence T̂_{2} defined by

T̂_{2}(16j + i) := 8(16j + i) + ϵ_{i} ,

for j ≥ 0, 0 ≤ i ≤ 15, where ϵ_{0}, …, ϵ_{15} are

2, −2, −6, −10, −14, −18, −22, −26, −30, −34, −38, −42, −46, −50, −54, 6 .

We have checked by computer that the sequences T_{2} and T̂_{2} agree for at least 400 million terms. On the other hand, the above theorem shows that the sequences must eventually disagree. For suppose on the contrary that T_{2}(n) = T̂_{2}(n) for all n, and consider the arithmetic progression 128j + 2, j ≥ 0. These are the values T̂_{2}(16j), and in T̂_{2} are followed by 128j + 6. But the proof of Theorem 3.1 shows that when j = 2^{119} − 1, s(128j + 2) ≥ 128j + 2 + 2^{126} ≠ 128j + 6. So certainly by term n = 8(2^{119} − 1) ≈ 10^{36.72...}, T_{2} and T̂_{2} disagree.

3.2. Fixed points

The fixed points of s(n), that is, the numbers n for which s(n) = n, are observed to be

0, 4, 8, 16, 20, 24, 32, 36, 40, 48, 52, …,  (A104235)  (22)

Dividing by 4 we obtain

0, 1, 2, 4, 5, 6, 8, 9, 10, 12, 13, 14, 16, …,  (A104401)  (23)

which omits the numbers

3, 7, 11, 15, 19, 23, 27, 31, 35, …,  (A103543)  (24)

The latter sequence in fact consists of the numbers of the form 4j + 3 (j ≥ 0), together with

62, 126, 190, 254, 318, 382, 446, 510, 574, 638, …. (A103584)  (25)

The following theorem explains these observations.

Theorem 3.2. s(n) = n if and only if n ≡ 0 (mod 4) and n does not belong to any of the arithmetic progressions

Q_{r} := {2^{4r}j − 4r : j ≥ 1} ,  (26)

for r = 1, 2, . . ..

Proof. These are straightforward verifications using (3), which shows that s(n) > n if and only if n + k ≡ 0 (mod 2^{k}) for some k ≥ 1. From k = 1 and k = 2, we have that if s(n) = n then n ≡ 0 (mod 4). We may exclude k ≥ 3 with k ≢ 0 (mod 4) because such k are subsumed by k = 1 and k = 2. Remark. An examination of (13) shows that we may restrict (26) to r such that t(4r) = 2^{4r} − 4r, since if t(4r) ≠ 2^{4r} − 4r, Q_{r} will be contained in Q_{s} for some s < r.

3.3. The number of terms in the formulae for t(n) and s(n)

While studying the missing numbers t(n), we investigated the number f(n) (say) of terms in the summation in (13), or, equally, in the summation (17) for the record values R(k). That is,

f(n) := #{1 ≤ k ≤ n : k ≡ n mod 2^{k} } ,  (27)

a number-theoretic function which may be of independent interest. The initial values f(1), …, f(32) are

\begin{matrix}1 & 1 & 2 & 1 & 2 & 2 & 2 & 1 & 2 & 2 & 3 & 1 & 2 & 2 & 2 & 1 \\ 2 & 2 & 3 & 2 & 2 & 2 & 2 & 1 & 2 & 2 & 3 & 1 & 2 & 2 & 2 & 1 & ⋯ & (A103318) \end{matrix}

The smallest n such that f(n) = 3 is 11, corresponding to the values k = 1, 3 and 11; and a 4 appears for the first time at f(2059). A search for the first occurrence of f(n) = 5 would be futile, as the following theorem and corollary will show.

Theorem 3.3. f(n) satisfies the recurrence f(1) = 1, and, for i ≥ 0, 1 ≤ j ≤ 2^{i},

f(2^{i} + j) = \{ \begin{matrix}f(j) + 1 & if 1 ≤ j ≤ i \\ f(j) & if i + 1 ≤ j ≤ 2^{i} . \end{matrix}  (28)

Proof. Note that k = n is always a solution to k ≡ n (mod 2^{k}), but there are no other solutions with k > log_{2} n. Suppose first that 1 ≤ j ≤ i. For values of k in the range 1 ≤ k ≤ i, the equation k ≡ 2^{i} + j (mod 2^{k}) is equivalent to k ≡ j (mod 2^{k}), giving f(j) solutions. For k in the range i + 1 ≤ k ≤ n, we get just one further solution, k = n, so f(2^{i} + j) = f(j) + 1. On the other hand, suppose that i + 1 ≤ j ≤ n. We would get f(j) + 1 solutions, as in the previous case, except that some values of k that contribute to f(j) are now lost. The lost values are those k > log_{2}(2^{i} + j), that is, k ≥ i + 1. There is just one such value, namely k = j, and so f(2^{i} + j) = f(j), as claimed.

Corollary. Let g(m) be the minimal value of n such that f(n) = m. Then g(m) satisfies the recurrence g(1) = 1,

g(m + 1) = 2^{g(m)} + g(m), m ≥ 1 ,  (29)

with values

1, 3, 11, 2059, 2^{2059} + 2059, 2^{2^{2059}+2059} + 2^{2059} + 2059, …, (A034797) .

Proof. This is an easy consequence of Theorem 3.3, and we omit the details.

Remark. The earliest reference to the sequence g(m) that we have found is the entry A034797 in [4], due to Joseph L. Shipman, where it arises as the index of the first impartial game of value m, using the natural enumeration of impartial games (cf. [1]). It is always rash to make such statements, especially in view of the connections between games and coding theory described in [2], but there does not seem to be any connection between the present work and the theory of impartial games.

We briefly mention the companion sequence f′(n) (say), giving the number of terms in the summation in (3). The initial values f′(0), f′(1), … are

0, 1, 1, 1, 0, 2, 1, 1, 0, 1, 1, 1, 1, 2, 1, 1, 0, …, (A104234) .

An argument similar to that used to establish Theorem 3.3 shows:

Theorem 3.4. f′(n) satisfies the recurrence f′(0) = 0, f′(1) = 1, and, for i ≥ 1, 0 ≤ j ≤ 2^{i} − 1,

f′(2^{i} + j) = \{ \begin{matrix}f′(j) + 1 & for j = 2^{i} − i − 1 \\ f′(j) & otherwise . \end{matrix}  (30)

Also

f′(2^{n} − n) = f(n) .  (31)

The positions g′(0), g′(1), … where f′(n) = 0, 1, 2, 3, … for the first time are

0, 1, 5, 2037, …, (A105035) .

We have not investigated this function, but these four values suggest the conjecture that g′(m) = 2^{g(m)} − g(m), which is consistent with (31). If so, this would imply that g′(4) = 2^{2059} − 2059. Certainly f′(2^{2059} − 2059) = 4, but is this the earliest occurrence of 4?

3.4. Average order

As the above discussion of trajectories illustrates, the function s(n) for n ≥ 0 is quite irregular. But it is straightforward to compute its average order (cf. [3, §18.2]).

Theorem 3.5. The average order of s(n) is n + O(log n).

The proof is an easy computation from (3), using [3, Eq. (18.2.1)].

4. Related sequences

In this section we describe some related sequences.

4.1. Two permutations of the nonnegative integers

Returning to the standard array of binary numbers, as on the left of Table 1, we define two sequences related to s(n) and d(n) which are actually permutations of the nonnegative integers.

The first sequence, σ(n), n ≥ 0, begins

0; 1; 3, 2; 6, 5, 4, 7; 15, 10, 9, 8, 11, 14, 13, 12; …, (A105027)

with a block structure indicated by semicolons. The initial term is 0. After that, the m-th block (m ≥ 0),

σ(2^{m}), σ(2^{m} + 1), …, σ(2^{m+1} − 1) ,

is constructed by starting at the leading 1-bit of the numbers 2^{m}, …, 2^{m+1} − 1 and reading diagonally upwards and to the right. The m-th block is in fact equal to the terms

s(p_{m}), s(p_{m} + 1), …, s(p_{m+1} − 1), t(m + 1) ,

which relates it to our sequences s(n) and t(n). For example, the third block consists of the numbers 15, 10, 9, 8, 11, 14, 13, 12, ending with t(4) = 12.

On the other hand, if instead we read downwards and to the right, we obtain the sequence δ(n), n ≥ 0, beginning

0; 1; 3, 2; 4, 7, 6, 5; 11, 10, 9, 12, 15, 14, 13, 8; …. (A105025)

We recognize this as being obtained from d(n) by omitting repeated terms (compare (7)). Both {σ(n) : n ≥ 0} and {δ(n) : n ≥ 0} are permutations of the nonnegative integers.

4.2. A second downward-sloping version

We might have begun by left-adjusting the array of binary numbers, so that it looks like

0 1

1 0
1 1
1 0 0
1 0 1
1 1 0
1 1 1
1 0 0 0
1 0 0 1
1 0 1 0
1 0 1 1

⋯

Now if we read by downward-sloping diagonals, we obtain the sequence 0, 10, 110, 101, …, or in decimal,

0, 2, 6, 5, 4, 14, 13, 8, 11, 10, 9, 12, 30, … (A105029) .

This seems less interesting than the previous sequence, and we have not analyzed it in detail. There are no repetitions, and the numbers 2^{m} − 1, m ≥ 1, do not appear.

Further related sequences can be found in the list appended to the end of this paper.

References

[1] J. H. Conway, On Numbers and Games, Academic Press, London, 1976.

[2] J. H. Conway and N. J. A. Sloane, Lexicographic codes: error-correcting codes from game theory, IEEE Trans. Inform. Theory, 32 (1986), 337–348.

[3] G. H. Hardy and E. M. Wright, An Introduction to the Theory of Numbers, Oxford, 5th ed., 1979.

[4] N. J. A. Sloane, The On-Line Encyclopedia of Integer Sequences, published electronically

    at http://www.research.att.com/∼njas/sequences/, 2005.

2000 Mathematics Subject Classification: Primary 11B83; Secondary 11A99, 11B37 . Keywords: binary numbers, integer sequences, permutations of integers.

(Concerned with sequences \underline{A034797} \underline{A102370} \underline{A102371} \underline{A103122} \underline{A103127} \underline{A103185} \underline{A103192}

\underline{A103202} \underline{A103205} \underline{A103318} \underline{A103528} \underline{A103529} \underline{A103530} \underline{A103542} \underline{A103543} \underline{A103581} \underline{A103582}
\underline{A103583} \underline{A103584} \underline{A103585} \underline{A103586} \underline{A103587} \underline{A103588} \underline{A103589} \underline{A103615} \underline{A103621} \underline{A103745}
\underline{A103747} \underline{A103813} \underline{A103842} \underline{A103863} \underline{A104234} \underline{A104235} \underline{A104378} \underline{A104401} \underline{A104403} \underline{A104489}
\underline{A104490} \underline{A104853} \underline{A104893} \underline{A105023} \underline{A105024} \underline{A105025} \underline{A105026} \underline{A105027} \underline{A105028} \underline{A105029}
\underline{A105030} \underline{A105031} \underline{A105032} \underline{A105033} \underline{A105034} \underline{A105035} \underline{A105085} \underline{A105104} \underline{A105108} \underline{A105109}

\underline{A105153} \underline{A105154} \underline{A105158} \underline{A105159} \underline{A105228} \underline{A105229} \underline{A105271} and \underline{A106623}.)

Received May 14 2005; revised version received August 2 2005. Published in Journal of Integer Sequences, August 3 2005.

Return to Journal of Integer Sequences home page.

Table 1: The sloping binary numbers s(n) are obtained by reading the array of binary numbers along upward-sloping diagonals. The table gives s(0), …, s(32) in both base 2 and base 10, as well as the values of (s(n) − n)/2.

n  s(n)  (s(n) − n)/2
0  0  0 0  0
1∗  1  1 1 3  1
2∗  1 0  1 1 0 6  2
3  1 1  1 0 1 5  1
4  1 0 0  1 0 0 4  0
5∗  1 0 1  1 1 1 1 15  5
6  1 1 0  1 0 1 0 10  2
7  1 1 1  1 0 0 1 9  1
8  1 0 0 0  1 0 0 0 8  0
9  1 0 0 1  1 0 1 1 11  1
10  1 0 1 0  1 1 1 0 14  2
11  1 0 1 1  1 1 0 1 13  1
12∗  1 1 0 0 1 1 1 0 0 28  8
13  1 1 0 1 1 0 1 1 1 23  5
14  1 1 1 0 1 0 0 1 0 18  2
15  1 1 1 1 1 0 0 0 1 17  1
16  1 0 0 0 0 1 0 0 0 0 16  0
17  1 0 0 0 1 1 0 0 1 1 19  1
18  1 0 0 1 0 1 0 1 1 0 22  2
19  1 0 0 1 1 1 0 1 0 1 21  1
20  1 0 1 0 0 1 0 1 0 0 20  0
21  1 0 1 0 1 1 1 1 1 1 31  5
22  1 0 1 1 0 1 1 0 1 0 26  2
23  1 0 1 1 1 1 1 0 0 1 25  1
24  1 1 0 0 0 1 1 0 0 0 24  0
25  1 1 0 0 1 1 1 0 1 1 27  1
26  1 1 0 1 0 1 1 1 1 0 30  2
27∗  1 1 0 1 1 1 1 1 1 0 1 61  17
28  1 1 1 0 0 1 0 1 1 0 0 44  8
29  1 1 1 0 1 1 0 0 1 1 1 39  5
30  1 1 1 1 0 1 0 0 0 1 0 34  2
31  1 1 1 1 1 1 0 0 0 0 1 33  1
32 1 0 0 0 0 0 1 0 0 0 0 0 32  0

Table 2: By using 2’s-complement notation for the binary expansion of negative numbers, s(n) can be defined for all n ∈ ℤ. The values {s(n) : n ≤ −1} are the numbers missing from {s(n) : n ≥ 0}.

n  s(n)
−6 ⋯ 1 1 0 1 0 1 1 1 1 1 0 62
−5 ⋯ 1 1 0 1 1 1 1 1 0 1 29
−4 ⋯ 1 1 1 0 0  1 1 0 0 12
−3 ⋯ 1 1 1 0 1  1 1 1 7
−2 ⋯ 1 1 1 1 0  1 0 2
−1 ⋯ 1 1 1 1 1  1 1
0 ⋯ 0 0 0 0 0  0 0
1 ⋯ 0 0 0 0 1  1 1 3
2 ⋯ 0 0 0 1 0  1 1 0 6
3 ⋯ 0 0 0 1 1  1 0 1 5
4 ⋯ 0 0 1 0 0  1 0 0 4
5 ⋯ 0 0 1 0 1  1 1 1 1 15
6 ⋯ 0 0 1 1 0  1 0 1 0 10