Behavior of digital sequences through exotic numeration systems

Many digital functions studied in the literature, e.g., the summatory function of the base-$k$ sum-of-digits function, have a behavior showing some periodic fluctuation. Such functions are usually studied using techniques from analytic number theory or linear algebra. In this paper we develop a method based on exotic numeration systems and we apply it on two examples motivated by the study of generalized Pascal triangles and binomial coefficients of words.


Introduction
Many digital functions, e.g., the sum of the output labels of a finite transducer reading base-k expansion of integers [11], have been extensively studied in the literature and exhibit an interesting behavior that usually involves some periodic fluctuation [5,6,7,8,9,10]. For instance, consider the archetypal sum-of-digits function s 2 for base-2 expansions of integers [18]. Its summatory function is counting the total number of ones occurring in the base-2 expansion of the first N integers, i.e., the sum of the sums of digits of the first N integers. Delange [6] showed that there exists a continuous nowhere differentiable periodic function G of period 1 such that (1) 1 N N −1 j=0 s 2 (j) = 1 2 log 2 N + G(log 2 N ).
For an account on this result, see, for instance, [4,Thm. 3.5.4]. The function s 2 has important structural properties. It readily satisfies s 2 (2n) = s 2 (n) and s 2 (2n+1) = 1 + s 2 (n) meaning that the sequence (s 2 (n)) n≥0 is 2-regular in the sense of Allouche and Shallit [2]. A sequence (u(n)) n≥0 is k-regular if the Z-module generated by its k-kernel, i.e., the set of subsequences {(u(k j n + r)) n≥0 | j ≥ 0, r < k j }, is finitely generated. This is equivalent to the fact that the sequence (u(n)) n≥0 admits a linear representation: there exist an integer d ≥ 1, a row vector r, a column vector c and matrices Γ 0 , . . . , Γ k−1 , of size d such that, if the base-k expansion of n is w j · · · w 0 , then u(n) = r Γ w0 Γ w1 · · · Γ wj c.
For instance, the sequence (s 2 (n)) n≥0 admits the linear representation Many examples of k-regular sequences may be found in [2,3]. Based on linear algebra techniques, Dumas [7,8] provides general asymptotic estimates for summatory functions of k-regular sequences similar to (1). Similar results are also discussed by Drmota and Grabner [5,Thm. 9.2.15] and by Allouche and Shallit [4].
In this paper, we expose a new method to tackle the behavior of the summatory function (A(N )) N ≥0 of a digital sequence (s(n)) n≥0 . Roughly, the idea is to find two sequences (r(n)) n≥0 and (t(n)) n≥0 , each satisfying a linear recurrence relation, such that A(r(n)) = t(n) for all n. Then, from a recurrence relation satisfied by (s(n)) n≥0 , we deduce a recurrence relation for (A(n)) n≥0 in which (t(n)) n≥0 is involved. This allows us to find relevant representations of A(n) in some exotic numeration system associated with the sequence (t(n)) n≥0 . The adjective "exotic" means that we have a decomposition of particular integers as a linear combination of terms of the sequence (t(n)) n≥0 with possibly unbounded coefficients. We present this method on two examples inspired by the study of generalized Pascal triangle and binomial coefficients of words [12,13] and obtain behaviors similar to (1). The behavior of the first example comes with no surprise as the considered sequence is 2-regular [13]. Nevertheless, the method provides an exact behavior although an error term usually appears with classical techniques. Furthermore, our approach also allows us to deal with sequences that do not present any k-regular structure, as illustrated by the second example.
Let us make the examples a bit more precise (definitions and notation will be provided in due time). The binomial coefficient u v of two finite words u and v in {0, 1} * is defined as the number of times that v occurs as a subsequence of u (meaning as a "scattered" subword) [14,Chap. 6]. The sequence (s(n)) n≥0 is defined from base-2 expansions by s(0) = 0 and, for all n ≥ 1, (2) s(n) := # v ∈ rep 2 (N) | rep 2 (n − 1) v > 0 and the sequence (s F (n)) n≥0 is defined from Zeckendorf expansions by where F stands for the Fibonacci numeration system. We have the following results. In the last section of the paper, we present some conjectures in a more general context.
2. Summatory function of a 2-regular sequence using particular 3-decompositions This section deals with the first example. For n ∈ N, we let rep 2 (n) denote the usual base-2 expansion of n. We set rep 2 (0) = ε and get rep 2 (N) = 1{0, 1} * ∪ {ε}. We will consider the summatory function of the sequence (s(n)) n≥0 . The first few terms of (A(N )) N ≥0 are 0, 1, 3, 6,9,13,18,23,27,32,39,47,54,61,69,76,81,87,96,107,117, . . . The quantity A(N ) can be thought of as the total number of base-2 expansions occurring as subwords in the base-2 expansion of integers less than or equal to N (the same subword is counted k times if it occurs in the base-2 expansion of k distinct integers). The sequence (s(n)) n≥0 being 2-regular [13], asymptotic estimates of (A(N )) N ≥0 could be deduced from [7]. However, as already mentioned, such estimates contain an error term. Applying our method, we get an exact formula for A(N ) given by Theorem 1. To derive this result, we make an extensive use of a particular decomposition of A(N ) based on powers of 3 that we call 3-decomposition. These occurrences of powers of 3 come from the following lemma.
Lemma 3 ([12, Lemma 9]). For all n ∈ N, we have A(2 n ) = 3 n . Remark 4. The sequence (s(n)) n≥0 also appears as the sequence A007306 of the denominators occurring in the Farey tree (left subtree of the full Stern-Brocot tree) which contains every (reduced) positive rational less than 1 exactly once. Note that we can also relate (s(n)) n≥0 to Simon's congruence where two finite words are equivalent if they share exactly the same set of subwords [16].
For the sake of presentation, we introduce the relative position relpos 2 (x) of a positive real number x inside an interval of the form [2 n , 2 n+1 ), i.e., where {x} = x − x denotes the fractional part of any real number x. In Figure 1, the map log 2 N + relpos 2 (N ) is compared with log 2 N . Observe that both functions take the same value at powers of 2 and the first one is affine between two consecutive powers of 2.
In the rest of the section, we prove the following result which is an equivalent version of Theorem 1 when considering the function H defined by H(x) = Φ(relpos 2 (2 x )).
Proposition 6 also permits us to derive two convenient relations for A(N ) where powers of 3 appear. This is the starting point of the 3-decompositions mentioned above.
Proof. Let us start with the first case. If r = 0, the result directly follows from Lemma 3. Now assume that 0 < r ≤ 2 −1 . Applying Proposition 6 and recalling that s(0) = 0, we get Let us proceed to the second case with 2 −1 < r < 2 and r = 2 − r. Notice that 0 < r < 2 −1 . Applying Proposition 6, we get We may apply the first part of this lemma with r and thus get Corollary 9. For all n ≥ 0, A(2n) = 3A(n).
Proof. Let us proceed by induction on n ≥ 0. The result holds for n ∈ {0, 1}. Thus consider n ≥ 2 and suppose that the result holds for all m < n. Let us write n = 2 + r with ≥ 1 and 0 ≤ r < 2 . Let us first suppose that 0 ≤ r ≤ 2 −1 . Then, by Lemma 8, we have We conclude this case by using the induction hypothesis. Now suppose that 2 −1 < r < 2 . Then, by Lemma 8, we have where r = 2 − r. We again conclude by using the induction hypothesis.
Definition 11 (3-decomposition). Let n ≥ 2. Iteratively applying Lemma 8 provides a unique decomposition of the form where a i (n) are integers, a 0 (n) = 0 and 2 (n) stands for log 2 n or log 2 n − 1 (depending on the fact that n = 2 log 2 n + r with 2 log 2 n −1 < r < 2 log 2 n or 0 ≤ r ≤ 2 log 2 n −1 respectively). We say that the word 3dec(A(n)) := a 0 (n) · · · a 2(n) (n) is the 3-decomposition of A(n). Observe that when the integer n is clear from the context, we simply write a i instead of a i (n). For the sake of clarity, we will also write (a 0 (n), . . . , a 2(n) (n)).
As an example, we have 2 (84) = 5 and, using (5), the 3-decomposition of A(84) is (6, −6, 4, 4, 8, 12). See also Table 1. Also notice that the notion of 3decomposition is only valid when the values taken by the sequence (A(N )) N ≥0 are concerned. For instance, the 3-decomposition of 5 is not defined because 5 / ∈ {A(n) | n ∈ N}.  (i) If rep 2 (n) = 10u, with u ∈ {0, 1} * possibly starting with 0, then we apply the first part of Lemma 8 and we are left with evaluations of A at integers whose base-2 expansions are shorter and given by 1u and rep 2 (val 2 (u)). Note that rep 2 (val 2 (u)) removes the possible leading zeroes in front of u. (ii) If rep 2 (n) = 11u, with u ∈ {0, 1} * \ 0 * , i.e., u contains at least one 1, then we apply the second part of Lemma 8 and we are left with evaluations of A at integers whose base-2 expansions are shorter and given by 1u and rep 2 (val 2 (u )) where u ∈ {0, 1} * has the same length as u and satisfies val 2 (u ) = val 2 (h(u)) + 1 where h is the involutory morphism exchanging 0 and 1. As an example, if u = 01011000, then h(u) = 10100111 and u = 10101000. If we mark the last occurrence of 1 in u (such an occurrence always exists): u = v10 n for some n ≥ 0, then u = h(v)10 n . (iii) If rep 2 (n) = 110 k , then we will apply the first part of Lemma 8 and we are left with evaluations of A at integers whose base-2 expansions are given by 10 k+1 and 10 k . This situation seems not so nice : we are left with a word 10 k+1 of the same length as the original one 110 k . However, the next application of Lemma 8 provides the word 10 k and the computation easily ends with a total number of calls to this lemma equal to k + 3, namely the computations of A(2 k+1 ), A(2 k ), . . . , A(2 0 ), A(0) are needed. This situation is not so bad since the numbers of calls to Lemma 8 to evaluate A at integers with base-2 expansions of the same length can be equal. For instance, the computation of A(12) requires the computations of A(8), A(4), A(2), A(1), A(0) and the one of A(14) requires the computations of A(6), A(4), A(2), A(1), A(0).
As already observed with Equations (4) and (5), the 3-decompositions of 42 and 84 share the same first digits. The next lemma states that this is a general fact. Roughly speaking, if two integers m, n have a long common prefix in their base-2 expansions, then the most significant coefficients in the corresponding 3decompositions of A(m) and A(n) are the same.
The first term in these two expressions will equally contribute to the coefficient a 0 in the two 3-decompositions. For the last two terms, we may apply the induction hypothesis. If n 1 = 0, applying again Lemma 8 to A(val 2 (1uv)) gives where v = x10 t and i is the smallest index such that n i > 0. We can conclude in the same way as in the case n 1 > 0. The idea in the next three definitions is that α gives the relative position of an integer in the interval [2 n+1 , 2 n+2 ).
Roughly, w n (α) is a word of length n + 2 and its relative position amongst the words of length n + 2 in 1{0, 1} * is given by an approximation of α.
To visualize the uniform convergence stated in Proposition 20, we have depicted the first functions φ 2 , . . . , φ 9 in Figure 3. For instance, e 2 (α) ∈ {9, 11, 13, 15} explaining the four subintervals defining the step function φ 2 .   To ensure convergence of the series that we will encounter, we need some very rough estimate on the coefficients occurring in 3dec(A(e n (α))). Lemma 22. Using notation of Definitions 11 and 18, for all n ≥ 2 and for 0 ≤ i ≤ 2 (n), we have In particular, for all α ∈ [0, 1) and all i ≥ 0, we have Proof. Let us write n = 2 + r with ≥ 1 and 0 ≤ r < 2 . Using Definition 11, let us write where a j (n) are integers, a 0 (n) = 0. Observe that we have 2 (n) ∈ { , − 1}. Let us fix some i ∈ {0, 1, . . . , 2 (n)}. By Lemma 8, terms of the form are the only ones possibly contributing to a i (n). Those of the first (resp., second) form yield 2 · 3 2(n)−i (resp., 4 · 3 2(n)−i ). Observe that for a term A(2 2(n)−i+1 + r ) of the first form with 2 2(n)−i−1 < r ≤ 2 2(n)−i , a second application of Lemma 8 gives, in addition to 2 · 3 2(n)−i , the term A(2 2(n)−i + r ), which is of the second form. Together, these terms give 6 · 3 2(n)−i . Our aim is now to understand, starting from A(2 + r), how the successive applications of Lemma 8 lead to terms of the form (7). Observe that the successive applications of the lemma can give terms of the form A(2 p + r ) where r can take several values for a given value of p. This is the reason why we consider a second index q in the sum below.
Let us describe a transformation process starting from a linear combination of the form 0≤p≤k 0≤q≤sp where k > 2 (n)−i+1 and, for all p and q, s p ∈ N, x p,q ∈ Z and r p,q ∈ {0, 1, . . . , 2 p − 1}. Applying Lemma 8 to every term of the form A(2 p + r p,q ) with p < 2 (n) − i will provide terms of the form A(2 p + r ) with p ≤ p and r < 2 p . Hence these terms are not of the form (7) and thus will never contribute to a i (n). Applying the lemma to every term of the form A(2 p + r p,q ) with p > 2 (n) − i + 1 gives a linear combination of 3 p and 3 p−1 together with a linear combination of the form Observe that p 2 = p if and only if r p,q = 2 p−1 . In this case we get p 1 = p − 1, r 1 = r 2 = 0 and the terms A(2 p ) = 3 p and A(2 p−1 ) = 3 p−1 . Therefore, applying Lemma 8 to all terms of the form A(2 p + r p,q ) with p > 2 (n) − i + 1 gives a linear combination of the form where for all j, y j ∈ Z and for all p and q, t p ∈ N, y p,q ∈ Z and r p,q ∈ {0, 1, . . . , 2 p − 1} and where 0≤p<k 0≤q≤tp So we get some information about how behave the coefficients when applying once the transformation process. Starting from the particular combination 1 · A(2 + r) and iterating this process − 2 (n)+i−1 times, we thus obtain a linear combination of the form We conclude by observing that Their combination yields a term 6 · 3 −1 .
Remark 23. With a deeper analysis, one could probably refine the above lemma (even though this is not required for what remains). Let (F (n)) n≥0 be the Fibonacci . The equality holds for α = 1/3. In this case, the sequence (w n (α)) n≥1 converges to (10) ω .
Indeed, thanks to Lemma 13, the sequence of finite words (3dec(A(e n (α)))) n≥1 converges to a(α). Moreover, due to Lemma 22, the sequence of partial sums uniformly converges to the series.
Let > 0. For all α ≥ 1/2, we observe, using (9), that the inequality is valid for n large enough. Indeed, the first inequality comes from (9). For the second inequality, we know that where C is a positive constant. Moreover, the sequence of functions ({log 2 (e n (α))}) n≥1 uniformly converges to log 2 (α + 1) and thus for n large enough. Finally, for n large enough. One proceeds similarly with (8) for the case where α < 1/2.
The function Φ defined by Proposition 20 takes particular values over rational numbers of the form r/2 k with r < 2 k odd. This lemma is the key point to get an exact formula in Theorem 5.
Thanks to Corollary 9, for all n ≥ k, we have
• To show that lim we make use of the uniform convergence and permute the two limits Observe that if α is close enough to 1, then the infinite word rep 2 (α) has a long prefix containing only letters 1. By definition, we get w n (α) = 1 n+2 and e n (α) = 2 n+2 −1.
In [13] we have showed that (s F (n)) n≥0 satisfies a recurrence relation of the same form as the one in Proposition 6. This sequence is F -regular. This notion of regularity is a natural generalization of 2-regular sequences to Fibonacci numeration system [1].
Proposition 26. We have s F (0) = 1, s F (1) = 2 and, for all ≥ 1 and 0 ≤ r < F ( − 1), The following result is the analogue of Corollary 7 and is obtained by induction.
The characteristic polynomial of the linear recurrence of (B(n)) n≥0 has three real roots as depicted in Figure 4. We let β ≈ 2.24698 denote the root of maximal modulus of X 3 − 2X 2 − X + 1. The other two roots are β 2 ≈ −0.80194 and β 3 ≈ 0.55496. From the classical theory of linear recurrences, there exist constants c ≈ 1.22041, c 2 ≈ −0.28011 and c 3 ≈ 0.0597 such that, for all n ∈ N, (12) B(n) = c β n + c 2 β n 2 + c 3 β n 3 . Thanks to Proposition 28, we have an analogue of Lemma 8.
Proof. Assume first that 0 ≤ r < F ( − 2). Applying Proposition 26 and Proposition 28, we get Let us prove the second part of the result by assuming that F ( −2) ≤ r < F ( −1). According to the second case of Proposition 26, we have Applying the first part of the result to the term A F (F ( ) + F ( − 2) − 1), we obtain and next, with Proposition 28, we get Similarly to the 3-decomposition of A(n) considered in Section 2.1, we will consider what we call the B-decomposition of A F (n). The idea is to apply iteratively Lemma 29 to derive a decomposition of A F (n) as a particular linear combination of terms of the sequence (B(n)) n≥0 . Indeed, each application of Lemma 29 provides a "leading" term of the form B( ) or 2B( ) plus terms of smaller indices. In this context, we choose to set A F (0) = 1 · B(0), A F (1) = 3 · B(0) and A F (2) = 6 · B(0).
Definition 30 (B-decomposition). Let n ≥ 3. Iteratively applying Lemma 29 provides a unique decomposition of the form We say that the word Bdec(A F (n)) := b 0 (n) · · · b F (n) (n) is the B-decomposition of A F (n). Observe that when the integer n is clear from the context, we simply write b i instead of b i (n). For the sake of clarity, we will also write (b 0 (n), . . . , b F (n) (n)).
As an example, we get  Table 2 displays the B-decomposition of A F (3), A F (4), . . . As in the base-2 case, observe that the B-decomposition is only defined for the integers (A F (n)) n≥0 . Remark 31. Assume that we want to develop A F (n) using only Lemma 29, i.e., to get the B-decomposition of A F (n). Only two cases may occur.
(i) If rep F (n) = 100u, with u ∈ 0 * rep F (N), then we apply the first part of Lemma 29 and we are left with evaluations of A F at integers whose normal F -representations are shorter and given by 10u and rep F (val F (u)). (ii) If rep 2 (n) = 101u, with u ∈ {ε}∪0 + rep F (N), then we apply the second part of Lemma 29 and we are left with evaluations of A F at an integer whose normal F -representation is shorter and given by 1u.
Lemma 13 is adapted in the following way.
Proof. The proof is similar to the proof of Lemma 13 and directly follows from Lemma 29.
If we compare the B-decompositions of A F (163) and A F (673), they share the same first five coefficients. In base 2, evaluation of A at powers of 2 is of particular importance. Here we evaluate A F at F (n) − 1.
Let us prove the second part of the result. We show that, for all n ≥ 3, Bdec(A F (F (n) − 1)) = (g 0 , g 1 , . . . , g n−2 , x), if n is odd; (g 0 , g 1 , . . . , g n−3 , y, z), if n is even; where x, y, z are integers. We proceed again by induction on n ≥ 3. One can check by hand that the result holds for n ∈ {3, 4} using Lemma 29. Thus consider n ≥ 4 and suppose the results holds for all m < n + 1. Suppose first that n is even. By Lemma 29, we have Using the induction hypothesis with Bdec(A F (F (n−1)−1)) = (g 0 , g 1 , . . . , g n−3 , x), we get By definition of the sequence (g n ) n≥0 , we have 2g j = g j+2 and we finally obtain which concludes the case where n is even. The case where n is odd can be proved using the same argument.
Let us prove the last part of the result. Using the definition of the sequence (g n ) n≥0 , we get Hence, since β 3 − 2β 2 − β + 1 = 0, we have The equality directly follows from the recurrence equation and the initial conditions defining the sequence (g n ) n≥0 .

3.3.
Behavior of the sequence (A F (N )) N ≥0 . Let ϕ be the golden ratio. In the following, we recall the notion of ϕ-expansion of a real number in [0, 1); for more on this subject and on numeration systems, see, for instance, [15,Chap. 7]. The ϕ-expansion of α ∈ [0, 1), denoted by rep ϕ (α), is the infinite word d 1 d 2 d 3 · · · satisfying i≥1 d i ϕ −i = α and for all j ≥ 1, Observe that d i d i+1 = 11 for all i ≥ 1. The idea in the next definitions is that α gives the relative position of an integer in the interval [F (n), F (n + 1)).
Definition 35. Let α be a real number in [0, 1). Define the sequence of finite words (w n (α)) n≥1 where w n (α) is the prefix of length n of the infinite word 10 rep ϕ (α).
Note that, since the ϕ-expansion of α does not contain any factor of the form 11, the word w n (α) is the normal F -representation of the integer e n (α) belonging to the interval [F (n − 1), F (n)).
To ensure convergence, a rough estimate is enough.
Lemma 39. For all n ≥ 3 and all 0 ≤ i ≤ F (n), we have In particular, for all α ∈ [0, 1) and all i ≥ 0, we have Proof. The proof follows the same lines as the proof of Lemma 22. Let us write n = F ( ) + r with ≥ 2 and 0 ≤ r < F ( − 1). Using Definition 30, let us write where b j (n) are integers, b 0 (n) = 0. Let us fix some i ∈ {0, 1, . . . , }. By Lemma 29, terms of the form are the only ones possibly contributing to b i (n).
Terms of the first form give either B( − i) or 2B( − i), depending on whether Terms of the second form with Mimicking the proof of Lemma 22, iterating Lemma 29 on A F (F ( ) + r) gives a linear combination of the form We conclude by observing that Let n be an integer such that rep F (n) = 10r 1 · · · r k with k ≥ 1 and r i ∈ {0, 1} for all i. We define Observe that relpos F (e n (α)) → α as n → +∞ and log F n = | rep F (n)| − 1.
Instead of considering rational numbers of the form r/2 k , we use the set which is dense in [0, 1]. The next result makes explicit the values taken by Ψ on the set D.
In the rest of the section, we prove the following result which is an equivalent version of Theorem 2.
A representation of Ψ is given in Figure 6. It has been obtained by estimating A F (N )/(c β log F N ) for N between 2584 and 4180. Proof. This proof is divided into four parts: the error term for the sequence (A F (N )) N ≥0 , the fact that Ψ(0) = 1, the limit lim α→1 − Ψ(α) = 1 and the continuity of the function Ψ.
• We first focus on the error term. Let rep F (N ) = 10r 1 · · · r k with k ≥ 1 and r 1 · · · r k ∈ {1, ε}{0, 01} * . Observe that k depends on N since k + 2 = | rep F (N )|. By definition, we have On the one hand, Lemma 41 gives On the other hand, we know that Thus, the error term is obtained by Let us divide the latter expression by β k+1 . Using (12), we get Firstly, we have again using Lemma 39. Hence , which tends to zero when k tends to infinity since β > β 2 and β > 2. This implies that R(N ) = o(β k+2 ).
Our aim is thus to show that which also tends to 0 as n tends to infinity. This shows that lim α→1 − Ψ(α) = 1.
• To finish the proof, let us show that Ψ is continuous. Let α ∈ [0, 1) and let us write rep ϕ (α) = (d n ) n≥1 . We make use of the uniform convergence of the sequence (ψ n ) n∈N and consider If we leave the k-regular setting and try to replace the Fibonacci sequence with another linear recurrent sequence, the situation seems to be more intricate. For the Tribonacci numeration system T = (T (n)) n≥0 built on the language of words over {0, 1} avoiding three consecutive ones, we conjecture that a result similar to Theorem 2 should hold for the corresponding summatory function A T . Computing the first values of A T (T (n)), the sequence (B(n)) n≥0 should be replaced with the sequence (V (n)) n≥0 satisfying V (n + 5) = 3V (n + 4) − V (n + 3) + V (n + 2) − 2V (n + 1) + 2V (n) ∀n ≥ 0 and with initial conditions 1, 3, 9, 23, 63. The dominant root β T of the characteristic polynomial of the recurrence is close to 2.703. There should exist a continuous and periodic function G T of period 1 whose graph is depicted in Figure 8 such that the corresponding summatory function has a main term in c T β log T (N ) T G T (log T (N )) where the definition of log T is straightforward. We are also able to handle the same computations with the Quadribonacci numeration system where the factor 1 4 is avoided. In that case, the analogue of the sequence (B(n)) n≥0 should be a linear recurrent sequence of order 6 whose characteristic polynomial is X 7 − 4X 6 + 4X 5 − 2X 4 − X 3 + 3X 2 − 6X + 2. Again, we conjecture a similar behavior with a function G Q depicted in Figure 8. Probably, the same type of result can be expected for Pisot numeration systems (i.e., linear recurrences whose characteristic polynomial is the minimal polynomial of a Pisot number).