27
Numeration Systems S. E. Payne 2010 Contents 1 General Numeration Systems 2 2 Greedy Representations 3 3 Combinatorial Numeration 13 4 Numeration with forbidden substrings 14 5 The dominant root of the recurrence relation 16 6 Initial conditions 17 7 Numeration system corresponding to an anti-Lyndon word 19 8 The lazy expression 23 8.1 Example .............................. 23 8.2 Example .............................. 24 9 The Non-anti-Lyndon case 25 10 Fibonacci Nim – Just for fun this time! 26 1

Numeration Systems - UC Denvermferrara/seminar/F2010/Numeration.pdf · 1 General Numeration Systems Let bbe an integer greater than 1. It is well known that each positive integer

Embed Size (px)

Citation preview

Numeration Systems

S. E. Payne

2010

Contents

1 General Numeration Systems 2

2 Greedy Representations 3

3 Combinatorial Numeration 13

4 Numeration with forbidden substrings 14

5 The dominant root of the recurrence relation 16

6 Initial conditions 17

7 Numeration system corresponding to an anti-Lyndon word 19

8 The lazy expression 238.1 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238.2 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

9 The Non-anti-Lyndon case 25

10 Fibonacci Nim – Just for fun this time! 26

1

1 General Numeration Systems

Let b be an integer greater than 1. It is well known that each positive integerN has a unique representation of the form

N = b0 + b1b+ b2b2 + · · ·+ brb

r, where 0 ≤ bi ≤ b− 1, 0 ≤ i ≤ r. (1)

The proof amounts to showing that the br+1 distinct expressions of theform in Eq. 1 give br+1 distinct numbers, and these numbers range from 0up through br+1 − 1.

A second useful numeration system is the following. Define the Fibonaccinumbers in the slightly uncommon way: F0 = 1, F1 = 2, and Fn = Fn−1 +Fn−2. (This is uncommon because the usual sequence starts with two termsequal to 1.) If dr, dr−1, . . . , d1, d0 is a binary string of length r + 1, put

N(drdr−1 · · · d0) = drFr + dr−1Fr−1 + · · ·+ d1F1 + d0F0. (2)

This version of the Fibonacci sequence {Fn}∞n=0 has the following prop-erties.

Theorem 1.1. Fibonacci Numbers

(i) For 0 ≤ i < j ∈ Z, Fi < Fj, so {Fn}∞n=0 is strictly increasing.

(ii) 2 · F0 = F1, but for n ≥ 1 we have 2 · Fn > Fn+1.

(iii) Fn is the number of binary strings of length n not containing 11 as asubstring.

Proof. F0 counts the empty string. F1 counts the two strings 0, 1.In general for n ≥ 2, the number of strings of length n having nosubstring 11 is the number Fn−2 of binary strings x1 · · ·xn−201 havingno substring 11, plus the number Fn−1 of binary strings x1 · · ·xn−10having no substring 11.

(iv) Fn+1 − 1 is the largest integer N corresponding to a binary string oflength at most n+ 1 and not having 11 as a subword.

2

Proof. It is fairly easy to see that the largest integer corresponding toa binary string of length at most n + 1 that does not have 11 as asubword must have a binary string of the form 101010 · · · . It is easyto check that F2 + F0 = F3 − 1 and F3 + F1 = F4 − 1. Suppose thatF2(k−1) +F2(k−2) + · · ·+F0 = F2k−1−1. Then F2k +F2(k−1) + · · ·+F0 =F2k + F2k−1 − 1 = F2k+1 − 1. It is similarly easy to show by inductionthat F2k+1 + F2k−1 + · · ·+ F1 = F2(k+1) − 1 for k ≥ 1. This shows that

Fn+1 − 1 = Fn + Fn−2 + Fn−4 + · · ·

is the largest N corresponding to a binary string of length at most n+1and not having 11 as a subword.

(v) (Zeckendorf 1939) Each positive integer may be represented in a uniqueway as the sum of nonconsecutive Fibonacci numbers.

Proof. Let N be any one of the Fn+1 integers satisfying 0 ≤ N ≤Fn+1 − 1. If N = 0, N corresponds to the empty binary word, whichdoes not have 11 as a subword. For N > 0, let m be the largest integersuch that Fm ≤ N , i.e., Fm ≤ N < Fm+1. Since 2Fm ≥ Fm−1 + Fm =Fm+1 > N , it follows that if kFm ≤ N , then k = 0 or k = 1. ThenFm−1 > N − Fm. Now choose the largest m′ such that Fm′ ≤ N − Fm,i.e., Fm′ ≤ N < Fm′+1. We just showed that m′ ≤ m − 2. Continuingin this fashion we see that each positive integer N has at least onerepresentation as a sum of nonconsecutive Fibonacci numbers. On theother hand, there are exactly Fn+1− 1 positive integers less than Fn+1,and exactly Fn+1 − 1 nonzero binary sequences of length n + 1 nothaving a subword equal to 11. It follows that each integer has a uniquerepresentation as a sum of nonconsecutive Fibonacci numbers.

2 Greedy Representations

In this section we present two results of Fraenkel [1]. To start, let 1 =u0 < u1 < u2 < · · · be a finite or infinite sequence of integers. Let N beany nonnegative integer, and suppose that un is the largest number in thesequence not exceeding N (except that we let n = 0 if N = 0). Dividing N

3

by un and iterating gives

N = dnun + rn, 0 ≤ rn < un

rn = dn−1un−1 + rn−1, 0 ≤ rn−1 < un−1

rn−1 = dn−2un−2 + rn−2, 0 ≤ rn−2 < un−2

......

ri+1 = diui + ri, 0 ≤ ri < ui

......

r2 = d1u1 + r1, 0 ≤ r1 < u1

r1 = d0u0.

Collecting terms we get

N = dnun + dn−1un−1 + · · ·+ d0u0 (di ≥ 0, i ≥ 0).

This is the greedy representation of N in the numeration system S ={u0, u1, u2, . . .}. The process above shows that every nonnegative integerhas a (unique greedy) representation in the system S. Note that

ri+1 = diui + di−1ui−1 + · · ·+ d0u0 < ui+1 (i ≥ 0).

Conversely, if N =∑n

i=0 diui, where

diui + di−1ui−1 + · · ·+ d0u0 < ui+1 (i ≥ 0), (3)

then∑n

i=0 diui is the unique greedy representation of N by S, as shown inthe following theorem:

Theorem 2.1. Let 1 = u0 < u1 < u2 < · · · be any finite or infinite sequenceof integers. Each nonnegative integer N has precisely one representation inthe system S = {u0, u1, . . .} of the form N =

∑ni=0 diui, where the di are

nonnegative integers satisfying Eq. 3.

Proof. It remains only to establish uniqueness. Suppose that N has tworepresentations:

N = cnun + · · ·+ c0u0 = dnun + · · · d0u0,

4

where the digits cj and dj are nonnegative integers and satisfy Eq. 3. Let ibe the largest integer such that ci+1 6= di+1, say ci+1 > di+1 (and cj = dj for0 ≤ j ≤ i). Then

ui+1 ≤ (ci+1 − di+1)ui+1 = (di − ci)ui + · · ·+ (d0 − c0)u0

≤ diui + · · ·+ d0u0 < ui+1,

an impossibility.The argument given above shows that each nonnegative integer N has at

least one representation satisfying Eq. 3, hence the proof is complete.

Note that Eq. 3 implies

0 ≤ di <ui+1

ui

(i ≥ 0). (4)

Sometimes Eq. 4 implies Eq. 3, and sometimes it does not. When theui are defined recursively, the situation depends on the length of the re-currence relation. If the recurrence relation contains only one term (viz.,un = b(n)un−1), then Eq. 4 does imply Eq. 3. We see this as follows. Assumethat Eq. 4 does hold. Then d0u0 < b(1)u0 = u1, so Eq. 3 holds for i = 0. Asan induction hypothesis assume that Eq. 4 holds for i = n− 1. Then

dnun + dn−1un−1 + · · ·+ d0u0 ≤ (b(n+1) − 1)un + dn−1un−1 + · · ·+ d0u0

< (b(n+1) − 1)un + un = b(n+1)un = un+1.

Hence for many of the standard numeration systems (e.g., b-ary repre-sentations for b > 1) the condition in Eq. 4 is a necessary and sufficientcondition for unique representation. But for systems in which the recurrencerelation contains more than one term, Eq. 4 is only a necessary condition,not a sufficient one. This will become clear from the deeper theorem below.

For m ≥ 1 let b1 = b(n)1 be a function of n, and b2, . . . , bm be constant

where b1, b2, . . . , bm are integers satisfying

1 ≤ bm ≤ · · · ≤ b2 ≤ b(n)1 .

Let u−m+1, u−m+2, . . . , u−1 be fixed nonnegative integers (in case m > 1),and let

u0 = 1, un = b(n)1 un−1 + b2un−2 + · · ·+ bmun−m (n ≥ 1), (5)

5

be an increasing sequence of positive integers.Suppose that N =

∑nj=0 djuj is the unique (greedy) representation sat-

isfying Eq. 3 of an integer N in the system S = {u0, u1, . . .}, where the ui

are defined by Eq. 5. Recall that this implies that {ui}∞n=0 must also satisfy

Eq. 4. If m = 1, then Eq. 4 implies di < ui+1/ui = b(i+1)1 (i ≥ 0). If m > 1,

then

di < (b(i+1)1 ui + b2ui−1 + · · ·+ bmui−m+1)/ui

≤ bi+1)1 + (b

(i)1 ui−1 + b2ui−2 + · · ·+ bmui−m/ui = b

(i+1)1 + 1 (i ≥ 1).

=⇒ di ≤ b(i+1)1 (if i ≥ 1 and m > 1).

By Eq. 4, d0 < u1, so that by putting n = 1 in Eq. 5 we have d0 < b(1)1 +∑m

j=2 bju1−j when m > 1. We record this as follows:0 ≤ di < b

(i+1)1 ( if i ≥ 0 and m = 1);

0 ≤ di ≤ b(i+1)1 ( if i ≥ 1 and m > 1);

0 ≤ d0 < b(1)1 +

∑mj=2 bju1−j (if m > 1).

(6)

Note: The condition of Eq. 6 is necessary for uniqueness of the repre-sentation N in the system S, but it is not necessarily sufficient. Fraenkel[1]gives the following “full” explanation of the situation.

Theorem 2.2. Let S = {ui} be a sequence of the form in Eq. 5. Eachnonnegative integer N has precisely one representation in S of the form N =∑n

i=0 diui where the digits di are nonnegative integers satisfying the following(two-fold) condition:

(i) Let k ≥ m− 1. For any j satisfying 0 ≤ j ≤ m− 2, if

(dk, dk−1, . . . , dk−j+1) = (b(k+1)1 , b2, . . . , bj), (7)

then dk−j ≤ bj+1; and if Eq. 7 holds with j = m−1, then dk−m+1 < bm.

In case m = 1 and j = 0, this means 0 ≤ dk < b(k+1)1 for k ≥ 0.

(ii) Let 0 ≤ k < m − 1. If Eq. 7 holds for some j satisfying 0 ≤ j ≤k − 1, then dk−j ≤ bj+1; and if Eq. 7 holds with j = k, then d0 <∑m

i=k+1 biuk+1−i.

6

Before starting into the proof of Theorem 2.2 we look at an example andthen consider a little more carefully just what the theorem is saying.

Example Consider the numeration system defined by m = 3, u−2 =0, u−1 = u0 = 1, un = 3un−1 + 2un−2 + un−3 (n ≥ 1). Thus b1 = 3, b2 =2, b3 = 1, and S = {1, 5, 18, 65, 236, . . .}. By Eq. 6 the digit bounds are0 ≤ di ≤ 3 for i ≥ 1, and 0 ≤ d0 ≤ 4.

First consider subcondition (i). Let k ≥ m−1 = 2 and 0 ≤ j ≤ m−1 = 2.In fact j = 0 gives a vacuous condition. If j = 1 and k ≥ 2, then dk = b1 = 3implies dk−1 ≤ b2 = 2. If j = m − 1 = 2, then (dk, dk−1) = (b1, b2) = (3, 2)implies that dk−2 < b3 = 1, so dk−2 = 0. Second, consider subcondition (ii).Suppose 0 ≤ k < m − 1 = 2. If for some j with 0 ≤ j ≤ k − 1 we have(dk, dk−1, . . . , dk−j+1) = (b1, b2, . . . , bj), then dk−j ≤ bj+1. If (for j = k) wehave (dk, . . . , d1) = (b1, . . . , bk), then we have d0 <

∑mi=k+1 biuk+1−i. The

following cases turn up. (k, j) = (0, 0) : =⇒ d0 < b1u0 + b2u−1 + b3u−2 = 5,so d0 ≤ 4, nothing new. (k, j) = (1, 0). This is a vacuous case. (k, j) = (1, 1).Here (d1 = b1 = 3 implies d0 <

∑3i=2 biu2−i = b2u0 + b3u−1 = 3, so d0 ≤ 2.

So putting this together we have the following for this specific example:

dk = 3 fork ≥ 1 =⇒ dk−1 ≤ 2;

(dk, dk−1) = (3, 2) for k ≥ 2 =⇒ dk−2 = 0.

We practice writing some integers in the system S using representationssatisfying the conditions of Theorem 2.2.

Case 1. N = 18. Clearly we could write 18 = 3 · 1 + 3 · 5, i.e., 1810 = 33S,but in this case d1 = 3 would force d0 < 3. Hence the “correct” representationis 1810 = 100S.

Case 2. N = 36. Clearly 200S = 3610, and this representation satisfiesthe conditions of Theorem 2.2. It is easy to see that we must have d2 ≥ 1(since d0 ≤ 4 and di ≤ 3 for i ≥ 1). Then d2 = 1 quickly forces d1 = d0 = 3,but d1 = 3 forces d0 ≤ 2. So 200S is the only acceptable representation.

Case 3. N = 65. If we try to get by using only u0, u1 and u2, we arequickly lead to 65 = 321S. But (d2, d1) = (3, 2) forces d0 = 0. so the onlyacceptable representation is 1000S.

Case 4. N = 236. Clearly 23610 = 10000S satisfies the conditions ofTheorem 2.2. If we try to get by using only u0, u1, u2 and u3, using d0 ≤ 4and di ≤ 3 for i ≥ 1, we are quickly led to 23610 = 3210S, but (d3, d2) = (3, 2)should force d1 = 0. Hence 10000S is the only acceptable representation.

7

Case 5. N = 235. Just using the conditions d0 ≤ 4 and di ≤ 3 for i ≥ 1we quickly see that d3 = 3. So d2 ≤ 2. Clearly d2 = 1 is too small for u1 andu0 to carry the rest of the weight. So d2 = 2. Then (d3, d2) = (3, 2) impliesd1 = 0, leaving d0 = 4. So the unique representation satisfying the conditionof Theorem 2.2 is 235 = 3204S.

Note that the conditions (i) and (ii) of Theorem 2.2 are both concernedwith blocks of consecutive digits. They differ only in the location of theseblocks: in (i) the right-hand digit dk−m+1 of a block of maximal size m is insome position k−m+ 1 ≥ 0. Such a block may appear anywhere within thedigit sequence. If it is “shifted right” until its rightmost digit goes beyondposition 0, we get a truncated block: the right-hand digit of the truncatedblock (of smaller maximal size k + 1 < m) occupies position 0. This is thesituation considered in (ii).

Next we want to see that the condition of Eq. 6 is implied by the conditionof the Theorem. For m = 1, the first part of (i) is empty and (ii) is empty.

The second part of (i) must be interpreted to say that 0 ≤ dk < b(k+1)1 for

k ≥ 0, so that for m = 1 the condition of Theorem 2.2 is equivalent toEq. 6. Now suppose that m > 1 and put j = 0 in the first part of (i). Eq. 7

holds vacuously and the conclusion must be interpreted to say dk ≤ b(k+1)1

for k ≥ 1, i.e., the first inequality in eq. 6 holds. Put j = k = 0 in the secondpart of (ii). Then d0 <

∑mi=1 biu1−i.

To motivate further the somewhat curious condition of Theorem 2.2, con-sider the violation of (i) in the special case when Eq. 7 holds for j = m−1 butdk−m+1 ≥ bm. Then the integer M =

∑ki=k−m+1 diui has two representations:

M = b(k+1)1 uk +

k−1∑i=k−m+2

bk−i+1ui + dk−m+1uk−m+1,

andM = uk+1 + (dk−m+1 − bm)uk−m+1.

The latter, which violates Eq. 3, follows from the former representation usingthe recurrence Eq. 5. (After Lemma 2.3 below, it may be seen that also theother violations of the condition of Theorem 2.2 boil down to the case ofa sequence of digits sufficiently large, so that a number has an additionalrepresentation, violating Eq. 3, obtained by using the recurrence Eq. 5.

Proof. (of Theorem 2.2) We start by showing that a representation satisfyingthe condition of the Theorem always exists. Let N be any nonnegative

8

integer and let N =∑n

i=0 diui be its (greedy) representation (so Eqs. 3 and4 hold). Suppose that (i) does not hold. First suppose that there is some jsatisfying 1 ≤ j ≤ m− 2 for which Eq. 7 holds (i.e., (dk, dk−1, . . . , dk−j+1) =

(b(k+1)1 , b2, . . . , bj)) but dk−j > bj+1 (so dk−j ≥ bj+1 + 1 =⇒ dk−juk−j ≥

(bj+1 + 1)uk−j). Then

k∑i=0

diui ≥k∑

i=k−j

diui ≥ b(k+1)1 uk +

j+1∑i=2

biuk+1−i + uk−j

= b(k+1)1 uk +

j+1∑i=2

biuk+1−i + b(k−j)1 uk−j−1 +

m∑i=2

biuk−j−i

≥ b(k+1)1 uk +

j+1∑i=2

biuk+1−i + b(k−j)1 uk−j−1 +

m−j−1∑i=2

biuk−j−i

≥ b(k+1)1 uk +

j+1∑i=2

biuk+1−i + bj+2uk−j−1 +

m−j−1∑i=2

bj+1+iuk−j−i

= b(k+1)1 uk +

m∑i=2

biuk+1−i = uk+1,

violating Eq. 3.Secondly, suppose that Eq. 7 holds with j = m − 1 but dk−m+1 ≥ bm.

This means

(dk, dk−1, . . . , dk−(m−2)) = (b(k+1)1 , b2, . . . , bm−1) and dk−m+1 ≥ bm.

Hence we have

k∑i=0

diui =m−2∑j=0

dk−juk−j +k∑

j=m−1

dk−juk−j

= b(k+1)1 uk +

m−2∑j=1

bj+1uk−j + dk−m+1uk−m+1 +k∑

j=m

dk−juk−j

≥ b(k+1)1 uk +

m−2∑j=1

bj+1uk−j + bmuk−m+1

= b(k+1)1 uk +

m∑j=2

bjuk+1−j = uk+1.

9

Then∑k

i=0 diui ≥ uk+1 contradicts Eq. 3, which must hold for the greedyrepresentation. Note that with m = 1 and j = 0 this violation of (i) means

dkuk ≥ b(k+1)1 uk. But k ≥ 0 means uk > 0, so this means dk ≥ b

(k+1)1 ,

contradicting the top row of Eq. 6.

Now suppose that (ii) does not hold. First suppose that 0 ≤ k < m− 1.Suppose there is a j satisfying 0 ≤ j ≤ k − 1 for which dk−j > bj+1 , so

dk−j ≥ bj+1 + 1, and (dk, dk−1, . . . , dk−j+1) = (b(k+1)1 , b2, . . . , bj). (Note that

in this case 0 ≤ j ≤ k − 1 ≤ m− 3.)

uk+1 > dkuk + · · ·+ dk−(j−1)uk−(j−1) + dk−juk−j +

k−j−1∑i=0

diui

≥ b(k+1)1 uk + · · ·+ bjuk+1−j + bj+1uk−j + uk−j

= b(k+1)1 uk + · · ·+ bj+1uk−j + b

(k−j)1 uk−j−1 + · · ·+ bm−(k−j)u2k−2j−m

+ · · ·+ bmuk−j−m

≥ b(k+1)1 uk + · · ·+ bj+1uk−j + bj+2uk−j−1 + · · · bmuk+1−m = uk+1.

Here we used br ≥ br+j+1.Finally, suppose that (ii) fails in the following way: Eq. 7 holds with j = k

and d0 ≥∑m

i=k+1 biuk+1−i. So (dk, dk−1, . . . , d1) = (b(k+1)1 , b2, . . . , bk). (Recall

that u0 = 1.)Then

uk+1 > dkuk + · · ·+ d0u0 = b(k+1)1 uk + b2uk−1 + · · ·+ bku1 + d0u0

≥ b(k+1)1 uk + · · · bku1 + bk+1u0 + · · ·+ bmuk+1−m = uk+1, an impossibility.

At this point we have shown that the greedy algorithm always providesa representation of the desired kind. To show that there is only one suchrepresentation we first give a lemma which is interesting in its own right.

Lemma 2.3. To start with let t be any nonnegative integer and write t+1 =qm+ r with 0 ≤ r < m where m is the m of Theorem 2.2.

(i) Consider the following representation of a nonnegative integer f(t) in

10

the system S of Eq. 5:

f(t) = b(t+1)1 ut + b2ut−1 + · · ·+ bm−1ut+2−m + (bm − 1)ut+1−m

+ b(t+1−m)1 ut−m + b2ut−1−m + · · · bm−1ut+2−2m + (bm − 1)ut+1−2m

+ · · ·+ b(t+1−qm)1 ut−(q−1)m

+ b2ut−1−(q−1)m + · · ·+ bm−1ut+2−qm + (bm − 1)ut+1−qm

+ b(t+1−qm)1 ut−qm + b2ut−1−qm + · · ·+ br−1ut+2−r−qm + d0u0,

d0 = bm − 1 (if r = 0); d0 =∑m−r

j=0 br+ju−j − 1 (if r > 0). Thenf(t) = ut+1 − 1.

(ii) Let N1 =∑n

i=0 diui and N2 =∑`

i=0 ciui +∑n

i=`+1 diui, where c` < d`,for ` any integer in [0, n], and the ci, di are arbitrary digits satisfyingthe condition of Theorem 2.2. Then N2 < N1.

Part (i) of the lemma states that f(t) is the analog of 999...9 (t+1 9’s) inthe decimal system. Part (ii) states that if two representations differ in the`th position, being identical to the left of it, then the representation with thelarger digit in position ` corresponds to the larger number. This is, of course,trivial for the decimal system. In the present more general case, however,this result is not a priori clear. Suppose, for example, that (for m > 3) threeconsecutive digits of some representation of some number satisfy

(dk, dk−1, dk−2) = (b(k+1)1 , b2, b3).

By the condition of Theorem 2.2 these digits are maximal, in the sense thatnone of them can be replaced by a larger one without violating the condition.However, replacing, say, dk−1 = b2 by b2 − 1 enables replacing bk−2 = b3 by

b(k−1)1 , which may be considerably larger than b3. Part (ii) of the Lemma

states that such a replacement yields a smaller, not a larger number as mightbe expected.

Proof. It is straightforward to verify the following two facts:

(a) The representation of f(t) as given in (i) satisfies the condition of The-orem 2.2.

(b) Increasing any digit of this representation while leaving the digits toits left unchanged results in a representation violating the condition ofTheorem 2.2.

11

For the proof of (i) note that Eq. 5 implies directly that

f(t) = (ut+1 − ut+1−m) + (ut+1−m − ut+1−2m) + · · ·+ (ut+1−(q−1)m − ut+1−qm) + (ut+1−qm − 1)

= ut+1 − 1.

Next, we prove (ii) by induction on the “digital position” `. The result isclear for ` = 0. Suppose that the result holds for any two representationssatisfying the condition of theorem 2.2 whose leftmost differing digits are insome position ≤ `. We have to show that, given any representation N1 =∑n

i=0 diui, we have N3 < N1, where

N3 =n∑

i=`+2

diui +`+1∑i=0

giui, g`+1 < di+1,

and the representations of N1 and N3 satisfy the condition of Theorem 2.2.Subtracting, we get

N1 −N3 = (d`+1 − g`+1)u`+1 +∑i=0

(di − gi)ui ≥ ui+1 −∑i=0

giui.

Let g(`) =∑`

i=0 giui. If the representatons of f(`) =∑`

i=0 fiui as givenin (i) of the lemma (with t replaced by `) and g(`) disagree, then the leftmostdisagreement occurs in position k for some k ∈ [0, `], that is, fk 6= gk, butfi = gi for k < i ≤ `. Since the representation g(`) =

∑`i=0 giui satisfies

the condition of Theorem 2.2, fact (b) implies gk < fk. by our inductionhypothesis we thus have g(`) ≤ f(`). Since by (i) f(`) = u`+1 − 1, we musthave N1 −N3 ≥ 1; that is N3 < N1.

We now resume the proof of Theorem 2.2. Let N =∑n

kiui be a repre-

sentation satisfying the condition of Theorem 2.2. If the representations off(n) and N are different, then fact (b) implies dk < fk for some k ∈ [0, n].By (ii) and (i) of Lemma 2.3, we thus have N ≤ f(n) < un+1, so inequal-ity Eq. 3 is satisfied. Hence the representation

∑ni=0 diui of N is unique by

Theorem 2.1.

12

3 Combinatorial Numeration

Theorem 3.1. Fix a positive integer k. Then each nonnegative integer nhas a unique representation of k terms of the form

n =

(b11

)+

(b22

)+ · · ·+

(bkk

),

in which the combinatorial digits bi are subject to

0 ≤ b1 < b2 < b3 < · · · < bk.

The combinatorial digits bi of n are found recursively as follows:bk is the greatest integer such that

(bk

k

)≤ n,

bk−1 is the greatest integer such that(

bk−1

k−1

)≤ n−

(bk

k

),

...br is the greatest integer such that

(br

r

)≤ n−

∑kj=r+1

(bj

j

),

...b1 is the greatest integer such that b1 ≤ n−

∑kj=2

(bj

j

).

Proof. It should be clear that the greedy algorithm given above to define thebj does give n =

(b11

)+(

b22

)+ · · · +

(bk

k

), for some nonnegative values of the

bj. It will take some work to show that 0 ≤ b1 < b2 < b3 < · · · < bk and thatsuch a representation is unique. Recall the well-known identity

n∑j=0

(r + j

j

)=

(r + n+ 1

n

). (8)

Suppose for now that this has been shown and let

n =

(b11

)+

(b22

)+ · · ·+

(bkk

)be the representation obtained by the greedy algorithm, and let

n =

(a1

1

)+

(a2

2

)+ · · ·+

(ak

k

)

13

be any other representation satisfying 0 ≤ a1 < a2 < · · · < ak < bk. Clearlybk has the largest possible value in any such representation of n. Then(a1

1

)+

(a2

2

)+ · · ·+

(ak

k

)≤

k∑j=1

(ak − (k − j)

j

)=

(ak + 1

k

)− 1 <

(bkk

).

Here we used the equality in Eq. 8. This shows that if there is a representationsatisfying the conditions of the theorem, it must be unique. We now just haveto show that the greedy algorithm gives such a representation.

So suppose that the greedy algorithm gives

n =

(b11

)+

(b22

)+ · · ·+

(bkk

).

This means that bk is the largest integer such that(

bk

k

)≤ n. Suppose that

bk−1 ≥ bk. Then

n ≥(bk−1

k − 1

)+

(bkk

)≥(

bkk − 1

)+

(bkk

)=

(bk + 1

k

),

which is a contradiction. The same argument works at each stage for bk−2

down to b1, so that indeed 0 ≤ b1 < b2 < · · · < bk as desired.

The article [1] goes on to study several types of numeration systems andto hint at uses of them for solving a variety of problems. However, we nowturn to a study of the results in [3].

4 Numeration with forbidden substrings

Let U = {un}n≥0 be an increasing sequence of natural numbers starting withu0 = 1. Also, from now on we assume that U is defined by a linear recurrenceof the form

un =m∑

`=1

a`un−` + un−m, 0 ≤ ai ∈ Z, 1 ≤ i ≤ m. (9)

So all the information about a sequence U is encoded in the word a =(a1, a2, . . . , am) = a1a2 . . . am: the coefficients of the order m recurrence are

14

a1, a2, . . . , am−1, am + 1. Later we will give the appropriate initial terms forcounting words with specific forbidden substrings.

Without loss of generality we ignore the case in which a is periodic, i.e.,there exists a non-empty word b and an exponent s > 1 for which a = bs. Ifa = bs, the recurrence defined by a is equivalent to that defined by b.

Given a sequence as above, we may associate a natural number witheach finite word in the alphabet N ∪ {0} as follows. Denote the word byw = (dk, dk−1, . . . , d0) = dkdk−1 . . . d0. The number

∑ki=0 diui corresponding,

in this base, to the word w will be denoted by N(w). If dk 6= 0, the word w isa called a U -representation, or simply a representation, for the number N =N(w). As a consequence, the number 0 is represented by the empty word ε.We shall use the words ‘(sub)word’ and ‘(sub)string” interchangeably, andall our subwords will be contiguous, i.e., u is a subword of w only if there arepossibly empty words a and b such that w = aub.

We saw in Section 2 that the greedy algorithm gives a uniquely definedrepresentation of N in the system U characterized by

N =n∑

i=0

diui withi∑

j=0

djuj < ui+1 (i ≥ 0).

The greedy U -representation of N will be denoted by 〈N〉U .

A word a = (a1, a2, . . . , am) = a1a2 · · · am is said to be anti-Lyndonprovided it is greater than each of its other cyclic shifts. So 312 and 3231are anti-Lyndon, but 2131 and 3131 are not. In addition to the usual lex-icographic order on words (denoted by “ < ”) we will use an order calledLenLex denoted �. Specifically, let v, w be words in an alphabet overwhich a total order “ < ” is defined which induces a lexicographic order onthe words. Then w � v if `(w) > `(v) or if `(w) = `(v) and w > v in thelexicographic order.

Given a sequence U , we are interested in the set of (words that are)greedy U -representations for the natural numbers. This set is denoted L(U).Let a = a1a2 · · · am be any given anti-Lyndon word. Let Fa denote the setof words of length at most m that are lexicographically greater than a. Aword is called Fa-free provided it contains no substrings belonging to Fa, i.e.,provided each of its substrings is lexicographically less than or equal to a.

In practice we use as our alphabet the set {0, 1, . . . , a1}. For example, ifthe alphabet is A = {0, 1, 2, 3}, if a = 312, the Fa-free words are the wordsnot containing as substrings the strings 32, 33 and 313.

15

The word w = aka1 . . . ar (where ak is the word consisting of a = a1 . . . am

repeated k times) is the lexicographically largest Fa-free word of its length.Indeed, w is Fa-free and any lexicographically larger word of the same lengthhas a prefix aha1 . . . as in common with w, followed by a digit b greater thanas+1: so a1 . . . asb is in Fa.

Recall that the greedy expressions of natural numbers in Fibonacci baseare exactly the binary words beginning with “1” and with no “11” substring,that is, the Fa-free words for a = 10 (and beginning with “1”). Generalizingthe fact that, conversely, the n-th Fibonacci number enumerates the binarywords beginning with “1” without “11” of length up to n, or equivalently,the n-th Fibonacci number enumerates all the binary words without “11”,regardless of their leftmost digit, of length exactly n, we shall see that for animportant class of recurrences, the n-th term un counts the Fa-free words oflength n.

5 The dominant root of the recurrence rela-

tion

The sequences U = {un} with which we are dealing arise from recurrences ofthe form

un = b1un−1 + · · ·+ bm−1un−m+1 + bmun−m

with nonnegative coefficients. The characteristic polynomials of these recur-rences are of the form

p(x) = xm − b1xm−1 − · · · − bm−1x− bm

with bi ≥ 0 and bm 6= 0. Such polynomials are called nonnegative. (SeeChapter 5 of [2] for these ideas and results.) A dominant root is a root ofthe characteristic polynomial having largest modulus.

A useful result is given by the following.

Theorem 5.1. Let un = b1un−1 + · · ·+bm−1un−m+1 +bmun−m be a recurrencesuch that b1 ≥ bi ≥ 0 for 2 ≤ i ≤ m, and bm 6= 0. Let p(x) = xm −b1x

m−1 − · · · − bm−1x − bm be its characteristic polynomial. Then p has aunique dominant root and this root lies in (b1, b1 + 1).

Proof. We start by showing that p(b1) < 0.

p(b1) = bm1 − b1bm−11 − · · · − bm−1b1 − bm,

16

where the first wo terms cancel out and the other ones are negative or zero.Next we show p(b1 + 1 ≥ 1. This proof proceeds by induction on m. If

m = 1, the p(x) = x − b1, so p(b1 + 1) = (b1 + 1) − b1 ≥ 1. Suppose m > 1the result is true for m− 1. Keep in mind that b1 ≥ bi for i > 1 both for thepolynomial of degree m and the polynomial of degree m− 1 in the inductivestep. Then we may write

p(b1 + 1) = (b1 + 1)m −m−1∑i=1

bi(b1 + 1)m−i − bm

= (b1 + 1)

[(b1 + 1)m−1 −

m−1∑i=1

bi(b1 + 1)m−i−1

]− bm

≥ (b1 + 1)− bm ≥ 1.

By the induction hypothesis we know that the expression in large bracketsis greater than or equal to 1, so we have proved that for all p we havep(b1 + 1) ≥ 1. Descartes’ rule of signs states in this case that p has at mostone positive root, so p has a unique positive root β. In polynomials withcoefficient signs as given here the unique positive root is dominant (see [2]),so β is a dominant root. (See the preprint [3] for further comments aboutthe dominant root.)

Call a polynomial primitive if the greatest common divisor of the in-dices of its non-zero coefficients is 1. In particular, this happens if b1 > 0,so our p is primitive. If a nonnegative polynomial is primitive, then it has aunique root of largest modulus ([2], page 106), and it is real. This concludesthe proof.

6 Initial conditions

Let U be as described above and put L(U) equal to the set of greedy expres-sions 〈N〉U . We have seen that L(U) is the set of words such that each suffixof length n is less than or equal to (in the lexicographic order) 〈un − 1〉U .

For instance, for the Fibonacci sequence, the numbers in the form un− 1(excluding 1 -1) are 1, 2, 4, 7, 12, 20, . . . which have greedy representations 1,10, 101, 1010, 10101, 101010, respectively. Note that these words are of theform ak where a = 10, possibly truncated. So in this case, as noted earlier,we have the fact that when writing numbers in the Fibonacci base greedily,all binary words with no substring “11” appear.

17

If the recurrence is defined by the word a = a1 . . . am, we choose initialconditions for the sequence U so that the word aka1 . . . ar is a U -expressionfor us − 1, where s = km + r with 0 ≤ r < m, and r = 0 means that theword is just ak. It turns out that these are also the correct initial conditionsfor enumerative purposes.

Lemma 6.1. Consider a sequence U = {un}n≥0 defined by a recurrence ofdegree m and used as a base for numeration. Take as initial conditions forthe numbers u0, . . . , um−1 the following:

u0 = 1;u1 = a1+1 = N(a1)+1;u2 = N(a1a2)+1; . . . um−1 = N(a1a2 . . . am−1)+1.

Then for s ≥ 0, if s = km + r with 0 ≤ r < m, with the convention thatwhen r = 0, the word a1 . . . ar denotes the empty word, we have

N(aka1 . . . ar) = us − 1. (10)

Proof. The proof is by induction on k. If k = 0, the result is given by thehypothesis. For k > 0, just note that

us − 1 =m∑

i=1

aius−i + us−m − 1,

by the recurrence defining the sequence, and the induction hypothesis says

N(ak−1a1 . . . ar) = us−m − 1.

So

N(aka1 . . . ar) = N(a00 . . . 0) +N(ak−1a1 . . . ar)

=m∑

i=1

aius−i + us−m − 1

= us − 1,

where in N(a00 · · · 0) exactly s−m zeros appear.

Hence we now have a U -representation for us−1, namely aka1 . . . ar, sinceN(aka1 . . . ar) = us− 1. But we need the greedy representation for us− 1. Itturns out that the expression aka1 . . . ar is indeed the greedy representationif (and only if) the word a is anti-Lyndon. This choice of initial conditionsis, in the present context, the only right one. When a is anti-Lyndon, sinceun will count the number of Fa-free words, the sequence starts off as givenin the following lemma.

18

Lemma 6.2. If a is anti-Lyndon, then for 0 ≤ i ≤ m − 1, the number ofFa-free words of length i is N(a1 . . . ai) + 1.

Proof. The claim of the lemma is trivially true for i = 0. (Note that regard-less of which word a is, the empty word ε is Fa-free.

Suppose we are constructing all Fa-free words of a fixed length i > 0,going from the left to the right. If we choose as the leftmost letter any ofthe a1 digits 0, 1, . . . , a1− 1, we may complete the word with any of the ui−1

Fa-free words of length i− 1 without the risk of obtaining an occurrence ofan Fa-subword. So for the moment we have a1ui−1 words.

We have still to count those words beginning with a1. If the second letteris any of the a2 digits less than a2, the word can be completed with any oneof the ui−2 Fa-free words of length of length i− 2. Now we have a2ui−2 morewords, getting a1ui−1 + a2ui−2 words so far.

We go on in the same way, but successively fixing the first k digits ofthe words to be constructed in common with the first k digits of a. So weconstruct all the words of length i, obtaining

a1ui−1 + a2ui−2 + · · ·+ ai−1u1 + (ai + 1)u0

of them (since the rightmost digit of any digit from 0 to ai can appear).

7 Numeration system corresponding to an anti-

Lyndon word

Let a = a1a2 · · · am be an anti-Lyndon word. The number system U deter-mined by a is described as follows. At this point we merely state what theinitial conditions are, but the next couple results will justify this choice.

u0 = 1u1 = N(a1) + 1 = a1 + 1u2 = N(a1a2) + 1 = a1u1 + a2u0 + 1...

um−2 = N(a1a2 . . . am−2) + 1 = a1um−3 + a2um−4 + · · ·+ am−2u0 + 1um−1 = N(a1 . . . am−1) + 1 = a1um−2 + a2um−3 + · · ·+ am−1u0 + 1un =

∑mi=1 aiun−i + un−m for n ≥ m.

Consider again the anti-Lyndon word a = 312. The associated numbersystem U has u0 = 1; u1 = a1 + 1 = 4; u2 = N(a1a2) + 1 = 14; u3 =

19

N(a1a2a3) + 1 = 49. Then un = 3un−1 + un−2 + 2un−3 + un−3. In particular,u4 = 173.

Consider the map N that assigns to a string w the integer it correspondsto (i.e., represents) in a particular numeration system. We first note that itdoes not preserve order. For example, N(1100) = 63 and N(1033) = 64, but1100 � 1033. The first representation is greedy and Fa-free, but the secondis neither. (The greedy and Fa-free representation of 64 is 1101.) On theother hand, the following lemmas shows that for Fa-free words the order ispreserved.

Lemma 7.1. Let w and v be distinct Fa-free words not beginning with zero.If w � v, then N(w) > N(v).

Proof. Let u, v begiven as described in the lemma. The proof is by inductionon ` = `(w). If ` = 1, the result is obvious. So suppose that ` > 1. Firstsuppose that ` = `(w) is greater than `(v). Consider the following chain ofidentities:

N(w) ≥ N(100 . . . 0) (`− 1 zeros) > N((a1a2 . . . am)ka1 . . . ar) ≥ N(v),

where `− 1 = km+ r and 0 ≤ r < m.The first inequality holds because we are actually removing some (pos-

itive) summands, while the second one follows from Lemma 6.1. The lastinequality holds by induction because the words (11a2 . . . am)ka1 . . . a`−1−mk

and v have length less than `, and the hypotheses of the lemma are satisfied:both words are Fa-free, and the fact that v is Fa-free implies that v is smallerthan or equal to (in the LenLex order) the word (a1 . . . am)ka1 . . . a`−1−mk)(indeed either the former is shorter than the latter or is lexicographicallysmaller than or equal to it by the penultimate paragraph of Section 4). Thisconcludes the proof in case `(w) > `(v).

Suppose that both words have length `, say w = w`−1 . . . w0 and v =v`−1 . . . v0 with w`−1 ≥ v`1 . Consider then the word w′ obtained by substi-tuting w`−1−v`−1 for w`−1 in w and then by stripping it of the leading zeros.Define analogously v′ starting from v. Now N(w′) = N(w) − v`−1u`−1 andN(v′) = N(v) − v`−1u`−1, the new words are still Fa-free and w′ � v′. Ifw`−1 > v`−1, the new words have different lengths, and we may apply theargument given for different-length words. If w`−1 = v`−1, then these newwords both have length less than `, and we may apply induction.

20

This lemma implies that there is at most one Fa-free representation of agiven natural number, since different Fa-free words represent different num-bers. We can also use the last lemma to prove that the greedy expression ofa number n is Fa-free: the next lemma shows that an expression containinga subword in Fa does not satisfy the “greediness” condition in Eq. 3.

Lemma 7.2. Let N =∑k

`=0 d`u`, and assume that in this expression forN , a word in Fa appears starting in the s-th position. That is, for someindex s ≤ k and for some number j ≥ 1 of digits we have ai = ds+1−i fori = 1, 2, . . . , j − 1, while aj < ds−j+1.

Then∑s

`=0 d`u` ≥ us+1, so that the given expression for N is not greedy.

Proof. The proof is by induction on s. The basis of the induction is givenby the cases s = 0, 1, . . . ,m − 1, that is, when the subword in Fa starts inone of the m rightmost digits. The base cases will be covered later. For theinductive step we shall consider the subword starting with ds and show thatit represents a number greater than or equal to us+1.

Now,

dsus + ds−1us−1 + · · ·+ d0u0

≥ dsus + ds−1us−1 + · · ·+ ds−j+1us−j+1

≥ a1us + a2us−1 + · · ·+ ajus−j+1 + us−j+1

= a1us + a2us−1 + · · ·+ ajus−j+1

+ a1us−j + a2us−j+1 + · · · amus−j+1 + · · ·+ amus−j−(m−1) + us−j−(m−1),(11)

where in the last step we have applied the recurrence to us−j+1.Consider now the word w = a1a2 . . . am0 . . . 0 with s− j − (m− 1) zeros

after am. This word corresponds to the terms a1us−j + · · · + amus−j−(m−1).The word w is greater lexicographically than aj+1aj+2 . . . ama1 . . . aj0 . . . 0(same number of zeros as above; the sums in the indices are taken modulom) by the anti-Lyndon condition, so we may apply Lemma 7.1. Hence thelast sum in Eq. 11 is greater than or equal to

a1us + a2us−1 + · · ·+ ajus−j+1 + aj+1us−j + · · ·+ amus−m+1

+a1us−m + · · ·+ ajus−j−(m−1) + us−j−(m−1).

We now carry out the actual inductive step, by applying the result withs − m in place of s and taking , as new di’s : ds−m = a1, ss−m−1 = a2,

21

. . . , ds−m−(j−2) = aj−1, ds−j−(m−1) = aj + 1, ds−j−m = 0, . . . , d0 = 0. In thisway we obtain the inequality

a1us−m + · · ·+ ajus−j−(m−1) + us−j−(m−1) ≥ us−m+1.

Thus the last previously displayed sum is greater than or equal to

a1us + a2us−1 + · · ·+ ajus−j+1 + aj+1us−j + · · ·+ amus−m+1 + us−m+1,

which is equal to us+1, as claimed, completing the general inductive step.The basis of induction works similarly, but when we rewrite the first few

terms of the sequence or compare numbers represented using them we musttake into account the fact that the recurrence has not yet kicked in. Moreprecisely, as us−j+1 is one of the first m terms, it is given by the definition ofthe starting terms rather than by the recurrence: a1us−j + a2us−j−1 + · · · +as−j+1u0 + 1. And when we use the inequality derived by the anti-Lyndoncondition, it involves now a word shorter than the full a. Howevr, the anti-Lyndon condition automatically implies that a prefex of a is lexicographicallygreater than or equal to the same length prefix of each cyclic shift.

We have now proved that each natural integer has an Fa-free expression,the greedy one. The uniqueness was proved in Lemma 7.1. This completesa proof of the following theorem.

Theorem 7.3. Let U be a sequence defined by the recurrence

un =m∑

`=1

a`un−` + un−m

with a = a1 . . . am an anti-Lyndon word and with the initial conditions u0 = 1,u1 = a1u0 + 1 = N(a1) + 1, u2 = a1u1 + a2u0 + 1 = N(a1a2) + 1, . . . , um−1 =a1um−2 + a2um−3 + · · · am−1u0 + 1 = N(a1a2 . . . am−1) + 1.

Then each positive integer n has a unique Fa-free representation, whichturns out to be the greedy one.

Moreover, considering the set of Fa-free strings not beginning by zero withthe LenLex order, the nth string represents the number n.

This theorem has an enumerative counterpart.

Corollary 7.4. If a = a1 . . . am is an anti-Lyndon word and U = {un}n≥0 isthe sequence as defined in Theorem 7.3, then the number of Fa-free words oflength k is uk.

22

Proof. The proof is straightforward from the theorem, keeping in mind thatwe are now counting all words (including those beginning by zero).

Remark 7.5.

Note that, while in the context of numeration systems we are generallyonly interested in words without leading zeros (which in this context would benon-significant digits), when we enumerate words with prescribed conditions,those are just ordinary words.

But this is not a problem, since counting all Fa-free words of a certainlength k is equivalent to counting the Fa words not beginning with zero oflength at most k (just pad the latter ones with zeros).

8 The lazy expression

When representing natural numbers in terms of a given sequence we mayact “lazily” rather than “greedily”, taking the smallest expression for a giveninteger, and if the sequence is given by an anti-Lyndon word, then it is easyto obtain a characterization for the strings appearing as lazy expressionsfor the natural numbers, much in the same way as shown above for greedyexpressions.

8.1 Example

The lazy representation of an integer using Fibonacci numbers turns out to beits (unique) expression as a sum of distinct Fibonacci numbers without everskipping more than one in a row. In terms of binary strings, this correspondsto strings with no consecutive zeros.

For instance, the lazy expression of 22 is 101101 while the greedy one is1000001 (still another expression is 110001).

It is easily seen that there is a simple procedure to get the lazy expressionof N , which basically “dualizes” the greedy one. We describe the procedurefor the case studied earlier, i.e., for a recurrent sequence arising from ananti-Lyndon word a = a1 . . . am, thus using the alphabet {0, . . . , a1}.

Perform the following steps to obtain the lazy expression for a naturalnumber N :

(i) Determine the smallest k such that the number N(a1a1 . . . a1) (k digits)is greater than or equal to N ;

23

(ii) Find the greedy expression bk−1 . . . b0 of the number N(a1a1 . . . a1)−N(padded on the left with zeros if its length is less than k);

(iii) Subtract termwise the string bk−1 . . . b0 from a1 . . . a1.

The result is the lazy expression for N .

8.2 Example

Consider once more the sequence arising from the word a = a1a2a3 = 312.So u0 = 1, u1 = 4, u2 = 14, u3 = 49, u4 = 173. We want to apply theabove procedure to N = 100. Then N(3) = 3, N(33) = 15, N(333) = 57,N(3333) = 204. So the k we need is k = 4. The greedy expression of204− 100 = 104 is 2012. Hence the lazy expression for 100 is 333− 2012 =1321. Check: 100 = 49 + 42 + 8 + 1.

When the word is anti-Lyndon, we have seen that the strings obtainedwith the greedy procedure have a simple characterization in terms of forbid-den substrings. From the procedure described above, it follows easily thatthe same is true in the lazy case. Here the forbidden strings are the comple-ments to a1a1 . . . a1. For instance, in the example just given, the forbiddensubwords in the greedy case are 32, 33, 313. Therefore in the lazy case thestrings are characterized by forbidding 01, 00, 020.

Recalling that, for an anti-Lyndon word a = a1 . . . am, the set Fa wasdefined to be the set of words of length at most m lexicographically greaterthan a, we define Fa to be the set of words of length at most m which arelexicographically less than a = (a1 − a2)(a1 − a2) . . . (a1 − am). With thisnotation, the above can be summarized in the following theorem.

Theorem 8.3. If a = a1 . . . am is an anti-Lyndon word and {un} is thesequence determined by the word a, the set of words that are lazy expressionsof natural numbers is the set of Fa-free words in the alphabet {0, 1, . . . , a1}.

Note that, while this theorem mirrors clearly the situation for greedystrings, there are other slightly less obvious parallels between the greedy andthe lazy cases. When we write numbers greedily, it is immediate to find theleast natural number expressed with a given number k of digits: it is simplyuk, the k-th term of the sequence, whose greedy representation is given by1 followed by k zeros. The largest k-digit expression, on the other hand, isless immediate, and is described in Lemma 6.1.

24

For lazy expressions, on the other hand, it is immediate to write thelexicographically largest one with k digits, which is simply a1a1 . . . a1, whilethe smallest one can be once more described in terms of repetitions of theword a. For instance, as the threes’ complement of 312 is 021, the leastnumber with a given number of digits in the base defined by this word hasthe form 1021021021 . . ..

9 The Non-anti-Lyndon case

The gist of the previous results culminating with Theorem 7.3 is that, whenthe recurrence is defined by an anti-Lyndon word a, the structure of theset L(U) of greedy expressions of natural numbers is encoded in the greedyexpression aka1 . . . ar of the terms of the form un − 1, where n = mk +r. Indeed, (recall the first paragraph of Section 6), the greedy expressionfor un − 1 characterizes completely L(U): if a is anti-Lyndon, the greedyexpression has this neat periodic form.

This is no longer true when a is not anti-Lyndon. If the word a defininga recurrence is not anti-Lyndon, then aka1 . . . ar is by Lemma 6.1 a represen-tation of the number un − 1 but is not its greedy expression. For instance,if a = 3132, then the first terms of its sequence are 1, 4, 14, 50, 179, . . .. Theword 3132 represents u4 − 1 = 178, but the greedy representation of 178 is3200.

Lemma 9.1. Let a = a1 . . . am be a non-anti-Lyndon (non-periodic) word.Let i + 1 (with i + 1 > 1) be the starting index of the anti-Lyndon shift ofa, so ai+1ai+2 . . . ama1 . . . ai is an anti-Lyndon word). Let ai+1 . . . ai+k be theprefix of the anti-Lyndon shift such that

ai+1 = a1, ai+2 = a2, . . . , ai+k−1 = ak−1, ai+k > ak.

Then the word a1 . . . aiai+1 . . . ai+k is not the greedy representation of thenumber N(a1 . . . aiai+1 . . . ai+k).

Proof. It suffices to show that ai+1 . . . ai+k is not greedy. We have ai+k ≥ak + 1. Then

N(ai+1 . . . ai+k) ≥ N(a1 . . . ak) + 1,

which is denoted greedily by 10 . . . 0 (k zeros).

So we obtain the following characterization.

25

Theorem 9.2. Let U be the sequence obtained with the recurrence inducedby the word a and the usual initial conditions. Then one has

〈un − 1〉U = aka1 . . . ar

if and only if a is an anti-Lyndon word.

10 Fibonacci Nim – Just for fun this time!

RULES FOR FIBONACCI NIM

1. Play starts with one pile of counters having at least 2 counters. Thefirst player may remove any positive number of counters, but not thewhole pile. Thereafter, each player must remove at least one counterand may remove at most twice the number of counters his opponenttook on the previous move.

2. The player who removes the last counter wins.

NOTE: If both players play perfectly, the first player can win if the num-ber of counters in the initial pile is not a Fibonacci number. If it is a Fibonaccinumber, the second player can win.

STRATEGYLet’s say you are playing first and your opponent is named Nim.Here is how to always win using Fibonacci numbers: On the first move,

leave Nim a Fibonacci number of coins, or Nim will leave you with a Fibonaccinumber of coins and force you to lose. If possible without losing, always leaveNim a Fibonacci number of coins. But don’t take too many, or Nim will takethe rest. Otherwise, count the number of coins remaining. (If the count isa Fibonacci number, Nim will win no matter what you do.) Write downthe number of coins on the board as the SUM of nonconsecutive Fibonaccinumbers. Find the smallest Fibonacci number in the sum. Remove thatnumber of coins from the board. Repeat this process each time you play.

For example, if it is your turn and 15 coins remain on the board, write15 as the sum of 13 + 2. Then remove 2 coins leaving 13. Nim can then onlyremove 1 to twice as many coins as you removed: that would be 1 to 4 coins.Suppose Nim removes 2 coins leaving 11. Write 11 as 8+3. Then remove 3coins leaving 8. Nim can now remove 1 to 6 coins (2x3=6). Suppose Nim

26

removes 2 coins leaving 6. Write 6 as 5+1. Then remove 1 coin leaving 5.Nim can only remove 1 or 2 coins now. Suppose Nim removes 1 coin leaving4. Write 4 as 3+1. Then take 1 coin leaving 3. If Nim takes 1 coin, youwill take 2 coins and win! If Nim takes 2 coins, you will take the last coinand win! Using this strategy, you will always win if you leave Nim a numberof coins equal to the sum of Fibonacci numbers. Remember also that everyFibonacci number is the sum of Fibonacci numbers. So, if possible leaveNim a Fibonacci number of coins. Just make sure Nim cannot take all theremaining coins.

For a proof that the strategy given above really works, see the article byHolshouser, Reiter and Rudzinski, [4].

References

[1] Aviezri S. Fraenkel, Systems of numeration, Amer. Math. Monthly92 (1985), 105 – 114.

[2] P. Cull, M. Flahive, R. Robson, Difference Equations – From Rab-bits to Chaos, Springer, 2005.

[3] Daniele A. Gewurz and Francesca Merola, Numeration and enu-meration, Proc. 4th Pythagorean

[4] Arthur Holshouser, Harold Reiter and James Rudzinski, Dynamicone-pile Nim, Fibonacci Quarterly, 41 #3 (June-July) (2003), 253– 262.

[5] D. H. Lehmer, The machine tools of combinatorics, in Applied Com-binatorial Mathematics (E. F. Beckenbach, ed), Wiley, 1964, 5 – 31.

[6] E. Zeckendorf, Representation des nombres naturels par une sommede nombres de Fibonacci ou de nombres de Lucas, Bull. Soc. Roy.Sc i. Liege, 41 (1972), 179 – 182.

27