The Power of Programs over Monoids in DA

The program-over-monoid model of computation originates with Barrington’s proof that it captures the complexity class NC 1 . Here we make progress in understanding the subtleties of the model. First, we identify a new tameness condition on a class of monoids that entails a natural characterization of the regular languages recognizable by programs over monoids from the class. Second, we prove that the class known as DA satisﬁes tameness and hence that the regular languages recognized by programs over monoids in DA are precisely those recognizable in the classical sense by morphisms from QDA . Third, we show by contrast that the well studied class of monoids called J is not tame and we exhibit a regular language, recognized by a program over a monoid from J , yet not recognizable classically by morphisms from the class QJ . Finally, we exhibit a program-length-based hierarchy within the class of languages recognized by programs over monoids from DA .


Introduction
A program of range n on alphabet Σ over a finite monoid M is a sequence of pairs (i, f ) where i is a number between 1 and n and f is a function assigning an element of the monoid M to any letter of Σ. This program assigns to each word w 1 w 2 · · · w n the monoid element obtained by multiplying out in M the elements f (w i ), one per pair (i, f ), in the order of the sequence. When associated with a subset F of M as an acceptance set, a program naturally defines the language L n of words of length n to which it assigns a monoid element in F . A program sequence (P n ) n∈N then defines the language formed by the union of the L n . Such sequences became the focus of attention when Barrington [3] made the striking discovery, in fact partly observed earlier [17], that polynomial length program sequences over the group S 5 and sequences of Boolean circuits of polynomial size, logarithmic depth and constant fan-in (defining the complexity class NC 1 ) recognize precisely the same languages.
A flurry of work followed. After all, a program over M is a mere generalization of a morphism from Σ * to M and recognition by a morphism equates with acceptance by a finite automaton. Given the extensive algebraic automata theory available at the time [15,11,22], 2:2 The Power of Programs over Monoids in DA it was to be a matter of a few years before the structure of NC 1 got elucidated by algebraic means.
The "optimism period" produced many significant results. The classes AC 0 ⊂ ACC 0 ⊆ NC 1 were characterized by polynomial length programs over the aperiodic, the solvable, and all monoids respectively [3,6]. More generally for any variety V of monoids (a variety being the undisputed best fit with the informal notion of a natural class of monoids) one can define the class P (V) of languages recognized by polynomial length programs over a monoid drawn from V. In particular, if A is the variety of aperiodic monoids, then P (A) characterizes the complexity class AC 0 [6].
But sadly, the optimism period ended: although partial results in restricted settings were obtained, the holy grail of reproving significant circuit complexity results and forging ahead by recycling the deep theorems afforded by algebraic automata theory never materialized. The test case for the approach was to try to prove, independently from the known combinatorial arguments [1,12,14] and those based on approximating circuits by polynomials over some finite field [24,27], that P (A) does not contain the parity language MOD 2 , i.e., that MOD 2 / ∈ AC 0 . But why has this failed? The answer of course is that programs are much more complicated than morphisms: programs can read an input position more than once, in non-left-to-right order, possibly assigning a different monoid element each time. Linear-length programs can indeed trivially recognize non-regular languages. In the classical theory, any two varieties provably recognize distinct classes of languages [11,22]. In the theory of recognition by polynomial length programs (we will speak then of p-recognition), distinct varieties can yield the same class, as do, for instance, any two varieties of monoids V and W that each contain a simple non-Abelian group, for which P (V) = P (W) = NC 1 [18, Theorem 4.1].
To further illustrate the subtle behavior of programs, consider the variety of monoids known as J. J is the variety of monoids generated by the syntactic monoids of the languages such that membership can be decided by looking for the presence or absence of certain subwords, where u is a subword of v if u can be obtained from v by removing some letters of v [26]. It follows that J is unable to recognize the language defined by the regular expression (a + b) * ac + . Yet (a + b) * ac + is p-recognizable over J. To see this consider the language L of all words having ca as a subword but not the subwords cca, caa and cb. L is therefore recognized by a morphism ϕ to some monoid M of J, i.e. L = ϕ −1 (F ) for some F ⊆ M . A program of range n over M can recognize the words of length n of (a + b) * ac + by using the following trick: reading the input letters in the order 2, 1, 3, 2, 4, 3, 5, 4, . . . , n, n−1, assigning to each letter read its image in M by ϕ and using the same acceptance set F as for L. For instance, on input abacc the program outputs ϕ(baabcacc) which is in F , while on inputs abbcc and abacca the program outputs respectively ϕ(babbcbcc) and ϕ(baabcaccac) which are not in F . Our paper is motivated by the need to better understand such subtle behaviors of polynomial length programs over monoids. Quite a bit of knowledge on such programs has accumulated over nearly thirty years (consider [5, 20, 21, 16, 28] beyond the references already mentioned). Yet, even within the realm of questions that do not hold pretense to major complexity class separations, gaps remain.
One beaming such gap concerns the variety of monoids DA. The importance of DA in algebraic automata theory and its connections with other fields are well established (see [30] for an eloquent testimony). DA is a relatively "small" variety, well within the variety of aperiodic monoids. One could argue that "small" varieties will be sensitive to duplications and rearrangements in the order in which input letters are read by a program. Presumably in part for that reason, programs over DA have seemingly not been successfully analyzed prior to our work.
Our main result is a characterization of the regular languages recognized by polynomial length programs over DA. We show that P (DA) ∩ Reg is precisely the class L (QDA) of languages recognized classically by morphisms in quasi-DA (QDA). A surjective morphism ϕ from Σ * to a finite monoid M is quasi-DA if, though M might not be in DA, there is a number k such that the image by ϕ of all words over Σ whose length is a multiple of k forms a submonoid of M which is in DA. In this particular case, this statement is equivalent to the fact that the only power added by p-recognition relative to classical recognition through monoids in DA is the ability to count input positions modulo a constant. Our proof shows, independently from [1, 12, 14, 24, 27], that, for regular languages, p-recognition over DA does not distort the algebraic properties of the underlying morphisms beyond adding the ability for fixed modulo counting on lengths. (This is precisely the statement, once extended to the variety of all aperiodic monoids, that would yield the elusive semigroup-theoretic proof that MOD 2 / ∈ AC 0 .) Our main result builds upon a statement of independent interest, namely, that any variety of monoids V that fulfills an appropriate tameness condition satisfies P (V)∩Reg ⊆ L (QV). The new tameness condition (see Definition 2) differs subtly but fundamentally from a similar notion developed for semigroups by Péladeau, Straubing and Thérien [21] and also studied in the case of monoids by Péladeau [20] and later Tesson [28] in their respective Ph.D. theses, and thus requires a separate treatment here. Proving that DA indeed satisfies our tameness condition is the main technical difficulty behind our characterization of P (DA) ∩ Reg.
We further consider P (DA). With C k the class of languages recognized by programs of length O(n k ) over DA, we prove that C 1 ⊂ C 2 ⊂ · · · ⊂ C k ⊂ · · · ⊂ P (DA) forms a strict hierarchy. We also relate this hierarchy to another algebraic characterization of DA and exhibit conditions on M ∈ DA under which any program over M can be rewritten as an equivalent subprogram (made of a subsequence of the original sequence of instructions) of length O(n k ), refining a result by Tesson and Thérien [29].
Our final result concerns the variety J. Observing that the regular language (a + b) * ac + mentioned above is not recognizable by a morphism in QJ, we conclude that J is not a tame variety. Be it the chicken or the egg, this lack of tameness "explains" the unexpected power of P (J) witnessed in our example above. Furthermore, since J is a p-variety of monoids in the sense of [21, 20, 28], J explicitly shows that our notion of tameness and that of [21,20,28] differ.
Organization of the paper. In Section 2 we define programs over varieties of monoids, p-recognition by such programs and the necessary algebraic background. The definition of tameness for a variety V is given in Section 3 with our first result showing that regular languages recognized by P (V) are included in L (QV) when V is tame; we also quickly discuss the case of J, which isn't tame. We show that DA is tame in Section 4. Finally, Section 5 contains the hierarchy results about P (DA).

Preliminaries 2:4
The Power of Programs over Monoids in DA Words and languages. Let Σ be a finite alphabet. We denote by Σ * the set of all finite words over Σ. We also denote by Σ + the set of all finite non empty words over Σ, the empty word being denoted by ε. A language over Σ is a subset of Σ * . A language is regular if it can be defined using a regular expression. Given a language L, its syntactic congruence ∼ L is the relation on Σ * relating two words u and v whenever for all x, y ∈ Σ * , xuy ∈ L if and only if xvy ∈ L. It is easy to check that ∼ L is an equivalence relation and a congruence for concatenation. The syntactic morphism of L is the mapping sending any word u to its equivalence class in the syntactic congruence.
The quotient of a language L over Σ relative to the words u and v is the language, denoted by u −1 Lv −1 , of the words w such that uwv ∈ L.

Monoids, semigroups and varieties.
A semigroup is a set equipped with an associative law that we will write multiplicatively. A monoid is a semigroup with an identity. An example of a semigroup is Σ + , the free semigroup over Σ. Similarly Σ * is the free monoid over Σ. A morphism ϕ from a semigroup S to a semigroup T is a function from S to T such that ϕ(xy) = ϕ(x)ϕ(y) for all x, y ∈ S. A morphism of monoids additionally requires that the identity is preserved. A semigroup T is a subsemigroup of a semigroup S if T is a subset of S and is equipped with the restricted law of S. Additionally the notion of submonoids requires the presence of the identity. The Cartesian (or direct) product of two semigroups is simply the semigroup given by the Cartesian product of the two underlying sets equipped with the Cartesian product of their laws.
A language L over Σ is recognized by a monoid M if there is a morphism h from Σ * to M and a subset F of M such that L = h −1 (F ). We also say that the morphism h recognizes L. It is well known that a language is regular if and only if it is recognized by a finite monoid. Actually, as ∼ L is a congruence, the quotient Σ * / ∼ L is a monoid, called the syntactic monoid of L, that recognizes L via the syntactic morphism of L. The syntactic monoid of L is finite if and only if L is regular. The quotient Σ + /∼ L is analogously called the syntactic semigroup of L.
A variety of monoids is a class of finite monoids closed under submonoids, Cartesian product and morphic images. A variety of semigroups is defined similarly. When dealing with varieties, we consider only finite monoids and semigroups.
An element s of a semigroup is idempotent if ss = s. For any finite semigroup S there is a positive number (the minimum such number), the idempotent number of S, often denoted ω, such that for any element s ∈ S, s ω is idempotent.
A variety can be defined by means of identities [25]. The variety is then the class of monoids such that each of them has all its elements satisfy the identities. For instance, the variety of aperiodic monoids A can be defined as the class of monoids satisfying the identity x ω = x ω+1 , where x ranges over the elements of the monoid while ω is the idempotent power of the monoid. The variety of monoids DA is defined by the identity (xy) ω = (xy) ω x(xy) ω . The variety of monoids J is defined by the identity (xy) ω = (xy) ω x = y(xy) ω .
Quasi and locally V languages, modular counting and predecessor. If S is a semigroup we denote by S 1 the monoid S if S is already a monoid and S ∪ {1} otherwise.
The following definitions are taken from [23]. Let ϕ be a surjective morphism from Σ * to a finite monoid M . For all k consider the subset ϕ(Σ k ) of M . As M is finite there is a k such that ϕ(Σ 2k ) = ϕ(Σ k ). This implies that ϕ(Σ k ) is a semigroup. The semigroup given by the smallest such k is called the stable semigroup of ϕ. If S is the stable semigroup of ϕ, S 1 is called the stable monoid of ϕ. If V is a variety of monoids, then we shall denote by QV the class of such surjective morphisms whose stable monoid is in V and by L (QV) the class of languages whose syntactic morphism is in QV.
For V a variety of monoids, we say that a finite semigroup S is locally V if, for every idempotent e of S, the monoid eSe belongs to V; we denote by LV the class of locally-V finite semigroups, which happens to be a variety of semigroups. Finally, L (LV) denotes the class of languages whose syntactic semigroup is in LV.
We now define languages recognized by V * Mod and V * D. We do not use the standard algebraic definition using the wreath product as we won't need it, but directly a characterization of the languages recognized by such algebraic objects [7, 31].
Let V be a variety of monoids. We say that a language L over Σ is in L (V * Mod) if there is a number k ∈ N >0 and a language L over Σ × {0, · · · , k − 1} whose syntactic monoid is in V, such that L is the set of words w that belong to L after adding to each letter of w its position modulo k.
Similarly we say that a language L over Σ is in L (V * D) if there is a number k ∈ N and a language L over Σ × Σ ≤k (where Σ ≤k denotes all words over Σ of length at most k) whose syntactic monoid is in V, such that L is the set of words w that belong to L after adding to each letter of w the word composed of the k (or less when near the beginning of w) letters preceding that letter. The variety of semigroups V * D can then be defined as the one generated by the syntactic semigroups of the languages in L (V * D) as defined above.
A variety V is said to be local if L (V * D) = L (LV). This is not the usual definition of locality, defined using categories, but it is equivalent to it [31, Theorem 17.3]. One of the consequences of locality that we will use is that L (V * Mod) = L (QV) [9, Corollary 18] (see also [8,19]).

Programs over varieties of monoids.
Programs over monoids form a non-uniform model of computation, first defined by Barrington and Thérien [6], extending Barrington's permutation branching program model [3]. Let M be a finite monoid and Σ a finite alphabet. A program P over M is a finite sequence of instructions of the form (i, f ) where i is a positive integer and f a function from Σ to M . The length of P is the number of its instructions. A program has range n if all its instructions use a number less than n. A program P of range n defines a function from Σ n , the words of length n, to M as follows. On input w ∈ Σ n , each instruction (i, f ) outputs the monoid element f (w i ). A sequence of instructions then yields a sequence of elements of M and their product is the output P (w) of the program.
A language L over Σ is p-recognized by a sequence of programs (P n ) n∈N if for each n, P n has range n and length polynomial in n and there exists a subset F n of M such that L ∩ Σ n is precisely the set of words w of length n such that P n (w) ∈ F n .
We denote by P (M ) the class of languages p-recognized by a sequence of programs (P n ) n∈N over M . If V is a variety of monoids we denote by P (V) the union of all P (M ) for M ∈ V.
The following is a simple fact about P (V). Let Σ and Γ be two finite alphabets and µ : Σ * → Γ * be a morphism. We say that µ is length multiplying, or that µ is an lmmorphism, if there is a constant k such that for all a ∈ Σ, the length of µ(a) is k.

General results about regular languages and programs
Let V be a variety of monoids. By definition any regular language recognized by a monoid in V is p-recognized by a sequence of programs over a monoid in V. Actually, since in a program over some monoid in V, the monoid element output for each instruction can depend on the position of the letter read, hence in particular on its position modulo some fixed number, it is easy to see that any regular language in L (V * Mod) is p-recognized by a sequence of programs over some monoid in V. In this section we show that for some "well behaved" varieties V the converse inclusion holds. For this we introduce the notion of an sp-variety of monoids. This notion is inspired by the notion of p-varieties (program-varieties) of monoids, that seems to have been originally defined by Péladeau in his Ph.D. thesis [20] and later used by Tesson in his own Ph.D. thesis [28]. The notion of a p-variety has also been defined for semigroups by Péladeau, Straubing and Thérien in [21] in order to obtain results similar to ours for varieties of semigroups of the form V * D.
Let µ be a morphism from Σ * to a finite monoid M . We denote by W(µ) the set of languages L over Σ such that L = µ −1 (F ) for some subset F of M . Given a semigroup S there is a unique morphism η S : S * → S 1 extending the identity on S, called the evaluation morphism of S. We write W(S) for W(η S ). We define W(M ) similarly for any monoid M . It is easy to see that if M ∈ V then W(M ) ⊆ P (V). The tameness condition requires a converse of this observation.

Definition 2.
An sp-variety of monoids, which we will call a tame variety, is a variety V of monoids such that for any finite semigroup S, if W(S) ⊆ P (V) then S 1 ∈ V.
The p-variety of monoids in [20, 28] is similar to our sp-variety but the former only requires that any finite monoid M verifying W(M ) ⊆ P (V) must in fact belong to V. This implies that any sp-variety of monoids is also a p-variety of monoids, but the converse is not always true. For instance, J is a p-variety of monoids [28], but Proposition 5 below states that J is not an sp-variety.
An example of an sp-variety of monoids is the class of aperiodic monoids A. This is a consequence of the result that for any number k > 1, checking if the number of a modulo k in a word is congruent to 0 is not in AC 0 = P (A) [12, 1] (a language we shall denote by MOD k over the alphabet {0, 1}). Towards a contradiction, assume there would exist a semigroup S such that S 1 is not aperiodic but still W(S) ⊆ P (A). Then there is an x in S such that x ω = x ω+1 . Consider the morphism µ : {a, b} * → S 1 sending a to x ω+1 and b to x ω , and the language L = µ −1 (x ω ). It is easy to see that L is the language of all words with a number of a congruent to 0 modulo k, where k is the smallest number such that is p-recognized by a sequence of programs (P n ) n∈N over an aperiodic monoid. For each n ∈ N, we can transform The following is the desired consequence of tameness. (programs over semigroups being defined in the obvious way). Our proof follows the same lines.
Proof. Let L be a regular language in P (M ) for some M ∈ V. Let M L be the syntactic monoid of L and η L its syntactic morphism. Let S be the stable semigroup of η L , in particular S = η L (Σ k ) for some k. We wish to show that S 1 is in V.
We show that W(S) ⊆ P (V) and conclude from the fact that V is an sp-variety that S 1 ∈ V as desired. Let η S : S * → S 1 be the evaluation morphism of S. Consider m ∈ S and consider L = η −1 S (m). We wish to show that L ∈ P (V). This implies that W(S) ⊆ P (V) by closure under union, Lemma 1.
Since m belongs to the syntactic monoid of L and η L is the syntactic morphism of L, a classical algebraic argument [22, Chapter 2, proof of Lemma 2.6] shows that L is a Boolean combination of quotients of L or their complements. By Lemma 1, we conclude that L ∈ P (V).
By definition of S, for any element s of S there is a word u s of length k such that η L (u s ) = s. Notice that this is precisely where we need to work with S and not S 1 .
Let f : S * → Σ * be the lm-morphism sending s to u s and notice that L = f −1 (L ). The result follows by closure of P (V) under inverse images of lm-morphisms, Lemma 1.
We don't know whether it is always true that for sp-varieties of monoids V, L (QV) is included into P (V). We can only prove it for local varieties. Proof. This follows from the fact that for local varieties L (QV) = L (V * Mod) [9]. The result follows from Proposition 3, as we always have L (V * Mod) ⊆ P (V).
As A is local [31, Example 15.5] and an sp-variety, it follows from Proposition 4 that the regular languages in P (A), hence in AC 0 , are precisely those in L (QA), which is the characterization of the regular languages in AC 0 obtained by Barrington, Compton, Straubing and Thérien [4].
We will see in the next section that DA is an sp-variety. As it is also local [2], we get from Proposition 4 that the regular languages of P (DA) are precisely those in L (QDA).
As explained in the introduction, the language (a + b) * ac + can be p-recognized by a program over J. A simple algebraic argument shows that it is not in L (QJ). Hence, by Proposition 3, we have the following result: Proposition 5. J is not an sp-variety of monoids.

4
The case of DA In this section, we prove that DA is an sp-variety of monoids. Combined with the fact that DA is local [2], we obtain the following result by Proposition 4.
The result follows from the following main technical contribution: Before proving the proposition we first show that it implies that DA is an sp-variety of monoids. Assume S is a finite semigroup such that W(S) ⊆ P (DA). Let η S : S * → S 1 be the evaluation morphism of S. We need to show that S 1 is in DA.
Assume first that S 1 is aperiodic. Towards a contradiction, assume S 1 is not in DA. Then, there exist x, y in S such that (xy) ω = (xy) ω x(xy) ω .

2:8
The Power of Programs over Monoids in DA Set e = (xy) ω , f = (yx) ω , s = ex and t = ye. Our hypothesis says that exe = e. We now have two cases, depending on whether f yf = f or not.
So, suppose f yf = f . In that case, let µ : {a, b, c} * → S 1 be the morphism sending a to s, b to t and c to e and consider the language L = µ −1 ({1, e}). Assume that L contains a word w with two consecutive a. Then w = w 1 aaw 2 and as w ∈ L, either e = µ(w 1 )exexµ(w 2 ) or 1 = µ(w 1 )exexµ(w 2 ). In both cases e = u 1 exeu 2 for some suitable values of u 1 and u 2 . This implies that e = u ω 1 e(xeu 2 ) ω = (u 1 xe) ω eu ω 2 . Because S 1 is aperiodic, this implies: e = exeu 2 = eu 2 . Hence exe = e, contradicting the fact that exe = e. Similar arguments show that L cannot contain a word with two consecutive b, a factor ac or a factor cb.
The other case, when f yf = f , is treated similarly using the morphism µ : {a, b} * → S 1 sending a to s and b to t and considering the language L = µ −1 ({1, e, t}). Using arguments as for the previous case, one can conclude that L = (b + ab) * .
Assume now that S 1 is not aperiodic. As in the two previous cases, we can then prove that there exist a morphism µ : {a, b} * → S 1 and a subset F ⊆ S 1 such that L = µ −1 (F ) is the regular language ((b * ab * ) k ) * for some k ∈ N, k ≥ 2 of all words over {a, b} with a number of a congruent to 0 modulo k.
In all cases, we have a language L defined as µ −1 (Q) for some subset Q of S 1 and some morphism µ to S 1 sending letters to elements of S. As W(S) ⊆ P (DA), it follows that η −1 S (Q) is p-recognized by a sequence of programs (P n ) n∈N over a monoid in DA. As in the example prior to Proposition 3 in the previous section, for each n ∈ N, we can transform P n into P n over the same monoid so that the sequence of programs (P n ) n∈N p-recognizes L. In all cases, we get a contradiction with Proposition 7.
In the remaining part of this section we prove Proposition 7.
Proof of Proposition 7. The idea of the proof is the following. We work by contradiction and assume that we have a sequence of programs over some monoid M of DA deciding one of the targeted language. Let n be much larger than the size of M , and let P n be the program running on words of length n. Consider a language of the form ∆ * for some finite set ∆ of words (for instance assume ∆ = {c, ab}, ∆ = {b, ab}, . . . ). We will show that we can fix a constant (depending on M and ∆ but not on n) number of entries to P n such that P n always accepts or always rejects and there is a completion of the fixed entries in ∆ * ; hence, if ∆ was chosen so that there is actually a completion of the fixed entries in the targeted language and one outside of it, P n cannot recognize it. We cannot prove this for all ∆, in particular it will not work for ∆ = {ab} and indeed (ab) * is in P (DA). The key property of our ∆ is that after fixing any letter at any position, except maybe for a constant number of positions, one can still complete the word into one within ∆ * . This is not true for ∆ = {ab} because after fixing a b in an odd position all completions fall outside of (ab) * . We now add some technical details. Let ∆ be a finite set of words. Let Σ be the corresponding finite alphabet and let ⊥ be a letter not in Σ. A mask is a word over Σ ∪ {⊥}. The positions of a mask carrying a ⊥ are called free while the positions carrying a letter in Σ are called fixed. A mask λ is a submask of a mask λ if it is formed from λ by replacing some occurrences of ⊥ by a letter in Σ.
A completion of a mask λ is a word w over Σ that is built from λ by replacing all occurrences of ⊥ by a letter in Σ. Notice that all completions of a mask have the same length as the mask itself. A mask λ is ∆-compatible if it has a completion in ∆ * .
The dangerous positions of a mask λ are the positions within distance 2l − 2 of the fixed positions or within distance l − 1 of the beginning or the end of the mask, where l is the maximal length of a word in ∆. A position that is not dangerous is said to be safe.
We say that ∆ is safe if the following holds. Let λ be a ∆-compatible mask. Let i be any free position of λ that is not dangerous. Let a be any letter in Σ. Then the submask of λ constructed by fixing a at position i is ∆-compatible. We have already seen that ∆ = {ab} is not safe. However our targeted ∆, ∆ = {c, ab}, ∆ = {b, ab}, ∆ = {a, b}, are safe. We always consider ∆ to be safe in the following.
Finally, we say that a completion w of a mask λ is safe if w is a completion of λ belonging to ∆ * or is constructed from a completion of λ in ∆ * by modifying only letters at safe positions of λ, the dangerous positions remaining unchanged.
The following lemma is the key to the proof. It shows that modulo fixing a few entries, one can fix the output. Setting ∆ = {c, ab} or ∆ = {b, ab}, when applying Lemma 8 for some monoid M ∈ DA with the trivial ∆-compatible mask λ of length n containing only free positions, with P some program over M of range n and with u and v the identity of M , the resulting mask λ has the property that we have an element t of M such that P (w) = t for any safe completion w of λ . Since the mask λ is ∆-compatible and as long as n is big enough, we have a safe completion w 0 ∈ ∆ * and a safe completion w 1 / ∈ ∆ * . Hence P cannot recognize ∆ * . This implies that (c + ab) * / ∈ P (M ) and (b + ab) * / ∈ P (M ). Finally, for any k ∈ N, k ≥ 2, we can prove that ((b * ab * ) k ) * / ∈ P (M ) by setting ∆ = {a, b} and completing the mask given by the lemma by setting the letters in such a way that we have the right number of a modulo k in one case and not in the other case.
This concludes the proof of Proposition 7 because the argument above holds for any monoid in DA.

A fine hierarchy in P (DA)
The definition of p-recognition by a sequence of programs over a monoid given in Section 2 requires that for each n, the program reading the entries of length n has a length polynomial in n. In the case of P (DA), the polynomial length restriction is without loss of generality: any program over a monoid in DA is equivalent to one of polynomial length over the same monoid [29] (in the sense that they recognize the same languages). In this section, we show that this does not collapse further: in the case of DA, programs of length O(n k+1 ) express strictly more than those of length O(n k ). Following [13], we use an alternative definition of the languages recognized by a monoid in DA. We define by induction a hierarchy of classes of languages SUM k , where SUM stands for strongly unambiguous monomial. A language L is in SUM 0 if it is of the form 2:10 The Power of Programs over Monoids in DA A * for some finite alphabet A. A language L is in SUM k if it is in SUM k−1 or L = L 1 aL 2 for some languages L 1 ∈ SUM i and L 2 ∈ SUM j and some letter a with i + j = k − 1 such that no word of L 1 contains the letter a or no word of L 2 contains the letter a.
Gavaldà and Thérien showed that a language L is recognized by a monoid in DA iff there is a k such that L is a Boolean combination of languages in SUM k [13]. For each k ∈ N, we denote by DA k the variety of monoids generated by the syntactic monoids of the Boolean combinations of languages in SUM k . It can be checked that, for each k, DA k forms a variety of monoids recognizing precisely Boolean combinations of languages in SUM k (see Appendix B).

Strict hierarchy
For each k we exhibit a language L k ⊆ {0, 1} * that can be recognized by a sequence of programs of length O(n k ) over a monoid M k in DA but cannot be recognized by any sequence of programs of length O(n k−1 ) over any monoid in DA.
The language L k expresses a property of the first k occurrences of 1 in the input word. To define L k we say that S is a k-set over n if S is a set where each element is an ordered tuple of k distinct elements of [n]. For any sequence ∆ = (S n ) n∈N of k-sets over n, we set L ∆ = n∈N K n,Sn , where K n,Sn is the set of words over {0, 1} of length n such that for each of them, it contains at least k occurrences of 1 and the ordered k-tuple of the positions of the first k occurrences of 1 belongs to S n .
On the one hand, we show that for all k there is a monoid M k in DA such that for all ∆ the language L ∆ is recognized by a sequence of programs over M k of length O(n k ). The proof is done by an inductive argument on k.
On the other hand, we show that there is a ∆ such that for any finite monoid M and any sequence of programs (P n ) n∈N over M of length O(n k−1 ), L ∆ is not recognized by (P n ) n∈N . This is done using a counting argument: for some monoid size i, for n big enough, the number of languages in {0, 1} n recognized by a program over some monoid of size i of length at most α · n k−1 is upper-bounded by a number that turns out to be asymptotically smaller than the number of different possible K n,Sn .
Upper bound. We start with the upper bound. Notice that for ∆ = (S n ) n∈N , the language of words of length n of L ∆ is exactly K n,Sn . Hence the fact that L ∆ can be recognized by a sequence of programs over a monoid in DA of length O(n k ) is a consequence of the following proposition.
Proposition 9. For all k ∈ N >0 there is a monoid M k ∈ DA k such that for all n ∈ N and all S n k-sets over n, the language K n,Sn is recognized by a program over M k of length at most 4n k .
Proof. We first define by induction on k a family of languages Z k over the alphabet Y k = {⊥ l , l | 1 ≤ l ≤ k}. For k = 0, Z 0 is {ε}. For k > 0, Z k is the set of words containing k and such that the first occurrence of k has no ⊥k to its left, and the sequence between the first occurrence of k and the first occurrence of ⊥k or k to its right, or the end of the word if there is no such letter, belongs to Z k−1 . A simple induction on k shows that Z k is defined by the following expression and therefore it is in SUM k and its syntactic monoid M k is in DA k .
Fix n. If n = 0, the proposition follows trivially, otherwise, we define by induction on k a program P k (i, S) for every k-set S over n and every 1 ≤ i ≤ n + 1 that will for the moment output letters of Y k instead of outputting elements of M k .
For any k > 0 and S a k-set over n, let f j,S be the function with f j,S (0) = ε and f j,S (1) = k if j is the first element of some ordered k-tuple of S, f j,S (1) = ⊥k otherwise. We also let g k be the function with g k (0) = ε and g k (1) = ⊥k. If S is a k-set over n and j ≤ n then S|j denotes the (k − 1)-set over n containing the ordered (k − 1)-tuplest such that (j,t) ∈ S.
For k > 0, 1 ≤ i ≤ n + 1 and S a k-set over n, the program P k (i, S) is the following sequence of instructions: (i, f i,S )P k−1 (i + 1, S|i)(i, g k ) · · · (n, f n,S )P k−1 (n + 1, S|n)(n, g k ).
In other words, the program guesses the first occurrence j ≥ i of 1, returns ⊥k or k depending on whether it is the first element of an ordered k-tuple in S, and then proceeds for the next occurrences of 1 by induction.
For k = 0, 1 ≤ i ≤ n + 1 and S a 0-set over n (that is empty or contains ε, the only ordered 0-tuple of elements of [n]), the program P 0 (i, S) is the empty program ε.
A simple computation shows that for any k ∈ N >0 , 1 ≤ i ≤ n + 1 and S a k-set over n, the number of instructions in P k (i, S) is at most 4n k .
A simple induction on k shows that when running on a word w ∈ {0, 1} n , for any k ∈ N >0 , 1 ≤ i ≤ n + 1 and S a k-set over n, P k (i, S) returns a word in Z k iff the ordered k-tuple of the positions of the first k occurrences of 1 starting at position i in w exists and is an element of S.
For any k > 0 and S n a k-set over n, it remains to apply the syntactic morphism of Z k to the output of the functions in the instructions of P k (1, S n ) to get a program over M k of length at most 4n k recognizing K n,Sn .

Lower bound.
The following claim is a simple counting argument. If for some k ∈ N >0 and 1 ≤ i ≤ α, α ∈ N >0 , we apply Claim 10 for all n ∈ N, l = α·n k−1 , we get a number of languages upper-bounded by n O(n k−1 ) , which is asymptotically strictly smaller than the number of distinct K n,Sn , which is 2 ( n k ) . Hence, for all j ∈ N >0 , there exist an n j ∈ N and T j a k-set over n j such that no program over a monoid of size 1 ≤ i ≤ j and of length at most j · n k−1 recognizes K nj ,Tj . Moreover, we can assume without loss of generality that the sequence (n j ) j∈N>0 is increasing. Let

2:12
The Power of Programs over Monoids in DA ∆ = (S n ) n∈N be such that S nj = T j for all j ∈ N >0 and S n = ∅ for any n ∈ N verifying that it is not equal to any n j for j ∈ N >0 . We show that no sequence of programs over a finite monoid of length O(n k−1 ) can recognize L ∆ . If this were the case, then let i be the size of the monoid. Let j ≥ i be such that for any n ∈ N, the n-th program has length at most j · n k−1 . But, by construction, we know that there does not exist any such program of range n j recognizing K nj ,Tj , a contradiction.
This implies the following hierarchy (where P (V, s(n)) for some variety of monoids V and a function s : N → N denotes the class of languages recognizable by a sequence of programs of length O(s(n))): Proposition 11. For all k ∈ N, P DA, n k P DA, n k+1 .

Collapse
Tesson and Thérien showed that any program over a monoid M in DA is equivalent to one of polynomial length [29]. We now show that if we further assume that M is in DA k then the length can be assumed to be O(n k ). The equivalent program of length O(n k ) is actually a subprogram of the initial one. For each possible acceptance set, an input word to the program is accepted iff the word over the alphabet M produced by the program belongs to some fixed Boolean combination of languages in SUM k . The idea is then just to keep enough instructions so that membership of the produced word over M in each of these languages does not change. For each of those languages, the set of instructions to keep is defined by induction on k using the inductive definition of SUM k given at the beginning of this section. Roughly, at each step, for each input letter and each input position, the small program keeps the first or last instruction of the big program producing the "pivot element" when reading this input letter at that position. The number of instructions kept in the end is then in O(n k ). The details can be found in Appendix C.

Conclusion
For local and tame varieties V we have shown that the regular languages recognized by programs over V are exactly those in L (QV). It is not clear whether locality is necessary. We don't have any example of a tame variety V for which L (QV) is not included into P (V). We leave this question for future work. We have shown that DA is tame but that J is not. Another example of a tame variety is A. However we needed the fact that MOD m is not in AC 0 for all m ≥ 2 in order to prove tameness. It would be interesting to give a direct algebraic proof of this result. As this would in particular imply that MOD 2 is not in AC 0 by Proposition 4, it is certainly a challenging task.
Finding the regular languages recognized by programs over J is left for future work.
To conclude we should add, in fairness, that the progress reported here does not obviously bring us closer to major NC 1 complexity subclasses separations, but it does uncover new ways in which a program can or cannot circumvent the limitations imposed by the underlying monoid algebraic structure available to it.

A Missing proofs from Section 4
Let M be a monoid in DA whose identity we will denote by 1.
Given two elements u, u of M we say that u ≤ L u if there is an element v of M such that u = vu. We write u ∼ L u if u ≤ L u and u ≤ L u. We write u < L u if u ≤ L u and u ∼ L u.
We shall use the following well-known fact about these preorders and equivalence relations (see [22, Chapter 3, Proposition 1.4]).

Lemma 13. For all elements u and
An element r of M is R-bad for u if u < R ur. Similarly an element r of M is L-bad for v if u < L rv. It follows from M ∈ DA that being R-bad or L-bad only depends on the ∼ R or ∼ L class, respectively: Let ∆ be a finite set of words and Σ be the corresponding finite alphabet, ∆ being safe, and let n ∈ N. We are now going to prove the main technical lemma that allows us to assert that after fixing a constant number of positions in the input of a program over M , it can still be completed into a word of ∆ * , but the program cannot make the difference between any two possible completions anymore. To prove the lemma, we define a relation ≺ on the set of quadruplets (λ, P, u, v) where λ is a mask of length n, P is a program over M for words of length n and u and v are two elements. We will say that an element (λ 1 , P 1 , u 1 , v 1 ) is strictly smaller than (λ 2 , P 2 , u 2 , v 2 ), written (λ 1 , P 1 , u 1 , v 1 ) ≺ (λ 2 , P 2 , u 2 , v 2 ) if λ 1 is a submask of λ 2 , P 1 is a subprogram of P 2 and one of the following cases occurs:

Proof. The proof goes by induction on ≺.
Let λ be a ∆-compatible mask of length n, let P be a program over M for words of length n, let u and v be elements of M such that (λ, P, u, v) is of height h, and assume that for any quadruplet (λ , P , u , v ) strictly smaller than (λ, P, u, v), the lemma is verified. Consider the following conditions concerning the quadruplet (λ, P, u, v): We will now do a case analysis based on which of these conditions are violated or not. Case 1: condition 1 is violated. So there exists some instruction (x, f ) of P such that for some letter a the submask λ of λ formed by setting position x to a (if it wasn't already the case) is ∆-compatible and f (a) is R-bad for u. Let i be the smallest number of such an instruction. Let P be the subprogram of P until instruction i − 1. Let w be a safe completion of λ. By minimality of i and by Lemma 14, it follows that u ∼ R uP (w).
So, because f (a) is R-bad for u, any safe completion w of λ , which is also a safe completion of λ, is such that u ∼ R uP (w) < R uP (w)f (a) ≤ R uP (w)v by Lemma 14, hence uP (w) < J uP (w)v by Lemma 13. So (λ , P , u, 1) ≺ (λ, P, u, v), therefore, by induction we get a ∆-compatible submask λ 1 of λ and a monoid element t 1 such that uP (w) = t 1 for all safe completions w of λ 1 . Let P be the subprogram of P starting from instruction i+1. Notice that, since u ∼ R t 1 (by what we have proven just above), u < R t 1 f (a) (by Lemma 14) and t 1 f (a)P (w)v = uP (w)f (a)P (w)v = uP (w)v for all safe completions w of λ 1 . Hence, (λ 1 , P , t 1 f (a), v) is strictly smaller than (λ 1 , P, u, v) and by induction we get a ∆-compatible submask λ 2 of λ 1 and a monoid element t such that t 1 f (a)P (w)v = t for all safe completions w of λ 2 .

2:16
The Power of Programs over Monoids in DA Hence any safe completion w of λ 2 is such that Hence λ 2 and t are the desired solutions. Case 2: condition 1 is verified but condition 2 is violated, so v is R-bad for u and Case 1 does not apply. Let w be a safe completion of λ: for any instruction (x, f ) of P , as the submask λ of λ formed by setting position x to w x (if it wasn't already the case) is ∆-compatible (by the fact that ∆ is safe and w is a safe completion of λ), f (w x ) cannot be R-bad for u, otherwise condition 1 would be violated, so u ∼ R uf (w x ). Hence, by Lemma 14, u ∼ R uP (w) for all safe completions w of λ. Notice then that u ∼ R uP (w) < R uP (w)v (by Lemma 14), hence uP (w) < J uP (w)v (by Lemma 13) for all safe completions w of λ. So (λ, P, u, 1) ≺ (λ, P, u, v), therefore we obtain a monoid element t 1 and a ∆-compatible submask λ of λ by induction such that uP (w) = t 1 for all completions w of λ . t = t 1 v is the desired element of M . Case 3: condition 3 is violated. So there exists some instruction (x, f ) of P such that for some letter a the submask λ of λ formed by setting position x to a (if it wasn't already the case) is ∆-compatible and f (a) is L-bad for v. We proceed as for Case 1 by symmetry. Case 4: condition 3 is verified but condition 4 is violated, so u is L-bad for v and Case 3 does not apply. We proceed as for Case 2 by symmetry. Case 5: conditions 1, 2, 3 and 4 are verified.
As it Case 2 and Case 4 we get that u ∼ R uP (w) and v ∼ L P (w)v for any prefix P of P , any suffix P of P and all safe completions w of λ. Moreover, since condition 2 and condition 4 are verified, by Lemma 14, we get that uP (w)v ∼ R u and uP (w)v ∼ L v for all safe completions w of λ.
Let w 0 be a completion of λ that is in ∆ * . Let λ be the submask of λ fixing all dangerous positions of λ using w 0 . Then, for any completion w of λ , which is a safe completion of λ by construction, we have that uP (w)v ∼ R u and uP (w)v ∼ L v. As M is aperiodic, this implies that there is a t in M such that uP (w)v = t for all completions w of λ (see [22, Chapter 3, Proposition 4.2]).
This concludes the proof of the lemma.

SU L k is a variety of languages
A variety of languages is a class of languages over arbitrary finite alphabets closed under Boolean operations, quotients and inverses of morphisms (i.e. if L is a language in the class over a finite alphabet Σ, if Γ is some other finite alphabet and ϕ : Γ * → Σ * is a morphism of monoids, then ϕ −1 (L) is also in the class). Eilenberg showed [11, Chapter VII, Section 3] that there is a bijective correspondence between varieties of monoids and varieties of languages: to each variety of monoids V we can bijectively associate L (V) the variety of languages whose syntactic monoids belong to V and, conversely, to each variety of languages V we can bijectively associate M(V) the variety of monoids generated by the syntactic monoids of the languages of V, and these correspondences are mutually inverse.
We denote by SUL k the class of regular languages that are Boolean combinations of languages in SUM k .
In this appendix, we show that, for all k ∈ N, SUL k is a variety of languages. As DA k is the variety of monoids generated by the syntactic monoids of the languages in SUL k , by Eilenberg's theorem, we know that, conversely, all the regular languages whose syntactic monoids lie in DA k are in SUL k .
Closure under Boolean operations is obvious by construction. Closure under quotients and inverses of morphisms is respectively given by the following two lemmas and by the fact that both quotients and inverses of morphisms commute with Boolean operations.
Given a word u over a given finite alphabet Σ, we will denote by alph(u) the set of letters of Σ that appear in u.
Lemma 15. For all k ∈ N, for all L ∈ SUM k over a finite alphabet Σ and u ∈ Σ * , u −1 L and Lu −1 both are a union of languages in SUM k over Σ.
Proof. We prove it by induction on k.
Base case: k = 0. Let L ∈ SU M 0 over a finite alphabet Σ and u ∈ Σ * . This means that L = A * for some A ⊆ Σ. We have two cases: either alph(u) A and then u −1 L = Lu −1 = ∅; or alph(u) ⊆ A and then u −1 L = Lu −1 = A * = L. So u −1 L and Lu −1 both are a union of languages in SUM 0 over Σ. The base case is hence proved. Inductive step. Let k ∈ N >0 and assume that the lemma is true for all k ∈ N, k < k. Let L ∈ SUM k over a finite alphabet Σ and u ∈ Σ * . This means that either L is in SUM k−1 and the lemma is proved by applying the inductive hypothesis directly for L and u, or L = L 1 aL 2 for some languages L 1 ∈ SU M i and L 2 ∈ SU M j and some letter a ∈ Σ with i + j = k − 1 and, either no word of L 1 contains the letter a or no word of L 2 contains the letter a. We shall only treat the case in which a does not appear in any of the words of L 1 ; the other case is treated symmetrically. There are again two cases to consider, depending on whether a does appear in u or not. If a / ∈ alph(u), then it is straightforward to check that u −1 L = (u −1 L 1 )aL 2 and Lu −1 = L 1 a(L 2 u −1 ). By the inductive hypothesis, we get that u −1 L 1 is a union of languages in SUM i over Σ and that L 2 u −1 is a union of languages in SUM j over Σ. Moreover, it is direct to see that no word of u −1 L 1 contains the letter a. By distributivity of concatenation over union, we finally get that u −1 L and Lu −1 both are a union of languages in SUM k over Σ. If a ∈ alph(u), then let u = u 1 au 2 with u 1 , u 2 ∈ Σ * and a / ∈ alph(u 1 ). It is again straightforward to see that Again, by the inductive hypothesis, we get that L 1 u 1 −1 is a union of languages in SUM i over Σ and that both u 2 −1 L 2 and L 2 u −1 are unions of languages in SUM j over Σ. And, again, by distributivity of concatenation over union, we get that u −1 L and Lu −1 both are a union of languages in SUM k over Σ. This concludes the inductive step and therefore the proof of the lemma. Proof. We prove it by induction on k.
Base case: k = 0. Let L ∈ SUM 0 over a finite alphabet Σ and ϕ : Γ * → Σ * a morphism of monoids where Γ is another finite alphabet. This means that L = A * for some A ⊆ Σ. It is straightforward to check that ϕ −1 (L) = B * where B = {b ∈ Γ | ϕ(b) ∈ A * }. B * is certainly a union of languages in SUM 0 over Σ. The base case is hence proved. Inductive step. Let k ∈ N >0 and assume that the lemma is true for all k ∈ N, k < k.
Let L ∈ SUM k over a finite alphabet Σ and ϕ : Γ * → Σ * a morphism of monoids where Γ is another finite alphabet. This means that either L is in SUM k−1 and the lemma is proved by applying the inductive hypothesis directly for L and ϕ, or L = L 1 aL 2 for some languages L 1 ∈ SUM i and L 2 ∈ SUM j and some letter a ∈ Σ with i + j = k − 1 and, either no word of L 1 contains the letter a or no word of L 2 contains the letter a. We shall only treat the case in which a does not appear in any of the words of L 1 ; the other case is treated symmetrically. Let us define B = {b ∈ Γ | a ∈ alph(ϕ(b))} as the set of letters of Γ whose image word by ϕ contains the letter a. For each b ∈ B, we shall also let ϕ(b) = u b,1 au b,2 with u b,1 , u b,2 ∈ Σ * and a / ∈ u b,1 . It is not too difficult to see that we then have By the inductive hypothesis, by Lemma 15 and by the fact that inverses of morphisms commute with unions, we get that ϕ −1 (L 1 u b,1 −1 ) is a union of languages in SUM i over Γ and that ϕ −1 (u b,2 −1 L 2 ) is a union of languages in SUM j over Γ. Moreover, it is direct to see that no word of ϕ −1 (L 1 u b,1 −1 ) contains the letter b for all b ∈ B. By distributivity of concatenation over union, we finally get that ϕ −1 (L) is a union of languages in SUM k over Γ. This concludes the inductive step and therefore the proof of the lemma.

C Collapse
In this appendix we prove Proposition 12, stating that when M is in DA k then any program over M is equivalent to one of length O(n k ). Recall that if P is a program over some monoid M of range n, then P (w) denotes the element of M resulting from the execution of the program P on w. It will be convenient here to also work with the word over M resulting from the sequence of executions of each instruction of P on w. We denote this word by EP (w).
The result is a consequence of the following lemma and the fact that for any acceptance set F ⊆ M , a word w ∈ Σ n (where Σ is the input alphabet) is accepted iff EP (w) ∈ L where L is a language in SUL k , a Boolean combination of languages in SUM k .
Lemma 17. Let Σ be a finite alphabet, M a finite monoid, and n, k natural numbers. For any program P over M of range n, any set Γ ⊆ M and any language K over Γ in SUM k , there exists a subsequence Q of the sequence of instructions P of length O(n max{k,1} ) such that for any subsequence Q of the sequence of instructions P containing Q as a subsequence, we have for all words w over Σ of length n: Proof. A program P over M of range n is a finite sequence (p i , f i ) of instructions where each p i is a natural number which is at most n and each f i is a function from Σ to M . We denote by l the number of instructions of P . For each set I ⊆ [l] we denote by P [I] the program over M consisting of the subsequence of instructions of P obtained after removing all instructions whose index is not in I. In particular, P [1, m] denotes the initial sequence of instructions of P , until instruction number m.
We prove the lemma by induction on k. Inductive step. Let k ≥ 2 and assume the lemma proved for all k < k. Let n be a natural number, P a program over M of range n and length l, Γ ⊆ M and any language K over Γ in SUM k . By definition, K = K 1 γK 2 for some languages K 1 ∈ SUM i and K 2 ∈ SUM j with i + j = k − 1. Moreover either γ does not occur in any of the words of K 1 or it does not occur in any of the words of K 2 . We only treat the case where γ does not appear in any of the words in K 1 . The other case is treated similarly by symmetry. For each p ≤ n and each a ∈ Σ consider within the sequence of instructions of P the first instruction of the form (p, f ) with f (a) = γ. We let I γ be the set of indices of these instructions for all a and p. Notice that the size of I is in O(n). For all i ∈ I γ , we let J i,1 be the set of indices of the instructions within P [1, i − 1] obtained by induction for K 1 and J i,2 be the same for P [i + 1, l] and K 2 . We now let I be the union of I γ and J i,1 and J i,2 = {j + i | j ∈ J i,2 } for all i ∈ I γ . We claim that P [I] has the desired properties. First notice that by induction the sizes of J i,1 and J i,2 for all i ∈ I γ are in O(n max{k−1,1} ) = O(n k−1 ) and because the size of I γ is linear in n, the size of I is in O(n k ) = O(n max{k,1} ) as required. Now take w ∈ Σ n . Assume now that EP (w) ∈ K. Let i be the position in EP (w) of label γ witnessing the membership in K. Let (p i , f i ) be the corresponding instruction of P . In particular we have that f i (w pi ) = γ. Because γ does not occur in any word of K 1 , for all j < i such that p j = p i we cannot have f j (w pj ) = γ. Hence i ∈ I γ . By induction we have that EP Assume finally that EP [I](w) ∈ K. Let i be the index in I whose instruction provides the letter γ witnessing the fact that EP [I](w) ∈ K. If i ∈ I γ we conclude easily by induction. If not this shows that there is an instruction (p j , f j ) with j < i, j ∈ I, p j = p i and f j (w pj ) = γ. But that would contradict the fact that γ cannot occur in K 1 . Base case. There are two subcases to consider. k = 1. Let n be a natural number, P a program over M of range n and length l, Γ ⊆ M and any language K over Γ in SUM 1 . Then K = A * 1 γA * 2 for some finite alphabets A 1 ⊆ Γ and A 2 ⊆ Γ. Moreover either γ / ∈ A 1 or γ / ∈ A 2 . We only treat the case where γ does not belong to A 1 , the other case is treated similarly by symmetry. We use the same idea as in the inductive step. For each p ≤ n, each α ∈ Γ and a ∈ Σ consider within the sequence of instructions of P the first and last instruction of the form (p, f ) with f (a) = α. We let I be the set of indices of these instructions for all a, α and p. Notice that the size of I is in O(n) = O(n max{k,1} ). We claim that P [I] has the desired properties. Take w ∈ Σ n . Assume now that EP (w) ∈ K. Let i be the position in EP (w) of label γ witnessing the membership in K. Let (p i , f i ) be the corresponding instruction of P . In particular we have that f i (w pi ) = γ and this is the γ witnessing the membership in K. Because γ / ∈ A 1 , for all j < i such that p j = p i we cannot have f j (w pj ) = γ. Hence i ∈ I. Let i be the index in I whose instruction provides the letter γ witnessing the fact that EP [I](w) ∈ K. If there is an instruction (p j , f j ), with j < i and f j (w pj ) / ∈ A 1 then either j ∈ I and we get a direct contradiction with the fact that EP [I ∩ [[1, i − 1]]](w) ∈ A * 1 , or j / ∈ I and we get a smaller j ∈ I with the same property, contradicting again the fact that EP [I ∩ [[1, i − 1]]](w) ∈ A * 1 . Hence for all j < i, f j (w pj ) ∈ A 1 . By symmetry we have that for all j > i, f j (w pj ) ∈ A 2 , showing that EP (w) ∈ A * 1 γA * 2 = K as desired. k = 0. Let n be a natural number, P a program over M of range n and length l, Γ ⊆ M and any language K over Γ in SUM 0 . Then K = A * for some finite alphabet A ⊆ Γ. We again use the same idea as before. For each p ≤ n, each α ∈ Γ and a ∈ Σ consider within the sequence of instructions of P the first instruction of the form (p, f ) with f (a) = α. We let I be the set of indices of these instructions for all a, α and p. Notice that the size of I is in O(n) = O(n {k,1} ). We claim that P [I] has the desired properties. Take w ∈ Σ n . Assume now that EP (w) ∈ K. As EP [I](w) is a subword of EP (w), it follows directly that EP [I](w) ∈ A * = K as desired. Assume finally that EP [I](w) ∈ K. If there is an instruction (p j , f j ), with j ∈ [l] and f j (w pj ) / ∈ A then either j ∈ I and we get a direct contradiction with the fact that EP [I](w) ∈ A * = K, or j / ∈ I and we get a smaller j ∈ I with the same property, contradicting again the fact that EP [I](w) ∈ A * = K. Hence for all j ∈ [l], f j (w pj ) ∈ A, showing that EP (w) ∈ A * = K as desired.