On the Number of Balanced Words of Given Length and Height over a Two-Letter Alphabet

We exhibit a recurrence on the number of discrete line segments joining two integer points in the plane using an encoding of such segments as balanced words of given length and height over the two-letter alphabet { 0 , 1 } . We give generating functions and study the asymptotic behaviour. As a particular case, we focus on the symmetrical discrete segments which are encoded by balanced palindromes


Introduction
The aim of this paper is to study some properties of discrete lines by using combinatorics on words.The first investigations on discrete lines are dated back to J. Bernoulli [Ber72], E.B. Christoffel [Chr75], A. Markoff [Mar82] and more recently to G.A. Hedlund and H. Morse [MH40] who introduced the terminology of Sturmian sequences, for the ones defined on a two-letter alphabet and coding lines with irrational slope.These works gave the first theoretical framework for discrete lines.A sequence u ∈ {0, 1} N is Sturmian if and only if it is balanced and not-eventually periodic.From the 70's, H. Freeman [Fre74], A. Rosenfeld [Ros74] and S. Hung [Hun85] extended these investigations to lines with rational slope and studied discrete segments.In [Rev91], J.-P.Reveillès defined arithmetic discrete lines as sets of integer points between two parallel Euclidean lines.There are two sort of arithmetic discrete lines, the naive and the standard one.
There exists a direct relation between naive (resp.standard) discrete arithmetic lines and Sturmian sequences.Indeed, given a Sturmian sequence u ∈ {0, 1} N , if one associates the letters 0 and 1 with a shifting along the vector e 1 and e 2 (resp.the vectors e 1 and e 1 + e 2 ) respectively, then, the vertices of the obtained broken line are the ones of a naive arithmetic discrete line (resp.a standard arithmetic discrete line) with the same slope (see Figure 1).
Let s : N −→ N be the map defined by: where #E denotes the cardinal of the set E. In other words, given L ∈ N, s(L) is the number of balanced words of length L, or equivalently, the number of discrete segments of any slope α ∈ [0, 1] of length L. In [Lip82], it is proved that where ϕ is Euler's totient function, that is, ϕ(n) is the number of positive integers smaller that n and coprime with n.Alternative proofs of this result can be found in [Mig91,BP93,CHT02,BL88].
In [dLL05,dLL06], de Luca and De Luca investigated the number p(L) of balanced palindrome words of length L ∈ N, that is the balanced words coding a symmetrical discrete segments of length L. They proved In the present work, we investigate the following question.Given two integer points of Z 2 (also called pixels in the discrete geometry literature [CM91]), how many naive discrete segments link these points (see Figure 1)?In other words, given L ∈ N and h ∈ N, how much is s(L, h) = #{w ∈ {0, 1} L , |w| 1 = h and w balanced}?We exhibit a recurrence relation on s(L, h) and generating functions and we study the asymptotic behaviour of the maps s.After this, we focus on the number p(L, h) of balanced palindromes of given length and height for which we also exhibit a recurrence relation and a generating function.
We are interested in these formulas to have a better understanding of the space of Sturmian sequences.Indeed the main combinatorial properties of theses sequences can be seen in similar formulas.For example the formula of s(L) is deeply related to the number of bispecial words of length L, see [CHT02].One main objective is to generalize these formulas to dimension two in way to understand the combinatorics structure of discrete planes.To a discrete plane is associated a two dimensional word.The study of these words is an interesting problem.The complexity of such a word is not known, the first step in its computation is the following article [DJVV10].
Figure 1: There exist six discrete segments of length 5 and height 2.

Basic notions and notation
Let {0, 1} * and {0, 1} N be the set of respectively finite and infinite words on the alphabet {0, 1}.We denote the empty word by .For any word w ∈ {0, 1} * , |w| denotes the length of w, and |w| 0 and |w| 1 denote respectively the number of 0's and 1's in w. |w| 1 is also called the height of w.A (finite or infinite) word w is balanced if and only if for any finite subwords u and v of w such that |u| = |v|, we have |u| 0 − |v| 0 ≤ 1.A (finite or infinite) word w is of type 0 (resp.type 1) if the word w does not contain 11 (resp.the word 00).We denote by S the set of finite balanced words and by S 0 (resp.S 1 ) the set of finite balanced words of type 0 (resp.1).
Let L, h ∈ N and α, β ∈ {0, 1} * .We denote by S α,β (L, h) the set of elements of S of length L and height h, of which α is a prefix and β is a suffix.Note that α and β may overlap.For short, we usually write S(L, h) instead of S , (L, h).Observe that S(L, h) is the set of finite balanced words which encode the discrete segments between (0, 0) and (L, h).Remark also that L − h is the width of the word, that is the number of zero's.We can count by height or by width, it is the same and this symmetry is used several times in the paper.
3 General case

Main theorem
In the present section, we prove the following result: Theorem 1.For all L, h ∈ N satisfying 0 ≤ h ≤ L/2, one has: In order to prove Theorem 1, let us now introduce some technical definitions and lemmas.Let ϕ be the morphism defined on {0, 1} * and {0, 1} N by: Let us recall that ϕ is a Sturmian morphism, that is, for any Sturmian sequence u, the sequence ϕ(u) is Sturmian [Par97,MS93].Moreover: 1.If 0w is Sturmian of type 0, then there exists a unique Sturmian sequence u satisfying ϕ(u) = 0w.

w is Sturmian if and only if so is ϕ(w).
Since every balanced word is a factor of a Sturmian word, we directly deduce: Corollary 3. If a finite word w ∈ {0, 1} * is balanced then so is ϕ(w).
We have w = 0 α 1w for some α ≥ 0. By assumption, the letter 1 is isolated in 0w1, so that w = and w starts with the letter 0. Hence, By the induction hypothesis, we obtain Example 1.We have by straightforward computations: ϕ(θ(11)) = 0101.
Thus the last equation of Lemma 4 is not true everywhere.
1.If w is of type 1 (i.e. the letter 0 is isolated in w), then we verify that θ(w) = 1 α for some integer α.Hence it is balanced.

Assume now that w ∈ S 0 .
• There exist α ∈ {0, 1}, β ∈ N and a Sturmian sequence u of type 0 such that the sequence 0 α w0 β 1u is Sturmian and starts with the letter 0. Notice that u starts with the letter 0 too.
• By point 1 of Lemma 2, there exists a Sturmian sequence u such that u = ϕ(u ).
The last technical property of θ we need is: All others sets are empty so that the result obviously holds.In the rest of the proof, we assume h ≥ 1.We prove the result for S 0,1 (L, h).The proof of other cases is similar and left to the reader.Notice first that S 0,1 (L, h) , by the pigeonhole principle, any w ∈ S 0,1 (L, h) must contain the subword 00.Since w is balanced, it cannot contain the subword 11 hence the letter 1 is isolated.Conversely, if the letter 1 is isolated in w, then w must contain at least h 0's, hence L ≥ 2h.
. We get the result by induction on h.
Lemma 8.For all L, h such that 0 Proof.We distinguish several cases.
• If 2h < L, the result is an immediate consequence of case 1 of Lemma 6.
We are now ready to prove the main theorem.
of Theorem 1.The property holds for L = 0.If L > 0, then the following disjoint union holds: and, consequently: From Lemmas 6 and 8, it follows that

Remark
To summarize, we can compute the formula for s(L, h) for all integers L, h ∈ Z. Indeed if L is negative, then it is null.If h = 0, then S(L, 0) = 1.If L = 0 then S(0, h) = 1.The other values can be computed with the statement of Theorem 1 and the relation s(L, h) = s(L, L − h) which is obtained by exchanging 0's and 1's.Sample values of s(L, h) are given in Table 1.The sum of elements in a row give the value of s(L).
L\h 0 1 2 3 4 5 6 7 8 9 10 0 1 Using the recurrence formula of Theorem 1, we can deduce an explicit formula for some particular cases.Actually we are not able to give an explicit formula in all cases.For instance, one has: Proposition 9. Let L ≥ 0 be an integer.Then, one has: Proof.By induction on L. One checks that the result holds for L ∈ {0, 1, 2, 3, 4}.Assume L ≥ 5 and the result holds for all nonnegative integers smaller than For all L ≥ 3, let u L = s(L, 2) − s(L − 3, 2).Then, u L+2 = u L + 2 and one obtains u L = L − 1 + (L mod 2).By induction, it follows: Finally, it suffices to check that: By considering the remainder of L modulo 6, we obtain that the fractional part of L 2 +2L 6 is strictly less than 1 2 if and only if L is even.The result follows.

Generating functions of s(L, h)
A classical way to obtain an explicit formula of a given function consists in computing its generating function.In this section, we exhibit for each h ≥ 0 the generating function S h (X) of s(L, h), namely S h (X) = L≥0 s(L, h)X L .
Let us recall that, in that case, s(L, h) = S (L) is the derivative of order L of S (L) .
Theorem 10.One has: where Proof.We have immediately the two first formulas.From the previous re-currence, for h ≥ 2, we get: Finally, we get the formula Notice that the previous equality does provide a closed formula for S h (X) although it still depends on s(L, h) because each sum is finite.Sample values of S h (X) are given in Table 2.
Table 2: Sample values of S h (X)

Asymptotic behaviour of s(L, h)
Using the generating functions we just computed, we may deduce an expression of s(L, h) which highlights its asymptotic behaviour when L grows.We prove the following theorem: Theorem 11.For all h ≥ 2, there exist u 0 , . . ., u h−2 , v 0 , . . ., v h−1 , w 0 , . . ., w h ∈ Q such that Before proving this theorem, we need some preliminary results.
Proof.We have 1−X are divisible by 1 + X.But in this case, we notice that F h (−1) = 0 so that F h (X) is also divisible by 1 + X and we may write where (1 Lemma 13.We recall that s(L) is the number of balanced words of length L, and that it is equal to h s(L, h).For all L ≥ 0 we have, Lemma 14.For all h ≥ 1, by using the recurrence relation from Th. 1 by using the relation s(L, h) = s(L, h mod L) on 3rd, 4th and 5th terms = s(h We are now ready to prove the main theorem of this section.

Balanced palindromes and symmetrical discrete segments
In the present section, we focus on the case of segments which are symmetrical with respect to the point (L/2, h/2).These segments are encoded by balanced palindromes.

Recurrence formula
This investigation is close to the general case by noticing that if w is a palindrome, then so is θ(w).We first need an additional property of the mapping θ.
Lemma 23.For all h ≥ 2: (2) Proof.If h is even then P h (X) may be written as We get the result with A(X) = (1 − X)A 0 (X) and B(X) = (1 − X)B 0 (X).If h is odd then 1 − X h−1 and 1 − X h+1 are also divisible by 1 + X so that we may write .
Lemma 24.For all L, h ∈ N such that L is even and h is odd, p(L, h) = 0.
Proof.By definition of p(L, h), the result is obvious if L = 0. Also, it is sufficient to prove the result for 0 ≤ h ≤ L because h and h mod L have the same parity if L is even.In this case, p(L, h) is exactly the number of balanced palindromes of length L and height h.Let w be a palindrome of length L. If L is even then w = uu˜for some u ∈ {0, 1} * and |w| 1 = 2|u| 1 .Hence, there exist no palindrome of even length and odd height.
We are now ready to prove the main theorem of this section.
of Theorem 22.The proof is similar to the proof of Theorem 11.In Equations 2 and 3, we write and we get for all h ≥ 2: • If h is even then and the series expansion of P h (X) is • If h is odd then and its series expansion is Considering the Taylor expansion of (1 − X) 2 P h (X) at X = 1 and, in case h is even, (1 + X) 2 P h (X) at X = −1, we get and, if h is odd, where the last equality is deduced from Lemma 24.Hence α = −α.
Finally, we get the result with u i = α + β + a i if h is even and u i = (1 − (−1) i )α + β + (−1) i β + a i if h is odd and v i = b i .