Locality and Centrality: The Variety ZG

We study the variety ZG of monoids where the elements that belong to a group are central, i.e., commute with all other elements. We show that ZG is local, that is, the semidirect product ZG * D of ZG by definite semigroups is equal to LZG, the variety of semigroups where all local monoids are in ZG. Our main result is thus: ZG * D = LZG. We prove this result using Straubing's delay theorem, by considering paths in the category of idempotents. In the process, we obtain the characterization ZG = MNil \vee Com, and also characterize the ZG languages, i.e., the languages whose syntactic monoid is in ZG: they are precisely the languages that are finite unions of disjoint shuffles of singleton languages and regular commutative languages.


Introduction
In this paper, we study a variety of monoids called ZG.It is defined by requiring that the elements of the monoid that belong to a group are central, i.e., commute with all other elements of the monoid.The notation ZG thus stands for Zentral Group, inspired by the classical notion of centrality in group theory.We can also define ZG with the equation x ω+1 y = yx ω+1 on all elements x and y, where ω is the idempotent power of the monoid.
The variety ZG has been introduced by Auinger [Aui00] as a subvariety of interest of the broader and better-known class ZE of semigroups where the idempotent elements are central.The study of ZE was initiated by Almeida and Azevedo [AA87].Straubing studied in particular the variety MNil (called simply V in [Str82]) of regular languages generated by finite languages, and showed that it is exactly the variety of aperiodic monoids in ZE.From this, a systematic investigation of the subclasses of ZE was started by Almeida and pursued by Auinger: see [Alm96,page 211] and [Aui00,Aui02].
Our specific motivation to investigate ZG is our recently published study [AJP21] of the dynamic membership problem for regular languages.In this problem, introduced in [SFMS97], we study how to apply substitution update operations on an input word while maintaining the information of whether it belongs to a fixed regular language.In [AJP21], we show Further, the variety MNil of aperiodic monoids in ZE (introduced in [Str82] and mentioned earlier) is exactly ZG 1 .Thus: Corollary 1.3.We have LMNil = MNil * D.
In the process of proving Theorem 1.1, we obtain a characterization of ZG p -congruences, i.e., congruences ∼ on Σ * where the quotient Σ * / ∼ is a monoid of ZG p .We show that they are always refined by a so-called n, p-congruence, which identifies the number of occurrences of the frequent letters (the ones occurring > n times in the word) modulo p, and also identifies the exact subword formed by the rare letters (the ones occurring ≤ n times).Thanks to this (Theorem 3.4), we also obtain a characterization of the languages of ZG, i.e., the languages whose syntactic monoid is in ZG: they are exactly the finite unions of disjoint shuffles of singleton languages and commutative languages (Corollary 3.5).We also characterize ZG as a variety of monoids (Corollary 3.6): ZG = MNil ∨ Com, for MNil defined in [Str82] and Com the variety of commutative monoids.
Paper structure.We give preliminaries in Section 2 and formally define the variety ZG.We then give in Section 3 our characterizations of ZG via n, p-congruences.We then define in Section 4 the varieties ZG * D, LZG, ZG p * D, and LZG p used in Theorem 1.1 and Corollary 1.2, which we prove in the rest of the paper.We first introduce the framework of Straubing's delay theorem used for our proof in Section 5, and rephrase our result as a claim (Claim 5.7) on paths in the category of idempotents.We then study in Section 6 how to pick a sufficiently large value of n as a choice of our n, p-congruence, show in Section 7 two lemmas on paths in the category of idempotents, and finish the proof in Section 8 by two nested inductions.We conclude in Section 9.

Preliminaries
For a complete presentation of the basic concepts (automata, monoids, semigroups, groups, etc.) the reader can refer to the book of Pin [Pin86] or to the more recent lecture notes [Pin19].Except for the free monoid, all semigroups, groups, and monoids that we consider are finite.
Semigroups, monoids, varieties.A semigroup S is a set equipped with an internal associative law (written multiplicatively).A monoid M is a semigroup with an identity element 1, i.e., an element with 1x = x1 = x for all x ∈ M : note that the identity element is necessarily unique.A variety of semigroups (resp., variety of monoids) is a class of semigroups (resp., monoids) closed under direct product, quotient, and subsemigroup (resp., submonoid).
For a semigroup S, we call x ∈ S idempotent if x 2 = x.We call the idempotent power of x ∈ S the unique idempotent element which is a power of x. (This means that x is idempotent iff it is its own idempotent power.)Now, the idempotent power of S is the least integer ω > 0 such that for any element x ∈ S, the element x ω is an idempotent power of x.We write x ω+k for any k ∈ Z to mean x ω+k ′ where k ′ ∈ {0, . . ., ω − 1} is the remainder of k in the integer division by ω.For example, x ω−1 simply denotes x 2ω−1 , where we have 2ω − 1 > 0; in particular, as expected, we have x ω−1 x = x ω .
Languages and congruences.We denote by Σ an alphabet and by Σ * the set of all finite words on Σ.A factor of a word is a contiguous subword of that word.For w ∈ Σ * , we denote by |w| the length of w.For u, v ∈ Σ * , we say that u is a subword of v if, letting n := |u|, there are 1 For w ∈ Σ * and a ∈ Σ, we denote by |w| a the number of occurrences of a in w.A language L is a subset of Σ * .
A congruence on a finite alphabet Σ is an equivalence relation on Σ * which satisfies compositionality, i.e., it is compatible with the concatenation of words in the following sense: for any words x, y, z, and t of Σ * , if x ∼ y and z ∼ t, then xz ∼ yt.It is a finite index congruence if it has a finite number of equivalence classes.For a given finite index congruence ∼, the quotient Σ * /∼ is a finite monoid, whose law corresponds to concatenation over Σ * and whose identity element is the class of the empty word.
The syntactic congruence of a regular language L over an alphabet Σ is the congruence on Σ where u, v ∈ Σ * are equivalent if for all s, t ∈ Σ * , we have sut ∈ L iff svt ∈ L. As L is regular, this congruence is a finite index congruence.The syntactic monoid of L over Σ * is then the quotient of Σ * by the syntactic congruence for L. The syntactic semigroup of L is the quotient of Σ + , the non-empty words over Σ, by the syntactic congruence.
A variety of regular languages is a class of regular languages which is closed under Boolean operations, left and right derivatives (also called left and right quotients), and inverse homomorphisms.By Eilenberg's theorem [Eil76], a variety V of monoids defines a variety of regular languages, namely, the languages whose syntactic monoid is in V. Following standard practice, we abuse notation and identify varieties of monoids with varieties of languages following this correspondence, i.e., we write V both for the variety of monoids and the variety of languages.
Letting V be a variety of monoids, we say that a finite index congruence ∼ on Σ is a V-congruence if the quotient Σ * /∼ is a monoid in V.For a given V-congruence ∼, the map η : Σ * → Σ * /∼, defined by associating each word with its equivalence class, is a surjective morphism to a monoid of V. Hence, each equivalence class is a language of V, since it is recognized by Σ * /∼.The variety ZG.In this paper, we study the variety of monoids ZG defined (via Reiterman's theorem [Rei82]) by the equation: x ω+1 y = yx ω+1 .Intuitively, this says that the elements of the form x ω+1 are central, i.e., commute with all other elements.This clearly implies the same for elements of the form x ω+k for any k ∈ Z, as we will implicitly use throughout the paper: Claim 2.1.For any monoid M in ZG, for x, y ∈ M , and k ∈ Z, we have: Proof.Recall that x ω+k denotes x ω+k ′ where k ′ ∈ {0, . . ., ω − 1} is the remainder of k in the integer division by ω.Now, we can write x ω+k ′ as (x ω+k ′ ) ω+1 , because the latter is equal to x (ω+k ′ )×(ω+1) which is indeed equal to x ω+k ′ .Thus, by setting x ′ := (x ω+k ′ ) and applying the equation of ZG, we conclude.
Note that the elements of the form x ω+1 are precisely the group elements, namely, the elements of the monoid that are within a (possibly trivial) group that is a subsemigroup of the monoid.In particular, the neutral elements of these groups are not necessarily the neutral element of the monoid.
Claim 2.1 motivates the name ZG, which stands for "Zentral Group": it follows the traditional notation Z(•) for central subgroups, and extends the variety ZE introduced in [Alm94, p211] which only requires idempotents to be central.Thus, we have ZG ⊊ ZE, and non-commutative groups are examples of monoids that are in ZE but not in ZG.
In addition to the class ZG, we will specifically study the subclasses ZG p for p > 0 defined by imposing the equation x ω+p = x ω in addition to the ZG equation.Intuitively, ZG p is the variety of monoids (and associated regular languages) where group elements commute and where the period of all group elements divides p, where the period of a group element x is the smallest integer p ′ such that x p ′ = x.Clearly, ZG = p>0 ZG p .Further, any finite language is in ZG p for any p > 0.
The period of a semigroup is the least common multiple of all periods of group elements.Note that the period of a semigroup always divides ω, because the period of any group element is equal to its idempotent power, hence divides ω.Further, the period of a monoid in ZG p always divides p.

Characterizations of ZG
In this section, we present our characterizations of ZG p and of ZG, which we will use to prove Theorem 1.1.We will show that ZG p is intimately linked to a congruence on words called the n, p-congruence.Intuitively, two words are identified by this congruence if the subwords of the rare letters (occurring less than n times) are the same, and the numbers of occurrences of the frequent letters (occurring more than n times) are congruent modulo p.This is the standard technique of stratification, used also, e.g., in [TW85, Example 0.1] or in [Alm94,Section 10.8].Formally: Definition 3.1 (Rare and frequent letters, n, p-congruence).Fix an alphabet Σ and a word w ∈ Σ * .Given a integer n ∈ N called the threshold, we call a ∈ Σ rare in w if |w| a ≤ n, and frequent in w if |w| a > n.The rare alphabet is the (possibly empty) set {a ∈ Σ | |w| a ≤ n}.We define the rare subword w |≤n to be the subword of w obtained by keeping only the rare letters of w.
For n > 0 and for any integer p > 0 called the period, the n, p-congruence ∼ n,p is defined by writing u ∼ n,p v for u, v ∈ Σ * iff: • The rare subwords are equal: u |≤n = v |≤n ; • The rare alphabets are the same: for all a ∈ Σ, we have |u| a > n iff |v| a > n; • The number of letter occurrences modulo p are the same: for all a ∈ Σ, we have that |u| a and |v| a are congruent modulo p. (Note that we already know this for rare letters using the previous conditions.) We first remark that two n, p-equivalent words are also m, q-equivalent for any divisor q of p and any m ≤ n: Claim 3.2.For any alphabet Σ, for any 0 < m ≤ n and p, q > 0 such that q divides p, the n, p-congruence refines the m, q-congruence.
Intuitively, it is less precise to look for exact subwords up to a lower threshold and with a modulo that divides the original modulo.Here is the formal proof: Proof of Claim 3.2.We first assume that p = q.The claim is trivial for m = n, so we assume n > m.As n > m, if two words u and v have the same rare alphabet for n, then they have the same rare alphabet for m, because the number of occurrences of all rare letters for n is the same, so the same ones are also rare for m.Furthermore, if u and v have the same rare subword for n, the restriction of this same rare subword to the rare letters for m yields the same rare subword for m.Last, the number of occurrences of the frequent letters modulo q is the same.Indeed, for the letters that were frequent for n, this is the case because their number of occurrences is congruent modulo p = q.For the letters that were not frequent for n, this is because their number of occurrences has to be the same because the rare subwords for n were the same.
We now assume that q < p.Let us now assume that m = n.Then the n, p-congruence refines the m, q-congruence because the rare alphabets and subwords must be equal (the threshold is unchanged), and the counts of the frequent letters modulo p determine these counts modulo q as q divides p.
To conclude in the general case, we know that the n, p-congruence refines the n, qcongruence which refines the m, q-congruence, so we conclude by transitivity.
What is more, observe that n, p-congruences are a particular case of ZG p -congruences: Claim 3.3.For any alphabet Σ and n > 0 and p > 0, the n, p-congruence over Σ * is a ZG p -congruence.
Proof.Let E be an equivalence class of the n, p-congruence, which we see as a language of Σ * , and let us show that E is a language of ZG p .Intuitively, E defines a language where the number of occurrences of each letter modulo p is fixed, where the set of letters occurring ≤ n times (the rare letters) is fixed, and the subword that they achieve is also fixed.Formally, let Σ = A ⊔ B the partition of Σ in rare and frequent letters for the class E, let u be the word over A * associated to the class E, and let ⃗ k be the |B|-tuple describing the modulo values for E.
We know that the singleton language {u} is a language of ZG p , because it is finite.Hence, the language U = B * u 1 • • • B * u n B * is also in ZG p , because it is the inverse of {u} by the morphism that erases the letters of B and is the identity on A. Similarly, the language C of words of B * where the number of occurrences of each letter modulo p are as prescribed by ⃗ k and where every letter occurs at least n times is a language of ZG p , because it is commutative and p is a multiple of the period of every group element.For the same reason, the language C ′ of words of Σ * whose restriction to B are in C is also a language of ZG p , because it is the inverse image of C by the morphism that erases the letters of A and is the identity on B. Now, we remark that E = C ′ ∩ U , so E is in ZG p , concluding the proof.
The goal of this section is to show the following result.Intuitively, it states that ZG p -congruences are always refined by a sufficiently large n, p-congruence.Formally: Theorem 3.4.For any p > 0, consider any ZG p -congruence ∼ over Σ * and consider the quotient M := Σ * /∼.Let n := (|M | + 1).Then the congruence ∼ is refined by the n, p-congruence on Σ.
We first present some consequences of Theorem 3.4, and then prove Theorem 3.4.
3.1.Consequences of Theorem 3.4.The most important consequence of Theorem 3.4 is a characterization of the languages in ZG, which is similar to the one obtained by Straubing in [Str82] for the variety MNil.To define MNil, first define the operation S 1 on a semigroup S: this is the monoid obtained from S by adding an identity element 1 to S if S does not have one.Now, define a nilpotent semigroup S to be a semigroup satisfying the equation x ω y = yx ω = x ω .The variety MNil is generated by monoids of the form S 1 for 4:7 S a nilpotent semigroup.Note that MNil ⊆ ZG, because the equation of MNil implies the equation of ZG.It was shown in [Str82] that the languages of MNil are generated by disjoint monomials, that is, they are Boolean combinations of languages of the form Our analogous characterization for ZG is the following, obtained via Theorem 3.4: Corollary 3.5.A language is in ZG if and only if it can be expressed as a finite union of languages of the form Equivalently, we can say that every language of ZG is a finite union of disjoint shuffles of a singleton language (containing only one word) and of a regular commutative language, where the disjoint shuffle operator interleaves two languages (i.e., it describes the sets of words that can be achieved as interleavings of one word in each language) while requiring that the two languages are on disjoint alphabets.Intuitively, these characterizations are because the syntactic congruence of a ZG language is a ZG-congruence, and Theorem 3.4 tells us that it is refined by an n, p-congruence, whose classes can be expressed as stated.Let us formally prove Corollary 3.5 using Theorem 3.4: Proof of Corollary 3.5.One direction is easy: if a language L is of the prescribed form, then it is a Boolean combination of languages of MNil and regular commutative languages.These languages are in ZG and ZG is closed under Boolean operations, so indeed L is in ZG.
For the converse direction, fix a language L in ZG, and consider the syntactic congruence ∼ of L: it is a ZG-congruence, more specifically a ZG p -congruence for some value p > 0. By Theorem 3.4, there exists n ∈ N such that ∼ is refined by a n, p-congruence ∼ ′ .Now, by definition of the syntactic congruence, the set of words of Σ * that are in L is a union of equivalence classes of ∼, hence of ∼ ′ .This means that L can be expressed as the union of the languages corresponding to these classes.Now, an equivalence class of the n, p-congruence ∼ ′ can be expressed as the shuffle of two languages: the singleton language containing the rare word defining the class, and the language that imposes that all frequent letters are indeed frequent (so the rare alphabet is as required) and that the modulo of their number of occurrences is as specified.The second language is commutative, and the disjointness of rare and frequent letters guarantees that the shuffle is indeed disjoint.
Thus, we have shown that L is a union of disjoint shuffles of a singleton language and a regular commutative language.The form stated in the corollary is equivalent, i.e., it is the shuffle of the singleton language {a 1 • • • a k } and of the commutative language obtained by restricting K to the subalphabet B.
Corollary 3.5 then implies a characterization of the variety of monoids ZG.To define it, we use the join of two varieties V and W, denoted by V ∨ W, which is the variety of monoids generated by the monoids of V and those of W. Alternatively, the join is the least variety containing both varieties.We then have: Corollary 3.6.The variety ZG is generated by commutative monoids and monoids of the form S 1 with S a nilpotent semigroup.In other words, we have: ZG = MNil ∨ Com.
Proof.Clearly ZG contains both Com and MNil.Furthermore, by Corollary 3.5, any language in ZG is a union of intersections of a language in MNil and a language in Com.Hence, it is in the variety generated by these two varieties of languages, concluding the proof.
On a different note, we will also use Theorem 3.4 to show a technical result that will be useful later.It intuitively allows us to regroup and move arbitrary elements: Corollary 3.7.For any monoid M in ZG, letting n ≥ |M | + 1, for any element m of M and elements m 1 , . . ., m n of M , we have Proof.We consider the free monoid M * .Let η : M * → M be the onto morphism defined by η(m) := m for all m ∈ M .Let ∼ be the congruence that η induces over M * , i.e., for u, v ∈ M * , we have u ∼ v if η(u) = η(v).Remark that, as M is in ZG, more specifically in ZG p for some p > 0, the congruence ∼ is a ZG p -congruence by definition.Hence, by Theorem 3.4, ∼ is refined by a n, p-congruence where n = |M | + 1.Now, consider the two words in the equation that we wish to show: they are words of M * .As the letter m over is then a frequent letter, we know that the two words are indeed n, p-congruent, which concludes the proof.
3.2.Proof of Theorem 3.4.Having spelled out the consequences of Theorem 3.4, we prove it in the rest of this section.It crucially relies on a general result about ZG that we will use in several proofs, and which is shown by elementary equation manipulations: Lemma 3.8.Let M be a monoid of ZG, let ω be the idempotent power, and let x, y ∈ M .Then we have: Proof.We show this claim by showing that two equalities establishing that each side of the equation is equal to the same term, namely, x ω y ω (xy) ω .Let us first show the first equality: (xy) ω = x ω y ω (xy) ω . (3.1) To show Equation 3.1, remember that we have (xy) ω = xy(xy) ω−1 from the definition of (xy) ω−1 in the preliminaries.Now, as (xy) ω−1 is central, the right-hand side is equal to x(xy) ω−1 y.By injecting an (xy) ω in the latter, we obtain: Applying this equality ω times gives: Now, we can expand (x(xy) ω−1 ) ω , commuting the (xy) ω−1 to regroup the x into x ω and regroup the (xy) ω−1 into ((xy) ω−1 ) ω which is equal to (xy) ω , so that the first factor of the right-hand side is equal to x ω (xy) ω .By commuting, we obtain Equation 3.1.The second equality is: 2) To show Equation 3.2, note that we have x ω y ω = x ω−1 xy ω−1 y, so by the equation of ZG we get: x ω y ω = x ω−1 y ω−1 xy.Now, we have x ω−1 y ω−1 = x ω−1 x ω y ω−1 y ω , and by the equation of ZG we have: Inserting the second equality in the first, we have: Now, applying this equality ω times gives x ω y ω = (x ω−1 y ω−1 ) ω x ω y ω (xy) ω .As the first factor of the right-hand side is equal to x ω y ω , we get x ω y ω = x ω y ω (xy) ω .This establishes Equation 3.2.
From Equations 3.1 and 3.2, we immediately conclude the proof.
To continue with our proof of Theorem 3.4, thanks to Lemma 3.8, we can now show a kind of "normal form" for ZG-congruences, by arguing that any word can be rewritten to a word where frequent letters are moved to the beginning of the word, without breaking equivalence for the ZG-congruence.This relies on Lemma 3.8 and allows us to get to the notion of n-equivalence.Specifically: Claim 3.9.Let ∼ be a ZG-congruence on Σ.Let n := (|M | + 1) where M is the monoid associated to ∼.Then, for all w ∈ Σ * , for every letter a ∈ Σ which is frequent in w (i.e., |w| a > n), writing w ′ the restriction of w to Σ \ {a}, and writing w ′′ := a |w| a w ′ , we have: w ∼ w ′′ .
Proof.Define n := |M | + 1 as in the claim statement, and let µ : Σ * → M = Σ * /∼ be the morphism associated to ∼. Remark that by definition, for any words u, v, we have Let us take an arbitrary w and a ∈ Σ such that a is frequent in w.We can therefore write we know by the pigeonhole principle that there exist 1 ≤ i < j ≤ m such that x i = x j .Furthermore, we have x j = x i zµ(a) where z = µ(w i+1 a • • • w j ).By applying the equation ω times, we have that x i = x i (zµ(a)) ω .Now, by Lemma 3.8, we have (zµ(a)) ω = z ω µ(a) ω .This is equal to z ω µ(a) ω µ(a) ω , and by now applying Lemma 3.8 in reverse we conclude that (zµ(a)) ω = (zµ(a)) ω µ(a) ω .Finally, we obtain Now, the equation of ZG ensures that µ(a) ω is central, so we can commute it in µ(w) and absorb all occurrences of µ(a) in µ(w), then move it at the beginning, while keeping the same µ-image.Formally, from x i = x i µ(a) ω , we have and we commute µ(a) ω to merge it with all µ(a) and then commute the resulting µ(a) ω+|w| a to obtain µ(a) ω+|w| a w ′ with w ′ as defined in the statement of the claim.Now, remark that for any i > |M |, for any x in M , we have x ω+i = x i .This is because, letting k ≤ |M | be the idempotent power of x, we have By applying this to x = µ(a) and i = |w| a > |M |, we deduce that µ(w) = µ(a) |w| a µ(w ′ ).This establishes that w ∼ w ′′ and concludes the proof.
We can now conclude the proof of Theorem 3.4: Proof of Theorem 3.4.Let ∼ be a ZG p -congruence on Σ * , M its associated monoid, and fix n := |M | + 1 as in the theorem statement.Let u and v be two n, p-congruent words of Σ * , we need to prove that they are indeed ∼-equivalent.Let Σ ′ = {a 1 , . . ., a r } be the subset of letters in Σ that are frequent in u (hence in v, as they are n, p-congruent).By successive applications of Claim 3.9 for every frequent letter in Σ ′ , starting with u, we know that the values |u| a i and |v| a i are greater than n which is ≥ |M |, and they are congruent modulo p, which is a multiple of the period of a i , so we have a . We also know by definition of the n, p-congruence that u |≤n = v |≤n .By compositionality of ∼, all of this establishes that u ∼ v. Thus, the n, p-congruence indeed refines the ∼-congruence, concluding the proof.

Defining ZG * D and LZG, and Result Statement
We have given our characterizations of ZG and presented some preliminary results.We now define LZG p and ZG p * D and show that they are equal (Theorem 1.1), and deduce the same for LZG and ZG * D. ZG p * D and ZG * D. We denote by D the variety of the definite semigroups, i.e., the semigroups satisfying the equation yx ω = x ω .For p > 0, the variety of semigroups ZG p * D is the variety generated by the semidirect products of monoids in ZG p and semigroups in D. We recall for completeness the definition of the semidirect product operator, even though we will not use it directly in this paper.Given two semigroups S and T , a semigroup action of S on T is defined by a map act : S × T → T such that act(s 1 , act(s 2 , t)) = act(s 1 s 2 , t) and act(s, t 1 t 2 ) = act(s, t 1 )act(s, t 2 ).We then define the product • act on the set T × S as follows: for all s 1 , s 2 in S and t 1 , t 2 in T , we have: The set T × S equipped with the product • act is a semigroup called the semidirect product of S by T , denoted T • act S. We then define ZG * D as the variety of semidirect products of monoids in ZG and semigroups in D.
Remark that the * operation is equivalent to the wreath product of varieties.We further note for the expert reader that we could equivalently replace D by the variety LI of locally trivial semigroups.We refer to [Str85] for a detailed presentation on this subject.
LZG p and LZG.Last, we introduce the varieties LZG p and LZG.For p > 0, the variety LZG p is the variety of semigroups S such that, for every idempotent e of S, the subsemigroup eSe of elements that can be written as ese for some s ∈ S is in ZG p .Note that this subsemigroup is actually a monoid, called the local monoid of e, and that its identity is e.The variety LZG is defined analogously but for ZG, and clearly LZG = p>0 LZG p .Remark that a semigroup is in LZG iff it satisfies the following equation: for any x, y and z in S, we have: . This incidentally shows by Reiterman's theorem that LZG is indeed a variety of semigroups.
Main result.Our main result, stated in Theorem 1.1, is that, for any p > 0, the varieties ZG p * D and LZG p are actually equal.In particular, for p = 1, we get that MNil * D = LMNil.
Let us first remark that Theorem 1.1 implies Corollary 1.2 stated in the introduction, namely, that LZG = ZG * D: Proof of Corollary 1.2.Any semigroup in LZG is in LZG p for some p, hence in ZG p * D by locality of ZG p * D, hence in ZG * D. Conversely, by definition of ZG * D being a variety, each semigroup S of ZG * D is obtained by applying the quotient, subsemigroup, and product operators to semigroups S 1 , . . ., S k for some k ∈ N, where each S i is a semidirect product of a monoid in ZG p i for a certain p i > 0 and of a semigroup in D. Letting p := 1≤i≤k p i , all semigroups S 1 , . . ., S k are then in ZG p * D, and applying the operators then witnesses that S also belongs to ZG p * D. By locality of ZG p * D, we know that S belongs to LZG p , hence to LZG.
Thus, fixing the value p > 0 for the rest of this paper, the only remaining task is to prove Theorem 1.1 on LZG p and ZG p * D. Note that we can freely use all equational results shown about monoids of ZG (e.g., Lemma 3.8), as they also hold for monoids in ZG p .
To prove Theorem 1.1, we will first present the general framework of Straubing's delay theorem in the next section and show the easy inclusion ZG p * D ⊆ LZG p , before moving on with the rest of the proof.

Straubing's Delay Theorem
To show our main result, we use Straubing's delay theorem from [Str85].We first give some prerequisites to recall this result.To this end, let us first define a general notion of finite category: ) Further, this composition law must be associative.What is more, we require that for any object o, there exists an arrow in C o,o which is the identity for all elements that it can be combined with (note that these arrows are in particular unique).
We now define the notion of category of idempotents of a semigroup: Definition 5.2 (Category of idempotents).Let S be a semigroup.The category of idempotents S E of S is the finite category defined as follows: • The objects of S are the idempotents of S.
• For any idempotents e 1 and e 2 and any element x of S such that x ∈ e 1 Se 2 , we have an arrow labeled by x going from e 1 to e 2 , which we will denote by (e 1 , x, e 2 ).Formally, C e 1 ,e 2 = {(e 1 , x, e 2 ) | x ∈ e 1 Se 2 }.The composition law of the category is (e 1 , x, e 2 )(e 2 , y, e 3 ) = (e 1 , xy, e 3 ).Note that it is clearly associative thanks to the associativity of the composition law on S. The identity element in C e,e for an idempotent e is simply (e, e, e).
Let us now study S E in more detail.We denote by B := {(e 1 , x, e 2 ) | x ∈ e 1 Se 2 } the set of arrows of the category of idempotents.
A path of S E is a nonempty word of B * whose sequence of arrows is valid, i.e., the ending object of each arrow except the last one is equal to the starting object of the next arrow.Because S E is a category, each path is equivalent to an element of the category, i.e., composing the arrows of the path according to the composition law of the category will give one arrow of the category, whose starting and ending objects will be the starting object of the path (i.e., that of the first arrow) and the ending object of the path (i.e., of the last arrow).Two paths are coterminal if they have the same starting and ending object.Two paths π 1 and π 2 are S E -equal if they evaluate to the same category element, which we write π 1 ≡ π 2 .Note that if two paths are S E -equal then they must be coterminal.A loop is a path whose starting and ending objects are the same.
A congruence on B * is an equivalence relation ∼ over B * that satisfies compositionality as previously defined.Note that the relation is also defined on words of B * that are not valid, i.e., that do not correspond to paths; the compositionality requirement also applies to such words.Definition 5.3 (Compatible congruence).A congruence ∼ on B * is said to be compatible with S E if for any two coterminal paths π 1 and π 2 of S E such that π 1 ∼ π 2 , we have π 1 ≡ π 2 .In other words, ∼ is compatible with S E iff, on words of B * that are coterminal paths, it refines S E -equality.
Recall the notion of a ZG p -congruence from Section 2. We are now ready to state Straubing's delay theorem, which was introduced in [Str85] and rephrased in [Til87].The theorem applies to any variety, but we state it specifically for ZG p for our purposes.The theorem gives us an alternative characterization of ZG p * D: Theorem 5.4 (Straubing's delay theorem, Theorem 5.2 of [Str85]).A semigroup S is in ZG p * D iff, writing S E the category of idempotents of S and B its set of arrows, there exists a ZG p -congruence on B * which is compatible with S E .
Using our notion of n, p-congruence, via Claim 3.3 and Theorem 3.4, we rephrase it again: Corollary 5.5.A semigroup S is in ZG p * D iff, writing S E and B as above, there exists an n, p-congruence on B * which is compatible with S E .
Before moving on to the full proof of our main theorem (Theorem 1.1), we conclude the section by noticing that the Straubing delay theorem implies the easy direction of our result, namely, if L is in ZG p * D then L is in LZG p .This easy direction follows directly from [Til87], but let us provide a self-contained argument: Claim 5.6.We have ZG p * D ⊆ LZG p .
Proof.If S is in ZG p * D, then by Theorem 5.4, there exists a ZG p -congruence ∼ compatible with S E .Let us now show that S is in LZG p by showing that, for any idempotent e, the local monoid eSe is in ZG p .Let e be an idempotent.By definition of S E , the local monoid eSe is isomorphic to the subset of arrows of S E going from e to e, with their composition law.Let us denote this subset by B e .Define ∼ e to be the specialization of the relation ∼ to B e .Remark that M = B * e /∼ e is a submonoid of B * /∼, and is hence in ZG p because B * /∼ is, and ZG p is a variety.Remark that since all words in B * e are valid paths in S E , the local monoid N := eSe defines a congruence ∼ 2 over B * e where two paths are equivalent if they evaluate to the same monoid element.We know that ∼, hence ∼ e , refines this congruence ∼ 2 .Hence, N is a quotient of M .Thus, eSe is a quotient of B * e /∼ e , which is a submonoid of a monoid in ZG p , concluding the proof.
In the rest of this paper, we show the much harder direction, i.e., if S is in LZG p then S is in ZG p * D. To prove this, using Corollary 5.5, it suffices to show: Claim 5.7.Let S be a semigroup of LZG p , write S E its category of idempotents and B the set of arrows of S E .There exists an integer n > 0 such that the n, p-congruence on B * is compatible with S E .This result then implies, by our rephrasing of Straubing's result (Corollary 5.5), that S is in ZG p * D. So in the rest of this paper we prove Claim 5.7.The proof is structured in three sections.First, in Section 6, we carefully choose the threshold n of the n, p-congruence to be "large enough" so that we can enforce a gap between the number of occurrences of the rare and frequent arrows according to the n, p-congruence, also ensuring a strong connectedness property on the category of idempotents.Second, in Section 7, we show auxiliary results about paths in the category of idempotents, using the ZG equation and the properties of the threshold.Third, in Section 8, we conclude the proof, doing first an outer induction on the total number of rare arrow occurrences, and then an inner induction on the number of frequent arrows, using a so-called ear decomposition of the category.

Choosing the Threshold of the Congruence
In this section, we explain how to choose the threshold n to prove Claim 5.7.Our threshold will enforce a large enough "gap" between the total number of occurrences of the rare letters and the number of occurrences of the frequent letters.This is called a distant threshold and will be useful in the rest of the argument.
This section is split into two subsections.In the first subsection, we formally define the notion of a distant rare-frequent threshold, and show how such a threshold can be used to find factors with no rare letters and a large number of copies of a frequent letter.We further explain that we can indeed find a sufficiently distant rare-frequent threshold.This is a generic result on words and alphabets that does not depend on ZG or on the category of idempotents.In the second subsection, we instantiate this result for paths in the category of idempotents, and explain how a distant rare-frequent threshold incidentally ensures a strong connectedness property on the category.This last subsection focuses on the category of idempotents, but is also generic in the sense that it does not use the ZG equation.Hence, all of the present section applies to arbitrary semigroups.6.1.Finding sufficiently distant thresholds.We now give our formal definition of a distant rare-frequent threshold: Definition 6.1.For Σ an alphabet, u ∈ Σ * , and m > 0, we say that an integer n > 0 is an m-distant rare-frequent threshold for u if, letting Σ r := {a ∈ Σ | |u| a ≤ n} be the rare alphabet of u for n, then the total number of occurrences of rare letters in u is less than a proportion 1/m of the threshold n, minus one.Formally: a∈Σr |u| a ≤ n m − 1.Note that if n > 0 is an m-distant rare-frequent threshold for u, then it is in particular an m ′ -distant rare-frequent threshold for any 0 < m ′ ≤ m.
If a word has a distant rare-frequent threshold, then any frequent letter can be found in sufficiently many occurrences in some factor containing no rare letter.This will be useful in pumping arguments, and is the motivation for the definition.Formally: Lemma 6.2.For any alphabet Σ and m > 0, if a word u ∈ Σ * has an m-distant rare-frequent threshold, then for any frequent letter a, the word u has a factor containing no rare letter and containing at least m + 1 occurrences of a.
Proof.As a is a frequent letter, by definition, its number |u| a of occurrences in u is such that |u| a > n.Let r := a∈Σr |u| a be the total number of occurrences of the rare letters.The definition of an m-distant rare-frequent threshold ensures that r ≤ n m − 1.Thus, r + 1 ≤ n m .
Multiplying by m, we obtain (r + 1)m ≤ n.Thus, |u| a > (r + 1)m.As there are r rare letters in total, there are r + 1 subwords between them containing no rare letter, so the inequality implies that one of them contains > m occurrences of a, i.e., ≥ m + 1 occurrences of a.This concludes the proof.
We now intuitively state the existence, for any m > 0, of an m-distant rare-frequent threshold that can be used for any word u.The precise claim is more complicated to phrase, as we cannot pick one n which can serve as a m-distant rare-frequent threshold for any word u.Indeed, for any choice of n, there will always be words u where the number of rare letter occurrences happens to be close to n.However, we can pick a large enough n such that, given any word u, we can pick some 0 < n ′ ≤ n as an m-distant rare-frequent threshold for u.We will state the claim more generally about picking a threshold for a pair of words u 1 and u 2 .
Here is the formal claim.We repeat that this result is a general claim about words, which is not specific to ZG. Lemma 6.3.For any alphabet Σ and m > 0, there exists an integer n > 0 ensuring the following: for any words u 1 , u 2 ∈ Σ * , there exists an integer n ′ with 0 < n ′ ≤ n which is an m-distant rare-frequent threshold for u 1 and for u 2 .
Let us now prove Lemma 6.3 in the rest of this subsection.We first show an abstract result capturing the essence of the underlying pigeonhole principle argument: Claim 6.4.For any d > 0 and m ′ > 0, there exists an integer n ≥ m ′ ensuring the following: for any d-tuple T of integers, there exists an integer n ′ with m ′ ≤ n ′ ≤ n such that i∈F T i ≤ n ′ m ′ , where F = {i | T i ≤ n ′ }.Intuitively, the value m ′ will be computed from m to ensure the "minus one" gap in Definition 6.1, the "dimension" d will be the cardinality of the alphabet Σ (multiplied by 2 as we consider two words), the integer n is the threshold that we will choose, and n ′ is the value that we wish to obtain.Let us prove Claim 6.4: Proof of Claim 6.4.Let us take n := (m ′ d) d+2 , which ensures n ≥ m ′ .The candidate values of n ′ that we will consider are intuitively the following: m ′ d, (m ′ d) 2 , . . ., (m ′ d) d+2 .Now take any d-tuple T .For any 1 Applying the pigeonhole principle on the cardinalities of these sets, there are 1 Let us set n ′ := (m ′ d) j .By construction, we have n ′ ≥ m ′ .Now, consider the sum With Claim 6.4, it is now easy to show Lemma 6.3: Proof of Lemma 6.3.Let n be the value given by Claim 6.4 when taking d := 2 |Σ| and m ′ := (m + 1)m.
Let us consider any pair of words u 1 , u 2 ∈ Σ * .Let T be the d-tuple of the letter occurrences of u 1 , followed by those of u 2 .The statement of Claim 6.4 ensures that there exists an integer n ′ with n ′ ≥ m ′ > m > 0 such that, when using n ′ as the rare-frequent threshold, the total number of rare letters in u 1 plus in u 2 is ≤ n ′ m ′ .Now, let us show that n ′ m ′ ≤ n ′ m − 1.To this end, as m ′ = m(m + 1), first note that and check that it is nonnegative.This difference evaluates to n ′ −m(m+1) m(m+1) .Now, we have Combining the conclusions of the two previous paragraphs, we obtain that the total number of rare letters u 1 plus in u 2 is ≤ n ′ m − 1.So the same is true of the rare letters in u 1 , and of the rare letters in u 2 .By contrast, the frequent letters in u 1 occur > n ′ times by definition, and the same is true of the frequent letters in u 2 .Hence, by Definition 6.1, the value n ′ is an m-distant rare-frequent threshold for u 1 and for u 2 , concluding the proof.Thus, we have shown that, for any alphabet size and desired distance m, we can pick a value n ensuring that for any two words we can use some 0 < n ′ ≤ n as an m-distant rare-frequent threshold for them.6.2.Choice of threshold and resulting properties.In the rest of this section, we instantiate the generic argument of the previous section to the choice of an arbitrary semigroup S and its category of idempotents S E : we claim the existence of a suitably distant rare-frequent threshold, and observe that it additionally ensures the strong connectedness of the category.However, the argument is still generic in the sense that it applies to an arbitrary semigroup S, even if it is not in ZG.
Let us first rephrase Lemma 6.3 to this setting by picking as alphabet the arrows B of the category of idempotents S E of S and by choosing m := |S|.We immediately obtain: Claim 6.5.Let S be a semigroup and let S E be its category of idempotents.There exists an integer n > 0 ensuring the following: for any paths u 1 , u 2 in S E , there is 0 < n ′ ≤ n which is a |S|-distant rare-frequent threshold for u 1 and for u 2 .
The rephrasing of Lemma 6.2 is: Claim 6.6.If a path u in S E has an |S|-distant rare-frequent threshold, then for any frequent arrow a, the path u has a factor containing no rare arrow and containing at least m + 1 occurrences of a.
We now close the section by observing that having an m-distant rare-frequent threshold for a path w, indeed having simply an 1-distant rare-frequent threshold for w, enforces a strong connectedness property on the category.Specifically, the set of frequent arrows in this path for this threshold must form a so-called union of strongly connected components (SCCs): Definition 6.7.Given S E and a subset B ′ of its set of arrows B, we say that B ′ is a union of SCCs if, letting G be the directed graph on the objects of S E formed of the arrows of B ′ , then all connected components of G are strongly connected.Claim 6.8.Fix S and S E and B, let w ∈ B * be a path of S E , and let n ′ > 0 be a 1-distant rare-frequent threshold of w.Then the set of frequent arrows of w for n ′ is a union of SCCs.
Proof.Consider G the directed graph of Definition 6.7.Let us assume by way of contradiction that G has a connected component which is not strongly connected.This means that there exists an edge (u, v) of G such that there is no path from u to v in G. Consider any frequent arrow a in S E achieving the edge (u, v) of G.
As a is frequent in w, we know that a occurs strictly more than n ′ times in w, hence w contains at least n ′ return paths, i.e., paths from the ending object v of a back to the starting object u of a.As there is no path from v to u in G, each one of these paths must contain an arrow of B which is rare in w.
Hence, the total number of rare arrows in w is at least n ′ .But the 1-distant rare-frequent threshold condition imposes that the total number of rare arrow occurrences in w is ≤ n ′ − 1.We have thus reached a contradiction.

The Loop Insertion and Prefix Substitution Lemmas
We now show two auxiliary results on the category of idempotents of LZG semigroups, to be used in the sequel.The first result is the loop insertion lemma: it allows us to insert any loop of frequent arrows to the power ω without affecting equivalence.The second is the prefix substitution lemma: it allows us to replace a prefix of frequent arrows by another, without affecting equivalence, up to inserting a loop later in the path.
The results shown in this section hold for semigroups in LZG, hence for those in LZG p for any p > 0. Thus, let us fix a semigroup S in LZG.Recall that S E denotes the category of idempotents of S, and denote by B the set of arrows of S E .
Remember that, by definition of the category of idempotents S E , for any idempotent e of S, the set of loops with starting and ending object e under the product law of the category forms a monoid which is isomorphic to the local monoid eSe of S. As we know that S is in LZG, all its local monoids are in ZG.Hence the ZG equation immediately applies to loops in the category of idempotents, which we will often use in the results of this section: Claim 7.1.Let x and y be two coterminal loops of S E , let k ∈ Z, and let ω be an idempotent power of S. We have: x ω+k y ≡ yx ω+k .7.1.Loop insertion lemma.The loop insertion lemma allows us, when we have a sufficiently distant rare-frequent threshold n ′ , to insert any arbitrary loop raised to the power ω without changing the category element to which a path evaluates.We also show that this change does not affect n ′ , ω-equivalence: this will suffice to preserve n ′ , p-equivalence (where p is the period of S), which will be useful later (we come back to this at the beginning of Section 8).Formally: Lemma 7.2 (Loop insertion lemma).Let π be a path, and assume that n ′ is an |S|-distant rare-frequent threshold for π.Let π = rt be a decomposition of π (with r or t possibly empty), let o be the object between r and t (i.e., the ending object of r, or the starting object of t if r is empty), and let π ′ be a loop on o that only uses frequent arrows.Then π ≡ r(π ′ ) ω t. (Note that these two paths are also n ′ , ω-equivalent by construction.) In the rest of this subsection, we show Lemma 7.2.We first rephrase the claim to the following auxiliary result: Claim 7.3.Let π be a path, and assume that n ′ is an |S|-distant rare-frequent threshold for π.Let π = rt be a decomposition of π and o be the object between r and t.Let X be the set of elements of the local monoid on o that can be achieved as some loop q x of frequent arrows raised to the power ω: formally, X is the set of elements x ∈ S such that there is a loop q x of frequent arrows such that q ω x evaluates to (o, x, o), noting that this implies that x is idempotent.Then letting q := x∈X q ω x , we have that π ≡ rqt.(Note that these two paths are also n ′ , ω-equivalent by construction.)Intuitively, in this claim, X stands for the set of elements of S that we can achieve as a loop on o raised at the power ω and using frequent arrows only.The claim states that inserting loops of this form at o to achieve all such elements x will preserve equivalence.
We first explain why Claim 7.3 implies Lemma 7.2.Indeed, when taking p = rt, letting o be the object between r and t, and taking r(π ′ ) ω t, the sets X defined in Claim 7.3 after the occurrence of r in p = rt and r(π ′ ) ω t will be the same for both paths (because X only depends on o).Thus, Claim 7.3 implies that there is a loop q such that rt ≡ rqt and r(π ′ ) ω t ≡ rq(π ′ ) ω t.Now, as (π ′ ) ω must correspond to an arrow of the form (o, x, o) for x ∈ X, it must be the same idempotent as one of the idempotents achieved by one of the loops in the definition of q, and as the local monoid is in ZG these idempotents commute and q ≡ q(π ′ ) ω .Hence, we have rqt ≡ rq(π ′ ) ω t.We know that rqt ≡ rt, and rq(π ′ ) ω t ≡ r(π ′ ) ω t.Thus we obtain rt ≡ r(π ′ ) ω t.Thus, Lemma 7.2 is proved once we have shown Claim 7.3.
Hence, all that remains is to show Claim 7.3.We will do so by establishing a number of claims.
We first show that, for any frequent arrow x, we can insert some loop of the form xu where u is a return path using only frequent arrows, while preserving equivalence.This uses the notion of distant rare-frequent threshold; specifically, this is where we perform the pumping made possible by Claim 6.6.
Claim 7.4.Let π = rt be a path with an |S|-distant rare-frequent threshold, let o be the object between r and t, and let x be any frequent arrow starting at o. Then we have π ≡ r(xu) ω t for some return path u using only frequent arrows.
Proof.As x is a frequent arrow and π has an |S|-distant threshold, we know by Claim 6.6 that π contains a factor ρ that contains only frequent arrows and contains k > |S| occurrences of x.This provides a decomposition of ρ in the form: By the pigeonhole principle, there exists i < j such that ρ Hence, iterating, we obtain: Moving the ω, we get: This proves that ρ and h(xu) ω g achieve the same category element when taking u := By compositionality, π and h ′ (xu) ω g ′ achieve the same category element, where h ′ is the part of π preceding ρ followed by h, and g ′ is g followed by the part of π following ρ.Now, recall that we must show the result for our decomposition π = rt, where the object o between r and t is the starting object of the arrow x and the ending object of h.Either h ′ is a prefix of r, or vice-versa.Assume first that we are in the first case, so h ′ = rw for some path w.Then, w and (xu) ω belong to the local monoid of o which is in ZG.Since idempotents commute with all elements, we have w(xu) ω ≡ (xu) ω w establishing that rw(xu) ω g ′ ≡ r(xu) ω wg ′ ≡ r(xu) ω t since wg ′ = t.The other case is symmetrical.This concludes the proof of Claim 7.4.following, where q ′ 1 , . . ., q ′ k are the loops q ′ on o of frequent arrows obtained by the statement of Corollary 7.6: ) ω t Note that the left-hand-side and right-hand-side are also n ′ , ω-equivalent.Now, since the q ′ i are loops on o consisting of frequent arrows, each (q ′ i ) ω evaluates to (o, x, o) for some x ∈ X.As the elements of X are in the local monoid of o which is in ZG, commuting the loops using Claim 7.1, we can combine each (q ′ i ) ω with some q ω j such that (q ′ i ) ω ≡ q ω j , hence (q ′ i ) ω q ω j = q ω j .Thus, we get that rt is n ′ , ω-equivalent to, and evaluates to the same category element as, the path: This concludes the proof of Claim 7.3, and thus establishes our desired result, Lemma 7.2.
7.2.Prefix substitution lemma.The prefix substitution lemma allows us to change any prefix of frequent arrows of a path, up to inserting a loop of frequent arrows elsewhere: Lemma 7.7.Let π = xry be a path, and assume that n ′ is an |S|-distant rare-frequent threshold for π.Let x ′ be a path coterminal with x.Assume that every arrow in x and in x ′ is frequent.Assume that some object o in the SCC of frequent arrows of the starting object of r occurs again in y, say as the intermediate object of y = y 1 y 2 .Then there exists y ′ = y 1 y ′′ y 2 for some loop y ′′ consisting only of frequent arrows such that π ≡ x ′ ry ′ and such that π and x ′ ry ′ are n ′ , ω-equivalent.
This lemma uses Claim 6.8 to argue that frequent arrows are a union of SCCs.Its proof relies on the loop insertion lemma (Lemma 7.2), but with extra technical work using the ZG equation.
To prove Lemma 7.7, we will first show that frequent loops can be "recombined" without changing the category image, simply by equation manipulation: Claim 7.8.For x, x ′ two coterminal paths in S E and y, y ′ coterminal paths in S E such that xy and x ′ y ′ are valid loops, we have: Proof.Let us first show that: To show Equation 7.1, first rewrite (xy) ω as x(yx) ω−1 y and likewise for (y ′ x ′ ) ω , to get: Then, we use Claim 7.1 to move (yx) ω−1 , so the above evaluates to the same category element as: We again rewrite (yx) ω−1 to y(xy) ω−2 x, yielding: We again use Claim 7.1 to move (xy) ω−2 , merge it with the prefix xy, and move it back to its place, yielding: We rewrite (y ′ x ′ ) ω−1 to y ′ (x ′ y ′ ) ω−2 x ′ , yielding: Again by Claim 7.1, we can merge (x ′ y ′ ) ω−1 with x ′ y ′ and move it to finally get: Thus, the left-hand side of Equation 7.1 evaluates to the same category element as the right-hand side, and we have shown Equation 7.1.Now, we have (xy) ω (x ′ y ′ ) ω ≡ (xy) 2ω (x ′ y ′ ) 2ω , so using Claim 7.1 again, Equation 7.1 gives: (xy We can now use Equation 7.1 to replace (xy) ω (x ′ y ′ ) ω by the right-hand side of Equation 7.1 and use Claim 7.1 to commute, yielding: By definition we have (xy Injecting these in the equation above, we get: Note that (⋆) is now equal to the left-hand-side of the equation.Substituting ω times the right-hand-side into (⋆), we obtain: As these elements commute (thanks to Claim 7.1), we have shown the desired equality.
We will now extend this result to show that we can change the initial part of a path, even if it is not a loop, provided that there is a coterminal path under an ω-power with which we can swap it.Claim 7.9.For x, x ′ two coterminal paths in S E and y, y ′ coterminal paths in S E such that xy and x ′ y ′ are valid loops, and for any path t coterminal with y, the following equation holds: We establish this again by equation manipulation.
Proof of Claim 7.9.We apply Claim 7.8 to show the following equality about the left-hand side: ) ω By commutation of (x ′ y) ω thanks to Claim 7.1, the right-hand side evaluates to the same category element as: By commutation of (xy) ω and expanding it to x(yx) ω−1 y, we get: Combining (yx) ω−1 with what precedes and follows, we get: By expanding (x ′ y ′ ) ω = x ′ (y ′ x ′ ) ω−1 y ′ , and commuting (yx ′ ) ω−1 and (yx) ω+1 , we get: so we get: Commuting (y ′ x ′ ) ω−1 and doing a similar transformation, we get: Now, expanding (yx) ω+1 , we get: Commuting (x ′ y) ω−1 and merging it with x ′ y, we get: so applying commutation we get: Now, applying Claim 7.8 in reverse (using commutation again), we can obtain: Then commuting (x ′ y ′ ) ω and merging it yields: A final commutation of (x ′ y ′ ) ω−1 yields the desired right-hand side, and we have preserved equivalence in the category of idempotents, establishing the result.With Claim 7.9 in hand, and using Lemma 7.2, we can now prove Lemma 7.7: Proof of Lemma 7.7.As n ′ is an |S|-distant rare-frequent threshold, it is in particular a 1-distant rare-frequent threshold, so we know by Claim 6.8 that the frequent arrows occurring in π are a union of SCCs.Thus, there is a return path s for x ′ (i.e., x ′ s is a loop, hence xs also is) where s only consists of frequent arrows.
By our hypothesis on the starting object of r, we can decompose y = y 1 y 2 such that the ending object of y 1 and starting object of y 2 is an object o which is in the SCC of frequent arrows of the starting object o ′ of r.Let ρ 1 be any path of frequent arrows from o to o ′ , and ρ 2 be any path of frequent arrows from o ′ to o.Now, take π ′ to be the loop ρ 1 s(xs) ω (x ′ s) ω xρ 2 : note that all arrows of π ′ are frequent.Hence, by Lemma 7.2, xry evaluates to the same category element as, and is n ′ , ω-equivalent to, By unfolding the power ω, we get the following: where we write z := ρ 2 (s(xs) ω (x ′ s) ω x) ω−1 y 2 for convenience.We can therefore apply Claim 7.9 to obtain that: What is more, these two paths are clearly n ′ , ω-equivalent, as they only differ in terms of frequent arrows (all arrows in x and x ′ being frequent) and the number of these arrows modulo ω is unchanged by the transformation.This path is of the form given in the statement, taking y ′ := y 1 ρ 1 s(xs) ω (xs)(x ′ s) ω−1 xz from which we can extract the right y ′′ .This concludes the proof.8. Concluding the Proof of the Main Result (Theorem 1.1) We are now ready to prove the second direction of Theorem 1.1, namely Claim 5.7.Let us fix the semigroup S in LZG p , write S E its category of idempotents, and write B for the set of arrows of S E .Let p ′ be the period of S: we know that p ′ divides the idempotent power ω of S. Further, p ′ divides p: this is because, for any group element x of S, we have that x belongs to the local monoid x ω Sx ω , hence it belongs to ZG p and its period divides p, thus p ′ is a multiple of the periods of all group elements, hence it divides p.
Let n be given by Claim 6.5.Our goal is to show that the n, p-congruence on B * is compatible with S E .We will in fact show the same for the n, p ′ -congruence, which is coarser than the n, p-congruence because p ′ divides p (using Claim 3.2), so suffices to establish the result.
To do so, we will show that two coterminal paths that are n, p ′ -equivalent must evaluate to the same category element, by two nested inductions.We first explain the outer induction, which is on the number of rare arrows in the paths, for an |S|-distant rare-frequent threshold n ′ ≤ n chosen from the two paths that we consider (via Claim 6.5).The threshold n ′ is not fixed from the beginning but it depends on the two paths considered, which is why we will not fix it in the inductive claim.However, we will only apply the claim to one value of n ′ chosen from the initial paths, i.e., it will not change during the induction.
Formally, we show by induction on the integer r the following: Claim 8.1 (Outer inductive claim on r).For any two paths π 1 and π 2 , for any |S|-distant rare-frequent threshold n ′ for π 1 and π 2 , if π 1 and π 2 are n ′ , p ′ -equivalent and contain r rare arrows each, then we have π 1 ≡ π 2 .
Once we have established this, we can conclude the proof of Claim 5.7.To do so, take any two coterminal paths π 1 and π 2 that are n, p ′ -equivalent.By Claim 6.5, we can pick a threshold n ′ (depending on u 1 , u 2 , and n) such that 0 < n ′ ≤ n which is an |S|-distant rare-frequent threshold for π 1 and π 2 .By Claim 3.2, as π 1 and π 2 are n, p ′ -equivalent, we know that they are also n ′ , p ′ -equivalent.Now that we have fixed the threshold n ′ , following Definition 3.1, we call an arrow of B rare in u 1 and u 2 if it occurs ≤ n ′ times in each, and frequent otherwise.Let r 0 be the number of rare arrows in u 1 and u 2 : this number is the same for both, because they are n ′ , p ′ -equivalent.We now apply the outer inductive claim (Claim 8.1) on π 1 , π 2 , n ′ , and r = r 0 , to conclude that π 1 ≡ π 2 , which concludes the proof of Claim 5.7.
It remains to show Claim 8.1, which we do in the rest of the section.
8.1.Outer base case (B): all arrows in π 1 and π 2 are frequent.We now show Claim 8.1.The base case of the outer induction is for paths that contain no rare arrows: Claim 8.2.For any two paths π 1 and π 2 , for any |S|-distant rare-frequent threshold n ′ for π 1 and π 2 , if π 1 and π 2 are n ′ , p ′ -equivalent and contain no rare arrows, then we have π 1 ≡ π 2 .4:23 We prove this result by an induction over the number of different arrows that occur in the paths π 1 and π 2 , noting that thanks to n ′ , p ′ -equivalence an arrow occurs in π 1 iff it occurs in π 2 .Specifically, we show by induction on the integer f the following: Claim 8.3 (Inner inductive claim on f ).For any two paths π 1 and π 2 , for any |S|-distant rare-frequent threshold n ′ for π 1 and π 2 , if π 1 and π 2 are n ′ , p ′ -equivalent and contain no rare arrows and there are ≤ f different frequent arrows that occur, then we have π 1 ≡ π 2 .
Once we have established this, we can conclude the proof of the base case of the outer induction, Claim 8.2.To do so, take any two coterminal paths π 1 and π 2 and an |S|-distant rare-frequent threshold n ′ such that π 1 and π 2 are n ′ , p ′ -equivalent, let f 0 be the number of frequent arrows that occur in π 1 and in π 2 , and conclude using Claim 8.3 with π 1 , π 2 , n ′ , and f = f 0 .
We now explain the proof of the inner inductive claim (Claim 8.3), before moving on to the inductive case of the outer induction.The base case of Claim 8.3 with f = 0 is trivial as π 1 and π 2 are then empty.For the induction step, assume that the claim holds for any π 1 , π 2 , and n ′ such that there are ≤ f different frequent arrows that occur.Fix π 1 , π 2 , and n ′ where there are ≤ f + 1 frequent arrows that occur.Consider the multigraph G of all arrows of S E that occur in π 1 and π 2 : G has ≤ f + 1 edges.If it has ≤ f edges we immediately conclude by induction hypothesis, so assume it has exactly f + 1 edges.Recall that G is strongly connected: indeed, as all arrows are frequent, thanks to the existence of the |S|-distant rare-frequent threshold n ′ (which is in particular 1-distant), we know by Claim 6.8 that G is a union of SCCs.Further, π 1 (or π 2 ) is a path where all edges of G occur, so it witnesses that G is connected, and G is therefore strongly connected.The induction case is shown using a so-called ear decomposition result on strongly connected multigraphs: Lemma 8.4 [BJG08].Let G be a strongly connected nonempty directed multigraph.We have: , where all vertices v 1 , . . ., v n are pairwise distinct, such that all intermediate vertices v 2 , . . ., v n−1 only occur in the edges of the cycle, and such that the removal of the cycle leaves the graph strongly connected (note that the case n = 1 corresponds to the removal of a self-loop); or • G contains a simple path v 1 → • • • → v n with n ≥ 2 where all vertices are pairwise distinct, such that all intermediate vertices v 2 , . . ., v n−1 only occur in the edges of the path, and such that the removal of the path leaves the graph strongly connected (note that the case n = 2 corresponds to the removal of a single edge).
This is a known result [BJG08], but we give a self-contained proof in Appendix A for the reader's convenience.
Thanks to this result, we can distinguish three cases in the inner induction step: if G is non-empty, it must be a simple cycle, contain a removable simple cycle, or contain a removable simple path.We first give a high-level view of the argument in each case: Proof sketch.The first case (B.1) is when G is a simple cycle.In this case n ′ , p ′ -equivalence ensures that the cycle is taken by π 1 and π 2 some number of times with the same remainder modulo p ′ , so they evaluate to the same element because p ′ is a multiple of the period.
The second case (B.2) is when G contains a removable simple cycle.This time, we argue as in the previous case that the number of occurrences of the cycle must have the same remainder, and we can use Corollary 3.7 to merge all the occurrences together.However, to eliminate them, we need to use Lemma 7.7, to modify π 1 and π 2 to have the same prefix (up to and including the cycle occurrences), while preserving equivalence.This allows us to consider the rest of the paths (which contains no occurrence of the cycle), apply the induction hypothesis to them, and conclude by compositionality.A technicality is that we must ensure that removing the common prefix does not make some arrows insufficiently frequent relative to the distant rare-frequent threshold.We avoid this using Lemma 7.2 to insert sufficiently many copies of a suitable loop.
The third case (B.3) is when G contains a removable simple path τ .The reasoning is similar, but we also use Lemma 7.2 to insert a loop involving a return path for τ and a path that is parallel to τ (i.e., does not share any arrows with it).The return path in this loop can then be combined with τ to form a loop, which we handle like in the previous case.
We now give the detailed argument for each case.
Case B.1: G is a simple cycle.If G is a simple cycle, then distinguish the starting object of π (hence, of π 2 ) as o, and let α be the cycle from o to itself, and τ the path from o to the common ending object of π 1 and π 2 .We have: π 1 = α n 1 τ and π 2 = α n 2 τ with n 1 and n 2 being ≥ n ′ − 1 and having the same remainder r modulo p ′ .We use the loop insertion lemma (Lemma 7.2) to insert α ω : the lemma tells us that π 1 and π 2 respectively evaluate to the same category element as π ′ 1 = α ω+n 1 and π ′ 2 = α ω+n 2 .Further, π 1 and π ′ 1 , and π 2 and π ′ 2 , are n ′ , p ′ -equivalent.
As α is a loop on the idempotent o, we know that there exists an element m ∈ oSo . Now, we have m ω+n 1 = m ω+k 1 •p ′ +r and m ω+n 2 = m ω+k 2 •p ′ +r where k 1 and k 2 are the respective quotients of n 1 and n 2 in the Euclidean division by p ′ and where r is the common remainder modulo p ′ .By definition of the period p ′ , we have m ω+n 1 = m ω+r and m ω+n 2 = m ω+r .We conclude that m ω+n 1 = m ω+n 2 , so that π ′ 1 ≡ π ′ 2 , and π 1 ≡ π 2 .This concludes case B.1.
Case B.2: G has a simple cycle.Recall that, in this case, we know that G has a simple cycle whose intermediate objects have no other incident edges and such that the removal of the simple cycle leaves the graph strongly connected.Let α be the simple cycle, starting from the only object o of the cycle having other incident edges.We can then decompose π 1 and π 2 to isolate the occurrences of the simple cycle (which must be taken in its entirety), i.e.: This ensures that the edges of α do not occur elsewhere than in the α factors, except possibly in x 1 , y 1 and in x t , y t ′ if the paths π 1 and/or π 2 start and/or end in the simple cycle.This being said, in that case, we know that the prefixes of π 1 and π 2 containing this incomplete subset of the cycle must be equal (same sequence of arrows), and likewise for their suffixes.For this reason, it suffices to show the claim that π 1 and π 2 evaluate to the same category element under the assumption that both their starting and ending objects are not intermediate vertices of the cycle.The claim then extends to the general case, by adding the common prefixes and suffixes to the two paths that satisfy the condition, using compositionality of the congruence.Thus, in the rest of the proof for this case, we assume that the edges of α only occur in the α factors.are coterminal, n ′ , p ′ -equivalent because π 1 and π 2 were, where the frequent letters that are used are a strict subset of the ones used in π 1 and π 2 , and where all other frequent letters occur sufficiently many times for n ′ to still be an |S|-distant rare-frequent threshold (as guaranteed by β n ′′ ω ).Thus, by induction hypothesis of the inner induction, we know that these two paths evaluate to the same category element, so that π ′ 1 and π ′ 2 also do.This concludes case B.2.
Case B.3: G has a simple path.Recall that, in this case, we know that G has a simple path where the starting and ending objects of intermediate arrows have no other incident edges, and such that the removal of the simple path leaves the graph strongly connected.We denote the path by τ and denote by x ̸ = y its starting and ending objects.Since the removal of the path does not affect strong connectedness of the graph, there is a simple path from x to y sharing no edges with τ , which we denote by κ.Furthermore, there is a simple path from y to x sharing no edges with τ (this is because all intermediate objects of τ only occur in the edges of τ ), which we denote by ρ.
Like in the previous case, up to removing common prefixes and suffixes, it suffices to consider the case where π 1 and π 2 do not start or end in the intermediate vertices of τ .For that reason, isolating all occurrences of τ also isolates all occurrences of the edges of τ , and we can write: where the x i and y i do not use the edges of τ .Like in the previous case, by Lemma 7.7, we can assume that x 1 = y 1 .By Lemma 7.2, we insert a loop (ρκ) ω after every occurrence of τ without changing the category element and still respecting the n ′ , ω-congruence, hence the n ′ , p ′ -congruence because p ′ divides ω.By expanding (ρκ) ω = ρκ(ρκ) ω−1 , it suffices to show that the following paths evaluate to the same category element, with x 1 = y 1 : π ′ 1 = x 1 τ ρκ(ρκ) ω−1 • • • x t−1 τ ρκ(ρκ) ω−1 x t π ′ 2 = y 1 τ ρκ(ρκ) ω−1 • • • y t ′ −1 τ ρκ(ρκ) ω−1 y t ′ We can now regroup the occurrences of τ ρ, which are loops such that some edges (namely, the edges of τ ) only occur in these factors.This means that we can conclude as in case 2 for the cycle τ ρ, as this cycle contains some edges that only occur there; we can choose β at the end of the proof to be a loop on x visiting all edges of G except those of τ , which is again possible because G is still strongly connected even after the removal of τ .
This establishes case 3 and concludes the induction step of the proof, establishing Claim 8.3.
We have thus proved by induction that π 1 and π 2 evaluate to the same category element, in the base case (Claim 8.2) of the outer induction (Claim 8.1) where all edges of π 1 and π 2 are frequent.8.2.Outer induction step (I): some arrows are rare.Let us now show the induction step for the outer induction (Claim 8.1), namely, the induction on the number of occurrences of rare arrows.We assume the claim of the outer induction for r ∈ N. Consider two paths π 1 and π 2 and an |S|-distant rare-frequent threshold n ′ such that π 1 and π 2 are n ′ , p ′ -equivalent and such that they contain r + 1 rare letters.Let us partition them as π 1 = q 1 as 1 and Lemma 7.7).This ensures that s ′ 1 ∼ n ′ ,p ′ s 2 , and that n ′ is still an |S|-distant rare-frequent threshold for them.
Hence, by the induction hypothesis, we have s ′ 1 ≡ s 2 , so that by compositionality we have π 1 ≡ π 2 .
Case I.2: C does not occur again after a.In this situation, we cannot apply Lemma 7.7.However, intuitively, the arrows visited in q 1 and in q 2 must be disjoint from those visited in the rest of the paths, so we can independently reason on q 1 and q 2 , and on s 1 and s 2 .
Formally, we first claim that q 1 ≡ q 2 by the base case (Claim 8.2) of the outer induction (Claim 8.1).Indeed, first note that they are two coterminal paths.Now, there are two cases: every arrow x which is frequent in π 1 and π 2 is either in the SCC C of the starting object of a or not.In the first case, all the occurrences of x in π 1 must be in q 1 , as any occurrence of x in s 1 would witness that we are in Case I.1; and likewise all its occurrences in π 2 must be in q 2 .In the second case, all its occurrences in π 1 must be in s 1 and all its occurrences in π 2 must be in s 2 , for the same reason.Thus, q 1 and q 2 contain no letter which was rare in π 1 and π 2 , some of the frequent letters of π 1 and π 2 (those of the other SCCs) do not occur there at all, and the others occur there with the same number of occurrences.Thus indeed q 1 ∼ n ′ ,p ′ q 2 , they contain no rare arrows, and n ′ is still an |S|-distant rare-frequent threshold for them.Thus, the base case of the outer induction concludes that they evaluate to the same category element.
We now claim that s 1 ≡ s 2 by the induction case of the outer induction (Claim 8.1).Indeed, they are again two coterminal paths.What is more, by the previous reasoning, the arrows that are frequent in π 1 and π 2 either occur only in s 1 and s 2 or do not occur there at all.Thus, s 1 and s 2 contain r rare arrows (for the arrows that were already rare in π 1 and π 2 ), and the frequent arrows either occur in s 1 and s 2 with the same number of occurrences as in π 1 and π 2 or not at all.This implies that n ′ is still an |S|-distant rare-frequent threshold for s 1 and s 2 .Thus, we have s 1 ∼ n ′ ,p ′ s 2 and the induction case of the outer induction establishes that s 1 ≡ s 2 .
Thus, by compositionality, we know that π 1 and π 2 evaluate to the same category element.We have concluded both cases of the outer induction proof and shown Claim 8.1.8.3.Concluding the proof.We have proven Claim 8.1, and explained afterwards how to use it to show that π 1 and π 2 evaluate to the same category element.This implies that n ′ , p ′ -equivalence for our choice of n ′ , hence also n, p-equivalence, is compatible with S E .Thus, by Corollary 5.5 we know that L is in ZG * D p .Hence, L ∈ LZG p implies that L ∈ ZG * D p , so we have shown Claim 5.7.Together with Claim 5.6, it establishes the locality result LZG p = ZG * D p , and we have shown Theorem 1.1.

Conclusion
In this paper, we have given a characterization of the languages of ZG, and proved that the variety ZG is local.More specifically, we have shown this for all the varieties ZG p for p > 0, in particular MNil = ZG 1 = ZG ∩ A.
A natural question for further study is whether the variety ZE is also local.This question seems more complicated.Indeed, as proved by Almeida [Alm94], we have ZE = G ∨ Com, that is, ZE is the variety of monoids generated by the variety G of groups and the variety Com of commutative languages.Now, G is a local variety [TW85, Example 1.3], while Definition 5.1.A finite category on a finite set of objects O defines, for every pair (o, o ′ ) ∈ O of objects, a finite set C o,o ′ of arrows.An arrow in C o,o ′ is said to be going from o to o ′ ; we call o the starting object and o ′ the ending object.The overall set of arrows o,o ′ ∈O C o,o ′ is equipped with a composition law: for any objects o, o ′ , o ′′ , for any arrows a ∈ C o,o ′ and b ∈ C o ′ ,o ′′ , the composition law gives us ab which must be an arrow of C o,o ′′ .(Note that the objects o, o ′ , and o ′′ are not necessarily pairwise distinct.