Regular expressions for tree-width 2 graphs

We propose a syntax of regular expressions, which describes languages of tree-width 2 graphs. We show that these languages correspond exactly to those languages of tree-width 2 graphs, definable in the counting monadic second-order logic ( CMSO ). 2012 ACM Subject Classification Mathematics of computing → Discrete mathematics Keywords


Introduction
Regular word languages form a robust class of languages.One of the witnesses for this robustness is the variety of equivalent formalisms defining them.They can be described by finite automata, by monadic second-order (MSO) formulas, by regular expressions or by finite monoids [3,6,10].Each of these formalisms has some advantages, depending on the context where it is used.For example, MSO is close to natural language, regular expressions define regular languages via their closure properties, automata have good algorithmic properties and can be used as actual algorithms to decide membership in a language, etc.Similarly, regular tree languages have equivalent formalisms, for various kinds of trees [11,13,9].
We will here further generalize the structures considered, by moving to graphs of bounded tree-width.Intuitively, they can be thought of as "graphs which resemble trees".In this framework, we already know that counting MSO (CMSO), an extension of MSO with counting predicates, and recognizability by algebra are equivalent [1,2], yielding a notion that could be called "regular languages of graphs of tree-width k".Engelfriet [7] also proposes a regular expressions formalism matching this class, but by his own admission, these expressions closely mimic the behavior of CMSO.The main feature missing in Engelfriet's regular expressions is a mechanism for iteration, which is the central operator for word regular expressions: the Kleene star.
In this paper, we propose a syntax of regular expressions for languages of tree-width 2 graphs, that follow more closely the spirit of regular expressions on words, using Kleene-like iterations.This constitutes a first step towards the long term objective of obtaining such expressions for languages of graphs of tree-width k.We believe the case of tree-width 2 is already a significant step in itself.Graphs of tree-width 2 form a robust class of graphs with several interesting characterizations.One of them is the characterization via the forbidden minor K 4 , the complete graph with four vertices.By the Robertson-Seymour theorem [12], it is known that for every k ∈ N, the class of tree-width k graphs is characterized by a finite set of excluded minors.However, this result is not constructive, and only the forbidden minors for k ≤ 3 are known.

Tree-width 2 graphs
▶ Definition 1 (Graphs).A graph G is a tuple (V, E 1 , E 2 , s, t, l 1 , l 2 , ι, o), where V is a set of vertices, E 1 and E 2 are two disjoint sets of unary and binary edges, s : E 1 ⊎ E 2 → V and t : E 1 → V are a source and a target functions specifying the source and the target of each edge 1 , l 1 : E 1 → Σ 1 and l 2 : E 2 → Σ 2 are labeling functions indicating the label of each edge, ι is the input vertex and o is the output vertex, ι and o are the interface vertices of G.All the vertices of G which are not interface vertices are called inner vertices.The interface of G is the pair (ι, o) if ι ̸ = o, or the vertex ι otherwise.An a-edge is an edge labeled by the letter a.We say that G is unary if ι = o, and binary otherwise.The interface of a binary edge e is (s(e), t(e)), the interface of a unary edge e is s(e).An interface in G is a list of vertices of length 1 or 2. A graph is empty if it has no edges, and if all its vertices are interface vertices.▶ Remark 2. What we call here a graph is what is usually called a hypergraph (because of the unary edges) with interface.We depict graphs with unlabeled ingoing and outgoing arrows to denote the input and the output, respectively.
▶ Definition 3 (Paths).A path p of G is a non-repeating list (v 0 , e 1 , v 1 , . . ., e n , v n ) where v i is a vertex of G and e i is an edge of G, such that the interface of e i is either (v i−1 , v i ) or (v i , v i−1 ), for every i ∈ [1, n].The path p is directed if the interface of e i is (v i−1 , v i ) for every i ∈ [1, n].The vertex v 0 is the input of p, v n is its output and (v 0 , v n ) its interface.The path p is safe if it does not contain an interface vertex of G as an inner vertex.▶ Definition 5 (tw 2 graphs).Consider the signature σ containing the binary operations • and ∥, the unary operations • and dom, and the nullary operations 1 and ⊤.We define tw 2 terms as the terms generated by the signature σ and the alphabet Σ: We define the graph of a term t, G(t), by induction on t, by letting: and interpreting the operations of the syntax as follows: In the picture above, we represent the graph G by an arrow from its input to its output.For example, the graph dom(G) is obtained from G by relocating the output to the input.We usually write tu instead of t•u and give priorities to the symbols of σ so that ab ∥ c parses to (a•b) ∥ c.We define the set of tw 2 graphs as the graphs of the terms above.The graphs of a and a ∥ 1, where a ∈ Σ, are called atomic.
We will sometimes identify terms with the graphs they generate.For example we may say that (a ∥ b) is binary or connected to say that its graph is so.
▶ Example 6. Below, from left to right, two tw 2 graphs and a graph which is not tw 2 .
▶ Definition 8 (Graph languages).Sets of graphs are called graph languages.A graph language is unary or binary if all its graphs have this arity.

Counting monadic second-order logic
We introduce CMSO, the counting monadic second-order logic, which is used to describe graph languages.
▶ Definition 9 (The logic CMSO).Let V be the relational signature which contains two binary symbols source and target, two unary symbols input and output and a unary symbol a for each (unary or binary) letter a ∈ Σ.
Let X 1 be a countable set of first-order variables and X 2 a countable set of set variables The formulas of CMSO are defined as follows: where r is an n-ary symbol of V, x 1 , . . ., x n , x ∈ X 1 , X ∈ X 2 and k, m ∈ N. Free and bound variables are defined as usual.A sentence is a formula without free variables.We use the usual syntactic sugar, for example φ ⇒ ψ as a shortcut for ¬φ ∨ ψ.
We define the semantics of CMSO formulas.To handle free variables, CMSO formulas are interpreted over pointed graphs.
▶ Definition 10 (Semantics of CMSO).Let G be a graph and Γ be a set of variables.An interpretation of Γ in G is a function mapping each first-order variable of Γ to an edge or vertex of G, and each set variables to a a set of edges and vertices of G.A pointed graph is a pair ⟨G, I⟩ where G is a graph and I is an interpretation of a set of variables Γ in G.If Γ is empty, we denote it simply as G. Let φ be a CMSO formula whose free variables are Γ and let ⟨G, I⟩ be a pointed graph such that I is an interpretation of Γ.We define the satisfiability relation ⟨G, I⟩ |= φ as usual, by induction on the formula φ.Here is an example of the semantics of some CMSO formulas: a(e) : e is an a-edge.
If φ is a sentence, we define L(φ), the graph language of φ as follows: ▶ Definition 11 (CMSO definability).A graph language is CMSO definable if it is the graph language of a CMSO sentence.
▶ Example 12.The language of graphs having an a-edge from the input to the output is definable in CMSO, by the following formula for instance: Note that the graphs of this language may not be tw 2 graphs.
▶ Example 13.The set of tw 2 graphs is a CMSO definable language.Indeed, tw 2 graphs are those graphs which exclude K 4 , the complete graph with four vertices, as minor.The set of graphs which exclude a fixed set of minors can be easily defined in CMSO [5].
The set of tw 2 graphs having an a-edge from the input to the output is definable in CMSO, by the conjunction of the formula φ of Ex. 12 and the formula defining tw 2 graphs.
We state below a localization result, which allows us to transform a CMSO sentence into another one which talks only about a part of the original graph.
▶ Proposition 14.Let φ be a CMSO sentence, x, y ∈ X 1 and X ∈ X 2 .There is a CMSO formula φ |(x,X,y) such that, for every graph G and interpretation I : (x → s, X → H, y → t), such that (s, H, t) is a subgraph of G, we have: There is another presentation of the syntax of CMSO, where we remove first-order variables and the formulas including them, and add the following formulas: X ⊆ Y and r(X 1 . . ., X n ) where r is an n-ary symbol of V.
The formula X ⊆ Y is interpreted as "X is a subset of Y " and r(X 1 . . ., X n ) as "for each i, X i is a singleton containing x i and r(x 1 . . ., x n )".This presentation is more convenient in proofs by induction as there are less cases to analyze.

Recognizability
We

Operations on graph languages
The operations of σ can be lifted from graphs to graph languages in the natural way.We say that an operation on graph languages is CMSO compatible if, whenever its arguments are CMSO definable, then so is its result.
▶ Proposition 18.Union and the operations of σ are CMSO compatible.
We define two additional operations: substitution and iteration.
▶ Definition 19 (Substitution and iteration).Let x be a letter, L and M be tw 2 graph languages and let be G a tw 2 graph.We define the set of graphs G[L/x] by induction on G as follows: where o is an n-ary operation of σ.We define M [L/x] as: We define similarly the simultaneous substitution M [ ⃗ L/⃗ x], where ⃗ L and ⃗ x are respectively a list of tw 2 graph languages and a list of letters of the same length.
For every n ≥ 1, we define the language L n,x and the iteration µx.L as follows: ▶ Remark 20.Substitution and iteration are not CMSO compatible in general.For instance, the iteration of the CMSO language {axb}, which is the set {a n xb n | n ∈ N}, is not CMSO definable.However, under a guard condition that we introduce later, we recover CMSO compatibility.
I C A L P 2 0 2 2 121:6 Regular Expressions for Tree-Width 2 Graphs We finally consider two restricted forms of iteration called Kleene and parallel iteration.
▶ Definition 21 (Kleene and parallel iteration).We define the Kleene iteration L + and the parallel iteration L ∥ of a language L as follows, where x is a letter not appearing in L: A graph language is (of type) series, parallel, domain or test if all its graphs have this type.

Pure graphs and modules
There is a canonical way to decompose pure graphs of type series, parallel and test.
▶ Proposition 25 ([4]).Let G be a pure graph.The graph G has the following shape: Here is a picture illustrating this proposition: A. Doumane 121:7 The following picture illustrates a unary and binary island of a graph.▶ Remark 28.Our notion of modules is different from the one usually used in graph theory, more precisely in the setting of modular decompositions.
▶ Remark 29.The parallel composition of two islands of a graph G with the same interface is also an island of G with the same interface.Similarly, the parallel composition of two modules of a graph G with the same interface is also a module of G with the same interface.This justifies the following definition.

▶ Definition 30 (Maximal islands and modules). Let G be a graph and I an interface in G.
The maximal island at I is the parallel composition of all the islands of G whose interface is I, we denote it by max-island G (I).The maximal module at I is the parallel composition of all the modules of G whose interface is I, we denote it by max-module G (I).
▶ Remark 31.The maximal module at a given interface does not always exist.
Multiset pre-expressions are defined as follows: Multiset expressions are those pre-expressions, where each sub-term appearing under a parallel iteration, is built using a single element a ∈ Σ m (all the other operations are allowed).The graph language of an expressions is defined as usual.
▶ Remark 36.To see why the condition on multiset regular expressions is useful, consider the expression e = (a ∥ b).The language of its parallel iteration is the set of multiset graphs which have the same number of a-edges and b-edges, and this is not a CMSO definable language.

Context-free expressions
▶ Definition 37 (Context-free expressions).We define context-free expressions as the set of terms generated by the following syntax: where e w and e m are respectively word and multiset regular expressions.We define the language of a context-free expression e, denoted L(e), by induction on e, interpreting the operations of the syntax as described in Sec.2.4.
Regular expressions for tw 2 graphs will be defined as a restriction of context-free expressions, where substitution and iteration are allowed only under a guard condition that we shall explain in the following.

The guard condition
▶ Definition 38 (Guarded letters).Let G be a graph and x a letter.We say that: x is s-guarded in G if x is binary and every x-labeled edge of G is parallel to a module.
x is p-guarded in G if x is binary and no x-labeled edge of G is parallel to a module.
A. Doumane 121:9 x is unary and no x-labeled edge of G is parallel to a module.Let τ ∈ {s, p, d, t} be a type and L a graph language.We say that x is τ -guarded in L if it is τ -guarded in every graph of L.
▶ Definition 39 (Guard condition).Let x be a letter, M a tw 2 graph language and L a pure language of type τ .The substitution We say that the iteration µx.L is of type τ if L is of type τ .

▶ Definition 40 (Regular expression).
A regular expression is a context-free expression where every substitution and iteration is guarded.A language of graphs is regular if it is the language of some regular expression.
▶ Remark 41.When L is test and x is a unary letter, then µx.L is always guarded.
▶ Proposition 42.We can decide if a context-free expression is regular.
▶ Remark 43.Be aware that prop.42 is about deciding a syntactic property of e, namely that the iterations and substitutions are guarded.However, the problem of determining if a context-free expression defines a CMSO language is undecidable.This apparent contradiction comes from the fact that some context-free expressions, which are not guarded, define CMSO languages, as we shall see in the upcoming examples.

Examples
▶ Example 44.The iteration µx.axb is not guarded.Indeed, the language of axb is series, as it contains a single series graph G.However, the letter x is not s-guarded in G, because it is not parallel to any module of G.The graph of this iteration look like this: ▶ Example 45.The iteration µx.a(x ∥ c)b is guarded.Indeed the language of a(x ∥ c)b is series, actually it contains a single graph G, depicted below left, which is series.The letter x is s-guarded in G, because it is parallel to a module, namely the c-edge.The graph of this iteration look like this: Note the similarity between the graph language of µx.axb and that of µx.a(x ∥ c)b: the former is obtained by forgetting the c-edges of the latter.Yet, the latter is CMSO definable, while the former is not.In the case of µx.a(x ∥ c)b, the c-edges will guide a CMSO formula to relate the a-edges and the b-edges of the same iteration depth.This is the main intuition behind the guard condition for series languages.
▶ Example 46.The iteration µx.(axa ∥ axa) is guarded.Indeed, the language of (axa ∥ axa) is parallel, as it contains a unique graph G (the left graph below) which is parallel.The letter x is p-guarded because all the occurrences of x are not parallel to any module of G.Note that the graphs of this expression have the following shape: they all start with a binary tree whose edges are labeled by a, end ends with the mirror image of this tree, while the corresponding leafs are connected by an x-edge.Those trees are colored in red below.At first glance, this expression dos not seem to be CMSO definable, as it seems that we need to test whether a graph starts and ends with the same tree.We will see however that the language of this expression, as those of all regular expressions, is CMSO definable.The guard condition is not "perfect", in the sense that some non-guarded context-free expressions might generate CMSO definable languages, as shown in the following example.
▶ Remark 48.Intuitively, the guard condition allows only those graphs where series and parallel operations alternate.This why we add the word and multiset expressions: to allow graphs where we can iterate only series or parallel operations respectively.

Main result
The main result of this paper is the following theorem: ▶ Theorem 49.Let L be a language of tw 2 graphs.We have: Thanks to Thm. 17, CMSO definability implies recognizablity.We show that regularity implies CMSO definability in Sec. 5 and that recognizabilty implies regularity in Sec. 6.

Companion relations
▶ Definition 50 (Companion relation).Let G be a graph.Two paths of G are orthogonal if they do not share any edge, and whenever they share a vertex, it is necessarily an interface vertex of one of them.A set of paths is a set of orthogonal paths if its paths are pairwise orthogonal.
A relation R on the vertices of G is a companion relation if there is a set of orthogonal paths P such that (v, w) ∈ R iff (v, w) is the interface of a path p ∈ P .We say that p is a witness for (v, w), and that P is a witness for the relation R.
▶ Example 51.The relation indicated by the green dotted arrows below is a companion relation.This is not the case for the one indicated by the red dotted arrows.
We introduce CMSO r , an extension of CMSO where quantification over companion relations is possible.
▶ Definition 52 (The logic CMSO r ).Let X r be a set of relation variables, whose elements are denoted R, S, . . . .The formulas of CMSO r are of the following form: As for CMSO, we need to define the semantics of a formula over pointed graphs to handle free variables.
▶ Definition 53 (Semantics of CMSO r ).Let G be a graph and Γ be a set of variables.An interpretation of Γ is as usual, but here every relation variable is mapped to a binary relation on the vertices of G.We define the satisfiability relation ⟨G, I⟩ |= φ as usual, by induction on the formula φ.The only new cases are the quantification ∃R which is interpreted as "there exists a companion relation R on the vertices of the graph", and the formulas (x, y) ∈ R which are interpreted as "there is a pair of vertices (x, y) in R".

The logic CMSO r have the same expressive power as CMSO
To guess a companion relation in CMSO, we show how to encode a set of guarded paths by a collection of sets called a footprint.
▶ Definition 54 (Frontier edges of a path).Let p = (v 0 , e 1 , v 1 , . . ., e n , v n ) be a path.If n > 1, we call e 1 the opening edge of p and e n its closing edge.If n = 0, we call e 0 its single edge.Opening, closing and single edges are called the frontier edges of p, the other edges are called its inner edges.

▶ Definition 55 (Footprint). A footprint in a graph G is the following collection of data: a partition of the vertices of G into non-path and path vertices, a partition of edges into non-path and path edges, a partition of path edges into frontier and inner edges, a partition of frontier edges into opening, closing and single edges and a partition of path edges into direct and inverse edges. The partition of path edges into direct and inverse ones provides them with a new orientation: they conserve their original orientation if they are direct, or get reversed (we swap the source and target) if they are inverse edges.
Let F be a footprint.A path p is encoded by F if its edges and vertices are path edges and path vertices of F, if its inner, frontier, opening, closing and single edges are edges of the corresponding sets in F.Moreover, p must form a directed path with the new orientation dictated by F. ▶ Example 56.We represent below a footprint in the left graph of Ex. 51.Non-path edges and vertices are grey, path vertices are black, opening edges are green, closing edges are yellow, single edges are pink and all the other inner edges are black.For path edges, we display the new orientation induced by the footprint instead of the original one.The set of paths encoded by this footprint are a witness that the green relation of Ex. 51 is a companion relation.

▶ Proposition 57. Let G be a graph and P a set of orthogonal paths of G.
There is a footprint F such that P is the set of paths encoded by F. ▶ Corollary 58.If a language is CMSO r definable then it is CMSO definable.Regular implies CMSO definable ▶ Theorem 59.If a language is regular, then it is CMSO definable.
To prove Thm. 59, we proceed by induction on regular expressions.The cases of word and multiset regular expressions follow from the similar result for words and commutative words.The cases of union and the operations of the signature σ follow from Prop.18.We are left with the cases of substitution and iteration; the rest of this section is dedicated to proving the following proposition.
▶ Proposition 60.Let x be a letter and L and M be languages of tw 2 graphs.We have: We handle the case of iteration, the case of substitution being similar.We show first that the iteration of a CMSO definable language, without any guard condition, is definable in an extension of CMSO where we are allowed to quantify existentially over sets of subgraphs of the input graph, which we call CMSO d .This logic is obviously strictly more expressive then CMSO, because it amounts to quantify over sets of sets.Based on this, we show that the guarded iteration of a CMSO definable language is definable in CMSO r , the extension of CMSO with companion relations defined in the previous section.This concludes the proof, the logic CMSO r being equivalent to CMSO.

Decompositions
When a graph is in the iteration µx.L of some language L, it is possible to structure it into a tree shaped decomposition, such that each part of this decomposition "comes from L".In the following, we define such decompositions.
▶ Definition 61 (Independent graphs).Let G be a graph and H, K be subgraphs of G.We say that H and K are independent if they do not share any edge; and whenever they share a vertex, it is necessarily an interface vertex of both H and K.

▶ Definition 62 (Decompositions).
A decomposition of G is a set D of modules of G such that G ∈ D and for every pair of graphs in D, they are either independent, or module one of the other.We call the graphs of a decomposition its components.We call the interfaces of D the set of interfaces of its components.
Let H and K be components of a decomposition D. We say that H is a child of K, if H is a module of K, and if there is no component C of D, distinct from H and K, such that H is a module of C and C is a module of K.

A. Doumane 121:13
▶ Definition 64 (L-decompositions).Let L be a graph language.An L-decomposition of a graph G is a decomposition of G such that the x-body of each of its components is in L.
▶ Remark 65.The body of a component is a subgraph of G, but its x-body is not a subgraph of G in general, because of the added x-edges.▶ Proposition 66.Let L be a graph language.We have:

The logic CMSO d
Let φ be a CMSO formula defining a graph language L. Using Prop 66, we can express that a graph G is in the iteration µx.L by guessing a decomposition D of G, and ensuring that the x-body of each component satisfies φ.But guessing a set of subgraphs is not expressible in CMSO.This is why we introduce CMSO d , an extension of CMSO where this is allowed.
▶ Definition 67 (CMSO d logic).Let X d be a set of graph set variables, whose elements are denoted X , Y . . . .The formulas of CMSO d are of the following form: Free and bound variables are defined as usual.As for CMSO, we need to define the semantics of a formula over pointed graphs to handle free variables.
▶ Definition 68 (Semantics of CMSO d ).Let G be a graph and Γ be a set of variables.

An interpretation of Γ is a function mapping every first-order variable of Γ to an edge or vertex of G, every set variable to a set of edges and vertices of G, and every graph set variable to a set of subgraphs of G.
We define the satisfiability relation ⟨G, I⟩ |= φ as usual, by induction on φ.The only new cases compared to CMSO are the quantification ∃X which is interpreted as "there exists a set of subgraphs X ", and the formulas (s, Z, t) ∈ X which are interpreted as "the graph whose input is s, whose output is t and whose set of edges and vertices is Z, is an element of X ". ▶ Proposition 69.There is a CMSO d formula decomp(X ), without graph set quantification, such that for every graph G and every set of subgraphs D of G, we have:

Iteration is expressible in CMSO d
Given a CMSO formula φ, we construct a formula φ having X as unique free variable, which expresses the fact that the x-body the head of the decomposition X satisfies φ.To construct φ , we need the following definition.

▶ Definition 70 (Complete sets). Let D be a decomposition of a graph G.
Let H be a set of edges and vertices of G.We say that H is complete if, whenever it contains an edge or an inner vertex of a child C of G (seen as a component of D), then it contains all the edges and inner vertices of C.
Let K be a set of edges and vertices of the x-body of G.We denote by complete D (K) the set of edges and vertices of G, obtained from K by replacing every x-edge coming from a child C of G by the set of edges and inner vertices C. I C A L P 2 0 2 2 121:14 Regular Expressions for Tree-Width 2 Graphs ▶ Remark 71.Note that if H is complete, there is a set S such that H = complete D (S).
Here is a picture illustrating complete sets.The green part is the body of G and the purple modules are its children.The yellow sets are complete, but the pink one is not.
▶ Proposition 72.The following formulas are CMSO d definable: : Y is the set of edges and inner vertices of a child of the input graph w.r.t. the decomposition X .is-complete X (Y ) : Y is complete wrt X .

body-edge X (Y )
: Y is a singleton containing an edge from the body of the input graph wrt X .sourceX (Y, Z) : childX (Z) and Y is a singleton containing the input of the corresponding child.target X (Y, Z) : the same as above, where input should be replaced by output.

choiceX (Y, Z)
: Z contains all the body elements of Y , and for every child contained in Y , Z contains exactly one element of this child.
We construct the formula φ by induction on the structure of φ.We suppose that φ is build using the syntax of CMSO where only set variables are allowed.
▶ Definition 73.Let φ be a CMSO formula whose free variables are Γ.We define the CMSO d formula φ , whose free variables are Γ ∪ {X }, by induction as follows: Transfer results are results of this form: to check that a transformation f(G) of a structure G satisfies a formula φ, construct a formula f −1 (φ) that G should satisfy.The proposition below is a transfer result, where the transformation is the x-body.▶ Proposition 74.Given a CMSO sentence φ defining, there is a CMSO d formula φ having X as unique free variable, such that for every graph G and every decomposition D of G whose components are non-empty: A. Doumane

121:15
The formula φ expresses the fact that the x-body of the head of a decomposition satisfies φ.Using this formula and the localization construction of Prop.14, we construct a formula µx.L saying that the x-body of all the components of a decomposition satisfy φ.
▶ Definition 75.If φ is a CMSO formula, we let µx.φ be the following CMSO d formula: The following proposition says that the language of µx.φ is the iteration of that of φ.
▶ Proposition 76.If φ is a CMSO formula defining a language of non-empty graphs, then:

Guarded iteration of CMSO languages is CMSO r
The idea here is that when the iteration µx.L is guarded, L-decompositions can be encoded by sets of edges and vertices and by companion relations.

The case of test languages
Let µx.L be a guarded iteration of type test, G ∈ µx.L and D an L-decomposition of G. Suppose that G is the left graph below, and that the red vertices are the interfaces 3 of D.
We claim that, thanks to the guard condition, this information is enough to reconstruct the whole decomposition D.More precisely, we claim that the components of D are exactly the maximal modules of G, whose interfaces are the red vertices, as depicted above.
▶ Definition 78.Let G be a graph and S be a set of vertices of G.We define D t (S) as the set of maximal modules of G, whose type is test, and whose interfaces belong to S. ▶ Proposition 79.Let µx.L be a guarded iteration of type test.We have: Proof.(⇒) Follows from Prop.66.To prove (⇐), we define the property P n as follows: We prove, by induction on n, that P n is valid for every n ≥ 1, and this is enough to conclude.
3 Recall that test graphs are unary, hence all the components of a decomposition of G are unary.When n = 1, take S to be the singleton containing the interface of G.We have that D t (S) = {G} and since G ∈ L, we have that D t (S) is an L-decomposition of G.

I C
Let G ∈ L n+1,x .By definition, there is a k-context H and graphs G 1 , . . ., G k such that: Thanks to the guard condition, there is no module of H parallel to a hole of H.For every i ∈ [1, k], let S i be the set of vertices provided by the induction hypothesis applied to the graph G i .Here is a picture illustrating these notations: The set of subgraphs D defined below is an L-decomposition of G.
Let φ be a CMSO formula whose language is L. We transform the CMSO d formula µx.φ of Def.75, whose language is µx.L, into a CMSO formula µx g .φ of the same language.The formula µx g .φ is obtained by replacing the quantification ∃X .by the set quantification ∃S., and by replacing every sub-formula of µx.φ of the form (s, Z, t) ∈ X by this formula: The last part of this formula is expressible in CMSO thanks to Prop.32.The language of µx g .φ is the set of graphs for which we can find an L-decomposition encoded by a set of vertices S, and this is precisely the language µx.L thanks to Prop.79. ◀

The case of domain languages
Let µx.L be a guarded iteration of type domain, G ∈ µx.L and D an L-decomposition of G.
Contrarily to the test case, the interfaces of D are not enough to reconstruct D. Indeed, in this case, a component of D whose interface is v is not necessarily the maximal module at v, but some domain module of interface v, among possibly many others.A way to determine if a domain module is in the decomposition is to check whether it contains an interface of the decomposition.This works only for the components which are not the leaves of the decomposition.This is why we need to say explicitly which domain modules are the leaves.We do so by coloring the edges of the later.

121:17
In the following, we show that a set of vertices of a graph (representing the interfaces of a decomposition) together with a coloring of this graph (indicating which modules are leaves), is enough to recover the decomposition.
▶ Definition 82 (Coloring, active modules.).A coloring of a graph G is a set of its edges called leaf edges.A module of G is active if it contains a leaf edge.Proof.Similar to the proof of prop.79.◀ As in the previous section, we use Prop.84 to get the following theorem.
▶ Theorem 85. Suppose that µx.L : d be a guarded iteration.We have:

The case of parallel languages
The case of guarded iterations of type parallel is similar to the test case.Let µx.L be a guarded iteration of type parallel, G ∈ µx.L and D an L-decomposition of G.We show that the interfaces I of D is enough to recover the whole decomposition D, because its components are the maximal modules of G whose interfaces belong to I.However, in this case, I is no longer a set of vertices, but a set of pairs of vertices, that is a relation on the vertices of G.
We will show that this relation is necessarily a companion relation.Using this result and the fact that CMSO and CMSO r have the same expressive power, we prove that the iteration is CMSO definable.
▶ Definition 86 (D p (R)).Let G be a graph and R a relation on the vertices of G.We define D p (R) as the set of maximal modules of G, whose type is parallel, and whose interfaces belong to S.
▶ Proposition 87.Let µx.L be a guarded iteration of type parallel.We have: ▶ Proposition 88.Let µx.L be an iteration of type parallel and let G a graph.The interfaces of every L-decomposition of G form a companion relation.
Proof.We prove by induction on n ≥ 1 that the interfaces of every L-decomposition of depth n of some graph G form a companion relation, witnessed by a set of paths P , such that the interface of G is witnessed by two parallel paths of P .
When n = 1, the decomposition D is reduced to the graph G. Since G is parallel, it has two parallel paths whose interface is the interface of G. Take P to be these two paths.
Suppose that D is a decomposition of depth n + 1. Hence it is of the form: where D i is an L-decomposition of depth at most n, of a graph G i , for every i ∈ [1, k].Let P i be the set of paths provided by the induction hypothesis for D i , and let p i , q i be the two paths witnessing the interface of G i , for i ∈ [1, k].
We set H := x-body D (G).Since H is parallel, it has two parallel paths p and q whose interface is the interface of H.We transform the paths p and q of H into the paths p ′ and q ′ of G as follows.The paths p ′ and q ′ are obtained from p and q respectively by the following procedure: if e is an x-edge of H which is substituted by some G i , then replace e by the path of p i .Let P be the following set of paths: The set P is orthogonal and witnesses the interfaces of D.Moreover, the interface of G is witnessed by two parallel paths of P , namely p ′ and q ′ .This concludes the proof.◀ ▶ Theorem 89.Suppose that µx.L is a guarded iteration of type parallel.We have: L is CMSO definable ⇒ µx.L is CMSO definable

The case of series languages
Let µx.L be a guarded iteration of type series, G a graph in µx.L and D an L-decomposition of G whose set of interfaces is I.As for the domain case, the set I is not enough to reconstruct the decomposition D, and we need a coloring of the graph to determine which modules are the leaves of the decomposition D. We show also that the set of interfaces I is a companion relation, which will be enough to conclude.▶ Theorem 93.Suppose that µx.L is a guarded iteration of type series.We have: Recognizable implies regular ▶ Theorem 94.If a language of tw 2 -graphs is recognizable, then it is regular.
We proceed gradually, by showing that this result holds for domain-free graphs, for domain-free graphs, then for tw 2 graphs.
▶ Definition 95 (Domain-free).A graph is domain-free if all its domain modules are atomic.
To give an example of how these proofs work, suppose that we have the following property: Proof.Let L be a language of domain graphs, A an algebra whose domain is D, h : G tw2 (Σ) → A a homomorphism and F ⊆ D such that h −1 (F ) = L. Let us show that L v , the set of graphs over Σ whose image is v, is regular for every v ∈ D.
We associate every v ∈ D with a new letter x v and let Γ := {x v | v ∈ D}.If Q ⊆ D, we denote by X D the letters of Γ corresponding to these elements.We extend the homomorphism h to tw 2 -graphs over the alphabet Σ ∪ Γ by letting h(x v ) = v for every x v ∈ Γ.
Let v ∈ D, Q ⊆ D and X ⊆ Γ.We define the set of graphs L Q,X v as follows.We let G be in this set if and only if: G is a domain graph over the alphabet Σ ∪ X, the image of G is v, the image of the strict domain modules of G belong to Q.
Let us show that L Q,X v is regular when X Q ∩ X = ∅.We proceed by induction on the size of Q. Suppose that Q = ∅.This case is based on the following lemma, obtained by case analysis on the graph G.
▶ Lemma 98.Let G be a domain graph whose domain modules, distinct from G itself, are all atomic.There is a domain-free graph H such that G = dom(H).
For every w ∈ D, let M X w be the set of domain-free graphs over the alphabet Σ ∪ X whose image is w.By Lem.98, we have the following equation: which concludes the base case, thanks to Prop.96.To handle the inductive case, we notice the following equality:

Conclusion
We are interested in studying the complexity-theoretic properties of our expressions.For instance understanding the complexity of deciding whether an expression is guarded, and what are the costs of translations between different formalisms (expressions, CMSO, algebra).This can help us get a better grasp of what role these expressions can play, and what is the fine interplay between these different formalisms.As stated in the introduction, this work on tree-width 2 graphs is meant to constitute a first step towards the case of tree-width k.

▶ Example 4 .
Here are some examples of graphs.The c-edge in the graph G a unary edge.
D as a module.▶ Definition 63 (Body of a component).Let G be a graph, D a decomposition of G and C a component of D. The body of C is the subgraph of G whose vertices are those of C minus the inner vertices of its children; and whose edges are those of C minus those of its children.The x-body of C is the graph whose interface is the interface of C, whose vertices are the vertices of the body of C, and whose edges are the edges of the body of C plus, for each child F of C, an x-edge whose interface is the interface of F .We denote it by x-body D (C).

▶
To conclude we only need to find a set of verticesS of G such that D t (S) = D. Let S S 1 • • • ∪ S k ∪ {ι}, where ι is the interface of G. Let us show that D t (S) = D.This is a consequence of the following lemma: ▶ Lemma 80. Let C be a context, K a graph and I an interface in H of the same arity as the hole of C. Suppose that the hole of C is not parallel to any module.We have:max-module C[K] (I) = max-module K (I)◀ Theorem 81.Suppose that µx.L is a guarded iteration of type test.We have:

▶
Definition 83 (D d (S, col)).Let G be a graph, S a set of vertices and col a coloring of G.We let D d (S, col) bet the set of active modules of G of type d, whose interfaces belong to S. ▶ Proposition 84.Let µx.L : d be a guarded iteration.We have: G ∈ µx.L ⇔ ∃S, col.S is a set of vertices and col a coloring of G such that D d (S, col) is an L-decomposition of G.

▶▶
Definition 90 (D s (R, col)).Let G be a graph, R a relation on the vertices of G and col a coloring of G.We let D s (R, col) bet the set of active modules of G of type series, whose interfaces belong to R. Proposition 91.Let µx.L be a guarded iteration of type series.We have:G ∈ µx.L ⇔ ∃R, col.R is a relation on the vertices of G, col is a coloring of G and D s (R, col) is an L-decomposition of G.▶ Proposition 92.Let µx.L be a guarded iteration of type series and let G be a graph.The interfaces of every L-decomposition of G form a companion relation.

▶
Proposition 96.If a language of domain-free graphs is recognizable, then it is regular.Using Prop.96, let us show the following property: ▶ Proposition 97.If a language of domain graphs is recognizable, then it is regular.
can specify languages of graphs by means of σ-algebras, generalizing to graphs the notion of recognizability by monoids.A σ-algebra A is the collection of a set D called its domain, and for each n-ary operation o of σ, a function o A : D n → D. A homomorphism h : A → B between two σ-algebras A and B is a function from the domain of A to the domain of B which preserves the operations of σ.Note that the set of tw 2 graphs, where the operations of σ are interpreted as in Def. 5, forms a σ-algebra which we denote by G tw2 .We say that a language L of tw 2 graphs is recognizable if there is a σ-algebra A with finite domain, a homomorphism h : G tw2 → A and a subset P of the domain of A such that L = h −1 (P ).
be graphs such that h i and the H i have the same arity, for all i ∈ [1, n].We define C[H 1 , . . ., H n ] as the graph obtained from the disjoint union of C and H 1 , . . ., H n , by removing the holes of G, and for every i ∈ [1, n] identifying the input of h i with the input of H i , the output of h i with the output of H i , and by letting its interface of to be that of C. ▶ Definition 27 (Islands and modules).An island of a graph G is a graph H such that there is a context C satisfying G = C[H].A module is a island which is pure.Two islands (or modules) of a graph are parallel if they have the same interface.Since modules are pure, we can speak of series, parallel, domain and test modules of a graph.
▶ Definition 26(Contexts).Let S be a set of special (unary and binary) letters, and let n ≥ 1.An n-context is a graph such that n of its edges, called holes, are numbered from 1 to n, and labeled by n distinct special letters.We call 1-contexts simply contexts.Let C be an n-context whose holes are h 1 . . ., h n and let H 1 , . . ., H n

▶
Proposition 32.Being series, parallel, domain, test, an island, a module, a maximal island, a maximal module are CMSO definable properties.

tw 2 graphs 3.1 Regular expressions for word and multiset graphs
▶ Definition 33 (Word and multiset alphabets).Let Σ w be the set of terms whose graphs have the following form, where a, b ∈ Σ 2 and c ∈ Σ 1 : Let Σ m be the set of terms whose graphs have the following form, where a ∈ Σ 2 and b ∈ Σ 1 :I C A L P 2

0 2 2 121:8 Regular Expressions for Tree-Width 2 Graphs Word
graphs are the graphs generated from those of Σ w by series composition, and multiset graphs are the graphs generated from those of Σ m by parallel composition.▶Example 34.Below, from left to right, a word graph and two multiset graphs.
▶ Definition 35 (Word an multiset expressions).Word expressions are defined as follows: