On a probabilistic extension of the Oldenburger-Kolakoski sequence

The Oldenburger-Kolakoski sequence is the only infinite sequence over the alphabet $\{1,2\}$ that starts with $1$ and is its own run-length encoding. In the present work, we take a step back from this largely known and studied sequence by introducing some randomness in the choice of the letters written. This enables us to provide some results on the convergence of the density of $1$'s in the resulting sequence. When the choice of the letters is given by an infinite sequence of i.i.d. random variables or by a Markov chain, the average densities of letters converge. Moreover, in the case of i.i.d. random variables, we are able to prove that the densities even almost surely converge.

In [3], M.S. Keane asked whether the density of 1's in this sequence is 1/2.In [4], V. Chvátal showed that the upper density of 1's (resp.2's) is less than 0.50084.This bound has been slightly improved by M. Rao but Keane's question still stands: "Is the density of 1's in Oldenburger-Kolakoski sequence defined and equal to 0.5?"By definition, the Oldenburger-Kolakoski sequence O = (x n ) n∈N ⋆ is a fixed point of the run-length encoding operator denoted ∆: In [1], R. Oldenburger refers to sequences over an alphabet Σ as trajectories and refers to the sequence ∆(w) as the exponent trajectory of the trajectory w.He stated that "a periodic trajectory is distinct from its exponent trajectory" (Thm.2, [1]) and, therefore, the Oldenburger-Kolakoski sequence is not periodic.
The Oldenburger-Kolakoski sequence is also connected to differentiable words, C ∞ -words and smooth words [5][6][7].A sequence w over the alphabet Σ ⊂ N ⋆ is differentiable if and only if ∆(w) is also defined over the same alphabet Σ.The sequence ∆(w) is called the derivative sequence of w [7].A C ∞ -word, or smooth word, is an infinitely differentiable sequence.Obviously, the Oldenburger-Kolakoski sequence is a C ∞ -word since it is a fixed-point of the run-length encoding operator ∆.
Although not answering Keane's question fully, F.M. Dekking established connections between possible combinatorial properties of the Oldenburger-Kolakoski sequence [7]: if the Oldenburger-Kolakoski sequence is closed by complementation (that is, if w occurs in O then so does w with 1 = 2 and 2 = 1) then it is recurrent (any word that occurs in O does so infinitely often) (Prop.1, [7]).Moreover, the Oldenburger-Kolakoski sequence is closed by complementation if and only if it contains every finite C ∞ -word (Prop.2, [7]).
A few years later, A. Carpi stated that the Oldenburger-Kolakoski sequence contains only a finite set of squares (words of the form xx where x is not empty) and does not contain any cube (word of the form xxx where x is not empty) [8].Hence, since O contains only squares of bounded length then it cannot be the fixed point of a nondegenerated morphism: the image of a square w = xx by such a morphism is still a square longer than w.
There are several ways to extend the definition of the Oldenburger-Kolakoski sequence, depending on whether one wants to preserve the fixed point property or to follow the construction scheme without requiring the resulting sequence to be a fixed point for the run-length encoding operator ∆.For instance, one can deal with other alphabets and thus construct Generalized Oldenburger-Kolakoski sequence (GOK-sequence for short) as follows: for any pair (a, b) of non-zero natural numbers, there exists a unique fixed point O a,b of ∆ over the alphabet {a, b} starting with a. Also, according to this notation, the original Oldenburger-Kolakoski sequence is O 1,2 .For instance, if a = 1 and b = 3, the first terms of O 1,3 are: A significant result is, unlike the case of the original Oldenburger-Kolakoski sequence, that the densities of 1's in O 1,3 and O 3,1 are known and approximately 0.3972 [9].Generalized Oldenburger-Kolakoski sequences are also connected with smooth words over arbitrary alphabets [10,11].As for the (Generalized) Oldenburger-Kolakoski sequences, the properties of smooth words are better known for alphabets with letters of the same parity: for instance, while the frequency of letters in an infinite smooth word over {1, 2} is still unsolved, in [11] the authors showed that the frequency of letters for extremal smooth words (for the lexicographic order) over the alphabet {a, b}, where a and b are both even, is 0.5.They also computed the frequency for extremal smooth words over alphabets of type {1, b}, where b is odd.Moreover, if a and b have the same parity, then every infinite smooth word over the alphabet {a, b} is recurrent [11].Also, if a and b are both odd, then every infinite smooth word is closed under reversal but not under complementation [11].On the other hand, if a and b are both even, then the extremal smooth words over the alphabet {a, b} are neither closed under reversal nor closed under complementation [11].
For a more detailed survey on the Oldenburger-Kolakoski sequence and on generalizations over arbitrary two letter alphabets, see [12].
In the present paper, we extend the Oldenburger-Kolakoski sequences by introducing the following notion of self-descriptive sequences.Given a sequence T = t 1 t 2 t 3 . . .over the alphabet {a, b} (with a, b ∈ N ⋆ and a ̸ = b) called the directive sequence, we say that the self-descriptive sequence directed by T is the sequence O T = x 1 x 2 x 3 . . .over {a, b} satisfying: Observe that the (original) Oldenburger-Kolakoski corresponds to the special case where the directive sequence is the periodic sequence T = (12) ∞ .We investigate the potential relationships between densities in T and (if any) in O T , for both deterministic and random directive sequences.The present paper is organized as follows: In Section 2, we introduce the notion of self-descriptive sequence O T directed by a sequence T over an alphabet {a, b}, and provide some related definitions.
In Section 3, we deal with the case where the terms of the directive sequence T = (T n ) n∈N ⋆ are drawn randomly and independently.We show that, given p ∈]0, 1[, if P (T n = 1) = p for all n ≥ 1, then the density of 1's in O T tends to p, almost surely (Thm.3.5).
In Section 4, we consider the case where the directive sequence T = (T n ) n∈N ⋆ is given by a Markov chain with initial value 1 and with transition probability p ∈]0, 1[ from 1 to 2 and from 2 to 1.We then show that, on average, the density of 1's in O T tends towards 1/2 (Thms.4.1 and 4.4).The motivation behind this work is to get closer to the Oldenburger-Kolakoski sequence: indeed, when p tends towards 1, the directive sequence tends to the periodic sequence (12) ∞ and thus O T converges to the Oldenburger-Kolakoski sequence.
In both previous cases, the densities of the letters in the directive sequence T are, almost certainly or on average, identical to those in O T .If the directive sequence T is periodic, simulations also suggest that T and the sequence directed by T have the same densities, and this seems to be true for even larger families of directive sequences.In Section 5, we provide, on the contrary, an example of deterministic sequences T and O T that cannot share the same densities (Thm.5.2).
2. Extending the construction scheme to any directive sequence Beyond the specific case of the sequence (ab) ω , this construction scheme can be extended to any finite or infinite sequence T = t 1 t 2 . . .over {a, b} as follows: "the n th block of O T = x 1 x 2 . . . is of length x n and is filled with the letter t n " (see Program 1).
Whether T is finite or infinite, we say that the sequence O T is directed by the sequence T , and that T is a directive sequence of O T .For instance, the sequence O a,b is directed by (ab) ω so that O a,b = O (ab) ω .In particular, the Oldenburger-Kolakoski sequence O is directed by ( 12) ω .
Notice that, in general, the directed sequence O T may no longer be a fixed point of the operator ∆.
Let us illustrate the construction of a directed sequence by considering the example of the directive sequence T = (τ n ) n∈N ⋆ = 21122 . . .We read the digits of T , one by one, from left to right: Step 1: Since τ 1 = 2, then O T starts with 2. Hence, the first block of O T is of length 2. It follows that O T = 22 . . . .Furthermore, since the second term of O T is 2, we also know that the second block of O T is of length 2 without knowing, for the moment, how it will be filled.We will denote: O τ1 = 22 ?? .
Step 2: Since τ 2 = 1, we now know that we can fill the second block of O T by 1's.Furthermore, knowing the third and the fourth letters of O T provides information on the length of its third and its fourth blocks: O τ1τ2 = 22 11 ?? .
Step 3: Since τ 3 = 1, we fill the third block of O T with a 1 and it follows that: And so on. . .Let us go back to the general case of a directive sequence T = (t n ) n∈N ⋆ .For n ∈ N ⋆ , let w n = O t1...tn .We denote by |w n | the length of w n , including question marks.Observe that it is equal to the sum of the digits 1 and 2 occurring in w n .For instance, in the example above, O τ1τ2τ3 is of length 7, that is 2 + 2 + 1 + 1 + 1.

Partitions of the set of directive sequences
We now introduce some subsets of directive sequences that will be crucial in the following sections.For this purpose, let us classify the sequences T according to the information they provide on the length of the blocks of O T : let k and n be two integers such that 1 ≤ k ≤ n and let S n,k be the set of sequences T = (t n ) n∈N ⋆ such that the length of the block of O T containing its n th letter is known when reading t k but not before.Formally, recalling that w n = O t1...tn for n ≥ 1 and setting w 0 = ε, namely the empty word, we have: and As an example, let us illustrate the definition of S 8,k with the same sequence T = (τ n ) n∈N ⋆ = 21122 . . .as in the previous paragraph.After having read τ 1 , τ 2 and τ 3 , we obtain w 3 = 22 11 1 ??and we still do not know the length of the block of O T containing its 8 th term.But, whatever the value of τ 4 , |w 4 | ≥ 8, so that T ∈ S 8,4 .
More generally, one shows that the sets S 8,k , with k ∈ 1; 8 , partition the set {1, 2} N ⋆ as follows:

Sequence directed by independent random variables
In the present section, T = (T n ) n∈N ⋆ is a sequence of independent and identically distributed random variables (i.i.d. for short) over the two-letter alphabet A = {1, 2}, with P(T n = 1) = p and P(T n = 2) = 1 − p for each n ∈ N ⋆ , where p is a fixed parameter in ]0, 1[.The sequence T is thus distributed according to the product distribution Let X = (X n ) n∈N ⋆ be the sequence directed by T. The sequence X is a random sequence with a priori unknown distribution.Assume that one wants to compute the n th letter X n of X, for some large integer n.Unless the sequence T begins with a long succession of 1's (an event which has a low probability to occur), one just has to read the first terms T 1 , . . ., T k of T, until knowing the length and position of the block containing X n .Then, one fills that block with 1's with probability p, or with 2's with probability 1 − p, independently of previous draws.The resulting value of X n obtained that way will have the desired distribution.This leads to the fact that lim n→+∞ P(X n = 1) = p, and we can even use this observation to compute more precisely the value of P(X n = 1), as shown in the following proposition.
Proof.Let us decompose the event {X n = 1} according to the partition {S n,k : k ∈ 1; n } of {1, 2} N ⋆ introduced in the previous section, and use the equalities (2.1) and (2.2).The following two particular cases are obvious: Let us now suppose that T ∈ S n,k , with k ≤ n − 2 and let us show that: In fact, it is sufficient to prove that, if T ∈ S n,k , then the n th letter of w k is a question mark and will be determined, conditionally on the event T ∈ S n,k , by an independent draw.
By definition, Let i be the smallest integer such that T i = 2.Then, w i−1 = 1 i−1 and w i = 1 i−1 22 ?? .Moreover, for all j ≥ i, w j ends with a block of question marks.Indeed when one reads a letter in T , one fills exactly one block and creates at least one block of question marks.
Two cases occur: then the last block of w k−1 is a block of question marks which ends at a position strictly smaller than n.When reading T k , we fill exactly one block which already exists in w k−1 , so it can't be the block containing the n th term of w k .Since T ∈ S n,k , |w k | ≥ n and the n th letter of w k is a question mark.
In both cases, the n th letter of w k is a question mark so that P( Finally, we use the formula of total probability: As a corollary, we obtain the following convergence of the proportion of 1's in X. By Proposition 3.1, we have lim n→+∞ P(X n = 1) = p and lim n→+∞ P(X n = 2) = 1 − p.We deduce that lim n→+∞ E(X n ) = 2 − p.By Cesàro lemma, we obtain: Each time we run a simulation with T ∼ (pδ 1 + (1 − p)δ 2 ) ⊗N ⋆ , the frequency of 1's in X seems to converge to p.We thus expect the sequence |X 1 . . .X n | 1 /n to converge almost surely to p, and not only in expectation.Since the random variables (X n ) n∈N ⋆ are correlated, we can not directly apply the strong law of large numbers (SLLN) to prove the almost sure convergence of (X 1 + ... + X n )/n.However, the correlations being sufficiently weak, we can apply the following stronger version of the SLLN.Theorem 3.3 (Lyons [13]).Let (Y n ) n∈N ⋆ be a sequence of real-valued random variables such that for all n ∈ N ⋆ , In order to apply Theorem 3.3, let us first prove the following lemma.Proof.Since S n,n ∩ (X m = 2) = ∅ and S n,n−1 ∩ (X m = 2) = ∅, we have It follows that: Let us now prove that: It is equivalent to proving that when the events X m = 2 and T ∈ S n,k are not incompatible, Let i be the integer such that the letter X m is given by T i .We can decompose the event T ∈ S n,k into the two following cases.
1.If i > k, then after reading T 1 . . .T k , we know the size of the blocks containing X m and X n but not their content.In other words, there are question marks at positions m and n in w k .Furthermore, since n − m ≥ 2, then X m and X n do not belong to the same block and their values will be determined by independent draws.In particular, the addtionnal information that X m = 2 does not affect the probability of having X n = 1. 2. If i ≤ k, then after reading T 1 . . .T k , one already knows whether X m = 2, but still does not know the value of X n , which will be drawn independently.
In all cases, we have: We deduce that We can now state the following theorem.
Proof.In order to apply Theorem 3.3, we need to center the random variables (X n ) n∈N ⋆ .For n ∈ N ⋆ , we thus introduce the random variables Xn = X n − (2 − p), in order to have | Xn | ≤ 1 and lim n→+∞ E( Xn ) = 0. Now, let us exploit Lemma 3.4 to compute E( Xm Xn ), for n ≥ m + 2. We have Gathering these values and using Proposition 3.1, we obtain To conclude on the case of a directive sequence following a product distribution, let us mention that the previous results can be extended to other alphabets.In particular, Proposition 3.1 is extended as follows.

Proof.
1. We use the same partition as in the proof of Proposition 3.1, but we now distinguish the sets S n,k then for the same reason as before, P(X n = 1 | T ∈ S n,k ) = 0.In all the other cases, P(X n = 1 | T ∈ S n,k ) = p.Thus, 2. Since a > 1, for all k ∈ N ⋆ , w k ends by at least one block of question marks.Thus, except if n ≤ b (in which case the n th letter might be written during the first step), we are sure that we will know the length of the block containing the n th letter strictly before filling it.As the draws are independent, we deduce that P(X n = a) = p.

Sequence directed by a Markov chain
In order to get closer to the deterministic case where a 1 always follows a 2 and vice versa, we are now interested in the case of directive sequences which are given by Markov chains.
In the present section, we assume that the directive sequence T = (T n ) n∈N ⋆ is a Markov chain over the alphabet {1, 2} with initial value T 1 = 1 and whose transition probability from 1 to 2 (and from 2 to 1) is p ∈]0, 1[.A large value of p encourages the alternation between 1 and 2. The original case of the Oldenburger-Kolakoski sequence can be viewed as a "limit" case of a Markov chain whose transition probability from 1 to 2 (and from 2 to 1) would be equal to 1. Proof.Let us first note that for all integers s > r ≥ 1, If T 1 . . .T ⌊n/4⌋ contains at least 2ℓ occurences of 2, then so do T 1 . . .T k and w k .This implies that w k contains at least 2ℓ question marks and thus, at least, ℓ blocks of question marks.Let D be the number of blocks of question marks in w k .It follows that: and the probability on the right tends to 0 as n tends to +∞.
Let i be such that X n is given by T i .For a ∈ {1, 2}, one has: We deduce that: Finally, by letting ℓ tends to +∞, we obtain lim n→+∞ P(X n = 1) = 1 2 .As a direct consequence of Theorem 4.1, we obtain the following result.
Corollary 4.2.Let p ∈]0, 1[ and let T be a Markov chain over the alphabet {1, 2} with initial value T 1 = 1 and whose transition probability from 1 to 2 (and from 2 to 1) is p ∈]0, 1[.Then We conjecture that the almost sure convergence can be proved in a similar way with some additional technical difficulties.Observe that Theorem 4.1 and Corollary 4.2 extend to other alphabets.In particular, one obtains an identical result over the alphabet {1, 3}: if T is a Markov chain with transition probability 0 < p < 1 from 1 to 3 (and from 3 to 1), then the average density of 1's is 1/2.Theorem 4.4.Let a ≥ 2 be an integer, let p ∈]0, 1[ and let T be a Markov chain over the alphabet {1, a} with initial value T 1 = 1 and whose transition probability from 1 to a (and from a to 1) is p ∈]0, 1[.Then and The statement of Theorem 4.4 is somewhat surprising and unexpected since the densities d 1 and d 3 of the letters 1 and 3 in the sequences O 1,3 and O 3,1 are respectively d 1 ≈ 0.3972 and d 3 ≈ 0.6028.[9].We will come back to this in the discussion of Section 6.

Non conservation of the density
In previous sections, we have studied different cases where the directive sequences are random.In all the cases we considered (sequences of independent and identically distributed random variables, Markovian sequences), the densities of letters of the directed sequence obtained are the same as those in the directive sequence, almost surely.
Simulations also suggest that for any (infinite) periodic sequence T , the density of 1's in the directed sequence O T is well-defined and is equal to the density of 1's in T , see Figure 1.
On Figure 1, we have chosen to represent only the data on short prefixes of O T so that it remains readable, especially to distinguish the densities in the very first terms of the sequence O T .However, further experiments have been carried out on a large number of periodic sequences T and they seem to corroborate our first impression, namely that if the sequence T is periodic, then the densities in O T would be the same as those in T .This leads us to state the following conjecture, that extends Keane's conjecture.
Conjecture 5.1.For any periodic sequence T over the alphabet {1, 2}, the density of 1's in the directed sequence O T is well-defined and is equal to the density of 1's in T .
Then, a natural question arises: does there exist a directive sequence T over {1, 2} for which the density of 1's in T is not conserved in O T ?Obviously, because of Conjecture 5.1, we do not expect to find such a candidate of directive sequence among the periodic ones.
However, we answer this question partially and positively thanks to the fact that the left-to-right reading of O T provides the size of the blocks even further to the right (see Sect. 2).In a prospect of building step by step both sequences T and O T , the knowledge of the length of not yet filled blocks of O T could allow us to choose, in a fully arbitrary way, with which letter we will fill them and it could give us the opportunity to force the sequence O T to contain relatively more 1's than the sequence T .
More precisely, we construct simultaneously a directive sequence T = (τ n ) n∈N and the sequence O T directed by T as follows: we initialize τ 1 to 2, then w 1 = O τ1 = 22 ?? and from now on, by reading w n = O τ1...τn from left to right, we build w n+1 by filling the blocks of size 2 with 1's and the blocks of size 1 with 1's and 2's alternatively.The first steps in the simultaneous construction of T and O T are thus as follows (with the notation of Sect.2): Step 1: We set τ 1 = 2 and then w 1 = 22 ??
Step 2: (a) The empty block of w 1 of size 2 is filled with 1's:

Conclusion and discussion
Over the alphabet {1, a}, with a ∈ {2, 3}, we have shown that in almost all the sequences directed by an infinite sequence T = (T n ) n∈N ⋆ of i.i.d.random variables with P(T n = 1) = p ∈]0, 1[ and P(T n = a) = 1 − p, the density of 1's is equal to p.We have also shown that the average density of 1's among all sequences directed by a Markov chain with transition probability p ∈]0, 1[ from 1 to a and from a to 1 is equal to 1/2.
Keane's conjecture [3] states that this result can be extended to the deterministic case, namely when p = 1, over the alphabet {1, 2}.On the other hand, over the alphabet {1, 3} this result is not extendable to the deterministic case since the density of 1's in O 1,3 is close to 0.3972.[9].
When T is a Markov chain, the closer its transition probability p is to 1, the more likely the sequence O T is to share a long prefix with O 1,3 .Therefore, the closer the transition probability p is to 1, the closer the density of 1's in the sequence O T is to that in the sequence O 1,3 on a long prefix.However, computer experiments suggest that when the first perturbations in the alternation of 1's and 3's appear in T, the density of 1's in the prefix of O T eventually approaches 0.5 as this prefix gets longer.See Figure 3 for an illustration with p = 0.99.
This implies it seems difficult to derive information about the original Oldenburger-Kolakoski sequence O 1,2 by letting p tend to 1 in the Markovian case over the alphabet {1, 2}.
Finally, the study of sequences directed by random sequences on alphabets of more than 2 letters or by random sequences constructed from other distributions is also largely open.

2. 1 .
Notion of directive sequence In the construction scheme of a Generalized Oldenburger-Kolakoski sequence, the blocks of O a,b are composed, alternatively, of a's and b's as shown in (1.1) when a = 1 and b = 2 and in (1.3) when a = 1 and b = 3.In other words, the n th block of O a,b = (x n ) n∈N ⋆ is of length x n and is filled with the letter τ n , where (τ n ) n∈N ⋆ = (ab) ω .

w 2 =Figure 2 : 1 and d O T 2 an..
Figure 2: Evolution of the densities of 1's in O T (blue) and T (black), where the two sequences are defined by Program 2.