Automata on -Adic Words
Abstract
A fundamental question in logic and verification is the following: for which unary predicates is the monadic second-order theory of decidable? Equivalently, for which infinite words can we decide whether a given Büchi automaton accepts ? Carton and Thomas showed decidability in the case that is a fixed point of a letter-to-word substitution , i.e., . However, abundantly more words, e.g., Sturmian words, are characterised by a broader notion of self-similarity that involves a set of substitutions. A word is said to be directed by a sequence over if there is a sequence of words such that and for all ; such are called -adic. We study the automaton acceptance problem for such words and prove, among others, the following: given finite and an automaton , we can compute an automaton that accepts if and only if directs a word accepted by . Thus we can algorithmically answer questions of the form “Which -adic words are accepted by a given automaton ?”
Keywords and phrases:
Sturmian words, S-adic words, automata theory, word combinatoricsCategory:
Track B: Automata, Logic, Semantics, and Theory of ProgrammingFunding:
Valérie Berthé: supported by the Agence Nationale de la Recherche through the projects SymDynAr (ANR-23-CE40-0024) and IZES (ANR-22-CE40-0011), as well as the ERC Synergy Grant DynAMiCs (101167561).Copyright and License:
2012 ACM Subject Classification:
Theory of computation Logic and verificationAcknowledgements:
The authors are grateful to the anonymous reviewers for their helpful suggestions.Editors:
Sayan Bhattacharya, Danupon Nanongkai, Michael Benedikt, and Gabriele PuppisSeries and Publisher:
Leibniz International Proceedings in Informatics, Schloss Dagstuhl – Leibniz-Zentrum für Informatik
1 Introduction
In 1962, Büchi proved that the monadic second-order (MSO) theory of the structure is decidable [8], and, in doing so, laid the foundations of the theory of automata over infinite words. Subsequently, Elgot and Rabin [12] adopted automata-theoretic techniques to show how to decide the MSO theory of for various interesting unary predicates including and . By then, it was already known that unary predicates lay at the frontiers of decidability: expanding with most natural functions (e.g., addition or doubling) or non-unary predicates yields undecidable MSO theories [23, 27, 26]. The question thus arose: for which unary predicates is the MSO theory of decidable? Equivalently, for which infinite words is the automaton acceptance problem111Here the problem is parametrised by ; the only input is the automaton ., which asks whether a given automaton accepts , decidable?
The automaton acceptance problem under various assumptions on has been studied, among others, by Semënov, Carton and Thomas, and Rabinovich [24, 10, 22]. Semënov [24] showed decidability for words that are effectively almost-periodic. These include, for example, the Thue-Morse word and toric words, which are obtained from certain compact dynamical systems [7]. Carton and Thomas [10], on the other hand, used algebraic methods to show decidability for morphic words , which include that can be constructed by infinitely iterating a letter-to-word morphism on a starting letter . Their result implies, in one fell swoop, the decidability of the MSO theory of where and is a polynomial with integer coefficients satisfying .
By now, the study of the automaton acceptance problem for various special classes of has led to rich interactions between word combinatorics, algebra (particularly monoid and group theory), number theory, and formal verification. For example, effectively almost-periodic words of Semënov have been identified as a powerful tool for analysing the behaviour of linear loops in program verification [19]. More recently, [6] showed the decidability of the MSO theory of using the fact that the order in which powers of coprime and occur is effectively almost-periodic by virtue of being captured by a computable Sturmian word (Sec. 3.2). Sturmian words are an extremely well-studied and fundamental class of “special words” that appear naturally in a range of fields including number theory, computer graphics, and astronomy [1, Chap. 9.6], [13, Chap. 6]. We refer the reader to [7] for a more detailed survey of the role of Sturmian words, and word combinatorics in general, in logic and verification.
In this paper, we are motivated by questions of the form, “Given an -regular language , decide whether it contains a Sturmian word.” (Of course, we can also ask about any other combinatorial class.) Our approach adopts the -adic perspective, a powerful tool for elucidating combinatorial properties of infinite words. Akin to the continued fraction expansion of a real number, or even a Fourier decomposition of a signal, we write an infinite word as an infinite composition of (possibly different) substitutions. A substitution over an alphabet gives rules to replace each letter with a non-empty word . For example, the Fibonacci substitution over replaces with and with ; the Fibonacci word is obtained as the limit of iterating infinitely on the letter (or, alternatively, the letter 1). Hence we have the infinite decomposition . In general, we have a set of substitutions, and say that a sequence over directs if there exists a sequence of words such that , and for all . This gives us the -adic decomposition . We refer to any as a directive sequence.
An observant reader might argue that every word is vacuously -adic for over the alphabet , where replaces the distinguished letter with and is the identity function elsewhere, and replaces with and is the identity function elsewhere. We then see that is directed by . The vacuous construction notwithstanding, the point of directive sequences is to provide a perspective that conveys more structural information about the word. E.g., characteristic Sturmian words are parametrised by directive sequences over the alphabet such that both letters occur infinitely often; a directive sequence encodes the continued fraction expansion of the slope of its Sturmian word. We show that this alternate perspective can still be used for verification, even when it does not give a vacuous reformulation of the word.
Indeed, entire classes of words such as Sturmian and Arnoux-Rauzy words (Sec. 3.2) can be parametrised in terms of directive sequences over a specific ; such a class is called -adic. Our central question is the following: given an -regular language and an -adic class of words , what is the set of all that are contained in ? Does there exist at least one such ? Equivalently, given an MSO formula , can we decide whether there exists that induces a structure in which holds? We remark that this question is similar in spirit to the problem solved in [17]: given a first-order formula , it is decidable whether there exists a Sturmian word such that holds in the induced first-order structure . The key idea there is that the class of structures , where ranges over all Sturmian words, is automatic [25].
Our main contribution is that -regular specifications on words in the -space translate to -regular constraints on the directive sequences in the -space of substitutions. Hence the common MSO theory of an -adic class of words is decidable. This generalises the result of [2] (in particular, Cor. 3 ibidem) that, given finite and an automaton whose language is closed (i.e., a Büchi automaton whose states are all accepting), the set of sequences over that direct a word accepted by constitutes a closed -regular language, which is moreover computable. We consider arbitrary -regular languages, are equipped to handle both directed words and generated words, and relax the finiteness assumption on .
Our algorithms thoroughly answer questions of the kind “Which -adic words are accepted by a given automaton ?” by translating it to, “Which parametrising directive sequences are accepted by the constructed automaton ?” For example, given two words and with , we can compute an effective representation (as an -regular language of directive sequences) of all Arnoux-Rauzy words in which between any two consecutive occurrences of , the number of occurrences of is congruent to modulo .
Outline and contributions of the paper
In Sec. 2 we establish the necessary mathematical background. In Sec. 3 we formally define what it means for a directive sequence to generate and to direct a word. Briefly, a sequence of substitutions generates if there exists a sequence of letters such that ; generating a word is a strong form of directing it. We then recall well-known properties of directive sequences, the most important of them being weak primitivity, and then describe Sturmian and Arnoux-Rauzy words, which are the best-known examples of -adic words (see e.g., [13, 4]).
In Sec. 4 we study the structure of words directed or generated by directive sequences. Our key insight is the augmentation of a directive sequence over222Our set of substitutions could possibly be infinite. The technically advanced reader might identify that a directive sequence induces an ordered Bratteli diagram whose vertices are letters of , and there is an edge between in level and in level labelled if occurs in the -th position of . Congenial expansions mark minimal paths in this diagram, and are guaranteed to exist by König’s lemma. This remark may be ignored by a reader unfamiliar with this terminology. into a congenial expansion over (Def. 9), which generates a word incrementally and predictably (Lem. 10). We prove the following pivotal results.
In Sec. 5 we introduce our second key ingredient, namely a suitable equivalence relation of finite index on substitutions. Intuitively, we take the “quotient” of the monoid of substitutions modulo the syntactic monoid of a given -regular language (Prop. 16); we denote the finite set of equivalence classes by . Given a sequence over the set of substitutions or a sequence over , we naturally define its trace to be, respectively, a word over or over . In Sec. 6 and 7 we use our two key ingredients, the notion of congeniality together with the monoid of equivalence classes, to prove our main results.
- Morphic Words.
-
Let be an automaton over , and be substitutions. Using only the respective equivalence classes of the latter, we can compute a regular language such that the word is well-defined and accepted by if and only if (Thm. 21). We can thus characterise all such , which generalises the result of [10] that it is decidable whether a given morphic word is accepted by .
- Generated Words.
-
Given an automaton over , we can construct an automaton over such that accepts the trace of if and only if is congenial and generates a word accepted by (Thm. 23).
- Directed Words.
In Sec. 8, we refine our main results for Sturmian and Arnoux-Rauzy words, which have an a priori known factor complexity (Sec. 2.3). We show that for such classes, acceptance by is completely determined by finitely many (depending only on and not ) partial quotients of the directive sequence (Thm. 30). In the case of Sturmian words, this has a nice geometric interpretation: an automaton can only resolve the slope and intercept associated with a Sturmian word up to a “pre-determined” finite precision.
2 Preliminaries
An alphabet is a finite set of symbols. Throughout this paper we assume that , i.e. we have at least two distinct letters. We write for the empty word. For a word , denotes the letter at the th position of , denotes the finite word , and denotes the infinite word . A finite word is a factor of a word if there exist indices such that . When we say that an object is computable, we mean that a representation in a scheme (that will be clear from the context) is computable.
A substitution is a non-erasing morphism from to , i.e., if and only if . We denote the set of all such substitutions by . For substitutions , we write for . A substitution is positive if every appears in for all , and left-proper if the images of all letters by begin with the same letter. For more on the subject of substitutions, see e.g., [13].
2.1 Topology of finite and infinite words
We equip with the product topology, and define the distance between distinct words to be , where is the first position in which they differ. E.g., distinct are a distance of apart. A notion of convergence of sequences of words follows naturally.
Definition 1.
Let be a sequence of finite non-empty words. We define as follows.
-
If there exists and such that for all , , then .
-
If there exists such that for all , for all sufficiently large , then .
-
Otherwise, , which denotes lack of convergence in .
Under this topology, is compact. The cylinder sets defined by fixing finitely many letters are both closed and open.
2.2 Automata and semigroups for infinite words
We consider infinite words and -regular languages from the algebraic and combinatorial perspectives. A language is -regular if and only if it can be recognised by a (nondeterministic) Büchi automaton , where is the alphabet, is the finite set of states, is the set of initial states, is the transition relation, and is the set of accepting states. A run of the automaton on an input word satisfies , and for all , . A word is accepted if it has a run such that for infinitely many .
Some of our technical tools, e.g., Semënov’s theorem, require the automaton to be deterministic, i.e., there must be a single initial state, and the transition relation must induce a function . For this reason, we also use deterministic parity automata, which are further equipped with a function . In the case of deterministic parity automata, a word has a single run , and is accepted if is even. Deterministic parity automata recognise precisely the class of -regular languages. For such and , we write for the sequence of states visited when reads .
We now recall -semigroups (see [21, Sec. 7]) as an equivalent way to recognise -regular languages. Formally, an -semigroup is a two-sorted algebra equipped with the following operations:
-
1.
A binary operation defined on and denoted multiplicatively,
-
2.
A mapping , called the mixed product, also denoted multiplicatively,
-
3.
An infinite product that maps infinite sequences over to an element of .
These operations must satisfy the following associativity properties:
-
1.
, equipped with the binary operation, is a semigroup.
-
2.
For every and , we have that .
-
3.
For every sequence over , and every strictly increasing sequence of indices, we have that .
-
4.
For every and every sequence over , we have that .
The last two conditions show that the infinite product can also be denoted multiplicatively as . Indeed, an -semigroup can be intuited as a semigroup where infinite products are defined. An immediate example is with word concatenation, where , and .
Given -semigroups a morphism of -semigroups is a pair such that is a semigroup morphism from into , and is a map from to preserving the mixed product and infinite product, i.e., for every and , , and for every sequence over , we have . We shall thus omit subscripts and denote the application of a morphism by simply . As an immediate example, a non-erasing substitution defines a morphism from to .
A set is recognised by a morphism from into an -semigroup if there exists a subset such that . A language is -regular if and only if it is recognisable by a finite -semigroup [21, Thm. 7.6]. See [21, Sections 8,9] respectively for effective translations from Büchi automata to -semigroups, and vice versa. Furthermore, analogous to the finite-word case, there is a notion of the (finite) syntactic -semigroup of an -regular language [21, Sec. 11].
A few remarks addressing presentation concerns are in order. A result of Wilke [28] showed that for finite -semigroups , the infinite product is fully determined by the function that maps to [21, Thm. 7.1]. This combinatorial result is proven through Ramsey’s theorem, and gives a method to construct -semigroups through Wilke algebras. We refer the reader to [21, Sec. 7] for details of how the semigroup structure of determines an extension into an -semigroup through linked pairs.
We use the equivalence of finite -semigroups and automata through the following lemma.
Lemma 2.
Let be a finite -semigroup, and . Extend into a monoid by adjoining a distinguished neutral element : for all , . We can construct an automaton over the alphabet that accepts if and only if the infinite product (defined as the possibly finite product of the subsequence obtained by discarding all terms) equals .
For example, consider the -regular language over the alphabet , i.e., the language of infinite words containing infinitely many occurrences of the letter . We recognise it algebraically as follows. Let , where . Let , where and . We define the morphism to map to , and to . Observe that a word is in the language if and only if .
2.3 Uniformly recurrent words
For a word , the set is called the (factor) language of . The factor complexity function computes the number of factors of of a given length . For example, if is Sturmian, then for all (see e.g., [13]).
For an infinite word and , denote by the smallest such that every factor of of length is a factor of every factor of of length . We call the recurrence function of . A word is said to be uniformly recurrent if for every . That is, every either does not occur in , or occurs infinitely often with bounded gaps. It is clear from the definition that for uniformly recurrent , the value of only depends on . We record the following, which follows by brute enumeration.
Lemma 3.
Let be uniformly recurrent. Suppose we have access to an oracle that, given , checks whether . Then we can effectively compute .
Semënov [24] gave an algorithm333Semënov’s result applies to the more general family of effectively almost-periodic words [20]. for determining whether a given deterministic automaton accepts a given uniformly recurrent word , which is represented by (A) an oracle computing on input and (B) an oracle computing an upper bound on given .
Theorem 4 (Semënov).
Let be a deterministic automaton and be a uniformly recurrent word represented by the oracles (A-B). We can effectively compute such that a state of appears infinitely often in if and only if it appears in .
In other words, to check whether accepts , we simply need to run on for steps, and observe the states that are visited. See [18, Chap. 3.1] for effective bounds on , from which we can deduce the following.
Proposition 5.
Let be a deterministic automaton and be a uniformly recurrent word represented by the oracles (A-B). We can compute such that for any uniformly recurrent with and for all , we have that accepts if and only if it accepts .
2.4 Ostrowski numeration system
We recall properties of a numeration system which proves to be particularly convenient to describe any Sturmian word in -adic terms [13]. Let . The continued fraction expansion of is the unique sequence of positive integers such that
We write . The convergents of are obtained by truncating the expansion at the -th level. The numerators and denominators satisfy the recurrences , , , , and for all . The convergents are the locally best approximants of : for every , , and ,
which implies that . The Ostrowski numeration system in base is based on the sequence . For any , there exists a sequence over such that (i) , (ii) for all , (iii) for all , if , and
We refer to as an Ostrowski expansion of in base . Conversely, every satisfying (i-iii) is an Ostrowski expansion of some in base , i.e., the infinite sum converges to a value in .444To check this, observe that alternates between positive and negative; , ; . If or if , then has a unique Ostrowski expansion in base . Otherwise, can have two expansions in base . For more on the subject, see e.g., [9].
3 -adic words
We now establish basic definitions and facts about -adicity; see e.g., [4] for more on the subject, with examples being provided in Sec. 3.2.
3.1 Directive and generating sequences
Let be an alphabet and be a possibly infinite set of non-erasing substitutions. We refer to as -directed if there exists a sequence over and a sequence of words over such that and for all ; note that each word in the sequence is the image of the subsequent one. We say that directs . A word is called -generated if there exists a sequence over such that
| (1) |
We refer to as an -adic expansion of . For finite or infinite , whenever (1) holds we say that generates . In both the -directed and the -generated settings (to which we collectively refer as -adic), is called a directive sequence.
Lemma 6.
If is generated by over , then it is also directed by . Furthermore, every over directs at least one non-empty word .
Proof.
We will first prove a slightly more general version of the first statement. Let be a sequence of letters and for all . Suppose is an accumulation point of , which subsumes the case of being generated by . We will inductively prove the existence of such that , , and is an accumulation point of for all . The base case is immediate.
For the inductive step, suppose we have constructed with the properties above. Write , and observe that by the induction hypothesis, is the limit of some sequence . By compactness, the sequence itself has an infinite subsequence that converges. We choose to be the limit, which is an accumulation point of . By the continuity of ,
which implies that .
To prove the second claim, choose an arbitrary sequence of letters and let be an accumulation point of . Apply the preceding argument. The converse of the lemma above, however, is not true: take to be the sequence of identity morphisms. We next study various special classes of -adic words with which we will work.
Definition 7.
A sequence over is weakly primitive if for every there exists such that is positive, i.e., for every , the letter appears in .
If is weakly primitive, then we can compute a sequence of increasing integers with such that is positive for all . Consequently, for any sequence of letters we have that ; this is known as being everywhere growing. A word directed by a weakly primitive sequence is uniformly recurrent [11].
The directive sequences with which we will work generate (and, as we will show in Sec. 4, direct) a unique word due to left-properness.
Lemma 8.
Let be weakly primitive with infinitely many left-proper terms. Then there exists a unique word such that for any , generates .
Proof.
Let be an increasing sequence such that and is left-proper for . Further, let be such that all images of begin with . Then . This limit exists and is infinite because the terms of the sequence are strict prefixes of one another. Now take , where is arbitrary. Then must agree with on the first letters, where is maximal with the property that . Since becomes arbitrarily large as , we have that .
3.2 Sturmian and Arnoux-Rauzy words
We now illustrate the concepts above through examples. Let . The characteristic Sturmian word with slope is defined by
| (2) |
for . For instance, the Fibonacci word has , where is the golden ratio. Characteristic Sturmian words are -directed for where maps to and the other letter to , i.e., it inserts to the left.
The word is intimately connected to the continued fraction expansion of . Suppose . We then have that is the unique word directed by the sequence
which we denote by . For example, has the continued fraction expansion , and hence the Fibonacci word is directed by . Observe that are left-proper. Moreover, for every , we have that is positive and hence is weakly primitive.
A (general) Sturmian word of slope and intercept is given by one of the following:
| (3) | ||||
| (4) |
Sturmian words are uniformly recurrent, and are equivalently characterised by their factor complexity , which is the lowest among non-periodic words. A Sturmian word with slope and intercept satisfies . That is, the language of a Sturmian word only depends on its slope. See for instance [13] for more on the subject.
Sturmian words are not necessarily -adic for defined above. However, they are -adic for where the substitution inserts to the right, i.e., maps to and to . Let be a Sturmian word with slope and intercept . Then there exists (by [5, Prop. 2.7, also see remark after Thm. 2.10]) an Ostrowski expansion of in base such that is directed by a sequence where
| (5) |
Conversely, the rules of Ostrowski expansion guarantee that each obtained from the expansions and as above is weakly primitive and directs a Sturmian word. Observe that we can unpack every to obtain a bona fide directive sequence over . We also observe that characteristic Sturmian words, with , are have directive sequences that use only .
In summary, Sturmian words can be characterised as the set of all generated by some weakly primitive containing infinitely many left-proper terms. Arnoux-Rauzy words generalise Sturmian words to larger alphabets. Let . For distinct , define and , and for , let . Observe that each is left-proper. Then a word is Arnoux-Rauzy if and only if it is generated by a weakly primitive containing infinitely many left-proper terms (see, e.g., [16, Sec. 2.3, Thm. 4.12, Sec. 5]). Arnoux-Rauzy words have factor complexity , but this is not a characterisation for . Observe that Sturmian words are precisely the Arnoux-Rauzy words over a two-letter alphabet. Other -adic generalisations of Sturmian words include episturmian words [16] and dendric shifts [3, 14].
4 Congenial expansions for -adic words
Let be a directive sequence over for an alphabet . In this section we will show that any word directed by can be written as a product of congenial words generated by . Congenial expansions are one of the main insights of this paper, and form the combinatorial cornerstone of our analysis of the automaton acceptance problem for -adic words.
Definition 9.
Let be an alphabet. A sequence over is congenial if begins with for all . A word is -congenial for a directive sequence if for a congenial sequence that augments .
The most desirable property of a congenial sequence is that is guaranteed to exist, and has every as a prefix. For example, the sequence , where are Sturmian substitutions, is congenial. This sequence generates the Fibonacci word.
The following lemma captures this property, and is proven via a straightforward induction.
Lemma 10.
Let be congenial, and for , let be such that . For all ,
For a directive sequence , denote by the set of all -congenial . We next show that this set is finite.
Lemma 11.
Let be an alphabet and be a directive sequence over . There exist at least one and at most congenial expansions of the form , and hence .
Proof.
By Lem. 6, there exists over such that for all . Let be the first letter of . We have that is congenial, and hence .
Now suppose there exist congenial sequences . By a pigeonhole argument, there must exist such that for infinitely many . From congeniality it follows that for all .
Congenial words constitute the building blocks of directed words. The “if” part of the following lemma follows by definition; the “only if” part holds because a directed word can naturally be factorised into a congenial prefix and a directed suffix (if the former is finite).
Lemma 12.
Let be an alphabet and be a directive sequence over . A word is directed by if and only if it can be expressed as a (possibly infinite) concatenation of -congenial words.
Proof.
Suppose , where for all . Let be a congenial sequence generating , and for all . We have that for all . It remains to define . Then and for all .
Now suppose is -directed, and let be the witnessing sequence of words with . Write for the first letter of . We construct the desired factorisation inductively. Let be the word defined by the congenial sequence . By the choice of , is a prefix of . If , then we are done. Otherwise, must be finite. Let be the unique sequence of finite words such that , is a prefix of for all , and for all . Write for all . Because for all and , we have that . That is, is a suffix of directed by . Set , and repeat the process on .
If is weakly primitive, then we have the following strengthening of Lem. 12.
Lemma 13.
Suppose is weakly primitive and directs . Then has a congenial expansion .
Proof.
Let be such that and , and be the first letter of . Then is congenial, is a prefix of for all , and by the growth assumption. Therefore, generates .
Lemma 14.
Let be a weakly primitive directive sequence. A word is directed by if and only if it is -congenial.
5 Equivalence of substitutions modulo a semigroup
The motivation behind the semigroup-based approach to the language-membership problem is that even though there are infinitely many substitutions in , from the perspective of a finite -semigroup recognising an -regular language , they can be divided into finitely many equivalence classes.
Let be an -regular language, and let it be recognised by a morphism into a finite -semigroup , e.g., the morphism into the syntactic -semigroup as defined in [21, Sec. 11]. Observe that an -semigroup morphism from into is completely determined by the images of each letter in . Since is finite, there are only finitely many possible morphisms. We denote the set of these morphisms by . We make a small technical adaptation, and interpret these as monoid morphisms, i.e., we adjoin a fresh neutral element to , and assign for each .
We define an equivalence relation on the set of non-erasing substitutions . Let be the function that takes a letter and , and returns a finite sequence of pairs from , determined as follows. Write
where are distinct letters and for all . I.e., we consider the factorisation of into segments based on the first occurrence of each letter. Then
| (6) |
Note that there are only finitely many possibilities for . For , define
We denote the class of by , and the finite set of the equivalence classes by . We next show how to effectively provide representatives for the equivalence classes.
Lemma 15.
Given an -regular language , we can compute morphisms such that for all and
Proof.
We simply iterate over each syntactic possibility for (as in Eq. (6)), and check if it is realised by a non-erasing substitution. In order to do so, for each letter , we will find a word such that assigning is consistent with for all . For and under consideration, let the purported , with such that for all , and , for all . We can compute regular languages such that for all and , if and only if and . Let denote .
We can effectively check whether is non-empty, and if yes, effectively compute . Such a word can be computed as an image for every letter (if and) only if the purported is indeed realisable by assigning each to the corresponding .
For technical convenience, we define the following auxiliary functions that can be derived from ; the first four of them are independent of .
-
(a)
records for each letter whether . It evaluates to false if and only if for all .
-
(b)
maps each letter to a finite sequence of pairs of letters with Boolean flags: if when factorised as in the definition of , then is where if and only if .
-
(c)
maps each letter to the first letter in .
-
(d)
takes as input a letter and a morphism . Write . We define .
-
(e)
takes and returns .
We next argue that composition of morphisms can be defined on equivalence classes. Let be non-erasing. We show how to determine using only and . Suppose , where and for all . Then
and each letter of will have already appeared in one of . Write . Then is equal to
Write . Observe that each letter of appears as a factor before in the factorisation above; the same applies to every . To compute we begin with the finite sequence
Note that the above can be effectively computed from and as and the two factors can be gleaned from, respectively, and . Rename the indices in the sequence above to obtain where and for all . Recall that for all . But it is possible that for some . To eliminate these, we repeat the following process for as long as possible. Find the smallest such that for some . Replace the two consecutive terms with . In the end we are left with .
Observe that only depends on ; we can thus index the auxiliary functions (a-e) above by the equivalence class . To summarise, we have the following.
Proposition 16.
The set is a finite monoid with the binary operation and the identity element , where for all .
Proof.
The set of substitutions is a monoid with composition being the binary operation. The map from substitutions to their equivalence classes respects the binary operation, by construction. Using this fact, it is straightforward to check that the binary operation on equivalence classes is associative, and that is indeed the identity element.
Let be a sequence over , for all , and be a sequence of letters from , where can be finite or infinite. We define and . We extend the definition of to finite sequences in the natural way: if is finite, then is the product . The next result shows that for any infinite and substitution , whether can be determined from .
Lemma 17.
Let be an -regular language and . There exists such that for any , if and only if . Furthermore, can be effectively computed if we can compute for all .
Proof.
Recall [21, Thm. 7.6] that we have a set such that for all , if and only if . We now view the substitution as an -semigroup morphism:
We thus define . The effectiveness claim follows from the fact that for all .
6 Morphic words in a given -regular language
We shall now use the machinery developed in Sec. 5 to characterise the set of morphic words in a given -regular language , thus generalising the main result of [10]. A word is substitutive if it is a fixed point of a non-trivial substitution, i.e., if there exists not the identity such that . A word is morphic if it is of the form for and a substitutive word. For and substitutions , define and . We will show that, for an -regular language and substitutions , the respective equivalence classes of substitutions determine:
-
Whether the substitution has a fixed point in (Thm. 22).
-
A regular language such that is in if and only if (Thm. 21).
Before we proceed to state our key properties, we remark that we work with . For the sake of brevity, we (syntactically) allow infinite words to be concatenated, i.e., for and , the syntactic concatenation equals . We furthermore allow to be concatenated: for any , , if is finite, and if is infinite.
Lemma 18.
Let be an alphabet and be a substitution. The following properties hold.
- Saturation.
-
For , we have that .
- Distributivity.
-
For , .
- Left-Expansion.
-
For ,
if then . - Right-Expansion.
-
For , if , then
. - Cycle of Contradiction.
-
Let , be distinct letters such that , and for any , . We have that
. - Terminal Letters.
-
If, for a letter , , then for all , .
Proof.
Saturation.
The sequences and have the same limit.
Distributivity.
We have that for all , . If , then for all large , . Taking the limit, we get . If , then for every position , there exists such that for all , . In other words, every position is eventually part of . Thus, . However, if , then for all . If , there is some position such that the letter fluctuates with . This means that the limit of must also be mapped to .
Left-Expansion.
Follows by repeatedly unrolling the equality.
Right-Expansion.
Follows by repeatedly applying .
Cycle of Contradiction.
The limit must be as the first letter of keeps alternating between .
Terminal Letters.
We find the set of letters such that by saturation. The key idea is that if converges within iterations, then must converge within iterations, i.e., for every letter in , must converge within iterations.
We start with the set of letters such that . We construct as the union of with the set of letters such that only contains letters from . This construction will saturate within steps. The invariant is that is the set of such that converges within iterations. We conclude that since for , , if converges in steps then it must have already converged within steps.
The following result, along with distributivity, implies that whether for a finite word is an infinite word accepted by is determined by the equivalence class ; this is the main technical novelty of this section.
Theorem 19.
Let be an -regular language recognised by an -semigroup . For any , substitutions with , and , we have that . Moreover, can be computed given only the equivalence class of along with the values of .
Proof.
By Lem. 18, we have a dynamic programming algorithm to compute in a “depth-first” manner. We shall show that this algorithm only uses .
Consider and write , where the factorisation is based on the first occurrence of each letter: we get from . By Saturation, we have that
We observe that the terms will affect the result only if all for are elements of . In this case, will also be a finite word, and by the Terminal Letters property, be . We denote by ; thus in this case, we have . We can rewrite
| (7) |
The elements can be obtained from . If , we are in the simpler case of Right-Expansion where , and have that
The first two terms are easily obtained through , and . Since the sequence of monoid elements is effectively ultimately periodic, so is the sequence of factors in the above infinite product, allowing us to compute it.
If , we first check that there is no such that : this can be done with access to for . If this check fails, we have a Cycle of Contradiction, and have that .
We now evaluate expansion (7). Write , and
Clearly, , and
In particular when for some , then . For each , if , we evaluate (we make a recursive call if it has not been evaluated before, otherwise we look up the memoized value). Otherwise, and we are in the case of Left-Expansion, and get that . In any case, we will eventually compute .
The result follows by applying the above depth-first routine to compute .
As a corollary, we obtain that whether belongs to an -regular language is completely determined by the equivalence classes and : indeed, acceptance only depends on , which is the same as applied to .
Corollary 20.
Let be an -regular language. For any letter , a, and substitutions , we can compute given only .
We thus arrive at the following.
Theorem 21.
Let be an -regular language and be substitutions with respective equivalence classes . We can compute a regular language such that if and only if .
Proof.
We construct a deterministic finite-word automaton recognising . The set of states is the set of elements of , the initial state is , the set of accepting states is (the semigroup elements whose preimages comprise ), and the transition function maps to . The latter is effective by Cor. 20.
Finally, whether has a fixed point in is effectively determined by .
Theorem 22.
Let be an -regular language and be a substitution. Given and , we can compute the set .
Proof.
We observe that any fixed point of must be a concatenation of words , where for . Write for the set of all such letters , which can be extracted from . The required set is then the sub--semigroup of generated by , whose elements in turn can be computed using Thm. 19.
7 -adic words in a given -regular language
We now present our main results, i.e., solutions to the language membership problem for -adic words. In this section, let be an -regular language recognised by a morphism into a finite -semigroup , and be such that . For convenience, further let be a deterministic automaton accepting . Recall the set of equivalence classes of substitutions modulo , defined in Sec. 5. We will first prove that for congenial over , defining a word accepted by is a property of , and the set of all such traces is -regular.
Theorem 23 (Main Result for Generated Words).
Let be an -regular language. We can compute an automaton over such that for all infinite sequences over , accepts if and only if is congenial and generates a word in .
Proof.
The automaton accepts if and only if is accepted by (constructed in Lem. 24 below) for some . Intuitively, , upon reading , checks that the expansion is congenial. If yes, then the generated word can be factorised as as described in Lem. 12. The automaton then evaluates the product .
Lemma 24.
Let . We can construct an automaton over such that for all infinite sequences over , accepts if and only if is congenial and , where is the word generated by .
Proof.
Recall that a sequence over is congenial if and only if for all , where . This property depends only on . The automaton , first and foremost, checks the condition above for all , and permanently transitions into a rejecting state if it observes a violating triple .
Now suppose is congenial, and define as above. As shown in Lem. 10,
for all , where satisfies . Let and for . By the properties of infinite products in (see Sec. 2.2) we have that if and only if . The automaton simulates the run of the automaton of Lem. 2 on the sequence . It remains to show how the automaton keeps track of as it reads . We have that
for . The automaton keeps track of one piece of information , in addition to the state required for simulating a run of on . Before reading the value of is , where the empty product (corresponding to the initial value of ) is the identity element of . Upon reading , the automaton first computes , in which the value of is used, then feeds the computed value to , and finally updates to . Finally, accepts if and only if accepts .
When is finite, for every individual we can compute the equivalence class , which yields the following.
Corollary 25.
Let be finite. We can compute an automaton over such that accepts if and only if is congenial and generates a word in .
We next consider -directed words, which are products of congenial words by Lem. 12.
Theorem 26 (Main Result for Directed Words).
Let be an -regular language. We can construct an automaton over such that for all , accepts if and only if directs some .
Proof.
Denote the image of under by . Recall from Lem. 12 that directed words are obtained by concatenating congenial words. To prove Thm. 26, we need to recognise the set of all for which the sub--semigroup generated by intersects the accepting set . We can precompute a set of sets that generate sub--semigroups intersecting . Our automaton needs to check that contains at least one such set . We denote by the projection of from Thm. 24 to , and observe: if and only if .
Corollary 27.
Let be finite. We can compute an automaton over such that accepts if and only if directs a word in .
The corollary above is proven in the same way as Cor. 25. We can apply the former to Arnoux-Rauzy words (which subsume Sturmian words) over the alphabet . Let . Recall that a word is Arnoux-Rauzy if and only if it is directed by a sequence which is (i) weakly primitive and (ii) contains infinitely many left-proper terms; by Lem. 8, such directive sequences direct a unique word, which is moreover infinite. By inspection, is weakly primitive if and only if for every , either or occurs infinitely often. Hence the requirements (i-ii) can be checked by an automaton, and from Cor. 27 we obtain the following.
Theorem 28 (Main Result for Arnoux-Rauzy words).
Let , be an -regular language, and be the finite set of morphisms generating the Arnoux-Rauzy words over as described above. We can compute an automaton that accepts if and only if is weakly primitive, contains infinitely many left-proper terms, and the unique Arnoux-Rauzy word directed by is in .
8 Factor complexity and partial quotients
In this section, we refine our main results presented in Sec. 7 when extra information concerning the factor complexity is available. For characteristic Sturmian words, in particular, we will show that whether a deterministic automaton accepts the characteristic Sturmian word with slope (as defined in (2)) only depends on the first terms in the continued fraction expansion of , where is independent of the slope .
Fix an alphabet , a (deterministic) automaton over recognising an -regular language , a class of uniformly recurrent words , and such that
-
1.
if and only if is directed (and hence generated) by some weakly primitive , and
-
2.
there exists a computable function such that for all and , where is the number of distinct factors of of length .
By assumption (1), every is uniformly recurrent (see Sec. 3). Characteristic Sturmian, Sturmian, and -letter Arnoux-Rauzy words are captured, respectively, with , ; , ; and , (see Sec. 3.2). We briefly mention that these techniques can also be applied to dendric words, whose factor-complexity function has a computable closed-form expression. The directive sequences generating such words, however, are characterised by conditions that are more involved [15].
Our main idea is that every has a prefix that is -saturated with respect to , i.e., any uniformly recurrent extension of with factor complexity agrees with upon acceptance by (Lem. 29), and hence also agrees upon membership in the recognised -regular language . The proof involves a careful consideration of Semënov’s algorithm for deciding whether a given automaton accepts a given uniformly recurrent word.
Lemma 29.
Let with effectively computable letters. Given an automaton , we can compute such that any with is accepted by if and only if is accepted by .
Proof.
Since we have access to the factor complexity function of and by assumption (2), we can compute the recurrence function : given , enumerate prefixes and integers until we find that (i) contains exactly distinct factors of length , and (ii) each of these factors contains distinct factors of length . Then .
Applying Prop. 5, we obtain and such that for any , if and for , then and agree upon acceptance by . By the above paragraph, we can compute such that if , then for . It remains to take .
Recall Lem. 13. Given a weakly primitive and congenial expansion of , we can compute an increasing sequence with such that, writing , and , each is positive, none of the strict prefixes of the composition is positive, and is also a congenial expansion of . We refer to as the sequence of partial quotients of . Since each is positive, the sequence of partial quotients is, in particular, strongly primitive. The main result of this section is that, for the class , acceptance by is determined by a fixed number of initial partial quotients.
Theorem 30.
We can compute (that depends only on and ) with the following property. Let be in with congenial -adic expansions and partial quotients and , respectively. If and for all , then accepts if and only if it accepts .
Proof.
Let be the set of all positive products such that for all and is not positive for all . Construct finite such that and for all distinct we have that . Let be the set of all congenial over . From the definition of congeniality it follows that is closed. Since is compact, so is .
Next, consider with a congenial expansion . Such belongs to , but not every word in necessarily has such an expansion. By Lem. 29 there exists a prefix of , which is generated by for some , that is -saturated. Write for the set of all whose first terms generate a -saturated finite word, observing that each is open. From Lem. 29 it follows that is an open cover of , which, by compactness, admits a finite sub-cover. That is, there exists (which can be effectively computed by enumeration) such that for every , generates a finite word that is -saturated. That is, for expansions in , whether the generated word is accepted or not only depends on the first terms.
Now consider (arbitrary) as in the statement of the theorem. Let over be such that for all , and observe that is also congenial. Let be the word generated by . By Thm. 24, accepts if and only if it accepts . By the earlier argument, whether accepts only depends on . It remains to observe that is completely determined by . Let us illustrate this result on Sturmian words. Given an automaton , apply Thm. 30 with and to compute . Let , , be the continued fraction expansion of , be an Ostrowski expansion of in base , and be the corresponding Sturmian word with slope and intercept . Recall that is directed (and uniquely generated; see Lem. 8) by the sequence
where . By the rules of Ostrowski expansion, at least one of is non-zero for all . Moreover, every composition of morphisms from that includes two morphisms with differing indices is positive. Since at least one of is non-zero for all (we could, however, have ), we have that is positive for every . Applying Thm. 30, whether is accepted by can be determined by looking at the first digits (where depends on ) of the computable expansions of and , since these are guaranteed to generate at least the first partial quotients of the unique -adic expansion of .
References
- [1] Jean-Paul Allouche and Jeffrey Shallit. Automatic Sequences: Theory, Applications, Generalizations. Cambridge University Press, 2003.
- [2] Pierre Béaur and Benjamin Hellouin de Menibus. Sturmian and infinitely desubstitutable words accepted by an -automaton. In Anna Frid and Robert Mercaş, editors, Combinatorics on Words, pages 104–116, Cham, 2023. Springer Nature Switzerland.
- [3] Valérie Berthé, Clelia De Felice, Francesco Dolce, Julien Leroy, Dominique Perrin, Christophe Reutenauer, and Giuseppina Rindone. Maximal bifix decoding. Discrete Mathematics, 338(5):725–742, 2015. doi:10.1016/J.DISC.2014.12.010.
- [4] Valérie Berthé and Vincent Delecroix. Beyond substitutive dynamical systems: -adic expansions. RIMS Kôkyûroku Bessatsu, B46:81–123, 2014.
- [5] Valérie Berthé, Charles Holton, and Luca Q. Zamboni. Initial powers of Sturmian sequences. Acta Arithmetica, 122(4):315–347, 2006.
- [6] Valérie Berthé, Toghrul Karimov, Joris Nieuwveld, Joël Ouaknine, Mihir Vahanwala, and James Worrell. On the decidability of monadic second-order logic with arithmetic predicates. In Proceedings of the 39th Annual ACM/IEEE Symposium on Logic in Computer Science, pages 1–14, 2024. doi:10.1145/3661814.3662119.
- [7] Valérie Berthé, Toghrul Karimov, Joris Nieuwveld, Joël Ouaknine, Mihir Vahanwala, and James Worrell. The monadic theory of toric words. Theoretical Computer Science, 1025:114959, 2025. doi:10.1016/J.TCS.2024.114959.
- [8] J. R. Büchi. On a decision method in restricted second order arithmetic. In The Collected Works of J. Richard Büchi, pages 425–435. Springer, 1990.
- [9] Yann Bugeaud and Michel Laurent. Combinatorial structure of Sturmian words and continued fraction expansion of Sturmian numbers. Annales de l’Institut Fourier, 73(5):2029–2078, 2023.
- [10] Olivier Carton and Wolfgang Thomas. The monadic theory of morphic infinite words and generalizations. Information and Computation, 176(1):51–65, 2002. doi:10.1006/INCO.2001.3139.
- [11] Fabien Durand. Corrigendum and addendum to “Linearly recurrent subshifts have a finite number of non-periodic factors”. Ergodic Theory and Dynamical Systems, 23(2):663–669, 2003.
- [12] Calvin C. Elgot and Michael O. Rabin. Decidability and undecidability of extensions of second (first) order theory of (generalized) successor. The Journal of Symbolic Logic, 31(2):169–181, 1966. doi:10.2307/2269808.
- [13] N. Pytheas Fogg. Substitutions in Dynamics, Arithmetics and Combinatorics. Springer, 2002.
- [14] France Gheeraert, Marie Lejeune, and Julien Leroy. -adic characterization of minimal ternary dendric shifts. Ergodic Theory and Dynamical Systems, 42(11):3393–3432, 2022.
- [15] France Gheeraert and Julien Leroy. -adic characterization of minimal dendric shifts. Discrete Mathematics & Theoretical Computer Science, 27(2), 2025.
- [16] Amy Glen and Jacques Justin. Episturmian words: a survey. RAIRO - Theoretical Informatics and Applications, 43(3):403–442, 2009. doi:10.1051/ITA/2009003.
- [17] Philipp Hieronymi, Dun Ma, Reed Oei, Luke Schaeffer, Christian Schulz, and Jeffrey Shallit. Decidability for Sturmian words. Logical Methods in Computer Science, 20(3):12:1–12:38, 2024. doi:10.46298/LMCS-20(3:12)2024.
- [18] Toghrul Karimov. Algorithmic verification of linear dynamical systems. PhD thesis, Saarland University, 2024.
- [19] Toghrul Karimov, Edon Kelmendi, Joël Ouaknine, and James Worrell. What’s decidable about discrete linear dynamical systems? In Principles of Systems Design: Essays Dedicated to Thomas A. Henzinger on the Occasion of His 60th Birthday, pages 21–38. Springer, 2022. doi:10.1007/978-3-031-22337-2_2.
- [20] A. Muchnik, A. Semenov, and M. Ushakov. Almost periodic sequences. Theoretical Computer Science, 304(1–3):1–33, 2003. doi:10.1016/S0304-3975(02)00847-2.
- [21] Dominique Perrin and Jean-Éric Pin. Semigroups and automata on infinite words. In Semigroups, Formal Languages and Groups, pages 49–72. Kluwer Academic Publishers, 1995.
- [22] Alexander Rabinovich. On decidability of monadic logic of order over the naturals extended by monadic predicates. Information and Computation, 205(6):870–889, 2007. doi:10.1016/J.IC.2006.12.004.
- [23] Raphael Robinson. Restricted set-theoretical definitions in arithmetic. Proceedings of the American Mathematical Society, 9(2):238–242, 1958.
- [24] A. L. Semenov. Logical theories of one-place functions on the set of natural numbers. Mathematics of the USSR-Izvestiya, 22(3):587–618, 1984.
- [25] Jeffrey Shallit. The Logical Approach to Automatic Sequences: Exploring Combinatorics on Words with Walnut. Cambridge University Press, 2022.
- [26] Wolfgang Thomas. A note on undecidable extensions of monadic second order successor arithmetic. Archiv für mathematische Logik und Grundlagenforschung, 17(1):43–44, 1975. doi:10.1007/BF02280812.
- [27] B. Trahtenbrot. Finite automata and the logic of one-place predicates. Siberian Mathematical Journal, 3:103–131, 1962.
- [28] Thomas Wilke. An Eilenberg theorem for -languages. In Automata, Languages and Programming, pages 588–599, 1991.
