Abstract 1 Introduction 2 Preliminaries 3 𝑺-adic words 4 Congenial expansions for 𝑺-adic words 5 Equivalence of substitutions modulo a semigroup 6 Morphic words in a given 𝝎-regular language 7 𝑺-adic words in a given 𝝎-regular language 8 Factor complexity and partial quotients References

Automata on S-Adic Words

Valérie Berthé ORCID Université Paris Cité, IRIF, CNRS, France    Toghrul Karimov ORCID Max Planck Institute for Software Systems, Saarland Informatics Campus, Saarbrücken, Germany    Mihir Vahanwala ORCID Max Planck Institute for Software Systems, Saarland Informatics Campus, Saarbrücken, Germany
Abstract

A fundamental question in logic and verification is the following: for which unary predicates P1,,Pk is the monadic second-order theory of ;<,P1,,Pk 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 S of substitutions. A word α is said to be directed by a sequence s=(σn)n over S if there is a sequence of words (αn)n such that α0=α and αn=σn(αn+1) for all n; such α are called S-adic. We study the automaton acceptance problem for such words and prove, among others, the following: given finite S and an automaton 𝒜, we can compute an automaton that accepts sSω if and only if s directs a word α accepted by 𝒜. Thus we can algorithmically answer questions of the form “Which S-adic words are accepted by a given automaton 𝒜?”

Keywords and phrases:
Sturmian words, S-adic words, automata theory, word combinatorics
Category:
Track B: Automata, Logic, Semantics, and Theory of Programming
Funding:
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).
Toghrul Karimov: supported by the DFG grant 389792660 as part of TRR 248 (see perspicuous-computing.science), and the ERC Synergy Grant DynAMiCs (101167561).
Mihir Vahanwala: supported by the DFG grant 389792660 as part of TRR 248 (see perspicuous-computing.science), and the ERC Synergy Grant DynAMiCs (101167561).
Copyright and License:
[Uncaptioned image] © Valérie Berthé, Toghrul Karimov, and Mihir Vahanwala; licensed under Creative Commons License CC-BY 4.0
2012 ACM Subject Classification:
Theory of computation Logic and verification
Related Version:
Extended Version: https://arxiv.org/abs/2506.17460
Acknowledgements:
The authors are grateful to the anonymous reviewers for their helpful suggestions.
Editors:
Sayan Bhattacharya, Danupon Nanongkai, Michael Benedikt, and Gabriele Puppis

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 ;<,P for various interesting unary predicates P including {n!:n} and {2n:n}. 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 P1,,Pk is the MSO theory of ;<,P1,,Pk 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 a. Their result implies, in one fell swoop, the decidability of the MSO theory of ;<,{p(n)an:n} where a1 and p is a polynomial with integer coefficients satisfying p().

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 ;<,a,b using the fact that the order in which powers of coprime a and b 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 L, decide whether it contains a Sturmian word.” (Of course, we can also ask about any other combinatorial class.) Our approach adopts the S-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 aΣ with a non-empty word σ(a)Σ+. For example, the Fibonacci substitution σ𝖿𝗂𝖻 over {0,1} replaces 0 with 01 and 1 with 0; the Fibonacci word α𝖿𝗂𝖻=01001010 is obtained as the limit of iterating σ𝖿𝗂𝖻 infinitely on the letter 0 (or, alternatively, the letter 1). Hence we have the infinite decomposition α𝖿𝗂𝖻=σ𝖿𝗂𝖻σ𝖿𝗂𝖻. In general, we have a set S of substitutions, and say that a sequence s over S directs αΣω if there exists a sequence of words (α(n))n such that α(0)=α, and α(n)=σn(α(n+1)) for all n. This gives us the S-adic decomposition α=σ0σ1. We refer to any sSω as a directive sequence.

An observant reader might argue that every word α=a0a1a2 is vacuously S-adic for S={σ1,,σ|Σ|,τ1,,τ|Σ|} over the alphabet Σ{b}, where σi replaces the distinguished letter b with aiΣ and is the identity function elsewhere, and τi replaces b with bai and is the identity function elsewhere. We then see that α is directed by σa0τa1τa2. 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 {λ0,λ1} 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 S; such a class 𝒲 is called S-adic. Our central question is the following: given an ω-regular language LΣω and an S-adic class of words 𝒲Σω, what is the set of all α𝒲 that are contained in L? 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 ;<,+,Pα{n:α(n)=1}. The key idea there is that the class of structures ;<,+,Pα, 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 S-space of substitutions. Hence the common MSO theory of an S-adic class of words is decidable. This generalises the result of [2] (in particular, Cor. 3 ibidem) that, given finite S and an automaton 𝒜 whose language is closed (i.e., a Büchi automaton whose states are all accepting), the set of sequences over S 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 S.

Our algorithms thoroughly answer questions of the kind “Which S-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 u,v{0,,d1} and a,b with b0, 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 u, the number of occurrences of v is congruent to a modulo b.

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 (σn)n generates α if there exists a sequence of letters (an)n such that α=limnσ0σn(an); 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 S-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 s over222Our set S 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 b in level n+1 and a in level n labelled r if a occurs in the r-th position of σn(b). 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. S into a congenial expansion s^ over S×Σ (Def. 9), which generates a word incrementally and predictably (Lem. 10). We prove the following pivotal results.

  • If s generates α, then it also directs α (Lem. 6).

  • A word α directed by s is a concatenation of words generated congenially by s (Lem. 12).

  • For s weakly primitive, s congenially generates α if and only if it directs α (Lem. 14).

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 L (Prop. 16); we denote the finite set of equivalence classes by ΞL. Given a sequence s over the set of substitutions S or a sequence s^ over S×Σ, we naturally define its trace to be, respectively, a word over ΞL or over ΞL×Σ. In Sec. 6 and 7 we use our two key ingredients, the notion of congeniality together with the monoid ΞL of equivalence classes, to prove our main results.

Morphic Words.

Let 𝒜 be an automaton over Σ, and σ,π be substitutions. Using only the respective equivalence classes ξ,ζΞL of the latter, we can compute a regular language LΣ+ such that the word π(σω(u)) is well-defined and accepted by 𝒜 if and only if uL (Thm. 21). We can thus characterise all such π,σ,u, 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 ΞL×Σ such that accepts the trace of s^ if and only if s^ is congenial and generates a word accepted by 𝒜 (Thm. 23).

Directed Words.

Given 𝒜 as above, we can construct an automaton over ΞL such that accepts the trace of s if and only if s directs a word accepted by 𝒜 (Thm. 26). This further generalises the result of [10] from infinite compositions of a single substitution σ to arbitrary infinite compositions over a set of substitutions S.

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 |Σ|>1, i.e. we have at least two distinct letters. We write ε for the empty word. For a word α, α(j) denotes the letter at the jth position of α, α[i,j) denotes the finite word α(i)α(j1), and α[j,) denotes the infinite word α(j)α(j+1). A finite word u is a factor of a word v if there exist indices i,j such that v[i,j)=u. 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., σ(v)=ε if and only if v=ε. We denote the set of all such substitutions by S(Σ). For substitutions μ,σ, we write μσ for μσ. A substitution is positive if every bΣ appears in σ(a) for all aΣ, 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 u,v to be 2n, where n is the first position in which they differ. E.g., distinct a,bΣ are a distance of 20=1 apart. A notion of convergence of sequences of words follows naturally.

Definition 1.

Let (un)n be a sequence of finite non-empty words. We define α=limnunΣ{} as follows.

  • If there exists vΣ and N such that for all nN, un=v, then α=v.

  • If there exists βΣω such that for all j, un[0,j)=β[0,j) for all sufficiently large n, 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 LΣω is ω-regular if and only if it can be recognised by a (nondeterministic) Büchi automaton 𝒜=(Σ,Q,I,Δ,F), where Σ is the alphabet, Q is the finite set of states, IQ is the set of initial states, ΔQ×Σ×Q is the transition relation, and F is the set of accepting states. A run rQω of the automaton on an input word α satisfies r(0)I, and for all n, (r(n),α(n),r(n+1))Δ. A word α is accepted if it has a run r such that r(n)F for infinitely many n.

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 δ:Q×ΣQ. For this reason, we also use deterministic parity automata, which are further equipped with a function 𝗂𝗇𝖽𝖾𝗑:Q. In the case of deterministic parity automata, a word α has a single run r, and is accepted if lim supn𝗂𝗇𝖽𝖾𝗑(r(n)) 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 M=(Mf,Mω) is a two-sorted algebra equipped with the following operations:

  1. 1.

    A binary operation defined on Mf and denoted multiplicatively,

  2. 2.

    A mapping Mf×MωMω, called the mixed product, also denoted multiplicatively,

  3. 3.

    An infinite product π that maps infinite sequences over Mf to an element of Mω.

These operations must satisfy the following associativity properties:

  1. 1.

    Mf, equipped with the binary operation, is a semigroup.

  2. 2.

    For every m1,m2Mf and m3Mω, we have that (m1m2)m3=m1(m2m3).

  3. 3.

    For every sequence (mn)n over Mf, and every strictly increasing sequence (kn)n of indices, we have that π(m0,m1,m2,)=π(m0mk0,mk0+1mk1,).

  4. 4.

    For every mMf and every sequence (mn)n over Mf, we have that mπ(m0,m1,)=π(m,m0,m1,).

The last two conditions show that the infinite product π(m0,m1,) can also be denoted multiplicatively as m0m1. Indeed, an ω-semigroup can be intuited as a semigroup where infinite products are defined. An immediate example is Σ with word concatenation, where Mf=Σ+, and Mω=Σω.

Given ω-semigroups M1,M2 a morphism h of ω-semigroups is a pair hf,hω such that hf is a semigroup morphism from M1,f into M2,f, and hω is a map from M1,ω to M2,ω preserving the mixed product and infinite product, i.e., for every m1M1,f and m2M1,ω, hf(m1)hω(m2)=hω(m1m2), and for every sequence (mn)n over M1,f, we have hf(m0)hf(m1)=hω(m0m1). We shall thus omit subscripts and denote the application of a morphism by simply h. As an immediate example, a non-erasing substitution σ defines a morphism from Σ to Σ.

A set LΣ is recognised by a morphism h from Σ into an ω-semigroup M if there exists a subset HMfMω such that L=h1(H). A language LΣω 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 M, the infinite product is fully determined by the function MfMω that maps m to mω [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 Mf 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 M=(Mf,Mω) be a finite ω-semigroup, and xMfMω. Extend Mf into a monoid Mf by adjoining a distinguished neutral element 1M: for all mMf, 1Mm=m1M=m. We can construct an automaton 𝒜x over the alphabet Mf that accepts m0m1(Mf)ω if and only if the infinite product m0m1 (defined as the possibly finite product of the subsequence mi0mi1 obtained by discarding all 1M terms) equals x.

For example, consider the ω-regular language (ab)ω over the alphabet {a,b}, i.e., the language of infinite words containing infinitely many occurrences of the letter b. We recognise it algebraically as follows. Let Mf={e,m}, where ee=e,em=me=mm=m. Let Mω={e^,m^}, where eω=e^ and mω=m^. We define the morphism h to map a to e, and b to m. Observe that a word α is in the language if and only if h(α)=m^.

2.3 Uniformly recurrent words

For a word αΣω, the set (α)={u:u is a factor of α} is called the (factor) language of α. The factor complexity function pα computes the number of factors of α of a given length n. For example, if α is Sturmian, then pα(n)=n+1 for all n (see e.g., [13]).

For an infinite word α and l0, denote by Rα(l) the smallest r{} such that every factor of α of length l is a factor of every factor of α of length r. We call Rα the recurrence function of α. A word αΣω is said to be uniformly recurrent if Rα(l) for every l. That is, every uΣl 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 Rα(l) 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 uΣ, checks whether u(α). Then we can effectively compute Rα(l).

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 α(n) on input n and (B) an oracle computing an upper bound R¯α(l) on Rα(l) given l.

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 M such that a state q of 𝒜 appears infinitely often in 𝒜(α) if and only if it appears in 𝒜(α)[M,2M).

In other words, to check whether 𝒜 accepts α, we simply need to run 𝒜 on α for 2M steps, and observe the states that are visited. See [18, Chap. 3.1] for effective bounds on M, 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 l,M such that for any uniformly recurrent β with β[0,M)=α[0,M) and Rβ(n)=Rα(n) for all nl, 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 S-adic terms [13]. Let η(0,1). The continued fraction expansion of η is the unique sequence (an)n1 of positive integers such that

η=1a1+1a2+

We write η=[0;a1,a2,]. The convergents (pn/qn)n of η are obtained by truncating the expansion at the n-th level. The numerators and denominators satisfy the recurrences p0=0, q0=1, p1=1, q1=a1, and (pn+2,qn+2)=an+2(pn+1,qn+1)+(pn,qn) for all n0. The convergents are the locally best approximants of η: for every n, p, and 0<q<qn,

|qnηpn|<minp|qηp|

which implies that |ηpnqn|<minp|ηpq|. The Ostrowski numeration system in base η is based on the sequence θn=qnηpn. For any χ[η,1η], there exists a sequence (bn)n1 over such that (i) 0b1<a1, (ii) 0bnan for all n2, (iii) for all n, bn=0 if bn+1=an+1, and

χ=n=1bnθn1.

We refer to (bn)n1 as an Ostrowski expansion of χ in base η. Conversely, every (bn)n satisfying (i-iii) is an Ostrowski expansion of some χ in base η, i.e., the infinite sum converges to a value in [η,1η].444To check this, observe that θn alternates between positive and negative; θ0=η, θ1=a1η1; θn+2=an+2θn+1+θn. If χ+η or if χ1+η, 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 S-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 SS(Σ) be a possibly infinite set of non-erasing substitutions. We refer to αΣΣω as S-directed if there exists a sequence (σn)n over S and a sequence (α(n))n of words over Σ such that α(0)=α and σn(α(n+1))=α(n) for all n; note that each word in the sequence is the image of the subsequent one. We say that (σn)n directs α. A word αΣΣω is called S-generated if there exists a sequence (σn,an)n over S×Σ such that

α=limnσ0σn(an). (1)

We refer to (σn,an)n as an S-adic expansion of α. For finite or infinite α, whenever (1) holds we say that (σn,an)n generates α. In both the S-directed and the S-generated settings (to which we collectively refer as S-adic), (σn)n is called a directive sequence.

Lemma 6.

If αΣΣω is generated by s over S(Σ), then it is also directed by s. Furthermore, every s over S(Σ) directs at least one non-empty word βΣ+Σω.

Proof.

We will first prove a slightly more general version of the first statement. Let (an)n be a sequence of letters and Um={σmσn(an):nm} for all m. Suppose α is an accumulation point of U0, which subsumes the case of α being generated by (σn,an)n. We will inductively prove the existence of (α(m))m such that α(0)=α, α(m)=σm(α(m+1)), and α(m) is an accumulation point of Um for all m. The base case is immediate.

For the inductive step, suppose we have constructed α(0),,α(m) with the properties above. Write um,n=σmσn(an), and observe that by the induction hypothesis, α(m) is the limit of some sequence (σm(um+1,ni))i. By compactness, the sequence (um+1,ni)i itself has an infinite subsequence (um+1,kj)j that converges. We choose α(m+1) to be the limit, which is an accumulation point of Um+1. By the continuity of σm:ΣΣωΣΣω,

limjσm(um+1,kj)=σm(limjum+1,kj)

which implies that α(m)=σm(α(m+1)).

To prove the second claim, choose an arbitrary sequence (an)n of letters and let β be an accumulation point of {σ0σn(an):n}. Apply the preceding argument. The converse of the lemma above, however, is not true: take s to be the sequence of identity morphisms. We next study various special classes of S-adic words with which we will work.

Definition 7.

A sequence (σn)n over S(Σ) is weakly primitive if for every n there exists mn such that σnσm is positive, i.e., for every b,cΣ, the letter b appears in σnσm(c).

If (σn)n is weakly primitive, then we can compute a sequence (kn)n of increasing integers with k0=0 such that σknσkn+11 is positive for all n. Consequently, for any sequence of letters (an)n we have that limn|σ0σn(an)|=; 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 (σn)nS(Σ)ω be weakly primitive with infinitely many left-proper terms. Then there exists a unique word αΣω such that for any (an)nΣω, (σn,an)n generates α.

Proof.

Let (kn)n be an increasing sequence such that k0=0 and σkn is left-proper for n>0. Further, let bnΣ be such that all images of σkn begin with bn. Then α=limnσ0σkn1(bn). This limit exists and is infinite because the terms of the sequence are strict prefixes of one another. Now take (σn,an)n, where (an)n is arbitrary. Then σ0σn(an) must agree with α on the first |σ0σkm1(am)| letters, where km is maximal with the property that kmn. Since km becomes arbitrarily large as n, we have that limnσ0σn(an)=α.

3.2 Sturmian and Arnoux-Rauzy words

We now illustrate the concepts above through examples. Let η(0,1). The characteristic Sturmian word with slope η is defined by

αη(n)=(n+2)η(n+1)η{0,1} (2)

for n. For instance, the Fibonacci word has η=1/ϕ2, where ϕ is the golden ratio. Characteristic Sturmian words are S-directed for S={λ0,λ1} where λi maps i to i and the other letter j to ij, i.e., it inserts i to the left.

The word αη is intimately connected to the continued fraction expansion of η. Suppose η=[0;1+a1,a2,]. We then have that αη is the unique word directed by the sequence

λ0,,λ0a1 times,λ1,,λ1a2 times,λ0,,λ0a3 times,λ1,,λ1a4 times,

which we denote by sη. For example, 1/ϕ2 has the continued fraction expansion [0;2,1,1,], and hence the Fibonacci word is directed by (λ0λ1)ω. Observe that λ0,λ1 are left-proper. Moreover, for every k,m>0, we have that λ0kλ1m is positive and hence sη is weakly primitive.

A (general) Sturmian word α of slope η(0,1) and intercept χ[η,1η] is given by one of the following:

α(n) =(n+2)η+χ(n+1)η+χ, for all n (3)
α(n) =(n+2)η+χ(n+1)η+χ, for all n. (4)

Sturmian words are uniformly recurrent, and are equivalently characterised by their factor complexity p(n)=n+1, 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 S-adic for S defined above. However, they are S-adic for S={λ0,λ1,ρ0,ρ1} where the substitution ρi inserts i to the right, i.e., maps i to i and j to ji. Let α be a Sturmian word with slope η=[0;a1+1,a2,] and intercept χ. Then there exists (by [5, Prop. 2.7, also see remark after Thm. 2.10]) an Ostrowski expansion (bn)n of χ in base η such that α is directed by a sequence (τ)n where

τn=ρ0b2n+1λ0a2n+1b2n+1ρ1b2n+2λ1a2n+2b2n+2. (5)

Conversely, the rules of Ostrowski expansion guarantee that each (τn)n obtained from the expansions (an)n and (bn)n as above is weakly primitive and directs a Sturmian word. Observe that we can unpack every τn to obtain a bona fide directive sequence over S={λ0,λ1,ρ0,ρ1}. We also observe that characteristic Sturmian words, with χ=0, are have directive sequences that use only λ0,λ1.

In summary, Sturmian words can be characterised as the set of all α generated by some weakly primitive (σn)n{λ0,λ1,ρ0,ρ1} containing infinitely many left-proper terms. Arnoux-Rauzy words generalise Sturmian words to larger alphabets. Let Σ={0,,d1}. For distinct i,jΣ, define λi(j)=ij and ρi(j)=ji, and for i=jΣ, let λi(j)=ρi(j)=i. Observe that each λi is left-proper. Then a word αΣω is Arnoux-Rauzy if and only if it is generated by a weakly primitive (σn)n{λ0,,λd1,ρ0,,ρd1} containing infinitely many left-proper terms (see, e.g., [16, Sec. 2.3, Thm. 4.12, Sec. 5]). Arnoux-Rauzy words have factor complexity p(n)=(n1)d+1, but this is not a characterisation for d>2. Observe that Sturmian words are precisely the Arnoux-Rauzy words over a two-letter alphabet. Other S-adic generalisations of Sturmian words include episturmian words [16] and dendric shifts [3, 14].

4 Congenial expansions for 𝑺-adic words

Let s be a directive sequence over S(Σ) for an alphabet Σ. In this section we will show that any word directed by s can be written as a product of congenial words generated by s. 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 S-adic words.

Definition 9.

Let Σ be an alphabet. A sequence ((σn,an))n over S(Σ)×Σ is congenial if σn+1(an+1) begins with an for all n. A word αΣ+Σω is s-congenial for a directive sequence s if α=limnσ0σn(an) for a congenial sequence ((σn,an))n that augments s.

The most desirable property of a congenial sequence (σn,an)n is that limnσ0σn(an) is guaranteed to exist, and has every σ0σn(an) as a prefix. For example, the sequence ((λ0,1)(λ1,0))ω, where λ0,λ1 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 ((σn,an))n be congenial, and for n1, let vnΣ be such that σn(an)=an1vn. For all n,

σ0σn(an)=σ0(a0)σ0(v1)σ0σ1(v2)(σ0σn1(vn)).

For a directive sequence s, denote by 𝖼𝗈𝗇𝗀𝖾𝗇𝗂𝖺𝗅𝗌s the set of all s-congenial αΣω. We next show that this set is finite.

Lemma 11.

Let Σ be an alphabet and s=(σn)n be a directive sequence over S(Σ). There exist at least one and at most |Σ| congenial expansions of the form (σn,an)n, and hence 1|𝖼𝗈𝗇𝗀𝖾𝗇𝗂𝖺𝗅𝗌s||Σ|.

Proof.

By Lem. 6, there exists (α(n))n over Σω such that σ0σn(α(n+1))=α(0) for all n. Let an be the first letter of α(n). We have that (σn,an+1) is congenial, and hence |𝖼𝗈𝗇𝗀𝖾𝗇𝗂𝖺𝗅𝗌s|1.

Now suppose there exist m|Σ|+1 congenial sequences (σn,an(i))n. By a pigeonhole argument, there must exist ij such that an(i)=an(j) for infinitely many n. From congeniality it follows that an(i)=an(j) for all n.

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 s=(σn)n be a directive sequence over S(Σ). A word αΣ+Σω is directed by s if and only if it can be expressed as a (possibly infinite) concatenation u0u1 of s-congenial words.

Proof.

Suppose α=u0u1, where ui𝖼𝗈𝗇𝗀𝖾𝗇𝗂𝖺𝗅𝗌s for all i. Let (σn,an(i))n be a congenial sequence generating ui, and ui(n)=limkσnσk(ak(i)) for all i. We have that un(i)=σn(un+1(i)) for all n. It remains to define α(n)=u0(n)u1(n). Then α(0)=α and αn(i)=σn(αn+1(i)) for all n.

Now suppose α is s-directed, and let (α(n))n be the witnessing sequence of words with α(0)=α. Write an for the first letter of α(n). We construct the desired factorisation inductively. Let v be the word defined by the congenial sequence (σn,an+1)n. By the choice of (an)n, v is a prefix of α. If v=α, then we are done. Otherwise, v must be finite. Let (vn)n be the unique sequence of finite words such that v0=v, vn is a prefix of α(n) for all n, and σn(vn+1)=vn for all n. Write α(n)=vnγ(n) for all n. Because σn(α(n+1))=α(n) for all n and σn(vn+1)=vn, we have that σn(γ(n+1))=γ(n). That is, γ=γ(0) is a suffix of α directed by s. Set u0=v, and repeat the process on γ.

If s is weakly primitive, then we have the following strengthening of Lem. 12.

Lemma 13.

Suppose s=(σn)n is weakly primitive and directs αΣω. Then α has a congenial expansion (σn,an)n.

Proof.

Let (α(n))n be such that α(0)=α and σn(α(n+1))=α(n), and an be the first letter of α(n+1). Then (σn,an)n is congenial, σ0σn(an) is a prefix of α for all n, and limn|σ0σn|= by the growth assumption. Therefore, (σn,an)n generates α.

Combining lemmas 6 and 13 we obtain the following.

Lemma 14.

Let s be a weakly primitive directive sequence. A word α is directed by s if and only if it is s-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 S(Σ), from the perspective of a finite ω-semigroup ML recognising an ω-regular language LΣω, they can be divided into finitely many equivalence classes.

Let LΣω be an ω-regular language, and let it be recognised by a morphism hL into a finite ω-semigroup ML=(ML,f,ML,ω), e.g., the morphism into the syntactic ω-semigroup as defined in [21, Sec. 11]. Observe that an ω-semigroup morphism from Σ into M is completely determined by the images of each letter in ML,f. Since ML,f is finite, there are only finitely many possible morphisms. We denote the set of these morphisms by 𝗆𝗈𝗋𝗉𝗁𝗂𝗌𝗆𝗌L. We make a small technical adaptation, and interpret these as monoid morphisms, i.e., we adjoin a fresh neutral element 1ML to ML, and assign h(ε)=1ML for each h.

We define an equivalence relation on the set of non-erasing substitutions σ:ΣΣ. Let 𝗌𝖾𝗀𝗆𝖾𝗇𝗍𝗌σ be the function that takes a letter aΣ and h𝗆𝗈𝗋𝗉𝗁𝗂𝗌𝗆𝗌L, and returns a finite sequence of pairs from Σ×ML, determined as follows. Write

σ(a)=b1v1bdvd

where b1,,bd are distinct letters and vi{b1,,bi} for all 1id. I.e., we consider the factorisation of σ(a) into segments based on the first occurrence of each letter. Then

𝗌𝖾𝗀𝗆𝖾𝗇𝗍𝗌σ(a,h)=(b1,h(v1)),,(bd,h(vd)). (6)

Note that there are only finitely many possibilities for 𝗌𝖾𝗀𝗆𝖾𝗇𝗍𝗌σ. For σ,μS(Σ), define

σLμ𝗌𝖾𝗀𝗆𝖾𝗇𝗍𝗌σ=𝗌𝖾𝗀𝗆𝖾𝗇𝗍𝗌μ.

We denote the class of σ by [σ]L, and the finite set of the equivalence classes by ΞL. We next show how to effectively provide representatives for the equivalence classes.

Lemma 15.

Given an ω-regular language L, we can compute morphisms σ1,,σm such that [σi]L[σj]L for all ij and ΞL={[σi]L:1im}.

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 a, we will find a word wa such that assigning σ(a)=wa is consistent with 𝗌𝖾𝗀𝗆𝖾𝗇𝗍𝗌σ(a,h) for all h. For aΣ and h𝗆𝗈𝗋𝗉𝗁𝗂𝗌𝗆𝗌L under consideration, let the purported 𝗌𝖾𝗀𝗆𝖾𝗇𝗍𝗌σ(a,h)=(b1,x1),,(bk,xk), with k1 such that bibj for all ij, and xiML, biΣ for all i. We can compute regular languages L1,,LkΣ such that for all i and wΣ, wLi if and only if h(wi)=xi and wi{b1,,bi}. Let La,h denote b1L1bkLk.

We can effectively check whether La=h𝗆𝗈𝗋𝗉𝗁𝗂𝗌𝗆𝗌LLa,h is non-empty, and if yes, effectively compute waLa. Such a word can be computed as an image for every letter (if and) only if the purported 𝗌𝖾𝗀𝗆𝖾𝗇𝗍𝗌σ is indeed realisable by assigning each σ(a) to the corresponding wa.

For technical convenience, we define the following auxiliary functions that can be derived from 𝗌𝖾𝗀𝗆𝖾𝗇𝗍𝗌σ; the first four of them are independent of L.

  1. (a)

    𝖾𝗑𝗉𝖺𝗇𝖽𝗂𝗇𝗀σ records for each letter a whether |σ(a)|>1. It evaluates to false if and only if 𝗌𝖾𝗀𝗆𝖾𝗇𝗍𝗌σ(a,h)=(b,1ML) for all h.

  2. (b)

    𝗂𝗇𝗍𝗋𝗈𝖽𝗎𝖼𝖾𝗌σ maps each letter to a finite sequence of pairs of letters with Boolean flags: if σ(a)=b1v1bdvd when factorised as in the definition of 𝗌𝖾𝗀𝗆𝖾𝗇𝗍𝗌σ, then 𝗂𝗇𝗍𝗋𝗈𝖽𝗎𝖼𝖾𝗌σ(a) is (b1,f1),,(bd,fd) where fi=1 if and only if viε.

  3. (c)

    𝗁𝖾𝖺𝖽σ maps each letter a to the first letter in σ(a).

  4. (d)

    𝗍𝖺𝗂𝗅σ takes as input a letter a and a morphism h. Write σ(a)=𝗁𝖾𝖺𝖽σ(a)v. We define 𝗍𝖺𝗂𝗅σ(a,h)=h(v).

  5. (e)

    𝖼𝗈𝗆𝗉𝗈𝗌𝖾σ:𝗆𝗈𝗋𝗉𝗁𝗂𝗌𝗆𝗌L𝗆𝗈𝗋𝗉𝗁𝗂𝗌𝗆𝗌L takes h and returns hσ.

We next argue that composition of morphisms can be defined on equivalence classes. Let σ,μ:ΣΣ be non-erasing. We show how to determine 𝗌𝖾𝗀𝗆𝖾𝗇𝗍𝗌σμ(a,h) using only 𝗌𝖾𝗀𝗆𝖾𝗇𝗍𝗌μ and 𝗌𝖾𝗀𝗆𝖾𝗇𝗍𝗌σ. Suppose μ(a)=b1v1bmvm, where biΣ and vi{b1,,bi} for all i. Then

σ(μ(a))=σ(b1)σ(v1)σ(bm)σ(vm)

and each letter of σ(vi) will have already appeared in one of σ(b1),,σ(bi). Write 𝗌𝖾𝗀𝗆𝖾𝗇𝗍𝗌σ(bi,h)=(ci,1,h(wi,1)),,(ci,ki,h(wi,ki)). Then σ(μ(a)) is equal to

c1,1w1,1c1,k1w1,k1σ(v1)cm,1wm,1cm,kmwm,kmσ(vm).

Write ti=wi,kiσ(vi). Observe that each letter of wi,j appears as a factor ce,l before wi,j in the factorisation above; the same applies to every ti. To compute 𝗌𝖾𝗀𝗆𝖾𝗇𝗍𝗌σμ(a,h) we begin with the finite sequence

(c1,1,h(w1,1)),,(c1,k11,h(w1,k11)),(c1,k1,h(t1))(cm,1,h(wm,1)),,(cm,km1,h(wm,km1)),(cm,km,h(tm)).

Note that the above can be effectively computed from 𝗌𝖾𝗀𝗆𝖾𝗇𝗍𝗌σ and 𝗌𝖾𝗀𝗆𝖾𝗇𝗍𝗌μ as h(ti)=h(wi,ki)h(σ(vi)) and the two factors can be gleaned from, respectively, 𝗌𝖾𝗀𝗆𝖾𝗇𝗍𝗌σ(bi,h) and 𝗌𝖾𝗀𝗆𝖾𝗇𝗍𝗌μ(a,𝖼𝗈𝗆𝗉𝗈𝗌𝖾σ(h)). Rename the indices in the sequence above to obtain (c1,h(w1),,(cM,h(wM)) where ciΣ and wiΣ for all i. Recall that wi{c1,,ci} for all i. But it is possible that ci=cj for some i,j. To eliminate these, we repeat the following process for as long as possible. Find the smallest j such that ci=cj for some i<j. Replace the two consecutive terms (cj1,h(wj1)),(cj,h(wj)) with (cj1,h(wj1)h(cj)h(wj)). In the end we are left with 𝗌𝖾𝗀𝗆𝖾𝗇𝗍𝗌σμ(a,h).

Observe that 𝗌𝖾𝗀𝗆𝖾𝗇𝗍𝗌σ only depends on ξ[σ]L; we can thus index the auxiliary functions (a-e) above by the equivalence class ξ. To summarise, we have the following.

Proposition 16.

The set ΞL is a finite monoid with the binary operation [σ]L[μ]L=[σμ]L and the identity element [𝗂𝖽]L, where 𝗂𝖽(w)=w for all wΣ.

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 [𝗂𝖽]L is indeed the identity element.

Let (σn)nI be a sequence over S(Σ), ξn=[σn]L for all n, and (an)nI be a sequence of letters from Σ, where I can be finite or infinite. We define 𝗍𝗋𝖺𝖼𝖾L((σn)nI)=(ξn)nI and 𝗍𝗋𝖺𝖼𝖾L((σn,an)nI)=(ξn,an)nI. We extend the definition of []L to finite sequences in the natural way: if I is finite, then [(σn)nI]L is the product nIξnΞL. The next result shows that for any infinite α and substitution σ, whether σ(α)L can be determined from [σ]L.

Lemma 17.

Let LΣω be an ω-regular language and αΣω. There exists ΦΞL such that for any σ:ΣΣ, σ(α)L if and only if [σ]LΦ. Furthermore, Φ can be effectively computed if we can compute h(α) for all h𝗆𝗈𝗋𝗉𝗁𝗂𝗌𝗆𝗌L.

Proof.

Recall [21, Thm. 7.6] that we have a set GML,ω such that for all αΣω, αL if and only if hL(α)G. We now view the substitution σ as an ω-semigroup morphism:

hL(σ(α))=hLσ(α)=𝖼𝗈𝗆𝗉𝗈𝗌𝖾σ(hL)(α).

We thus define Φ={ξΞL:𝖼𝗈𝗆𝗉𝗈𝗌𝖾ξ(hL)(α)G}. The effectiveness claim follows from the fact that 𝖼𝗈𝗆𝗉𝗈𝗌𝖾ξ(hL)𝗆𝗈𝗋𝗉𝗁𝗂𝗌𝗆𝗌L 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 LΣω, 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 σS(Σ) not the identity such that σ(α)=α. A word αΣω is morphic if it is of the form π(β) for πS(Σ) and β a substitutive word. For uΣ and substitutions σ,π, define σω(u)=limnσn(u) and πσω(u)=π(σω(u)). We will show that, for an ω-regular language L and substitutions σ,π, the respective equivalence classes ξ,ζΞL of substitutions σ,π determine:

  • Whether the substitution σ has a fixed point in L (Thm. 22).

  • A regular language (ξ,ζ)Σ+ such that πσω(u) is in L if and only if u(ξ,ζ) (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 u, u=, u= if u is finite, and u=u if u is infinite.

Lemma 18.

Let Σ be an alphabet and σ be a substitution. The following properties hold.

Saturation.

For uΣ, we have that σω(u)=σω(σ(u)).

Distributivity.

For u,vΣ, σω(uv)=σω(u)σω(v).

Left-Expansion.

For aΣ,uΣ+,vΣ,
if σω(a)=uσω(a)σω(v) then σω(a)=uω.

Right-Expansion.

For aΣ,uΣ, if σ(a)=au, then
σω(a)=auσ(u)σn(u).

Cycle of Contradiction.

Let a0,,ap1, p>1 be distinct letters such that 𝗁𝖾𝖺𝖽σp(a0)=a0, and for any r{1,,p1}, 𝗁𝖾𝖺𝖽σr(a0)=ar. We have that
σω(a0)==σω(ap1)=.

Terminal Letters.

If, for a letter a, σω(a)=uΣ+, then for all n|Σ|, σn(a)=u.

Proof.

Saturation.

The sequences (σn(u))n and (σn+1(u))n+1 have the same limit.

Distributivity.

We have that for all n, σn(uv)=σn(u)σn(v). If σω(u)=μΣ, then for all large n, σn(uv)=μσn(v). Taking the limit, we get σω(uv)=μσω(v). If σω(u)Σω, then for every position j, there exists N such that for all nN, |σn(u)|>j. In other words, every position j is eventually part of σn(u). Thus, σω(uv)=σω(u). However, if βΣω, then βμ=β for all μΣ. If σω(u)=, there is some position j such that the letter σn(u)(j) fluctuates with n. This means that the limit of σn(u)σn(v) 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 σn(ar) keeps alternating between a0,,ap1.

Terminal Letters.

We find the set A of letters a such that σω(a)=uΣ+ by saturation. The key idea is that if σω(a) converges within n iterations, then σω(σ(a)) must converge within n1 iterations, i.e., for every letter b in σ(a), σω(b) must converge within n1 iterations.

We start with the set A0 of letters a0 such that σ(a0)=a0. We construct An+1 as the union of An with the set of letters an+1 such that σ(an+1) only contains letters from An. This construction will saturate within |Σ| steps. The invariant is that Aj is the set of a such that σω(a) converges within j iterations. We conclude that since for n|Σ|, An=A|Σ|, if σω(a) converges in n steps then it must have already converged within |Σ| steps.

The following result, along with distributivity, implies that whether σω(u) for a finite word u is an infinite word accepted by 𝒜 is determined by the equivalence class [σ]L; this is the main technical novelty of this section.

Theorem 19.

Let LΣω be an ω-regular language recognised by an ω-semigroup ML=(ML,f,ML,ω). For any h𝗆𝗈𝗋𝗉𝗁𝗂𝗌𝗆𝗌L, substitutions σ,τS(Σ) with σLτ, and aΣ, we have that hσω(a)=hτω(a). Moreover, hσω(a) can be computed given only the equivalence class ξΞL of σ,τ along with the values of h,a.

Proof.

By Lem. 18, we have a dynamic programming algorithm to compute hσω(a) in a “depth-first” manner. We shall show that this algorithm only uses [σ]L=ξ.

Consider bΣ and write σ(b)=c1v1ckvk, where the factorisation is based on the first occurrence of each letter: we get c1,,ck from 𝗂𝗇𝗍𝗋𝗈𝖽𝗎𝖼𝖾𝗌ξ. By Saturation, we have that

hσω(b)=hσω(c1)hσω(v1)hσω(ck)hσω(vk).

We observe that the terms hσω(vi) will affect the result only if all hσω(cj) for ji are elements of ML,f. In this case, σω(vi) will also be a finite word, and by the Terminal Letters property, be σ|Σ|(vi). We denote hσ|Σ| by g; thus in this case, we have hσω(vi)=g(vi). We can rewrite

hσω(b)=hσω(c1)g(v1)hσω(ck)g(vk). (7)

The elements g(v1),,g(vk) can be obtained from 𝗌𝖾𝗀𝗆𝖾𝗇𝗍𝗌ξ(b,g). If c1=b, we are in the simpler case of Right-Expansion where σ(b)=bu, and have that

hσω(b)=h(b)h(u)hσ(u)hσ2(u).

The first two terms are easily obtained through 𝗍𝖺𝗂𝗅ξ, and hσn(u)=𝗍𝖺𝗂𝗅ξ(b,𝖼𝗈𝗆𝗉𝗈𝗌𝖾ξn(h)). Since the sequence of monoid elements ξn is effectively ultimately periodic, so is the sequence of factors in the above infinite product, allowing us to compute it.

If c1b, we first check that there is no r such that σr(c1)=b: this can be done with access to 𝗁𝖾𝖺𝖽ξr for r|Σ|. If this check fails, we have a Cycle of Contradiction, and have that hσω(b)=.

We now evaluate expansion (7). Write m0=1ML, and

mi=hσω(c1)g(v1)hσω(ck)g(vi).

Clearly, mi+1=mihσω(ci+1)g(vi+1), and

hσω(b)=mihσω(ci+1)g(vi+1)hσω(ck)g(vk).

In particular when miML,f for some i, then hσω(b)=mi. For each i, if cib, we evaluate hσω(ci) (we make a recursive call if it has not been evaluated before, otherwise we look up the memoized value). Otherwise, ci=b and we are in the case of Left-Expansion, and get that hσω(b)=mi1ω. In any case, we will eventually compute mk=hσω(b).

The result follows by applying the above depth-first routine to compute hσω(a).

As a corollary, we obtain that whether π(σω(u)) belongs to an ω-regular language L is completely determined by the equivalence classes [σ]L and [π]L: indeed, acceptance only depends on hLπσω(u), which is the same as h𝖼𝗈𝗆𝗉𝗈𝗌𝖾[π]L(hL) applied to σω(u).

Corollary 20.

Let LΣω be an ω-regular language. For any letter a, ah𝗆𝗈𝗋𝗉𝗁𝗂𝗌𝗆𝗌L, and substitutions σ,π, we can compute hπσω(a) given only h,a,[σ]L,[π]L.

We thus arrive at the following.

Theorem 21.

Let LΣω be an ω-regular language and σ,π be substitutions with respective equivalence classes ξ,ζΞL. We can compute a regular language (ξ,ζ)Σ+ such that πσω(u)L if and only if u(ξ,ζ).

Proof.

We construct a deterministic finite-word automaton recognising (ξ,ζ). The set of states is the set of elements of ML,fML,ω, the initial state is 1ML, the set of accepting states is G (the semigroup elements whose preimages comprise L), and the transition function maps (m,a) to m(hLπσω)(a). The latter is effective by Cor. 20.

Finally, whether σ has a fixed point in L is effectively determined by [σ]L.

Theorem 22.

Let LΣω be an ω-regular language and σ be a substitution. Given [σ]L and h𝗆𝗈𝗋𝗉𝗁𝗂𝗌𝗆𝗌L, we can compute the set {h(α):σ(α)=α}ML.

Proof.

We observe that any fixed point of σ must be a concatenation of words σω(a), where σ(a)=au for uΣ. Write A for the set of all such letters a, which can be extracted from 𝗂𝗇𝗍𝗋𝗈𝖽𝗎𝖼𝖾𝗌σ. The required set is then the sub-ω-semigroup of ML generated by {hσω(a):aA}, 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 S-adic words. In this section, let LΣω be an ω-regular language recognised by a morphism hL into a finite ω-semigroup ML=(ML,f,ML,ω), and HML,ω be such that hL1(H)=L. For convenience, further let 𝒜 be a deterministic automaton accepting L. Recall the set ΞL of equivalence classes of substitutions modulo ML, defined in Sec. 5. We will first prove that for congenial s^ over S(Σ)×Σ, defining a word accepted by 𝒜 is a property of 𝗍𝗋𝖺𝖼𝖾L(s^), and the set of all such traces is ω-regular.

Theorem 23 (Main Result for Generated Words).

Let LΣω be an ω-regular language. We can compute an automaton over ΞL×Σ such that for all infinite sequences s^ over S(Σ)×Σ, accepts 𝗍𝗋𝖺𝖼𝖾L(s^) if and only if s^ is congenial and generates a word in L.

Proof.

The automaton accepts s^(ΞL×Σ)ω if and only if s^ is accepted by x (constructed in Lem. 24 below) for some xH. Intuitively, x, upon reading s^, checks that the expansion is congenial. If yes, then the generated word can be factorised as u0u1 as described in Lem. 12. The automaton then evaluates the product hL(u0u1)=hL(u0)hL(u1).

Lemma 24.

Let xML,fML,ω. We can construct an automaton x over ΞL×Σ such that for all infinite sequences s^ over S(Σ)×Σ, x accepts 𝗍𝗋𝖺𝖼𝖾L(s^) if and only if s^ is congenial and hL(α)=x, where α is the word generated by s^.

Proof.

Recall that a sequence s=(σn,an)n over ΞL×Σ is congenial if and only if 𝗁𝖾𝖺𝖽ξn(an)=an1 for all n1, where ξn=[σn]L. This property depends only on 𝗍𝗋𝖺𝖼𝖾L(s). The automaton x, first and foremost, checks the condition above for all n1, and permanently transitions into a rejecting state if it observes a violating triple ξn,an,an1.

Now suppose s=(σn,an)n is congenial, and define ξn as above. As shown in Lem. 10,

σ0σn(an)=σ0(a0)σ0(v1)σ0σ1(v2)(σ0σn1(vn))

for all n, where vn satisfies σn(an)=an1vn. Let u0=σ0(a0) and un=σ0σn1(vn) for n1. By the properties of infinite products in ML (see Sec. 2.2) we have that hL(α)=x if and only if n=0hL(un)=x. The automaton x simulates the run of the automaton 𝒜x of Lem. 2 on the sequence (hL(un))n. It remains to show how the automaton keeps track of hL(un) as it reads (ξn,an)n. We have that

hL(u0) =(𝖼𝗈𝗆𝗉𝗈𝗌𝖾ξ0(hL))(a0),
hL(un) =𝗍𝖺𝗂𝗅ξn(an,𝖼𝗈𝗆𝗉𝗈𝗌𝖾ξ0ξn1(hL))

for n1. The automaton x keeps track of one piece of information ξΞL, in addition to the state required for simulating a run of 𝒜x on (hL(un))n. Before reading (ξn,an) the value of ξ is ξ0ξn1, where the empty product (corresponding to the initial value of ξ) is the identity element of ΞL. Upon reading (ξn,an), the automaton x first computes hL(un), in which the value of ξ is used, then feeds the computed value to 𝒜x, and finally updates ξ to ξξn. Finally, x accepts (σn,an)n if and only if 𝒜x accepts (hL(un))n.

When S is finite, for every individual σS(Σ) we can compute the equivalence class [σ]L, which yields the following.

Corollary 25.

Let SS(Σ) be finite. We can compute an automaton over S×Σ such that accepts s^ if and only if s^ is congenial and generates a word in L.

We next consider S-directed words, which are products of congenial words by Lem. 12.

Theorem 26 (Main Result for Directed Words).

Let LΣω be an ω-regular language. We can construct an automaton over ΞL such that for all sS(Σ)ω, accepts 𝗍𝗋𝖺𝖼𝖾L(s) if and only if s directs some αL.

Proof.

Denote the image of 𝖼𝗈𝗇𝗀𝖾𝗇𝗂𝖺𝗅𝗌s under hL by XsML,fML,ω. 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 𝗍𝗋𝖺𝖼𝖾s for which the sub-ω-semigroup generated by Xs intersects the accepting set H. We can precompute a set 𝒳 of sets X that generate sub-ω-semigroups intersecting H. Our automaton needs to check that Xs contains at least one such set X. We denote by 𝒞x the projection of x from Thm. 24 to ΞL, and observe: s() if and only if X𝒳xXs(𝒞x).

Corollary 27.

Let SS(Σ) be finite. We can compute an automaton over S such that accepts s if and only if s directs a word in L.

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 Σ={0,,d1}. Let S={λ0,,λd1,ρ0,,ρd1}. Recall that a word α is Arnoux-Rauzy if and only if it is directed by a sequence sSω 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, sSω is weakly primitive if and only if for every 0i<d, either ρi or λi 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 Σ={0,,d1}, LΣω be an ω-regular language, and S be the finite set of morphisms generating the Arnoux-Rauzy words over Σ as described above. We can compute an automaton 𝒞 that accepts sSω if and only if s is weakly primitive, contains infinitely many left-proper terms, and the unique Arnoux-Rauzy word directed by s is in L.

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 N(𝒜) terms in the continued fraction expansion of η, where N is independent of the slope η.

Fix an alphabet Σ, a (deterministic) automaton 𝒜 over Σ recognising an ω-regular language L, a class of uniformly recurrent words 𝒲Σω, and SS(Σ) such that

  1. 1.

    α𝒲 if and only if α is directed (and hence generated) by some weakly primitive sSω, and

  2. 2.

    there exists a computable function p such that pα(n)=p(n) for all α𝒲 and n, where pα(n) is the number of distinct factors of α of length n.

By assumption (1), every α𝒲 is uniformly recurrent (see Sec. 3). Characteristic Sturmian, Sturmian, and d-letter Arnoux-Rauzy words are captured, respectively, with S={λ0,λ1}, p(n)=n+1; S={λ0,ρ0,λ1,ρ1}, p(n)=n+1; and S={λ0,,λd1,ρ0,,ρd1}, p(n)=n(d1)+1 (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 u that is p-saturated with respect to 𝒜, i.e., any uniformly recurrent extension β of u with factor complexity p agrees with α upon acceptance by 𝒜 (Lem. 29), and hence also agrees upon membership in the recognised ω-regular language L. 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 M such that any β𝒲 with β[0,M)=α[0,M) 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 Rα(n): given n, enumerate prefixes α[0,B) and integers K until we find that (i) α[0,B) contains exactly pα(K) distinct factors of length K, and (ii) each of these pα(K) factors contains pα(n) distinct factors of length n. Then K=Rα(n).

Applying Prop. 5, we obtain M1 and such that for any β𝒲, if α[0,M1)=β[0,M1) and Rα(n)=Rβ(n) for n, then α and β agree upon acceptance by 𝒜. By the above paragraph, we can compute M2 such that if α[0,M2)=β[0,M2), then Rα(n)=Rβ(n) for n. It remains to take M=max(M1,M2).

Recall Lem. 13. Given a weakly primitive and congenial expansion (σn,an)n of α, we can compute an increasing sequence (kn)n with k0=0 such that, writing ln=kn+11, τn=σknσln and bn=aln, each τn is positive, none of the strict prefixes of the composition σknσln is positive, and (τn,bn)n is also a congenial expansion of α. We refer to (τn,bn)n as the sequence of partial quotients of (σn,an)n. Since each τn 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 N (that depends only on 𝒜 and 𝒲) with the following property. Let α,α be in 𝒲 with congenial S-adic expansions (σn,an)n,(σn,an)n and partial quotients (τn,bn)n and (τn,bn)n, respectively. If τnLτn and bn=bn for all nN, then 𝒜 accepts α if and only if it accepts α.

Proof.

Let P be the set of all positive products σ1σr such that σiS for all i and σ1σi is not positive for all i<r. Construct finite ΠP such that {[π]L:πP}={[π]L:πΠ} and for all distinct π1,π2Π we have that [π1]L[π2]L. Let Ω be the set of all congenial (πn,bn)n over Π×Σ. From the definition of congeniality it follows that Ω(Π×Σ)ω is closed. Since (Π×Σ)ω is compact, so is Ω.

Next, consider α with a congenial expansion s^=(πn,bn)nΩ. 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 (πn,bn)n=0M for some M, that is p-saturated. Write ΩM for the set of all s^Ω whose first M terms generate a p-saturated finite word, observing that each ΩM is open. From Lem. 29 it follows that {ΩM:M} is an open cover of Ω, which, by compactness, admits a finite sub-cover. That is, there exists N (which can be effectively computed by enumeration) such that for every (πn,bn)nΩ, (πn,bn)n=0N generates a finite word that is p-saturated. That is, for expansions in Ω, whether the generated word is accepted or not only depends on the first N terms.

Now consider (arbitrary) α𝒲 as in the statement of the theorem. Let (πn)n over Π be such that τnLπn for all n, and observe that t^(πn,bn)n is also congenial. Let β be the word generated by t^. By Thm. 24, 𝒜 accepts α if and only if it accepts β. By the earlier argument, whether 𝒜 accepts β only depends on (πn,bn)n=0N. It remains to observe that (πn,bn)n=0N is completely determined by (τn,bn)n=0N. Let us illustrate this result on Sturmian words. Given an automaton 𝒜, apply Thm. 30 with S={λ0,λ1,ρ0,ρ1} and p(n)=n+1 to compute N. Let η(0,1), χ[η,1η], [0;a1+1,a2,] be the continued fraction expansion of η, (bn)n 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

(σn)n=ρ0b1,λ0c1,ρ1b2,λ1c2,ρ0b3,λ0c3,ρ1b4,λ1c4,

where ci=aibi. By the rules of Ostrowski expansion, at least one of cn,cn+1 is non-zero for all n. Moreover, every composition of morphisms from {λ0,λ1,ρ0,ρ1} that includes two morphisms with differing indices is positive. Since at least one of bn,cn is non-zero for all n>1 (we could, however, have a1=b1=c1=0), we have that σnσn+5 is positive for every n. Applying Thm. 30, whether α is accepted by 𝒜 can be determined by looking at the first 6N digits (where N depends on 𝒜) of the computable expansions of η and χ, since these are guaranteed to generate at least the first N partial quotients of the unique S-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: S-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.