Synthesis of Computable Regular Functions of Infinite Words

Regular functions from infinite words to infinite words can be equivalently specified by MSO-transducers, streaming $\omega$-string transducers as well as deterministic two-way transducers with look-ahead. In their one-way restriction, the latter transducers define the class of rational functions. Even though regular functions are robustly characterised by several finite-state devices, even the subclass of rational functions may contain functions which are not computable (by a Turing machine with infinite input). This paper proposes a decision procedure for the following synthesis problem: given a regular function $f$ (equivalently specified by one of the aforementioned transducer model), is $f$ computable and if it is, synthesize a Turing machine computing it. For regular functions, we show that computability is equivalent to continuity, and therefore the problem boils down to deciding continuity. We establish a generic characterisation of continuity for functions preserving regular languages under inverse image (such as regular functions). We exploit this characterisation to show the decidability of continuity (and hence computability) of rational and regular functions. For rational functions, we show that this can be done in $\mathsf{NLogSpace}$ (it was already known to be in $\mathsf{PTime}$ by Prieur). In a similar fashion, we also effectively characterise uniform continuity of regular functions, and relate it to the notion of uniform computability, which offers stronger efficiency guarantees.


Introduction
Let Inputs and Outputs be two arbitrary sets of elements called inputs and outputs respectively. A general formulation of the synthesis problem is as follows: for a given specification of a function S : Inputs → 2 Outputs relating any input u ∈ dom(S) 1 to a set of outputs S(u) ⊆ Outputs, decide whether there exists a (total) function f : dom(S) → Outputs such that (i) for all u ∈ dom(S), f (u) ∈ S(u) and (ii) f satisfies some additional constraints such as being computable in some way, by some device which is effectively returned by the synthesis procedure. Assuming the axiom of choice, the relaxation of this problem without constraint (ii) always has a positive answer. However with additional requirement (ii), a function f realising S may not exist in general. In this paper, we consider the particular case where the specification S is functional, 2 in the sense that S(u) is singleton set for all u ∈ dom(S). Even in this particular case, S may not be realisable while satisfying requirement (ii).
The latter observation on the functional case can already be made in the Church approach to synthesis [Alo62,JL69], for which Inputs, Outputs are sets of infinite words and f is required to be implementable by a Mealy machine (a deterministic automaton which can output symbols). More precisely, an infinite word α over a finite alphabet Σ is a function α : N → Σ and is written as α = α(0)α(1) . . .. The set of infinite words over Σ is denoted by Σ ω . In Church ω-regular synthesis, we have Inputs = Σ ω i and Outputs = Σ ω o , and functions S are specified by ω-automata over Σ i .Σ o . Thus, such an automaton defines a language L ⊆ (Σ i .Σ o ) ω and in turn, through projection, a function S L defined by S L (i 1 i 2 . . . ) = {o 1 o 2 · · · | i 1 o 1 i 2 o 2 · · · ∈ L}. Such a specification is said to be synchronous, meaning that it alternatively reads an input symbol and produces an output symbol. It is also ω-regular because it can be represented as an automaton over Σ i .Σ o . As an example, consider Σ i = Σ o = {a, b, @} and the function S swap defined only for all words of the form u 1 σ@u 2 such that u 1 ∈ {a, b} * and σ ∈ {a, b} by S swap (u 1 σ@u 2 ) = σu 1 @u 2 . The specification S swap is easily seen to be synchronous and ω-regular, but not realisable by any Mealy machine. This is because a Mealy machine is an input deterministic model and so cannot guess the last symbol before the @ symbol.
1.1. Computability of functions over infinite words. In Church synthesis, the notion of computability used for requirement (ii) is that of being computable by a Mealy machine. While this makes sense in a reactive scenario where output symbols (reactions) have to be produced immediately after input symbols are received, this computability notion is too strong in a more relaxed scenario where reactivity is not required. Instead, we propose here to investigate the synthesis problem for functional specifications over infinite words where the computability assumption (ii) for f is just being computable by some algorithm (formally a Turing machine) running on infinite inputs. In other words, our goal is to synthesize algorithms from specifications of functions of infinite words. There are classical computability notions for infinite objects, like infinite sequences of natural numbers, motivated by real analysis, or computation of functions of real numbers. The model of computation we consider for infinite words is a deterministic machine with three tapes: a read-only one-way tape holding the input, a two-way working tape with no restrictions and a write-only one-way output tape. All three tapes are infinite on the right. A function f is computable if there 1.2. Examples. The function S swap is computable. Since it is defined over all inputs containing at least one @ symbol, if a Turing machine is fed with such a word, it suffices for it to read its input and write it in working tape, until the first @ symbol is met. Now go back in the working tape to see the last symbol read before @, write the same in output tape. It is followed by further going back to the beginning in the working tape, and copying all the symbols of working tape except the last one from left to right into the output tape. This gives us the prefix σu 1 . The suffix @u 2 can simply be produced by copying the content of input tape into output tape.
Over the alphabet Σ = {a, b}, consider the function f ∞ defined by f ∞ (u) = a ω if u contains infinitely many as, and by b ω otherwise. This simple function is not computable, as it requires to read the whole infinite input to produce even the very first output symbol. For any word u ∈ Σ * , we denote by u its mirror (e.g. abaa = aaba). Consider the (partial) function f mir defined on (Σ * ) ω by f (u 1 u 2 . . .) = u 1 u 2 . . .. It is computable by a machine that stores its input u 1 in memory until the first is read, then outputs u 1 , and proceeds with u 2 , and so on. It is however not uniformly computable. Indeed, if it were, with some m : N → N, then, for inputs u 1 u 2 · · · such that |u 1 | > m(1), it is impossible to determine the first output symbol (which is the last of u 1 ) by reading only a prefix of length m(1) of u 1 .
Finally, consider the (partial) function f dbl defined on (Σ * ) ω by f (u 1 u 2 . . .) = u 1 u 1 u 2 u 2 . . .. Similarly as before, it is computable but also uniformly computable: to determine the i th output symbol, it suffices to read an input prefix of length at most i. Indeed, let u 1 u 2 . . . u be a prefix of length i of the input x, then u 1 u 1 u 2 u 2 . . . u is a prefix of f (x) of length ≥ i.
1.3. Computability and continuity. There are strong connections between computability and continuity: computable functions are continuous for the Cantor topology, that is where words are close to each other if they share a long common prefix. Intuitively, it is because the very definition of continuity asks that input words sharing longer and longer prefixes also share longer and longer output prefixes. It is the case of the functions f mir and f dbl seen before. Likewise, uniformly computable functions are uniformly continuous. The reverse direction does not hold in general: assuming an effective enumeration M 1 , M 2 , . . 1.4. Beyond synchronous functions: regular functions. Functional specifications in the Church ω-regular synthesis problem range over the class of synchronous functions as described before: they can be specified using automata over Σ i .Σ o . For example, while S swap and f ∞ are synchronous, f mir and f dbl are not. In this paper, we intend to go much beyond this class by dropping the synchronicity assumption and consider the so-called class of regular functions. It is a well-behaved class, captured by several models such as streaming ω-string transducers (SST), deterministic two-way Muller transducers with look around (2DMT la ), and also by MSO-transducers [AFT12, Thm. 1, Prop. 1]. We propose the model of deterministic two-way transducers with a prophetic Büchi look-ahead (2DFT pla ) and show that they are equivalent to 2DMT la . This kind of transducer is defined by a deterministic two-way automaton without accepting states, extended with output words on the transitions, and which can consult another automaton, called the look-ahead automaton, to check whether an infinite suffix satisfies some regular property. We assume this automaton to be a prophetic Büchi automaton [CPP08, Sec. 7], because this class is naturally suited to implement a regular look-ahead, while capturing all regular languages of infinite words. Look-ahead is necessary to capture functions such as f ∞ . Two-wayness is needed to capture, for instance, functions f dbl and f mir .
1.5. Contributions. We call effectively reg-preserving functions those functions that effectively preserve regular languages by inverse image [SH63,Kos74,SM76,PS17]. This includes for instance rational functions, regular functions and the more general class of polyregular functions [Boj18,EHS21]. We first show that for effectively reg-preserving functions, computability and continuity coincide, respectively, uniform computability and uniform continuity (Section 3, Theorem 3.4). To the best of our knowledge, this connection was not made before. The connection is effective, in the sense that when f is effectively reg-preserving and continuous (resp. uniformly continuous), we can effectively construct a Turing machine computing f (resp. uniformly computing f ). For rational functions (functions defined by non-deterministic one-way Büchi transducers), we show that continuity and uniform continuity are decidable in NLogSpace (Section 5, Theorem 5.2). Continuity and uniform continuity for rational functions were already known to be decidable in PTime, from Prieur [Pri02,Prop. 4]. However, Prieur's proof techniques do not transfer to the two-way case. We then prove that uniform continuity (and hence uniform computability) is decidable in PSpace for regular functions given by deterministic Büchi two-way transducers with look-ahead (Section 5, Theorem 5.7). Using the same techniques, we also get the decidability of continuity (and hence computability) for regular functions (Theorem 5.12) in PSpace. For both problems, we show that this upper-bound is tight, namely, both problems are PSpace-hard.
Our proof technique relies on a characterisation of non-continuous reg-preserving functions by the existence of pairs of sequences of words which have a nice regular structure (Section 4, Lemma 4.4). Based on this, we derive a decision procedure for continuity of rational functions by checking in NLogSpace a structural transducer pattern. This pattern expresses properties of synchronised loops on two runs of the transducers. The case of regular functions is much more involved as loops in two-way automata or transducers are more complex. We also give a characterisation via a structural pattern which we show to be checkable by a bounded-visit non-deterministic two-way Parikh automaton of polynomial size, yielding the PSpace upper bound as those automata can be checked in PSpace for emptiness [FGM19].
1.6. Related work. The notion of continuity has not been extensively studied in the transducers literature over infinite words. The work by Prieur [Pri02] is the closest to ours, while [CSV13] looks at continuity of regular functions encoded by ω-automata.
Notions of continuity with respect to language varieties have been studied for rational functions of finite words in [CCP17,CCP20]. Our notion of uniform continuity can be linked to continuity with respect to a particular language variety which was not studied in [CCP17] (namely the non-erasing variety generated by languages of the shape uA * ). A quite strong Lipschitz continuity notion, called bounded variation due to Choffrut (e.g. [Cho03]), was shown to capture, over finite words, the sequential functions (the corresponding topology is however trivial, hence simple continuity is not very interesting in this context).
Another result connecting computability and continuity is from [CKLP15] where the authors find that some notion of computability by AC 0 circuits corresponds, over sequential functions, to continuity with respect to some language variety.
Our result on rational functions has been extended recently to rational functions of infinite words over an infinite alphabet in [EFR20]. More precisely, continuity for functions of infinite data words defined by (one-way) transducers with registers has been shown to be decidable. The proof of [EFR20] goes by reduction to the finite alphabet setting and uses our result presented in the paper [DFKL20].
Changes from the conference version. The results in this paper are an extension of the work presented at CONCUR 2020 [DFKL20]. In the conference version, Lemmas 4.4 and 5.1 had only a short proof sketch; this version contains the full technical details. A major change from the conference version is in Section 5.2. This has an added contribution, where we present a new proof for the decidability of continuity and uniform continuity for regular functions. To aid us in this, we define what is called a critical pattern (Section 5.2.3) and show that the existence of such patterns in two way transducers help in deciding the continuity of the corresponding regular function (Proposition 5.4). Finally, in the proof of Theorem 5.7 and Theorem 5.12, we analyze the complexity of the pattern detection, which in turn yields a (tight) upper-bound for the complexity of checking continuity and uniform continuity of regular functions; this was left open in the CONCUR 20 paper.

Languages, Automata and Transducers over ω-Words
Given a finite set Σ, we denote by Σ * (resp. Σ ω ) the set of finite (resp. infinite) words over Σ, and by Σ ∞ the set of finite and infinite words. Let Σ j represent the set of all words over Σ with length j. We denote by |u| ∈ N ∪ {∞} the length of u ∈ Σ ∞ (in particular |u| = ∞ if u ∈ Σ ω ). For a word w = a 1 a 2 a 3 . . . , w[ : j] denotes the prefix a 1 a 2 . . . a j of w. Let w[j] denote a j , the j th symbol of w and w[j : ] denote the suffix a j+1 a j+2 . . . of w. For a word w and i ≤ j, w[i : j] denotes the factor of w with positions from i to j, both included. For two words u, v ∈ Σ ∞ , u v (resp. u ≺ v) denotes that u is a prefix (resp. strict prefix) of v (in particular if u, v ∈ Σ ω , u v if and only if u = v). For u ∈ Σ * , let ↑u denote the set of words w ∈ Σ ∞ having u as prefix i.e. u w. Let mismatch be a function which takes two words, and returns a boolean value, denoted by mismatch(u, v) for u and v; it returns true if there exists a position i ≤ |u|, |v| such that u[i] = v[i], and returns false otherwise. The longest common prefix between two words u and v is denoted by u ∧ v and their distance is A Büchi automaton is a tuple B = (Q, Σ, δ, Q 0 , F ) consisting of a finite set of states Q, a finite alphabet Σ, a set Q 0 ⊆ Q of initial states, a set F ⊆ Q of accepting states, and a transition relation δ ⊆ Q × Σ × Q. A run ρ on a word w = a 1 a 2 . . . ∈ Σ ω starting in a state q 1 in B is an infinite sequence q 1 Let Inf(ρ) denote the set of states visited infinitely often along ρ. The run ρ is a final run if Inf(ρ) ∩ F = ∅. A run is accepting if it is final and starts from an initial state. A word w ∈ Σ ω is accepted (w ∈ L(B)) if it has an accepting run. A language L of ω-words is called ω-regular if L = L(B) for some Büchi automaton B.
An automaton is co-deterministic if any two final runs on any word w are the same [CPP08, Sec. 7.1]. Likewise, an automaton is co-complete if every word has at least one final run. A prophetic automaton P = (Q P , Σ, δ P , Q 0 , F P ) is a Büchi automaton which is co-deterministic and co-complete. Equivalently, a Büchi automaton is prophetic if and only if each word admits a unique final run. The states of the prophetic automaton partition Σ ω : each state q defines a set of words w such that w has a final run starting from q. For any state q, let L(P, q) be the set of words having a final run starting at q. Then Σ ω = q∈Q P L(P, q). It is known [CPP08, Thm. 7.2] that prophetic Büchi automata capture ω-regular languages.
2.1. Transducers. We recall the definitions of one-way and two-way transducers over infinite words. A one-way transducer A is a tuple (Q, Σ, Γ, δ, Q 0 , F ) where Q is a finite set of states, Q 0 , F respectively are sets of initial and final states; Σ, Γ respectively are the input and output alphabets; δ ⊆ (Q × Σ × Q × Γ * ) is the transition relation. We equip A with a Büchi acceptance condition. A transition in δ of the form (q, a, q , γ) represents that from state q, on reading a symbol a, the transducer moves to state q , producing the output γ. Runs, final runs and accepting runs are defined exactly as in Büchi automata, with the addition that each transition produces some output ∈ Γ * .
The output produced by a run ρ, denoted out(ρ), is obtained by concatenating the outputs generated by transitions along ρ. Let dom(A) represent the language accepted by the underlying automaton of A, ignoring the outputs. The relation computed by A is defined as ] is a function. A relation (function) is rational if it is recognised by a one-way (functional) transducer.
Two-way transducers extend one-way transducers and two-way finite state automata. A two-way transducer is a two-way automaton with outputs. In [AFT12, Prop. 1], regular functions are shown to be those definable by a two-way deterministic transducer with Muller acceptance condition, along with a regular look-around (2DMT la ). In this paper, we propose an alternative machine model for regular functions, namely, 2DFT pla . A 2DFT pla is a deterministic two-way automaton with outputs, along with a look-ahead given by a prophetic automaton.  Figure 1: A 2DFT pla with automaton on the right implementing the look-ahead.
is a prophetic Büchi automaton and T = (Q, Σ, Γ, δ, q 0 ) is a two-way transducer such that Σ and Γ are finite input and output alphabets, Q is a finite set of states, q 0 ∈ Q is a unique initial state, δ : +1} is a partial transition function. T has no acceptance condition: every infinite run in T is a final run. A two-way transducer stores its input a 1 a 2 . . . on a two-way tape, and each index of the input can be read multiple times. A configuration of a two-way transducer is a tuple (q, i) ∈ Q × N where q ∈ Q is a state and i ∈ N is the current position on the input tape. The position is an integer representing the gap between consecutive symbols. Thus, before , the position is 0, between and a 1 , the position is 1, between a i and a i+1 , the position is i + 1 and so on. The 2DFT pla is deterministic: for every word w = a 1 a 2 a 3 . . . ∈ Σ ω , every input position i ∈ N, and state q ∈ Q, there is a unique state p ∈ Q A such that a i a i+1 . . . ∈ L(A, p). Given w = a 1 a 2 . . ., from a configuration (q, i), on a transition δ(q, a i , p) = (q , γ, d), d ∈ {−1, +1}, such that a i+1 a i+2 . . . ∈ L(A, p), we obtain the configuration (q , i + d) and the output γ is appended to the output produced so far. This transition is denoted as (q, i) The output of ρ, denoted out(ρ) is then γ 1 γ 2 · · · . The run ρ reads the whole word w if sup{i n | 0 ≤ n < |ρ|} = ∞. The output [[(T , A)]](w) of a word w on run ρ is defined only when sup{i n | 0 ≤ n < |ρ|} = ∞, and equals out(ρ). 2DFT pla are equivalent to 2DMT la , and capture all regular functions. It is easy to see because different representations of ωlook-ahead are equiexpressive, the look-behind of 2DMT la can be eliminated while preserving the expressiveness, and one can encode the acceptance condition of 2DMT la as part of the look-ahead in 2DFT pla (see Appendix A for the proof).
Theorem 2.1. A function f : Σ ω → Γ ω is regular if and only if it is 2DFT pla definable.
Example 2.2. Consider the function g : Σ ω → Γ ω over Σ = Γ = {a, b} such that g(uab ω ) = uub ω for u ∈ Σ * and g(b ω ) = b ω . The 2DFT pla is shown in Figure 1 with the prophetic look-ahead automaton A on the right. The transitions are decorated as α, p | γ, d where α ∈ {a, b}, p is a state of A, γ is the output and d is the direction. In transitions not using the look-ahead information, the decoration is simply α | γ, d. Notice that L(A, p 1 ) = Σ + ab ω , Each word in Σ ω has a unique final run.
We also use a look-ahead-free version of two-way transducers in some of the proofs, where we also have a Büchi acceptance condition given by a set of states F , just as for Büchi automata. The resulting model is called two-way deterministic Büchi transducer (2DBT). The definitions of configuration, run, and the semantics are done just like for 2DFT pla .

Computability versus Continuity
Computability of a function on infinite words can be described intuitively in the following way: there is an algorithm which, given access to the input word, can enumerate the letters in the output word. We also investigate a stronger notion of computability, which we call uniform computability. The main idea is that given some input word x and some position j one can compute the j th position of the output in time that depends on j but not on x. An appealing aspect of uniform computability is that it offers a uniform bound on the number of input symbols one needs to read in order to produce the output at some fixed precision.
Definition 3.1 (Computability/Uniform computability). A function f : Σ ω → Γ ω is computable if there exists a deterministic multitape Turing machine M computing it in the following sense. The machine M has a read-only one-way input tape, a two-way working tape, and a write-only one-way output tape. All tapes have a left delimiter and are infinite to the right. Let x ∈ dom(f ). For any j ∈ N, let M (x, j) denote the output produced by M till the time it moves to the right of position j, onto position j + 1 in the input (or if this move never happens). The function f is computable by M if for all x ∈ dom(f ), for all Moreover if there exists a computable function m : N → N (called a modulus of continuity for M ) such that for all It turns out that there is a quite strong connection between computability and continuity of functions. In particular computable functions are always continuous. This can be seen intuitively since given a deterministic Turing machine, it must behave the same on the common prefixes of two words. Hence two words with a very long common prefix must have images by the machine that have a somewhat long common prefix. This connection also transfers to uniform computability and uniform continuity. We start by formally defining continuity and uniform continuity.
Definition 3.2 (Continuity/Uniform continuity). We interchangeably use the following two textbook definitions [Rud76] of continuity.
there exists m : N → N, called a modulus of continuity for f such that, Example 3.3. As explained in the introduction, the function f ∞ is not continuous, and, as we will see later, is thus not computable. The function f halt is continuous, even uniformly continuous (it is constant) yet is obviously not computable. The function f mir is computable, however is not uniformly continuous, two words can be arbitrarily close but with far away outputs: consider a n ω and a n b ω . Finally, the function f dbl is uniformly computable.
We now investigate the relationship between continuity and computability for functions that are effectively reg-preserving. More precisely, we say that a function f : Σ ω → Γ ω is effectively reg-preserving if there is an algorithm which, for any automaton recognising a regular language L ⊆ Γ ω , produces an automaton recognising the language Two well-studied classes (see e.g. [Fil15]) of reg-preserving functions are the rational and the regular functions, which we will study in Section 5. As announced, continuity and computability coincide for effectively reg-preserving functions: Theorem 3.4. An effectively reg-preserving function f : Σ ω → Γ ω is computable (resp. uniformly computable) if and only if it is continuous (resp. uniformly continuous).
Proof. ⇒) This implication is easy and actually holds without the reg-preserving assumption. Assume that f is computable. We prove the continuity of f . Let M be the machine computing f . Let x ∈ dom(f ) be the content on the input tape of M . Intuitively, the longer the prefix of input x ∈ dom(f ) is processed by M , the longer the output produced by M on that prefix, which converges to f (x), according to the definition of computability. For all i ≥ 0, define Pref M (x, i) to be the smallest j ≥ 0 such that, when M moves to the right of x[ : j] into cell j + 1, it has output at least the first i symbols of f (x). For any i ≥ 0, choose j = Pref M (x, i). Consider any z ∈ dom(f ) such that |x ∧ z| ≥ j. After reading j symbols of x, the machine M outputs at least i symbols of f (x). Since |x ∧ z| ≥ j, the first j symbols of x and z are the same, and M being deterministic, outputs the same i symbols on reading the first j symbols of z as well. These i symbols form the prefix for both f (x), f (z), and Thus, for every x ∈ dom(f ) and for all i, there exists Moreover, if f is uniformly computable, then the modulus of continuity of M is in particular a modulus of continuity for f and is thus uniformly continuous.
Input: x ∈ Σ ω 1 out := ; this is written on the working tape out := out.γ ; append to the working tape 6 output γ ; this is written on the output tape ⇐) The converse direction is less trivial and makes use of the reg-preserving assumption. Suppose that f is continuous. We design the machine M , represented as Algorithm 1, which is shown to compute f . This machine processes longer and longer prefixes x[ : i] of its input x (for loop at line 2), and tests (line 4) whether a symbol γ can be safely appended to the output. The test ensures that the invariant out f (x) is preserved at any point. Moreover, the continuity of f at x ensures that out is updated infinitely often. The only thing left to obtain computability is that the test of line 4 is decidable. Let u and v be two words, deciding . These sets are effectively regular since u, v are given and f is effectively reg-preserving, and dom(f ) = f −1 (Γ ω ). Since the constructions are effective, and the languages are regular, the inclusion is decidable. We only have left to show that if f is moreover uniformly continuous, then M has a computable modulus of continuity. We start by showing that f has a computable modulus of continuity. Let us consider the predicate Since f is uniformly continuous, m is indeed well defined and is a modulus of continuity of f . To show that m is computable, we only have to show that P (i, j) is decidable.
Let us consider the negation of P Since f is effectively reg-preserving, S is effectively regular. By searching exhaustively for words v 1 , v 2 ∈ Γ i we get decidability of P (i, j). We only have left to define a modulus of continuity for M . Let m : N → N be defined by m (i) = m(i) + i. If we read m(i) symbols, we know we can output at least i symbols. Hence in each of the next i steps, we are guaranteed to output a letter. Hence m is a modulus of continuity for M and f is uniformly computable.
Remark 3.5. Note that we focus on functions that are effectively reg-preserving, but Algorithm 1 is actually more general than that. The continuity-computability equivalence indeed carries over to any class of functions for which the test in line 4 is decidable.

A Characterisation of Continuity and Uniform Continuity
We provide here a characterisation of continuity (and uniform continuity) for reg-preserving functions (we don't need effectiveness here). The characterisation is based on a study of some particular properties of sequences and pairs of sequences which we define below.
Topology preliminaries. A regular word (sometimes called ultimately periodic) over Σ is a word of the form uv ω with u ∈ Σ * and v ∈ Σ + . The set of regular words is denoted by Reg(Σ). The topological closure of a language L ⊆ Σ ω , denoted byL, is the smallest language containing it and closed under taking the limit of converging sequences, i.e.L = {x | ∀u ≺ x, ∃y, uy ∈ L}. A language is closed if it is equal to its closure. A sequence of words (x n ) n∈N is called regular if there exists u, v, w ∈ Σ * , z ∈ Σ + such that for all n ∈ N, x n = uv n wz ω . The proof of the characterisation of continuity (Lemma 4.4) requires the following folklore or easy to show propositions: Proposition 4.1. Let L ⊆ Σ ω be regular language, then (1)L is regular, (2) L ⊆ L ∩ Reg(Σ) (i.e. the regular words are dense in a regular language), (3) any regular word ofL is the limit of a regular sequence of L Proof. Proof of Proposition 4.1.3: Let L ⊆ Σ ω be regular. Let uv ω be a regular word inL. By regularity of L, there is a power of v, v k such that for any words, w, x, wv k x ∈ L ⇔ wv 2k x ∈ L. Let us consider the language K = x | uv k x ∈ L which is non-empty since uv ω ∈L. Moreover, K is regular, and thus contains a regular word wz ω . Hence we have that uv ω is the limit of the sequence uv kn wz ω n∈N of L. Proof. The case of continuous functions is obtained just by definition. For uniform continuity, consider a function f with a bad pair ((x n ) n∈N , (x n ) n∈N ), and let us show that it is not uniformly continuous. We can assume that both (f (x n )) n∈N and (f (x n )) n∈N converge.
Otherwise we can extract subsequences that converge, by compactness of Γ ω . Moreover, since the pair is bad, one can assume that they converge to different limits y = y . Let i be such that y For any j, one can find N such that for all n ≥ N , |x n ∧ x n | ≥ j since both sequences converge to x. Since (f (x n )) n∈N converges to y, we can ensure that N is large enough so that for all n ≥ N , |f (x n ) ∧ y| ≥ i. We can also ensure that for n ≥ N , which means that f is not uniformly continuous. Let f be a function which is not uniformly continuous, we want to exhibit a bad pair of f . According to the definition, there exists i such that for all j there exist x j , x j with |x j ∧ x j | ≥ j but |f (x j ) ∧ f (x j )| < i. By compactness of Σ ω , there exists a subsequence of (x j ) j∈N which is convergent. Let x τ (j) j∈N , with τ : N → N increasing, denote such a subsequence. Then we have for all j that |x τ (j) ∧x τ (j) | ≥ τ (j) ≥ j and |f (x τ (j) )∧f (x τ (j) )| < i. Therefore up to renaming the sequences, we can assume that for all j, |x j ∧ x j | ≥ j and |f (x j ) ∧ f (x j )| < i, with (x j ) j∈N being convergent. By repeating the process of extracting subsequences, we can assume that are also convergent.
Since for any j, |x j ∧ x j | ≥ j, the two sequences converge to the same limit. In the end we Note that in case dom(f ) is not compact, then we may not have a subsequence of (x j ) j∈N which converges in dom(f ). However, the definition of bad pairs does not require convergence in the domain; it only asks for convergence to some x, which need not be in dom(f ).
The main result of this section is the following lemma which says that one can restrict to considering only synchronised bad pairs. In the following sections this characterisation will be used to decide continuity/uniform continuity.  Proof. This lemma extends Proposition 4.3. It shows that, in the case of reg-preserving functions, one can restrict to considering synchronised pairs, which are much easier to deal with. The only if direction is a simple consequence of Proposition 4.3. For the other direction, we first show that for a reg-preserving function f , if there is a bad pair at some x, then there is one at some regular z, i.e. z = uv ω for some finite words u, v. Moreover, for the case of non-uniform continuity, we show that z can be chosen so that x ∈ dom(f ) ⇔ z ∈ dom(f ). In a second step, since we have two sequences converging to a regular z, we show how to replace the bad pair by a bad pair of regular sequences, still using the fact that f is reg-preserving. Finally, we prove that we can synchronise these two regular sequences and end up with a synchronised bad pair at z. Let f : Σ ω → Γ ω be a reg-preserving function which is not uniformly continuous. Then according to Proposition 4.3, it has a bad pair ((x n ) n∈N , (x n ) n∈N ) at some point x. If f is not continuous then we can assume that x ∈ dom(f ). Our goal is to exhibit a synchronised bad pair at a point z, such that if x ∈ dom(f ) then z ∈ dom(f ).
By compactness of Γ ω , we can extract subsequences such that both (f (x n )) n∈N and (f (x n )) n∈N converge. Moreover, since the pair is bad, one can assume that they converge to different limits y = y . Let i be such that y[i] = y[i ] and let B y = {z | |y ∧ z| ≥ i} = ↑y[ : i] and B y = {z | |y ∧ z| ≥ i} = ↑y [ : i]. By definition we have B y ∩ B y = ∅, and moreover both sets B y , B y are regular. Up to extracting subsequences, we can assume that for all n, x n ∈ f −1 (B y ) and x n ∈ f −1 (B y ). This means that x ∈ f −1 (B y ) ∩ f −1 (B y ). Since f is reg-preserving, and from Proposition 4.1.1, the set f −1 (B y ) ∩ f −1 (B y ) is regular, and nonempty. Hence there exists a regular word z ∈ f −1 (B y ) ∩ f −1 (B y ). Moreover, since dom(f ) is also regular, we can choose z so that x ∈ dom(f ) ⇔ z ∈ dom(f ). Since z ∈ f −1 (B y ), there is a sequence (z n ) n∈N of words in f −1 (B y ) which converges to z. Furthermore, since f −1 (B y ) is regular and since z is a regular word, we can assume, from Proposition 4.1.3, that the sequence (z n ) n∈N is regular. Similarly, there is a regular sequence (z n ) n∈N in f −1 (B y ) which converges to z.
If either sequence (f (z n )) n∈N or (f (z n )) n∈N is not convergent then we are done, because one of the pairs ((z n ) n∈N , (z n ) n∈N ) or ((z n ) n∈N , (z n ) n∈N ) is bad and of course synchronised. If both sequences are convergent, then lim n f (z n ) ∈ B y and lim n f (z n ) ∈ B y (because B y and B y are both closed), which means that | lim n f (z n ) ∧ lim n f (z n )| ≤ i, hence the pair (f (z n )) n∈N , (f (z n )) n∈N is bad. We only have left to show that we can synchronise the sequences. Let z n = uv n wt ω and let z n = u v n w t ω Let us first assume that z n is constant equal to z. Let z = u −1 z, we have that v n z = z and uv n z = z for any n. Thus the pair (z n ) n∈N , (z) n∈N is a synchronised bad pair.
Let us now assume that neither sequence is constant, which means that |v|, |v | > 0. Without loss of generality, let us assume that |u| ≥ |u |, let k ∈ N, let p < |v | be such that Note that v ω = v ω , which means that v |v | = v |v| . Let y n = z |v |n =uv |v |n wt ω and let y n = z |v|n =uv |v|n w t ω . Then the pair (y n ) n∈N , (y n ) n∈N is a synchronised bad pair at z.  Figure 2: Pattern characterising non-continuity of rational functions given by trim one-way Büchi transducers.

Deciding Continuity and Uniform Continuity
We first show how to decide (uniform) continuity for rational and then for regular functions.
5.1. Rational case. We exhibit structural patterns which are shown to be satisfied by a one-way Büchi transducer if and only if the rational function it defines is not continuous (resp. not uniformly continuous). We express those patterns in the pattern logic defined in [FMR18, Sec. 6], which is based on existential run quantifiers of the form ∃π : p u|v − − → q where π is a run variable, p, q are state variables and u, v are word variables. Intuitively, there exists a run π from state p to state q on input u, producing output v. A one-way transducer is called trim if each of its states appears in some accepting run. Any one-way Büchi transducer can be trimmed in polynomial time. The structural patterns for trim transducers are given in Figures 2 and 3. The predicate init(p) expresses that p is initial while acc(p) expresses that it is accepting. The predicate mismatch expresses the existence of a mismatch between two words, as defined in Section 2.
Lemma 5.1. A trim one-way Büchi transducer defines a non-continuous (resp. nonuniformly continuous) function if and only if it satisfies the formula φ cont of Figure 2 (resp. the formula φ u-cont of Figure 3).
Proof. Showing that the patterns of Figure 2 and Figure 3 induce non-continuity and nonuniform continuity, respectively, is quite simple. Indeed, the first pattern φ cont is a witness that (uv n wz) n∈N is a bad sequence at a point uv ω of its domain, for z a word with a final run from r 2 , which entails non-continuity by Proposition 4.3 (if a sequence s is bad then (s, s) is bad). Similarly, the pattern φ u-cont witnesses that the pair (uv n wz) n∈N , (uv n w z ) n∈N is synchronised and bad (with z, z words that have a final run from r 1 , r 2 , respectively), which entails non-uniform continuity.
For the other direction, we again use Lemma 4.4. From a synchronised bad pair, we can find a pair of runs with a synchronised loop, such that iterating the loop does not affect the Let us first show that if the pattern of φ cont appears, then we can exhibit a bad pair at a point of the domain. Let us assume φ cont holds. Then the word uv ω is in the domain of the function realised by the transducer since it has an accepting run. Let zt ω be a word accepted from state r 2 , which exists by trimness, and let us consider the pair (uv ω ) n∈N , (uv n wzt ω ) n∈N . We have f (uv ω ) = u 1 v ω 1 and u 2 lim n f (uv n wzt ω ). If mismatch(u 1 , u 2 ) then the pair is bad, otherwise, we must have v 2 = and thus u 2 w 2 lim n f (uv n wzt ω ). Since mismatch(u 1 , u 2 w 2 ) we again have that the pair is bad.
Let us assume that the function f is not continuous at some point x ∈ dom(f ). Then according to Lemma 4.4, there is a synchronised bad pair (uv n wz ω ) n∈N , (uv n w z ω ) n∈N converging to some point of dom(f ).
Our goal is to exhibit a pattern as in φ cont . If v is empty, then the sequences are constant which contradicts the functionality of T . So both the sequences converge to uv ω , but their output sequences either do not converge or if converges, then not to f (uv ω ). Because of the mismatch, either (uv n wz ω ) n∈N , (uv ω ) n∈N is a bad pair or (uv ω ) n∈N , (uv n w z ω ) n∈N is a bad pair (or both). Without loss of generality, let (uv n wz ω ) n∈N , (uv ω ) n∈N be a bad pair.
Let us consider an accepting run ρ of T over uv ω . Since the run is accepting, there is an accepting state q 1 visited infinitely often. Let l ∈ {1, . . . , |v|} be such that, the state reached after reading uv n v[1 : l] in the run ρ is q 1 for infinitely many ns. Let v = v[l + 1 : |v|]v[1 : l], let u = uv[1 : l] and let w = v[l + 1 : |v|], we have that (u v n w z ω ) n∈N , (u v ω ) n∈N is a bad pair. To simplify notations, we write this pair again as (uv n wz ω ) n∈N , (uv ω ) n∈N . We have gained that on the run over uv ω , the accepting state q 1 is reached infinitely often after reading v factors. Now let k, l be integers such that p 1 uv k − − → q 1 v l − → q 1 , with p 1 an initial state. We consider l different sequences, for r ∈ {0, . . . , l − 1} we define the sequence s r = uv ln+r wz ω n∈N . Since (uv n wz ω ) n∈N , (uv ω ) n∈N is a bad pair, there must be a value r such that (uv k )(v l ) n (v r w)z ω n∈N , (uv k )(v l ) ω n∈N is a bad pair. To simplify notations, again, we rename this pair (uv n wz ω ) n∈N , (uv ω ) n∈N , and we know that p 1 u − → q 1 v − → q 1 , with p 1 initial and q 1 accepting.
For any m larger than the number of states |Q| of T , let us consider the run of T over uv m wz ω . Let i m , j m , k m be such that we have the accepting run p m with i m +j m +k m = m and 0 < j m ≤ |Q|. And let r m = i m +k m mod j m . Let us consider for some m, the sequence (uv rm )(v jm ) n (wz) ω n∈N . By the presence of these loops, each of these sequences has a convergent image. There is actually a finite number of such sequences, since j m and r m take bounded values. Since the original pair is bad, this means that there must exist m such that the sequence f ((uv rm )(v jm ) n (wz) ω ) n∈N does not converge to f (uv ω ). Let u = uv im , v = v jm and w = v km w, then (u v n w z ω ) n∈N , (u v ω ) n∈N is a bad pair. Once again we rename the pair (uv n wz ω ) n∈N , (uv ω ) n∈N and now we have both p 1 u − → q 1 v − → q 1 and p 2 u − → q 2 v − → q 2 , such that p 1 , p 2 are initial, q 1 is accepting and wz ω has a final run from q 2 . Now we have established the shape of the pattern, we only have left to show the mismatch properties.
Let us first assume that v 2 = . Then lim n f (uv n wz ω ) = u 2 v ω 2 . Since the pair is bad, there exists k such that mismatch(u 1 v k 1 , u 2 v k 2 ). Hence, up to taking u = uv k , we have established the pattern: Let us now assume that v 2 = . Then lim n f (uv n wz ω ) = u 2 y 2 . Then there is a prefix w 2 of y 2 and an integer k such that mismatch(u 1 v k 1 , u 2 w 2 ). Hence, up to taking u = uv k , and w a sufficiently long prefix of wz ω we have established the pattern: which concludes the proof.
Theorem 5.2. Deciding if a one way Büchi transducer defines a continuous (resp. uniformly continuous) function can be done in NLogSpace.
Proof. Let T be a one way Büchi transducer defining a function f . From Lemma 5.1, if T is trim, non-continuity of f is equivalent to T satisfying the formula φ cont of Figure 2. This formula is expressed in the syntax of the pattern logic from [FMR18], where it is proved that model-checking pattern formulas against transducers can be done in NLogSpace [FMR18,Thm. 6]. This yields the result.
If T is not trim, then we modify the formula φ cont to additionally express that there must be some accepting run from r 2 on some input. Equivalently, we express that there exists a run from r 2 to some accepting state s, and a run looping in s, in the following way: we just add the quantifiers ∃π 3 : r 2 α|β − − → s ∃π 4 : s γ|τ − − → s to φ cont and the constraint acc(s) which requires s to be accepting.
The proof for non-uniform continuity, using formula φ u-cont is similar.

Regular case.
As for the rational case, we first define a pattern which is satisfied by a 2DFT pla if and only if it defines a non-continuous function. Then we show how to check for the existence of this pattern. It is however more intricate than in the rational setting. First, we get rid of the look-ahead by working on words annotated with look-ahead information.
5.2.1. Look-ahead removal and annotated words. Let f be realized by a 2DFT pla T over alphabet Σ with look-ahead automaton P . Let Q P be the states of P . We define T , a 2DBT over Σ × Q P which, informally, simulates T over words annotated with look-ahead states, and which accepts only words with a correct look-ahead annotation with respect to P . Formally, for an annotated word u ∈ (Σ × Q P ) ∞ , we denote by π Σ (u) ∈ Σ ∞ its projection on Σ. An annotated word x ∈ (Σ × Q P ) ω is well-labelled if π Q P (u) is the accepting run of P over u.
As P is prophetic, for all words u ∈ dom(f ), there exists a unique well-annotated word, denotedũ, which satisfies π Σ (ũ) = u. We now letf be the function defined, for all u ∈ dom(f ), byf (ũ) = f (u). The functionf is easily seen to be definable by a 2DBT which simulates T over the Σ-component of the input word and simulates P over the Q P -component of the input word to check that the annotation is correct.
Proposition 5.3. One can construct, in linear-time, a 2DBT denoted T which realises the functionf .

5.2.2.
Transition monoid of 2DBT. In our pattern, we will be using the notion of transition monoid of a 2DBT, as the transition monoid of its underlying two-way automaton (obtained by ignoring the output words on transitions).
Let T be a 2DBT, we define its transition monoid M T in the usual way (see e.g. [BGMP18] for details), but we also add information telling us if a word produces empty output or not.  The transition monoid of a two-way automaton is defined similarly, except that the information on whether there is a production of non-empty output or not is not required, i.e. it is a set of functions of type Q × {L, R} → Q × {L, R}.

Critical Pattern.
Let T be a 2DFT pla and T be its associated 2DBT running over annotated words (see Section 5.2.1). Let ρ = (q 0 , i 0 = 0) be an initial run of T over a finite word uvw. We say that the factor v is non-producing in ρ if all the transitions occurring within v output . Otherwise v is producing. Formally, if in all the transitions (q j , i j ) b i j /γ j −→ (q j+1 , i j+1 ) in run ρ such that |u| ≤ i j < |uv| and γ j = , then v is non-producing.
We define the notion of critical pattern for the 2DBT T . We say that T admits a critical pattern if there are words u, v ∈ Σ * , u 1 , v 1 , w 1 , z 1 , u 2 , v 2 , w 2 , z 2 ∈ (Σ × Q P ) * such that (1) π Σ (u 1 ) = π Σ (u 2 ) = u, π Σ (v 1 ) = π Σ (v 2 ) = v, (2) v 1 and v 2 are idempotent 4 with respect to the transition monoid of T , (3) there exist two accepting runs of T on u 1 v 1 w 1 z ω 1 and u 2 v 2 w 2 z ω 2 which can be respectively decomposed into ρ 1 λ 1 and ρ 2 λ 2 such that for all i = 1, 2, (4) ρ i is over u i v i w i and does not end in v i , (5) v i is not producing in ρ i , (6) there is a mismatch between out(ρ 1 ) and out(ρ 2 ).
We give the following characterisation of continuity and uniform continuity. Note that the patterns are similar to the one-way case.
Proposition 5.4. Let T be a 2DFT pla realising a function f . Then the following holds: (1) f is not uniformly continuous (resp. continuous).
Let us first assume that we have a critical pattern u 1 , u 2 , v 1 , v 2 , w 1 , z 1 , w 2 , z 2 , ρ 1 , λ 1 , ρ 2 , λ 2 . Our goal is to prove that (π Σ (u 1 v n 1 w 1 z ω 1 )) n , (π Σ (u 2 v n 2 w 2 z ω 2 )) n is a bad pair. We define ρ n 1 , ρ n 2 the runs obtained from ρ 1 , ρ 2 , just by iterating the respective v 1 , v 2 factors n times. Since v 1 , v 2 are idempotents, reading v i or v n i does not change the shape of the run ρ i , nor the order of the outputs occurring outside of v i . Moreover, since v i is non-producing in both runs, the outputs over v i and v n i are also the same. Hence we get out(ρ 1 ) = out(ρ n 1 ) and out(ρ 2 ) = out(ρ n 2 ). Thus the runs ρ n 1 λ n 1 and ρ n 2 λ n 2 produce outputs which mismatch at a position smaller than max(|ρ 1 |, |ρ 2 |) and the pair (π Σ (u 1 v n 1 w 1 z ω 1 )) n , (π Σ (u 2 v n 2 w 2 z ω 2 )) n is indeed bad.
Conversely, let us assume that (uv n x 1 y ω 1 ) n , (uv n x 2 y ω 2 ) n is a bad pair. Up to extracting subsequences, we can assume that v, y 1 , y 2 are idempotent both for T and its look-ahead automaton. Thus we can obtain, up to taking a larger word u, a synchronised bad pair of the form (π Σ (u 1 v n 1 w 1 z ω 1 )) n , (π Σ (u 2 v n 2 w 2 z ω 2 )) n with π Σ (u 1 ) = π Σ (u 2 ) = u and π Σ (v 1 ) = π Σ (v 2 ) = v. We also write π Σ (w i ) = x i and π Σ (z i ) = y i for i ∈ {1, 2}. Since the pair is bad there exists i such that for any m, there exists n ≥ m with |f (uv n x 1 y ω 1 ) ∧ f (uv n x 2 y ω 2 )| ≤ i. Let n be larger than 2i + 2 with |f (uv n x 1 y ω 1 ) ∧ f (uv n x 2 y ω 2 )| = j ≤ i. Let ρ 1 (resp. ρ 2 ) be the prefix of the run over u 1 v n 1 w 1 z ω 1 (resp. u 2 v n 2 w 2 z ω 2 ) which stops after producing the jth output. We make the following claim with respect to the sequence u 1 v i+1 1 v k 1 v i+1 1 w 1 z ω 1 : Claim 5.5. Any transition of ρ 1 occurring within the factor v k 1 must produce empty outputs and ρ 1 ends outside of this factor.
If we assume that the claim is true, then it is similarly true for ρ 2 . Then we obtain a critical pattern We only have left to show that the claim holds.
Proof of Claim 5.5. Let us assume towards a contradiction that a transition occurring within v k 1 in ρ 1 has non-empty output. Let ρ 1 the shortest prefix of the run λ over u 1 v i+1 1 v k 1 v i+1 1 w 1 z1 ω which extends ρ 1 and ends outside of the v k 1 factor. Note that if ρ 1 already ends outside of this factor, ρ 1 = ρ 1 . Let ρ be a factor of ρ 1 which contains such a producing transition and which starts and ends at a boundary of the v k 1 factor without leaving it. SinceT is deterministic and since v 1 is idempotent, all v 1 factors (except possibly for the first and last ones) must also produce such a non-empty output in λ. These outputs must occur in λ either in increasing or decreasing order with respect to the order of the input word. If they occur in increasing order, the first i + 1 v 1 factors produce non-empty outputs within ρ 1 , which contradicts the assumption that |out(ρ 1 )| ≤ i. Similarly if the outputs occur in decreasing order then the last i + 1 v 1 factors produce non-empty outputs within ρ 1 , which also yields a contradiction, hence we obtain that the claim must hold.

5.2.4.
Deciding uniform continuity and continuity for regular functions. We now show how to decide, in PSpace, whether a given 2DFT pla defines a uniform continuous function by checking whether its associated 2DBT over annoted words admits a critical pattern. Deciding continuity is based on the same ideas and shown in the last paragraph of this section. We reduce the problem to checking the emptiness of a non-deterministic two-way Parikh automaton [Iba14]. A two-way Parikh automaton (2PA) P of dimension d is a two-way automaton, running on finite words, extended with vectors of integers (including 0) of dimension d. Each dimension can be seen as a counter which can only be incremented. A run on a finite word is accepting if it reaches some accepting state and the (pairwise) sum of the vectors met along the transitions belong to some given semi-linear set represented as some existential Presburger formula 5 . The emptiness problem for 2PA is undecidable but decidable in PSpace for bounded-visit 2PA [FGM19]. A 2PA is bounded visit if there exists some k such that in any accepting run of P, any input position is visited at most k times by that run. The 2PA we construct will be of polynomial size and bounded-visit, entailing PSpace decidability of uniform continuity for 2DFT pla , following Proposition 5.3.
Lemma 5.6. Given a 2DFT pla T , one can construct in polynomial time a bounded-visit 2PA P T (of polynomial size) such that L(P T ) = ∅ if and only if T admits a critical pattern.
Before proving the lemma, let us state our main result. 5 We recall that existential Presburger formulas are existentially quantified first-order formulas over the predicate t1 ≤ t2 where ti are terms over the constants 0, 1 and the addition +. Theorem 5.7. Deciding whether a regular function given as a deterministic two-way transducer with prophetic Büchi look-ahead is uniformly continuous is PSpace-Complete.
Hardness also holds for continuity.
Proof. The upper-bound is a direct consequence of Proposition 5.3, Lemma 5.6, and the PSpace upper-bound of [FGM19] for the non-emptiness of bounded-visit two-way Parikh automata.
The lower-bound is easily obtained by reducing the problem of checking the non-emptiness of the language of a deterministic two-way automaton over finite words, which is known to be PSpace-hard 6 . Given a deterministic two-way automaton A on finite words over some alphabet Σ containing at least two letters a and b, we construct a 2DFT pla T defining the following function f . It is defined on all ω-words u in (Σ ∪ {#}) ω by f (u) = a ω if u = v#w for some v ∈ L(A) and w contains infinitely many a, otherwise by f (u) = b ω . Clearly, if L(A) is empty, then f is the constant function mapping any word to b ω and is therefore uniformly continuous (and continuous). Conversely, if there exists some v ∈ L(A), then we claim that f is not continuous (and hence not uniformly continuous). Indeed, consider the family of words u n = v#a n # ω for all n ≥ 0 and some a ∈ Σ. Clearly, f (u n ) = b ω for all n as u n contains finitely many a. However f (lim n→∞ u n ) = f (v#a ω ) = a ω , which is different from lim n→∞ f (u n ) = b ω . Finally, it remains to show how to construct T from A. The idea is to use a look-ahead to check whether the input is of the form v#w where v ∈ Σ * and w contains infinitely many a. If that is the case, then T simulates A on v (using # as an endmarker). At the end of this simulation, if A reaches an accepting state, then T reads w and keeps on producing a. On the other hand, if A reaches a non-accepting state, then T keeps on producing b on the w part. If the look-ahead has failed (meaning that the input is not of the above form), then T keeps on producing b while reading its input in a one-way fashion.
We now proceed to the proof of Lemma 5.6.
Encoding of the set of critical patterns as a language. We show how to encode the set of critical patterns as the language of a 2PA. To that end, let us see how a critical pattern can be encoded as a word. The 2PA will have to check properties (1) − (6) of the definition of a critical pattern. The first condition is about projections. To check that u 1 , u 2 project on the same Σ-word, as well as v 1 , v 2 , we just encode them as words over the alphabet Σ × Q P × Q P . Let us make this more formal. Let # be a fresh symbol. For any two alphabets A, B and any two words w 1 ∈ A * and w 2 ∈ B * of same length, we let w 1 ⊗ w 2 ∈ (A × B) * be their convolution, defined by (w 1 ⊗ w 2 )[i] = (w 1 [i], w 2 [i]) for any position i of w 1 .
We now define a language Crit T ⊆ then u 1 , v 1 , w 1 , z 1 , u 2 , v 2 , w 2 , z 2 is a critical pattern.
The following proposition is immediate Note that this encoding makes sure condition (1) of the definition of critical pattern is ensured, but the other properties will have to be checked by the 2PA. Checking idempotency with a succinct two-way automaton. The 2PA has to check condition (2) of the critical patterns, i.e. idempotency with respect the transition monoid of the 2DBT T . We show more generally, given a deterministic two-way automaton A, how a two-way automaton of polynomial size can recognise idempotent words with respect to the transition monoid of A. The proof of this result is not needed to understand the proof of the main lemma (Lemma 5.11), namely that the set Crit T is recognisable by a 2PA, and can be skipped in a first reading.
Lemma 5.9. For any deterministic two-way automaton A (resp. deterministic two-way Büchi transducer T ), one can construct in polynomial time a (bounded-visit) deterministic two-way automaton I A which recognises the set of words #u# such that u is idempotent with respect to A, and # is a fresh symbol.
Proof. We prove the result for automata. Its adaptation to transducers is trivial, as the transition monoid of a transducer is the same as the transition monoid of its underlying automaton obtained by ignoring the outputs, without the information on whether some non-empty output is produced or not by a traversal. The following construction, done for automata, can be trivially adapted to account for this information.
Let Q be the set of states of A. Without loss of generality, we can assume that Q = {1, . . . , n}. Let (i, j) ∈ Q 2 . We explain how a two-way automaton A LR i,j can check whether (i, j) is is left-to-right traversal of u: it needs to start from the left of u in state i, and simulates A until it reaches a boundary of u: if it is the left boundary, it rejects, if it the right boundary, it accepts. Now, let us explain how a two-way automaton B L,R i,j can check whether (i, j) is a left-to-right traversal of A over uu, by reading only #u#. Intuitively, the main idea is to simulate A and when A wants to go to the right of u following some transition t, then B L,R i,j comes back to the left of u and applies t and proceeds with its simulation of A. More precisely, B L,R i,j has two modes: M 1 and M 2 . It stays in mode M 1 as long as A does not cross the right boundary of u or crosses the left boundary (in which case it stops its computation in a non-accepting state). As soon as it crosses the right boundary, using some transition t, B L,R i,j moves to mode M 2 , comes back to the left of u, and applies t. It then simulates A until it reaches the right boundary in state j in which case it stops its computation and accepts, or it reaches the left boundary in which case it stops its computation and rejects.
Note that in the above constructions, A LR i,j and B LR i,j are both deterministic, since A is deterministic. Therefore, they have bounded crossing. Moreover, they have a polynomial number of states. We construct in a similar way automata for each type of traversals (LR, RL, LL, RR) and each pair (i, j).
Then, clearly, u is idempotent if and only if the following holds Since the automata are deterministic, they can be complemented in polynomial time. Moreover, intersection of two-way automata can be done in linear time by serial composition: the first automaton is simulated and if it eventually accepts, then the other automaton is simulated and must accept as well. Using these results, one can construct in polynomial time a deterministic two-way automaton implementing the conjunction above, concluding the proof. Checking acceptance of lasso words by a succinct two-way automaton over finite words. We prove a useful technical lemma, which intuitively says that it is possible to construct a two-way automaton of polynomial size accepting words of the form u#v such that uv ω is accepted by a given Büchi two-way automaton A and v is idempotent with respect to the transition monoid of A. The statement of the lemma is slightly more general. The proof of this lemma is not needed to understand the proof of the main lemma, namely that the set Crit T is recognisable by a 2PA, and can be skipped in a first reading. A marked word over an alphabet Σ is an ω-word over Σ × {0, 1} which contains exactly one occurrence of 1. Given i ≥ 1 and x ∈ Σ ω , we denote by x i the marked word such that for all j ≥ 1, Lemma 5.10. Let A be a non-deterministic (bounded-visit) two-way automaton over an alphabet Σ, # ∈ Σ and q be a state of A. Let L q be the language of words ( u#v ) i such that u, v ∈ Σ * , 2 ≤ i ≤ |u| + 1, v is idempotent with respect to the transition monoid of A, and there exists an accepting run of A on uv ω starting in configuration (q, i). Then, L q is recognisable by a non-deterministic bounded-visit two-way automaton of polynomial size (in A).
Proof. We define a two-way automaton P recognising L q . The symbol # is needed to identify the left boundary of v. First, P checks that the input is valid, i.e. it is of the form ( u#v ) i such that 2 ≤ i ≤ |u| + 1 and v is idempotent with respect to the transition monoid of A. To check idempotency, we rely on the construction of Lemma 5.9.
If the validity checking succeeds, P comes back to the initial position of its input and check the existence of an accepting run as required by the statement of the lemma. Since this accepting run is on uv ω and P can only read one occurrence of v, we first give a characterisation of such an accepting run which will turn useful to check its existence while accessing only one iteration of v. This characterisation intuitively says that there is an accepting loop on some finite iteration v κ accessible from the marked position i in state q. More precisely, it can be seen that any accepting run r of A on uv ω starting in configuration (q, i) can be decomposed as: r = ρ 0 L 1 R 1 . . . L n R n ρ 1 ω where: (1) n is smaller than the number of states of A (2) ρ 0 is a run on u from configuration (q, i) to some configuration (q 1 , |u| + 1) (3) for all 1 ≤ j ≤ n, L j is a left-to-left traversal on v ω starting in some configuration (q j , |u| + 1) and ending in some configuration (p j , |u|) (4) for all 1 ≤ j ≤ n, R j is a right-to-right traversal on u starting in configuration (p j , |u|) and ending in some configuration (q j , |u| + 1) (5) ρ 1 is a finite run visiting only positions of v ω from configuration (q n , |u| + 1) to some configuration (p, j 1 ) such that j 1 = |u| + |v|.m + 1 for some m (i.e. j 1 is the initial position of some iteration of v) (6) is a finite run visiting only positions of v ω from configuration (p, j 1 ) to some configuration (p, j 2 ) such that j 2 = j 1 + |v|m for some m ≥ 1 (i.e. j 2 is the initial position of some iteration of v, and is at the right of j 1 ) In the above characterisation, note that L j , R j are either LL-or RR-traversal starting at the right boundary of u. Since r is accepting, it visits the whole infinite input uv ω and therefore there cannot be more such traversals than the number of states. Otherwise, this boundary would be visited twice in the same state by A, and therefore, it would be visited infinitely many times, contradicting that the whole input is read. This justifies why we can take n smaller than the number of states. This characterisation is not directly exploitable by P . We make the following observation: since v is idempotent, L j is a left-to-left traversal on vv for all 1 ≤ j ≤ n. Indeed, suppose that is not the case, it means that L j visits all positions of v 2 σ at least once, where σ is the first symbol of v. Let s 1 be the state of L j the first time it reaches the end of v, and s 2 be the state of L j the first time it reaches the end of vv. In other words, there is a left-to-right traversal from q j to s 1 on v and a left-to-right traversal from q j to s 2 on vv. Since v is idempotent, we get that s 1 = s 2 . This contradicts that L j is a left-to-right traversal, since A then loops on s 1 = s 2 and moves forever to the right when initially starting to read v ω on state q j . This means that to check the existence of a left-to-left traversal on v ω , one only needs to consider two iterations of v.
We now proceed to the construction of P . The automaton P guesses a decomposition as in the above characterisation by simulating A. The main difficulty is that it reads only one occurrence of v while A must be simulated on uv ω . Let us first explain how the decomposition can be guessed. First, P accesses the marked position i and start simulating A from state q (ignoring the marking in {0, 1} since A is over alphabet Σ). If eventually A reaches the right boundary of u in some state q 1 , P guesses some state p 1 and checks whether there exists a left-to-left traversal L 1 of A, from q 1 to some p 1 , on v ω (we explain later how this verification can be done by P ). If it is the case, P again simulates A on u and if eventually A reaches the right boundary of u in some state q 2 , once again, P checks whether there exists a left-to-left traversal of v ω from q 2 to some p 2 , and so on for at most n times. Non-deterministically, when P reaches the right boundary of u, it can decide to check for the existence of an accessible accepting loop in v ω , i.e. runs ρ 1 and as in the above characterisation (we also explain later how this verification can be done by P ). If such a loop is found, P accepts.
Let us now explain how the two verifications involved in the latter simulation can be done by P , namely: checking the existence of a left-to-left traversal on v ω from some state, say s, and checking the existence of an accessible accepting loop. The main difficulty is that P has access to only one occurrence of v, but it can use two-wayness to overcome this problem. If A needs to cross the right boundary of v from the left (i.e. access the next iteration of v), P just rewinds its reading head to the first position of v, and if A needs to cross the left boundary of v from the right (i.e. access the previous iteration of v), then P moves its reading head to the last position of v. We call this simulation a simulation modulo. We use this idea of simulation modulo to check the existence of LL-traversals as well as ρ 1 and .
For LL-traversals, as explained before, one only needs to check the existence of an LL-traversal on vv. P therefore performs a simulation of A modulo and uses a bit of information to check whether it is in the first or second occurrence of v.
To check the existence of ρ 1 , we can use similar arguments as before, based on the fact that v is idempotent, to prove that ρ 1 only visits the two first iterations of v. This is due to the fact that ρ 1 can be decomposed into a sequence of traversals on some powers of v but each of those traversal is a traversal on v by idempotency. For example, ρ 1 might be an LR-traversal on v κ 1 followed by a LL-traversal on v κ 2 , followed by a RR-traversal on v κ 3 , up to reaching configuration (p, j 1 ). However by idempotency, each of these traversals are actually traversals on v, so, κ j = 1 for all j. Hence, only two iterations of v are needed (two and not one, because, for instance, an LR-traversal on v can be followed by a LL-traversal on v, and hence two iterations are needed). Since two iterations of v are needed, P can check the existence of ρ 1 using some simulation modulo and one bit of information. Finally, it remains for P to check for the existence of a loop visiting an accepting state. Using idempotency of v and similar arguments as before, it can be shown that such a loop can be found only on three iterations of v, i.e. on v 3 . So, once again, P can perform a simulation modulo, and use two bits of information to check whether it is on the first, second or third copy of v.
Note that since A is bounded-visit, and since P only performs simulations of A on up to three iterations of v, it is bounded visit as well.
Construction of the 2PA. We now have all the ingredients to construct a 2PA whose language is non-empty if and only if T admits a critical pattern. More precisely, we show the following: Lemma 5.11. The language Crit T is recognisable by a 2PA C of polynomial size (in T ).
Proof. We do not give a formal construction of C, which would be unnecessarily too technical. Instead, we explain how C can check the six conditions (1) − (6) of the definition of a critical pattern when reading valid encodings. The dimension of C is 2 (i.e. its vectors are in N 2 or equivalently, it has two incrementing counters). We say that the counters are unchanged by a transition if the vector on that transition is (0, 0). First C checks, by doing a left-to-right pass on the whole input w, whether w is a valid encoding, i.e. whether w ∈ ((Σ × Q 2 P ) * #) 2 ((Σ × Q P ) * #) 4 . If this is the case, then C comes back to the beginning of u and proceed by checking other properties, otherwise it rejects. Note that this first verification only needs a constant number of states. During this phase, counters are unchanged.
Let us now assume that C has validated the type of its input w, which is then of the form w = (u ⊗ a 1 ⊗ a 2 )#(v ⊗ b 1 ⊗ b 2 )#w 1 #z 1 #w 2 #z 2 # . Let u i = u ⊗ a i and v i = v ⊗ v i . Note that C can navigate between each #-free factors of w by just keeping in its state whether it is in the first, second, up to sixth factor. This information can be updated when the separator # is met and is polynomial. The second observation is that condition (1) (u 1 and u 2 projects on the same Σ-word, as well as v 1 and v 2 ) is necessarily satisfied by definition of the encoding.
Let us explain how C checks condition (2) about idempotency of v 1 and v 2 . We rely on the construction of Lemma 5.9 applied to the 2DBT T where outputs are ignored (therefore, it is a deterministic two-way automaton). If this second phase accepts, C proceeds to checking conditions (3) − (6). Otherwise it rejects. Again, during this verification, counters are unchanged.
We now turn to conditions (3) − (6). The 2PA C first constructs a finite run ρ 1 on u 1 v 1 w 1 which does not end in v 1 . Since ρ 1 is existentially quantified in the definition of critical patterns, this is where non-determinism of C is needed. To do so, C simulates T on u 1 v 1 w 1 . More precisely, it reads (u ⊗ a 1 ⊗ a 2 )#(v ⊗ b 1 ⊗ b 2 )#w 1 # but ignores the third components a 2 and b 2 as well as the # symbols. During this simulation, outputs of T are also ignored. If T wants to cross the left boundary of w 1 , then C rejects, otherwise condition (4) is not satisfied. If T is in v 1 but produces a non-empty output, then C rejects as well, ensuring condition (5). Non-deterministically, C decides to stop the simulation, but only if T is not in v 1 (otherwise, this would violate condition (4)). If it does not stop the simulation, then C will never accept its input. Stopping the simulation means that C has constructed a run ρ 1 which satisfies conditions (4) and (5) (for i = 1). We call this simulation phase S 1 .
To construct a run ρ 2 on u 2 v 2 w 2 , C proceeds similarly as in S 1 . We call this simulation S 2 . Note that both simulation requires only a polynomial number of states. It remains to explain (i) how to check condition (6) and (ii) how to check condition (3), i.e. whether ρ i can be extended into accepting runs over u i v i w i z ω i , for i = 1, 2. The two counters are used to check condition (6), i.e. to check the existence of a mismatch between the outputs of ρ 1 and ρ 2 . To do so, the simulation S i , i = 1, 2, is again divided into two modes: in the first mode, whenever T produces some output word α, the ith counter of C is incremented by |α|, using the vector (|α|, 0) for i = 1, and (0, |α|) for i = 2. So, the ith counter counts the length of the outputs produced so far by T on u i v i w i . Non-deterministically, it eventually decides to stop counting this length, and increments the counter c i one last time by some 0 ≤ ≤ |α|. It then keeps in memory the c i th letter produced by T , say, τ i ∈ Γ. After this non-deterministic guess, which corresponds to existentially quantify an output position, the ith counter is left unchanged during the whole computation of C. The automaton C will accept only if c 1 = c 2 and d 1 = d 2 , ensuring the existence of a mismatch between out(ρ 1 ) and out(ρ 2 ). Again, this needs only a polynomial number of states: simulation S i is divided into two modes (before and after the non-deterministic guess), so, C only needs to remember in which mode it is.
To conclude, it remains to show how condition (3) can be checked, i.e. how C can check that ρ i can be extended into an accepting run over u i v i w i z ω i . This is a direct application of Lemma 5.10.
Finally, Lemma 5.6 is a direct consequence of Lemma 5.11 and Proposition 5.8.
Deciding continuity for regular functions. We prove the following theorem: Theorem 5.12. Deciding whether a regular function given as a deterministic two-way transducer with prophetic Büchi look-ahead is continuous is PSpace-c.
We have established that f is continuous if and only if T admits a strong critical pattern. As shown in Lemma 5.11, the set of (encodings of) critical patterns is recognisable by a bounded-visit 2PA of polynomial size. We need here to slightly modify the 2PA constructed in Lemma 5.11 so that it also checks whether π 1,3 (u 1 (v 1 ) ω ) is in the domain of T . Based on Lemma 5.10, we can construct a bounded-visit two-way automaton of polynomial size checking the latter property. When this automaton has successfully checked the latter property, it is then sequentially composed with a 2PA as in Lemma 5.11 checking whether the input (where the third components of the alphabets are ignored) forms a critical pattern. The resulting composition is a bounded-visit 2PA of polynomial size, whose emptiness can be checked in PSpace, as shown in [FGM19].

Conclusion
In this paper, we have studied two notions of computability for rational and regular functions, shown their correspondences to continuity notions which we proved to be decidable in NLogSpace and PSpace respectively. The notion of uniform computability asks for the existence of a modulus of continuity, which tells how far one has to go in the input to produce a certain amount of output. It would be interesting to give a tight upper bound on modulus of continuity for regular functions, and we conjecture that it is always a linear (affine) function in that case.
Another interesting direction is to find a transducer model which captures exactly the computable, and uniformly computable, rational and regular functions. For rational functions, the deterministic (one-way) transducers are not sufficient, already for uniform computability, as witnessed by the rational function which maps any word of the form a n b ω to itself, and any word a n c ω to a 2n c ω . For regular functions, we conjecture that 2DFT characterise the computable ones, but we have not been able to show it yet.
Finally, much of our work deals with reg-preserving functions in general. An interesting line of research would be to investigate continuity and uniform continuity for different classes of functions which have this property. One natural candidate is the class of polyregular functions introduced in [Boj18] which enjoy several different characterisations and many nice properties, including being effectively reg-preserving. This means that continuity and computability also coincide, however deciding continuity seems challenging.