Keywords: structures, 9, 3, 1 Monadic second-order model-checking problems, sparse relational structures

To Dominique and Louco

Introduction

This book contributes to several fields of Fundamental Computer Science. It extends to finite graphs several central concepts and results of Formal Language Theory and it establishes their relationship to results about Fixed-Parameter Tractability. These developments and results have applications in Structural Graph Theory. They make an essential use of logic for expressing graph problems in a formal way and for specifying graph classes and graph transformations. We need some short historical accounts in order to describe these contributions.

Formal Language Theory

This theory has been developed with different motivations. Linguistics and compilation have been among the first ones, around 1960. In view of the applications to these fields, different types of grammars, automata and transducers have been defined to specify formal languages, i.e., sets of words, and transformations of words called transductions, in finitary ways. The formalization of the semantics of sequential and parallel programming languages, that uses respectively program schemes and traces1 , the modelling of biological development and yet other applications have motivated the study of new objects, in particular of sets of terms.2 These objects and their specifying devices have since been investigated from a mathematical point of view, independently of immediate applications. However, all these investigations have been guided by three main types of questions: comparison of descriptive power, closure properties (with effective constructions in case of positive answers) and decidability problems.

A context-free grammar generates words, hence specifies a formal language. However, each generated word has a derivation tree that represents its structure relative to the considered grammar. Such a tree, which can also be viewed as a term, is usually the support of further computation, typically a translation CONTENTS into a word of another language (this is the case in linguistics and in compilation). Hence, even for its initial applications, Formal Language Theory has had to deal with trees as well as with words. In Semantics, terms are even more important than words. Thus, sets of terms, usually called tree languages3 , and transductions of terms, called tree transductions, have become central notions in Formal Language Theory.

Together with context-free grammars, finite (also called finite-state) automata are among the basic notions of Language Theory, in particular for their applications to lexical analysis and pattern matching. They have also been used early (around 1960) for building algorithms to check the validity of certain logical formulas, especially those of Monadic Second-Order Logic, in certain relational structures. On the other hand, Monadic Second-Order Logic can be used to specify and to classify sets of words and terms. 4 There are deep relationships between monadic second-order formulas and finite automata that recognize words and terms (see [*Tho97a]). The fundamental result is that every language that is specified by a sentence of Monadic Second-Order Logic (expressing a property of words) can be recognized by a finite automaton, and vice-versa. Moreover, the finite automaton can be constructed effectively from the sentence. This means that Monadic Second-Order Logic can be viewed as a high-level specification language that can be compiled into "machine code": a finite automaton that recognizes the words that satisfy the specification. The same result holds for terms, with respect to finite automata on trees. As a consequence of this fundamental relationship, Monadic Second-Order Logic is now one of the basic tools used in Formal Language Theory and its applications, in addition to context-free grammars, finite automata and finite transducers (which are finite automata with output).

The extension of the basic concepts of Formal Language Theory to graphs is a natural step because graphs generalize trees. However, graphs have already been present from the beginnings in several of its fields. In compilation, one uses attribute grammars that are context-free grammars equipped with semantic rules ([*AhoLSU, *Cre]). These rules associate graphs (called dependency graphs) with derivation trees. An attribute grammar is actually the paradigmatic example of a context-free graph grammar (based on hyperedge replacement rewriting rules, [*DreKH]). In the semantics of parallelism, traces are canonically represented by graphs, and an important concern is to specify them by finite automata ([*DiekRoz]).

One starting point of the research presented in this book has been the development of a robust theory of context-free graph grammars, of recognizability of graphs (to be short, an algebraic formulation of finite automata) and of graph transductions. In order to use the theory of context-free grammars and recognizability in arbitrary algebras initiated by Mezei and Wright in [MezWri], we choose appropriate (and natural) operations on graphs. Thus, graphs be-come the value of terms that are built with these (infinitely many) operations. Roughly speaking, a context-free graph grammar is a finite set of rules of the form A 0 → f (A 1 , . . . , A n ), n ≥ 0, where each A i is a nonterminal of the grammar and f is one of the chosen graph operations. The rule means that if the graphs G 1 , . . . , G n are generated by respectively A 1 , . . . , A n , then A 0 can generate the graph f (G 1 , . . . , G n ). Such grammars have useful applications to Graph Theory: they can be used to describe many graph classes in uniform ways and to prove by inductive arguments certain properties of their graphs. Still roughly speaking, a set of graphs is recognizable if there is a finite automaton that recognizes all the terms that evaluate to a graph in the set. Thus, the automaton does not work directly on the given graph, but rather on any term that represents that graph. In a similar way one can define graph transductions through the use of tree transducers. Note that, to describe a set of graphs or a graph transduction in a finitary way, one can necessarily use only finitely many graph operations. As we will see, that is a rather severe, but natural restriction.

Our main goal will be to show that the fundamental use of Monadic Second-Order Logic as a high-level specification language carries over to graphs, not only for the specification of recognizable sets of graphs, but also for contextfree sets of graphs and for certain types of graph transductions. This gives a new dimension to the above-mentioned fundamental result for words and terms, because the properties of graphs that can be specified in Monadic Second-Order Logic are more varied and useful than those of words and terms.

We will specify a set of graphs by a monadic second-order sentence, and a graph transduction by a tuple of monadic second-order formulas that define an "interpretation" of the output graph in the input graph. From such a specification we will show how one can construct a finite automaton on terms, or a tree transducer in the second case, that is related to the specification as explained above. Note that the logic "acts" directly on the graphs, whereas the automata and transducers work on the terms that denote these graphs. Thus, Monadic Second-Order Logic can be viewed as playing the role of "finite automata on graphs" and "finite transducers of graphs" in our Formal Language Theory for Graphs.

Graph algorithms

The above-mentioned developments have important applications for the construction of polynomial-time algorithms on graphs. In his 16th NP-completeness column, published in 1985 [John], Johnson reviews a number of NP-complete graph problems that become polynomial-time solvable if their inputs are restricted to particular classes of graphs such as those of trees, of series-parallel graphs, of planar graphs to name a few. For many of these classes, in particular for trees, almost trees (with parameter k), partial k-trees, series-parallel graphs, outerplanar graphs and cographs, the efficient algorithms take advantage of certain hierarchical structures of the input graphs. Because of these structures, CONTENTS these graphs are somehow close to trees5 . The notion of a partial k-tree has emerged as a powerful one subsuming many other types of "tree-like graphs". (The cographs have a canonical hierarchical structure but they are not included in the class of partial k-trees for any fixed k.) Many articles have produced polynomial-time algorithms for NP-complete problems restricted to partial ktrees. In 1994, Hedetniemi has compiled a list of 238 references [*Hed] on partial k-trees and algorithms concerning them. The notion of a partial k-tree has also been used with a different terminology (tree-width, tree-decomposition) by Robertson and Seymour in their study of the structure of graph classes that exclude fixed graphs as minors. They formulate this notion in terms of particular decompositions of graphs, called tree-decompositions, that are at the basis of the construction of polynomial-time algorithms. Each tree-decomposition has a width, and a graph is a partial k-tree if and only if it has tree-width at most k, which means that it has a tree-decomposition of width at most k.

The recent theory of Fixed-Parameter Tractability (the founding book by Downey and Fellows [*DowFel] was published in 1999) now gives a conceptual framework to most of these results. The notion of a fixed-parameter tractable algorithm specifies how the multiplicative constant factor of the time-complexity of a polynomial-time algorithm depends on certain parts of the data. It happens that for most of the graph algorithms based on tree-decompositions, the exponent of the polynomial is 1: these algorithms are linear-time in the size of the input graphs, with multiplicative "constant" factors that depend exponentially (or more) on the widths of the input tree-decompositions.

The explanation for this fact is one of the main goals of this book. We will show that, for a certain natural choice of graph operations, tree-decompositions correspond to terms, and tree-decompositions of width at most k correspond to terms that are built from a finite subset of those operations. A general algorithmic result that encompasses many of the above-mentioned results, follows from the fundamental relationship between monadic second-order logic and finite automata discussed before: if the considered problem is specified by a monadic second-order sentence (and this is the case for many NP-complete graph problems not using numerical values in their inputs), then a finite automaton on the terms that encode the tree-decompositions of width at most k can be constructed (for each k) to give the answer to the considered question (for example, Is the given graph 3-colorable? ) where the input graph is given by a tree-decomposition (or a term encoding it). The linearity result follows because finite automata can be implemented so as to work in linear time (and because a tree-decomposition of a graph can be found in linear time).

We will extend the case of tree-width bounded graphs (already discussed in [*DowFel]) to another type of graph decompositions, based on another natural choice of graph operations. This leads to the notion of clique-width of a graph. Clique-width is more powerful than tree-width in the sense that every set of graphs of bounded tree-width has bounded clique-width but not vice-versa, an example being the set of cographs. On the other hand, in the above general result, the monadic second-order sentences must be restricted to use quantifications on sets of vertices (instead of both vertices and edges), so less graph problems can be specified. The algorithms are cubic-time instead of linear-time because, for these graph operations, cubic time is needed to find a term for a given graph.

The theory that will be exposed in the nine chapters of this book has arisen from the confluence of the two main research directions presented above. The remainder of this introduction will present in a more detailed way, but still informally, the main concepts and results.

The role of logic

We will study and compare finitary descriptions of sets of finite graphs by using concepts from Logic, Universal Algebra and Formal Language Theory. We first explain the role of Logic. A graph6 can be considered as a logical structure (also called relational structure) whose domain (also called its universe) consists of the vertices, and that is equipped with a binary relation that represents adjacency. Graph properties can thus be expressed by logical formulas of different languages and classified accordingly.

First-order formulas are rather weak in this respect because they can only express local properties such as that a graph has maximum degree or diameter bounded by a fixed integer. Most properties of interest in Graph Theory can be expressed by second-order formulas: these formulas can use quantifications on relations of arbitrary arity. Unfortunately, little can be obtained from the expression of a graph property in second-order logic. Our favourite logical language will be its restriction called Monadic Second-Order Logic. Its formulas are the second-order formulas that only use quantifications on unary relations, i.e., on sets. They can express many useful graph properties like connectivity, p-colorability (for fixed p) and minor inclusion, whence planarity. Such properties are said to be monadic second-order expressible, and the corresponding sets of graphs are monadic second-order definable.

These logical expressions have interesting algorithmic consequences as explained above, but only for graphs that are somehow "tree-like" (because 3colorability is NP-complete and expressible by a monadic second-order sentence). Monadic second-order sentences are also used in Formal Language Theory to specify languages, i.e., sets of words or terms. The fundamental result establishes that monadic second-order sentences and finite automata have the same descriptive power. But monadic second-order formulas are even more important for specifying sets of graphs than for specifying languages because there is no convenient notion of graph automaton. They replace finite automata, not only for specifying sets of graphs, but also for specifying graph transforma-CONTENTS tions. Such transformations, called monadic second-order transductions, generalize the transductions of terms and words defined by finite automata with output called finite transducers. 7 Independently of these language theoretic applications, monadic second-order transductions are technically useful for constructing monadic second-order formulas because the inverse image of a monadic second-order definable set of relational structures under a monadic second-order transduction is monadic second-order definable.

However, monadic second-order logic alone yields no interesting results. In order to be useful for the construction of algorithms, the expression of a graph property by a monadic second-order sentence must be coupled with constraints on the graphs of interest such as having bounded tree-width or bounded cliquewidth. The language theoretical issues to be discussed below will also combine monadic second-order sentences and the very same constraints. Hence, we will study certain hierarchical graph decompositions, like tree-decompositions, that fit with monadic second-order logic.

Graph algebras

Graph decompositions will be formalized algebraically by terms written with appropriate graph operations. Hence, we will use concepts from Universal Algebra in addition to ones from Logic.

For treating graphs as algebraic objects, i.e., as elements of appropriate algebras (words and traces are elements of monoids), we will define graph operations that generalize the concatenation of words. We will consider two natural ways to "concatenate" two graphs. One way is to "glue" them together, by identifying some of their vertices. The other way is to "bridge" them (or rather, "bridge the gap between them"), by adding edges between their vertices. Clearly, to obtain single valued operations, we have to specify which vertices must be "glued" or "bridged". By means of labels attached to vertices, we will specify that vertices with the same label must be identified, or that edges must be created between all vertices with certain labels. Hence, we will define "concatenation" operations on labelled graphs. To allow the flexible use of vertex labels, we also define (unary) operations that modify these labels. Terms written with these operations evaluate to finite (labelled) graphs. The value G of a term t = f (t 1 , t 2 ) is a certain combination, specified by f , of the values of its subterms t 1 and t 2 . These values are, roughly speaking, subgraphs of G (only "roughly" because the labels of the vertices of the graphs defined by t 1 and t 2 may differ from their labels in the resulting graph G). The same holds for all subterms of t, hence, t represents a hierarchical decomposition of G.

Based on the idea of "gluing" graphs (and using the numbers 1, . . . , k + 1 as labels), we will define, for each k, a finite set of graph operations, F HR [k+1] , that generates exactly the graphs of tree-width at most k. Hence, these operations formalize algebraically an existing combinatorial notion. They yield a graph algebra (that generalizes the monoid of words) having countably many operations. We will call it the HR algebra for reasons explained below. Another countable family of graph operations, also indexed by positive integers and based on the idea of "bridging" graphs, will yield a different graph algebra, called the VR algebra, and a graph complexity measure called clique-width. By definition, a graph has clique-width at most k if it belongs to the analogous finite set of graph operations F VR [k] . As observed before, clique-width is more powerful than tree-width in the sense that every set of graphs of bounded tree-width has bounded clique-width but not vice-versa. Many definitions and results will be similar for these two graph algebras. We will explain below why both algebras are interesting.

The introduction of graph operations is essential for our project of extending to graphs the basic concepts of Formal Language Theory in a clean way. We will use for that the algebraic notions of an equational set and of a recognizable set. An equational set is a component of the least solution of an equation system written with set union and the operations of the considered algebra. Equation systems formalize context-free grammars that generate elements of the algebra: if such a context-free grammar has, e.g., three rules A → f (B, C), A → g(A) and A → a for the nonterminal A, where B and C are two other nonterminals, f and g are operations of the algebra and a is a constant of the algebra, then the corresponding equation system has the equation A = f (B, C) ∪ g(A) ∪ {a} (where A, B and C now stand for sets of elements of the algebra). The contextfree languages are actually the equational sets of the monoids of words over their terminal alphabets (due to the least fixed-point characterization of context-free grammars of [GinRic] and [ChoSch]). A recognizable set is a set saturated by a congruence having finitely many classes. The regular languages are thus the recognizable sets of the monoids of words. When all elements of the algebra can be denoted by a term (which is the case for the HR and VR algebra), a set is recognizable if and only if there exists a finite automaton on terms that recognizes all the terms that evaluate to an element of the set.

The chart of Figure 1 shows some relationships between the above defined notions. An arrow means: "used for a definition or a construction".

Two graph algebras

Since we will define two graph algebras, we will obtain two types of equational sets, called the HR-and the VR-equational sets. For each k, the set of graphs of tree-width at most k is HR-equational (because it is generated by the finite set of operations F HR [k+1] ), and similarly, the set of graphs of clique-width at most k is VR-equational. There are also two types of recognizable sets of graphs, the HR-and the VR-recognizable sets. Every HR-equational set is VR-equational and every VR-recognizable set is HR-recognizable, but not vice-versa. The class of HR-equational sets is incomparable with the class of HR-recognizable sets, and similarly for the VR algebra.

These facts show some important differences with the case of words. For words, we have a unique algebraic structure based on a single operation, and the class of recognizable sets (the regular languages) is properly included in that CONTENTS of equational sets (the context-free languages). But graphs are intrinsically more complicated than words: this explains why we need countably many operations and not just one. We will explain next why we have two algebras and two (robust) classes of equational sets that both generalize the class of context-free languages.

The two graph algebras have been defined initially in such a way that their equational sets coincide with existing context-free sets of graphs: the HRequational sets are actually (but not by definition) those generated by certain context-free graph grammars based on a rewriting mechanism called Hyperedge Replacement (that uses "gluing" of graphs) and we call the corresponding algebra the HR algebra to refer to this fact; the other algebra, called the VR algebra, has been designed similarly so that its equational sets are those generated by the context-free graph grammars based on Vertex Replacement (that uses "bridging" of graphs); see [*DreKH] and [*EngRoz] respectively for these two types of graph grammars.

Many properties of the equational and recognizable sets of graphs of both kinds are just particular instances of those of the equational and recognizable sets in arbitrary algebras. By using this algebraic approach, we generalize the context-free languages without having to define a graph rewriting mechanism and check that such rewriting is actually context-free (the general notion of context-free rewriting is defined in [START_REF] Courcelle | An axiomatic definition of context-free rewriting and its application to NLC graph grammars[END_REF]). Similarly, we generalize the regular languages without having to define any notion of graph automaton and to look for closure properties of the class of sets of graphs that are recognized by such automata.

Monadic Second-Order Logic and the VR graph algebra

We first discuss the equational sets and the recognizable sets of the VR algebra, and their relationships with monadic second-order logic.

Two main results of this book are the Recognizability Theorem and the Equationality Theorem. They relate two ways of handling graphs: the "logical way" by which graphs are characterized in terms of what they are made of and contain (vertices, edges, paths, minors, subgraphs with particular properties) and the "algebraic way" by which sets of graphs are characterized more globally by means of equation systems and congruences. In the latter approach, graphs are treated as elements of algebras and related with other elements that are not necessarily among their subgraphs.

The Recognizability Theorem says that if a set of graphs is monadic secondorder definable, then it is VR-recognizable. The Equationality Theorem says that a set of graphs is VR-equational if and only if it is the image of the set of finite trees under a monadic second-order transduction8 . Here are some consequences of these two results.

The Recognizability Theorem entails that if a graph G is defined by a term t written with operations of the VR algebra belonging to any fixed finite set F , then one can check in time O(|t|), whether or not G satisfies a fixed monadic second-order property. This fact, based on a compilation of monadic secondorder formulas into finite automata over F , is one of the keys9 to the construction of fixed-parameter tractable algorithms for the verification of monadic secondorder properties of graphs of bounded clique-width (whence also of graphs of bounded tree-width since bounded tree-width implies bounded clique-width). Another consequence is the Filtering Theorem saying that the graphs of a VRequational set that satisfy a fixed monadic second-order property (for example planarity) form a VR-equational set. This is based on a Filtering Theorem that holds in all algebras and says that the intersection of an equational set and a recognizable one is equational (generalizing the corresponding fact for context-free and regular languages). Since the emptiness of an equational set is decidable, we get as another corollary that the monadic second-order satisfiability problem is decidable for each VR-equational set L. This means that one can decide whether or not a given monadic second-order sentence is satisfied by some graph in L.

The Equationality Theorem entails that the class of VR-equational sets of graphs is preserved under monadic second-order transductions, because the class of monadic second-order transductions is closed under composition. This corollary strengthens the Filtering Theorem. It is similar to the fact that the image of a context-free language under a rational transduction is context-free.

CONTENTS

Monadic second-order logic and the HR graph algebra

The Recognizability and the Equationality Theorems have versions relative to the HR algebra. For describing them, we must go back to the initial definition of monadic second-order formulas (MS formulas in the sequel) interpreted in graphs: they only use quantifications on vertices and sets of vertices. This is due to the chosen representation of a graph by a relational structure whose domain is its set of vertices. However, we can also express logically the properties of a graph G via its incidence graph Inc(G). The vertices of this (bipartite) graph are the vertices and the edges of G, and its adjacency relation links a vertex and the edges incident with it. Thus, monadic second-order formulas to be interpreted in Inc(G) (MS 2 formulas in the sequel) can also use quantifications on edges and sets of edges. A graph property is MS 2 -expressible if it is expressible by an MS 2 formula, and the corresponding set of graphs is MS 2 -definable. The notation MS 2 refers to this extension of the initially defined language (referred to by MS in the sequel). It is strictly more expressive. For example, the existence of a perfect matching is MS 2 -expressible but not MS-expressible. However, MS 2 formulas are not more expressive than MS formulas for properties of words, of trees and of certain types of graphs such as planar graphs and, for each k, of graphs of degree at most k. These facts show the existence of deep links between structural graph properties (such as planarity) and the expressive power of MS 2 versus MS sentences.

The Recognizability Theorem for the HR algebra says that every MS 2definable set of graphs is HR-recognizable, and the Equationality Theorem says that a set of graphs is HR-equational if and only if the set of its incidence graphs is the image of the set of finite trees under a monadic second-order transduction. We obtain an algorithmic consequence similar to the one we have discussed for MS-expressible problems and the VR algebra: if a graph is defined by a term t over F HR [k] for some fixed k, then one can check in time O(|t|) whether or not it satisfies a fixed MS 2 property. Since there exists a polynomial-time algorithm that decomposes appropriately the input graphs, we obtain, for each MS 2 property, a fixed-parameter tractable verification algorithm, tree-width being the parameter. The algorithm for MS properties applies to larger classes of graphs, because bounded tree-width implies bounded clique-width, but to less properties than this one, because not every MS 2 -expressible property is MS-expressible. The notions of tree-width and clique-width are thus both useful, for solving different problems. We also have a Filtering Theorem for the HR-equational sets and MS 2 -expressible properties, whence the decidability of the MS 2 -satisfiability problem for each HR-equational set. The Equationality Theorem for the HR algebra entails that the class of HR-equational sets of graphs is preserved under the monadic second-order transductions that transform incidence graphs.

A graph is uniformly k-sparse if its number of edges is at most k times its number of vertices, and the same holds for all its subgraphs. Another main result of this book is the Sparseness Theorem: MS 2 formulas are not more expressive than MS formulas for properties of uniformly k-sparse graphs, for each fixed k. The above-mentioned types of graphs are uniformly k-sparse for some k.

Logical and Language Theoretical issues

Tree-width and clique-width are closely related with the decidability of monadic second-order satisfiability problems for particular sets of graphs. The satisfiability problem of MS 2 sentences for the set of graphs of tree-width at most some fixed k is decidable (because it is decidable for each HR-equational set), and the same holds for MS sentences and the set of graphs of clique-width at most k. Some converse results also hold: bounded tree-width is a necessary (but not sufficient) condition for a set of graphs to have a decidable MS 2 -satisfiability problem, and a similar result holds for clique-width and MS sentences. Their proofs use monadic second-order transductions and deep results of Graph Theory.

The Recognizability and the Equationality Theorems contribute to establishing the foundations of a sound and robust extension of the theory of formal languages to the description of sets of finite graphs. In this extension, monadic second-order logic plays a major role. From the above informal (and simplified) statements, this extension may seem to be straightforward. However, graphs are intrinsically more complex than words and terms, and some results do not extend as one could expect or hope. We give two examples. First, the set of all graphs is not equational in any of the two graph algebras, whereas the set of all words over a finite alphabet is (almost trivially) context-free. Second, there are uncountably many VR-and HR-recognizable sets of graphs, and this fact prevents any exact characterization of these sets in terms of graph automata or logical formulas. Such a characterization would generalize nicely the classical characterization of the recognizable (i.e., the regular) languages in terms of finite automata and monadic second-order sentences, but it cannot exist. These examples are related to the fact that the sets of operations of the two graph algebras are infinite, and that this infiniteness is somehow unavoidable10 .

Graph structure

Graph structure is a flexible concept covering many different cases. Graph decompositions form an important type of structuring. We have already discussed those that yield the notions of tree-width and clique-width in connection with algorithmic applications. There exist other types of graph decomposition that are useful for algorithmic purposes or for proving results. Examples are the modular decomposition defined by Gallai [Gal], the decomposition in 3-connected components defined by Tutte [*Tut] and the clique-sum decomposition used by Robertson and Seymour [*Gro,[START_REF] Robertson | Graph minors XVI. Excluding a non-planar graph[END_REF]. The existence of an embedding in a fixed surface, or of a homomorphism into a fixed graph (a proper vertex coloring with p colors of a loop-free graph can be defined as a homomorphism CONTENTS of this graph into the complete graph K p ) is a type of structure. Finally, the non-existence in a graph of particular induced subgraphs, minors or vertexminors is also an important type of structural property. (See [*Die] for minors and [START_REF] Oum | Rank-width and vertex-minors[END_REF] for vertex-minors). There exist nontrivial relations between these different notions. Here are some examples: the graphs without a fixed planar graph as a minor have tree-width bounded by a value computable from this graph and those embeddable in a fixed surface are characterized by finitely many excluded minors [*Die]; forbidding certain induced subgraphs implies bounded clique-width [BraDLM, BraELL].

Monadic second-order sentences can express many such structural properties. The expression of p-colorability (for fixed p) is immediate. It is easy to construct a monadic second-order sentence expressing that a given graph has no minor or no induced subgraph isomorphic to a fixed graph. Hence the sets of planar graphs and of graphs of tree-width at most k (for all k) are MS-definable because each of them is characterized by finitely many excluded minors. A set of graphs defined by finitely many excluded induced subgraphs (this is the case of cographs) or by an infinite but MS-definable set of minimal excluded induced subgraphs is also MS-definable. The latter observation applies to comparability graphs [START_REF] Courcelle | The monadic second-order logic of graphs XV: On a conjecture by D. Seese[END_REF][START_REF] Gallai | Transitiv orientierbare Graphen[END_REF]) and to perfect graphs ([* ChuRST, ChuRST]). Their definitions are not directly expressible by monadic second-order sentences, and finding the minimal excluded induced subgraphs requires difficult proofs.

In many situations concerning graph structure, we need more than a yes or no answer. For example, that a graph does not contain K 5 or K 3,3 as a minor implies that it is planar, but this negative fact, when it is valid, does not help to find a planar embedding. In other words, we are not only interested in checking that a given graph "has some structure", e.g., has a planar embedding or a treedecomposition of width bounded by a fixed integer, but we are also interested in having a monadic second-order transduction that constructs from the given graph some planar embedding or some tree-decomposition. Such transductions may be difficult to construct. Some constructions are given in [START_REF] Courcelle | The monadic second-order logic of graphs X: Linear orderings[END_REF][START_REF] Courcelle | The monadic second-order logic of graphs XI: Hierarchical decompositions of connected graphs[END_REF]Cou00,[START_REF] Courcelle | The monadic second-order logic of graphs XVI: Canonical graph decompositions[END_REF][START_REF] Courcelle | Circle graphs and monadic second-order logic[END_REF] and challenging questions remain open in this area.

To conclude with this aspect, we can state that many constructions of monadic second-order formulas and transductions use in an essential way results of Graph Theory, and even very deep ones in some cases. Conversely, the methods developed in this book bring new results in Graph Theory apart from algorithmic applications. For example, the infinite set of minimal excluded induced subgraphs that characterizes the comparability graphs has a certain regularity that we can formalize by observing that this set is VR-equational. Such applications deserve further study.

The main contributions of this book

Let us summarize the main ideas and results to be developed in this book. We define two graph algebras called the HR algebra and the VR algebra, from which we get two classes of equational and two classes of recognizable sets of graphs. The terms of these algebras denote graphs and formalize certain hierarchical CONTENTS structures. The particular cases of this theorem for the HR and the VR graph algebras follow as immediate corollaries.

Chapter 6 (L, LT, A) is devoted to algorithmic applications. It reviews the parsing algorithms that construct the necessary expressions of the input graphs by terms over the operations of the HR and of the VR algebra. It develops in detail the "compilation" of monadic second-order formulas into finite automata intended to run on the terms resulting from the parsing step. This construction is hopefully more usable than the one of Chapter 5. It yields alternative proofs of weaker versions of the Recognizability Theorem.

Chapter 7 (L, LT, GT) defines monadic second-order transductions and establishes their main properties: closure under composition and preservation of monadic second-order definability under inverse monadic second-order transductions: we call this latter result the Backwards Translation Theorem. The Equationality Theorem characterizes the VR-and the HR-equational sets as the images of the set of trees (equivalently of terms over any rich enough functional signature) under monadic second-order transductions of appropriate types. Four types of transductions come from the two possible representations of a graph by a relational structure for the input and the output. The Equationality Theorems characterize bounded clique-width and bounded tree-width in a way that does not depend on the graph operations chosen in Chapter 2. Hence, VRand HR-equationality as well as the properties of having bounded clique-width and tree-width are robust in the sense that they are stable under the monadic second-order transductions that are respectively specified by MS and by MS 2 formulas.

Chapter 8 (L, LT) shows that the classical automata-theoretic characterization (recalled in Chapter 5) of the monadic second-order definable sets of terms (hence, also of words) extends to monadic second-order transductions. More precisely, these transductions are characterized in terms of two-way finite-state transducers on words, and of tree-walking transducers on terms, where "tree" refers to the representation of terms by labelled ordered trees. Characterizations of the VR-equational (equivalently of the HR-equational) languages of words and terms are obtained. Every (functional) monadic second-order transduction of graphs of bounded tree-width can be realized by a tree-walking transducer on the level of terms (of the HR algebra), i.e., it can be realized by parsing the input graph, applying the tree transducer to the resulting input term, and evaluating the output term of the transducer to produce the output graph. The same result holds for clique-width and the VR algebra. This can be viewed as a generalization of the Recognizability Theorem to graph transductions.

Chapter 9 (L, GT, UA, A) extends to finite relational structures the definitions and results of Chapters 2 to 7. It contains in particular an extension to relational structures of the Equationality Theorem. Although many results extend easily from graphs to relational structures, some seemingly difficult questions remain open. Additionally, this chapter proves the Sparseness Theorem which establishes that, for expressing properties of uniformly k-sparse graphs (or relational structures11 ) by monadic second-order formulas, quantifications over sets of edges (or sets of tuples, respectively) bring no additional power: every MS 2 formula can be translated into an equivalent MS formula.

Chapter 10 reviews some open problems and some results not presented in the previous chapters.

The bibliography is organized in two parts: the first part (with reference labels starting with *) lists books, book chapters and survey articles. The second one lists research articles and dissertations.

All necessary definitions will be given, but the reader is expected to be familiar with the basic notions of Logic (mainly first-order logic), of Universal Algebra (algebras, congruences), of Formal Language Theory (context-free grammars, finite automata), and of Graph Theory (basic notions). Chapters 2 to 9 present detailed proofs of results that have been published in articles. It was not an easy task to elaborate consistent definitions and notations for many different notions from various fields, namely Language Theory, Universal Algebra, Logic and Graph Theory. By giving precise definitions and carefully written proofs, our first aim is to give a robust foundation to the field described in this introduction. Our second aim is that these definitions and proofs can be adapted to related notions, implemented and improved by researchers without too much effort.

Chapter 1

Overview

This chapter presents the main definitions and results of this book and their significance, with the help of a few basic examples. It is written so as to be readable independently of the others. Definitions are sometimes given informally, with simplified notation, and most proofs are omitted. All definitions will be repeated with the necessary technical details in the subsequent chapters.

In Section 1.1, we present the notion of equational set of an algebra by using as examples a context-free language, the set of cographs and the set of series-parallel graphs. We also introduce our algebraic definition of derivation trees.

In Section 1.2, we introduce the notion of recognizability in a concrete way, in terms of properties that can be proved or refuted, for every element of the considered algebra, by an induction on any term that defines this element. We formulate a concrete version of the Filtering Theorem saying that the intersection of an equational set and a recognizable one is equational. It follows that one can decide if a property belonging to a finite inductive set of properties is valid for every element of a given equational set. We explain the relationship between recognizability and finite automata on terms.

In Section 1.3, we show with several key examples how monadic second-order sentences can express graph properties. We recall the fundamental equivalence of monadic second-order sentences and finite automata for words and terms.

In Section 1.4, we introduce two graph algebras. They are called the VR and the HR algebra because their equational sets are those that are generated by the context-free Vertex Replacement and Hyperedge Replacement graph grammars respectively. The cographs and the series-parallel graphs are respectively our current examples of a VR-and an HR-equational set. We state (a weak version of) the Recognizability Theorem which says, in short, that monadic secondorder definability implies recognizability. From it we obtain a logical version of the Filtering Theorem where the recognizable sets are defined by monadic second-order sentences.

In Section 1.5, we review the basic definitions of Fixed-Parameter Tractability and we state the algorithmic consequences of the (weak) Recognizability Theorem. This theorem has actually two versions, relative to the two graph algebras defined in Section 1.4, and yields two Fixed-Parameter Tractability Theorems.

In Section 1.6, we describe the consequences of the Recognizability and Filtering Theorems for the problem of deciding whether a given monadic secondorder sentence is satisfied by some graph of tree-width at most a given k or, more generally, by some graph of an equational set.

In Section 1.7, we introduce the notion of a monadic second-order transduction by means of examples that have some graph theoretic content, and we state the Equationality Theorem for the VR algebra. It gives a characterization of the VR-equational sets, and in particular of the sets of graphs of bounded clique-width, that is formulated in purely logical terms.

In Section 1.8, we consider monadic second-order formulas interpreted in incidence graphs (as opposed to in graphs "directly"). These formulas can use edge set quantifications. We compare the corresponding four types of monadic second-order transduction and we state the Equationality Theorem for the HR algebra: it is based on monadic second-order transductions that transform incidence graphs.

In Section 1.9, we define relational structures and we extend to them (easily) some results relative to graphs represented by their incidence graphs. We introduce betweenness and cyclic ordering as examples of combinatorial notions that are based on linear orderings but are defined in a natural way as ternary relations.

Context-free grammars

By starting from the standard notion of a context-free grammar, we introduce the notion of an equational set and we define two equational sets of graphs. We define the equational sets of a (one-sorted) algebra and the corresponding sets of derivation trees.

Context-free word grammars

By using context-free grammars, one can specify certain formal languages, namely the context-free languages, in a finitary way. Context-free grammars are usually defined as rewriting systems satisfying particular properties, conveyed by the term "context-free" and axiomatized in [START_REF] Courcelle | An axiomatic definition of context-free rewriting and its application to NLC graph grammars[END_REF]. However, the Least Fixed-Point Characterization of context-free languages due to Ginsburg and Rice [GinRic] and to Chomsky and Schützenberger [ChoSch] is formulated in terms of systems of recursive equations written with the operations of union and concatenation over languages. This algebraic view has been developed by Mezei and Wright [MezWri] and has many advantages. First, it is more synthetic in that it deals with languages rather than with words produced individually by derivation sequences. Second, it puts the study of context-free languages in the more general framework of recursive definitions handled as least solutions of systems of equations, and last but not least, it is applicable to any algebra. This latter aspect is especially important for the extension to graphs.

We recall how context-free languages can be characterized as the components of the least solutions of certain systems of equations in languages. A contextfree grammar G is a finite set of rewriting rules defined with two alphabets, a terminal alphabet A and a nonterminal alphabet N . For every S in N , the context-free language over A generated by G from S is denoted by L(G, S).

Example 1.1 We consider for example the context-free grammar G with terminal alphabet A = {a, b, c}, nonterminal alphabet N = {S, T } and rules named respectively p, q, . . . , w (where ε denotes the empty word): p : S → aST q : S → SS r : S → a s : T → bT ST u : T → a v : T → c w : T → ε It defines two languages L(G, S) and L(G, T ) over A, i.e., sets of words in A * . These languages satisfy the equations of the following system Σ G :

Σ G K = aKL ∪ KK ∪ {a} L = bLKL ∪ {a, c, ε}
with K = L(G, S) and L = L(G, T ). The pair (L(G, S), L(G, T )) is thus a solution of Σ G . However, it is not the only one. The pair of languages (A * , bA * ∪ {a, c, ε}) is another solution as one checks easily1 . The Least Fixed-Point Characterization of context-free languages establishes that the pair (L(G, S), L(G, T )) is the least solution of Σ G for component-wise inclusion.

Cographs

We give two examples of similar definitions of sets of graphs. We first consider as ground set the set G u of undirected simple graphs2 . Two isomorphic graphs are considered as the same object. We will use ⊕ to denote the disjoint union of two graphs G and H. This means that G ⊕ H is the union of G and of a copy of H disjoint with G (hence G ⊕ G = G). We will also use the complete join, G ⊗ H, defined as G ⊕ H augmented with undirected edges linking every vertex of G and every vertex of H. We let 1 denote any graph with one vertex and no edges. Note that both ⊕ and ⊗ are commutative and associative operations.

The set of cographs C can be defined as the least set of graphs satisfying the equation

C = (C ⊕ C) ∪ (C ⊗ C) ∪ {1}. (1.1)
This set (it is a proper subset of G u ) has actually alternative characterizations (see Section 1.3.1 below). From this equation, one can derive definitions of certain subsets of C. Consider for example the following system of two equations:

C 0 = (C 0 ⊕ C 0 ) ∪ (C 1 ⊕ C 1 ) ∪ (C 0 ⊗ C 0 ) ∪ (C 1 ⊗ C 1 ) C 1 = (C 0 ⊕ C 1 ) ∪ (C 0 ⊗ C 1 ) ∪ {1}. (1.2)
Its least solution in P(G u ) × P(G u ) is the pair of sets (C 0 , C 1 ) where C 0 (resp. C 1 ) is the set of cographs having an even (resp. an odd) number of vertices. 3 We will give general and effective methods for deriving from an equation or a system of equations that defines a set L, an equation or a system of equations defining {x ∈ L | P (x)} where P is a property of the objects under consideration. This is possible if P has an appropriate "inductive behaviour" relative to the operations with which the given equation or system of equations is written.

From the definition of cographs as elements of the least subset C of G u satisfying (1.1), it follows that each of them is denoted by a term, more formally, is the value of a term in an algebra of graphs. Examples of terms denoting cographs are

1, 1 ⊕ 1, (1 ⊕ 1) ⊗ 1, (1 ⊕ 1) ⊗ (1 ⊕ 1).
The cograph of Figure 1.1 is the value of the term t = (1

⊗ 1 ⊗ 1) ⊗ (1 ⊕ (1 ⊗ 1)).
Since ⊗ is associative, we have written t by omitting some parentheses as usual, for readability. These terms belong to the set T ({⊕, ⊗, 1}) of all terms written with the constant 1 and the two binary operations ⊕ and ⊗. Equation (1.1) can also be solved with ground set T ({⊕, ⊗, 1}). For this interpretation of (1.1) the unknown C denotes subsets of T ({⊕, ⊗, 1}). Clearly, the set of terms T ({⊕, ⊗, 1}) itself is the least (in fact, the only) solution of (1.1) in P(T ({⊕, ⊗, 1})).

A similar fact holds for System (1.2). Its least solution in P(T ({⊕, ⊗, 1})) × P(T ({⊕, ⊗, 1})) is a pair of sets (T 0 , T 1 ) where T 0 , T 1 ⊆ T ({⊕, ⊗, 1}) and for each i = 0, 1, the set C i is the set of cographs which are the values of the terms in T i .

This example shows that a grammar, i.e., a system of equations like (1.2), specifies not only a tuple of sets of objects, here graphs, but also denotations by terms of the specified objects. These objects can be words, terms, trees, graphs, as we will see. Each term is a formalization of the structure of the object it denotes, as specified by the grammar; it provides a hierarchical decomposition of that object. In many cases, an object can be denoted by several terms that are correct with respect to the grammar. In such a case, we say that the grammar is ambiguous. The grammars (1.1) and (1.2) are ambiguous: since ⊕ and ⊗ are commutative and associative, most cographs are denoted by more than one term.

As an example of structure, consider again the term (1⊗1⊗1)⊗(1⊕(1⊗1)) that denotes the cograph of Figure 1.1. It provides a decomposition of that cograph, because the subterm 1 ⊗ 1 ⊗ 1 denotes the triangle at the left of Figure 1.1, whereas the subterm 1 ⊕ (1 ⊗ 1) denotes the three vertices at the right of Figure 1.1 together with the edge between two of them.

Series-parallel graphs

The ground set of graphs is here the set J d 2 of directed graphs G equipped with two distinct distinguished vertices marked 1 and 2 called its sources, denoted respectively by src G (1) and src G (2). These graphs may have multiple edges 4 . Let e be a constant denoting the graph with two vertices and only one edge from source 1 to source 2. The operations are the parallel-composition, denoted by , and the series-composition, denoted by •. For G and H in J d 2 , the graph G H is the union of G and an isomorphic copy H of H such that src G (1) = src H [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF], src G (2) = src H (2), and G and H have nothing else in common. We define src G H (1) := src G (1) and src G H (2) := src G (2). Note that G G has twice as many edges as G, hence G = G G in general.

Series-composition is defined similarly. For G, H ∈ J d 2 , we let G • H be the union of G and an isomorphic copy H of H such that src G (2) = src H [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] and G and H have nothing else in common. We let src G•H (1) := src G (1) and src G•H (2) := src H (2). These operations are illustrated in Figure 1.2. The set of series-parallel graphs5 is defined by the equation: S = (S S) ∪ (S • S) ∪ {e} (1.3) where by "defined" we mean that S is the least subset of J d 2 satisfying (1.3). As for cographs, this definition gives a notation of series-parallel graphs by terms. The set of terms is here T ({ , •, e}). Examples of terms are:

e, e e, (e e) • (e e), ((e e) • e) (e • e).

The graph denoted by the last of these terms is shown in Figure 1.3. Note that the subterm (e e) • e denotes the three edges at the left of Figure 1.3, with their three incident vertices, whereas the subterm e • e denotes the two edges at the right, with their three incident vertices.

The general setting

Let F be a (functional) signature, that is, a set of function symbols such that each symbol f is given with a nonnegative integer intended to be the number of arguments of the corresponding function. This number is called its arity and is denoted by ρ(f ). A function symbol of arity 0 is also called a constant symbol.

An F -algebra M is a set M equipped with total functions f M : M ρ(f ) → M for all f in F . We write it M = M, (f M ) f ∈F . We call M the domain and f M an operation of M; if f has arity 0, then f M is also called a constant of M. The F -algebra M is finite if M is finite.

Let X = {x 1 , . . . , x n } be a set of unknowns (or variables), intended to denote subsets of M . A polynomial is an expression of the form p = m 1 ∪ • • • ∪ m k where each m i is a monomial, i.e., a term written with the symbols of F ∪ X and well formed with respect to arities (the unknowns are of arity 0).

For each n-tuple (L 1 , . . . , L n ) of subsets of M and each monomial m, the set m(L 1 , . . . , L n ) is a subset of M . This subset is defined by taking x i = L i and by interpreting each function symbol f as f M , where, for all A 1 , . . . , A ρ(f ) ⊆ M :

f M (A 1 , . . . , A ρ(f ) ) := {f M (a 1 , . . . , a ρ(f ) ) | a i ∈ A i }.
Hence f M also denotes the extension to sets of the function f M : M ρ(f ) → M . For a polynomial p = m 1 ∪ • • • ∪ m k we define:

p(L 1 , . . . , L n ) := m 1 (L 1 , . . . , L n ) ∪ • • • ∪ m k (L 1 , . . . , L n ).
A system of polynomial equations (an equation system for short) is a system of the form: S = x 1 = p 1 , . . . , x n = p n (1.4) where p 1 , . . . , p n are polynomials.

Example 1.2 In the particular case of the grammar G considered in Example 1.1, we let F = {•, ε, a, b, c} and M = A * , •, ε, a, b, c , where A = {a, b, c} and • denotes concatenation; the equation system Σ G can be written formally as follows:

x 1 = a • (x 1 • x 2 ) ∪ x 1 • x 1 ∪ a x 2 = b • ((x 2 • x 1 ) • x 2 ) ∪ a ∪ c ∪ ε,
where the associativity of concatenation is not taken for granted any more. Note that for the constant symbol a of F we have a M = a and also, according to the above extension, a M = {a}; similarly, the constant symbol ε denotes both the empty word ε and the language {ε}.

Going back to the general case, a solution of a system S as in (1.4) is an n-tuple (L 1 , . . . , L n ) in P(M ) n that satisfies the equations of S, which means that L i = p i (L 1 , . . . , L n ) for every i = 1, . . . , n. Solutions are compared by component-wise inclusion and every system has a least solution. The components of the least solutions of such systems are called the equational sets of the F -algebra M. We will denote by Equat(M) the family of equational sets of M.

For a signature F , we denote by T (F ) the set of terms written with the symbols of F and well formed with respect to arities. The usual notation for terms is with the function symbols in leftmost position, their arguments are between parentheses and separated by commas. In this notation, the term denoting the graph of Figure 1.3 is written (•( (e, e), e), •(e, e)). 6 As is well known, terms can be represented by certain labelled, directed and rooted trees. This representation is the reason that terms are usually called trees in Formal Language Theory.

The set T (F ) is turned into an F -algebra, denoted by T(F ), by defining the operation f T(F ) by f T(F ) (t 1 , . . . , t ρ(f ) ) := f (t 1 , . . . , t ρ(f ) ).

This operation performs no computation; it combines its arguments which are terms into a larger term.

For every F -algebra M, a term t ∈ T (F ) has a value t M in M that is formally defined as follows:

t M := f M if t = f and f has arity 0 (it is a constant symbol),

t M := f M (t 1M , . . . , t ρ(f )M ) if t = f (t 1 , . . . , t ρ(f ) ).
Since every term can be written in a unique way as f or f (t 1 , . . . , t ρ(f ) ) for terms t 1 , . . . , t ρ(f ) , the value t M of t is well defined. The mapping t → t M , also denoted by val M , is the unique F -algebra homomorphism from T(F ) into M. 7An F -algebra M is generated by F if every element of M is the value of some term in T (F ).

An equation system S of the form (1.4) has a least solution in P(T (F )) n that is an n-tuple (T 1 , . . . , T n ) of subsets of T (F ). The least solution (L 1 , . . . , L n ) of S in P(M ) n is also characterized by L i = {t M | t ∈ T i }, for each i = 1, . . . , n. This is an immediate consequence of a result of [MezWri] saying that the least fixed-point operator commutes with homomorphisms. A term t in T i represents the structure of the element t M of L i as specified by the system S.

It follows in particular that for each i, L i = ∅ if and only if T i = ∅. Hence the least solutions of a system S in all algebras have the same empty components. The emptiness of each set T i can be decided by the algorithm that decides the emptiness of a context-free language. Each set T i is actually a context-free language over the alphabet consisting of F , parentheses and comma.

We will use these definitions for algebras of graphs M in the following way: M will be a class of graphs like G u or J d 2 in the examples of cographs and seriesparallel graphs, F will be a set of total functions f M : M ρ(f ) → M that will be used to construct graphs. These functions, called the operations of M, generalize the concatenation of words. The constants will be basic graphs. For each such graph algebra M, the class of equational sets Equat(M) generalizes the class of context-free languages since they are characterized as the components of the least solutions of equation systems as recalled in Section 1.1.1. There is thus no unique notion of a context-free set of graphs because this notion depends on the considered algebra.

However, even in the case of languages, several algebras can be considered, because one can enrich the monoid structure of A * by new operations. This increases the class of equational sets, hence defines richer notions of context-free languages, if we take this term in the algebraic sense. The squaring function that associates with a word u the word uu, can be such an operation. Another one is the shift that associates with a word au the word ua, where a is a letter. The corresponding classes of equational sets have not received specific attention.

In the case of graphs, we will show that there are only two robust classes of equational sets, where robust means that they are closed under certain graph transformations definable by formulas of monadic second-order logic. These transformations, called monadic second-order transductions, play the role of rational transductions in the theory of formal languages.

Each of the two classes of context-free sets of graphs is the class of images of the set of finite binary trees under monadic second-order transductions of appropriate forms. Somewhat similarly, the class of context-free languages is the class of images of the language defined by the equation L = aLbLc ∪ {d}, under all rational transductions. This language encodes binary trees. Hence trees play a major role in all three cases.

Derivation trees

Context-free grammars specify languages. However the real importance of the notion of a context-free grammar is that, when a word is recognized as wellformed, the grammar specifies one or several parse trees for this word. These trees are obtained as results of the syntactic analysis (or parsing) of the considered word. They represent the syntactical structures of the considered word as generated by the grammar. In compiling applications, grammars are constructed so as to be unambiguous, and each recognized word has a unique parse tree. This tree is the support of further computation, in particular type checking and translation into intermediate code.

Similarly, an equation system specifies a set of objects and, as we have seen, it additionally specifies terms that denote those objects and represent their structure. Let S be an equation system and M = M, (f M ) f ∈F an algebra, and consider an algorithm that, for each element m of M , computes a term t that denotes m as specified by S (if such a term exists). Due to the similarity with context-free grammars, we will say that this is a parsing algorithm for S.

However, if we view a context-free grammar G such as the one of Example 1.1 as an equation system S = Σ G over the signature F = {•, ε, a, b, c}, as indicated in Example 1.2, then the terms in T (F ) specified by the system Σ G are not the parse trees of G (because they do not show which rules of G are applied). Nevertheless, it is possible to view G as an equation system S in a different way, such that the terms of S do correspond to the parse trees of G, or rather a variant of parse trees called derivation trees. Let us illustrate this for the context-free grammar G of Example 1.1.

Example 1.3 We consider again the grammar G of Example 1.1. Its rules are named by symbols p, q, . . . , w, that we will consider as function symbols with arities defined by ρ such that ρ(s) = 3, ρ(p) = ρ(q) = 2, ρ(r) = ρ(u) = ρ(v) = ρ(w) = 0; they form a signature P . The arity of a rule is the number of occurrences of nonterminals in the righthand side of the rule.

Consider for example the word baaac generated from nonterminal T by the derivation sequence D:

T ⇒ bT ST ⇒ bT aST T ⇒ baaST T ⇒ baaaT T ⇒ baaaT ⇒ baaac where the rules s, p, u, r, w, v are successively applied. (The arrow ⇒ denotes the one-step derivation relation of G). Assuming that rule w is applied to the leftmost T in baaaT T , we associate with D the term d = s(u, p(r, w), v) of T (P ). This term contains more information than the sequence (s, p, u, r, w, v); from it one can find all derivation sequences of the word baaac that are equivalent to D by permutations of steps. In particular the leftmost derivation sequence uses successively rules s, u, p, r, w, v, and the rightmost one uses rules s, v, p, w, r, u. Figure 1.4 shows the parse tree of D and the corresponding term d.

Terms like d will be called derivation trees. We keep the name parse tree for the trees like the one of Figure 1.4 (left part) that are used in the theory of parsing. (Good text books exposing this theory are the "Dragon Book" by Aho et al. [*AhoLSU] and the book by Crespi-Reghizzi [*Cre]).

The equation system Σ G of Example 1.1 can be rewritten into the following system:

Σ G K = p(K, L) ∪ q(K, K) ∪ r L = s(L, K, L) ∪ u ∪ v ∪ w.
Instead of solving this system for the F -algebra M = {a, b, c} * , •, ε, a, b, c (which is the algebra for Σ G in Example 1.2), we solve it for the P -algebra M with the same domain {a, b, c} * but with the following interpretation of the symbols of P . If we interpret the symbols p, q, s by the following operations on then Σ G is just an alternative writing of Σ G , and its least solution for the algebra M is also (L(G, S), L(G, T )). But the system Σ G has also a least solution (K , L ) in P(T (P )) × P(T (P )), and the derivation tree d is an element of L . More generally we define the sets of derivation trees of G respectively associated with S and T as the sets of terms K and L . For the above interpretation of the symbols of P , we can evaluate every term t of T (P ) into a word t M in A * . In particular d M = baaac. Clearly, L(G, S) = {t M | t ∈ K } and L(G, T ) = {t M | t ∈ L }. Thus, since a parsing algorithm for Σ G produces derivation trees of G, it corresponds to a classical parsing algorithm of the context-free grammar G.

The system Σ G and the derivation trees of G represent the abstract syntax of the grammar G whereas the P -algebra M represents its concrete syntax. It should be clear that the construction of Σ G and M can be realized for every context-free grammar G. It should be noted, however, that the signature P and the algebra M both depend on G.

A term that is associated with the word baaac according to the equation system Σ G in Example 1.2, is b • ((a • (a • (a • ε))) • c). That term can be obtained from derivation tree d by (re)interpreting the symbols p, q, s as the following operations on terms in T ({•, ε, a, b, c}): p(x, y) := a • (x • y), q(x, y) := x • y, and s(x, y, z) := b • ((x • y) • z). Thus, a parsing algorithm for Σ G (producing derivation trees) can easily be transformed into one for Σ G (producing terms).

In fact, derivation trees can be defined for the elements of general equational sets. The transformation of Σ G into Σ G can be generalized into the transformation of an arbitrary equation system S = x 1 = p 1 , . . . , x n = p n into a system S = x 1 = p 1 , . . . , x n = p n such that each polynomial p i is a union of monomials of the form r(x i1 , . . . , x i ρ(r) ) corresponding one-to-one to the monomials of p i , where r belongs to a signature P associated with S. If m ∈ T (F ∪ {x 1 , . . . , x n }) is the monomial of p i to which r(x i1 , . . . , x i ρ(r) ) corresponds, then x i1 , . . . , x i ρ(r) is the sequence of unknowns that occur in m. Furthermore, we impose that each r has a unique occurrence in S . The least solution of S in P(T (P )) n defines the n-tuple of sets of derivation trees of S.

Let F be the signature over which S is written, and M the F -algebra for which S is to be solved. The function M ρ(r) → M that interprets a symbol r in P is the one defined8 (in the usual sense) by the unique term t r in T (F ∪ {y 1 , . . . , y ρ(r) }) such that (i) the variables y 1 , . . . , y ρ(r) occur in t r in that order and no variable y j occurs more than once, and (ii) the monomial of S to which the monomial r(x i1 , . . . , x i ρ(r) ) of S corresponds is obtained by substituting x ij for y j in the term t r , for every j = 1, . . . , ρ(r).

We obtain thus a P -algebra M (with the same domain as M) and the system S interpreted in M is the same as the system S interpreted in M.

The value mapping t → t M maps each set of derivation trees D i (the i-th component of the least solution of S in P(T (P )) n ) to the component L i of the least solution of S in P(M ) n . Taking M = T(F ), D i is mapped to the set of terms T i : the i-th component of the least solution of S in P(T (F )) n . Thus, a parsing algorithm for S can easily be transformed into one for S. Since a parsing algorithm for S produces derivation trees that represent the syntactical structure of the elements of M as specified by the system S, it will also be called a parsing algorithm for S; thus, from now on, parsing algorithms produce derivation trees and/or terms.

Here is an example of the construction of S from S.

Example 1.4 We let S be the system:

x 1 = x 2 ∪ a ∪ f (x 1 , x 2 , x 1 )
x 2 = h(g(x 1 , x 1 ), a) ∪ f (x 1 , x 2 , x 1 ).

Then S is:

x 1 = r 1,1 (x 2 ) ∪ r 1,2 ∪ r 1,3 (x 1 , x 2 , x 1 )
x 2 = r 2,1 (x 1 , x 1 ) ∪ r 2,2 (x 1 , x 2 , x 1 )

and the functions that interpret r i,j are defined by the following terms: t r1,1 := y 1 , t r1,2 := a, t r1,3 := f (y 1 , y 2 , y 3 ), t r2,1 := h(g(y 1 , y 2 ), a), t r2,2 := f (y 1 , y 2 , y 3 ).

Note that r 1,1 is interpreted as the identity function and that r 1,3 and r 2,2 are interpreted as the same function. The construction of S from S does not depend on any F -algebra for which S is to be solved, and hence neither do the derivation trees of S.

Inductive sets of properties and recognizability

This section is a mild introduction to the algebraic notion of recognizability. This notion can be defined in several equivalent ways and we begin with its most concrete characterization, based on finite sets of properties that can be checked inductively.

Properties of the words of a context-free language

Let us consider the problem of proving an assertion of the form ∀w ∈ L. P (w) where L is a context-free language, an equational set of graphs, or more generally, an equational set in an F -algebra with domain M , and where P is a property of the elements of M . Such an assertion expresses that P is universally valid on L.

Example 1.5 Let X := {f, x, y} and L ⊆ X * be the language defined as the least solution (it is actually the unique solution) of the equation L = f LL ∪ {x, y}. This language is the set of Polish prefix notations of the terms in T ({f, x, y}) where ρ(f ) = 2 and ρ(x) = ρ(y) = 0. It satisfies the assertion ∀w ∈ L. P (w) where property P (w) is defined by:

2|w| f = |w| -1 ∧ ∀u ∈ X * (u < w ⇒ 2|u| f ≥ |u|).
Here |w| denotes the length of a word w, |w| f the number of occurrences of f in w and < the strict prefix order on words. Establishing the following facts is a routine exercise:

(i) P (w) holds if w = x or w = y;

(ii) P (w) holds if w = f w 1 w 2 and P (w 1 ) and P (w 2 ) both hold.

Then the proof that ∀w ∈ L. P (w) holds can be done by induction on the length of a derivation sequence of a word w in L, relative to the context-free grammar with rules A → f AA, A → x and A → y. However this proof can also be formulated in terms of equation systems. By the Least Fixed-Point Theorem (Theorem 3.7), the least solution in P(M ) n of a system S of the form (1.4) is also the least solution of the corresponding system of inclusions:

       L 1 ⊇ p 1 (L 1 , . . . , L n ) . . . . . . L n ⊇ p n (L 1 , . . . , L n ) (1.5)
where L i ⊆ M . In the above example, Facts (i) and (ii) can be restated as the inclusion:

K P ⊇ f K P K P ∪ {x, y} (1.6)
where K P := {w ∈ X * | P (w)}. Since the language L, defined by L = f LL ∪ {x, y}, is also the least solution of (1.6), we have L ⊆ K P which yields the validity of ∀w ∈ L. P (w).

We will say that an assertion of the form ∀w ∈ L. P (w) is provable by fixedpoint induction in order to express that this method applies, i.e., that property P satisfies Facts (i) and (ii). A property Q may be universally valid on the language L without this being provable by fixed-point induction. For example consider the property Q(w) defined for w ∈ X * by |w| = 1 or w = w (where w denotes the mirror image of w) and

K Q := {w ∈ X * | Q(w)}. It is not true that f K Q K Q ⊆ K Q (since x and f belong to K Q and f xf / ∈ K Q ). However L ⊆ K Q .
Hence the valid assertion ∀w ∈ L. Q(w) is not provable by fixed-point induction.

In order to establish that Q is universally valid on L it suffices to find a property R such that:

(1) ∀w ∈ X * (R(w) ⇒ Q(w)) is true, and

(2) ∀w ∈ L. R(w) is provable by fixed-point induction.

We can take R(w) :⇐⇒ w ∈ {x, y}∪f X * {x, y}. We prove in this way a stronger assertion than ∀w ∈ L. Q(w) which was the initial goal.

Finding such R is always possible in a trivial way, by taking R(w) to mean that w belongs to L, which does not yield any proof since [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] is just what is to be proved and (2) holds in a trivial way. Hence this observation is interesting if R can be found such that (1) and (2) are "easily provable", which is not a rigorous notion. A proof method can be defined by requiring that R is expressed in a particular language and/or that the proofs of ( 1) and (2) can be done in a particular proof system. We will give below an example of such a situation (Proposition 1.6).

We generalize the notion of an assertion provable by fixed-point induction to systems of equations. Let S be an equation system of the general form (1.4) and let (L 1 , . . . , L n ) be its least solution in P(M ) n for some F -algebra M. Let (P i ) 1≤i≤n be an n-tuple of properties of elements of M , such that the assertion ∀i ∈ [n], ∀d ∈ L i . P i (d) (1.7) is true. We say that this assertion is provable by fixed-point induction if:

K Pi ⊇ p i (K P1 , . . . , K Pn ) (1.8)
for each i = 1, . . . , n, where K Pi denotes {d ∈ M | P i (d)}. It follows from the Least Fixed-Point Theorem that the validity of (1.8) for all i implies that L i ⊆ K Pi for all i, hence that the considered assertion (1.7) is true. The proof method consisting in proving (1.8) to establish (1.7) is thus sound. Let us go back to context-free languages. Let the context-free language L 1 ⊆ A * be defined as the first component of the least solution (L 1 , . . . , L n ) of an equation system S = x 1 = p 1 , . . . , x n = p n . Proposition 1.6 For every regular language K such that L 1 ⊆ K, there exists an n-tuple of regular languages (K 1 , . . . , K n ) such that K 1 ⊆ K and such that the assertion: ∀i ∈ [n], ∀d ∈ L i . d ∈ K i is provable by fixed-point induction.

Proof sketch: We have K = h -1 (N ) where h is a homomorphism of A * into a finite monoid

9 Q = Q, • Q , 1 Q and N ⊆ Q ([*Eil, *Sak]). We define K i := h -1 (h(L i )) = {h -1 (q) | q ∈ Q, h -1 (q) ∩ L i = ∅}.
Note that this definition does not depend on N .

We first prove that K 1 ⊆ K. We consider a word v in K 1 . For some word v in L 1 , we have h(v) = h(v ). Since L 1 ⊆ K, we have v ∈ K. Hence v ∈ K since h(v ) ∈ N and K = h -1 (N ). This achieves the first goal.

In order to prove that for each i we have p i (K 1 , . . . , K n ) ⊆ K i , we need only consider a monomial α of p i (i.e., the righthand side of a rule x i → α of the context-free grammar S) and prove that:

w 0 K i1 w 1 • • • K i k w k ⊆ K i , (1.9)
where α = w 0 x i1 w 1 x i2 • • • x i k w k with w 0 , . . . , w k ∈ A * . Let v j ∈ K ij for j = 1, . . . , k. There exist v 1 , . . . , v k such that h(v j ) = h(v j ) and v j ∈ L ij for each j.

Hence the word v = w 0 v 1 w 1 • • • v k w k belongs to L i , because (L 1 , . . . , L n ) is a solution of S.

Letting v = w 0 v 1 w 1 • • • v k w k we have h(v) = h(v ) hence v ∈ K i .
This proves inclusion (1.9) and completes the proof of the proposition.

This result shows that assertions of the form L ⊆ K where L is a contextfree language and K is a regular one can be proved by fixed-point induction. The proofs that a "guessed" n-tuple (K 1 , . . . , K n ) satisfies K 1 ⊆ K and the inclusions K i ⊇ p i (K 1 , . . . , K n ) establish that L 1 ⊆ K and use only algorithms on finite automata: Boolean operations, concatenation and emptiness test.

Some properties of series-parallel graphs

We now show that fixed-point induction can also be used for proving universal properties of equational sets of graphs. We use the example of the set of seriesparallel graphs defined by Equation (1.3) considered in Section 1.1.3: S = (S S) ∪ (S • S) ∪ {e} where S ⊆ J d 2 . We will prove the assertions ∀G ∈ S. P i (G), where the properties P i are defined as follows:

P 1 (G) :⇐⇒ G is connected, P 2 (G) :⇐⇒ G is bipolar, P 3 (G) :⇐⇒ G is planar, P 4 (G) :⇐⇒ G has no directed cycle.
A directed graph G with two sources denoted by src G (1) and src G (2) (cf. Section 1. 1.3) is bipolar if it has no directed cycle and every vertex belongs to a directed path from src G [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] to src G (2).

Following the same method as for the language L of Example 1.5, we need only prove that P i (e) holds and that, for all graphs G, H in J d 2 : P i (G) ∧ P i (H) implies P i (G H) ∧ P i (G • H).

These facts are clearly true for properties P 1 and P 2 . The assertions that every graph in S satisfies P 1 on the one hand and P 2 on the other are thus provable by fixed-point induction, hence P 1 and P 2 are universally valid on S.

Property P 3 is not provable in this way because it is not true that, for all graphs G, H in J d 2 , P 3 (G) ∧ P 3 (H) implies P 3 (G H). For a counterexample, take H to be an edge, G to be K 5 minus one edge (K 5 is a complete simple undirected graph with 5 vertices) and equipped with sources in such a way that G H is isomorphic to K 5 , which is non-planar. However, G and H are both planar, hence satisfy P 3 .

For proving that every series-parallel graph is planar, we can use the property Q saying that a graph has a planar drawing with its two sources on the external face. (The books [*Die] and [*MohaTho] give formal definitions about graphs on surfaces.) This property is provable by fixed-point induction (with respect to the equation defining S), hence it is true for all graphs in S. Since Q(G) implies P 3 (G) for all graphs G in J d 2 , we obtain the announced result. The case of property P 4 (the absence of directed cycles) is similar. The assertion that every graph in S satisfies P 4 is not provable by fixed-point induction, however it is true. For proving it, one takes the stronger property P 2 considered above.

This proof technique can be applied to systems of equations (and not only to single equations) and to graph properties expressed in monadic second-order logic (see Section 1.3). More precisely, for every such graph property P and every equational set of graphs L:

(1) we can decide whether or not P is universally valid on L,

(2) if P is, then we can build a set of auxiliary properties, like the sets K 1 , . . . , K n in Proposition 1.6, that yields a proof by fixed-point induction of the universal validity of P on L.

These constructions and the verification of conditions like (1.8) can be done by algorithms.

Inductive sets of properties

We now consider properties that are not necessarily universally valid on the considered sets of graphs, so that they raise decision problems. We will consider a graph property as a function from graphs to {True, False}.

Example 1.7 Cographs.

The property E(G) that a cograph G (cographs are defined in Section 1.1.2) has an even number of vertices is not universally valid. However, it satisfies the following rules:

E(1) = False, E(G ⊕ H) = (E(G) ⇔ E(H)), E(G ⊗ H) = (E(G) ⇔ E(H)).
For Boolean values p and q, p ⇔ q is defined as usual as ((p ∧ q) ∨ (¬p ∧ ¬q)). It follows that if a cograph G is the value of a term t in T ({⊕, ⊗, 1}) (we denote this by G = val (t)), then the validity of E(G) can be determined by computing E(val (t )) for all subterms t of t, by starting from the smallest ones. This type of computation can be done by automata on terms that we will present in Section 1.2.4.

The property F (G) defined as "G has an even number of edges", can be checked in a similar way by computing simultaneously E(val (t )) and F (val (t )) for every subterm t of t. This computation uses the following rules:

F (1) = True, F (G ⊕ H) = (F (G) ⇔ F (H)), F (G ⊗ H) = F (G) ⇔ F (H) ∧ E(G) ∨ E(H) ∨ F (G) ⇔ ¬F (H) ∧ ¬E(G) ∧ ¬E(H) .
Hence, F (G) can be checked with the help of E(G) as additional information.

We now generalize this computation method. We introduce a definition relative to an arbitrary F -algebra M. Let P be a set of properties, i.e., of mappings: M → {True, False}. We say that P is F-inductive if for every P ∈ P, for every f ∈ F of arity n > 0, and for every m 1 , . . . , m n in M , the Boolean value P (f M (m 1 , . . . , m n )) can be computed by a fixed Boolean expression depending on P and f , in terms of finitely many Boolean values Q(m i ) with Q in P and i = 1, . . . , n.

In the previous example, the set of properties {E, F } is {⊕, ⊗}-inductive for the algebra of cographs, but the set {F } is not. The computation of F (G ⊗ H) can be expressed by:

F (G ⊗ H) = B(E(G), F (G), E(H), F (H))

INDUCTIVE SETS OF PROPERTIES AND RECOGNIZABILITY 35

where B(p 1 , p 2 , p 3 , p 4 ) is the Boolean expression: (p 2 ⇔ p 4 ) ∧ (p 1 ∨ p 3 ) ∨ (p 2 ⇔ ¬p 4 ) ∧ (¬p 1 ∧ ¬p 3 ) .

In order to have a uniform notation, if P is finite and is enumerated as {P 1 , . . . , P k }, we write:

P i (f M (m 1 , . . . , m n )) =
B i,f P 1 (m 1 ), . . . , P k (m 1 ), P 1 (m 2 ), . . . , P k (m 2 ), . . . , P 1 (m n ), . . . , P k (m n ) to formalize the way P i (f M (m 1 , . . . , m n )) can be computed from the Boolean values P i (m j ). In this writing, each B i,f is a Boolean expression in the propositional variables p h,j , 1 ≤ h ≤ k, 1 ≤ j ≤ n, and P h (m j ) is substituted in B i,f for p h,j .

An important theorem is the following one:

Theorem 1.8 (Filtering Theorem, concrete version) Let M be an F -algebra and P be a finite F -inductive set of properties. For every equational set L of M, for every P in P, the set L P := {x ∈ L | P (x)} is equational. If the Boolean expressions involved in the definition of the inductivity of P are given, then the construction of a system of equations defining L P from one defining L is effective, i.e., can be done by an algorithm.

The classical result saying that the intersection of a context-free language and a regular one is context-free is a special case of this theorem. Let us consider the language L of Example 1.5 defined by the equation L = f LL ∪ {x, y}. From this language we want to keep only the words whose length is a multiple of 3. For i ∈ {0, 1, 2}, we let L i := {w ∈ L | mod 3 (|w|) = i}. The triple (L 0 , L 1 , L 2 ) is the least solution (and actually also the unique one) of the system:

     L 0 = f L 0 L 2 ∪ f L 1 L 1 ∪ f L 2 L 0 , L 1 = f L 0 L 0 ∪ f L 1 L 2 ∪ f L 2 L 1 ∪ {x, y}, L 2 = f L 0 L 1 ∪ f L 1 L 0 ∪ f L 2 L 2 .
It follows that the language L 0 is context-free. A similar example for cographs is System (1.2) in Section 1.1.2 (cf. the discussion after (1.2)).

Corollary 1.9 Let M and P be as in Theorem 1.8. For every equational set L of M, one can decide whether or not a property P in P is universally valid on L, and whether or not it is satisfied by some element of L.

Proof sketch: We assume that L is given by a system of equations S. By using Theorem 1.8 we can construct a system S that defines L P . As noted in Section 1.1.4, we can test the emptiness of the components of the least solution of S , hence in particular of L P . We can thus decide if P is satisfied by some element of L.

Since P is inductive, so is P ∪{¬P }. We can apply the previous result to ¬P . Then P is universally valid on L if and only if L ¬P = ∅, which is decidable.

Example 1.10 We again let L be the language of Example 1.5 defined by the equation L = f LL ∪ {x, y}. We know from this example that every word of L has odd length (because |w| = 2|w| f + 1 for every w ∈ L), but we will see how the algorithm of Corollary 1.9 "discovers" this fact. Let K 0 and K 1 be the sets of words in L of even and odd length respectively. These languages are defined by the two equations:

K 0 = f K 0 K 1 ∪ f K 1 K 0 K 1 = f K 0 K 0 ∪ f K 1 K 1 ∪ {x, y}.
It is easy to see that K 0 is empty (just look at the corresponding context-free grammar). Hence K 1 = L and every word of L has odd length.

It is useful to have a proof by fixed-point induction that a property is universally valid on an equational set although an algorithm can also give the answer, because a proof is more informative than the yes or no answer of an algorithm: it shows the properties of all components of the solution of the equation system that "contribute" to the validity of the proved property. This is clear in the case of Proposition 1.6.

We now consider one more example about graphs.

Example 1.11 The 2-colorability of series-parallel graphs.

We illustrate Theorem 1.8 with the 2-colorability of series-parallel graphs. A proper vertex k-coloring of a graph assigns to each vertex a color, i.e., an element of {1, . . . , k} such that two adjacent vertices have different colors. A graph is k-colorable if it has a proper vertex k-coloring. We consider three properties of a series-parallel graph G defined as follows:

γ 2 (G) :⇐⇒ G is 2-colorable, σ(G) :⇐⇒ G is 2-colorable with the two sources of the same color, δ(G) :⇐⇒ G is 2-colorable with the two sources of different colors.

The set of series-parallel graphs is defined by Equation (1.3) S = (S S) ∪ (S • S) ∪ {e} in the algebra J d 2 , , •, e . Property γ 2 is not universally valid on S because γ 2 (e (e•e)) = False. 10 The set {γ 2 } is not inductive because γ 2 (e) = True, γ 2 (e•e) = True, γ 2 (e e) = True and γ 2 (e (e • e)) = False. It follows that the validity of γ 2 (G H) cannot be deduced from those of γ 2 (G) and γ 2 (H). Hence, as in the case of property F for cographs in Example 1.7, we need additional properties. They will be σ and δ. The set {σ, δ} is inductive; this is clear from the following facts:

σ(G • H) = (σ(G) ∧ σ(H)) ∨ (δ(G) ∧ δ(H)), δ(G • H) = (δ(G) ∧ σ(H)) ∨ (σ(G) ∧ δ(H)), σ(G H) = σ(G) ∧ σ(H), δ(G H) = δ(G) ∧ δ(H).
(1.10) One can thus compute for every term t in T ({ , •, e}) the pair of Boolean values (σ(val (t)), δ(val (t))) by induction on the structure of t (where val (t) is the graph in J d 2 defined by a term t). From the pair of Boolean values associated with a term t such that val (t) = G, one can decide whether γ 2 (G) holds or not, since for every graph G in J d 2 , γ 2 (G) is equivalent to σ(G) ∨ δ(G). This computation can be formalized as the run of a finite deterministic automaton on t because the considered inductive set of properties, here {σ, δ}, is finite. The finiteness of a set of inductive properties is the essence of the notion of recognizability that we now introduce informally.

Recognizability

In Formal Language Theory, the recognizability (or regularity) of a set of finite or infinite words or terms means frequently that this set is defined by a finite automaton of some kind. Recognizable sets of finite words and terms are defined by finite deterministic automata and this fact yields algebraic characterizations of recognizability in terms of homomorphisms into finite algebras. In particular, a language L ⊆ A * is recognizable if and only if L = h -1 (N ) where h : A * → Q is a monoid homomorphism, Q is a finite monoid and N ⊆ Q. (We have used this fact in the proof of Proposition 1.6).

This characterization has the advantage of being extendable in a meaningful way to any algebra, whereas the notion of automaton has no immediate generalization to arbitrary algebras. Furthermore, it fits very well with the notion of an equational set. The Filtering Theorem shows this, as we will explain in Section 1.2.5.

Following Mezei and Wright [MezWri], we say that a subset L of an F -algebra M (where F is finite) is recognizable if L = h -1 (N ) for some homomorphism of F -algebras h : M → Q where Q is a finite F -algebra and N ⊆ Q. We will denote by Rec(M) the family of recognizable subsets of M.

The above definition of recognizability of L is equivalent to saying that the property P L of the elements of M such that P L (x) is True if and only if x ∈ L, belongs to a finite F -inductive set of properties. In fact, assume that L is recognizable and let Q = {q 1 , . . . , q k }. Define for each i ∈ [k] the property P i by: P i (m) :⇐⇒ h(m) = q i . Since h(f M (m 1 , . . . , m n )) = f Q (h(m 1 ), . . . , h(m n )), the Boolean value P i (f M (m 1 , . . . , m n )) can be computed from the Boolean values P h (m j ), by a Boolean expression. Thus, {P 1 , . . . , P k } is F -inductive in M. Hence, also the set {P L , P 1 , . . . , P k } is inductive, because P L (m) = qi∈N P i (m). The other direction of the equivalence is discussed in Section 1.2.5. Proposition 1.6 also holds in general for recognizable sets instead of regular languages (with exactly the same proof, replacing A * by M). Thus, inclusions L ⊆ K with L ∈ Equat(M) and K ∈ Rec(M) are provable by fixed-point induction, using auxiliary properties that correspond to recognizable subsets of M . Together with Corollary 1.9, this shows that the analogues of statements ( 1) and (2) at the end of Section 1.2.2 hold for properties that correspond to recognizable sets, in arbitrary algebras.

We now recall the link between recognizability for subsets of T (F ) and finite automata on terms (i.e., bottom-up finite tree automata). Let us consider a set L ∈ Rec(T(F )) defined as L = h -1 (N ) where h is the unique homomorphism: T(F ) → Q, Q is a finite F -algebra and N ⊆ Q. (Note that h(t) = t Q ). The pair (Q, N ) corresponds to a finite deterministic and complete F -automaton A (Q, N ) (the general definitions can be found in the book [*Com+] and in the book chapter [*GecSte], Section 3.3) with set of states Q, set of accepting states N and transitions consisting of the tuples (a 1 , . . . , a ρ(f ) , f, a) such that f ∈ F , a 1 , . . . , a ρ(f ) , a ∈ Q and a = f Q (a 1 , . . . , a ρ(f ) ).

On each term t in T (F ), the automaton A = A (Q, N ) has a unique ("bottom-up") run, defined as a mapping run A ,t : Pos(t) → Q such that run A ,t (u) = h(t/u) for every position11 u of t. Hence t is accepted by A if and only if h(t) = run A ,t (root t ) ∈ N .

Conversely, if L is the set of terms in T (F ) accepted by a finite, possibly not deterministic, automaton B, then it is also accepted by a finite deterministic and complete automaton A (that one can construct from B) and there is a unique pair (Q, N ) such that A (Q, N ) = A . Hence, L is recognizable in T(F ).

By a recognizable set of graphs, we will mean a subset of a graph algebra that is recognizable with respect to that algebra. No notion of "graph automaton" arises from this definition. However, we obtain finite automata accepting the sets of terms that denote the graphs of recognizable sets (this is true because the signature is finite). We will give a more precise statement in Theorem 1.12 below.

From inductive sets to automata

Let P = {P 1 , . . . , P k } be a finite inductive set of properties on an F -algebra M where F is finite. We associate with P a finite deterministic and complete F -automaton A = A (Q, N ) as follows. Its set of states is Q = {True, False} k ; its transitions, i.e., the operations of Q, are defined in such a way that for every f in F of arity n, we have: f Q (q 1 , . . . , q n ) = q if and only if q i = (a 1,i , . . . , a k,i ), q = (b 1 , . . . , b k ) belong to {True, False} k and (we use the notation introduced in Section 1.2.3): b i = B i,f (a 1,1 , . . . , a k,1 , a 1,2 , . . . , a k,2 , . . . , a 1,n , . . . , a k,n ).

It follows that for every t ∈ T (F ), t Q = (P 1 (t M ), . . . , P k (t M )) ∈ {True, False} k .

INDUCTIVE SETS OF PROPERTIES AND RECOGNIZABILITY 39

Hence if we want to specify by an automaton the set of objects m ∈ M that satisfy P 3 (m) (to take an example), we take as set N of accepting states the set of Boolean vectors (b 1 , . . . , b k ) such that b 3 = True. More precisely, a term t ∈ T (F ) is accepted by A if and only if t M has property P 3 .

This proves the implication (2) ⇒ (3) in the next result. The other direction also holds, provided M is generated by F (as defined in Section 1.1.4).

Theorem 1.12 Let M be an F -algebra generated by F , where F is finite, and let L ⊆ M . The following are equivalent:

(1) L is recognizable in M,

(2) L = {m ∈ M | P (m)} where P belongs to a finite F -inductive set of properties,

(3) the set of terms t in T (F ) such that t M belongs to L is recognizable in T(F ), equivalently, is the set accepted by a finite F -automaton.

The equivalence of ( 1) and ( 2) gives a concrete meaning to the algebraic notion of recognizability (and does not need M being generated by F ). The implication (1) ⇒ (2) was shown in Section 1.2.4. The other direction follows from the above discussion. If h : M → Q is defined by h(m) := (P 1 (m), . . . , P k (m)), then h is a homomorphism from M to the finite F -algebra Q, because P is inductive. And, e.g., h -1 (N ) = {m ∈ M | P 3 (m)}.

Let L be an equational set of M, defined by an equation system S = x 1 = p 1 , . . . , x n = p n , and assume that L ⊆ {m ∈ M | P 3 (m)}. The equivalence of ( 1) and ( 2) implies that such an inclusion is provable by fixed-point induction, using auxiliary properties R 1 , . . . , R n that belong to a finite inductive set of properties. In fact, considering the proof of Proposition 1.6, with the above definition of Q, N and h, it can be seen that every R i is a Boolean combination of P 1 , . . . , P k and hence P ∪ {R 1 , . . . , R n } is an inductive set of properties.

The equivalence of ( 1) and (3) implies that the membership in a recognizable set of an element of M , given as t M , for some term t in T (F ), or the validity of P (t M ) where P belongs to a finite inductive set of properties, can be checked in time O(|t|), i.e., in time linear in the size of t.

Let us go back to Example 1.11 about the 2-colorability of series-parallel graphs. For the inductive set P = {σ, δ} we obtain the set of states Q = {True, False} × {True, False} = {(σ, δ), (σ, δ), (σ, δ), (σ, δ)}, where, for readability, we use σ and δ to denote True and σ and δ to denote False. For every state q ∈ Q we let S q be the set of series-parallel graphs G such that (σ(G), δ(G)) = q, i.e., S q = h -1 (q) ∩ S with h(G) = (σ(G), δ(G)) (cf. the proof of Proposition 1.6). Thus, S σ,δ is the set of series-parallel graphs that satisfy σ and δ, S σ,δ the set of those that satisfy σ and not δ, S σ,δ the set of those that satisfy δ and not σ, and S σ,δ the set of those that satisfy neither σ nor δ. From Properties (1.10) we obtain the operations Q , • Q and the constant e Q , which determine the transitions of the automaton A . For example, since the graph defined by e satisfies δ and not σ, we have e Q = (σ, δ). As another example, if G = H • K and both H and K satisfy δ and not σ, then G satisfies σ and not δ; hence • Q ((σ, δ), (σ, δ)) = (σ, δ).

From the defining equation S = (S S) ∪ (S • S) ∪ e and the transitions of A we obtain the following system of equations that define the sets S σ,δ , S σ,δ , S σ,δ and S σ,δ (we omit parentheses around terms like S σ,δ S σ,δ for better readability):

(a) S σ,δ = S σ,δ S σ,δ ∪ S σ,δ • S σ,δ ∪ S σ,δ • S σ,δ ∪ S σ,δ • S σ,δ ∪ S σ,δ • S σ,δ ∪ S σ,δ • S σ,δ (b) S σ,δ = e ∪ S σ,δ S σ,δ ∪ S σ,δ S σ,δ ∪ S σ,δ S σ,δ ∪ S σ,δ • S σ,δ ∪ S σ,δ • S σ,δ (c) S σ,δ = S σ,δ S σ,δ ∪ S σ,δ S σ,δ ∪ S σ,δ S σ,δ ∪ S σ,δ • S σ,δ ∪ S σ,δ • S σ,δ (d) S σ,δ = S σ,δ S σ,δ ∪ S σ,δ S σ,δ ∪ S σ,δ S σ,δ ∪ S σ,δ S σ,δ ∪ S σ,δ S σ,δ ∪ S σ,δ S σ,δ ∪ S σ,δ S σ,δ ∪ S σ,δ S σ,δ ∪ S σ,δ S σ,δ ∪ S σ,δ • S σ,δ ∪ S σ,δ • S σ,δ ∪ S σ,δ • S σ,δ ∪ S σ,δ • S σ,δ ∪ S σ,δ • S σ,δ ∪ S σ,δ • S σ,δ ∪ S σ,δ • S σ,δ
These equations are constructed as follows. Since e Q = (σ, δ), the constant symbol e is put in the righthand side of the equation that defines S σ,δ and nowhere else. Moreover, for f ∈ { , •}, if f Q (q 1 , q 2 ) = q, then we put the monomial f (S q1 , S q2 ) in the righthand side of the equation that defines S q . Thus, S σ,δ • S σ,δ is in the righthand side of Equation (c).

Since we have e in the righthand side of Equation (b), we have S σ,δ = ∅. Using this fact and since we have the term S σ,δ • S σ,δ in the righthand side of Equation (c), we have S σ,δ = ∅. And by these facts and since we have S σ,δ S σ,δ in the righthand side of Equation (d), we have S σ,δ = ∅. Since every term in the righthand side of Equation (a) contains S σ,δ , we have S σ,δ = ∅. This proves that no series-parallel graph has one coloring of type σ and another one of type δ. Moreover, according to the proof of Proposition 1.6, this property is provable by fixed-point induction, as the reader can easily check. Using this and the commutativity of , we can simplify the system into the following one:

(b ) S σ,δ = e ∪ S σ,δ S σ,δ ∪ S σ,δ • S σ,δ ∪ S σ,δ • S σ,δ (c ) S σ,δ = S σ,δ S σ,δ ∪ S σ,δ • S σ,δ ∪ S σ,δ • S σ,δ (d ) S σ,δ = S σ,δ S σ,δ ∪ S σ,δ S σ,δ ∪ S σ,δ S σ,δ ∪ S σ,δ S σ,δ ∪ S σ,δ • S σ,δ ∪ S σ,δ • S σ,δ ∪ S σ,δ • S σ,δ ∪ S σ,δ • S σ,δ ∪ S σ,δ • S σ,δ
Thus, this construction proves that every series-parallel graph either has no 2coloring (it is then generated by S σ,δ ) or has one of type σ and none of type δ (it is generated by S σ,δ ) or has one of type δ and none of type σ (it is generated by S σ,δ ). Let us for clarity replace S σ,δ by T σ and S σ,δ by T δ . Then the set T of 2-colorable series-parallel graphs is defined by the equation system:

     T = T σ ∪ T δ T σ = T σ T σ ∪ T σ • T σ ∪ T δ • T δ T δ = e ∪ T δ T δ ∪ T σ • T δ ∪ T δ • T σ
The construction of this system is based on Properties (1.10). A similar construction can be done for every equation system and every finite inductive set of properties, which proves the Filtering Theorem (Theorem 1.8).

Monadic second-order logic

We now introduce monadic second-order logic, a logical language with which we will specify finite inductive sets of properties. It is actually a favorite language among logicians because it is decidable for many sets of (finite or infinite) structures. Furthermore, it is suitable for expressing numerous graph properties.

Monadic second-order graph properties

We first explain how a graph can be made into a logical structure, hence can be a model of a sentence. For every graph G, we let G be the relational structure 12,13 V G , edg G with domain V G , the set of vertices. Its second component is the binary relation edg G ⊆ V G × V G , such that (x, y) ∈ edg G if and only if there exists an edge from x to y if G is directed, and an edge between x and y if G is undirected.

The classical undirected graphs K n and K n,m are represented by the following relational structures14 : Properties of a graph G can be expressed by sentences 15 of relevant logical languages, that are interpreted in G . For example, if G is a directed graph, then G |= ∀x∃y, z(edg(y, x) ∧ edg(x, z))

K n := [n],
if and only if every vertex of G has at least one incoming edge and at least one outgoing edge (we may have y = z = x). If G is a simple undirected graph, then we have:

G |= ∀x ¬edg(x, x) ∧ ¬∃w, x, y, z edg(w, x) ∧ edg(x, y) ∧ edg(y, z)

∧ ¬edg(w, y) ∧ ¬edg(w, z) ∧ ¬edg(x, z)

if and only if G has no loop and no induced subgraph isomorphic to P 4 (P 4 is the graph

•-•-•-•).
If G is assumed finite and nonempty, this property expresses that it is a cograph. This is an alternative characterization of cographs that has no immediate relation with the grammatical definition given in Section 1.1.2.

A simple graph G is completely defined by the relational structure G : we will say that the representation of G by G is faithful. This representation is not faithful for graphs with multiple edges: the graphs e and e e (we use here the notation of Section 1.1.3) are not the same but the structures e and e e are. The graph properties expressed by logical formulas via the structures G are necessarily independent of the multiplicity of edges. We will present in Section 1.8 a representation of a graph G by a relational structure denoted G that is faithful, where each edge of G is also an element of the domain of G . The incidence between edges and vertices is represented by two binary relations in G if G is directed and by only one if G is undirected. By using this alternative representation, we will be able to express properties that distinguish multiple edges.

The above two examples use first-order formulas whose variables denote vertices. Monadic second-order formulas have a richer syntax and wider expressive power. They also use variables denoting sets of vertices. Uppercase variables will denote sets of vertices, and lowercase variables will denote individual vertices. The property:

G |= ∃X ∃x. x ∈ X ∧ ∃y. y / ∈ X ∧ ∀x, y(edg(x, y) ⇒ (x ∈ X ⇔ y ∈ X))

holds if and only if G is not connected. (We consider the empty graph as connected.) In this sentence, X is a set variable. Let γ 3 be the sentence:

∃X, Y, Z Part(X, Y, Z) ∧ ∀x, y edg(x, y) ∧ x = y ⇒ ¬ x ∈ X ∧ y ∈ X) ∧ ¬ x ∈ Y ∧ y ∈ Y ∧ ¬ x ∈ Z ∧ y ∈ Z
where Part(X, Y, Z) expresses that (X, Y, Z) is a partition 16 of the domain. The formula Part(X, Y, Z) is written as follows:

∀x x ∈ X ∨ x ∈ Y ∨ x ∈ Z ∧ ¬(x ∈ X ∧ x ∈ Y ) ∧ ¬(x ∈ Y ∧ x ∈ Z) ∧ ¬(x ∈ X ∧ x ∈ Z) .
Then G |= γ 3 if and only if G is 3-colorable. That the ends of an edge are in different sets X, Y, Z means that they have different colors.

For each integer k, one can construct a similar sentence γ k such that, for every graph G, we have G |= γ k if and only if G is k-colorable.

Many graph constructions can be expressed in terms of basic ones like choosing subsets and computing transitive closures of binary relations. The example of 3-colorability illustrates the first of these basic constructions. We have given a sentence expressing non-connectivity. Its negation expresses connectivity, hence, a property of the transitive closure of the relation edg G ∪ edg -1 G . We now give an explicit construction of the transitive closure of an arbitrary binary relation.

Let R be a binary relation that is either a relation of the considered relational structure ( G or a more general one) or is defined by a formula R(u, v) with free variables u and v. We say that a set X is R-closed if it satisfies the condition ∀u, v u ∈ X ∧ R(u, v) ⇒ v ∈ X . The formula ϕ(x, y), defined as

∀X(x ∈ X ∧ "X is R-closed" ⇒ y ∈ X)
(where "X is R-closed" is to be replaced by the formula expressing this condition), expresses that (x, y) belongs to R * , the reflexive and transitive closure of R, i.e., that there exists a finite sequence z 1 , . . . , z n , such that x = z 1 , y = z n and (z i , z i+1 ) ∈ R for all i = 1, . . . , n -1. We sketch the proof of this claim. If x = z 1 , y = z n with (z i , z i+1 ) ∈ R for all i, then for every R-closed set X such that x belongs to X, we have z i ∈ X for all i = 1, . . . , n, hence y ∈ X and ϕ(x, y) holds. Conversely, if ϕ(x, y) holds then one takes X = {z | (x, z) ∈ R * }. It is R-closed, hence y ∈ X and (x, y) belongs to R * .

In order to have a uniform notation, we denote by TC[R; x, y] this formula ϕ(x, y). We can use it to build a formula with free variable Y expressing that G[Y ], the induced subgraph of G with set of vertices Y , is connected. We let CONN(Y ) be the formula

∀x, y x ∈ Y ∧ y ∈ Y ⇒ TC[R; x, y]
where R is the relation defined by the formula ϕ R with free variables u, v and Y :

u ∈ Y ∧ v ∈ Y ∧ edg(u, v) ∨ edg(v, u) .
The variable Y is free in ϕ R , hence it is also free in the monadic second-order formula TC [R; x, y]. It is clear that the formula CONN(Y ) expresses the desired property. This formula can be used for expressing further properties. The following sentence expresses that an undirected graph G has a cycle with at least 3 vertices:

∃x, y, z x = y ∧ y = z ∧ x = z ∧ edg(x, z) ∧ edg(z, y) ∧ ∃Y z / ∈ Y ∧ x ∈ Y ∧ y ∈ Y ∧ CONN(Y ) .
Together with the expressibility of connectivity, we can thus express that a simple undirected graph is a tree 17 . Aiming at the expression of planarity, we examine the monadic second-order expressibility of minor inclusion. We consider undirected graphs. We say that H is a minor of G, denoted by H ¢ G if and only if H is obtained from a subgraph G of G by edge contractions. A graph G is planar if and only if it has no minor isomorphic to K 5 or to K 3,3 . (This is a variant due to Wagner of a well-known result by Kuratowski; it is proved in the books [*Die] and [*MohaTho]). Lemma 1.13 Let H be a simple, loop-free, undirected graph with set of vertices [n]. A graph G contains a minor isomorphic to H if and only if there are in G pairwise disjoint nonempty sets of vertices Y 1 , . . . , Y n such that each graph G[Y i ] is connected and for every edge of H between i and j, there exists an edge in G between u and v such that u ∈ Y i and v ∈ Y j .

Corollary 1.14 For every graph H as in Lemma 1.13, there exists a monadic second-order sentence MINOR H such that, for every undirected graph G, we have G |= MINOR H if and only if G has a minor isomorphic to H.

Proof:

The construction follows from Lemma 1.13. One takes for MINOR H the sentence:

∃Y 1 , . . . , Y n 1≤i≤n (∃y. y ∈ Y i ) ∧ CONN(Y i ) ∧ 1≤i<j≤n ¬∃y y ∈ Y i ∧ y ∈ Y j ∧ (i,j)∈edg H ∃u, v u ∈ Y i ∧ v ∈ Y j ∧ edg(u, v) .
Corollary 1.15 An undirected graph is planar if and only if it satisfies the sentence ¬MINOR K5 ∧ ¬MINOR K3,3 .

With this collection of examples, the reader should have a good idea of how one can express graph properties in monadic second-order logic. However, not all graph properties can be expressed in this language. Here are some properties of a graph G and of subsets X, Y of its vertex set V G that are not monadic second-order expressible. 17 A tree is a nonempty connected undirected graph without cycles. This last condition implies that a tree has no loops and no multiple edges. The absence of loops is expressed by the sentence ∀x(¬edg(x, x)), but the absence of multiple edges cannot be expressed by a sentence interpreted in G . There are however some differences between these properties, and we have remedies in some cases. For Property P 1 , the remedy consists in extending the language by adding a set predicate, Even(X), expressing that the set X has even cardinality. All results that we will prove for monadic second-order logic hold for the extended language called counting modulo 2 monadic second-order logic. The notation C 2 MS will refer to it (and MS will refer to formulas written without cardinality predicates).

Property P 5 is actually expressible by a sentence of monadic second-order logic that additionally uses quantifications on sets of edges, and the incidence relations between edges and vertices. This language is based on the representation of a graph G by the richer relational structure than G that we will define in Section 1.8 and denote by G . It can be viewed as another extension of monadic second-order logic that we will denote by MS 2 where the index 2 recalls that there are two types of elements in the domain of G , vertices and edges. There are some significant differences between the languages MS and MS 2 but our main results presented in the next sections and their applications to the construction of fixed-parameter tractable algorithms have formulations that apply to MS 2 as well as to MS.

Concerning the other three properties, there is nothing to do. Adding new set predicates, say Card Prime (X) expressing that |X| is a prime number, or EqCard (X, Y ) expressing that |X| = |Y |, or Auto(X) expressing that G[X] has a non-trivial automorphism, yields extensions of monadic second-order logic for which the results to be presented in Sections 1.4, 1.5 and 1.6 fail.18

Monadic second-order logic and recognizability

Logical sentences express properties of relational structures of the appropriate type. They can also be viewed as finite specifications of sets of structures, namely, their sets of models. We first make precise the corresponding terminology. For a logical language L (such as MS, C 2 MS, or MS 2 ), we say that a property of relational structures over a fixed finite set of relation symbols is L-expressible if it can be expressed by a sentence of L. A set L of such structures is L-definable if the membership of a structure in L is L-expressible. These definitions are applicable to graphs represented by relational structures. Hence, with respect to a fixed representation, we will say that a graph property is L-expressible. Examples have been given above. Let C be a set of graphs; an element of C will be called a C-graph. We will say that a set of graphs L ⊆ C is an L-definable subset of C (or, an L-definable set of C-graphs) if the membership of a graph in L is L-expressible and the considered representation is faithful for C-graphs. Hence, the connectedness of a graph G is MS-expressible with respect to its representation by G , but the set of connected graphs is not an MS-definable set of graphs, because this representation is not faithful for graphs with multiple edges. On the other hand, the set of connected simple graphs is an MS-definable set of simple graphs. In the first case C is the set of all graphs, and in the second case it is the set of all simple graphs.

Let F be a finite signature. There is a bijection between T (F ) and a set of labelled trees that are simple graphs. It follows that every term t in T (F ) can be faithfully represented by a relational structure t over a finite set of relations (the binary edge relation of the tree, and a unary relation for each label). We say that a set L ⊆ T (F ) is MS-definable if there exists an MS sentence ϕ such that L = {t ∈ T (F ) | t |= ϕ}. Since the property that a finite relational structure is isomorphic to t for some term t in T (F ) is itself MS-expressible, the set L ⊆ T (F ) is MS-definable19 if and only if the set of relational structures that are isomorphic to some structure t for t in L is MS-definable.

The following fundamental theorem is due to Doner [Don] and to Thatcher and Wright [ThaWri] (see Section 1.10 for related references). We will prove it in Chapters 5 and 6. Theorem 1.16 A set of terms over a finite signature is MS-definable if and only if it is recognizable, i.e., accepted by a finite automaton.

For the two graph algebras G u := G u , ⊕, ⊗, 1 and J d 2 := J d 2 , , •, e whose operations are defined respectively in Sections 1.1.2 and 1.1.3, we have the following results: Proposition 1.17 Every MS-definable subset of G u is recognizable in G u . Every MS 2 -definable subset of J d 2 is recognizable in

J d 2 .
This proposition is a corollary of the Recognizability Theorem (stated below in Section 1.4.3) that applies to algebras that extend G u and J d 2 .

Two graph algebras

Up to now, we have only given two examples of graph algebras, the algebra G u in which we have defined the cographs and the algebra J d 2 in which we defined the series-parallel graphs. These algebras are subalgebras of two larger algebras that we now define. They will differ by the way in which graphs will be composed: the first algebra has operations that "bridge" two disjoint graphs by creating edges between them (vertex labels determine how these edges are created) and the second one has operations that "glue" two disjoint graphs by fusing certain vertices specified by labels. The operations from which cographs and seriesparallel graphs are defined illustrate these two types of graph composition.

The algebra of simple graphs with ports

Our first graph algebra, called the VR algebra20 , generalizes the algebra G u . In order to define more powerful edge creating operations than ⊗, we will use vertex-labelled graphs. We let A be a countable set of labels. In this overview chapter, we take it equal to N , the set of nonnegative integers. This will simplify some statements; in Chapter 2 we will assume that N ⊆ A. We let G be the set of (abstract) simple directed graphs21 . This set contains G u because for simple graphs we consider an undirected edge as a pair of directed opposite edges. This is coherent with the representation of a graph G by G defined in Section 1.3.1. We let GP be the set of (abstract) graphs with ports, or p-graphs in short, defined as pairs G = G • , port G where G • ∈ G and port G is a mapping V G • → A. If port G (u) = a ∈ A we say that u is an a-port of G and that a is its port label. Every graph in G will be considered as the p-graph, all vertices of which are 1-ports; hence G ⊆ GP. The operations on GP are the following ones. First, the disjoint union22 :

G ⊕ H := G • ⊕ H • , port G ∪ port H .
Then we define unary operations that manipulate port labels. For a, b ∈ A and G = G • , port G we let:

relab a→b (G) := G • , port where port(u) := if port G (u) = a then b else port G (u).
The next unary operations add directed edges. 23 For a = b, we define --→ add a,b (G) as G , port G where

V G = V G and edg G is edg G • ∪ {(u, v) | (port G (u), port G (v)) = (a, b)}.
This operation adds an edge linking u to v whenever u is an a-port and v is a b-port, unless there already exists one (we only consider simple graphs). It does not add loops. We let 1 be a constant symbol denoting a single vertex that is a 1-port and we let 1 denote the same graph with a loop. The only way to define loops is by means of these constant symbols. Moreover, we let ∅ be a constant symbol denoting the empty graph, that we denote also by ∅. We denote empty sets 24 by the different symbol ∅.

operation that transforms G into --→ add b,a ( --→ add a,b (G)). 24 We consider that an empty set of numbers is not equal to an empty set of words.

We obtain the algebra GP of (abstract) p-graphs, also called the VR algebra. Its domain is GP and its signature, denoted by F VR , is the countable set of operations introduced above. For every term t ∈ T (F VR ), we denote by t GP its value, which is a p-graph, computed according to the definitions of the operations of F VR . The equational sets of GP are called the VR-equational sets.

The complete join G ⊗ H can be defined in terms of the operations of F VR as follows:

G ⊗ H := relab 2→1 ( --→ add 2,1 ( --→ add 1,2 (G ⊕ relab 1→2 (H)))),
hence by the term relab 2→1 ( --→ add 2,1 ( --→ add 1,2 (x 1 ⊕ relab 1→2 (x 2 )))). Such an operation, defined by a term with variables, is called a derived operation of the relevant algebra, here GP. 25 Note that although this operation uses the port label 2, it transforms two graphs G, H in G (G is the set of graphs, all vertices of which are 1-ports) into a graph in the same set.

Systems of equations (that define VR-equational sets) can frequently be written more clearly with the help of derived operations. For example, Equation (1.1) in Section 1.1.2 can be written as the following equation:

C = (C ⊕ C) ∪ relab 2→1 ( --→ add 2,1 ( --→ add 1,2 (C ⊕ relab 1→2 (C)))) ∪ 1,
where C defines a subset of GP, but it is more readable as in (1.1).

For each k ∈ N we denote by F VR [k] the finite subsignature of F VR consisting of the operations written with port labels in [k]. 26 Hence,

F VR [k] := {⊕, relab a→b , ---→ add a,b , 1, 1 , ∅ | 1 ≤ a, b ≤ k}.
It is not hard to see that every p-graph with n vertices and port labels in [n] is the value of a term t in F VR [n] . However, in many cases, much fewer labels suffice, and for algorithmic applications it is useful to use as few labels as possible.

In this perspective, we define the clique-width of a graph G, either directed or undirected, as the minimum k such that G is the value of a term in T (F VR [k] ). This number is denoted by cwd (G). Trees have clique-width at most 3. Cographs have clique-width at most 2: this is clear because the above equation that defines cographs uses only two port labels.

Proposition 1.18 Every VR-equational set of graphs has bounded clique-width. For each k, the set of graphs of clique-width at most k is VR-equational.

Proof sketch: Let L be a VR-equational set of graphs. It is defined by an equation system written with port labels in some set [k]. It follows that all pgraphs belonging to the components of its least solution are the values of terms in F VR [k] . In particular, the graphs in L have clique-width at most k.

Conversely consider the sets of p-graphs S and T defined by the equation system: (1.11) where the union extends to all unary operations f belonging to F VR [k] . In the equation that defines T , all port labels are transformed into 1. The set S consists of all p-graphs defined by terms in T (F VR [k] ) and the set T consists of those whose vertices are all 1-ports, hence of all graphs of clique-width at most k.

S = (S ⊕ S) ∪ f (S) ∪ 1 ∪ 1 ∪ ∅ T = relab 2→1 (• • • (relab k→1 (S) • • • ))
At the cost of some technicalities that we want to avoid here, the notion of clique-width and Proposition 1.18 can be extended to graphs with ports. However, port labels are just a tool to construct graphs. Hence Proposition 1.18 states the main facts about the relationship between VR-equational sets of graphs and clique-width.

The Clique-Width Checking problem consists in deciding whether or not cwd (G) ≤ k for given (G, k). It is NP-complete ( [FelRRS]). It is not known whether this problem is polynomial for fixed k, when k ≥ 4, but it is when k ≤ 3 ( [CorHLRR]).

The algebra of graphs with sources

We now define an algebra of graphs with multiple edges, called the HR algebra27 , that extends the algebra J d 2 = J d 2 , , •, e considered in Section 1.1.3. We consider (abstract) directed or undirected graphs, possibly with multiple edges. They form the set J . For a graph in J , E G denotes its set of edges (and V G its set of vertices). We let A be a countable set of labels (as in Section 1.4.1 we take it equal to N ) that will be used to distinguish particular vertices. These distinguished vertices will be called sources, and A is the set of source labels. (This notion of source is unrelated with edge directions).

A graph with sources, or s-graph in short, is a pair G = G • , src G where G • ∈ J and src G is a bijection from a finite subset τ (G) of A to a subset of V G • . We call τ (G) the type of G and src G (τ (G)) the set of its sources. The vertex src G (a) is called the a-source of G; its source label, also called its source name, is a.

We let J S denote the set of s-graphs; J is thus the set of s-graphs having an empty type. Clearly, J d 2 ⊆ J S and the elements of J d 2 are s-graphs of type {1, 2}. We define operations on J S: first a binary operation called the parallelcomposition, a particular case of which has been defined in Section 1.1.3. For G, H ∈ J S we let

G H := G ∪ H , src G ∪ src H
where H is isomorphic to H28 and is such that

E H ∩ E G = ∅, src G (a) = src H (a) if a ∈ τ (G) ∩ τ (H ), V G ∩ V H = {src G (a) | a ∈ τ (G) ∩ τ (H )}.
This operation "glues" G and a disjoint copy of H by fusing their sources having the same names. The s-graph G H is well defined up to isomorphism. Its type is τ (G) ∪ τ (H).

We define unary operations that manipulate source labels. Let G = G • , src G be an s-graph. For a ∈ A, we let fg a (G) := G • , src where src (b) is src G (b) if b ∈ τ (G) -{a} and is undefined otherwise. We say that fg a forgets the a-source: if G has an a-source, then this vertex is no longer distinguished as a source in fg a (G) and is turned into an "ordinary", we will say internal, vertex. Hence τ (fg a (G)) = τ (G) -{a}.

The next operation modifies source names; it is called a renaming. We also define constant symbols: ab, -→ ab, a, a , ∅ to denote respectively an undirected edge linking an a-source and a b-source, a directed edge from an a-source to a b-source, a single vertex that is an a-source, an a-source with a loop, and the empty graph. (Since we can change source names, it would suffice to use the constant symbols 12, -→ 12, 1, 1 , ∅. However, using many renaming operations would make terms denoting graphs unreadable.)

We obtain a countable signature denoted by F HR and an F HR -algebra of graphs denoted by JS and called the HR algebra. It has domain J S. As for GP, for every term t ∈ T (F HR ), we denote by t JS the s-graph that is its value. The equational sets of JS are called the HR-equational sets.

As for VR-equational sets, the equations that define HR-equational sets can be shortened if they are written with derived operations. For example, the series-composition of graphs of type {1, 2} is a derived operation that can be expressed by: G • H := fg 3 (ren 2↔3 (G) ren 1↔3 (H)).

We denote by F HR [k] the finite subsignature of F HR consisting of the operations , fg a , ren a↔b , for a, b ∈ [k] and of the constant symbols denoting graphs with source names in [k].

Each s-graph G with n vertices and source names in [n] is the value of a term in T (F HR [n] ). The least integer k such that a graph G (without sources) is the value of a term in T (F HR [k+1] ) is a well-known graph complexity measure called the tree-width of G and denoted by twd (G). It has been defined previously in a combinatorial way by Robertson and Seymour and by other authors using a different terminology. In the combinatorial definition, twd (G) is the least integer k such that G has a so-called tree-decomposition of width k. A treedecomposition of G is a decomposition of G into a tree of subgraphs, where each node of the tree corresponds to a subgraph of G; its width is the maximal number of vertices of those subgraphs, minus 1. The notion of tree-width is important for the construction of graph algorithms and for the study of graph minors: see the books [*Die], [*DowFel] and [*FluGro], and the survey articles [*Bod93] and [*Bod98]. We will study this combinatorial notion in Chapter 2 and prove the following result which is an algebraic characterization of it: Proposition 1.19 A graph has tree-width at most k if and only if it is the value of a term in T (F HR [k+1] ).

By contrast clique-width, defined in terms of graph operations, has yet no alternative combinatorial definition. Using Proposition 1.19 the following result can be proved in the same way as Proposition 1.18. Proposition 1.20 Every HR-equational set of graphs has bounded tree-width. For each k, the set of graphs of tree-width at most k is HR-equational.

A weak Recognizability Theorem

The VR algebra GP has a countable signature F VR that generates it: this means that each element is the value of some term. For each k in N , we let GP gen [k] be the subalgebra of GP that is generated by the finite subsignature F VR

[k] of F VR . Its domain GP gen [k] consists of the graphs with ports that are values of terms in T (F VR [k] ). We define similarly JS gen [k] as the subalgebra of the HR algebra JS that is generated by the finite subsignature F HR [k] of F HR . Its domain is J S gen [k]. Proposition 1.17 extends into the following theorem: Theorem 1.21 (Weak Recognizability Theorem)

(1) Let L be a CMS-definable set of simple graphs. For every k ∈ N , the set L ∩ GP gen [k] is recognizable in the algebra GP gen [k].

then the auxiliary properties used in that proof are Boolean combinations of the properties in P. In Chapter 5, the proof of Theorem 1.21 shows that, more precisely, every CMS-expressible property P belongs to a finite inductive set P of CMS-expressible properties in the algebra GP gen [k] (and similarly for CMS 2 and JS gen [k]). Hence, the auxiliary properties in the proof by fixed-point induction are CMS-expressible (respectively CMS 2 -expressible).

Fixed-parameter tractability

In this section, we describe some algorithmic applications of the Weak Recognizability Theorem. We first recall the basic definition of fixed-parameter tractability. This notion has been introduced in order to describe in an abstract setting the frequently met situation where the computation time of an algorithm is bounded by an expression of the form f (p(d)) • |d| c , where the set of inputs is equipped with two computable integer valued functions, a size function d → |d| (d is the generic input) and a parameter function d → p(d), such that 0 ≤ p(d) ≤ |d|, and where f is a fixed computable function of nonnegative integers and c is a fixed positive integer. If these conditions are satisfied, the considered algorithm is fixed-parameter tractable with respect to the parameter p. If c = 1, 2 or 3, we say that it is fixed-parameter linear, quadratic or cubic respectively.

As size of an input graph G, we will use either the number of its vertices and edges, denoted by G , or, in particular if G is simple, its number of vertices. Parameters can be the degree of G, its tree-width or its clique-width. Our results will use these last two values; other examples can be found in the books [*DowFel] and [*FluGro] which present in detail the theory of fixed-parameter tractability.

The size |t| of a term t or the size |ϕ| of a formula ϕ is, roughly speaking, the number of symbols with which t or ϕ is written, i.e., the length of the corresponding word. 29Example 1.23 The subgraph isomorphism problem consists in deciding for a pair of simple graphs (G, H) whether H is isomorphic to a subgraph of G. It is ). For each fixed graph H, this problem can be solved in time O(n m ) where n = |V G | and m = |V H |. However it is fixed-parameter linear with respect to Deg(G), the degree of G. This follows from a result by Seese [START_REF] Seese | Linear time computable problems and first-order descriptions[END_REF] (another proof is given in [DurGra]) saying that for every first-order sentence ϕ, one can decide in time bounded by f (|ϕ| + Deg(G)) • |V G | whether G satisfies ϕ, for some fixed computable function f . The property that G has a subgraph isomorphic to a fixed graph H is expressible by a first-order sentence ϕ H to be interpreted in G . Hence the subgraph isomorphism problem can be solved in time at most f (|ϕ

H | + Deg(G)) • |V G |.
Fixed-parameter tractable algorithms that check monadic second-order graph properties can be derived from Theorems 1. 16 and 1.21. The model-checking problem for a logical language L and a class of structures C consists in deciding whether S |= ϕ, for a given structure S ∈ C and a given sentence ϕ ∈ L.

Theorem 1.24 For every finite signature F , every monadic second-order sentence ϕ and every term t in T (F ), one can decide in time at most f (F, ϕ) • |t| whether t |= ϕ, where f is a fixed computable function.

Proof: The proof of Theorem 1.16 being effective, it yields an algorithm that constructs from F and ϕ a finite deterministic F -automaton A accepting the set of terms s in T (F ) such that s |= ϕ. By running A on a given term t, one gets the answer in time proportional to |t|. The total computation time is thus f 1 (F, ϕ) + f 2 (F, ϕ) • |t| where f 1 (F, ϕ) is the time taken to compute A and f 2 (F, ϕ) is the maximum time taken by A to perform one transition.

In other words, the model-checking problem for monadic second-order sentences and the class of terms is fixed-parameter linear with respect to F + |ϕ|, where F is the sum of arities of the symbols in F plus the number of constant symbols in F . This follows from Theorem 1.24 because, up to the names of the symbols in F and of the variables in ϕ, there are finitely many pairs (F, ϕ) such that F + |ϕ| ≤ p, so that f (F, ϕ) can be bounded by g( F + |ϕ|) for some computable function g.

We now consider the model-checking problem for monadic second-order sentences on graphs and its two possible parametrizations by tree-width and cliquewidth. For a graph G given by a term t in T (F HR [k] ) or in T (F VR [k] ), one gets a fixed-parameter linear algorithm as in Theorem 1.24 because, by Theorems 1.21 and 1.12, one can construct from k and ϕ a finite deterministic F HR

[k] -automaton A ϕ,k that accepts the set of terms t such that t JS satisfies ϕ, and similarly with F VR [k] . This situation happens in particular if G belongs to an HR-or VRequational set of graphs and is given by a corresponding term or derivation tree (cf. Section 1.1.5). However, if such a term or derivation tree is not given, it must be computed from the input graph by a parsing algorithm.

Theorem 1.25

(1) The model-checking problem for CMS sentences and the class of simple graphs is fixed-parameter cubic with respect to cwd (G) + |ϕ|. The input sentence is ϕ and the size of the input graph G is its number of vertices.

(2) The model-checking problem for CMS 2 sentences and the class of graphs is fixed-parameter linear with respect to twd (G) + |ϕ|. The input sentence is ϕ and the size of the input graph G is its number G of vertices and edges.30

Proof: We first consider the parametrization by tree-width. We let n be the number of vertices and edges of the input graph G, i.e., n := G . There exists an algorithm (by Bodlaender [START_REF] Bodlaender | A linear-time algorithm for finding treedecompositions of small treewidth[END_REF], see also [*DowFel]) that, for every graph G and integer k, decides if twd (G) ≤ k in time at most g(k)•|V G | (for some fixed computable function g), and that constructs if possible a tree-decomposition of width k of G; this tree-decomposition can be converted in linear time (in n) into a term t in T (F HR [k+1] ) that evaluates to G, cf. Proposition 1.19.

Step 1 : For given G and by repeating this algorithm for k = 1, 2, . . . at most twd (G) times one obtains an optimal tree-decomposition of G. This computation takes time at most twd (G) • g (twd (G)) • n for some fixed computable function g and builds a term in T (F ) where F := F HR [twd(G)+1] , that evaluates to G. (The function g takes into account the time needed to transform a treedecomposition into a term.)

Step 2 : By using Theorems 1.21 and 1.12, one constructs a finite deterministic F -automaton A ϕ,k where k = twd (G) + 1 that accepts the set of terms t ∈ T (F ) that evaluate to a graph satisfying ϕ.

Step 3 : By running this automaton on t, one obtains the answer.

We now consider the parametrization by clique-width. The main difference concerns Step 1. There exists an algorithm (that combines algorithms from [HliOum] and [OumSey], see Section 6.2.3 for details) that, for every simple graph G and every integer k, either reports (correctly) that cwd (G) > k or constructs a term in T (F VR [h(k)] ) that evaluates to G (and hence G has cliquewidth at most h(k)) where h(k) = 2 k+1 -1. This algorithm takes time g (k) • n 3 for some fixed computable function g , where n = |V G |. Note that it does not determine the exact clique-width of G.

Step 1 of the case of tree-width is replaced by the following: for given G and by repeating this algorithm for k = 1, 2, . . . at most cwd (G) times, one obtains a term t in T (F VR [m] ) that evaluates to G for some m ≤ h(cwd (G)). This computation takes time at most cwd (G) • f (cwd (G)) • n 3 , where f (k) is the maximum of g (i) for i = 1, . . . , k. The computation continues then by constructing a finite F VR [m] -automaton (by Theorems 1.21 and 1.12) and running it on t like in Steps 2 and 3 above.

The algorithms of Theorem 1.25 are actually not directly implementable because of the sizes of the automata to be constructed. Specifically, the automata A ϕ,k in the two cases of Theorem 1.25 have a number of states that is not bounded by a function of the form exp • exp • • • • • exp(|ϕ|) with a fixed number of iterated exponentiations (exp(n) = 2 n for every n). (This is also the case for the automaton constructed in the proof of Theorem 1.24). This fact is not a weakness of the construction, but a consequence of the fact that complicated properties can be expressed by short formulas. This phenomenon occurs for first-order as well as for monadic second-order logic, as proved in [START_REF] Frick | The complexity of first-order and monadic second-order logic revisited[END_REF].

Concrete constructions of F VR

[k] -automata for small values of k and simple graph properties will be presented in Section 6.3.

A second reason that makes these algorithms difficult, if not impossible, to implement so as to run for arbitrary graphs is the time needed for parsing the input graphs, i.e., for building terms in T (F HR [k] ) or in T (F VR [k] ) for given values of k that evaluate to them. The linear algorithm by Bodlaender [Bod96] used in the proof of Theorem 1.25 takes time 2 32k 3 • n. We will review other more efficient, even if not linear, algorithms in Chapter 6. The cubic algorithm of [HliOum] is not implementable either.

Decidability of monadic second-order logic

Apart from model-checking discussed in the previous section, another major problem in Logic consists in deciding whether a given sentence holds in some relational structure (or in a graph represented by a relational structure) of a fixed set L. In this case, the input of the problem is an arbitrary sentence from a logical language L. This problem is called the L-satisfiability problem for the set L. A related problem consists in deciding if a given sentence of L belongs to the L-theory of L, that is, to the set of sentences of L that hold for all graphs (or structures) in L. We say that the L-theory of L is decidable if this problem is decidable. As logical languages L, we will consider fragments and extensions of monadic second-order logic that are closed under negation. For such languages, the L-satisfiability problem for a set L is decidable if and only if the L-theory of L is decidable.

The main motivation for the fundamental Theorem 1.16 was to prove the decidability of the MS-theory of the set of terms T (F ) (more precisely, the set of structures { t | t ∈ T (F )}), for every finite signature F . From Theorem 1.22 we obtain a similar result for graphs, as observed at the end of Section 1.4.3. Theorem 1.26 The CMS-theory of the set CWD(≤ k) of simple graphs of clique-width at most k, or of a VR-equational set of graphs is decidable. So is the CMS 2 -theory of the set TWD(≤ k) of graphs of tree-width at most k, or of an HR-equational set of graphs.

One obtains results which are quite powerful in that they apply to many different sets of graphs. One might hope to use them in order to obtain automatic proofs of conjectures or of difficult theorems in graph theory. However the situation is not so favorable. Let us take the example of the 4-Color Theorem, stating that every planar graph is 4-colorable. In Section 1.3.1 we have shown the existence of two MS sentences, π and γ 4 , expressing respectively that a graph is planar (Corollary 1.15) and that it is 4-colorable. The 4-Color Theorem 31 can thus be stated in the following logical form: Theorem 1.27 We have G |= π ⇒ γ 4 for every graph G in G.

31 Its proof by Robertson et al. ([RobSanST]) has been checked by computer by Gonthier [Gon] with the software Coq based on Type Theory.

able. The two main results regarding this question are collected in the following theorem 34 . Theorem 1.29 Let L be a set of finite, simple, undirected graphs.

(1) If L has a decidable MS 2 -satisfiability problem, then it has bounded treewidth.

(2) If L has a decidable C 2 MS-satisfiability problem, then it has bounded clique-width.

Assertion [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] is proved by Seese in [See91]. He asks in this article whether every set L having a decidable MS-satisfiability problem (which is weaker than having a decidable C 2 MS-satisfiability problem) is "tree-like", which is actually equivalent (by the Equationality Theorem for the VR algebra presented below in Section 1.7.3) to having bounded clique-width. Assertion (2) proved in [CouOum] is thus a partial answer to Seese's question.

Graph transductions

The theory of formal languages studies finite descriptions of languages (sets of words or terms) by grammars and automata, and also finite descriptions of transformations of these objects. Motivations come from the theories of coding, of compilation, of computational linguistics, just to cite a few. The finite devices that specify these transformations are called transducers and the corresponding transformations of words and terms are called transductions. Typical questions are the following:

Is a given class of transductions closed under composition? under inverse? Does it preserve a given family of languages? Is this family the set of images of a particular language (called a generator) under the transductions of the class?

Is the equality of the transductions defined by two transducers of a certain type decidable?

In the study of sets of words, rational transductions play a prominent role originating from the work by Nivat [Niv]. The inverse of a rational transduction and the composition of two rational transductions are rational transductions. The families of regular and of context-free languages are preserved under rational transductions, and there exist context-free languages (like the one defined by the equation L = f (L, L) ∪ a where L ⊆ A * and A consists of a, f , parentheses and comma), whose images under all rational transductions are all contextfree languages. Transducers are usually based on finite automata or on more complicated devices like macros (see, e.g, the macro tree transducers in [START_REF] Engelfriet | Macro tree transducers, attribute grammars, and MSO definable tree translations[END_REF]). Can one define similar notions for graphs? Since graphs can be denoted by terms, one can use transductions of terms to specify transductions of graphs (as,e.g.,[START_REF] Engelfriet | Graph grammars and tree transducers[END_REF][START_REF] Drewes | Decidability of the finiteness of ranges of tree transductions[END_REF]). However, doing this requires for processing the input a parsing step that is algorithmically difficult (cf. Sections 1.5 and 6.2). For building the output, each term produced by such a transduction must be evaluated into a graph. The main drawback of the detour through terms over (necessarily) finite signatures is that it limits the input and output graphs of transductions to have bounded tree-width or clique-width. It is natural to try to avoid such a detour and to define transducers that work "directly" on graphs, by traversing them according to some rules and by starting from some specified vertex. However no notion of finite graph automaton has been defined that would generalize conveniently finite automata on words and terms. Monadic second-order logic offers a powerful alternative. In this section, we define monadic second-order transductions by means of examples more than formally. These transductions have good interactions with the HR-and VR-equational sets (our "context-free sets of graphs") that follow from the Equationality Theorem presented below in Section 1.7.3. It will be shown in Chapter 8 that every (functional) monadic second-order transduction of graphs of bounded tree-width or clique-width can be realized by a macro tree transducer on the level of terms.

Examples of monadic second-order transductions

Monadic second-order transductions are transformations of graphs specified by monadic second-order formulas. The basic notion is that of a monadic secondorder transduction of relational structures over a fixed set of relation symbols. It applies to graphs faithfully represented by relational structures.

All examples and results presented in this section (Section 1.7) will concern simple graphs, for which G → G is a faithful representation. Hence, we will consider mappings f from simple graphs to simple graphs such that, for every G, the structure f (G) representing its image under f is defined from G by monadic second-order formulas.

The simplest case is when:

f (G) := V f (G) , edg f (G) , V f (G) := {u ∈ V G | G |= δ(u)}, edg f (G) := {(u, v) ∈ V G × V G | G |= δ(u) ∧ δ(v) ∧ θ(u, v)},
where δ and θ are monadic second-order formulas with free variables u, and u and v respectively. The formula δ defines the set of vertices of f (G) as a subset of V G and the formula θ defines the edge relation of f (G) in terms of that of G. The mapping f is thus specified by a pair δ, θ of monadic secondorder formulas. We will say that f is a monadic second-order transduction and that δ, θ is its definition scheme. If δ and θ are first-order formulas, we will say that f is a first-order transduction. The general definition is actually more complicated. We introduce it step by step by giving several examples. The edge-complement associates with a simple, undirected and loop-free graph G, the simple, undirected and loop-free graph G such that V G = V G and u -v is an edge of G if and only if u = v and u -v is not an edge of G. This transformation is a first-order transduction with definition scheme δ, θ where:

δ(x) is the Boolean constant True, θ(x, y) is the formula x = y ∧ ¬edg(x, y).

Example 1.31 (Elimination of loops and isolated vertices)

The transformation that eliminates loops and then, isolated vertices is a first-order transduction with definition scheme δ, θ where:

δ(x) is the formula ∃y edg(x, y) ∨ edg(y, x) ∧ x = y , θ(x, y) is the formula edg(x, y) ∧ x = y. Example 1.32 (Transitive closure of a directed graph)
For every directed graph G, we let G + be its transitive closure, the simple graph defined by:

V G + := V G , edg G + := edg + G := {(u, v) | there is in G a nonempty directed path 35 from u to v}.
Note that u has a loop in G + if it belongs to a directed cycle in G. The mapping G → G + is defined by the definition scheme δ, θ where:

δ(x) is the formula True, θ(x, y) is the formula 36 edg(x, y) ∨ ∃ z(edg(x, z) ∧ TC[edg; z, y]).
We use here the definition of the reflexive and transitive closure of a binary relation by a monadic second-order formula presented in Section 1.3.1.

Example 1.33 (Transitive reduction of a directed acyclic graph)

A directed acyclic graph (a DAG) is a simple directed graph without directed cycles. Every such finite graph G has a unique minimal subgraph H such that H + = G + . It is called the transitive reduction of G and is denoted by Red (G). (The Hasse diagram of a partial order D, ≤ is a graphical representation of 35 i.e., a sequence of pairwise distinct vertices w 1 , w 2 , . . . , wn such that u = w 1 , v = wn and

w i → w i+1 in G for each i = 1, . . . , n -1. A directed cycle is a sequence of this form with w 1 = wn, n ≥ 2, w i = w j for 1 ≤ i ≤ j ≤ n -1.
36 The atomic formula edg(x, y) in θ(x, y) can be omitted, but putting it in makes the formula more clear.

the transitive reduction of the directed acyclic graph D, < .) The edge relation of Red (G) is characterized by:

edg Red(G) (x, y) :⇐⇒ edg(x, y) ∧ ¬∃z(edg G + (x, z) ∧ edg G + (z, y)),
hence is defined in G by a monadic second-order formula θ built with the formula θ of the previous example. It follows that the mapping Red from directed graphs to directed graphs is a partial function that is a monadic second-order transduction specified by a sentence χ and two formulas δ, θ such that:

G |= χ if and only if it is acyclic (hence if and only if Red (G) is well defined), G |= δ(u) for every u in V G (so that V Red(G) = V G ), G |= θ (u, v) if and only if Red (G) has an edge u → v.
It is frequently necessary to consider functions f that assign a graph to the pair of a graph G and a set of vertices X. In this case, the definition scheme consists of formulas χ, δ and θ with a free set variable X called a parameter. The formula χ expresses the conditions to be verified by G and X so that f (G, X) be defined. Here is an example.

Example 1.34 (The largest connected subgraph of G containing X)

The partial function f such that f (G, X) is the largest connected induced subgraph of G containing a nonempty subset X of V G is a monadic second-order transduction with parameter X. Its definition scheme is χ, δ, θ where:

χ(X) is the formula (∃x. x ∈ X) ∧ ∃Y X ⊆ Y ∧ CONN(Y ) , 37 δ(X, x) is the formula ∃Y X ⊆ Y ∧ x ∈ Y ∧ CONN(Y ) , θ(X, x, y) is ∃Y X ⊆ Y ∧ x ∈ Y ∧ y ∈ Y ∧ edg(x, y) ∧ CONN(Y ) .
In the previous example, a parameter X is necessary because the function f to be defined does not depend only on G but also on a set of vertices. However, in some cases, parameters may be necessary even if the output graphs depend only, up to isomorphism, on the input graphs (and not on the values of the parameters). Here is an example of such a case.

Example 1.35 (The DAG of strongly connected components of a directed graph)

Let G be a directed graph. Let ≈ be the equivalence relation on V G defined by: u ≈ v if and only if u = v or there exists a directed path from u to v and a directed path from v to u.

An induced subgraph G[X]

where X is an equivalence class of this relation is called a strongly connected component. The DAG of strongly connected components of G is the quotient graph G/≈ defined as follows: its vertices are the strongly connected components; there is in G/≈ an edge X → Y if and only if X = Y and u → v in G for some u ∈ X and v ∈ Y . Our objective is to prove that there exists a monadic second-order transduction associating with every graph G a graph H isomorphic to G/≈. Its definition uses a parameter X for denoting sets U ⊆ V G required to contain one and only one vertex of each strongly connected component. Such sets are used as sets of vertices of H and its edges are defined accordingly. We use the following formulas:

Eq(x, y) is the auxiliary formula TC[edg; x, y] ∧ TC[edg; y, x], χ(X) is defined as: ∀x, y x ∈ X ∧ y ∈ X ∧ Eq(x, y) ⇒ x = y ∧ ∀x∃y Eq(x, y) ∧ y ∈ X , δ(X, x) is defined as: x ∈ X, θ(X, x, y) is defined as: x ∈ X ∧ y ∈ X ∧ ¬Eq(x, y) ∧ ∃z, z edg(z, z ) ∧ Eq(x, z) ∧ Eq(y, z ) .
The definition scheme χ, δ, θ specifies a monadic second-order transduction that associates with a directed graph G and a "well-chosen" subset U of V G a graph f (G, U ) with vertex set U that is isomorphic to G/≈ (u ∈ U corresponds to an equivalence class, hence to a vertex of G/≈). It is clear that for every graph G there exists a set U satisfying χ, and that, for any two sets U and U satisfying χ, the graphs f (G, U ) and f (G, U ) are isomorphic (the corresponding bijection h :

U → U is defined by h(u) = v if and only if u ∈ U , v ∈ U and u ≈ v).
This construction extends actually to every equivalence relation definable by a monadic second-order formula in place of ≈ and proves that the mapping that associates with a graph G its quotient G/≈ by a monadic second-order definable equivalence relation ≈ is a monadic second-order transduction. In all the above examples, the set of vertices of the output graph is a subset of the set of vertices of the input graph. The general definition of a monadic second-order transduction includes the possibility of enlarging the input graph, by "copying it" a fixed number of times.

A k-copying monadic second-order transduction associates with a graph G a graph H such that:

V H := (V 1 × {1}) ∪ • • • ∪ (V k × {k}) edg H := {((u, i), (v, j)) | 1 ≤ i, j ≤ k, (u, v) ∈ E i,j } where the sets V 1 , . . . , V k ⊆ V G and the relations E i,j ⊆ V G × V G are
defined in G by monadic second-order formulas, respectively δ 1 , . . . , δ k and θ i,j for 1 ≤ i, j ≤ k and possibly written with parameters. Let us give an example.

Example 1.36 (Graph duplication)

For every simple directed graph G, its duplication is the simple graph H = dup(G) defined as follows:

V H := V G × {1, 2},
the edges of H are the edges of each copy of G, together with the edges (u, 1) → (u, 2) for all u ∈ V G .

The mapping dup has the definition scheme δ 1 , δ 2 , θ 1,1 , θ 1,2 , θ 2,1 , θ 2,2 where: andE 2,1 := ∅. Informally H consists of two disjoint copies of G (i.e, G ⊕ G) together with an edge from any vertex of the first copy to the corresponding vertex of the second copy.

δ 1 (x) and δ 2 (x) are both the Boolean constant True, θ 1,1 (x, y) and θ 2,2 (x, y) are both edg(x, y), θ 1,2 (x, y) is x = y, θ 2,1 (x, y) is the Boolean constant False. The formulas δ 1 and δ 2 define V 1 and V 2 as V G ; the formulas θ i,j define E 1,1 := E 2,2 := edg G , E 1,2 := {(u, u) | u ∈ V G },
The general definition of a monadic second-order transduction combines the above presented features. To summarize, a monadic second-order transduction associates with a relational structure S and subsets U 1 , . . . , U m of its domain D S that must satisfy a monadic second-order formula χ(X 1 , . . . , X m ), a relational structure T = f (S, U 1 , . . . , U m ) defined as follows. Its domain is

D T := (D 1 × {1}) ∪ • • • ∪ (D k × {k}) where each set D i is defined as {d ∈ D S | S |= δ i (U 1 , . . . , U m , d)}
for some monadic second-order formula δ i . If R is an n-ary symbol of the relational signature of T , the corresponding n-ary relation on D T is defined as

i1,...,in∈[k] {((d 1 , i 1 ), . . . , (d n , i n )) | d 1 ∈ D i1 , . . . , d n ∈ D in , S |= θ R,i1,...,in (U 1 , . . . , U m , d 1 , . . . , d n )},
where each θ R,i1,...,in is a monadic second-order formula.

Such a transduction f is specified by a tuple of formulas called a definition scheme of the form χ, δ 1 , . . . , δ k , (θ w ) w∈W where W consists of all tuples (R, i

1 , . . . , i ρ(R) ) such that R is a relation symbol of T and i 1 , . . . , i ρ(R) ∈ [k].
The following fact is clear from the definitions: Fact 1.37 For every monadic second-order transduction f there exists an integer k such that, if f transforms a relational structure S into a relational structure T , then

|D T | ≤ k • |D S |.
We have k = 1 in the first six examples and k = 2 in the last one. We now give another example, with k = 1 and without parameters.

Example 1.38 (The cograph denoted by a term)

As a final example we consider the mapping that evaluates a term t in T ({⊕, ⊗, 1}) into the cograph val (t) (cf. Section 1.1.2 and Example 1.7). First of all we must explain how t is represented by a relational structure. We let t = N t , son t , lab ⊕t , lab ⊗t , lab 1t be the relational structure such that:

• N t is Pos(t)
, the set of positions of t, i.e., of occurrences of symbols from {⊕, ⊗, 1}; we will consider N t as the set of nodes of a rooted labelled tree representing t and also denoted by t; Since the operations ⊕ and ⊗ are commutative, we need not express, when v is a son of u, whether it is the left or the right son. Hence we can use a simpler representation than the general one to be defined in Section 5. 1.1. Here is an example. We let:

•
s := 1 1 ⊗ 2 1 3 ⊕ 4 1 5 ⊗ 6 1 7 ⊕ 8 1 9
where we number from left to right the nine occurrences of 1, ⊕, ⊗ (this numbering is indicated by subscripts). The corresponding labelled tree is shown in Figure 1.5. Then s = [9], son, lab ⊕ , lab ⊗ , lab 1 with son = {(6, 4), (6, 8), (4, 2), (4, 5), (2, 1), (2, 3), (8, 7), (8, 9)}, lab ⊕ = {4, 8}, lab ⊗ = {2, 6}, lab 1 = {1, 3, 5, 7, 9}.

In the general case, the cograph G = val (t) that is the value of a term t in T ({⊕, ⊗, 1}) can be defined from t as follows:

V G is the set of elements of N t that are labelled by 1 (i.e, that are the leaves of the tree t); for distinct vertices u and v of G, there is an edge between u and v if and only if the least common ancestor of u and v in t is labelled by ⊗.

In the above example of s, the vertices of the cograph val (s) are 1, 3, 5, 7, 9. There is an edge between 3 and 9 because their least common ancestor in s is 6 which is labelled by ⊗. There is no edge between 1 and 5 because their least common ancestor is 4, labelled by ⊕. The monadic second-order transduction that associates with t , for any term t in T ({⊕, ⊗, 1}), the relational structure val (t) is specified by the definition scheme True, δ, θ where: δ(x) is the formula lab 1 (x), θ(x, y) is the formula x = y ∧ ∃z(LCA(x, y, z) ∧ lab ⊗ (z)).

In this writing, LCA(x, y, z) stands for the following formula expressing that z is the least common ancestor of x and y:

TC[son; z, x] ∧ TC[son; z, y] ∧ ∀w (TC[son; w, x] ∧ TC[son; w, y]) ⇒ TC[son; w, z] .
This formula is a straightforward translation of the definition of the least common ancestor. Note that if x is an ancestor of y or if x = y, then LCA(x, y, x) is valid. Furthermore LCA(x, y, z) defines z in a unique way from x and y.

The main properties of monadic second-order transductions

A monadic second-order transduction is a subset f of S × T where S and T are classes of graphs or, more generally, of relational structures, that is specified as explained in the examples by monadic second-order formulas. If L ⊆ S and f ⊆ S × T , we let f (L) := {T | (S, T ) ∈ f, S ∈ L} be the image of L under f . Hence, f can also be seen as the multivalued mapping f : S → P(T ) such that f (G) := f ({G}). In Examples 1.30,1.31 and 1.32, f (G) consists of a unique graph. In Example 1.33 it consists of at most one graph and in Example 1.34 of several graphs (the connected components). However, a monadic second-order transduction is always based on a (single-valued) partial function that transforms parametrized relational structures into relational structures. A parametrized relational structure is a tuple (S, A 1 , . . . , A n ) consisting of a relational structure S and an n-tuple of subsets of its domain D S . From a partial function f that transforms (S, A 1 , . . . , A n ) into f (S, A 1 , . . . , A n ) in T for S in S and for certain subsets A 1 , . . . , A n of D S , we define f as the transduction

{(S, f (S, A 1 , . . . , A n )) | A 1 , . . . , A n ⊆ D S and f (S, A 1 , . . . , A n ) is defined}).
We also say that f and f are monadic second-order transductions.

The composition of two monadic second-order transductions is the composition of the corresponding binary relations: if f ⊆ S × T and g ⊆ T × U, then f • g := {(S, U ) | (S, T ) ∈ f and (T, U ) ∈ g for some T ∈ T }. If f and g are functional, we will also use the notation g • f for f • g. Theorem 1.39 The composition of two monadic second-order transductions is a monadic second-order transduction.

A more precise statement showing how parameters are handled in the composition of monadic second-order transductions will be given in Chapter 7 (Theorem 7.14).

Theorem 1.40 (Backwards Translation Theorem)

If the set L ⊆ T is MS-definable and f ⊆ S × T is a monadic second-order transduction, then the set

f -1 (L) := {S ∈ S | f (S) ∩ L = ∅} is MS-definable.
Theorem 1.40 is formally a consequence of Theorem 1.39 but it is actually used for proving Theorem 1.39 (see Chapter 7). We call Theorem 1.40 the Backwards Translation Theorem because its proof yields an algorithm that transforms a formula defining L into one defining f -1 (L). We now give the idea of its proof. Let us go back to the edge-complement transformation (Example 1.30). It is a first-order transduction that transforms G into G. If P is a first-order graph property, then the property

Q defined by Q(G) if and only if P (G) is also first- order. The edge relation of G is defined by edg G (u, v) :⇐⇒ u = v∧¬edg G (u, v).
Hence one obtains a first-order sentence expressing Q by replacing in the given first-order sentence expressing P each atomic formula of the form edg(x, y) by (x = y ∧ ¬edg(x, y)). Here is an example. We let P be defined by the sentence:

∃x, y, z x = y ∧ y = z ∧ x = z ∧ edg(x, y) ∧ edg(y, z) ∧ ¬edg(x, z)
expressing that an undirected graph G has an induced path P 3 (of the form

• -• -•). The sentence defining Q is then: ∃x, y, z x = y ∧ y = z ∧ x = z ∧ x = y ∧ ¬edg(x, y) ∧ y = z ∧ ¬edg(y, z) ∧ ¬ x = z ∧ ¬edg(x, z) .
It can actually be simplified into:

∃x, y, z x = y ∧ y = z ∧ x = z ∧ ¬edg(x, y) ∧ ¬edg(y, z) ∧ edg(x, z)
expressing that G has an induced subgraph of the form •-• •. This construction extends easily to monadic second-order transductions without parameters, like those of Examples 1.31,1.32 and 1.33. Let us now assume that f is defined by a definition scheme of the form χ(X), True, θ(X, x, y) with one parameter X. Here χ(X) is a formula that imposes some conditions on the parameter X. In Example 1.34, the condition "X denotes a singleton" might be imposed on X: the corresponding transduction associates with each vertex its connected component.

Let β be a sentence and let L be the set of graphs such that G |= β. Let then β # be the formula with free variable X obtained by replacing in β every atomic formula edg(x, y) by θ(X, x, y) (by using appropriate substitutions, and, if necessary, renamings of bound variables in θ(X, x, y)). For A ⊆ V G , the graph f (G, A) is well defined if and only if G |= χ(A), and then, f (G, A) |= β if and only if G |= β # (A). It follows that f -1 (L) is defined by the sentence ∃X χ(X) ∧ β # (X) .

The Equationality Theorem

The Equationality Theorems for the VR and the HR algebras (and for an algebra of relational structures that generalizes the VR algebra) are among the main results established in this book.

As an introduction to the Equationality Theorem for the VR algebra, we recall that the mapping that associates the cograph val (t) with a term t in T ({⊕, ⊗, 1}) is a monadic second-order transduction (Example 1.38). More generally:

Theorem 1.41 For every k, the mapping that associates with a term t in T (F VR [k] ) the p-graph t GP is a monadic second-order transduction.

This implies that the set of graphs of clique-width at most k, which is a VRequational set, is the image of the set of terms (over some finite signature) under a monadic second-order transduction. The following result includes a converse of this result and is very important for the theories of graph structuring and of graph grammars.

Theorem 1.42 (Equationality Theorem for the VR algebra) A set of simple graphs is VR-equational if and only if it is the image of the set of binary rooted trees under a monadic second-order transduction.

As an immediate consequence and by using Theorem 1.39, we obtain that the image of a VR-equational set under a monadic second-order transduction is again VR-equational. Note that this implies, as a special case, the logical version of the Filtering Theorem (Theorem 1.22): for a sentence χ, the transduction

f χ = {(G, G) | G |=
χ} is a monadic second-order transduction with definition scheme χ, True, edg(x, y) , and f χ (L) = {G ∈ L | G |= χ} for every set of graphs L. Another immediate consequence, using Proposition 1.18, is the following.

Corollary 1.43 A set of simple graphs has bounded clique-width if and only if it is included in the image of the set of binary rooted trees under a monadic second-order transduction. Thus, again using Theorem 1.39, the image of a set of graphs of bounded clique-width under a monadic second-order transduction from graphs to graphs has bounded clique-width.

In Theorem 1.42 and Corollary 1.43, one can replace "the set of binary rooted trees" 39 by "the set of trees" or by "T (F ) where F is any finite signature with at least one constant symbol and at least one symbol of arity at least 2".

Monadic second-order logic with edge set quantifications

If a graph G is represented by a relational structure whose domain also contains the edges, instead of by G , then the expressive power of monadic secondorder logic is increased, even for expressing properties of simple graphs. We will also compare the four types of monadic second-order transductions obtained by representing input and output graphs G either by G or by the alternative structure denoted by G .

Expressing graph properties with edge set quantifications

For every undirected graph G, we let G be the pair

V G ∪ E G , in G where 40 in G = {(e, u) | e ∈ E G , u ∈ V G , u is an end vertex of e}.
If G has several edges (called multiple edges) between two vertices, these edges are distinct elements of the domain of G . The structure G can be seen as Inc(G) where Inc(G)

39 A rooted tree is directed in such a way that the root is the unique node of indegree 0 and every node is accessible from the root by a directed path. It is binary if each node has outdegree 0 or 2. The associated (undirected) tree has degree at most 3. 40 Recall that V G is the set of vertices and E G is the set of edges.

is a bipartite directed graph called the incidence graph of G, whose edge relation is denoted by the binary relation symbol in. In a relational structure S = D S , in S isomorphic to G for some graph G, the elements of D S corresponding to edges are those, say u, such that (u, v) ∈ in S for some v. The element u corresponds to a loop if and only if there is a single such v. It follows that G can be reconstructed from S in a unique way. Thus, the representation of G by G is faithful for all undirected graphs. For directed graphs, we will use

G := V G ∪ E G , in 1G , in 2G
where (e, u) ∈ in 1G (resp. (e, u) ∈ in 2G ) if and only if u is the tail 41 (resp. the head) of e. Hence G can be seen as a directed bipartite graph, also denoted by Inc(G), with edges labelled either by 1 or by 2. Loops in G are multiple edges (with different labels) in Inc(G).

In this setting, edges are considered, like vertices, as objects that form a graph and not as the pairs of some binary relation over vertices. In particular, we do not consider an undirected edge as a pair of opposite directed edges.

Graph properties can be expressed logically, either via the representation of a graph G by G , or via the initially defined representation G := V G , edg G . The representation G only allows quantification on vertices and on sets of vertices in monadic second-order formulas, whereas the representation G also allows quantification on edges and sets of edges. A graph property is MS 2expressible if it is expressible by a monadic second-order formula interpreted in G . The index 2 refers to the possibility of "two types of quantification", on sets of vertices and sets of edges. A property is MS 1 -expressible if it is by a monadic second-order formula interpreted in G . Unless for emphasizing the contrast with MS 2 , we will write MS instead of MS 1 . 42 Let us stress that we do not modify the logical language, but only the representation of graphs by relational structures. Since an incidence graph is a graph, we still deal with a single language that we use to express formally graph properties. We now compare the power of these two ways of expressing graph properties. It is clear that a property of a graph G like "for every two vertices u, v, there are no more than 3 edges from u to v" cannot be expressed by any sentence interpreted in G because this relational structure cannot identify the existence of multiple edges, and thus no sentence can take into account their multiplicity. However, even for expressing properties of simple graphs, monadic second-order sentences with edge set quantifications are more powerful. The property that a loop-free undirected graph G has a perfect matching is equivalent to G |= ∃X. ψ where ψ is a formula with free variable X expressing that X is a set of edges and that for every vertex u there exists a unique e ∈ X such that (e, u) ∈ in G . The formula ψ is easy to write with first-order quantifications only. However, there is no monadic second-order sentence ϕ expressing this property by G |= ϕ. The formal proof of this assertion (to be done in 41 If e is an edge directed from u to v, then we say that u is its tail and that v is its head. 42 By an MS 2 formula, we mean a monadic second-order formula written with the binary relation symbols in, in 1 , in 2 , intended to be interpreted in logical structures of the form G . An MS 1 formula is written with the binary relation symbol edg and is to be interpreted in G .

Chapter 5) is based on the observation that the complete bipartite graph K n,m has a perfect matching if and only if n = m, and on the theorem saying that no monadic second-order formula can express that two sets have the same cardinality. It is easy to express that a given set of edges, say X, is a perfect matching, and this is what formula ψ does. But one cannot replace "there exists a set of edges satisfying ψ" by an MS formula without edge set quantification. The property "G has a Hamiltonian cycle" can be expressed similarly by an MS formula interpreted in G . The graphs K n,m can be used as counter-examples, as above for perfect matchings, to prove that this is not possible by an MS formula over G .

It is clear that every MS 1 -expressible graph property is MS 2 -expressible. Although some properties of simple graphs are MS 2 -expressible but not MS 1expressible, MS 2 formulas are in many cases no more expressive than MS 1 formulas.

Theorem 1.44 (Sparseness Theorem) Let L be a set of simple graphs that are all, either planar, or of degree at most k, or of tree-width at most k for some fixed k. Every MS 2 sentence ϕ can be translated into an MS 1 sentence ψ such that for every graph G in L:

G |= ϕ if and only if G |= ψ.
This result actually extends to sets of uniformly sparse graphs, as we will prove in Section 9.4.

Monadic second-order transductions over incidence graphs

For expressing properties of graphs G, we can choose between the two representing relational structures G and G . For defining monadic second-order graph transductions, we get thus four possibilities arising from two possible representations for the input as well as for the output. All examples of Section 1.7.1 use the first representation for the input and the output. We give below examples using G . We first fix some notation.

A graph transduction f is an MS i,j -transduction where i, j ∈ {1, 2}, if there exists a monadic second-order transduction g such that (G, H) ∈ f if and only if (S, T ) ∈ g where S is G if i = 1 and G if i = 2, and similarly, T is H if j = 1 and H if j = 2. Hence the indices i and j indicate which representations are used, respectively for the input and the output graphs.

It is clear that every MS 1,j -transduction is also an MS 2,j -transduction, because every MS 1 formula can be rewritten into an equivalent MS 2 formula. Hence changing in this way 1 into 2 makes "easier" the task of writing formulas to specify a transduction. For the "output" side we get that every MS i,2transduction is an MS i,1 -transduction, and not vice-versa as one might think, because in the former case the transduction must define the edges (and not only the vertices) from elements of the input structure, either G or G . We have the following inclusions of classes of monadic second-order transductions:

MS 1,2 ⊆ MS 1,1 ⊆ MS 2,1 MS 1,2 ⊆ MS 2,2 ⊆ MS 2,1 .
We will give examples proving that these inclusions are proper, that MS The line graph Line(G) of an undirected graph G is the loop-free undirected graph H such that V H = E G and e, f are adjacent vertices of H if and only if they have at least one common vertex as edges of G. The mapping G → H is an MS 2,1 -transduction with definition scheme χ, δ, θ edg such that:

χ :⇐⇒ True, δ(x) :⇐⇒ ∃z. in(x, z), θ edg (x, y) :⇐⇒ x = y ∧ ∃z(in(x, z) ∧ in(y, z)).
Could one use G instead of G for the input? The answer is no by Fact 1.37 because for arbitrary graphs G, if H = Line(G) then we do not have

|D H | = O(|D G |) since D H = V H = E G and D G = V G .
Could one use H instead of H for the output? Again the answer is no by a similar argument: if

G = K 1,n , then |D G | = 2n + 1, |V H | = n, |E H | = n(n -1)/2, hence |D H | = n(n + 1)/2 and is not O(|D G |).
Hence the line graph transduction is neither in MS We have seen in Example 1.32 that the transitive closure : G → G + on directed graphs is an MS 1,1 -transduction. It is not an MS 2,2 -transduction: consider Q n , the directed path with n vertices. We have |D Qn | = 2n -1 and

|D Q + n | = n(n + 1)/2, hence we do not have |D Q + n | = O(|D Qn |).
Consequently the transitive closure of directed graphs is not an MS 2,2 -transduction.

Example 1.47 (Edge subdivision)

For G simple, directed and loop-free, we let Sub(G) be the graph of the same type such that:

V Sub(G) := V G ∪ E G , E Sub(G) := {(u, e), (e, v) | (e, u) ∈ in 1G , (e, v) ∈ in 2G }.
This transformation, called edge subdivision consists in replacing directed edges by directed paths of length 2. We have (v, 1) of Sub(G), and an edge e linking u to v is made into a vertex (e, 1) and into edges (e, 2) and (e, 3) of Sub(G) that link respectively (u, 1) to (e, 1) and (e, 1) to (v, 1). Its definition scheme will be given in Chapter 7 (Example 7.44)

|V Sub(G) | = |V G | + |E G | and |E Sub(G) | = 2|E G |. Edge subdivision is an MS 2,2 -transduction because the transformation of G into Sub(G) is a 3-copying monadic second-order transduction: a vertex v of G is made into a vertex
. Since |V Sub(G) | is not O(|V G |), edge subdivision is not an MS 1,1 -transduction.

Example 1.48 (Identity)

The identity mapping is trivially an MS 1,1 -and an MS 2,2 -transduction, and hence also an MS 2,1 -transduction. It is not an MS 1,2 -transduction, as a clear consequence of Fact 1.37. However we have the following theorem which entails Theorem 1.44 with the help of Theorem 1.40.

Theorem 1.49 On each set of simple graphs that are planar, or of degree at most k, or of tree-width at most k for some fixed k, the identity is an MS 1,2transduction.

We conclude this discussion with a diagram (Table 1.1) relating the different types of MS-transductions, where lines indicate strict inclusions from bottomup. All inclusions are clear from the definitions and the above observations. That they are strict and that MS 1,1 and MS 2,2 are incomparable is proved by Examples 1.45,1.46,1.47 and 1.48.

MS 2,1 - MS 1,1 ∪ MS 2,2 - - MS 1,1 MS 2,2 - - MS 1,1 ∩ MS 2,2 - MS 1,2
Table 1.1: The different classes of monadic second-order transductions.

The results in Section 1.7.3 are stated for MS 1,1 -transductions and the VR algebra. There are analogous statements for MS 2,2 -transductions and the HR algebra. We first observe a technical point: since the identity on trees or terms is an MS 1,2 -transduction and since the composition of two MS-transductions is an MS-transduction, a transduction from trees or terms to graphs is an MS 1,jtransduction if and only if it is an MS 2,j -transduction. There are thus only two types of transductions taking trees or terms as input to consider and we get the following fully similar results: Theorem 1.50 For every k, the mapping that associates with a term t in T (F HR [k] ) the s-graph t JS is an MS 1,2 -transduction.

Theorem 1.51 (Equationality Theorem for the HR algebra) A set of graphs is HR-equational if and only if it is the image of the set of binary rooted trees under an MS 1,2 -transduction.

As in Section 1.7.3, this implies, using the closure of monadic second-order transductions under composition (Theorem 1.39), that the image of an HRequational set under an MS 2,2 -transduction is again HR-equational (generalizing the logical version of the Filtering Theorem for HR). Moreover, using the Equationality Theorems for both the VR and the HR algebra, we obtain that the image of an HR-equational set under an MS 2,1 -transduction is VRequational, and the image of a VR-equational set under an MS 1,2 -transduction is HR-equational. Note that if f is an MS i,j -transduction and g is an MS j,ktransduction (i, j, k = 1, 2), then their composition f •g is an MS i,k -transduction.

Using Proposition 1.20, Theorem 1.51 implies the following corollary.

Corollary 1.52 A set of graphs has bounded tree-width if and only if it is included in the image of the set of binary rooted trees under an MS 1,2 -transduction.

As for Theorem 1.42 and its corollary, both Theorem 1.51 and Corollary 1.52 hold with "the set of binary rooted trees" replaced by "the set of trees" or by "T (F ) where F is any finite signature with at least one constant symbol and at least one symbol of arity at least 2". In these results, graphs are without ports or sources in order to have simpler statements. Slightly more general results will be stated in Chapter 7.

From Corollaries 1.52 and 1.43 we get the following corollary from which quick proofs that certain sets of graphs have bounded or unbounded tree-width or clique-width can be obtained.

Corollary 1.53

(1) The image of a set of graphs of bounded tree-width under an MS 2,2transduction (resp. under an MS 2,1 -transduction) has bounded tree-width (resp. bounded clique-width).

(2) The image of a set of graphs of bounded clique-width under an MS 1,1transduction (resp. under an MS 1,2 -transduction) has bounded cliquewidth (resp. bounded tree-width).

(3) A set of simple planar graphs or of simple graphs of bounded degree has bounded tree-width if and only if it has bounded clique-width.

Statements ( 1) and (2) follow from Corollaries 1.52 and 1.43,by Theorem 1.39. Since all proofs are effective, the new bound can be computed from the given bound and the definition scheme of the MS-transduction. Using again Theorem 1.39, statement (3) follows from Theorem 1.49 and the fact that the identity is an MS 2,1 -transduction (Example 1.48). We will give in Section 2.5.5 a proof of statement (3) that does not use transductions and gives a good estimate of the bound on tree-width.

To conclude this section, let us stress the nice parallelism between two groups of definitions:

(1) the VR algebra, clique-width and MS formulas, and

(2) the HR algebra, tree-width and MS 2 formulas.

The Recognizability Theorem and the Equationality Theorem have fully analogous statements for both groups. Furthermore, the same graph theoretic conditions, those of Theorem 1.44 (and more general ones), ensure the equivalence of clique-width and tree-width, and simultaneously of MS and MS 2 formulas. The MS 1,2 -and MS 2,1 -transductions define "bridges" between the "world of bounded clique-width" and that of "bounded tree-width". The facts show how intimate are the relationships between logical and combinatorial notions.

Relational structures

Terms, graphs, labelled graphs, hypergraphs of different types are, or rather can be conveniently represented by relational structures. We have only seen up to now relational structures with unary and binary relations, that correspond to vertex-and edge-labelled graphs. However, many of our results can be proved without any difficulty for general relational structures.

In order to illustrate the usefulness of relational structures in Discrete Mathematics, we will present the examples of betweenness relations and cyclic orderings, two combinatorial notions defined in a natural way as ternary relations. Furthermore, in a different domain, the theory of relational databases is based on the concept of relational structure (see the book by Abiteboul, Hull and Vianu [*AbiHV]). However, our theory will not bring much to this field for reasons that we will discuss briefly.

Relational signatures and structures

A relational signature (to be contrasted with the notion of a functional signature defined in Section 1.1.4) is a finite set R of relation symbols where each symbol R of R has an associated arity ρ(R) in

N + := N -{0}. A relational structure of type R, called simply an R-structure, is a tuple S = D S , (R S ) R∈R consisting of a finite (possibly empty) domain D S and of a ρ(R)-ary relation 43 R S for each R ∈ R. The set of R-structures is denoted by STR(R). We let ρ(R) := max{ρ(R) | R ∈ R}. A signature R (resp. an R-structure) is binary if ρ(R) ≤ 2.
Since every k-ary function can be considered as a (k + 1)-ary relation, there is no loss of generality in considering relational structures as opposed to more 43 A k-ary relation can be defined as a subset of D k S or, equivalently, as a total function:

D k S → {True, False}.
general logical structures containing also functions. Although a constant, i.e., a 0-ary function can be replaced by a (singleton) unary relation, it will be convenient (for instance for representing the sources of graphs) to allow constants. However, in this introductory section, we will only consider relational structures without constants. Formulas are written with atomic formulas of the two forms x 1 = x 2 and R(x 1 , . . . , x ρ(R) ) where x 1 , . . . , x ρ(R) are individual variables. The notion of an MS-expressible property of R-structures follows immediately. A subset L of STR(R), the set of all R-structures, is MS-definable if it is the set of finite models of a monadic second-order sentence ϕ, formally, if

L = {S ∈ STR(R) | S |= ϕ}.
For expressing graph properties by monadic second-order formulas, we have defined two relational structures associated with a graph G, denoted by G and G . We have observed that certain graph properties are monadic secondorder expressible via the "rich" representation G , but not via the "natural" one G . The former properties are called MS 2 -expressible. A similar extension of monadic second-order logic can be defined for relational structures. We let

R Inc := R ∪ {in i | 1 ≤ i ≤ ρ(R)} with ρ(R) = 1 for R ∈ R and ρ(in i ) = 2 for i = 1, . . . , ρ(R). The incidence structure of S = D S , (R S ) R∈R is the R Inc -structure Inc(S) defined as D S ∪ T S , (R Inc(S) ) R∈R , in 1 Inc(S) , . . . , in k Inc(S)
where k := ρ(R) and:

T S := {(R, d 1 , . . . , d ρ(R) ) | R ∈ R, (d 1 , . . . , d ρ(R) ) ∈ R S }, R Inc(S) (d) :⇐⇒ d = (R, d 1 , . . . , d ρ(R) ) ∈ T S for some d 1 , . . . , d ρ(R) ∈ D S , in i Inc(S) (d, d ) :⇐⇒ d ∈ T S , d ∈ D S and d = (R, d 1 , . . . , d ρ(R) ) for some R ∈ R and d 1 , . . . , d ρ(R) such that d = d i .
It is clear that two R-structures S and S are isomorphic if and only if Inc(S) and Inc(S ) are isomorphic. The incidence structure Inc(S) of S is actually a vertex-and edge-labelled bipartite directed graph. Furthermore, each relation

in i Inc(S) is functional. A set of R-structures is MS 2 -definable if it is {S ∈ STR(R) | Inc(S)
|= ϕ} for a monadic second-order sentence ϕ over the signature R Inc . As for graphs, we obtain the notion of an MS 2 -expressible property of R-structures by replacing S by Inc(S).

Since the incidence structure of a relational structure is a labelled graph, the results concerning MS 2 formulas and labelled graphs of bounded tree-width transfer easily to relational structures. It is not difficult to see that the identity on incidence structures (of R-structures) is an MS 1,2 -transduction, which implies that Inc(S) has the same MS 2 -expressible and MS 1 -expressible properties (cf. Theorems 1. 49 and 1.44).

We define twd Inc (S) := twd (Inc(S)) to be used as parameter. For each k, we define STR k (R) as the class {S ∈ STR(R) | twd Inc (S) ≤ k} and we get the following result.

Theorem 1.54 Let R be a relational signature.

(1) The model-checking problem for CMS 2 sentences and the class of Rstructures is fixed-parameter linear with respect to twd Inc (S) + |ϕ| where S is the input structure and ϕ is the input sentence.

(2) For each k ∈ N , the CMS 2 -satisfiability problem for the class STR k (R) is decidable.

(3) If a subset of STR(R) has a decidable MS 2 -satisfiability problem, then it is contained in STR m (R) for some m.

This theorem generalizes to R-structures the parts of Theorems 1.25, 1.26 and 1.29 that concern tree-width and CMS 2 -expressible graph properties. Establishing analogous results for CMS properties (as opposed to CMS 2 properties) raises difficult open problems.

Betweenness and cyclic ordering

We now present the two combinatorial notions of betweenness and cyclic ordering that are naturally defined as ternary relations. They raise open questions relative to monadic second-order expressibility. All results stated below will be proved in Section 9.1.

With a finite linear order D, ≤ such that |D| ≥ 3 we associate the following ternary relation, called its betweenness relation: B(x, y, z) :⇐⇒ (x < y < z) ∨ (z < y < x) (where x < y means "x ≤ y and x = y"). We denote it by B(≤). This relation satisfies the following properties, for all x, y, z, t ∈ D:

(B1) B(x, y, z) ⇒ x = y ∧ x = z ∧ y = z, (B2) B(x, y, z) ⇒ B(z, y, x), (B3) B(x, y, z) ⇒ ¬B(y, z, x), (B4) B(x, y, z) ∧ B(y, z, t) ⇒ B(x, y, t) ∧ B(x, z, t), (B5) B(x, y, z) ∧ B(y, t, z) ⇒ B(x, y, t) ∧ B(x, t, z), (B6) x = y ∧ x = z ∧ y = z ⇒ B(x, y, z) ∨ B(y, z, x) ∨ B(z, x, y).
Conversely, if B is a ternary relation satisfying these properties, it is B(≤) for some linear order on D, hence is a betweenness relation. A set X ⊆ D 3 is consistent for betweenness if X ⊆ B for some betweenness relation B on D. The problem Betweenness consisting in deciding whether a given set X ⊆ D 3 is consistent for betweenness is NP-complete ([*GarJoh]).

If X is consistent for betweenness, we define

X := {B | X ⊆ B, B is a betweenness relation}.
The set X satisfies properties (B1)-(B5). We say that X is a partial betweenness relation on D if X = X. These definitions raise the following open questions, where a ternary relation X ⊆ D 3 is identified with the R-structure D, X (for some fixed singleton R):

Questions 1.55

(1) Is the set of relational structures { D, X | X is consistent for betweenness} MS-definable?

(2) Is the set of partial betweenness relations MS-definable?

For MS 2 the answers to these questions are positive.

Proposition 1.56 The set of partial betweenness relations and the set of ternary relations that are consistent for betweenness are MS 2 -definable.

For X ⊆ D 3 , we define the size of D, X as |D| + |X| and twd Inc (X) as the tree-width of the labelled graph Inc( D, X ). From Proposition 1.56 and Theorem 1.54 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] we immediately obtain the next result.

Corollary 1.57

The problem Betweenness is fixed-parameter linear with respect to twd Inc .

We now consider the similar notion of cyclic ordering. With a finite linear order D, ≤ such that |D| ≥ 3, we associate the ternary relation:

C(x, y, z) :⇐⇒ (x < y < z) ∨ (y < z < x) ∨ (z < x < y). Let D := {d 1 , . . . , d n } with d 1 < d 2 < • • • < d n
where d 1 , . . . , d n are points on a circle such that, according to some orientation of the plane, d i+1 follows d i and d 1 follows d n . Then C(x, y, z) expresses that, if one traverses the circle according to this orientation by starting at x, one meets y before z. We denote by C(≤) the ternary relation associated with ≤ in this way. A relation of this form is a cyclic ordering. A cyclic ordering C satisfies the following properties, for every x, y, z, t of its domain D:

(C1) C(x, y, z) ⇒ x = y ∧ x = z ∧ y = z, (C2) C(x, y, z) ⇒ C(y, z, x), (C3) C(x, y, z) ⇒ ¬C(x, z, y), (C4) C(x, y, z) ∧ C(y, t, z) ⇒ C(x, y, t) ∧ C(x, t, z), (C5) x = y ∧ y = z ∧ x = z ⇒ C(x, y, z) ∨ C(x, z, y).

Every ternary relation satisfying

(C1)-(C5) is a cyclic ordering. A subset X of D 3 is consistent for cyclic ordering if X ⊆ C for some cyclic ordering on D.
The problem Cyclic Ordering that consists in deciding if a set X ⊆ D 3 is consistent for cyclic ordering is NP-complete ( [GalMeg]).

As for betweenness, for X ⊆ D 3 , we let X be the intersection of all cyclic orderings C on D such that X ⊆ C (and X is undefined if X = ∅ or if there is no cyclic ordering containing X). A partial cyclic ordering on a set D is defined as a subset of D 3 such that X = X. For cyclic ordering, we have the same results and open questions as for betweenness.

Relational databases

The theory of relational databases (exposed in the book [*AbiHV]) is based on relational structures. In this theory, a relational signature R is called a database schema, its elements are called relation schemas, and an R-structure is called a database instance. A query is a syntactic or algorithmic description of a relation with specified arity written in some query language and defined in terms of the relations stored in the considered database instance. One concern is to compare the expressive powers of several such languages. Another one is to construct efficient algorithms for evaluating these relations, that is, to list their tuples or sometimes, only to count them.

Theorem 1.54 yields linear-time algorithms for such computations (and for fixed queries) in cases where the input structures are constrained to belong to STR k (R) for some fixed k, or to satisfy some similar condition (e.g., for binary structures, to have bounded clique-width), and formulas are required to be monadic second-order. In the case of databases, there is usually no reason to assume that the relational structure modelling the database instance satisfies such constraints. Constraints are rather put on the formulas expressing queries in order to ensure the existence of efficient algorithms. These constraints are formulated in terms of tree-width and hypertree-width of certain graphs associated with formulas: we refer the reader to the comprehensive article by Gottlob et al. [GotLS]. Hence, the basic concepts of relational structures and logical formulas are the same as in the algorithms of Section 1.5, but the methods for constructing fixed-parameter tractable algorithms are not. The books by Downey and Fellows [*DowFel] and by Flum and Grohe [*FluGro] present in detail the theory of fixed-parameter tractability and contain important sections on tree-decompositions and their algorithmic applications. The surveys by Grohe [*Gro] and by Kreutzer [*Kre] focus on algorithms for problems expressed by first-order and monadic second-order sentences relative to graphs that are structured in various ways.

One of our objectives is to extend to finite graphs the algebraic view of Formal Language Theory initiated by Mezei and Wright [MezWri]. The least fixed-point characterization of context-free languages due to Ginsburg and Rice [GinRic] and to Chomsky and Schützenberger [ChoSch] has inspired the notion of equational sets, defined in [MezWri]. This article extends to general algebras the notion of recognizability studied for monoids by Eilenberg, Schützenberger and many others: see the books by Eilenberg [*Eil] and Sakarovitch [*Sak].

Monadic second-order logic on words, terms and trees, either finite or infinite, and its relationships with automata is a vast domain presented in the two book chapters by Thomas [*Tho90] and [*Tho97a]. From this theory, we will only use Theorem 1.16 by Doner [Don] and Thatcher and Wright [ThaWri] that generalizes to terms the corresponding basic result established for words by Büchi [Büc], Elgot [Elg] and Trakhtenbrot [Tra].

We will not study countable graphs and structures. For this rich topic we refer the reader to the book chapters by Thomas Chapter 2

Graph algebras and widths of graphs

We will define graph operations that generalize the concatenation of words. Some of these operations have been used in Section 1.1 to define the cographs and the series-parallel graphs. We will define actually two signatures of graph operations, hence two graph algebras. Both algebras will be defined in such a way that their equational sets are exactly the sets defined by certain context-free graph grammars. (The notion of an equational set has been presented informally in Section 1.1.4 and will be studied in detail in Chapter 3.)

Two main types of context-free sets of graphs defined by certain graph rewriting mechanisms have emerged from the intense research conducted from (around) 1980 and that is synthesized in the handbook [*Roz] edited by Rozenberg.

We will first define the HR graph algebra that corresponds in this respect to the Hyperedge Replacement grammars. It turns out that the operations of this algebra yield an exact characterization (as equational sets) of the sets of graphs of tree-width bounded by fixed integers. The terms built with the operations of the HR algebra can be seen as algebraic expressions of tree-decompositions. (Tree-width and the corresponding tree-decompositions are important for the construction of efficient graph algorithms and also for the characterization of the graphs that exclude a fixed graph as a minor.)

The second algebra, called the VR algebra, is defined so that its equational sets are those generated by the (context-free) Vertex Replacement grammars. A new graph complexity measure called clique-width has arisen in a natural way from the definition of the VR algebra, without having (yet) any independent combinatorial characterization. As tree-width, clique-width is an interesting parameter yielding fixed-parameter tractable algorithms for problems expressible in monadic second-order logic.

This chapter introduces by necessity many definitions and a lot of notation. We define algebras and terms in Section 2.1, graphs in Section 2.2, the HR algebra in Section 2.3, tree-decompositions and their relationships with the HR algebra in Section 2.4, the VR algebra and clique-width in Section 2.5. The HR and VR algebras are one-sorted, but for defining the notion of recognizability, we will need many-sorted versions of these algebras that we define in Section 2.6.

Algebras and terms

For every set A, we denote by Seq(A) the set of finite sequences of elements of A and by s = (a 1 , . . . , a n ) the generic sequence. Its length is n, denoted by |s|. The empty sequence of length 0 is denoted by (). The concatenation of two sequences is denoted by

•, hence (a 1 , . . . , a n ) • (b 1 , . . . , b m ) = (a 1 , . . . , a n , b 1 , . . . , b m ).
If A is an alphabet, i.e., a set1 of letters (or symbols), an element of Seq(A) is called a word over A. The notations A * , a 1 a 2 • • • a n and ε replace respectively Seq(A), (a 1 , . . . , a n ) and (). The • representing concatenation is frequently omitted. The i-th element of a sequence s (in particular of a word s) is denoted by s[i]. A language over A is subset of A * . (A language in general is a set of words or a set of terms, see Definition 2.2 below).

If k belongs to N , the set of natural numbers (including 0), then [k] denotes the set {1, . . . , k}, so that [0] = ∅. The set N -{0} of positive integers is denoted by N + .

Definition 2.1 (Algebras)

A functional signature F is a set of function symbols, each being given with a natural number called its arity. We denote by ρ(f ) the arity of f . We say that f is a constant symbol if it has arity 0. We let

F i := {f ∈ F | ρ(f ) = i}, F + := F -F 0 and ρ(F ) := max{ρ(f ) | f ∈ F }. A signature is unary (resp. binary) if ρ(F ) ≤ 1 (resp. ρ(F ) ≤ 2).
Let F be a (finite or infinite) functional signature. An F -algebra M is a set M equipped with total functions f M : M ρ(f ) → M for f ∈ F . If f ∈ F 0 , then f M is a function with no arguments, hence an element of M that we call a constant. We write M = M, (f M ) f ∈F . We call M the domain of M and the functions f M (for f in F + ) its operations. The domain may be empty unless F 0 is nonempty.

The graph algebras G u = G u , ⊕, ⊗, 1 and J d 2 = J d 2 , , •, e have been defined in Section 1.1. In these cases and in many others we denote an operation f M by f , that is, we do not distinguish an operation from the symbol denoting it. Algebras of terms and words are defined below (Definitions 2.2 and 2.7).

A signature H is a subsignature of F , which we denote by H ⊆ F , if H is a subset of F and the arity of f in H is the same with respect to H and to F . If M is an F -algebra and N is an H-algebra, then we say that N is a subalgebra of M, which we denote by

N ⊆ M, if H is a subsignature of F , N ⊆ M and f N = f M N ρ(f ) for every f ∈ H (in particular f N = f M if f ∈ F 0 ). A homomorphism h : M → N, where M and N are two F -algebras is a mapping h : M → N such that for every f ∈ F and m 1 , . . . , m ρ(f ) ∈ M , we have h(f M (m 1 , . . . , m ρ(f ) )) = f N (h(m 1 ), . . . , h(m ρ(f ) )). In particular h(f M ) = f N if f ∈ F 0 . If h is a bijection, it is an isomorphism and M, N are isomorphic algebras.
The Cartesian product of two F -algebras M and N is defined as the F -algebra

M × N := M × N, (f M×N ) f ∈F where f M×N ((m 1 , n 1 ), . . . , (m ρ(f ) , n ρ(f ) )) := (f M (m 1 , . . . , m ρ(f ) ), f N (n 1 , . . . , n ρ(f ) )) for all m 1 , . . . , m ρ(f ) in M and n 1 , . . . , n ρ(f ) in N .
A monoid is an F -algebra M such that F = {•, 1} where • is binary, 1 is a constant symbol, and the operation • M is associative with unit element 1 M . The symbol will also be used to denote the unit element.

Definition 2.2 (Terms)

Let F be a functional signature. The set T (F ) of terms over F is the unique subset L of F * (here we consider F as an alphabet) such that:

L = f ∈F f L • • • L (2.1)
where, in each f L • • • L, we have ρ(f ) occurrences of L.2 This way of writing terms, due to Lukaciewicz, is called Polish prefix notation. This notation is unambigous, which means that every element of L has a unique expression of the form

f t 1 • • • t ρ(f ) for f ∈ F and t 1 , . . . , t ρ(f ) ∈ L.
Inductive definitions and proofs will be based on this fact. The set of subterms of a term t is defined by the following induction:

Subterm(t) := {t} ∪ Subterm(t 1 ) ∪ • • • ∪ Subterm(t ρ(f ) ) if t = f t 1 • • • t ρ(f )
and t 1 , . . . , t ρ(f ) are terms.

For signature F , a language over F is a subset of T (F ); since T (F ) ⊆ F * , it is also a language over the alphabet F .

Let M be an F -algebra. Every term t ∈ T (F ) evaluates into an element of M denoted by t M . Formally, we have:

t M := f M (t 1M , . . . , t ρ(f )M ) if t = f t 1 • • • t ρ(f ) and t 1 , . . . , t ρ(f ) ∈ T (F ); the value t M is
defined in a unique way because Polish prefix notation is unambigous. We will also denote by

val M : T (F ) → M the mapping that associates t M with t ∈ T (F ). Let F ⊆ F . A subset of M is generated by F if it is a subset of val M (T (F )).
The subalgebra of M with signature F and domain val M (T (F )) is called the subalgebra of M generated by F . In particular, we say that M is generated by

F if M = val M (T (F )).
We let T(F ) be the F -algebra with domain T (F ) such that:

f T(F ) (t 1 , . . . , t ρ(f ) ) := f t 1 • • • t ρ(f ) ,
for all f ∈ F and t 1 , . . . , t ρ(f ) ∈ T (F ). It is called the initial F -algebra because for every F -algebra M, the mapping val M is the unique homomorphism : T(F ) → M. This homomorphism is surjective if and only if M is generated by F . We also define S(F ) as the F -algebra F * , (f S(F ) ) f ∈F such that each operation f S(F ) is defined like f T(F ) , that is:

f S(F ) (u 1 , . . . , u ρ(f ) ) := f u 1 • • • u ρ(f )
for all f ∈ F and u 1 , . . . , u ρ(f ) in F * . Then T(F ) is the subalgebra of S(F ) generated by F .

We now introduce some definitions relative to the internal structure of terms.

(t) = {Occ(t, f )|f ∈ F }.
The leading symbol of t is t [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. The height of t is defined inductively as follows:

ht(f ) = 0 if f ∈ F 0 ht(f t 1 • • • t ρ(f ) ) = 1 + max 1≤i≤ρ(f ) ht(t i ) otherwise.

Definition 2.4 (Notational improvements)

In order to improve readability, we will write terms with commas and parentheses. For example the term f ghabcggbcc where ρ(f With this notation the arities of the symbols occurring in a term need not be specified because they can be determined from the term (whereas for parsing Polish prefix notation, one needs to know the arities of symbols). In other words, we use for terms the same notation as for function application in the metalanguage.

) = 3, ρ(g) = 2, ρ(h) = 1, ρ (
Another notational variant will be used. If f is a binary function symbol intended to denote an associative operation, we will write t 1 f t 2 instead of f (t 1 , t 2 ). This notation is ambiguous because the two different terms f (f (t 1 , t 2 ), t 3 ) and f (t 1 , f (t 2 , t 3 )) are denoted in the same way by t 1 f t 2 f t 3 , but this ambiguity does not matter if we use this notation in cases where f denotes an associative operation. This notation can be used for a single associative binary operation. For writing terms with several such operations, we add parentheses. For example we will write (1

⊕ 1 ⊕ 1) ⊗ (1 ⊕ 1 ⊕ 1) the term ⊗ ⊕ 1 ⊕ 11 ⊕ 1 ⊕ 11 that denotes the cograph K 3,3 (cf. Section 1.1.2). Another notation for this term is ⊗(⊕(1, ⊕(1, 1)), ⊕(1, ⊕(1, 1))). We might also use the notation ⊕(1, ⊕(1, 1)) ⊗ ⊕(1, ⊕(1, 1)).
3 Positions can also be designated by finite sequences of integers called Dewey sequences. This method is used in many articles and books, e.g., [*Cou83], [*Com+] and [*GecSte].

Definition 2.5 (Terms with variables)

We will use terms written with first-order variables, i.e., variables that can denote arbitrary elements of the domains of algebras (and not functions or relations). If X is a set of variables (implicitly, of first-order variables), then T (F, X) is the set of terms over F ∪ X, where variables are symbols of arity 0. We always assume implicitly that F ∩ X = ∅.

Let X = {x 1 , . . . , x n } be a set of variables listed in this order and t be a term in T (F, X). In every F -algebra M, the term t defines an n-ary total function t M : M n → M such that for all m 1 , . . . , m n in M , t M (m 1 , . . . , m n ) is the value of t in M computed by considering x i as a constant symbol denoting m i . This function will also be denoted by λm 1 , . . . , m n • t M (m 1 , . . . , m n ) or by λx 1 , . . . , x n • t if M is known from the context. (This notation has the advantage of specifying the list of argument variables.) Such a function is called a derived operation of M. A term t with variables is linear if each variable has at most one occurrence in t. A derived operation is linear if it is defined by a linear term.

We denote by X n the standard set of variables {x 1 , . . . , x n } (listed in this order) and similarly Y k := {y 1 , . . . , y k }.

Definition 2.6 (Substitutions, contexts and subterms)

If t ∈ T (F, X), if v 1 , . . . , v n are pairwise distinct variables in X and t 1 , . . . , t n ∈ T (F, X), then we denote by t[t 1 /v 1 , . . . , t n /v n ] or equivalently by t[t i /v i ; i ∈ [n]]
the result of the substitution in t of t i for each occurrence of v i . A variable v i may have no or several occurrences in t, hence an argument t i may disappear or be duplicated. For example if

t = f gav 1 v 1 v 3 , then t[t 1 /v 1 , t 2 /v 2 , t 3 /v 3 ] = f gat 1 t 1 t 3 for all terms t 1 , t 2 , t 3 in T (F, X).
This operation has the following semantic meaning: if s = t[t 1 /v 1 , . . . , t n /v n ] where t, t 1 , . . . , t n ∈ T (F, {v 1 , . . . , v n }), then for every F -algebra M, the mapping s M is the composition of the derived operations : M n → M associated with t, t 1 , . . . , t n , i.e., s M (m) = t M (t 1M (m), . . . , t nM (m)) for every m ∈ M n .

A context over F ∪ X is a term t in T (F, X ∪ {w}) where w is an auxiliary variable assumed not to belong to X and that has a unique occurrence in t. The term w is the empty context. We denote by Ctxt(F, X) the set of contexts over F ∪ X, and we write Ctxt(F ) instead of Ctxt(F, ∅). If c ∈ Ctxt(F, X) and t ∈ T (F, X) then c[t] denotes the result of the substitution in c of t for w. The actual choice of w as auxiliary variable is irrelevant provided w / ∈ X. This variable does not appear in the notations Ctxt(F, X) and c[t].

If t ∈ T (F, X) and i ∈ Pos(t), then t can be written in a unique way as t = αt β where α, β ∈ (F ∪ X) * , |α| = i -1 and t ∈ T (F, X). We call t the subterm of t issued from position i, and we denote it by t/i. (Hence t/1 = t). Let w be a variable (not in X) to be used for defining contexts as terms. The term c = αwβ belongs to Ctxt(F, X) and we have t = c[t ]. We will denote it by t ↑ i and call it the context of t issued from i. Hence, we have t

= (t ↑ i)[t/i]. For example, if t = f gav 1 v 1 v 3 (with ρ(f ) = 3, ρ(g) = 2, ρ(a) = 0) then t/2 = gav 1 and t ↑ 2 = f wv 1 v 3 .
If t ∈ T (F, X), we denote by ListVar (t) the word in X * obtained by deleting from t all symbols from F . Every term

t in T (F, X n ) such that ListVar (t) = x i1 • • • x i k is equal to t [x i1 /y 1 , . . . , x i k /y k ] for a unique term t in T (F, Y k ) such that ListVar ( t ) = y 1 y 2 • • • y k . For t = f gax 3 x 3 x 1 with f, g, a as above, we have ListVar (t) = x 3 x 3 x 1 , t = f gay 1 y 2 y 3 , i 1 = i 2 = 3 and i 3 = 1. It is clear that t M = λm 1 , . . . , m n • t M (m i1 , . . . , m i k ).
Definition 2.7 (Three algebras of words) The set of words A * over an alphabet A is an F A -algebra where the signature F A consists of a binary symbol • to be interpreted as the concatenation, of the constant symbol to be interpreted as the empty word ε and of the constant symbol a to be interpreted as the word a for each a ∈ A. We let W(A) := A * , •, ε, (a) a∈A be the corresponding algebra. It is generated by F A (every word in A * is the value of some term in T (F A )). The algebra A * , •, ε is the free monoid generated by A.

However, two other algebraic structures on A * will be relevant to our purposes. We let U A := A ∪ { } be the unary signature such that ρ( ) = 0 and ρ(a) = 1 for each a in A. We let then W right (A) := A * , ε, (r a ) a∈A where r a (w) := wa for every a ∈ A and w ∈ A * . Dually, W left (A) := A * , ε, (l a ) a∈A where l a (w) := aw for every a ∈ A and w ∈ A * .

These two algebras are generated by U A and for each of them, a word in A * is the value of a unique term in

T (U A ). It is clear that if a 1 , . . . , a n ∈ A and t = a n (a n-1 (• • • (a 1 ( )) • • • )) then a 1 • • • a n-1 a n = val W right (A) (t) and a n a n-1 • • • a 1 = val W left (A) (t)
. Hence, we have two bijections from T (U A ) to A * , which are isomorphisms from T(U A ) to W right (A) and W left (A).

Definition 2.8 (Effectively given sets, signatures and algebras) We will use infinite signatures for defining graph algebras. We now discuss effectivity questions in order to obtain algorithms and not only abstract formalizations.

An encoding of a finite or countable set A is a triple (|A|, enc A , ξ A ) such that |A| belonging to N ∪ {ω} is the cardinality of A, enc A is a decidable subset4 of N and ξ A is a bijection : A → enc A . Since enc A = ξ A (A), an encoding is uniquely determined by the bijection ξ A , which will therefore also be called an encoding.

We fix standard encodings (ω, N , ξ) of sets like N , N × {0, 1}, N × N and Seq(N ) where we assume that ξ and ξ -1 are computable. For instance, for the set N , the mapping ξ is the identity on N , and for the set N × {0,

) := ξ Seq(N ) (ξ A (a 1 ), . . . , ξ A (a m )). A subset B of A is a decidable subset of A if ξ A (B) := {ξ A (b) | b ∈ B} is a decidable subset of enc A (and hence of N ). The standard encoding of B is the restriction of ξ A to B, i.e., the triple (|B|, ξ A (B), ξ A B). A function f : A 1 × • • • × A k → A is computable (implicitly, via the encodings of A 1 , . . . , A k , A) if the mapping f : enc A1 × • • • × enc A k → enc A such that f (x 1 , . . . , x k ) := ξ A (f (ξ -1 A1 (x 1 ), . . . , ξ -1 A k (x k )) is computable.
For example, B is a decidable subset of A if and only if the mapping g : A → {True, False} is computable, where g(a) is defined to be True if a ∈ B and False otherwise.

Encoded sets will be given as input to algorithms and they will be produced as output by algorithms. An encoded set is effectively given if it is specified by its cardinality |A| ∈ N ∪ {ω} and an algorithm that decides the membership of an element of N in enc A . It is semi-effectively given if it is specified by a membership algorithm only. If an encoded set A is finite and effectively given, then the set enc A can be computed5 , but if it is only semi-effectively given, then that is not possible in general. Conversely, if the finite set enc A is given, then it is effectively given (i.e., its cardinality can be computed and a membership algorithm for enc A can be constructed).

A signature F is effectively given if the set F is effectively given and the arity mapping ρ : F → N is computable, i.e., the mapping ρ := ρ • ξ -1 F is computable (and an algorithm computing ρ must be specified). It follows that the set of terms T (F ) is semi-effectively given by its standard encoding as a decidable subset of Seq(F ). If the integer i encodes the word f 1 • • • f m , with f 1 , . . . , f m ∈ F , then the sequence (ξ F (f 1 ), . . . , ξ F (f m )) of integers that encode its function symbols can be computed from i, because ξ -1 Seq(N ) is computable. It can then be checked if that sequence encodes a term t in T (F ), and if this is the case, the integers encoding its subterms can be computed because ξ Seq(N ) is computable. In a similar way the sets of terms T (F, X n ) are effectively given, where X n is the set of standard variables {x 1 , . . . , x n }. With the standard encoding of T (F ), the algebra T(F ) of terms over F is a semi-effectively given F -algebra, according to the next definition, as can easily be verified.

An F -algebra M is effectively given (respectively semi-effectively given) if its signature F is effectively given, its domain M is effectively given (respectively semi-effectively given) and its operations f M are computable in the following uniform way: the mapping ζ M : Seq M → M is computable (and an algorithm computing ζ M must be specified), where Seq M is the decidable subset of F × Seq(M ) consisting 6 of all tuples (f, x 1 , . . . , x p ) such that f ∈ F , p = ρ(f ) and x 1 , . . . , x p ∈ M , and ζ M is defined by ζ M (f, x 1 , . . . , x p ) := f M (x 1 , . . . , x p ). It follows in particular that each operation is computable. Furthermore, the mapping val M : T (F ) → M is also computable. The derived operations of M are computable in a similar way (with a term t in T (F, X p ) instead of a function symbol f in F p ).

If M is semi-effectively given and generated by F , then there exists a computable "parsing" mapping π : M → T (F ) that associates with every element m in M a term t such that val M (t) = m. To compute π(x) it suffices to enumerate the elements of N until some integer is found that encodes a term t such that ξ M (val M (t)) = x, and this equality can be checked since val M is computable. If M is finite and effectively given, such a mapping π, or equivalently π itself, can be computed once and for all into a table.

Graphs

We assume well known the basic terminology of graph theory. We mainly fix notation and give some definitions that are not standard. We pay particular attention to the distinction between a concrete graph with specified sets of vertices and edges, and an abstract graph which is the isomorphism class of a concrete graph.

There are many types of graphs. They can be directed or not, with or without loops and/or multiple edges; they can be "decorated" with labels, colors or weights. We give formal definitions for a few basic cases and we indicate how they extend to "decorated" graphs. Definition 2.9 (Graphs) A directed graph G consists of a set of vertices V G , a set of edges E G and a mapping vert G that associates with every edge e in E G an ordered pair of

vertices vert G (e) ∈ V G × V G . An undirected graph G is a triple V G , E G , vert G as above except that vert G (e)
is a set of one or two vertices for each edge e in E G . 7 In many cases, we leave vert G implicit and we only use V G and E G . We always assume that V G ∩ E G = ∅, and when we discuss several graphs G, H, we assume that V G ∩ E H = ∅ except when specified otherwise (e.g., for line graphs; cf. Section 1.8.2, Example 1.45). If G is directed and vert G (e) = (u, v) (we may have u = v) we often write e : u → v and we say that e links u to v or that e is from u to v. If G is undirected and vert G (e) = {u, v} (possibly u = v) we write e : u -v and we say that e links u and v or that e is between u and v. (We write u → G v or u -G v if it is useful to specify the graph G.) If e : u → v or e : u -v we say that e is incident with u and v, and that u and v are the end vertices assume that its standard encoding is used.

7 For a more precise set theoretical formalization, one could choose a countable set U containing N that is closed under pairing (i.e., is such that (x, y) and {x, y} are in U if x, y ∈ U ), and require for all graphs G that V G and E G are contained in U . In this way, the collection of all graphs forms a set.

(or ends) of e. In the former case, we say that u is the tail of e and v its head.

In both cases we say that u and v are adjacent or that they are neighbors. The degree of a vertex is the number of its incident edges, and (in the directed case) its indegree (outdegree) is the number of its ingoing (outgoing) edges, i.e., the edges of which it is the head (the tail). A vertex is isolated if it is has degree 0. The degree of a graph is the maximal degree of its vertices, and similarly for the indegree and outdegree of a graph. Two (distinct) edges e and f are parallel if vert G (e) = vert G (f ). A graph is simple if it has no pair of parallel edges. Parallel edges are also called multiple edges. We say that e is a loop if e : u → u or e : u -u, and we say in this case that u has a loop. A graph is loop-free if no vertex has a loop.

For a simple directed graph G, one can identify an edge e with the ordered pair vert G (e). Such a graph can be specified more simply as a pair V G , edg G where edg G ⊆ V G × V G is the binary relation such that (u, v) ∈ edg G if and only if e : u → v for some edge e. Every binary relation on a set V defines a graph with set of vertices V .

A simple undirected graph G can be specified similarly as a pair V G , edg G where edg G is the symmetric relation such that (u, v) ∈ edg G if and only if e : u -v for some e in E G . It follows that a simple undirected graph can be considered as a simple directed graph with a symmetric edge relation, i.e., such that every edge (u, v) that is not a loop has an opposite edge (v, u). However, this identification is not always convenient for our grammatical and logical treatments. In many cases, we will consider directed and undirected graphs as distinct species and use explicit codings between directed and undirected graphs whenever appropriate.

For

G = V G , E G , vert G , directed, we denote by und (G) the undirected graph V G , E G , vert und(G) such that vert und(G) (e) = {u} if e : u → G u and vert und(G) (e) = {u, v} if e : u → G v, u = v.
We call it the undirected graph underlying G. Even if G is simple, the graph und (G) may have pairs of parallel edges (coming from pairs of opposite directed edges). An orientation of an undirected graph is a directed graph obtained by choosing a direction for each edge (i.e., choosing a head and a tail). Hence, G is an orientation of H if and only if und (G) = H. The core of a graph G is the graph core(G) obtained from und (G), or from G if G is undirected, by deleting loops and by fusing parallel edges. Thus, core(G) is simple, loop-free and undirected.

A clique is a simple, loop-free, undirected graph, such that any two distinct vertices are adjacent. We denote by K n the isomorphism class of cliques with n vertices. (Graph isomorphisms are formally defined in Definition 2.10 below). A clique in a graph G (directed or not) is a set of vertices of G such that any two vertices are adjacent.

Let G be an undirected graph, and u, v ∈ V G . A walk from u to v (or, linking u to v) is a sequence of edges (e 1 , . . . , e n ) such that, for some sequence of vertices (u 0 , . . . , u n ) with u = u 0 and u n = v, we have vert G (e i ) = {u i-1 , u i } for each i = 1, . . . , n. This walk is a path if u i = u j for every i and j = i. It will be convenient to view, for n = 0, the empty sequence () as an empty path from u to u for each vertex u. A cycle is a walk (e 1 , . . . , e n ) such that n ≥ 1, u 0 = u n , e i = e j if i = j and u i = u j if 0 ≤ i < j < n. In cases where this does not create ambiguity, especially for simple graphs (such as trees), we will designate a path by the sequence (u 0 , u 1 , . . . , u n ) of its vertices. This sequence is not empty, even if n = 0.

If G is a directed graph, the notions of walk, path and cycle are those relative to und (G). A directed walk is a walk (e 1 , . . . , e n ) as above such that vert G (e i ) = (u i-1 , u i ) for each i. The notions of directed path and of directed cycle (also called a circuit) follow accordingly.

A graph G is connected if any two vertices are the ends of a path. A graph G is finite if the set V G ∪ E G is finite. We will mostly consider finite graphs. However certain expressions of graph properties by logical formulas will be valid for infinite graphs. We will indicate if finiteness is crucial for the validity of such formulas.

We denote by ∅ the empty graph, such that V ∅ = E ∅ = ∅ (where ∅ denotes the empty set). The empty graph is connected.

We define the size G of a finite graph G as |V G |+|E G |. This notion will be used for analyzing algorithms. In many cases, and in particular for algorithms taking simple graphs as input, the appropriate notion of size will be |G| := |V G |.

Definition 2.10 (Isomorphisms)

Let G and H be graphs, either both directed or both undirected. An iso-

morphism h : G → H is a pair of bijections (h V , h E ) where h V : V G → V H , h E : E G → E H , vert H (h E (e)) = (h V (u), h V (v)) if e : u → v, and vert H (h E (e)) = {h V (u), h V (v)} if e : u -v. If G and H are simple, it suf- fices to specify h V because, if (h V , h E ) is an isomorphism : G → H, then h E
is determined in a unique way from h V by the conditions of the definition. In this case, an isomorphism : G → H can be more simply defined as a bijection h V : V G → V H such that some bijection h E : E G → E H exists that makes (h V , h E ) into an isomorphism. We denote by G H the existence of an isomorphism : G → H and we say that G and H are isomorphic.

All our results will concern graphs up to isomorphism. To establish them, we will need to perform constructions on graphs with specific sets of vertices and edges. Hence we refine our terminology as follows: a graph G = V G , E G , vert G is called a concrete graph. By an abstract graph, we mean the isomorphism class, denoted by [G] iso , of a concrete graph G. We say that a concrete graph G is isomorphic to an abstract graph

[H] iso if G H, i.e., if G belongs to the isomorphism class [H] iso ; this is also written as G [H] iso .
A graph property is a property of concrete graphs invariant under isomorphism, hence a property of abstract graphs. By a class of graphs we mean a set of concrete graphs closed under isomorphism, hence equivalently, a set of abstract graphs8 . In most circumstances we will leave implicit the distinction between a concrete and an abstract graph. Roughly speaking, statements concern abstract graphs while proofs, usually starting with "Let G = V G , E G , vert G be a graph", deal by necessity with concrete graphs.

Definition 2.11 (Concrete and abstract labelled graphs) A labelled (or colored ) graph is a graph equipped with additional information, formalized as follows. A labelling function (or coloring function) of a concrete graph G is a mapping γ from V G ∪ E G into a set Γ. In most cases, Γ will be finite.

For example, finite automata recognizing words can be seen as labelled graphs: a finite automaton is a directed graph such that certain vertices, called its states, are labelled as initial or final (or accepting). A state may be labelled as both initial and final. Furthermore, each transition, i.e., each edge of the corresponding graph, has a label which is a letter from a finite alphabet or the symbol ε denoting the empty word.

The following notion of labelled graph includes these graphs. Let K and Λ be two finite disjoint9 sets of labels. A (K, Λ)-labelled graph is a graph, directed or not, such that:

-each edge has one and only one label, which belongs to Λ, and -each vertex has a possibly empty set of labels belonging to K.

The corresponding labelling function maps

V G ∪ E G into Γ := P(K) ∪ Λ. Such a graph G is simple if no two edges have the same pair (ordered if G is directed, unordered if G is undirected) of end
vertices and the same label. We may have parallel edges with different labels. For example, a finite automaton over an alphabet A is a simple, directed, (K, Λ)-labelled graph where K = {initial , final } and Λ = A ∪ {ε}.

If R is a binary relational signature (cf. Section 1.9.1) then R-structures correspond bijectively to simple, directed (R 1 , R 2 )-labelled graphs, where R i is the set of symbols in R of arity i. The graph G corresponding to an R-structure S = D S , (R S ) R∈R has vertex set D S , it has an edge from u to v labelled by R in R 2 if and only if (u, v) ∈ R S , and a vertex u has label R in R 1 if and only if u ∈ R S . Conversely, every simple, directed (K, Λ)-labelled graph G is associated in this way to a binary relational R-structure such that (R 1 , R 2 ) = (K, Λ).

According to the definition, a (K, ∅)-labelled graph has no edges. However, we will call (K, ∅)-labelled a graph with unlabelled edges (equivalently, with all edges having the same label) and vertices with labels in K. In this way, we need not specify a default edge label.

We now define isomorphisms of labelled graphs, from which follows the notion of an abstract labelled graph. If G and H are concrete graphs with labelling functions γ G and γ H , we say that an isomorphism h :

G → H is an isomorphism of labelled graphs if γ H (h V (u)) = γ G (u) for every u ∈ V G ,
and similarly for h E . Hence we can define abstract labelled graphs as isomorphism classes of concrete labelled graphs. We use the same terminology as in the case of unlabelled graphs.

These definitions apply to weighted graphs, where a weight function is a total or partial function from V G ∪ E G to the set of real numbers or to another set usually equipped with an algebraic structure. Each time we will use labelled or weighted graphs, we will specify the particular properties of the labelling or weight functions under consideration.

Definition 2.12 (Subgraphs) Let G and H be concrete graphs, either both directed or both undirected. We

say that H is a concrete subgraph of G, written H ⊆ G, if V H ⊆ V G , E H ⊆ E G and vert H (e) = vert G (e) for all e ∈ E H . It is an induced subgraph, written H ⊆ i G, if E H is the set of edges of G having their ends in V H , and it is a spanning subgraph if V H = V G . If G and H are abstract graphs, saying that H is a subgraph of G means that H is isomorphic to a concrete subgraph of a concrete graph isomorphic to G.
If G is labelled and H ⊆ G, then the edges and vertices of H have the same labels as in G.

The induced subgraph of a concrete graph G with set of vertices

X ⊆ V G is denoted by G[X]. We let G -X := G[V G -X] and G -u := G -{u} if u is a vertex. If F ⊆ E G , then the subgraph G[F ] of G is such that E G[F ] = F and V G[F ]
is the set of vertices incident with an edge in F , and its subgraph

G -F is defined by V G-F = V G and E G-F = E G -F ; we let G -e := G -{e} if e is an edge.

Definition 2.13 (Trees)

A tree is a nonempty connected undirected graph without cycles. It is thus simple, loop-free and every two vertices are linked by a unique path. A rooted tree is a directed graph T such that und (T ) is a tree, all vertices have indegree 1 except one which has indegree 0; this vertex is called the root of T and is denoted by root T . In a rooted tree, every vertex is accessible from the root by a unique directed path. The edge directions of a rooted tree T are defined in a unique way from und (T ) and root T . Any vertex of a tree can be chosen as a root so as to turn the tree into a rooted tree. Hence, in many cases, we will specify a rooted tree as a pair (U, r) consisting of a tree U and a vertex r.

A forest (a rooted forest) is a (possibly empty) graph, each connected component of which is a tree (a rooted tree). A rooted forest has thus a (possibly empty) set of roots, and can be defined by the pair (F, R) of a forest F and a set of vertices R containing one and only one vertex from each connected component. Every subgraph of a (rooted) forest is a (rooted) forest, and every nonempty connected subgraph of a (rooted) tree is a (rooted) tree. The height ht(H) of a rooted forest H is the maximal length (i.e., number of edges) of a directed path of H.

In many cases, we will discuss simultaneously a graph and a tree representing its structure. It will be convenient to call nodes the vertices of the tree in order to distinguish them from the vertices of the graph.

Since it is a simple graph, a tree or a forest H can be specified as a pair H = N H , edg H where N H is the set of its nodes. If H is a rooted forest and u ∈ N H , we denote by H/u the subtree issued from u. It is the rooted tree such that N H/u is the set of nodes reachable from u by a directed path (this path may be empty, so that u belongs to N H/u ) and edg H/u = edg H ∩(N H/u ×N H/u ). If H is labelled or weighted, then H/u inherits the labels or weights of H in the obvious way. For a rooted forest H we will denote by son H the relation edg H , and we will use the classical terminology for rooted trees: leaf, son, father, ancestor, descendant, least common ancestor of two nodes, etc. More precisely, for u, v ∈ N H we say that u is an ancestor of v, or that v is a descendant of u, which we denote by v ≤ H u, if there is a directed path in H from u to v, i.e., if v ∈ N H/u ; in order to exclude the equality 10 u = v, we say that u is a proper ancestor of v, or that v is a proper descendant of u, and we write v < H u. We also say that v is below u and that u is above v if v ≤ H u; to exclude equality, we say that v is strictly below u or that u is strictly above v. A topological order on H is a linear order ≤ on its set of nodes that contains ≥ H (i.e., v ≤ H u implies u ≤ v).

A computation on H is a bottom-up computation if it processes sequentially the nodes of H, in such a way that the computations done at node u can use results of computations done at some nodes v below u. Hence, it can be done in any order on the nodes such that v is processed before u if v < H u, that is, in the reverse order of any topological order.

A spanning tree of an undirected graph G is a spanning subgraph of G that is a tree. If F ⊆ E G and G[F ] is a spanning tree of G, then we say that F forms the spanning tree G[F ]. A spanning tree of a directed graph G is, by definition, one of und (G). A rooted spanning tree is a rooted tree T such that und (T ) is a spanning tree. The direction of an edge of a rooted spanning tree need not coincide with its direction in G when G is directed. A rooted spanning tree T is normal if every two vertices that are adjacent in G are comparable with respect to ≤ T . Every nonempty connected graph has a normal spanning tree that can be constructed by a depth-first traversal starting from any given vertex 11 .

Definition 2.14 (Syntactic trees of terms) Let t ∈ T (F ). Its syntactic tree is the concrete labelled rooted tree T denoted by Syn(t) such that N T = Pos(t) and:

(i) root T is 1, the first position of t, (ii) a node u of T is labelled by f ∈ F if and only if u ∈ Occ(t, f ), i.e., if and only if t[u] = f (u is a positive integer and the symbol at occurrence u in t is the u-th element of t, since we use Polish prefix notation for terms);

(iii) there is in T an edge u → v labelled by i in N + if and only if t = αf t 1 • • • t ρ(f ) β for some α, β ∈ F * and f ∈ F such that |α| = u -1 (so that u ∈ Occ(t, f )), t 1 , . . . , t ρ(f ) ∈ T (F ) and v = |αf t 1 • • • t i-1 | + 1; hence the outdegree of u is ρ(f ). (We have t/u = f t 1 • • • t ρ(f ) and t/v = t i .)
10 For every partial order ≤ we denote by < the corresponding strict partial order, i.e., x < y if and only if x ≤ y and x = y. This convention applies to all partial orders defined here or below: ≤ H , ≤t etc.

11 Every countable connected graph has a normal spanning tree that is not necessarily obtained by depth-first search (Theorem 8.2.4 of [*Die]). Hence Syn(t) is an (F , [ρ(F )])-labelled graph for every finite subsignature F of F such that t ∈ T (F ). Figure 2.1 shows the tree Syn(t) for the term t = f (g(a, b), h(g(x 1 , a)), g(x 1 , x 2 )) that belongs to T ({f, g, h, a, b}, {x 1 , x 2 }). The set of nodes of Syn(t) is [11]. The symbol t[i] at position i in t is indicated between parentheses.

For each u ∈ Pos(t), the tree Syn(t)/u is an induced subgraph of Syn(t) and is isomorphic to Syn(t/u). (Its set of vertices is the set of descendants of u in Syn(t).) The corresponding bijection

h u : N Syn(t/u) → N Syn(t)/u ⊆ N Syn(t) is defined by h u (i) = i + u -1. If for example t = g(f (a, b), f (a, b)) then we have t/2 = t/5 = f (a, b). The two mappings h 2 and h 5 such that h 2 (1) = 2, h 2 (2) = 3, h 2 (3) = 4, h 5 (1) = 5, h 5 (2) = 6, h 5 (3) = 7 are isomorphisms from Syn(f (a, b))
to the two subtrees Syn(t)/2 and Syn(t)/5 of Syn(t). More generally, two subterms t/u and t/v of a term t are equal if and only if Syn(t)/u Syn(t)/v.

Similarly, if u ∈ Pos(t), then the syntactic tree of the context t ↑ u is isomorphic (up to the label of u) to the subgraph of Syn(t) that is induced by the set of vertices consisting of u and those that are not descendants of u. We denote by Syn(t) ↑ u the labelled graph obtained from this subgraph by changing the label of u into the special variable w (or another special variable if this is more convenient). Then

Syn(t ↑ u) is isomorphic to Syn(t) ↑ u: a position i of t ↑ u corresponds to i in Pos(t) if 1 ≤ i ≤ u, and to i + |t/u| -1 if u < i ≤ |t|.
We will use for positions in terms the terminology relative to trees: leaf, son, ancestor, root. In particular, if u is an occurrence in t of f ∈ F k , then it has a sequence of k sons, (u 1 , . . . , u k ), (u i will be called the i-th son of u) and we have t/u = f (t/u 1 , . . . , t/u k ).

The syntactic tree T = Syn(t) of t ∈ T (F ) can be specified by the tuple N T , (son iT ) 1≤i≤r , lab T where r is the maximal arity of a symbol that has an occurrence in t, son iT (u, v) holds if and only if v is the i-th son of u, and lab T (u) = t[u]. If F is finite, this tuple can be replaced by a relational structure over a binary relational signature (see Chapter 5). We will usually denote N T by N t instead of by N Syn(t) , ≤ T by ≤ t , son iT by son it , etc., when T is the syntactic tree of t. Moreover, for a node u ∈ N t , we will denote the set of nodes of Syn(t)/u by N t /u, to distinguish it from N t/u which is the set of nodes of Syn(t/u); similarly, N t ↑ u will denote the set of nodes of Syn(t) ↑ u.

The term t can be recovered from any labelled rooted tree that is isomorphic to the syntactic tree Syn(t). We will call such a tree a syntactic tree of t, as opposed to its syntactic tree. Thus, the mapping t → [Syn(t)] iso is injective, which shows that terms can be represented by abstract labelled rooted trees. A labelled rooted tree T is a syntactic tree of some term over F if and only if: every node u of T has exactly one label f from F , its outdegree is ρ(f ) and its outgoing edges are numbered by 1, . . . , ρ(f ), such that each number in [ρ(f )] labels a single edge.

For a finite signature F , a mapping t → val (t) from T (F ) to some finite set M is computable inductively on the structure of

t if val (f (t 1 , . . . , t k )) = v f (val (t 1 ), . . . , val (t k )) for all f ∈ F and t 1 , . . . , t k ∈ T (F )
where k = ρ(f ) and v f is a fixed mapping : M k → M . Equivalently, the mapping val is equal to val M for some F -algebra M with domain M (and v f = f M ). Such a mapping val can be computed bottom-up on the syntactic tree of t, and in linear time (in the size of t) if the mappings v f are computable in constant time (that is in time depending only on "fixed" parameters).

A parsing algorithm for a finite signature F takes as input a word in F * and either outputs the answer that this word is not a term in T (F ) or constructs its syntactic tree if it is (with the appropriately linked data structure that makes it easy to traverse this tree later on). Text books on compilation (e.g., [*AhoLSU] and [*Cre]) present such algorithms. Let us only note that the natural order on positions of a term t (defined as integers) is a topological order of its syntactic tree. By reading the word t from right to left and by using a pushdown to store the necessary information, one can evaluate t in a given algebra, compute the unique run on it of a deterministic automaton (see Section 3.3), build its syntactic tree or, more generally, perform a bottom-up computation 12 . Such a computation takes linear time on t given as a word if it takes linear time on the syntactic tree of t. Definition 2.15 (Quotient graphs and minors) Let G be a concrete graph, directed or not. Let ≈ be an equivalence relation on V G . The quotient graph of G by ≈ is obtained, informally, by fusing any two equivalent vertices into a single one. We do not fuse or delete edges. However, we wish to define this graph as a concrete graph by specifying its vertices. We denote by [u] the equivalence class of u ∈ V G . A cross-section of ≈ is a set X ⊆ V G that has one and only one element u in each equivalence class [u].

For every cross-section X of ≈, we define the concrete quotient graph (G/≈) X as the graph H such that:

V H := X, E H := E G , vert H (e) := (u, v) or {u, v} or {u} if vert G (e) is (u, v) or {u, v} or {u} respectively.
If the edges of G are labelled, then their labels are transferred to those of H in the obvious way. If G is a (K, Λ)-labelled graph, then a vertex of H inherits all labels of the vertices of G that are equivalent to it. For any two cross-sections X and Y , the graphs (G/≈) X and (G/≈) Y are isomorphic in a canonical way (u in X is mapped to u in Y such that u ≈ u , and the correspondence between the edge sets E (G/≈) X and E (G/≈) Y is the identity). Hence, we will write G/≈ instead of (G/≈) X if X need not be specified and we will consider it as the quotient graph of G by ≈. (This definition will facilitate the description of the quotient construction as a monadic second-order transduction to be done in Section 7. 1.1,cf. Example 1.35 in Section 1.7.1).

If G and G are isomorphic by an isomorphism h that maps an equivalence relation ≈ on V G to an equivalence relation ≈ on V G (i.e., h(u) ≈ h(v) if and only if u ≈ v), then (G/ ≈) X and (G / ≈ ) Y are isomorphic for any two cross-sections X and Y of ≈ and ≈ . Hence in such a case the quotient by an equivalence relation is well defined on abstract graphs.

Edge contraction is a particular type of quotient. Let G be a concrete graph and F ⊆ E G . We let ≈ F be the equivalence relation generated by the set of pairs vert G (e) for e in F . A cross-section of ≈ F is thus a set of vertices X that has one and only one element in each connected component of the subgraph of G with vertex set V G and F as set of edges. For a cross-section X of ≈ F , we define (G/F ) X as the graph ((G -F )/≈ F ) X = (G/≈ F ) X -F . Again (G/F ) X and (G/F ) Y are canonically isomorphic if X and Y are any two cross-sections. We will use the simplified notation G/F if we need not specify any cross-section. We let G/e := G/{e} if e is an edge. Contracting a loop is the same thing as deleting it.

A concrete graph H is a minor of a concrete graph

G if H = (G /F ) X for some concrete subgraph G of G, some set F ⊆ E G and some cross-section X of ≈ F relative to G . Note that V H = X ⊆ V G ⊆ V G and E H = E G -F ⊆ E G ⊆ E G ,
but the incidences are not the same in H and in G. We denote this relation by H ¢ G. Here is some further notation:

H ¢ c G means H = (G/F ) X (hence G = G in the initial definition). We say that H is a proper minor of G if F = ∅ or G = G or both conditions hold.
Proposition 2.16 Let H be a minor of a concrete graph G. The following are equivalent:

(1) H = G, (2) V H = V G and E H = E G , (3) |V H | = |V G | and |E H | = |E G |.
Then H is a proper minor of G if and only if H ¡ G, i.e., H ¢ G and H = G.

Proof: Let H ¢ G. By the definition we have V H ⊆ V G and E H ⊆ E G .
(1) =⇒ ( 3) is clear, and (3) =⇒ ( 2) is immediate from the two above inclusions, since graphs are finite. We now prove (2) =⇒ [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF].

Let H = (G /F ) X with V H = V G and E H = E G . As observed above, V H = X ⊆ V G ⊆ V G and E H = E G -F ⊆ E G ⊆ E G . Hence V G = V G , F = ∅, and E G = E G . Since G ⊆ G, we have G = G and F = ∅. Hence, by definition, H = (G /F ) X = G.
Proposition 2.17

(1) The relation ¢ is a partial order on concrete graphs.

(2) A concrete graph H is a proper minor of a concrete graph G if and only if H is obtained from G by a nonempty sequence of edge deletions K → K -e, vertex deletions K → K -u and edge contractions K → K/e (where K is a concrete graph, e ∈ E K and u ∈ V K ).

Proof: 1) of Proposition 2.16.

(1) It is clear that G ¢ G. Let us assume H ¢ G ¢ H. We have V H ⊆ V G ⊆ V H and E H ⊆ E G ⊆ E H hence H = G by (2) =⇒ (
Next we consider transitivity. We let K ¢ H ¢ G. By the definitions we have

K ¢ c H ⊆ H ¢ c G ⊆ G. We first prove that if K ¢ c H ¢ c G then K ¢ c G. We let K = (H/L) Y and H = (G/F ) X with Y ⊆ X. We have K = (G/(L ∪ F )) Y , which gives K ¢ c G.
To complete the proof we verify that, if

H ⊆ H ¢ c G with H = (G /F ) X then H ¢ c G ⊆ G and H = (G /F ) Y ,
F = F ∩ E G and Y = X ∩ V G . The verification that H = (G /F ) Y is easy.
Then going back to the proof of transitivity, we have

K ¢ c H ⊆ H ¢ c G ⊆ G, hence K ¢ c H ¢ c G ⊆ G ⊆ G, hence K ¢ c G ⊆ G
and K ¢ G as was to be proved.

(2) "If" is clear from (1) because an edge deletion, a vertex deletion (we delete a vertex and all incident edges) and an edge contraction transform a graph G into a minor H of it, such that

|V H | + |E H | < |V G | + |E G |, whence H ¡ G.
"Only if": A subgraph of G can be obtained from it by edge and vertex deletions. If H = (G/F ) X and F = {f 1 , . . . , f n } then H can be obtained from G by the successive contractions of f 1 , . . . , f n . We omit the details.

On abstract graphs the minor relation ¢ can be defined by:

H ¢ G if
= [H ] iso = [H ] iso , G = [G ] iso = [G ] iso and G , G , H , H are concrete. By the definitions we have |V H | ≤ |V G | = |V G | ≤ |V H | = |V H | hence |V H | = |V G | and similarly for sets of edges. It follows from (3) =⇒ (1) of Proposition 2.16 that H = G . Hence H = G.
Transitivity follows in a similar way from Proposition 2.17(1) and the fact that if concrete graphs satisfy G ¢ H H , then there is a concrete graph G such that G G ¢ H .

Remark 2.19

The definitions of edge contraction and minor inclusion apply to infinite graphs. Proposition 2.16 is no longer valid because Assertion (3) does not imply Assertion (2) if G is infinite. However Proposition 2.17 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF], the proof of which uses no cardinality argument, is valid for infinite graphs. Proposition 2.18 is not valid: the minor relation on infinite abstract graphs is only a quasi-order because we may have H ¢ G ¢ H and G = H. As an example13 take H = K ω , the complete undirected graph with countably many vertices, and G the union of two disjoint copies of K ω . However, even on finite concrete graphs, the minor relation is usually referred to as a quasi-order. The reason is that it is usually defined on concrete graphs G, H as follows:

H is a minor of G if and only if H is isomorphic to a concrete graph H such that H ¢ G.
This definition is a mixture of concepts relative to concrete and abstract graphs.

A cleaner situation occurs if we separate definitions relative to abstract graphs from those relative to concrete graphs.

We now review basic definitions and facts concerning graph classes defined by excluded (or forbidden) minors.

Definition 2.20 (Well-ordered sets) Let D, ≤ be a partially ordered set. We say that ≤ is Noetherian if there is no strictly decreasing infinite sequence, i.e., no sequence (d i ) i∈N such that d i ∈ D and

d 0 > d 1 > • • • > d i > • • • .
We say that D is well-ordered by ≤ if this partial order is Noetherian and has no infinite antichain, i.e., no infinite subset of pairwise incomparable elements.

Let ≤ be an arbitrary partial order on a set D. For every A ⊆ D, we define14 :

Forb(A) := {d ∈ D | a ≤ d for no a in A}, Obst(A) := {d ∈ D | d / ∈ A and for all d ∈ D if d < d then d ∈ A}. Hence, Obst(A) is the set of ≤-minimal elements of D -A. A subset A of D is ≤-closed, or is an ≤-ideal, if d ≤ d and d ∈ A imply d ∈ A.
Proposition 2.21 Let D, ≤ be a partially ordered set.

(1) If D has no infinite antichain, then Obst(A) is finite for every A ⊆ D.

(2) If D is Noetherian and A is an ≤-ideal, then A = Forb(Obst(A)).

(3) If D is well-ordered by ≤, then every ≤-ideal A is Forb(B) for some finite set B, and in particular for B = Obst(A). ∈ Forb(Obst(A)). This proves that Forb(Obst(A)) ⊆ A. In this proof we have not used the hypothesis that A is ≤-closed. We will use it for proving the opposite inclusion.

We now assume that some d belongs to A ∩ (D -Forb(Obst(A))). Then d ≤ d for some d ∈ Obst(A). But d / ∈ A, and this contradicts the hypothesis that A is ≤-closed. Hence A ⊆ Forb(Obst(A)) which completes the proof.

(3) Immediate consequence of ( 1) and (2).

These definitions and results can be applied to graphs as follows. We let D be the set of abstract simple and loop-free undirected graphs, partially ordered by minor inclusion. This order is Noetherian because

H ¡ G implies |V H | + |E H | < |V G | + |E G |
by Proposition 2.16. The Graph Minor Theorem proved by Robertson and Seymour establishes that D is well-ordered by ¢. (See the book [*DowFel], Section 7.6, for an overview of the proof and references.)

It follows that if a class C of simple, loop-free, undirected graphs is a ¢-ideal, i.e., is closed under taking minors, then there exists a finite subset K of D such that C is the class of graphs in D that have no minor isomorphic to a graph in K. This applies to the class C of planar graphs and the corresponding set K is {K 5 , K 3,3 } (see [*Die] Section 4.4 or [*MohaTho] Section 2.3). The Graph Minor Theorem also holds for directed graphs [START_REF] Robertson | Graph minors XX. Wagner's Conjecture[END_REF] but this instance is seldom used.

Definition 2.22 (Union and intersection of graphs)

Two concrete graphs H and K are compatible if the mappings vert H and vert K agree, i.e., vert H (e) = vert K (e) for every e ∈ E H ∩ E K . This implies in particular that the ends of an edge in

E H ∩ E K are in V H ∩ V K .
If H and K are compatible, we can define their union M := H ∪ K as the graph such that

V M := V H ∪ V K , E M := E H ∪ E K and vert M := vert H ∪ vert K .
Clearly, H and K are subgraphs of M . We can also define their intersection as the graph

N := H ∩ K such that V N := V H ∩ V K , E N := E H ∩ E K and vert N := vert H E N = vert K E N . Clearly H ∩ K is a subgraph of both H and K. If H ⊆ G and K ⊆ G, then H and K are compatible and we have H ∩ K ⊆ H ⊆ H ∪ K ⊆ G.
Two concrete graphs G and

H are disjoint if V G ∩ V H = ∅ and E G ∩ E H = ∅.
This implies that they are compatible, that G ∩ H = ∅ (the empty graph) and that G ∪ H is defined.

It is clear that the union and the intersection of two concrete graphs are not always defined. In the next section we will define the disjoint union, a binary operation that is well defined for any two abstract graphs.

The HR algebra of graphs with sources

In this section we define operations on abstract graphs that generalize the parallel-composition and the series-composition used in Section 1.1.3 to define series-parallel graphs. Sources are distinguished vertices that allow to glue graphs in uniquely defined ways. Thus graphs are built from smaller graphs like words are built by concatenating shorter words. But graphs are intrinsically more complex than words, and so we cannot build them by means of a single concatenation operation. We need countably many operations. However, finite sets of these operations generate significant graph classes. In particular, there is for each k a finite subset of these operations that generates the graphs of tree-width at most k.

The acronym HR stands for Hyperedge Replacement and will be justified in Chapter 4.

The HR graph operations

We make the definitions of Section 1.4.2 more precise by paying attention to the distinction between abstract and concrete graphs.

Definition 2.23 (Disjoint union of abstract graphs)

Let G, H, K be concrete graphs. We write G = H ⊕ K if H and K are disjoint and G = H ∪ K. For abstract graphs G, H and K we write

G = H ⊕ K if G H ⊕ K
where H H, K K and the graphs H and K are disjoint concrete graphs 15 . There is not a single such pair of concrete graphs (H , K ). However G is uniquely defined as an abstract graph because any two pairs (H , K ) and (H , K ) satisfying these conditions yield isomorphic graphs H ⊕ K and H ⊕ K . The following facts are clear from the definitions: for every concrete graph G, we have G = G ∪ G but G ⊕ G is undefined unless G is empty; for every finite 16 nonempty abstract graph G the graph G ⊕ G is defined and different from G.

Disjoint union is not powerful enough to generate interesting classes of graphs from finitely many basic abstract graphs. In order to "glue" graphs, we introduce distinguished vertices that we call sources.

Definition 2.24 (Graphs with sources)

Let A be a fixed countable set, the elements of which will be used as names (or labels) of distinguished vertices. We assume that N ⊆ A and that A is ordered linearly by an ordering that extends the usual order on N . 17 A concrete graph with sources, or a concrete s-graph in short, is a pair If slab G (u) = a, then we say that u is the a-source of G and that a is the name (or label ) of source u. We will also use the bijection src G : τ (G) → Src(G) defined as the inverse of slab G . A graph is an s-graph of empty type. The set of vertices that are not sources, called the internal vertices, is denoted by Int G .

G = G • , slab G consisting of a concrete graph G • and a partial injective function slab G : V G • → A. We will simplify the notation V G • into V G ,
For example, a series-parallel graph as defined in Section 1.1.3 is an s-graph with two sources, a 1-source and a 2-source. A rooted tree (Definition 2.13) can be defined as a tree with one source, the vertex selected as root.

Isomorphisms of concrete s-graphs are defined in the obvious way, and still denoted by . (We mean by this that if G H, the bijection h V : V G → V H maps Src(G) onto Src(H) and that slab H (h V (u)) = slab G (u) for every u in Src(G)). Hence the above terminology and notation concerning sources apply to abstract s-graphs. The type of an abstract s-graph is well defined.

We denote by J S u and J S d the classes of undirected and directed abstract s-graphs 18 .

Definition 2.25 (Parallel-composition)

Let G, H be concrete s-graphs. We say that H is a subgraph of G, written

H ⊆ G, if H • ⊆ G • and slab H = slab G V H (so that τ (H) ⊆ τ (G)).
Let G, H, K be concrete s-graphs. We write G = H K, and we say that G is the parallel-composition of H and K, if and only if: 16 We have G = G ⊕ G if G is the abstract graph isomorphic to the union of countably many disjoint copies of a concrete graph H.

17 Additionally, we assume that A is effectively given (see Definition 2.8) and that the linear order < on A is decidable. The latter means that the mapping f : A × A → {True, False} such that f (a, b) = True if a < b and False otherwise, is computable.

18 As explained in Section 1.4, the letter J in notations like J S and JS is intended to remind the reader that the graphs of the corresponding algebras may have multiple edges. By contrast, the letter G in GP and GP refers to algebras of simple graphs.

(1) H ⊆ G, K ⊆ G, G • = H • ∪ K • , (2) V H ∩ V K = Src(H) ∩ Src(K), (3) E H ∩ E K = ∅, (4) slab G = slab H ∪ slab K .
These conditions imply that slab H and slab K agree and that slab

H (v) = slab K (w) if v ∈ Src(H) -V K and w ∈ Src(K) -V H .
From the definitions, we get the following: Proposition 2.26 For concrete s-graphs G, H, K, we have G = H K if and only if the following conditions hold:

(1) V G = V H ∪ V K , (2) V H ∩V K = Src(H)∩Src(K), and if u ∈ V H ∩V K then src G (a) = src H (a) = src K (a) = u for some a ∈ A,
(3) u ∈ Src(G) if and only if u ∈ Src(H) ∪ Src(K), and its name (as a source) is the same with respect to G and to H and/or to K.

(

) E G = E H ∪ E K , E H ∩ E K = ∅, (5) vert G (e) = vert H (e) if e ∈ E H , vert K (e) if e ∈ E K . We have τ (H K) = τ (H) ∪ τ (K); if τ (H) ∩ τ (K) = ∅, then (H K) • = H • ⊕ K • . 4
Parallel-composition is not defined for all pairs of concrete s-graphs. We will turn it into a total binary function on abstract s-graphs, more or less as we did for disjoint union in Definition 2.23. Definition 2.27 (Parallel-composition of abstract s-graphs) Let H and K be abstract s-graphs. The abstract s-graph H K, called the parallel-composition of H and K, is the isomorphism class of H K for any two concrete s-graphs H and K such that H H , K K and H K is defined. For any two pairs (H , K ) satisfying these conditions, the resulting s-graphs H K are isomorphic. Hence H K is well defined for any two s-graphs H and K. Informally we will say that H and K are "glued at their sources with the same name". See Figure 2.2 for an illustration. (In this figure and in Figure 2.3, the graphs H, K and G have three sources; their possible internal vertices and incident edges are not shown.)

It is clear that for all s-graphs G, H and K, we have τ

(G H) = τ (G)∪τ (H) and (G H) K = G (H K).
Since parallel-composition is associative, we will use infix notation without parentheses for it. Note also that, for G finite, G = G G if and only if E G = ∅ and all vertices are sources.

Definition 2.28 (Quotient s-graphs) The notion of a quotient graph has been defined for graphs in Definition 2.15. For a concrete s-graph G and an equivalence relation ≈ on V G such that no two distinct sources are equivalent, we define its (concrete) quotient s-graph G/≈ of the same type as G, as follows. For every cross-section X of ≈ we let (G/≈) X be the concrete s-graph H such that H

• := (G • /≈) X and, for every a ∈ τ (G), src H (a) = u if u ∈ X and u ≈ src G (a)
. Any two cross-sections yield isomorphic quotients. We denote (G/≈) X by G/≈ when X need not be specified.

The following proposition is an immediate consequence of the definitions. It describes the "gluing of sources" by a quotient.

Proposition 2.29 If H and K are disjoint concrete s-graphs, then the abstract s Definition 2.30 (Source manipulating operations) Let h : A → A be a partial injective function that is the identity outside of a finite subset

-graph [H] iso [K] iso is equal to [L/≈] iso where L is the concrete s-graph such that L • = H • ∪ K • , src L (a) = src H (a) if a ∈ τ (H), src L (a) = src K (a) if a ∈ τ (K) -τ (H),
C of A (hence Dom(h) ⊇ A -C and h(C) ⊆ C). 19 For example, h(d) = d for d / ∈ {a, b, c}, h(c) is undefined, h(a) = b and h(b) = a (or h(b) = c). For every concrete s-graph G, we let app h (G) be the s-graph H such that H • := G • and slab H := h • slab G . It follows that Src(app h (G)) ⊆ Src(G), τ (app h (G)) = h(τ (G)) and |τ (app h (G))| ≤ |τ (G)|.
The mapping app h commutes with isomorphisms hence applies to (abstract) s-graphs. It will be convenient actually to distinguish two main cases.

The first case is when h(a) is either undefined or equal to a, for every a ∈ A. Hence B := A -Dom(h) is finite and we will denote app h by fg B . The effect of In the general case, we have that app h (G) = ren h (fg B (G)) where B is the set A -Dom(h) and h is any bijection : A → A that extends h (the existence of which follows from Lemma 2.37 below). Thus, app h is a derived operation.

Each operation fg B is defined in a finitary way since B is required to be a finite set. Each operation ren h can also be specified in a finitary way because D = {a ∈ A | h(a) = a} is a finite set. Hence it can be written ren {b1→c1,b2→c2,...,bn→cn} where D = {b 1 , . . . , b n } = {c 1 , . . . , c n } and c i = h(b i ) for all i = 1, . . . , n. We will also abbreviate ren {a→b,b→a} into ren a↔b , and for n = 0, ren {} is the identity. Since A is countable, the set of operations of the forms fg B and ren h is countable.

Definition 2.31 (Basic s-graphs)

We now specify some basic (abstract) s-graphs that will be the values of the constant symbols a and a for a ∈ A. These symbols denote s-graphs consisting of a vertex that is the a-source, and, in the latter case, that has also a loop.

(We need not distinguish directed and undirected loops.) If a, b ∈ A, a = b, the constant symbol ab denotes an s-graph consisting of two vertices, an a-source and a b-source, linked by a single undirected edge, and -→ ab denotes the similar sgraph with an edge directed from the a-source to the b-source. We can consider ab and ba as the same symbol. Assuming fixed a linear order < on A, we will only use ab with a < b. It will be useful for some constructions to have also a constant symbol ∅ denoting the empty graph. Every term evaluating to a nonempty graph can be transformed into an equivalent one without ∅, by means of properties of the operations , ren h and fg B that will be stated in Proposition 2.48.

Definition 2.32 (The HR algebra of s-graphs)

We have defined a binary operation that "glues" s-graphs, and unary operations fg B and ren h that transform them by modifying their source names. We have also defined constant symbols that define basic s-graphs, directed or not, having at most one edge. We obtain thus two algebras, one with domain J S u , the set of (abstract) undirected s-graphs, and the other one with domain J S d , the similar set of directed s-graphs. We let:20

F HR + := { , fg B , ren h | B ∈ P f (A), h ∈ Perm f (A)}, F HRu 0 := {a, a , ab, ∅ | a, b ∈ A, a < b}, F HRd 0 := {a, a , -→ ab, ∅ | a, b ∈ A, a = b}, F HRu := F HR + ∪ F HRu 0 , F HRd := F HR + ∪ F HRd 0 .
These signatures are countably infinite. We let JS u denote the F HRu -algebra with domain J S u and JS d denote the F HRd -algebra with domain J S d . In order to simplify notation, we will not distinguish the operations of these algebras from the corresponding symbols in their signatures. We call JS u and JS d the (undirected or directed) HR algebra. Every term t in T (F HRu ) has a value in J S u denoted by t JS u or by val JS u (t) according to the notation of Definition 2.2. If t is in T (F HRd ), then its value t JS d (or val JS d (t)) belongs to J S d . In both cases and for other graph algebras, we will use the generic notation val (t), the relevant algebra being understood from the context. We will say that the term t evaluates to the s-graph val (t) or that t denotes or defines val (t). Two terms t and t are equivalent if val (t) = val (t ).

We now extend these definitions to (K, Λ)-labelled graphs (cf. Definition 2.11) equipped with sources, called (K, Λ)-labelled s-graphs (or labelled s-graphs if we need not specify K and Λ). We always assume that (K ∪ Λ) ∩ A = ∅. Each vertex has a possibly empty set of labels that belong to K and each edge has a unique label in Λ. If G and H both have an a-source, then we take as set of labels of the a-source of G H the set γ G (src G (a)) ∪ γ H (src H (a)), i.e., we take the labels from G and those from H. The operations that manipulate source names are the same.

We will use the constant symbols -→ ab λ , ab λ and a λ to denote an edge labelled by λ ∈ Λ that is, respectively, directed from the a-source to the b-source, undirected between the a-source and the b-source, and a loop incident with the a-source. For specifying vertex labels, we will use the constant symbol a κ to denote the s-graph with a single vertex that is the a-source and is labelled by κ ∈ K. We denote by F HRu Let us stress that we have defined algebras of abstract s-graphs. We have no algebraic structure on concrete s-graphs because the parallel-composition of two concrete s-graphs is not always defined. The terms "graph" and "sgraph" will mean "abstract graph" and "abstract s-graph" respectively. In many statements, we will refer to JS, J S, F HR without specifying the variant, relative to directed or undirected s-graphs. Any such statement will cover two statements, one for directed s-graphs and one for undirected s-graphs. For example, the statement "every term t ∈ T (F HR ) evaluates to an s-graph val (t) in J S" means that if t belongs to T (F HRu ), then val (t) ∈ J S u and also that if t belongs to T (F HRd ), then val (t) ∈ J S d . The same convention applies to the algebras of labelled graphs.

Every term in T (F HR ) is written with finitely many source names. We make this precise as follows. For C ⊆ A, we let:

F HR C+ := { , fg B , ren h | B ∈ P f (C), h ∈ Perm f (C)}, F HRu C0 := {a, a , ab, ∅ | a, b ∈ C, a < b}, F HRd C0 := {a, a , -→ ab, ∅ | a, b ∈ C, a = b}, F HRu C := F HR C+ ∪ F HRu C0 , F HRd C := F HR C+ ∪ F HRd C0 .
The notation F HR The signature F HR is effectively given (Definition 2.8). In fact, we can assume that the countable set A is effectively given with a fixed bijection ξ A onto N (one could take A = N , but more flexibility will be convenient in some proofs). Each function symbol of F HR can be formally written as a sequence in Seq(N ∪ P ) where P is a finite auxiliary set of symbols. For example the renaming operation ren {a→b,b→c,c→a} with a, b, c ∈ A can be written: (ren, a, b, b, c, c, a) where ren ∈ P and a, b, c are integers that encode respectively a, b and c (i.e., a = ξ A (a) and similarly for b and c). These sequences form an infinite decidable subset of Seq(N ∪ P ) and can be encoded as integers by the standard encoding of that set, with a computable arity mapping.

The algebra JS is also effectively given. Although that should be intuitively clear, let us look at some details. Without loss of generality, we can describe an s-graph by a concrete s-graph G with vertex set [n] and edge set [n + 1, p] for some p ≥ n (we have p = n and [n + 1, p] = ∅ if G has no edges). The mappings vert G and slab G can be written as sequences of triples and of pairs of integers. For example, the directed s-graph G = a• → • ← • → •b can be written as the sequence (4, 0, 5, 1, 2, 0, 6, 3, 2, 0, 7, 3, 4, 0, 0, 1, ξ A (a), 0, 4, ξ A (b)) where the first occurrence of 4 indicates the number of vertices, the integers 5, 6, 7 represent edges and are followed by the associated pairs of vertices, and 0 separates the different objects of the sequence. Several such sequences can describe the same s-graph. As the description of an s-graph we can take the first sequence that describes it, with respect to some standard linear order on Seq(N ). Hence we obtain a bijection between s-graphs and a decidable subset 21 of Seq(N ), whence an encoding ξ J S of J S in N . The operations of JS are computable via this encoding (cf. Definition 2.8). The algebra JS is thus effectively given. It should, however, be stressed here that when discussing efficiency of algorithms we will not use this encoding to represent s-graphs, but rather the usual representation by a traditional data structure like an incidence matrix. 22 The notion of an effectively given algebra will only play a role when the efficiency of algorithms is not an issue.

These remarks extend clearly to labelled graphs.

Proposition 2.33 Let C ⊆ A and let G be an s-graph such that τ (G) ⊆ C and |V G | = |C|. Then G is the value of a term t over F HR C of size Θ(|V G | + |E G |). Furthermore, if G is (K, Λ)-labelled, then it is the value of a term over F HR C,[K,Λ]
. Proof: We first consider an undirected G. We extend the mapping src G : τ (G) → V G to a bijection : C → V G . Each vertex can be identified with an 21 An algorithm can check if a sequence in Seq(N ) actually describes some s-graph and another one can check if two sequences describe the same s-graph; hence an algorithm can check if a sequence is the description of an s-graph.

22 These representations are equivalent: an algorithm can find, for every concrete s-graph G given by an incidence matrix, the integer that encodes the s-graph [G] iso , and vice versa. However, the algorithms that translate one representation into the other, are not efficient. element of C. Now let B = C -τ (G). We let t be the term:

fg B (x 1 y 1 • • • x m y m z 1 • • • z p w 1 • • • w q ),
where the non-loop edges of G are e i : x i -y i (with x i < y i ; < is a fixed strict linear order on A) for i = 1, . . . , m, its isolated vertices are z 1 , . . . , z p , and the loops are e j : w j -w j for j = 1, . . . , q. Because we allow multiple edges and loops, we may have {x i , y i } = {x j , y j } or w i = w j for i = j; also, we may have 23 It is clear from this construction and the definitions that val (t) = G.

w i ∈ {x 1 , . . . , x m , y 1 , . . . , y m }. Note that t = fg C (∅) if G = ∅.
For directed s-graphs, we use constant symbols --→ x i y i instead of x i y i . The construction extends in an obvious way to labelled s-graphs; a vertex label κ can be attached to a vertex a by adding a κ to the parallel-composition in t. It is clear from these constructions that:

|t| = 2(|E G | + |Isol G |) ≤ 2(|E G | + |V G |),
where Isol G is the set of isolated vertices of G, whereas, for every term t evaluating to an s-graph G:

|E G | + |V G | ≤ 3|t|.
For a (K, Λ)-labelled graph, with K = ∅, we have:

|t| ≤ 2(|E G | + |K| • |V G |),
and the second inequality is also valid.

This proposition entails that the algebra JS is generated by its signature F HR . The construction used in its proof is equivalent to the specification of an s-graph as a list of vertices, edges and of sources with their names. It yields no interesting structuring of it similar to that of series-parallel graphs described in Chapter 1.

Example 2.34 Let G be the s-graph shown in Figure 2.4, and of type τ (G) = {1, 2, 3, 4}. The construction of Proposition 2.33 gives:

G = val ( -→ 12 -→ 21 -→ 23 4 3 3 ) and
und (G) = val (12 12 23 4 3 3 ).

For the algorithmic applications that we will detail in Chapter 6, it is useful to denote graphs by terms in T (F HR C ) such that C is of smallest possible cardinality. It is also necessary for finding for a given graph such a term for a set C of fixed size, as efficiently as possible (cf. Definition 2.46). Since there are close relationships between these terms and the well-developed theory of tree-decompositions, as we will see in Section 2.4, we will get answers to these algorithmic questions.

τ (t 1 t 2 ) = τ (t 1 ) ∪ τ (t 2 ), τ (f g B (t 1 )) = τ (t 1 ) -B, τ (ren h (t 1 )) = h(τ (t 1 )), τ (a) = τ (a ) = {a}, τ (ab) = τ ( -→ ab) = {a, b}, τ (∅) = ∅.
These rules can be used to determine the types of all positions in a term t, by using a bottom-up computation on the syntactic tree of this term. We can also compute in this way the set τ (t) defined as {τ (t/u) | u ∈ Pos(t)}. This is the set of all names of the sources of s-graphs defined by the subterms of t.

We have noted in Definition 2.32 that every term t in T (F HR ) belongs to T (F HR C ) for some finite set C ⊆ A. We let µ(t) denote the minimal such set, where minimality is relative to set inclusion. This set is well defined because

F HR C ∩ F HR D ⊆ F HR C∩D for all C, D ⊆ A.
It can be computed inductively by the following rules:

µ(t 1 t 2 ) = µ(t 1 ) ∪ µ(t 2 ), µ(fg B (t 1 )) = µ(t 1 ) ∪ B, µ(ren h (t 1 )) = µ(t 1 ) ∪ {a ∈ A | h(a) = a} µ(c) = τ (c) for every constant symbol c.
We call µ(t) the extended type of t and |µ(t)| the width of t denoted by wd (t). We will establish in Section 2.4.5 its relationship with tree-width. Both τ (t) and τ (t) are included in the extended type of t, as shown next.

Lemma 2.36 For every t ∈ T (F HR ), we have τ (t) ⊆ τ (t) ⊆ µ(t).

Proof: We prove that if C is a finite subset of A and t ∈ T (F HR C ), then τ (t) ⊆ C. Then also τ (t) ⊆ C, because t/u ∈ T (F HR C ) for every u. The proof is by induction on the structure of t and uses the above rules for τ .

(1

) If t is a constant symbol, then τ (t) ⊆ C by definition of F HR C . (2) If t = t 1 t 2 , then τ (t) = τ (t 1 ) ∪ τ (t 2 ) ⊆ C since, by induction, we have τ (t 1 ) ⊆ C and τ (t 2 ) ⊆ C.
(3) If t = fg B (t 1 ), then τ (t) = τ (t 1 ) -B ⊆ C by the induction hypothesis.

(4) If t = ren h (t 1 ), then τ (t) = h(τ (t 1 )). We have τ (t 1 ) ⊆ C by the induction hypothesis. By the definition of F HR C , h is a permutation of C and so

h(τ (t 1 )) ⊆ h(C) = C.
However the inclusion τ (t) ⊆ µ(t) may be strict: take for example t 1 = fg {a,b} (a). Then τ (t 1 ) = {a} ⊂ {a, b} = µ(t 1 ). As another example take t 2 = ren {a→b,b→c,c→a} (a). Then τ (t 2 ) = {a, b} ⊂ {a, b, c} = µ(t 2 ). The term t 1 can actually be replaced by the equivalent term t 1 = fg a (a) for which µ(t 1 ) = {a}. Similarly the term t 2 can be replaced by the equivalent term t 2 = ren a↔b (a) for which µ(t 2 ) = {a, b}. In order to generalize these observations, we say that a term t is reduced if for every subterm t of t we have the following: It is clear that the function f can be constructed in a canonical way from g and a fixed strict linear order < on A (where B and B are subsets of A): in the above proof, we take b

(a) if t = fg B (t ) then B ⊆ τ (t ), (b) if t = ren h (t ) then h is permutation of τ (t ) ∪ h(τ (t )).
i < b i+1 and b i < b i+1 for every i ∈ [n -1]. Proposition 2.38 Every term t in T (F HR C ) is equivalent to a reduced term t in T (F HR τ (t) ); we have µ(t) = τ (t) = τ (t). Proof: The proof is by induction on the structure of t. If t is a constant symbol, then t = t. If t = t 1 t 2 , then t = t 1 t 2 . If t = fg B (t 1 ), then t = fg B ( t 1 ) where B = B ∩ τ (t 1 ). If t = ren h (t 1 ), then t = ren h ( t 1 )
where h is a permutation of τ (t 1 ) ∪ h(τ (t 1 )) that coincides with h on τ (t 1 ). This permutation exists by Lemma 2.37. The following assertions can be proved by this induction:

val (t) = val (t), τ (t) = τ (t) and µ(t) = τ (t).
To prove the last equation, it suffices by Lemma 2.36 to show that µ(t) ⊆ τ (t), i.e., that t ∈ T (F HR τ (t) ). Hence t belongs to T (F HR τ (t) ) which completes the proof. C . We will prove in Section 2.4.5 (Theorem 2.83) that its s-graphs are those in J S[C] of tree-width at most |C| -1.

(2) For constructing a term t over F HR evaluating to a given s-graph G, we must use a set of labels µ(t) such that τ (G) ⊆ µ(t). But the source names in µ(t) -τ (G) can be chosen arbitrarily and changed like bound variables in logical formulas. In most cases, we are interested in defining graphs (without sources). If a graph G is defined by a term t in F HR C , and C is in bijection with C, then G = val(t ) for some t ∈ T (F HR C ). The term t is obtained from t by replacing, in each operation symbol, every source name (it belongs to C) by the corresponding element of C .

(3) We have not formulated Definition 2.35, Lemma 2.36 and Proposition 2.38 for labelled graphs because the extensions are obvious. In the sequel, we will leave implicit the extensions to labelled graphs when they are obvious.

Construction of the s-graph defined by a term

The mapping val : T (F HR ) → J S is defined by induction on the structure of terms in T (F HR ) in a straightforward manner because the constant symbols of F HR evaluate to fixed (abstract) s-graphs and its function symbols define the unary and binary operations of Definitions 2.27 and 2.30. However, this definition is not fully satisfactory for several reasons: it does not construct val (t) as a precise concrete s-graph, it does not relate the subterms of t to the corresponding subgraphs of val (t) and it gives no tool to verify that a given concrete s-graph G is isomorphic to val (t) where t is a given term. For the latter verification, we must construct val (t) as a concrete s-graph by applying Definitions 2.27, 2.30 and 2.31 and look for an isomorphism between G and this concrete s-graph.

The construction we will define remedies these drawbacks, yields a clear correspondence between terms and tree-decompositions (to be developed in Section 2.4.5) and is directly translatable into a monadic second-order transduction (see Chapter 7 and Section 1.7). We first explain the idea.

The edges of a concrete s-graph G defined by a term t in T (F HR ) are in bijection with the occurrences in t of constant symbols of the forms ab, -→ ab or a . We say that such an occurrence describes the corresponding edge. Hence, one part of the correspondence between G and t will be a bijection between E G and these occurrences. The description of vertices is more complicated. We first take an example. Let t be the term fg a (ab) bc. The vertex x is common to the edges described by ab and bc. It is described by the occurrences of these two symbols, and also by occurrences of others. Here is the definition: a vertex is described by u in Pos(t) if it is a source of the value of t/u. In the example above, the vertex x is described by all occurrences of the symbols of t. The a-source of val (ab) is described by the occurrence of ab only. The c-source of val (bc) is described by the occurrences of bc and of . 24 We will construct a concrete s-graph isomorphic to val (t) by defining its vertices as equivalence classes of pairs (u, a) such that u ∈ Pos(t) and a ∈ τ (val (t/u)), hence, as a quotient of an s-graph Exp(t) called the expansion of t. Furthermore, by selecting in each equivalence class a canonical representing element, we will get a canonical concrete s-graph cval (t). We now give the formal definitions.

Definition 2.40 (The expansion of a term and its quotients) Let t ∈ T (F HR ) be a term with syntactic tree specified as N t , son 1t , son 2t , lab t (cf. Definition 2.14) where N t is Pos(t), the set of positions of t. Each u ∈ N t has a type τ (u) := τ (val (t/u)) ⊆ µ(t) (we use here Lemma 2.36). The types of all nodes can be computed bottom-up on the syntactic tree of t (cf. Definition 2.35), in linear time (provided µ(t) ⊆ C with C fixed). We let Exp(t) denote the concrete s-graph called the expansion of t and defined as follows 25 :

V Exp(t) := {(u, a) | u ∈ N t , a ∈ τ (u)}, E Exp(t) := {u ∈ N t | lab t (u) = ab, -→ ab or a for some a, b ∈ A}, vert Exp(t) (u) :=          {(u, a), (u, b)} if lab t (u) = ab, (u, a), (u, b) if lab t (u) = -→ ab, {(u, a)}
if lab t (u) = a and t ∈ T (F HRu ), (u, a), (u, a) if lab t (u) = a and t ∈ T (F HRd ), src Exp(t) (a) := (root t , a) for every a ∈ τ (t) = τ (root t ).

We let R t be the binary relation on V Exp(t) defined as follows:

R t := { (u, a), (v i , a) | lab t (u) = , son it (u, v i ), i ∈ {1, 2}} ∪ { (u, a), (v, a) | lab t (u) = fg B , son 1t (u, v)} ∪ { (u, h(a)), (v, a) | lab t (u) = ren h , son 1t (u, v)}.
We let ≈ t be the equivalence relation generated by R t . The vertex set of val(t) will be defined as the quotient set of V Exp(t) by ≈ t . With these definitions we have the following proposition.

Proposition 2.41 For every term t ∈ T (F HR ), we have

val (t) = [Exp(t)/≈ t ] iso .
24 We could also decide that the a-source of val(ab) is described by the occurrence of fg a . This idea works well for terms defining graphs (without sources) because each vertex corresponds to a unique occurrence of an operation fg a . It will be used in Chapter 6. 25 Clearly, Exp(∅) is the empty graph.

Proof: Let t ∈ T (F HR ). For every u in N t , we define

V u := {(w, a) ∈ V Exp(t) | w ≤ t u}, E u := {w ∈ E Exp(t) | w ≤ t u} and R t,u := R t ∩ (V u × V u ).
We let also ≈ t,u be the equivalence relation on V u generated by R t,u . We let Exp(t) u be the s-graph H of type τ (u) such that H • is the subgraph of Exp(t) • with vertex set V u , edge set E u , and such that src H (a) = (u, a) for every a in τ (u).

Claim 2.41.1 For every u in N t , if (u, a) ≈ t,u (u, b), then a = b.
Proof: For fixed t, by bottom-up induction26 on u.

It follows that the quotient graph (Exp(t) u)/≈ t,u is well defined for every u in N t .

Claim 2.41.2 For every u in N t , we have

val (t/u) = [(Exp(t) u)/≈ t,u ] iso .
Proof: For fixed t, by bottom-up induction on u. In the case where u is an occurrence of we use Proposition 2.29 with H := (Exp(t) v 1 )/ ≈ t,v1 and

K := (Exp(t) v 2 )/≈ t,v2 , where son it (u, v i ) for i ∈ {1, 2}.
We now complete the proof of the proposition. If u = root t , then we have Exp(t) u = Exp(t) and ≈ t,u is ≈ t . Hence Claim 2.41.2 yields the result. This proposition will entail (in Section 7.4) that the mapping val , from terms to graphs, is a monadic second-order transduction.

In the above proposition, we have shown how to construct from a term t a concrete s-graph isomorphic to val (t). Actually, for each cross-section X of ≈ t we have a particular concrete s-graph, defined as (Exp(t)/≈ t ) X . However, we can define a canonical cross-section, whence, a canonical concrete s-graph isomorphic to val (t).

Lemma 2.42 Each equivalence class of ≈ t contains a unique pair (u, a) such that u is maximal for ≤ t . We will denote by max (u, a) the unique maximal pair equivalent to (u, a), that exists by the previous lemma, and by X max the set of all such maximal pairs. This set is a cross-section of ≈ t that we call the canonical cross-section and we let cval (t) be the concrete s-graph (Exp(t)/≈ t ) Xmax , called the canonical (concrete) s-graph denoted by t.

Proof: It follows from the definitions that if (u, a) ≈ t (u , b) then (u, a) ≈ t (w, c) ≈ t (u
We now characterize what it means for an arbitrary concrete s-graph G to be isomorphic to val (t).

Definition 2.43 (Witnesses)

Let G be a concrete s-graph and t be a term over

F HR . A witness of G val (t) is a mapping w : V G ∪ E G → (N t × µ(t)) ∪ N t satisfying the following conditions: (1) w defines a bijection from E G to the set {u ∈ N t | lab t (u) = ab,
-→ ab or a for some a, b ∈ A}; it is a subset of the set of leaves of the syntactic tree of t, i.e., of occurrences of constant symbols,

(2) w defines a bijection from V G to a cross-section X of ≈ t (this equivalence relation is defined in Definition 2.40),

(3) if e ∈ E G , lab t (w(e)) = -→ ab and vert G (e) = (x, y), then w(x) ≈ t (w(e), a) and w(y) ≈ t (w(e), b); if lab t (w(e)) = ab and vert G (e) = {x, y}, then this condition or the one with a and b exchanged holds, (4) if e ∈ E G , lab t (w(e)) = a and vert G (e) is either {x} or (x, x), then w(x) ≈ t (w(e), a),

(5) x is an a-source of G if and only if w(x) ≈ t (root t , a).

Proposition 2.44 Let G be a concrete s-graph and t a term over F HR . Then:

(1) w is a witness of G val (t) with cross-section X of ≈ t if and only if (w V G , w E G ) is an isomorphism from G to (Exp(t)/≈ t ) X , and

(2) G val (t) if and only if there exists a witness of G val (t).

Proof: Assertion (1) is easy to check from the definitions. Assertion (2) is then immediate from Proposition 2.41; in the "only-

if" direction, if (h V , h E ) is an isomorphism from G to (Exp(t)/≈ t ) X , then w := h V ∪ h E is a witness of G val (t).
As an illustration, consider the term t of the proof of Proposition 2.33, where

t = fg B ( • • • x 1 y 1 • • • x m y m z 1 • • • z p w 1 • • • w q )
is here written in Polish prefix notation (which was not the case in that proof for readability). We let G be the associated graph. A witness w of G val (t) can be defined as follows. Note that the first symbol fg B of t is followed by m+p+q-1 occurrences of . We let w(e i ) := m+p+q+i, w(z k ) := 2m+p+q+k, w(e j ) := 2m + 2p + q + j, and for every non-isolated vertex x, we let w(x) be equal to w(e i ) or w(e j ) for some edge e i or e j that is incident with x.

A canonical witness of G val (t) is one such that X = X max in Condition (2) of Definition 2.43. By Assertion (1) of Proposition 2.44 it corresponds to an isomorphism from G to cval (t). Thus, the canonical witnesses of cval (t) val (t) correspond to the automorphisms of cval (t). A ground witness of G val (t) is one such that u is a leaf of t for each pair (u, a) ∈ X. It is not hard to see that each equivalence class of ≈ t contains at least one such pair. Hence, one can also construct concrete s-graphs isomorphic to val (t) whose vertices are such pairs (u, a); the corresponding witnesses are ground witnesses. By selecting from an equivalence class of ≈ t the pair (u, a) such that u is the left-most leaf (according to the linear order of positions in t), we get a unique such concrete s-graph which we denote by gval (t); a corresponding ground witness is called a left-most ground witness. Thus, a left-most ground witness of G val (t) corresponds to an isomorphism from G to gval (t).

Let us say more generally that two witnesses w 1 and w 2 of G val (t) are equivalent if w 1 (e) = w 2 (e) for every e ∈ E G and w 1 (x) ≈ t w 2 (x) for every x ∈ V G . Then, every witness of G val (t) is equivalent to a unique canonical witness and to a unique left-most ground witness of G val (t).

Proposition 2.45 For each finite set C, the concrete s-graph cval (t) can be constructed from t ∈ T (F HR C ) in linear time, i.e., in time O(|t|). One can also construct within the same time the concrete s-graph gval (t) and a left-most ground witness of cval (t) val (t). These results extend to (K, Λ)-labelled s-graphs with the same computation times.

Proof: Let t ∈ T (F HR C ). We know that we can compute in linear time by a bottom-up computation the types of its nodes. Hence, we can also compute in linear time the sources of the s-graph Exp(t) and its sets of vertices and edges. It is clear that a pair (u, a) ∈ V Exp(t) belongs to X max if and only if either u is the root of t or its father is an occurrence of fg B such that a ∈ B. Hence X max , the vertex set of cval (t), can also be computed bottom-up in linear time. It remains to compute the mapping vert cval(t) . The set R t of Definition 2.40 is the set of edges of a rooted forest H, with set of roots X max . It has at most |C| • |t| edges and can also be constructed in linear time by a bottom-up computation on t. Then, by using depth-first traversals of its trees (there is one such tree for each element of X max ), one can compute the mapping max that associates with each node (u, a) of H the root max (u, a) of the tree to which it belongs. In particular, we obtain for every occurrence u (in t) of a constant symbol that defines an edge, say ab, its end vertices max (u, a) and max (u, b) in cval (t). These traversals can be done in linear time in the size of H, hence in time O(|C| • |t|). By similar depth-first traversals, one can associate with each element x of X max an equivalent pair left(x) := (u, a) such that u is a left-most leaf. Hence, one can also construct gval (t) and a left-most ground witness w of cval (t) val (t). In fact, w(x) = left(x) for every x ∈ V cval(t) and w(e) = e for every e ∈ E cval(t) .

The extension of these definitions and results to labelled graphs is easy: edge labels are specified in the constant symbols that specify edges. The different labels of a vertex are specified by different occurrences of constant symbols. However, the depth-first traversal that defines the mapping max can also compute the set of labels of each vertex: whenever one reaches a leaf (u, a) of H such that u is an occurrence of a κ in t, one adds κ to the current set of labels of max (u, a).

Definition 2.46 (Parsing)

The parsing problem relative to the HR algebra is defined as follows:

Input: A finite set C of source names and a concrete s-graph G of type included in C.

Output: A term t in T (F HR C ) and a witness of G val (t) if they exist, or the answer that they do not exist.

It follows from the proof of the previous proposition that an arbitrary witness can be converted in linear time into an equivalent canonical or left-most ground one. In fact, if w :

V G ∪ E G → V Exp(t) ∪ E Exp(t) is a witness of G val (t)
, then the mapping w such that w(x) = max (w(x)) if x ∈ V G and w(e) = w(e) if e ∈ E G is the unique canonical witness of G val (t) equivalent to w. The algorithm sketched in the proof of Proposition 2.45 can be adapted to compute w from w and t in linear time. Similarly, with left instead of max , w can be converted in linear time into the unique left-most ground witness w of G val (t) equivalent to w.

By the results of the next section, the parsing problem is equivalent to that of finding a tree-decomposition of G of width at most some given integer. We will review some algorithms that solve it in Section 6.2. Having parsed a graph G, it is often easy to parse a graph that is a modification of G obtained by, e.g., adding loops and multiple edges, adding labels, changing labels or changing the direction of edges, as shown by the following proposition. In particular, any algorithm solving the parsing problem can easily be extended into one solving the corresponding problem for labelled graphs.

We recall from Definition 2.9 that the core of a graph is obtained by removing edge directions and loops, and by fusing multiple edges. If G is a labelled sgraph, we let core(G) be the unlabelled, simple, loop-free, undirected s-graph core(G • ), slab G . Thus, sources and their names are not modified.

Proposition 2.47

(1) Let be given a concrete s-graph G, a term t in T (F HR C ) and a witness w of core(G) val (t). We can compute in linear time a term t in T (F HR C ) that evaluates to G, together with a witness of this fact. 27 (2) Let be given a concrete s-graph G, a term t in T (F HR C ) and a witness w of G val (t). Let γ be a labelling function turning G into a (K, Λ)labelled s-graph G. In linear time (for fixed C, K and Λ), we can compute t ∈ T (F HR C, [K,Λ] ) that evaluates to G, together with a witness of this fact.

(3) Let G, t and w be as in (2) with G possibly (K, Λ)-labelled. Let G be obtained from G by changing certain vertex and edge labels and by reversing certain edge directions (if G is directed). We can compute in linear time a term t in T (F HR C ) or T (F HR C, [K,Λ] ) that evaluates to G , such that w is a witness of this fact.

Proof: Let us assume that G is undirected; the proof for the directed case is similar.

(1) By the above observations, we first transform the given witness into a ground one that we still denote by w. Moreover, since ab = ab a, we may assume that for every vertex x of G, if w(x) = (u, a) then the leaf u is an occurrence of a in t. We construct t from t by the following simultaneous replacements. It is then easy to transform w into a ground witness of G val (t).

For every vertex x of G, we do the following: we have w(x) = (u, a) for some leaf u in t that is an occurrence of a constant symbol a. If x has loops e 1 , . . . , e m in G with m > 0, then we replace the occurrence at u by the term a • • • a , the parallel-composition of m constant symbols a .

For every edge e : x -y of core(G), we do the following: the witness w specifies a position w(e) in t that is an occurrence of some ab. If G has edges e 1 , . . . , e n in G with ends x and y, then we replace the occurrence at w(e) by the parallel-composition of n constant symbols ab. 28 (2) The proof is similar (using that also a = a a). For every vertex x of G, if {κ 1 , . . . , κ p } = γ(x) with p > 0, i.e., if κ 1 , . . . , κ p are the labels of x in G, then we replace the occurrence of a by the term a κ1 • • • a κp .

For every edge e of G, w(e) is an occurrence of ab or a . If λ = γ(e), i.e., if λ is the label of e in G, then we replace the constant symbol at w(e) by ab λ or a λ respectively.

(3) The proof is similar but we need not assume that w is ground. At certain positions specified by w, it suffices to replace constant symbols of the form a λ (or ab λ or -→ ab λ ) by a µ (or ab µ or -→ ab µ ), and to replace -→ ab λ by -→ ba λ (or -→ ab by -→ ba for unlabelled graphs). These transformations do not modify the source names that are used in t, hence they preserve the width of t.

Algebraic properties and derived operations defined by contexts

Three equational axioms characterize the monoid of words over any alphabet.

The situation for graphs is more complicated.

Proposition 2.48 For all s-graphs G, H, J, all unary operations fg B , fg B , ren h , ren h in F HR and all a, b ∈ A we have:

(1) G H = H G, (2) G (H J) = (G H) J,

(3) G ∅ = G, (4) fg B (fg B (G)) = fg B∪B (G), (5) fg B (∅) = ∅, (6) fg ∅ (G) = G, (7) ren h (ren h (G)) = ren h•h (G), (8) ren h (G H) = ren h (G) ren h (H), (9) ren h (∅) = ∅, ( 10
) ren {} (G) = G, (11) ren h (fg B (G)) = fg h(B) (ren h (G)), (
) a ab λ = ab λ , a -→ ab λ = -→ ab λ and a -→ ba λ = -→ ba λ . 17
Proof: Easy to check from the definitions.

Equalities (6) and (10) could be omitted from this list because they just say that fg ∅ and ren {} are identity operations. Hence, they express properties of the syntax and not properties of nontrivial graph operations. However, the reader will have in this a comprehensive list of equalities usable for proofs.

We have not listed conditional equalities, in particular the following one, let us number it for later reference:

(18) fg b (G H) = G fg b (H) if b / ∈ τ (G).
Such conditional equalities are best expressed as equalities of typed terms of the many-sorted HR algebra that we will define in Section 2.6.2. However, we will not develop this aspect.

Let us ask the question whether the equalities of Proposition 2.48 form a complete description of the equational29 properties of JS?

We can formulate this question more precisely, as follows. Every term t in T (F HR , {x 1 , . . . , x n }) where x 1 , . . . , x n are variables (intended to denote sgraphs) defines a derived operation t JS : J S n → J S. Two terms t and t in T (F HR , {x 1 , . . . , x n }) are equivalent if t JS = t JS . Does there exist, for each finite set C ⊆ A, a finite set C such that C ⊆ C ⊆ A and a finite set of equational axioms of the form t = t where t, t ∈ T (F HR C , {x 1 , . . . , x m }) that characterizes in equational logic the equivalence of pairs of terms in T (F HR C , {x 1 , . . . , x n }) for all n ≥ 0?

The many-sorted framework of Section 2.6.2 is perhaps necessary, or at least convenient. For a quite similar algebra, an equational characterization of the equivalence of terms without variables, hence that evaluate to constant s-graphs30 , is given in [BauCou] Proof: It is clear that, by using Equalities (1), (3), ( 5), ( 6) and (9) of Proposition 2.48, we can transform a term t in T (F HR C ) into an equivalent term t in T (F HR C ) with |t | ≤ |t| such that either t = ∅ or t is without ∅ and fg ∅ . The first case is excluded since val (t) = ∅. We now eliminate the source renaming operations from t assumed to be already without ∅ and fg ∅ . The construction is by induction on the size of t.

(1) If t is a constant symbol then t = t.

(2) If t = t 1 t 2 then t = t 1 t 2 .

(3) If t = fg B (t 1 ) then t = fg B ( t 1 ).

(4) If t = ren h (t 1 ), then we distinguish several subcases: (4. The constant symbols a are actually useful only for defining isolated vertices. If a term t in T (F HR ) evaluates to an s-graph G without isolated vertices, then the term t obtained from t by replacing each symbol a by ∅ evaluates to G, because all its vertices are defined as the ends of edges, hence by constant symbols of the forms ab, -→ ab and a . The constant symbols a κ are useful to define vertex labels. These labels are not otherwise specified because the constant symbols ab λ , -→ ab λ and a λ that define labelled edges do not specify the labels of the ends of these edges.

We will write a context over F HR as a term in T (F HR , {x 1 }) where the variable x 1 has a single occurrence (see Definition 2.6). Such a term defines a unary derived operation of the algebra JS. (For all other terms t in T (F HR , {x 1 }), such as the term x 1 x 1 , the unary derived operation t JS cannot be defined by a context.) We will prove that each such derived operation can be concretely described as the result of gluing a fixed s-graph to the input s-graph, followed by one forgetting and one renaming operation. The basic idea is that all renaming and forgetting operations of a term can be "moved outwards".

We define two contexts as equivalent if they define the same derived operation.

Proposition 2.50 Let C be a finite set of source names. For every context c in Ctxt(F HR C ), there exists a context c in Ctxt(F HR C ) written without renaming operations, and a permutation h of C such that the context ren h (c) is equivalent to c.

Proof:

The proof is by induction on the structure of c.

(1) If c = x 1 , then we let c be c and h be the identity.

(2) If c = c 1 t (or c = t c 1 ) where c 1 ∈ Ctxt(F HR C ) and t ∈ T (F HR C ), then, by the induction hypothesis, c 1 is equivalent to ren h1 (c 1 ) for some c 1 in Ctxt(F HR C ) written without renaming operations, and some permutation h 1 of C. It follows that c is equivalent to ren h1 (c 1 ) t and to ren h1 (c

1 ren h -1 1 (t))
by Equality (8) of Proposition 2.48. Hence we can take h := h 1 and c := c 1 t , where t is a term without renaming operations that is equivalent to ren h -1 1 (t). Such a term can be constructed by Proposition 2.49.

(3) If c = ren h (c 1 ) and h 1 , c 1 are obtained from c 1 by the induction hypothesis, we can take c := c 1 and h := h • h 1 by Equality (7) of Proposition 2.48.

(4) If c = fg B (c 1 ) and h 1 , c 1 are as in the previous case, then c is equivalent to fg B (ren h1 (c 1 )) and to ren h1 (f g h -1

1 (B) (c 1 )) by Equality (11) of Proposition 2.48. Hence we can take h := h 1 and c := f g h -1 (B) (c 1 ).

Proposition 2.51 Let B be a finite set of source names, and let c be a context in Ctxt(F HR B ). For every A ⊆ B there exists a set C of source names such that C ∩ B = ∅ and |C| ≤ |A|, a term t over F HR B∪C , a subset A of A and a permutation h of B ∪ C such that for every s-graph G of type included in A we have:

c JS (G) = ren h (fg A (G t JS )).
In other words, the restriction of c JS to s-graphs of type included in A is defined by the context ren h (fg A (x 1 t)) that belongs to Ctxt(F HR B∪C ).

Proof: We first use Proposition 2.50 to reduce the proof to the case of contexts written without renaming operations: a context c in Ctxt(F HR B ) is equivalent to ren k (c) for some permutation k of B and some context c without renaming operations. If c is equivalent on s-graphs of type included in A to a context of the form ren h (fg A (x 1 t)) with A ⊆ A and h ∈ Perm f (B ∪ C), then c is equivalent to ren k•h (fg A (x 1 t)) on the same s-graphs, because k is the identity on C (we use Equality (7) of Proposition 2.48).

We now prove the statement for a context c without renaming operations. Such a context is a term in T (F HR B , {x 1 }) and we let u be the occurrence in c of the variable x 1 . Without loss of generality we assume that c is written with the elementary operations fg a for a in B, and not with their compositions fg D for D ⊆ B (see Equalities (4) and (6) of Proposition 2.48). For convenience, the unary derived operation c JS defined by c will also be denoted by c.

We prove the statement by induction on the structure of c, together with the additional statements that (i) C = {a | a ∈ A } where {a | a ∈ A} is a set of source names in bijection with A and disjoint with B, and (ii) h is such that h(a) = a, h(a) = a for a in A and h(b) = b for b / ∈ A ∪ C. Thus, C and h are determined uniquely by A . We will also write t instead of t JS for a term t over F HR .

(1) If c = x 1 , then we take A := ∅ and t

:= ∅, because c(G) = G = ren {} (fg ∅ (G ∅)).
(2) If c = c 1 s where c 1 ∈ Ctxt(F HR B ) and s ∈ T (F HR B ), then, by the induction hypothesis, there are A and t 1 such that c 1 (G) = ren h (fg A (G t 1 )) for every s-graph G with τ (G) ⊆ A. For c we take the same set A and the term t := t 1 ren h (s). Then ren h (fg A (G t)) = ren h (fg A (G t 1 ) ren h (s)) by the fact that for all s-graphs H, K and every set of source names A , we have

fg A (H K) = fg A (H) K if τ (K) ∩ A = ∅ (and note that τ (ren h (s)) ⊆ h(B)
and h(B) ∩ A = ∅), see Equality (18) after Proposition 2.48. By Equalities (8) and (7) of Proposition 2.48 this equals ren h (fg A (G t 1 )) ren h•h (s) which equals c 1 (G) s because h • h is the identity.

(3) If c = fg b (c 1 ), with b / ∈ A or b ∈ A , and A , t 1 are obtained from the induction hypothesis, then we can take the same A and t := fg h(b) (t 1 ) by Equality (18) (and note that h(b) / ∈ τ (G)) and by Equalities (4) and (11) of Proposition 2.48.

(4) If c = fg a (c 1 ), with a ∈ A -A , and A , t 1 are obtained from the induction hypothesis, then we can take for c the same term t := t 1 and the set A := A ∪ {a} with the corresponding permutation h . In fact, again by Equalities (10) and (4) of Proposition 2.48, we have that c(G) = fg a (ren h (fg

A (G t 1 ))) = ren h (fg a (fg A (G t 1 ))) = ren h (fg A (G t 1 )) because h(a) = a, and this equals ren h (fg A (G t 1 )) because h (b) = h(b) for every b ∈ (B ∪ C) -A .
The extensions of Propositions 2.49, 2.50 and 2.51 to labelled graphs are straightforward.

Example 2.52 We let A = {a} and c be the context fg a (fg a (x 1 ab) ab ac) ac.

For τ (G) ⊆ {a} we have (with obvious simplifications):

G = ren {} (fg ∅ (G ∅)), G ab = ren {} (fg ∅ (G ab), fg a (G ab)
= ren a↔ā (fg a (G ab)), fg a (G ab) ab ac = ren a↔a (fg a (G ab ab ac)), fg a (fg a (G ab) ab ac) = ren a↔a (fg a (G fg a (ab ab ac))) and c(G)

= ren a↔a (fg a (G fg a (ab ab ac) ac))

by cases ( 1), ( 2), (4), (2), (3) and (2) respectively. Thus, ren h = ren a↔ā , fg A = fg a , and t = fg ā(ab āb āc) āc.

Tree-decompositions

In this section, we define tree-decompositions and we establish that the terms over F HR describe them. We get in this way a characterization of the associated graph complexity measure known as tree-width. For the numerous equivalent definitions and properties of tree-decompositions and tree-width, we refer the reader to the two comprehensive overview articles by Bodlaender [*Bod93, *Bod98] and to the books [*DowFel] and [*FluGro]. We only present and discuss the aspects of tree-decompositions that will be useful in the forthcoming chapters.

Tree-and path-decompositions

Our definition of tree-decomposition differs from the usual one on two minor technical points: it uses rooted trees and concerns graphs with sources.

(It generalizes the definition given in Section 1.4.2.) Since tree-and pathdecompositions do not depend on vertex or edge labels, we only define them for (unlabelled) s-graphs.

Definition 2.53 (Tree-decompositions)

Let G be a concrete s-graph. A tree-decomposition of G is a pair (T, f ) such that T is a concrete rooted tree and f is a mapping from N T to P(V G ) satisfying the following conditions, where a box of (T, f ) is a set f (u) for some u in N T :

(1) every vertex of G belongs to some box,

(2) every edge of G that is not a loop has its end vertices in some box,

(3) for every vertex x of G, the set f -1 (x) of all nodes u of T such that x ∈ f (u), is connected (i.e., T [f -1 (x)] is connected); this condition is called the connectivity condition,

(4) all sources of G belong to the box f (root T ), called the root box of the decomposition.

An equivalent formulation of (3) is that if u and v are two nodes of T , then f (u) ∩ f (v) ⊆ f (w) for every node w on the path in T between u and v. 31The width of (T, f ) is defined as wd (T, f ) := max{|f (u)| | u ∈ N T } -1. The tree-width of G, denoted by twd (G), is the smallest width of a tree-decomposition of G.

A tree-decomposition of a concrete s-graph G is optimal if its width is equal to twd (G). Isomorphic concrete s-graphs have isomorphic tree-decompositions, hence the same tree-width. Tree-decompositions and tree-width are thus well defined for (abstract) s-graphs. We denote by TWD(≤ k) the set of graphs of tree-width at most k, and by TWD(≤ k, C) the set of s-graphs of tree-width at most k and of type included in a set of source names C. The tree-width twd (L) of a set of s-graphs L is defined as the least upper-bound of the tree-widths of its elements. We say that L has bounded tree-width if twd (L) ∈ N ∪ {-1} (otherwise twd (L) = ω).

Definition 2.54 (Rich tree-decompositions) A rich tree-decomposition of an s-graph G is a pair (T, f ) where T is as in Definition 2.53, f is a mapping : N T → P(V G ∪ E G ) and Condition (2) is replaced by the following one:

(2 ) every edge of G belongs to a unique box and its end vertices belong to this box.

The width of (T, f ), denoted by wd (T, f ), is defined as max{|f

(u) ∩ V G | | u ∈ N T } -1. It is clear that if (T, f ) is a rich tree-decomposition of G, then (T, f ) such that f (u) := f (u)∩V G for
all u is a tree-decomposition of G, having the same width as (T, f ). Conversely, every tree-decomposition (T, f ) can be turned into a rich one, (T, f ), such that f (u) = f (u)∩V G for every u. It suffices to define f (u) as the set f (u) ∪ {e ∈ E G | u is the least common ancestor of the nodes w such that f (w) contains the end vertices of e}. It follows that the tree-width of an s-graph is the same whether we define it with respect to tree-decompositions or to rich tree-decompositions.

From a rich tree-decomposition (T, f ) of an s-graph G, we will construct in Section 2.4.5 a term in T (F HR ) evaluating to G, and conversely, a rich treedecomposition will be associated with each term evaluating to it.

Remarks 2.55

(a) If (T, f ) is a tree-decomposition or a rich tree-decomposition of G, then every vertex x of G belongs to a unique ≤ T -maximal box f (u) of (T, f ). This follows from Conditions (1) and (3) of the definitions and the fact that T is rooted (otherwise ≤ T is not defined). In fact, u is the least common ancestor of all nodes in f -1 (x), and it is the root of the rooted tree T [f -1 (x)].

(b) For a graph, Condition (4) of Definition 2.53 is trivially true and any node of the tree T can be chosen as the root. Equivalently, the tree T of a tree-decomposition (T, f ) of a graph can be defined as a tree without root.

(c) Let (T, f ) be a tree-decomposition or a rich tree-decomposition of G with wd (T, f ) = k -1. By Conditions (1) and (2), we have that

|V G | ≤ k •|N T | and, if G is simple, that |E G | ≤ k 2 • |N T |.
|τ (G)| -1 ≤ twd (G) ≤ |V G | -1.
The tree-width of the empty graph is -1. A nonempty s-graph has tree-width 0 if and only if it has only loops and isolated vertices, and has at most one source.

(d) The notion of a tree-decomposition depends neither on edge directions nor on colors, labels or weights possibly attached to vertices and/or edges. Adding or deleting a loop, or fusing two edges with the same ends into a single one does not change the tree-width. Thus, twd (G) = twd (core(G)) for every s-graph G (for the core of G, see Definition 2.9 and Proposition 2.47).

Examples 2.56

The following examples concern graphs.

(1) A tree T with at least one edge has tree-width 1. To see this, we choose any node r as a root, which turns T into a rooted (hence directed) tree (cf. Definition 2.13). We let f : N T → P(N T ∪ E T ) be defined by: (a) f (r) := {r}, Clearly (T, f ) is a rich tree-decomposition of T and its width is 1. For constructing a tree-decomposition of a forest F , we add edges to turn F into a tree to which we apply the above construction. We obtain a tree-decomposition of width 1 of F .

(2) Figures 2.5, 2.6, 2.7 show a graph G and a rich tree-decomposition (T, f ) of this graph. The root of T is the node a in Figure 2.7, the boxes of the decomposition are represented in Figure 2.6 as disjoint graphs with continuous lines representing edges. A dotted edge links two vertices of these disjoint graphs that correspond to the same vertex of G. We denote by G(T, f ) the graph representing (T, f ) as it is shown in Figure 2.6 with its two types of edges. Its dotted edges form a forest. The graph G is obtained from it by contracting all dotted edges (see Definition 2.15 for edge contractions). The vertex x of G belongs to boxes b, c, d, e. The four vertices (x, b), (x, c), (x, d), (x, e) of the graph G(T, f ) of Figure 2.6 get fused and yield the vertex x of G. Nodes b, c, d, e form a path in T , hence T [f -1 (x)] is connected. The width of (T, f ) is 3.

(3) Here are the tree-widths of some classical graphs. The graphs K n (the cliques) and K n,m (the complete bipartite graphs) are defined in Section 1.3.1; C n is a cycle with n vertices and G n×m is the rectangular n × m grid defined as [n] × [m], edg with ((i, j), (i , j )) ∈ edg if and only if either i = i + 1 and j = j, or i = i and j = j + 1. For n, m ≥ 1 we have twd and the inequalities twd (K n,m ) ≤ min{n, m}, twd (C n ) ≤ 2, twd (G n×m ) ≤ min{n, m} follow from easy constructions (see also (6) below). Theorem 12.3.9 of [*Die] shows that twd (G n×n ) ≥ n-1 (with a proof technique that can be used for finding other lower bounds). The lower bound twd (G n×n ) ≥ n is proved in [*Bod98], Corollary 89. Hence we get by Corollary 2.60(1) stated below that twd (G n×m ) = min{n, m}. The other opposite inequalities will be proved in Section 2.4.2.

(K n ) = n -1, twd (K n,m ) = min{n, m}, twd (C n ) = 2 if n ≥ 3, and twd (G n×m ) = min{n, m}. The inequality twd (K n ) ≤ n -1 follows from Remark 2.55(c),
(4) Rectangular grids, hence more generally, planar graphs have unbounded tree-width but outerplanar graphs have tree-width at most 2 (see [*Bod98]).

(5) The incidence graph Inc(G) of an undirected graph G (already defined in Section 1.8.1) has vertex set V G ∪ E G and edges between e and x whenever x ∈ V G , e ∈ E G and x is an end of e. The tree-width of Inc(G) is at most max{2, twd (G)}. To see this, take a rich tree-decomposition (T, f ) of G. For each edge e of G, add to the node u of T such that e ∈ f (u) a new son u e and extend f in such a way that f (u e ) consists of e and its ends. The resulting pair is a tree-decomposition of Inc(G) as the reader will easily verify.

(6) Let us say that a rooted tree T is normal for a graph G if N T = V G and every two adjacent vertices of G are comparable with respect to ≤ T (like in a normal spanning tree, except that here, we do not require that two adjacent nodes of T are adjacent in G, see Definition 2.13). A normal tree-decomposition of a graph G is a tree-decomposition (T, f ) such that T is normal for G and f is defined as follows from G and T :

f (u) := {u} ∪ {w | u ≤ T w and w is adjacent in G to some v ≤ T u}.
It is a tree-decomposition as one checks easily: if u ∈ f -1 (w), then u ≤ T w and all vertices on the path from w to u in T are in f -1 (w), and so f -1 (w) is connected.

As an example, a normal spanning tree T of the cycle C n is obtained by removing an edge and taking one of its ends as root (thus, T is a directed path). The corresponding normal tree-decomposition (T, f ) has width 2. As another example, a normal tree for the complete bipartite graph K n,m , with n ≤ m, is the directed path with edges (i, i + 1) (it first enumerates the n nodes and then the m nodes of the bipartition). The corresponding normal tree-decomposition has width n. As a final example, a normal tree for the grid G n×m , with n ≤ m, is the directed path with root (1, 1) and edges ((i, j), (i+1, j)) and ((n, j), (1, j+1)), and the normal tree-decomposition has width n.

We will show in Corollary 2.73(3) that every nonempty graph has an optimal normal tree-decomposition. Definition 2.57 (Path-decompositions and path-width) A path-decomposition (resp. a rich path-decomposition) of an s-graph is a treedecomposition (resp. a rich tree-decomposition) (T, f ) such that T is a directed path (and hence its root is one end of this path). The path-width of an s-graph G is the smallest width of its path-decompositions. It is denoted by pwd (G). We denote by PWD(≤ k) the set of graphs of path-width at most k, and by PWD(≤ k, C) the set of s-graphs of path-width at most k and of type included in a set of source names C.

A path-decomposition of an s-graph G can be specified as a sequence D ∈ Seq(P(V G )): it corresponds to (T, f ) where

T = [|D|], {(i, i + 1) | i ∈ [|D| -1]} and f (i) = D[i].
Since every path-decomposition is a tree-decomposition, we have

twd (G) ≤ pwd (G) ≤ |V G | -1.
The tree-width of an s-graph may be smaller than its path-width. In particular trees have unbounded path-width, but tree-width at most 1. The graphs K n , K n,m , C n , G n×m considered in Examples 2.56(3,6) have equal path-width and tree-width. For every graph G we have, by a result of [BodGHK]:

pwd (G) ≤ (twd (G) + 1) • log(|V G |).
We now detail the case of the complete binary tree T n of height n: its set of nodes is the set of words over {0, 1} of length at most n and a node u is an ancestor of w if and only if u is a prefix of w. Hence ε is the root. For n ≥ 1, we have twd

(T n ) = 1 and pwd (T n ) = n/2 . A path-decomposition of T 2 of width 1 is D 1 := ({0, 00}, {0, 01}, {0, ε}, {ε, 1}, {1, 10}, {1, 11}).
By induction on n, we define

D n+1 := (00D n + 0) • (01D n + 0) • ({0, ε}, {ε, 1}) • (10D n + 1) • (11D n + 1),
where we use the following notation: if D is a path-decomposition of a graph G with vertices in {0, 1} * , then D + u is the path-decomposition (of a graph with at most one more vertex than G) obtained by adding u to each box, and uD the path-decomposition of a graph isomorphic to G obtained by replacing each word w by uw. The reader will verify easily that D n is, for each n, a pathdecomposition of T 2n of width n. The path-width of T 2n+1 is larger than n: this follows from the characterization given in [TakUK] of the acyclic excluded minors for graphs of path-width at most n.

Some properties of tree-decompositions

We review a few results that will be useful in the sequel. Proofs and references can be found in [*Bod98]. For two disjoint sets A and B, we denote by A ⊗ B the complete bipartite concrete graph with V A⊗B = A ∪ B and edges between each vertex of A and each vertex of B.

Proposition 2.58 Let (T, f ) be a tree-decomposition of a concrete s-graph G and A, B ⊆ V G . If A is a clique in the graph core(G), then A is included in some box of (T, f ). If A ∩ B = ∅ and A ⊗ B is a subgraph of core(G), then at least one of A and B is included in some box.

It follows that twd

(K n ) ≥ n -1 and twd (K n,m ) ≥ n -1 if n ≤ m. We know from Examples 2.56(3,6) that twd (K n ) ≤ n -1 and twd (K n,m ) ≤ n. Thus, twd (K n ) = n -1.
Since K n+1 is a minor of K n,n , we have (by Corollary 2.60(1) below) twd (K n+1 ) ≤ twd (K n,m ) and thus twd (K n,m ) = n (if n ≤ m). (To prove that K n+1 ¢ K n,n we consider the graph isomorphic to K n,n with vertices u 1 , . . . , u n , v 1 , . . . , v n and edges e i,j : u i -v j for all i, j ∈ [n]; we contract the edges e i,i for i = 2, . . . , n, which yields a graph H with vertices u 1 , . . . , u n , v 1 ; it is clear that K n+1 is isomorphic to core(H). Since core(H) ⊆ H, we obtain from Proposition 2.17 that

K n+1 ¢ K n,n .) Similarly, K 3 ¢ C n for n ≥ 3
(G) -1 ≤ twd (H) ≤ twd (G).
The proof is easy. We obtain thus from Proposition 2.17(2) the first assertion of the following corollary.

Corollary 2.60

(1) If H is a minor of a graph G, then twd (H) ≤ twd (G).
(2) For every k there is a finite set Ω k of simple, loop-free, undirected graphs such that a graph G has tree-width at most k if and only if core(G) has no minor isomorphic to a graph in Ω k .

The second assertion follows from the first assertion, the fact that twd (G) = twd (core(G)) and a particular case of the Graph Minor Theorem recalled in Section 2.2 (after Proposition 2.21) that is proved in [START_REF] Robertson | Graph minors IV. Tree-width and well-quasi-ordering[END_REF]. The sets Ω k are known for k at most 3: Ω 1 = {K 3 }, Ω 2 = {K 4 } and Ω 3 consists of four graphs (see [ArnPC]). Each set Ω k contains K k+2 . A result in [Lag] shows that graphs in Ω k have size at most exp(exp(O(k 5 ))) where for every integer n, exp(n) = 2 n . It follows that they can be, in principle, determined. However, this upper-bound is too large to be usable in any implementable algorithm.

Proposition 2.59 and Corollary 2.60 hold for path-width instead of treewidth, with a finite set Θ k instead of Ω k for the graphs of path-width at most k. The trees in Θ k have been determined in [TakUK]: there are more than (k!) 2 trees in Θ k , all with (5/2) • (3 k -1) vertices.

Proposition 2.61 For each k, the set Ω k contains at least one planar graph. Conversely, for every planar graph P , the set of graphs not containing P as a minor has bounded tree-width.

Proof: Since twd (G (k+1)×(k+1) ) = k + 1 (Example 2.56(3)), the undirected grid core(G (k+1)×(k+1) ) has a minor P in Ω k by Corollary 2.60(2). This graph P is planar since every minor of a planar graph is planar. The second assertion is due to Robertson and Seymour and is proved in Theorem 12.4.3 of [*Die]. The proof yields an upper-bound exp(O(n 5 )) where n is the number of vertices of P .

The set Ω k characterizes the graphs in TWD(≤ k). It can also be used to characterize the s-graphs in TWD(≤ k, C) where C is a set of at most k+1 source names. Let C be such a set and let K C be the simple loop-free undirected sgraph of type C such that K We conclude this review with easier results. Every graph can be decomposed into its 2-connected components (its maximal induced subgraphs without separating vertices), and these components form a tree. Furthermore, every 2-connected graph can also be decomposed into a tree of so-called 3-blocks. A 3-block is either a cycle, or a bond (a set of pairwise parallel edges) or a 3-connected graph (a 2-connected graph without separating set of two vertices). The 3-blocks of a graph, i.e., the 3-blocks of its 2-connected components, are minors of it.

Proposition 2.62 The tree-width of a nonempty graph G is the maximal treewidth of its connected components. It is also the maximal tree-width of its 2-connected components and the maximal tree-width of its 3-blocks.

The last assertion is proved in [START_REF] Courcelle | The monadic second-order logic of graphs XI: Hierarchical decompositions of connected graphs[END_REF]. The two others follow from straightforward constructions.

Transformations of tree-and path-decompositions

We consider transformations of tree-and path-decompositions of a given s-graph intended to reduce some parameters like the number of boxes without, hopefully, increasing the width, or by increasing it in a controlled way. By iterating certain of these elementary transformations, one can put tree-decompositions in certain normal forms.

Definition 2.63 (Edge contractions in a tree-decomposition) Let (T, f ) be a (rich) tree-decomposition of an s-graph G, and let e : u → v be an edge of T . We let T /e be the result of the contraction of e. Its set of nodes is defined as N T /e = N T -{v}: from the two vertices u and v that are fused, we keep u as result of the fusion, and the edges from v to w of T are made into edges from u to w in T /e. We let (T /e, f e ) be the pair such that:

f e (w) := f (w) if w ∈ N T -{u, v} = N T /e -{u} f (u) ∪ f (v) if w = u.
With these notations and hypotheses: Lemma 2.64 The pair (T /e, f e ) is a (rich) tree-decomposition of G if (T, f ) is a (rich) tree-decomposition of G. We have

wd (T /e, f e ) = max{wd (T, f ), |(f (u) ∪ f (v)) ∩ V G | -1}
where u and v are the end vertices of e. The same result holds for (rich) pathdecompositions.

Remark 2.65 If E is a set of edges of a rooted tree T , then (((T /e 1 )/e 2 ) • • • )/e n is the same for every enumeration e 1 , . . . , e n of E. This is so because rooted trees are directed so that each node has indegree at most 1 and when we contract an edge, we take its tail as the vertex resulting from this contraction. We can thus define T /E, the result of the simultaneous contraction of all edges of E. The nodes in T that are in T /E are the roots of the rooted forest T

[E]. Similarly, if (T, f ) is a tree-decomposition of G, then (T /E, f E ) is also one, where, for a root r of T [E], f E (r) is the union of all f (u) such that u is a descendant of r in T [E].
We consider some conditions that can be imposed on tree-decompositions and on path-decompositions without increasing the associated widths. In all cases, we give an algorithm that transforms an arbitrary decomposition into one of no larger width that satisfies the considered conditions. Definition 2.66 (Downwards increasing decompositions) A tree-decomposition (T, f ) of an s-graph G is downwards increasing if, for every edge u → v of T , we have f (v) -f (u) = ∅. This means that f (v) is not a subset of f (u). In this case wd (T, f ) ≤ k implies |f (u)∩f (v)| ≤ k for every edge u → v. Assuming that the box f (root T ) is nonempty, we also have

|N T | ≤ |V G |. A tree-decomposition (T, f ) is 1-downwards increasing if |f (v) -f (u)| = 1 for every u, v as above. In this case, |V G | = |N T | + |f (root T )| -1.
Every normal tree-decomposition (Example 2.56(6)) is 1-downwards increasing. The tree-decomposition of Figure 2.6 is downwards increasing but not 1-downwards increasing.

Proposition 2.67

(1) Let (T, f ) be a tree-or a path-decomposition of an s-graph G. By applying to T a series of edge contractions, one can transform it into a tree-or a path-decomposition of G of the same width, such that every two boxes are incomparable for inclusion, and that is thus downwards increasing.

(2) Every graph has an optimal tree-decomposition (path-decomposition) that is 1-downwards increasing.

Proof: (1) Let (T, f ) be such that f (v) ⊆ f (u) or f (u) ⊆ f (v) for some edge e : u → v. By contracting this edge, we get by Lemma 2.64 a tree-or a pathdecomposition (T /e, f e ) of G. Since f (u) ∪ f (v) is equal to f (u) or to f (v) we have wd (T /e, f e ) = wd (T, f ). By repeating this elementary step at most |edg T | times, we obtain a decomposition of the desired form.

(2) By [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF], every graph has an optimal tree-decomposition (path-decomposition) that is downwards increasing. This decomposition can be made 1-downwards increasing by insertion of new nodes in the tree. We omit the easy formal details.

Definition 2.68 (Binary tree-decompositions) Let (T, f ) be a (rich) tree-decomposition. It is binary if every node of T has outdegree at most 2. For u ∈ N T , we let d(u) := max{0, outdegree(u) -2} and d(T ) := u∈N T d(u). Hence (T, f ) is binary if and only if d(T ) = 0.

Proposition 2.69 Every (rich) tree-decomposition (T, f ) of an s-graph G can be transformed into a binary (rich) tree-decomposition (T , f ) of G of the same width, such that ht(T ) ≤ (max u∈N T { log(d(u) + 2) }) • ht(T ). The reverse transformation of (T , f ) into (T, f ) can be done by edge contraction.

Proof: Let (T, f ) and G be as in the statement. It obviously suffices to consider the non-rich case. If d(T ) = 0 there is nothing to do. If d(T ) = 0, we take any node u with outgoing edges u → v 1 , . . . , u → v p , p ≥ 3, we introduce a new node u and we replace the edges u → v p-1 and u → v p by the edges u → u , u → v p-1 and u → v p . We obtain a tree T 1 with d(T 1 ) = d(T ) -1. We turn it into a tree-decomposition (T 1 , f 1 ) by defining f 1 (u ) := f (u) and f 1 (w) := f (w) for w ∈ N T . It is clear that (T 1 , f 1 ) is a tree-decomposition of G that gives back (T, f ) by contracting the new edge u → u .32 Since f 1 (u ) = f (u) we have wd (T, f ) = wd (T 1 , f 1 ).

By repeating this elementary transformation d(T ) times, we obtain from (T, f ) a binary tree-decomposition (T , f ) of the s-graph G of the same width that gives back (T, f ) by d(T ) edge contractions. The height of T is at most (max u∈N T {d(u) + 1}) • ht(T ) which is not the desired bound.

We now modify the construction so as to obtain a binary tree-decomposition (T , f ) of height ht(T ) ≤ (max u∈N T { log(d(u)+2) })•ht(T ). In the case where p ≥ 4, we add two new nodes u and u and we replace the edges

u → v 1 , . . . , u → v p by u → u , u → u , u → v 1 , . . . , u → v q , u → v q+1 , .
. . , u → v p where q = p/2 . We obtain a tree T and we define f by f (u ) := f (u), f (u ) := f (u), and f (w) := f (w) for w ∈ N T . We obtain a tree-decomposition (T , f ) of the s-graph G such that wd (T , f ) = wd (T, f ), d(T ) < d(T ) -1 and that gives back (T, f ) by contracting two edges. By repeating this step at most d(T ) times, we obtain a tree-decomposition having the desired properties.

Remark 2.70 The transformations of Propositions 2.67 and 2.69 go in opposite directions. This suggests the following question: Does every graph have an optimal tree-decomposition that is binary and downwards increasing?

The answer is no, we give a counter-example. We let G be the simple undirected graph such that V G = {1, 2, 3, 4, 1 , 2 , 3 , 4 }, its edges are between i and j for 1 ≤ i < j ≤ 4 and between i and j for 1 ≤ i, j ≤ 4, i = j. This graph is shown in Figure 2.8.

The graph G is the union of 5 cliques with sets of vertices f (0) = {1, 2, 3, 4}, f (1) = {1 , 2, 3, 4}, f (2) = {1, 2 , 3, 4}, f (3) = {1, 2, 3 , 4} and f (4) = {1, 2, 3, 4 }. It has a tree-decomposition (T, f ) where T consists of the edges 0 → 1, 0 → 2, 0 → 3, 0 → 4. Let (U, g) be a downwards increasing optimal tree-decomposition. Its width cannot be less than 3 (because by Proposition 2.58 each set f (i) is included in a box g(u) for some u in N U ). Hence, it is 3. Assuming that U is binary, we will get a contradiction.

Let u ∈ N U be a node such that g(u) = f (0). Consider a son v of u. It must contain one of 1 , 2 , 3 , 4 . Assume it contains 1 . Necessarily g(v) = f (1) and v is a leaf. Now u has at most two sons, v and v . Without loss of generality we assume that g(v) = f (1) and g(v ) = f (2). Hence (whether u has 2, 1, or 0 sons) there exist two nodes w and w such that g(w) = f (3) and g(w ) = f (4), and none of them is below u. The father y of u belongs to the (undirected) paths in U between u and w and between u and w . (We may have y = w or y = w ). It follows that g(y) includes {1, 2, 4} (because y is on the path between u and w) and g(y) includes {1, 2, 3} (because y is on the path between u and w ). Hence g(y) includes {1, 2, 3, 4} = g(u), which contradicts the fact that (U, g) is downwards increasing. Thus, the graph G has no optimal, binary and downwards increasing tree-decomposition.

Tree-decompositions and chordal graphs

We consider the graphs that have tree-decompositions, all boxes of which induce cliques. Efficient algorithms for chordal graphs, based on their treedecompositions, are presented in [Gav] 2.8 is 4-chordal.) A k-perfect elimination order for a graph G in C is an enumeration π = (v 1 , . . . , v n ) of V G such that for each i = 2, . . . , n, the set N i := {v j | j < i and v j -G v i } is a nonempty clique with at most k -1 vertices33 . A k-perfect spanning tree is a normal (rooted) spanning tree T of G (cf. Definition 2.13) such that for every u ∈ V G , the set

M u := {w ∈ V G | u -G w and u ≤ T w} is a clique in G with at most k -1 vertices. A graph is chordal if it is k-chordal for
some k, and similarly perfect for a spanning tree or an elimination order means k-perfect for some k. The clique number of a graph G is ω(G), the maximal number of vertices of a clique in G.

A simplicial orientation of a graph G ∈ C is an acyclic orientation H of G such that for every vertex u, the set Adj - H (u) of vertices w such that w → H u is a clique in H (hence, a clique in G). Its indegree is the maximal indegree of its vertices.

Proposition 2.72 For every graph G belonging to C the following properties are equivalent:

(1) G is k-chordal,

(2) G has a k-perfect elimination order,

(3) G has a simplicial orientation of indegree at most k -1, (4) G has a k-perfect spanning tree, (5) G has no induced cycle with at least 4 vertices and its clique number is at most k.

Proof: (1) =⇒ (2). The proof is by induction on n = |V G |. The case n = 1 requires no proof. Otherwise, let (T, f ) be a tree-decomposition of G, each box of which is a nonempty clique with at most k vertices. We can assume that it is downwards increasing because the transformation of Proposition 2.67 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] preserves the property that each box is a nonempty clique with at most k vertices.

If |N T | = 1, then any linear order on V G = f (root T ) is a k-perfect elimination order. Otherwise, let u be any leaf of T . The box f (u) contains a vertex v that belongs to no other box, hence the set f (u) -{v} of its neighbors is a nonempty clique (because G is connected) with at most k -1 vertices. The graph G -v (i.e., G minus v and the incident edges) is also k-chordal (it is still connected) and, by the induction hypothesis, it has a k-perfect elimination order (v 1 , . . . , v n-1 ). Then (v 1 , . . . , v n-1 , v) is a k-perfect elimination order for G, which completes the proof.

(2) =⇒ (3). Let G ∈ C have a k-perfect elimination order (v 1 , . . . , v n ). We define an acyclic orientation H of G by letting v j → H v i if and only if j < i and v j -G v i . It is simplicial and of indegree at most k -1.

(3) =⇒ (4). Let G ∈ C have a simplicial orientation H of indegree at most k -1. Since H is acyclic (and finite), it has a vertex u 1 of indegree 0. Every vertex u of H is reachable from u 1 by a directed path, as one proves easily by induction on the length of an undirected path from u 1 to u (if u i-1 , u i , u i+1 are three consecutive vertices on that path with u i-1 → H u i and

u i ← H u i+1 , i.e., u i+1 → H u i , then u i-1 -G u i+1 because Adj - H (u i
) is a clique). We let T be the transitive reduction of H, i.e., the graph T such that V T := V H = V G and E T is the set of edges w → H u such that there is no directed path in H of length at least 2 from w to u. The vertex u 1 has also indegree 0 in T . Every other vertex u has at least one incoming edge because it is reachable from u 1 . If it had indegree at least 2 in T , we would have w → T u and w → T u with w = w , hence w → H w (or vice versa) because Adj - H (u) is a clique, and then w → u could not be an edge of T . It follows that T is a rooted spanning tree of H and of G. If w → H u, then there is a directed path in T from w to u, i.e., u ≤ T w. Hence T is a normal spanning tree. It is k-perfect since M u = Adj - H (u) and Adj - H (u) is a clique with at most k -1 vertices. (4) =⇒ [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. Let T be a k-perfect spanning tree of G and let (T, f ) be the associated normal tree-decomposition (as defined in Example 2.56(6)). We have actually f (u) = {u}∪M u : from the definition of f , we have {u}∪M u ⊆ f (u); for proving the opposite inclusion, we note that, since T is perfect, if v < T w and w is adjacent to v, then w is adjacent to every vertex u such that v < T u < T w (if u is the father of v, then both w and u are in M v ). Since T is k-perfect, each set f (u) is a nonempty clique with at most k vertices, hence G is k-chordal.

(2) =⇒ (5). Let G in C have a perfect elimination order π = (v 1 , . . . , v n ). Assume that C is an induced cycle in G of length at least 4 with last element v i . There are v j and v j in C that are adjacent to v i , that are not adjacent and are such that j, j < i. This contradicts the hypothesis that π is a perfect elimination order. Since G also satisfies [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF], its clique number is at most k (by Proposition 2.58).

(5) =⇒ [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. This is proved as Proposition 5. (1) Every chordal graph G is ω(G)-chordal, and its tree-width is ω(G) -1.

(2) The tree-width of a graph G with at least one edge that is not a loop, is the minimal tree-width of a chordal graph H such that V G = V H and core(G) ⊆ H.

(3) Every nonempty graph has an optimal normal tree-decomposition 34 .

Proof:

(1) That ω(G) -1 ≤ twd (G) follows from Proposition 2.58. If G is chordal, it has a tree-decomposition (T, f ), each box of which is a clique, hence G is ω(G)-chordal and twd (G) ≤ ω(G) -1.
(2) Let m be the minimal tree-width of a chordal graph H containing core(G) as subgraph. Then twd (G) = twd (core(G)) ≤ m by Corollary 2.60 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF].

Let conversely (T, f ) be an optimal tree-decomposition of G. Since G has at least one edge that is not a loop, the width of (T, f ) is at least 1. By Proposition 2.67 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] we may assume that (T, f ) has no empty boxes. Moreover, we may assume that (T, f ) has the special property that adjacent boxes are not disjoint. In fact, for every edge e : u → v of T with f (u)∩f (v) = ∅, we introduce a new node w e and we replace the edge e by the edges u → w e and w e → v. We extend f by defining f (w e ) = {x, y} for some x ∈ f (u) and y ∈ f (v). It is clear that this leads to a tree-decomposition of G of the same width. Now let H be the graph such that V H = V G and any two vertices in a same box of (T, f ) are adjacent. Since (T, f ) has the above special property, we obtain that H is connected, hence H ∈ C. Clearly core(G) ⊆ H, (T, f ) is a tree-decomposition of H of width twd (G), and H is chordal. This completes the proof.

(3) Let G be a nonempty graph. The result is obvious if all edges of G are loops. So, let G have at least one edge that is not a loop, and let k := twd (G). By (2), there is a chordal graph H such that V G = V H , core(G) ⊆ H, and twd (H) = k. Then H is (k + 1)-chordal by [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. Hence, by the proof of Proposition 2.72 (in particular (4) =⇒ [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]), H has a normal tree-decomposition (T, f ) of width k. Since core(G) ⊆ H, the tree T is normal for G and if (T, f ) is the corresponding normal tree-decomposition of G, then f (u) ⊆ f (u) for every u in V G . Hence (T, f ) has width k.

Normal tree-decompositions will be used in Example 5.2(4) for defining logical representations of tree-decompositions.

Corollary 2.74

(1) Every simple, loop-free, undirected graph G of tree-width at most k has at most k

• |V G | -k(k + 1)/2 edges if |V G | ≥ k + 1.
(2) For all k, n > 0, there are less than 2 kn•(log(n)+1) simple, loop-free, undirected concrete graphs of tree-width at most k with vertex set [n].

Proof: (1) Let G be as in the statement with at least one edge (the result is obvious for graphs without edges). Using Corollary 2.73(2), let H be a chordal graph of tree-width at most k such that G ⊆ H and V H = V G . By Corollary 2.73 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF], H is (k + 1)-chordal. Thus, by ( 1) =⇒ (2) of Proposition 2.72, the graph H has a (k + 1)-perfect elimination order π = (v 1 , . . . , v n ). We let

G i = G[{v 1 , . . . , v i }].
The property holds for G k+1 , and for each i we have

|E Gi | ≤ |E Gi-1 | + k (because |N i | ≤ k)
, which gives the result for each graph G i , by induction on i, hence for G.

(2) We let G, H, π be as in [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] with

V G = [n].
It follows from the existence of π that H is the union of at most k edge-disjoint forests35 , hence is a subgraph of the union of k trees with set of nodes V G . The same holds for G, and the same holds, obviously, for graphs without edges.

There are n n-2 trees36 with set of nodes [n], at most n k(n-2) unions of k such trees, and at most 2 k(n-1) ways to delete edges from any set of at most k(n -1) edges, so that there are at most 2 k(n-1) • 2 k(n-2)•log(n) < 2 kn•(log(n)+1) graphs that are the union of k forests with vertex set [n]. This gives the claimed result.

Since there are n n-2 trees with set of nodes [n], the upper-bound 2 kn•(log(n)+1) cannot be lowered to 2 o(n•log(n)) .

A syntax for tree-decompositions

We will establish correspondences between terms in T (F HR ) and tree-decompositions of the s-graphs they define. These correspondences will yield the equality twd (G) = wd (G) -1 where wd (G) is the width of an s-graph G defined as the minimal cardinality of a set C such that G is the value of a term in T (F HR C ). We first give an idea of the constructions. The expression of an s-graph G as val (t) for t ∈ T (F HR C ) yields a tree-decomposition of G based on the syntactic tree T of t. The size of a box of this decomposition is at most |C| which gives twd (G) ≤ wd (G) -1. For the other direction, we will transform a rich tree-decomposition (T, f ) of an s-graph G into a term that evaluates to it and is written with at most wd (T, f ) + 1 source names. Although none of these two transformations is the inverse of the other, they are closely related. The specific features of a tree-decomposition like being binary or unary (i.e., being a path-decomposition), its size and its height are reflected in the corresponding terms.

Definition 2.75 (The rich tree-decomposition associated with a term over F HR ) Let t ∈ T (F HR ). We recall from Definition 2.35 that µ(t) is the set of source names in A that are used in the operations of t, and that wd (t), the width of t, equals |µ(t)|. We denote by X max the canonical cross-section of ≈ t (cf. Section 2.3.2) that consists of the pairs (u, a) such that u is maximal for ≤ t . The concrete s-graph cval (t) = (Exp(t)/≈ t ) Xmax with vertex set X max is isomorphic to val (t). We take the syntactic tree T of t (without its labels) as the rooted tree of the rich tree-decomposition (T, f ) of cval (t) to be constructed. We define f as follows.

Case 1 : u is an occurrence of a constant symbol that describes an edge of the s-graph cval (t). Then u is this edge in Exp(t) as well as in cval (t). We let:

f (u) := {u} ∪ {w ∈ X max | w ≈ t (u, a) for some a in τ (u)}.
Case 2 : u is not an occurrence of such a symbol. Then we let f (u) be the set {w ∈ X max | w ≈ t (u, a) for some a in τ (u)}.

In both cases, there are at most wd (t) such pairs (u, a), because τ (u) ⊆ µ(t); hence |f (u) ∩ X max | ≤ wd (t).

For example, the decomposition associated with the term

t = -→ cd ren a↔c ( -→ ab fg b ( -→ ab -→ bc))
is shown in Figure 2.9. In each box f (u) the elements of τ (u) are indicated, i.e., the names of the sources of val (t/u). The elements of X max are circled.

With this notation we have:

Proposition 2.76

(1) For each finite set C, if t ∈ T (F HR C ), then the pair (T, f ) defined in Definition 2.75 is a rich tree-decomposition of the s-graph cval (t) of width at most |C| -1. It can be constructed from t in time O(|t|).

(2) We have twd (G) ≤ wd (G) -1 for every (labelled) s-graph G.

Proof: (1) Let t ∈ T (F HR C ) and (T, f ) be as in Definition 2.75. All conditions of the definition of a tree-decomposition are clearly valid, except possibly the connectivity condition (Condition (3) of Definition 2.53). For each w ∈ X max , the set f -1 (w) defined as {u ∈ N T | w ∈ f (u)}, is the set of nodes that are the first components of the pairs (u, a) that are ≈ t -equivalent to w. But the equivalence relation ≈ t is generated by pairs ((u, a), (v, b)) such that u and v are adjacent nodes of T . Hence the nodes in f -1 (w) induce a connected subgraph of T . This proves the connectivity condition. It is clear that

|f (u) ∩ V cval(t) | ≤ wd (t) ≤ |C| for every u ∈ N T , which gives wd (T, f ) ≤ |C| -1. It is also clear, from the proof of Proposition 2.45, that (T, f ) can be constructed from t in time O(|C| • |t|): w ∈ f (u) if and only if w = max (u, a) for some a in τ (u).
(2) is an immediate consequence of (1).

Remarks 2.77 (1) If (u, a) is a vertex of cval (t), then it belongs to a unique maximal box of the tree decomposition (Remark 2.55(a)). This box is f (u) because X max , the vertex set of cval (t), is the canonical cross-section and thus consists of the maximal pairs (u, a). See Figure 2.9 where the circled vertices are those of X max .

Figure 2.9: The rich tree-decomposition for the term t of Definition 2.75.

(2) The rich tree-decompositions (T, f ) produced by this construction have the particular property that only the boxes at the leaves of T contain edges, and they never contain more than one edge. Hence, not all rich tree-decompositions are associated with terms by the above construction.

Furthermore, these tree-decompositions are binary but not downwards increasing. The number of boxes is clearly not minimal; it can be reduced by edge contractions (cf. Section 2.4.3). In particular, if u is an occurrence of a renaming operation ren h , and its son is v, then f (u) = f (v). One can thus contract the edge u → v of T and one gets a smaller rich tree-decomposition of the same s-graph, having the same width.

(3) If t is a term that defines a (K, Λ)-labelled graph, then we perform the same construction by neglecting the labels belonging to K ∪ Λ that are attached to some constant symbols.

A converse construction

We need some notation and a lemma. Let (T, f ) be a rich tree-decomposition of an s-graph G. For every node u of the rooted tree T , we recall that T /u denotes the subtree of T issued from u, with N T /u = {w ∈ N T | w≤ T u}. We denote by G(u) the s-graph defined as follows. The graph

G(u) • is the subgraph of G • such that V G(u) • ∪ E G(u) • = {f (w) | w ∈ N T /u }. The sources of G(u) are those of G that belong to V G(u) • , i.e., slab G(u) = slab G V G(u) • . These sources belong to f (u) by the connectivity condition. Clearly, G(root T ) = G.
Lemma 2.78 Let (T, f ) be a tree-decomposition of width at most k -1 of an s-graph G and let C ⊆ A be a set of cardinality k such that τ (G) ⊆ C. There exists a coloring γ : V G → C that extends slab G and is injective on each box of the decomposition. Such a coloring can be determined in linear time in the size of T , i.e., in time O(|N T |).

Proof: Let G, C, T, f be as in the statement. Obviously, there is an injective mapping δ 0 : f (root T ) → C that extends slab G . We will prove that for every u ∈ N T the following holds:

Every injective mapping δ : f (u) → C can be extended into a map- ping γ : V G(u) → C that is injective on f (w) for each w in N T /u .
The proof is by bottom-up induction on u. If u is a leaf of T there is nothing to prove. Otherwise, let u 1 , . . . , u p be the sons of u. For each of them one can find an injective mapping δ i : f (u i ) → C that coincides with δ on f (u i ) ∩ f (u). By the induction hypothesis, it can be extended into γ i defined on V G(ui) . Then, the common extension γ of these mappings γ i and of the mapping δ is the desired coloring. This extension exists because if x ∈ N T /ui ∩ N T /uj , i = j, then x ∈ f (u i ) ∩ f (u) ∩ f (u j ) by the connectivity condition, and so γ i (x) = γ j (x) = δ(x).

For example, Figure 2.10 shows a rich tree-decomposition of width 2 that is colored with colors a, b, c. Boxes are numbered from 1 to 5, and 1 is the root.

It is routine work to construct a linear algorithm computing γ. Remark 2.79 Since the ends of any edge are in the same box, the mapping γ constructed by the proof of Lemma 2.78 is a proper (vertex) k-coloring, i.e., a coloring γ of V G using k colors such that γ(x) = γ(y) if x = y and x -y is an edge. However, this coloring is not optimal. The cycle C 6 is properly 2-colorable, however it has tree-width 2 and the above construction yields a coloring using three colors.

Definition 2.80 (The term representing a rich tree-decomposition) Let (T, f ) be a rich tree-decomposition of width at most k -1 of a concrete s-graph G. We let C ⊆ A be a set of cardinality k that contains τ (G). Let γ : V G → C be a vertex coloring of G that is injective on each box and is such that γ(x) = slab G (x) for every source x of G (Lemma 2.78).

For each u ∈ N T , we let G(u) be the s-graph

G(u) • , slab G(u) such that slab G(u) := γ (f (u) ∩ V G ). (This mapping slab G(u) extends slab G(u) because all vertices of f (u)∩V G are sources of G(u)). It follows then from the definitions that: G = fg C-τ (G) (G(root T )). (2.2)
By bottom-up induction on u, we construct for each u ∈ N T a term t(u) ∈ T (F HR C ) such that G(u) val (t(u)) and a ground witness of this fact. Let u have sons u 1 , . . . , u p , p ≥ 0; we can assume that we have already constructed t(u 1 ), . . . , t(u p ) and we have:

G(u) = fg B1 (G(u 1 )) • • • fg Bp (G(u p )) H(u) (2.3)
where the sets B i and the s-graph H(u) are defined as follows:

(1)

B i := {γ(x) | x ∈ f (u i ) -f (u)} for i = 1, . . . , p. 37
(2) H(u) := (H, slab) where H is the subgraph of G • such that V H ∪ E H = f (u) and slab := γ V H . To optimize the construction, the isolated vertices of H(u) that are in f (u 1 ) ∪ • • • ∪ f (u p ) can be removed, including their source names.

The s-graph H(u) has at most k vertices and a term t (u) in T (F HR C ) evaluating to it can be constructed by Proposition 2.33; a ground witness w of this fact is easy to determine (cf. the discussion after Proposition 2.44). Hence the term t(u) := fg B1 (t(u 1 ))

∈ V G(u) ∪ E G(u) : w(x) = h p+1 (w (x)) for x ∈ f (u), and
w(x) = h i (w i (x)) for i ∈ [p] and x ∈ (V G(ui) -f (u)) ∪ E G(ui) .
For the optimized construction the definition of w is slightly more complicated. By Equality 2.2, the term t := fg C-τ (G) (t(root T )) has value G. A witness w of this fact is easy to obtain from a witness w of G(root T ) val (t(root T )): if w(x) is (u, a) or u, then w(x) is defined as (u + 1, a) or u + 1, respectively. As observed after Definition 2.46, w can be converted in linear time into a canonical witness of G val (t).

This construction need not distinguish the cases of directed and undirected s-graphs because Proposition 2.33 covers both cases. The extension to labelled graphs is straightforward. It can also be obtained from Proposition 2.47(2).

Example 2.81 Consider the rich tree-decomposition of Figure 2.10. The vertices are colored by a, b, c. The optimized construction of Definition 2.80 gives the term: t = fg c a fg a (ab ac) bc fg a (ab ac) bc.

The full construction has a bc instead of bc (at its two occurrences). If the loop is in box f (1) (and not in box f (3) as shown in Figure 2.10), then the same (optimized) construction gives the term fg c (a fg a (ab ac) bc) fg a (ab ac) a bc.

Proposition 2.82

(1) Let C be a set of k source names. The construction of Definition 2.80 associates with every rich tree-decomposition (T, f ) of width at most k -1 of a concrete s-graph G of type included in C a term in T (F HR C ) (hence of width at most k) that evaluates to G, and a canonical witness of this fact. This construction can be done in linear time in the size of (T, f ), i.e., in time

O(|E G | + |N T |).
(2) For every (labelled) s-graph G, we have wd (G) ≤ twd (G) + 1.

Proof: The proof of ( 1) is straightforward by bottom-up induction on the node u of T , and ( 2) is an immediate consequence of (1).

Propositions 2.76 and 2.82 give the following theorem.

Theorem 2.83

(1) Let C ∈ P f (A). An s-graph G is the value of a term in T (F HR C ) if and only if τ (G) ⊆ C and twd (G) ≤ |C| -1. The corresponding terms (with witnesses) and tree-decompositions can be constructed from each other in linear time. The same result holds for (K, Λ)-labelled s-graphs and terms in T (F HR C,[K,Λ] ).

(2) For every ((K, Λ)-labelled) s-graph G, we have twd (G) = wd (G) -1.

Proof: If w is a witness of G val (t) and (T, f ) is the rich tree-decomposition of cval (t) obtained by Proposition 2.76 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF], then (T, w -1 For a given s-graph G, the source names in C -τ (G) are "auxiliary" and can be chosen arbitrarily. In particular, if τ (G) = ∅, then G has tree-width at most k -1 if and only if G = val (t) for some term t over F HR [k] .

Remarks 2.84

(1) The construction of Definition 2.80 does not use the source renaming operations ren h . For the purpose of defining s-graphs by terms, they are dispensable: not using them does not result in the necessity of augmenting the number of source names. We have already observed this fact in Proposition 2.49. In other words, the tree-width of an s-graph can be characterized as in Theorem 2.83 in terms of wd (G), where this width wd is relative to the subsignature of F HR C obtained by omitting the source renaming operations.

(2) In Definition 2.80, a term t(u) in T (F HR C ) (for some finite set C) is associated with each node u of T ; if u has sons u 1 , . . . , u p then Equality (2.3) can be rewritten G(u) = g(G(u 1 ), . . . , G(u p )) where g is the linear derived operation λx 1 , . . . , x p • fg B1 (x 1 ) • • • fg Bp (x p ) t (u). By Proposition 2.69 it is not a loss of generality to assume that the given tree-decomposition is binary, i.e., that p ≤ 2. With this assumption and for defining simple graphs, the number of different terms t (u) is finite and consequently, so is the number of different derived operations g for each fixed set C. Without the restriction to simple s-graphs, the s-graphs H(u) can have arbitrarily many edges and the set of derived operations g is countably infinite.

(3) Every term in T (F HR C ) written with the operations fg a (and not with the operations fg B ) that evaluates to a nonempty s-graph G has size at least

|Int G |+ 2 • (|E G | + |Isol G |
) -1 as one can check easily (cf. the proof of Proposition 2.33). This lower bound can be realized by such a term in T (F HR C ) with C of cardinality twd (G)+1. This term can be obtained by the construction of Proposition 2.82(1) from an optimal downwards increasing tree-decomposition. We omit the details. As an example, consider the term t of Example 2.81. It is (also) obtained from the optimal downwards increasing tree-decomposition that one gets from Figure 2.10 by removing box 3 and putting the loop in box 2.

(4) A set of s-graphs of tree-width at most k and of type included in a finite set C is a subset of the domain of the F HR C -algebra JS[C] and also of that of the F HR D -algebra JS gen [D] (cf. Remark 2.39( 1)) where D is any finite set that includes C and that has at least k + 1 elements.

(5) We recall from Section 1.4.2 that the series-composition G • H of two directed s-graphs of type [2] can be defined as a derived operation of JS, as follows: G • H = fg 3 (ren 2↔3 (G) ren 1↔3 (H)). It follows that every seriesparallel graph, as defined in Section 1.1.3, is the value of a term over F HRd [3] . Hence, by Theorem 2.83, series-parallel graphs have tree-width at most 2.

Conversely, the graphs of tree-width at most 2 and of type included in [2] are those generated by the signature F HR

[2] ∪ {•}. Moreover, by generalizing series-composition to a k-ary operation, we obtain a similar characterization for graphs of tree-width at most k. We let H k be the signature F HR [k] ∪ {S k } where S k is the generalized series-composition defined as follows:

S k (G 1 , . . . , G k ) := fg 0 (ren 0↔1 (G 1 ) • • • ren 0↔k (G k )).
Hence, S k is a derived operation defined with the help of the source label 0. It is intended to be used for s-graphs

G 1 , . . . , G k of type included in [k]. It is clear that G • H = S 2 (H, G) for G and H of type [2].
The signature H k generates the set of s-graphs of type included in [k] and of tree-width at most k. (The simple loop-free undirected graphs in this set are called partial k-trees, see [*Bod98] for details.) This fact is used in [ArnCPS], [CorRot] and [CouOla]. Apparently, the signature H k uses less source labels than F HR [k+1] to generate the same s-graphs of type included in [k], however, the definition of S k uses the source label 0 / ∈ [k].

Our next objective is to characterize s-graphs of bounded path-width as values of particular terms over F HR .

A term t over a signature F is slim if, for every subterm of t of the form f (t 1 , . . . , t k ), at most one of t 1 , . . . , t k is not a constant symbol. We will denote by Slim(F ) the set of slim terms over F . Proof: Let G be defined by a slim term t in T (F HR C ). This means that for every subterm of t of the form t 1 t 2 , the term t 1 or t 2 (or both) is of the form ab, -→ ab, a, a or ∅. Let T be the syntactic tree of t and (T, f ) be the rich treedecomposition of G constructed by Definition 2.75. If no node has outdegree 2, then (T, f ) is a path-decomposition and the result is proved.

Otherwise let u be a node of T with two sons u 1 and u 2 . It is an occurrence of , and one of the two sons, say u i , is an occurrence of a constant symbol. Note that f

(u i ) ∩ V G ⊆ f (u) ∩ V G .
By contracting the edge u → u i of T we obtain a tree-decomposition of G having the same width as (T, f ) and one less node of outdegree 2, cf. Remark 2.77(2). By repeating this step finitely many times, we obtain a path-decomposition of G of width at most k -1.

Let us assume conversely that (T, f ) is a path-decomposition of an s-graph G of width k -1. We apply the construction of Definition 2.80. Since T is a path-decomposition, we have p ≤ 1 at each occurrence u. Let t (u) = c 1 • • • c n for constant symbols c 1 , . . . , c n (the construction of Proposition 2.33 is applied with B = ∅). With the same notation as in Definition 2.80, we can write the term t(u) as:

t(u) = (• • • (((s c 1 ) c 2 ) c 3 ) • • • c n )
where s := ∅ if p = 0 and s := fg B1 (t(u 1 )) if p = 1.

The term t for G is then defined as t := fg C-τ (G) (t(root T )). It is a slim term (provided we write the parallel-compositions with parentheses as indicated).

For each finite set C, we let P HR C be the signature consisting of the constants ∅, ab, -→ ab, a, a for a, b ∈ C, a = b, of the unary operations ren a↔b for a, b ∈ C, a = b, the unary operations fg B for B ⊆ C, and the unary derived operations λx • x c where c is any of the above constant symbols except ∅. It follows from Proposition 2.85 that an s-graph G is the value of a term in T (P HR C ) if and only if τ (G) ⊆ C and pwd (G) ≤ |C| -1. We omit a detailed proof. Needless to say that the extension of the previous proposition to labelled s-graphs is straightforward.

Tree-decompositions and their algebraic expressions will be used in Chapter 6 for some algorithmic applications.

The VR algebra of simple graphs with ports

We define graph operations that generalize the complete join of two graphs used in Section 1.1.2 for defining cographs. These operations will provide us with another algebra of graphs that we will call the VR algebra because its equational sets (cf. Section 1.1.4) are those generated by the context-free Vertex Replacement graph grammars (see [*EngRoz] or [*Eng97]). These equational sets will be studied in Chapter 4. A graph complexity measure called cliquewidth is associated in a natural way with the definition of a graph by a term over the signature of the VR algebra. Taken as parameter, it yields fixed-parameter tractable algorithms for problems expressible in monadic second-order logic. In this section, we only consider simple, possibly labelled graphs. This restriction is due to the way edges will be defined.

The VR graph operations

A simple (directed) graph will be handled as a binary relation on a finite set of vertices38 , hence such a graph G will be defined as a pair V G , edg G consisting of a set of vertices V G and a binary relation edg G ⊆ V G × V G . This relation is symmetric if the graph is undirected. There is a loop incident with a vertex x if and only if (x, x) ∈ edg G . Undirected graphs are just particular (directed) graphs.

Definition 2.86 (Simple graphs with ports)

Let A be a fixed countable set of port labels with the same properties as in Definition 2.24 (in particular, N ⊆ A). A concrete graph with ports, or a concrete p-graph in short, is a pair

G = G • , port G consisting of a concrete simple (directed) graph G • and a mapping port G : V G • → A. A vertex x is an a-port of G if port G (x) = a.
We denote by π(G) the set port G (V G ) (we denote V G • also by V G , and similarly for other notations). The set of port labels π(G) is called the type of G, like τ (G) in the HR algebra.

Let G and H be concrete p-graphs. We say that G is a

subgraph of H if G • is a subgraph of H • and port G is the restriction of port H to V G (so that π(G) ⊆ π(H)). An isomorphism : G → H is a bijection h : V G → V H such that for every u, v in V G we have (h(u), h(v)) ∈ edg H if and only if (u, v) ∈ edg G ,
and port H (h(u)) = port G (u). Since these graphs are simple, isomorphisms between them can be specified by bijections between their vertex sets only (cf. Definition 2.10) and these bijections must preserve the vertex labellings defined by the port mappings (cf. Definition 2.11). We obtain thus the notion of an abstract p-graph.

Every simple graph will be considered as a p-graph, all vertices of which are a-ports for some fixed default label a, usually 1.

We now define operations on concrete and abstract p-graphs. We denote by GP the class of abstract p-graphs and by GP u the class of undirected abstract pgraphs. In the sequel, the term "abstract" will be omitted, except for emphasis.

Definition 2.87 (Operations on p-graphs) We define a signature of graph operations on GP that we will denote by F VR .

Disjoint union. For disjoint concrete p-graphs G and H, we let G ⊕ H be the graph G • ∪ H • equipped with the port mapping port G⊕H := port G ∪ port H . If G and H are not disjoint, we replace them by disjoint isomorphic copies. In this way, we obtain a well-defined binary operation on (abstract) p-graphs. Clearly

π(G ⊕ H) = π(G) ∪ π(H). Edge addition. Let a, b ∈ A, with a = b. For every concrete p-graph G, we let --→ add a,b (G) be the p-graph G such that V G := V G , edg G := edg G ∪ {(x, y) | x, y ∈ V G , port G (x) = a, port G (y) = b} and port G := port G .
This operation is well defined for all concrete p-graphs, and obviously for p-graphs as well.

Clearly π( --→ add a,b (G)) = π(G). Note that --→ add a,b (G) = G if a or b does not belong to π(G)
, or if there are already edges from every a-port to every b-port.

For adding undirected edges, we use add a,b (G) defined as --→ add b,a ( --→ add a,b (G)). Hence add a,b is a derived operation of the algebra we are defining. However, to allow an easy description of undirected p-graphs, it is more convenient to consider add a,b as a basic operation. Note that add a,b and add b,a are two function symbols with the same associated operation. We also have π(add a,b (G)) = π(G). None of these operations creates loops. Loops can be specified by constant pgraphs defined below.

Port relabelling. If h :

A → A is a mapping that is the identity outside of a finite subset of A, then we let relab h be the unary operation such that

G = relab h (G) if V G := V G , edg G := edg G and port G := h • port G .
This operation is well defined for concrete as well as for abstract p-graphs and π(relab h (G)) = h(π(G)).

A particular case deserves an easier notation. For a, b ∈ A, a = b, we let relab a→b denote relab h where h : A → A is defined by h(a) = b and h(c) = c for every c ∈ A, c = a. We call this operation an elementary relabelling. We have

relab a→b (G) = G if a / ∈ π(G). Furthermore relab h • relab h = relab h•h
for all mappings h, h . We can thus express as a single operation relab h a composition of elementary relabellings relab a1→b1 • relab a2→b2 • • • • • relab a k →b k , and viceversa.

For C ⊆ A and a mapping h : C → A that is the identity outside of a finite subset of C (which holds in particular if C is finite), we also denote by relab h the operation relab h where h agrees with h on C and is the identity outside of C. For each set C ⊆ A, we denote by [C → C] f the set of mappings h : C → C such that h is the identity outside of a finite subset of C.

Basic graphs. We let the constant symbols a and a denote p-graphs with a single vertex that is an a-port, and for the second, that also has an incident loop. It will be useful for some constructions to have also the symbol ∅ to denote the empty graph. We will see that every term denoting a nonempty p-graph can be replaced by an equivalent one not using ∅.

The VR algebra of p-graphs. We obtain thus a countably infinite (but effectively given) signature:

F VR := {⊕, --→ add a,b , add a,b , relab h , a, a , ∅ | a, b ∈ A, a = b, h ∈ [A → A] f }
and, for dealing with undirected graphs, its subsignature:

F VRu := {⊕, add a,b , relab h , a, a , ∅ | a, b ∈ A, a = b, h ∈ [A → A] f }.
We let GP denote the F VR -algebra with domain GP. It is effectively given. We call GP the VR algebra, and we denote by GP u its subalgebra with domain GP u and the operations of F

( --→ add 3,1 ( --→ add 1,2 (1 ⊕ 1 ⊕ 2) ⊕ 1 ⊕ 3 )).
(2) For each n ≥ 1, the clique K n with all vertices being 1-ports is the value of the term t n defined inductively by: t (3) The mapping that associates the complete join G ⊗ H with two graphs G and H (two p-graphs of type {1}) is the derived operation t GP defined by the term t := relab 2→1 (add 1,2 (x 1 ⊕relab 1→2 (x 2 ))) that belongs to T (F VRu [2] , {x 1 , x 2 }). It follows that cographs (see Section 1.1.2) can be defined by terms in T ({⊕, add 1,2 , relab 1→2 , relab 2→1 , 1}). The set of cographs C is thus defined by the equation:

1 := 1, t n+1 := relab 2→1 (add 1,2 (t n ⊕ 2)) for each n ≥ 1.
C = (C ⊕ C) ∪ t GP (C, C) ∪ {1}.
We have already presented such definitions in Sections 1.1.2 and 1.4.1, and we will consider them in more detail in Chapter 4.

(4) We now consider rooted trees. We let the root of a rooted tree T be a 1-port and all the other nodes be 2-ports. The type of a rooted tree T is {1} or {1, 2}. If T is the union of pairwise disjoint rooted trees T 1 , . . . , T p augmented with a new node r that is the root of T , and with edges from r to the roots of T 1 , . . . , T p , then we have:

T = relab 3→1 (relab 1→2 ( --→ add 3,1 (3 ⊕ T 1 ⊕ • • • ⊕ T p ))).
It follows that rooted trees are defined by the system of two equations:

Σ Trees S = {1} ∪ relab 3→1 (relab 1→2 ( --→ add 3,1 (3 ⊕ F ))) F = S ∪ (F ⊕ S).
This system defines the set S of rooted trees and the set F of nonempty rooted forests.

Definition 2.89 (Clique-width)

The clique-width of a p-graph G is the minimal cardinality of a set C such that G is the value of a term in T (F VR C ). (We generalize the definition given for graphs in Section 1.4.1). It is denoted by cwd (G). A term t ∈ T (F VR C ) with |C| = cwd (G) is called an optimal clique-width term for G.

It is easy to check that the clique-width of an undirected p-graph is the minimal cardinality of a set C such that this graph is the value of a term in T (F

(G • ), port G with und (G • ) = V G , edg G ∪ edg -1
G . Since the type of val (t) is included in C for every term t in T (F VR C ), every p-graph G has clique-width at least |π(G)|. By a proof similar to the one of Proposition 2.33 (see Proposition 2.104(1) below), we obtain that every pgraph is the value of a term in T (F VR C ) for every set C such that π(G) ⊆ C and |C| = |V G |. Hence the algebra GP is generated by its signature F VR , and every p-graph G has clique-width at most |V G |. More precise results will be given in Section 2.5.4. 39If a p-graph G is the value of a term t in

F VR C and h ∈ [A → A] f is injective on C, then relab h (G) = val (t ) for some term t ∈ T (F VR h(C) )
; this term is obtained from t by replacing every port label a of C by h(a). If, in particular, h is the identity on π(G), then G = val (t ). This can be used to prove the following easy analogue of Theorem 2.83(1): a p-graph G is the value of a term in T (F VR C ) if and only if π(G) ⊆ C and cwd (G) ≤ |C|. (For the proof of this fact, the only-if direction is clear; for the if-direction, let G = val (t) for some t ∈ T (F VR D ) with

|D| ≤ |C|. Choose some h ∈ [A → A] f with h(D) ⊆ C that is injective on D and is the identity on π(G) ⊆ D. Then G = val (t ) and t ∈ T (F VR C ).) In particular, if G is a graph (i.e., π(G) = {1}), then G has clique-width at most k if and only if G = val (t) for some term t over F VR [k]
. The clique-width cwd (L) of a set of p-graphs L is the least upper-bound (possibly ω) of the integers cwd (G) for G ∈ L. We say that L has bounded clique-width if cwd (L) ∈ N . The class of all graphs has unbounded cliquewidth: this fact follows from the exact characterization of the clique-width of square grids in Proposition 2.106 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF], and also by a different proof based on Corollary 2.122 and using a counting argument.

The linear clique-width of a p-graph G is the minimal cardinality of a set C such that G is the value of a slim term in T (F VR C ). It is denoted by lcwd (G). The notion of linear clique-width is thus similar to that of path-width, characterized in Proposition 2.85 by means of slim terms over F HR C . The linear clique-width of a set of p-graphs is the least upper-bound of the linear clique-widths of its elements.

Linear clique-width is to clique-width what path-width is to tree-width. It plays a central role in the NP-completeness proof ( [FelRRS]) of the Clique-Width Checking Problem, i.e., of the problem of checking that cwd (G) ≤ k for given (G, k).

Definition 2.90 (Labelled graphs with ports)

We let K and Λ be two finite, disjoint, sets of labels such that (K ∪ Λ) ∩ A = ∅, and we let GP [K,Λ] be the set of simple 40 directed [K, Λ]-labelled graphs equipped with port labels, called [K, Λ]-labelled p-graphs. In a [K, Λ]-labelled p-graph, each edge has one and only one label in Λ and each vertex has, in addition to its port label in A, a possibly empty set of labels from K. Hence, we extend Definition 2.11 to graphs with ports (as we did in Definition 2.32 for graphs with sources). We will apply to [K, Λ]-labelled p-graphs the disjoint union ⊕ and the relabelling operations relab h , generalized from Definition 2.87 to GP [K,Λ] in the obvious way, and edge addition operations that depend on edge labels: for every λ ∈ Λ and a, b ∈ A with a = b, we define an operation --→ add a,b,λ that adds λ-labelled edges from every a-port x to every b-port y (if a λ-labelled edge already exists from x to y, then no other edge is added between these vertices).

We also define new constant symbols (in addition to ∅). For M ⊆ K ∪ Λ and a ∈ A, the constant symbol a M denotes the p-graph with a single vertex that is an a-port, has label κ for each κ ∈ K ∩ M and an incident λ-labelled loop for each λ ∈ Λ ∩ M . Hence a ∅ defines the same p-graph as a, and a {ι} defines the same p-graph as a if ι is taken as default edge label.

The operations ⊕, relab h and --→ add a,b,λ do not modify the labels from K and Λ once they have been specified for a vertex or a loop by some constant a M or, for an edge that is not a loop, at the moment of its introduction by an operation --→ add a,b,λ .

We denote the corresponding signature by F VR [K,Λ] and its restriction to operations using port labels in C by F VR C, [K,Λ] . The clique-width of a [K, Λ]-labelled p-graph G is defined as the minimal cardinality of a set C of port labels such that G is the value of a term over F VR C, [K,Λ] . Specialized definitions for undirected41 p-graphs, and linear clique-width are straightforward to set up.

Example 2.91 Let G be the (∅, {λ, µ})-labelled graph with vertex set {1, 2, 3, 4}, λ-labelled edges 2 → 1, 2 → 3, 4 → 3 and µ-labelled edge 4 → 1. It is the value of the term

relab h ( --→ add 2,1,λ ( --→ add 2,3,λ ( --→ add 4,3,λ ( --→ add 4,1,µ (1 ⊕ 2 ⊕ 3 ⊕ 4)))))
where h(i) = 1 for every i ∈ [4]. Its clique-width is thus at most 4 and is actually 4, as one checks by trying all possibilities of constructing this graph by a term in T (F VR [3],[∅,{λ,µ}] ); in fact, only finitely many possibilities need to be tried, see the last paragraph of Section 2.5.3 below. If we make labels λ and µ identical then the clique-width of the resulting graph is only 2. It is the value

of relab 2→1 ( --→ add 1,2,λ (2 ⊕ 1 ⊕ 2 ⊕ 1)).

Construction of the p-graph defined by a term

Our aim is to construct from a term t ∈ T (F VR ) a concrete p-graph isomorphic to val (t), and to define a notion of witness of G val (t), where G is a concrete graph, as we did in Definition 2.43 for terms in T (F HR ). Fortunately, the definitions and constructions will be much simpler because, when G val (t), we have a bijection from V G to the set Occ 0 (t) of occurrences in t of constant symbols different from ∅. A witness of G val (t) will be such a bijection w, satisfying some conditions ensuring that w is an isomorphism between G and val (t). No quotient graph will be needed.

Definition 2.92 (Terms denoting concrete p-graphs) For every a ∈ A (the countable set of port labels) and every x ∈ U (the universal set of vertices, see Definition 2.9) we let a(x) and a (x) denote the concrete pgraphs with vertex x that is an a-port, and also has an incident loop in the second case.

We let F cVR 0 := {a(x), a (x), ∅ | a ∈ A, x ∈ U} and F cVR be the signature obtained by replacing in F VR the set of constant symbols F VR 0 by F cVR 0 . A constant symbol a(x) or a (x) describes the vertex x. We obtain a new signature F cVR (and its variants F cVR C , F cVRu C , etc.), where the superscript 'c' stands for "concrete".

Not every term T (F cVR ) defines a concrete p-graph because for concrete p-graphs G and H, G ⊕ H is well defined only if V G ∩ V H = ∅. (However f (G) is well defined for every unary operation f in F VR .) We now formalize this observation. Let t ∈ T (F cVR ). Two occurrences of constant symbols are conflicting if they describe the same vertex. The value of a term t ∈ T (F cVR ) is the concrete p-graph denoted by cval (t) defined as follows:

cval (t) is a(x), a (x) or ∅ if t is a(x), a (x) or ∅ respectively 42 cval (t) := f (cval (t 1 )) if t = f (t 1 ), cval (t) := cval (t 1 ) ⊕ cval (t 2 ) if t = t 1 ⊕ t 2 and V cval(t1) ∩ V cval(t2) = ∅, otherwise cval (t) is undefined.
Hence V cval(t) is the set of vertices x that are described by the constant symbols occurring in t. Note in particular that if cval (t) is defined and u and v are two positions in t that are incomparable with respect to ≤ t , then the pgraphs cval (t/u) and cval (t/v) are disjoint43 . The next lemma can be proved by induction on the structure of t.

Lemma 2.93 For every term t over F cVR , the concrete p-graph cval (t) is defined if and only if no two occurrences of constant symbols in t are conflicting. If cval (t) is defined, its vertex set is the set of vertices described by the constant symbols.

We define concrete p-graphs that are values of terms over F VR . Let t be such a term and w be a bijection : V → Occ 0 (t) where V is a finite subset of U, the universal set of vertices, and as before, Occ 0 (t) is the set of occurrences in t of constant symbols different from ∅. We define the term t w in T (F cVR ) by replacing in t at each occurrence u of a constant symbol a or a this symbol by a(w -1 (u)) or a (w -1 (u)) respectively. Clearly, this term has no conflicting occurrences, hence cval (t w ) is a concrete p-graph G such that V G = V and G val (t). (Here, val (t) is the abstract p-graph that is the value of t.) In particular, we can take V := Occ 0 (t) and w equal to the identity function on Occ 0 (t), denoted by Id . Thus, the set of vertices of cval (t Id ) is Occ 0 (t). We will also denote cval (t Id ) by cval (t); moreover, for every u ∈ N t , we will also denote cval (t Id /u) by cval (t)/u. 44If a concrete p-graph G is isomorphic to val (t) for a term t in

T (F VR C ), then G = cval (t ) for some term t ∈ T (F cVR C ): if w is an isomorphism from G to cval (t Id ), then G = cval (t w ) as one checks easily. Hence, a concrete p-graph G is the value of a term in T (F cVR C ) if and only if [G] iso is the value of a term in T (F VR C ).
Our next aim is to describe the concrete p-graph cval (t) = cval (t Id ), for t in T (F VR ). We need auxiliary definitions.

Definition 2.94 (Ports of p-graphs defined by subterms) Let t belong to T (F VR ) and Syn(t) be its syntactic tree. The set of nodes of Syn(t), denoted by N t , is Pos(t). We recall that lab t (u) = f if and only if u ∈ Occ(t, f ). If u ∈ N t , then Syn(t)/u, the subtree of Syn(t) issued from u, is isomorphic to the syntactic tree of the subterm t/u of t. The vertex set of the (concrete) p-graph cval (t)/u is Occ 0 (t) ∩ N t /u = {x ∈ Occ 0 (t) | x ≤ t u}. For u ∈ N t and x ∈ Occ 0 (t) such that x ≤ t u (which means that x is below u in Syn(t)), we define: port t (u, x) := port cval(t)/u (x).

Hence, if G = cval (t), then V G = Occ 0 (t) and port G (x) = port t (root t , x) for every x ∈ Occ 0 (t). The following is clear from the definitions.

Lemma 2.95 The partial function port t : N t × Occ 0 (t) → A satisfies the following properties:

1. if x = u, then port t (u, x) = a where lab t (x) is a or a , 2. if x < t u and u is the son of u such that x ≤ t u < t u, then we have:

port t (u, x) = port t (u , x) if lab t (u) ∈ {⊕, add a,b , --→ add a,b } h(port t (u , x)) if lab t (u) = relab h .
The second case of this lemma can be written as follows:

port t (u, x) = (h 1 • h 2 • • • • • h n )(port t (x, x))
where h 1 , h 2 , . . . , h n is the sequence of mappings that define relabellings on the path in Syn(t) from u to x.

Lemma 2.96 Let t ∈ T (F VR ) and let G be the concrete p-graph cval (t) with vertex set Occ 0 (t). The edges of G are the pairs (x, y) in Occ 0 (t) × Occ 0 (t) such that either x = y and lab t (x) = a (for some a ∈ A) or x = y and there exists u in N t with lab t (u) ∈ {add a,b , add b,a , --→ add a,b }, x ≤ t u, y ≤ t u, port t (u, x) = a and port t (u, y) = b (for some a, b ∈ A).

Proof: Let t and G be as in the statement. One can prove by bottom-up induction on u that, for every u in N t , the relation edg cval(t)/u is the set of pairs (x, y) such that either x = y, x ≤ t u and lab t (x) = a , or x = y and there exists u in N t with u ≤ t u and lab t (u ) ∈ {add a,b , add b,a , --→ add a,b }, x ≤ t u , y ≤ t u , port t (u , x) = a and port t (u , y) = b. Taking u = root t the result is obtained.

In Section 7.2 we will use these two lemmas to prove that the mapping val from terms over F VR to p-graphs is a monadic second-order transduction. (Proposition 2.41 will be used in a similar way in Section 7.4 for terms over F HR .) Definition 2.97 (Witnesses) Let G be a concrete p-graph and t ∈ T (F VR ). A witness of G val (t) is a bijection w : V G → Occ 0 (t) satisfying the following conditions:

(1) edg G is the set of pairs (x, y) in V G × V G such that either x = y and lab t (w(x)) = a (for some a ∈ A) or x = y and there exists u in N t with lab t (u) ∈ {add a,b , add b,a , --→ add a,b }, w(x) ≤ t u, w(y) ≤ t u, port t (u, w(x)) = a and port t (u, w(y)) = b (for some a, b ∈ A), and

(2) port G (x) = port t (root t , w(x)) for all x ∈ V G .

Proposition 2.98 Let G be a concrete p-graph and t a term over F VR . Then G val (t) if and only if there exists a witness of G val (t).

Proof: By Lemma 2.96, a witness of G val (t) is an isomorphism from G to cval (t). 45 Since cval (t) val (t), the result follows.

The above definitions and results on the construction of concrete p-graphs from terms extend to labelled p-graphs and to the terms that define them in a straightforward way.

Definition 2.99 (Parsing)

The parsing problem relative to the VR algebra is defined as follows:

Input: Finite pairwise disjoint sets C of port labels, K of vertex labels, Λ of edge labels and a concrete (K, Λ)-labelled p-graph G of type included in C.

Output:

A term t in T (F VR C,[K,Λ]
) and a witness of G val (t) if they exist, or the answer that they do not exist.

Efficient algorithms for this problem are more difficult to build than for parsing relative to the HR algebra. We will discuss them in Section 6.2.

The proof of the following proposition is similar to that of Proposition 2.47 (but easier: it suffices to replace constant symbols).

Proposition 2.100

(1) Let be given a concrete p-graph G, a term t in T (F VR C ) and a witness w of G val (t). Let γ be a labelling function turning G into a (K, ∅)labelled p-graph G. In linear time (for fixed C and K), we can compute

t ∈ T (F VR C,[K,∅]
) that evaluates to G, such that w is a witness of this fact.

(2) A similar result holds for deleting or adding loops, or modifying their labels, and for modifying vertex labels.

Proposition 2.47 is similar for s-graphs and the HR algebra, but here we cannot add edge labels or reverse edge directions. Examples showing that will be given in Section 2.5.4.

Algebraic properties and derived operations defined by contexts

The results of this section are analogous to those of Section 2.3.3 relative to the HR algebra. We define some notation. If (f i ) i∈I is a finite family of unary total functions on some set that commute pairwise, i.e., are such that f i • f j = f j • f i for every i, j in I, then we denote by i∈I f i their composition in any order (if I = ∅, it denotes the identity on the set). The resulting operation is the same for every order of composition.

The following proposition is stated for labelled p-graphs; its proof is an easy verification from the definitions.

Proposition 2.101 For all (K, Λ)-labelled p-graphs G, H, J, all mappings h, h in [A → A] f , all a, b, c, d in A with a = b, c = d, all λ, µ in Λ, and all subsets M of K ∪ Λ, we have:

(1) G ⊕ H = H ⊕ G, (2) G ⊕ (H ⊕ J) = (G ⊕ H) ⊕ J, (3) G ⊕ ∅ = G, (4) relab h (relab h (G)) = relab h•h (G), (5) relab h (G ⊕ H) = relab h (G) ⊕ relab h (H), (6) relab h (∅) = ∅, (7) relab Id (G) = G, where Id is the identity on A, (8) relab h (a M ) = c M if c = h(a), (9) --→ add a,b,λ ( --→ add c,d,µ (G)) = --→ add c,d,µ ( --→ add a,b,λ (G)), (10) --→ add a,b,λ (G ⊕ H) = --→ add a,b,λ ( --→ add a,b,λ (G) ⊕ H), (11)
--→ add a,b,λ (∅) = ∅, (12) --→ add a,b,λ (relab h (G)) = relab h (( a ∈h -1 (a),b ∈h -1 (b) --→ add a ,b ,λ )(G)), (13) --→ add a,b,λ (c M ) = c M .
Equalities ( 9) -(13) hold with add instead of --→ add .

Some further equalities can be derived from those of this proposition. In particular we have, for unlabelled p-graphs:

(10 ) --→ add a,b ( --→ add a,b (G)) = --→ add a,b (G)
by letting H = ∅ in (10) and by using (3), and

(9 ) add a,b (G) = add b,a (G) by (9) since add a,b (G) is defined as --→ add b,a ( --→ add a,b (G)). If h is injective, then (12)
can be rewritten into:

(12 ) relab h ( --→ add a,b (G)) = --→ add h(a),h(b) (relab h (G)).
Equality (7) states that relab Id denotes the identity, and could have been omitted. (We made a similar remark after Proposition 2.48.)

Conditional equalities can be formalized as equalities in the many-sorted setting of Section 2.6.3. We can cite in particular:

(14) relab h (G) = relab h (G) if h and h agree on π(G), (15) --→ add a,b (G) = G if a / ∈ π(G) or b / ∈ π(G), (16) --→ add a,b (G ⊕ H) = --→ add a,b (G) ⊕ H if a / ∈ π(H) and b / ∈ π(H).
If t, t belong to T (F VR C,[K,Λ] , X n ) and t is obtained from t by using the rules of Proposition 2.101, then t and t are equivalent, i.e., they define the same derived operation of GP or the same labelled p-graph if n = 0. For transforming, conversely, two equivalent terms in T (F VR C,[K,Λ] , X n ) one into the other, conditional rewriting rules (or rules with terms in the many-sorted signature of Section 2.6.3) seem necessary. The questions raised after Proposition 2.48 for the signature F HR can also be raised for F VR .

Corollary 2.102 Every term in T (F VR C,[K,Λ] ) that denotes a nonempty labelled p-graph is equivalent to a term in T (F VR C,[K,Λ] -{∅}).

Proof: Let t be a term containing occurrences of ∅. By using rules (1), (3), ( 6) and (11) of Proposition 2.101, we can transform t into an equivalent term t that is ∅ or has no occurrence of ∅. The first case is excluded since val (t) is not the empty graph. These transformations do not introduce new port labels, hence

t ∈ T (F VR C,[K,Λ] ) if t ∈ T (F VR C,[K,Λ] ).
As we did in Section 2.3.3 for the HR algebra, we will express in a concise way the unary derived operations defined by contexts. If C is a finite set of port labels and R ⊆ C × C, we denote by ADD R the derived operation (a,b)∈R,a =b --→ add a,b .

In the (K, Λ)-labelled case we define ADD R := (a,b,λ)∈R,a =b --→ add a,b,λ for R ⊆ C × C × Λ. It is well defined because the result does not depend on the order of composition by Equality (9) of Proposition 2.101. Note that Equality (12) of that proposition can now be formulated as follows:

-

-→ add a,b,λ (relab h (G)) = relab h (ADD R (G)) with R = h -1 (a) × h -1 (b) × {λ}.
The next result is stated for the unlabelled case.

Proposition 2.103 Let B be a finite set of port labels and let c ∈ Ctxt(F VR B ). There exist a set C of port labels with

C ∩ B = ∅ and |C| ≤ |B| • 2 2|B| , a term t over F VR B∪C with π(t GP ) ⊆ C, a relation R ⊆ (B × B) ∪ (C × B) ∪ (B × C) and a mapping h : B ∪ C → B such that, for every p-graph G with π(G) ∩ C = ∅, we have c GP (G) = relab h (ADD R (G ⊕ t GP )). If c is written without ⊕, then C = ∅ and t = ∅.
Proof: We will use x 1 as special variable in contexts. For convenience, we will write c(G) instead of c GP (G).

We first consider the ⊕-free case, i.e., the case where c is written without ⊕. By using Equalities (4), ( 9) and (12) of Proposition 2.101 and the derived equality (10 ), we can transform c into an equivalent context of the form relab h (ADD R (x 1 )). For doing this we need not introduce new port labels, hence C = ∅ and so R ⊆ B × B and h : B → B. The transformation can be done in linear time for fixed B.

We now consider the case where c contains at least one ⊕. In this case we let C := B × P(B) × P(B). 46 We define

R C ⊆ (C × B) ∪ (B × C) by R C := {((b, A, A ), a) ∈ C × B | a ∈ A} ∪ {(a, (b, A, A )) ∈ B × C | a ∈ A }, and we define h C : C → B such that h C (b, A, A ) := b for every (b, A, A ) ∈ C. Thus, if G and H are p-graphs with π(G) ∩ C = ∅ and π(H) ⊆ C, then ADD R C (G ⊕ H) is obtained from G ⊕ H
as follows: for every x ∈ V H , with port H (x) = (b, A, A ), edges are added from x to every y ∈ V G with port G (y) ∈ A, and edges are added from every y ∈ V G with port G (y) ∈ A to x; note that b is irrelevant.

By the ⊕-free case, it suffices to prove that there exist a context c ∈ Ctxt(F VR B ) that is written without ⊕ and a term t ∈ T ( We prove the existence of c and t by induction on the structure of c. We will also write s instead of s GP for a term s over F VR .

F VR B∪C ) with π(t GP ) ⊆ C such that c(G) = relab h C (c (ADD R C (G ⊕ t GP ))) for every p-graph G with π(G) ∩ C = ∅. In fact, if c = relab h (ADD R (x 1 )), with R ⊆ B × B and h : B → B, then R := R ∪
(1) If c = x 1 , then we take c := x 1 and t := ∅. This is correct because 14) and (15) after Proposition 2.101.

relab h C (ADD R C (G)) = G if π(G) ∩ C = ∅, cf. Equalities (
(

) If c = c 1 ⊕ s where c 1 ∈ Ctxt(F VR B ) and s ∈ T (F VR B ), then there are c 1 and t 1 such that c 1 (G) = relab h C (c 1 (ADD R C (G ⊕ t 1 ) 2
)) for every p-graph G with π(G) ∩ C = ∅, by the induction hypothesis. For c we take c := c 1 and t := t 1 ⊕ relab j (s) where j :

B → C maps each a ∈ B to (a, ∅, ∅) in C. Then c 1 (ADD R C (G ⊕ t 1 ⊕ relab j (s))) = c 1 (ADD R C (G ⊕ t 1 )) ⊕ relab j (s)
, by the fact that for all p-graphs J, K and every unary operation f ∈ F VR D , we have 5), ( 14) and ( 16) of Proposition 2.101. Applying relab h C to both sides of the equality, we obtain the required equality for c(G) by Equality (5) of Proposition 2.101 and by the fact that relab h C (relab j (s)) = s.

f (J ⊕ K) = f (J) ⊕ K if π(K) ∩ D = ∅, cf. Equalities (
(3) If c = relab g (c 1 ) and c 1 , t 1 are obtained from the induction hypothesis, then we can take c := relab g (c 1 ) and t := relab g (t 1 ), where g : C → C applies g to the first component of the port labels in C, i.e., g(a, A, A ) := (g(a), A, A ). Indeed, c(G) = relab g (relab h C (c 1 (ADD R C (G ⊕ t 1 )))) by the induction hypothesis and that clearly equals relab h C (relab g (c 1 (ADD R C (G ⊕ relab g (t 1 ))))).

:= relab k (ADD S (t 1 )). We have c(G) = --→ add a,b (relab h C (c 1 (ADD R C (G ⊕ t 1 )
))) by the induction hypothesis and that clearly equals

relab h C ( --→ add a,b (ADD T (c 1 (ADD R C (G ⊕ ADD S (t 1 ))))
)) where T is the set of all pairs ((a, A, A ), b) and (a, (b, D, D )) with A, A , D, D ⊆ B. By Equalities (9) and (12) of Proposition 2.101, this equals

relab h C ( --→ add a,b (c 1 (ADD R C (ADD T (G ⊕ ADD S (t 1 ))))
)) where T consists of all pairs ((a, A, A ), d) with d ∈ g -1 1 (b) and all pairs (d, (b, D, D )) with d ∈ g -1 1 (a). From this it should be clear that

ADD R C (ADD T (G ⊕ ADD S (t 1 ))) = ADD R C (G ⊕ relab k (ADD S (t 1 )))
and so we obtain that

c(G) = relab h C ( --→ add a,b (c 1 (ADD R C (G ⊕ relab k (ADD S (t 1 ))))
)) which proves the result.

We finally note that it follows from the above proof that c and a concrete p-graph H isomorphic to t GP can also be defined directly from c as follows. Let u be the occurrence of

x 1 in c. First, c = f p (• • • f 2 (f 1 (x 1 )) • • • ) where f 1 , f 2 , .
. . , f p are the unary operations that occur in this order on the path in Syn(c) from u to the root. Second,

H • = cval (c[∅]) • , cf. Section 2.5.2. Third, for each vertex x of H, we have port H (x) = (port cval(c[∅]) (x), A(x), A (x)), where A(x) (resp. A (x)) is the set of all b ∈ B such that there is an edge x → u (resp. u → x) in the concrete p-graph cval (c[b]), cf. Section 2.5.2.
The result extends to (K, Λ)-labelled graphs and the corresponding terms with |C| ≤ |B| • 2 2|Λ|•|B| because we need sets similar to A and A for each edge label.

We can now show that there is an algorithm to determine whether or not a p-graph G has clique-width at most k, for given G and k. The algorithm has to find out whether there exists a term over F ) is written without ⊕ and s ∈ T (F VR C ), then |c| ≤ k 2 -k + 2 (because such a subterm can be replaced by relab h (ADD R (s)) for some h and R). Since there are only finitely many terms satisfying both conditions, the algorithm can just check them all. The number of terms is exponential in the number of vertices of G (see Corollary 2.122 below). This problem is discussed in more detail in Section 6.2.

Properties of clique-width

We review some properties of clique-width and give some examples.

Proposition 2.104 For every labelled p-graph G, we have:

(1) |π(G)| ≤ cwd (G) ≤ |V G |, (2) if G is undirected, unlabelled and without ports (i.e., π(G) is singleton), then cwd (G) ≤ |V G | -k where k is the largest integer such that 2 k < |V G | -k.
Proof: [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] This fact is similar to Remark 2.55(c). As observed before, |π(G)| ≤ cwd (G) because π(val (t)) ⊆ C for every t ∈ F VR C . For showing that cwd (G) ≤ |V G | we let G be unlabelled to simplify the proof. Let C be a set of port labels that contains π(G) such that there exists a bijection k : V G → C. For each x in V G we let c(x) be the constant a(x) (resp. a (x)) if a = k(x) and x has no loop (resp. if a = k(x) and x has a loop), cf. Definition 2.92. We let

R := {(a, b) | a, b ∈ C and (k -1 (a), k -1 (b)) ∈ edg G }. We let h : C → π(G) be such that h(a) = port G (k -1 (a)). Then we have G = relab h (ADD R (c(x 1 ) ⊕ • • • ⊕ c(x n )))
where V G = {x 1 , . . . , x n } (and ADD R is defined before Proposition 2.103).

The construction for (K, Λ)-labelled p-graphs is essentially the same. The constants a M (x) specify the labels of a vertex x with port label a, the loops incident to it and their labels. Each edge addition operation adds a unique edge with its label. Hence, the same number of port labels is used as for an unlabelled graph.

(2) This result is proved in [Joha].

The following results are useful for giving upper-and lower-bounds to the clique-width of particular p-graphs. We recall from Definition 2.12 that

H ⊆ i G means that H = G[V H ], i.e.
, that H is an induced subgraph of G (with the same labels for its vertices and edges as in G). If G is a labelled p-graph, we let core(G) be the unlabelled, loop-free and undirected p-graph core(G • ), port G ; for the core of a graph, see Definition 2.9.

We generalize as follows the edge-complement G of a simple, loop-free, undirected graph G defined in Example 1.30. If G is a concrete (K, Λ)-labelled p-graph, then we let G be the p-graph with the same vertices, port labels and vertex labels as G; it has an edge x → y labelled by λ (possibly a loop, if x = y) if and only if G has no such edge. If G is undirected, loop-free and unlabelled, then, apart from loops and port labels, we have G = G (we recall that an undirected edge is a pair of opposite directed edges).

The next proposition should be compared with Remark 2.55(d) and Corollary 2.60 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF].

Proposition 2.105 (1) If H ⊆ i G, then cwd (H) ≤ cwd (G).
(2) The addition and deletion of loops, the modification of vertex labels and of labels of loops do not modify the clique-width of a p-graph.

(3) For every p-graph G, we have cwd (core(G)) ≤ cwd (G).

(4) For every (K, Λ)-labelled p-graph G, we have cwd

( G) ≤ 2 • cwd (G). Proof: (1) Let H, G be concrete (K, Λ)-labelled p-graphs such that H ⊆ i G. We let G = cval (t Id ) with t ∈ T (F VR C,[K,Λ]
), cf. Definition 2.92. We have that V G = Occ 0 (t) and Id is the identity on V G . The p-graph H is obtained from G by removing some vertices and their incident edges. For every x ∈ V G -V H , we replace in t Id the constant symbol a M (x) which specifies vertex labels (in K), loops and their labels (in Λ) by the constant symbol ∅ (which denotes the empty graph). We obtain a term t Id where t ∈ T (F VR C,[K,Λ] ) and Id is the identity on V H = Occ 0 (t ), the value of which is nothing but H (by Lemmas 2. 95 and 2.96).

It follows that cwd (H) ≤ cwd (G).

(2) This follows from Proposition 2.100(2), because the transformations of terms considered there do not modify the port labels. If G is transformed into H, then cwd (H) ≤ cwd (G). Since the inverse transformations are of the same nature, we have an equality.

(3) Let G be a p-graph defined by a term t in T (F

(t ) = core(G), hence cwd (core(G)) ≤ cwd (G).
The proof is the same for labelled graphs.

(4) The proof will be given at the end of Section 2.5.6. The case of loop-free undirected graphs is proved in Theorem 4.1 of [CouOla].

We review the clique-widths of some classical graphs, as we did in Example 2.56(3) for tree-width. The graph P n is an undirected path with n vertices. We denote by G u n×m the undirected rectangular grid und (G n×m ).

Proposition 2.106

(1) The following equalities hold:

cwd (K n ) = 2 if n ≥ 2, cwd (K n,m ) = 2 if n, m ≥ 1, cwd (P n ) = 3 if n ≥ 4, cwd (C 5 ) = cwd (C 6 ) = 3, cwd (C n ) = 4 for n ≥ 7, cwd (G u n×n ) = n + 1 if n ≥ 2, m + 1 ≤ cwd (G u n×m ) ≤ m + 2 if n > m ≥ 3.
(2) A simple loop-free undirected graph is a cograph if and only if its cliquewidth is at most 2.

Proof (2) We have observed in Remark 2.55(d) that tree-width does not depend on edge directions. We have also proved in Proposition 2.47(3) that changing an edge direction or a label in a graph defined by a term in T (F HR ) or in T (F HR [K,Λ] ) corresponds to changing a constant symbol in this term. The situation is here similar for vertex labels (cf. Proposition 2.100(2)), but it is not for edge labels and edge directions because the operations --→ add a,b and --→ add a,b,λ define edge directions and/or edge labels simultaneously for a set of edges forming a directed complete bipartite graph. Hence the modification of a single edge direction or of a single edge label may necessitate a reorganization of the term defining the graph. We have already seen that in Example 2.91 for edge labels.

The following example shows that clique-width depends on edge directions.

Example 2.108 Let G 0 , G 1 , G 2 be the following graphs:

G 0 = • -• -•, G 1 = • → • ← •, G 2 = • → • → •. Clearly, G 0 = P 3 = K 1,2 and cwd (G 0 ) = 2. We have G 1 = val ((1⊕1) - → ⊗ 1) where the complete directed join of G and H is defined by G - → ⊗ H = relab 2→1 ( --→ add 1,2 (G⊕ relab 1→2 (H))), thus cwd (G 1 ) = 2. Then cwd (G 2 ) ≤ |V G2 | = 3,
and one can check that there is no term written with two port labels that defines G 2 . Hence cwd (G 2 ) = 3. Since cwd (G 2 ) > cwd (G 0 ) = cwd (G 1 ), this example shows that clique-width is preserved neither under reversal of edge directions47 nor under forgetting edge directions.

We have seen in Proposition 2.62 that the tree-width of a nonempty graph is the maximal tree-width of its connected components, of its 2-connected components and also of its 3-blocks. There exists a similar result for clique-width and the notion of a prime induced subgraph, relative to modular decomposition.

For stating it we need some definitions. They concern unlabelled graphs.

Definition 2.109 (Substitution to a vertex) Let G and H be disjoint concrete graphs 48 and u be a loop-free vertex of G. We let G[u ← H] be the concrete graph K defined as follows:

V K := V G-u ∪ V H , edg K := edg G-u ∪ edg H ∪ {(v, w) | v ∈ V G-u , w ∈ V H and (v, u) ∈ edg G } ∪ {(w, v) | v ∈ V G-u , w ∈ V H and (u, v) ∈ edg G }.
If G is a p-graph, we define the port mapping of K by:

port K (v) := port G (v) if v ∈ V G-u , port G (u) if v ∈ V H .
This definition is applicable if H is a p-graph but the port mapping of H does not play any role: we have ), let u be a loop-free vertex of G described by a(u) in t and let H be the value of a term t in

G[u ← H] = G[u ← H • ]. We say that G[u ← H] is obtained from G by
T (F cVR D ) such that H and G are disjoint. Then G[u ← H] is the value of the term t[relab π(H)→a (t )/a(u)] that belongs to T (F cVR C∪D ). 49 (2) If H = ∅, then cwd (G[u ← H]) = max{cwd (G), cwd (H • )}. Proof: (
(G[u ← H]) ≤ max{cwd (G), cwd (H • )} (because cwd (H • ) = cwd (val (relab π(H)→a (t ))) ).
For the opposite equality, we note that of a graph G is a set M ⊆ V G such that, for every x, y ∈ M and every z ∈ V G -M , we have:

H • ⊆ i G[u ← H] • and that G is isomorphic to the subgraph of G[u ← H] induced by V G ∪ {w}
(H • ) ≤ cwd (G[u ← H] • ) ≤ cwd (G[u ← H]) and cwd (G) ≤ cwd (G[u ← H]), which gives the desired result. If H = ∅, then G[u ← H] = G -u and we have cwd (G -u) ≤ cwd (G) by Proposition 2.105(1). We may have that cwd (G[u ← H]) is less than cwd (G) = max{cwd (G), cwd (H • )}.
(x, z) ∈ edg G ⇐⇒ (y, z) ∈ edg G and (z, x) ∈ edg G ⇐⇒ (z, y) ∈ edg G . Thus, V H is a module of G[u ← H].
A graph is prime if it has no other modules than its vertex set, each of its singletons and ∅. A prime induced subgraph is an induced subgraph that is prime. The graph P 3 is not prime but the graphs P n are prime for all n ≥ 4.

Proposition 2.112 For every graph G we have:

cwd (G) = max{cwd (H) | H is a prime induced subgraph of G}.
Proof: The direction ≥ follows from Proposition 2.105 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. For the other direction, we use the fact that every directed graph G can be expressed by means of (nested) substitutions of graphs isomorphic to its prime induced subgraphs and of the particular graphs I 2 (two isolated vertices),

-→ K 2 = • → • and K 2 . 50 (If G is undirected, the graph -→ K 2 is not used in this expression).
The other inequality follows from this result and Proposition 2.110(2).

Example 2.113 Two graphs G and H are shown in Figure 2.12. We have

G = H[u ← I 2 ][v ← -→ K 2 ][w ← M ] where M = • → • → •.
The graph H is defined by the term

t H := relab {2,3}→1 ( --→ add 1,3 (relab 3→1 [ --→ add 2,1 ( --→ add 3,2 (1(u) ⊕ 2(v) ⊕ 3(w)))] ⊕ 3(x))).
The p-graphs I 2 , -→ K 2 and M of respective types {1}, {2} and {3} are the values of the terms t

1 := 1 ⊕ 1, t 2 := relab 1→2 ( --→ add 1,2 (1 ⊕ 2)) and t 3 := relab {1,2}→3 ( --→ add 1,2 ( --→ add 2,3 (1 ⊕ 2 ⊕ 3))).
Then G is the value of the term t H [t 1 /1(u), t 2 /2(v), t 3 /3(w)] hence, of the term

t G := relab {2,3}→1 ( --→ add 1,3 (relab 3→1 [ --→ add 2,1 ( --→ add 3,2 (t 1 ⊕ t 2 ⊕ t 3 ))] ⊕ 3))
that belongs to T (F VR [3] ). It follows that cwd (G) ≤ 3. Actually cwd (G) = 3 because H and M have clique-width 3. Note that H and M are induced subgraphs of G.

It follows from this proposition that an optimal clique-width term for a graph can be obtained from its modular decomposition and optimal clique-width terms for its prime induced subgraphs.

Comparisons between tree-width and clique-width

Tree-width, path-width and clique-width are functions on graphs that one can consider as graph complexity measures51 . Certain graphs considered as basic have low values for these measures: paths (graphs of the form P n ) have pathwidth at most 1, trees have tree-width at most 1, cliques (the graphs K n ) have clique-width at most 2. These three complexity measures yield infinite hierarchies of graph families. In this section, we will compare tree-width and cliquewidth. Since clique-width is only defined for simple graphs, the comparisons will be stated for simple graphs (without ports or sources).

A tournament is an orientation of a clique, i.e., a directed graph obtained from a clique by choosing a direction for each of its edges.

Proposition 2.114

(1) For every simple (K, Λ)-labelled graph G we have:

(1.1) cwd (G) ≤ 2 2|Λ|•(twd(G)+1) + twd (G) + 1, (1.2) cwd (G) ≤ 3 • 2 twd(G)-1 if G is unlabelled and undirected, (1.3) lcwd (G) ≤ pwd (G) + 2.
(2) For each k, there is a graph G of tree-width k and clique-width at least 2 k/2 -1 .

(3) Cliques have clique-width at most 2 and unbounded tree-width. Tournaments have unbounded clique-width and tree-width.

Proof: (1) Inequality (1.1) will be proved in Section 4.3.4; the slightly stronger statement cwd (G) ≤ 2 2twd(G)+2 + 1 for G unlabelled and directed is proved in [CouOla] 52 . Inequality (1.2) is proved in [CorRot]. We now prove inequality (1.3) for directed unlabelled graphs. Its extension to the other cases will be discussed afterwards.

Let G be a simple directed graph of pathwidth k -1. By Proposition 2.85, it is the value of a slim term in T (F HR [k] ). Let us say that a term t in T (F HR ) is simple if val (t) is simple; note that if t is simple, then every subterm of t is simple. By induction on the structure of t, we transform every simple slim term t over F HR [k] into a slim term t over F cVR [0,k] such that the p-graph cval (t ) is obtained from the s-graph val (t) by turning each a-source into an a-port, and each internal vertex into a 0-port. Thus, if in particular t evaluates to G, then t evaluates to the graph G of type {0}, that is, whose vertices are turned into 0-ports (G is without sources). Hence, lcwd (G)

≤ k + 1 = pwd (G) + 2.
The inductive definition is as follows. It is straightforward to prove its correctness.

• If t is ∅, then t := ∅. If t is a or a , then t is defined as a(x) or a (x) for some x. If t is -→ ab, then t := --→ add a,b (a(x) ⊕ b(y))
for some x and y = x.

• If t is ren h (t 1 )
where h is a permutation of [k], then t := relab h (t 1 ).

• If t is fg a (t 1 ), then t := relab a→0 (t 1 ). Similarly for fg B .

• If t is a t 1 and a / ∈ τ (t 1 ), then t := a(x) ⊕ t 1 for some x that is not a vertex of cval (t 1 ); otherwise a ∈ τ (t ) and t := t 1 .

• If t is a t 1 and a / ∈ τ (t 1 ), then t := a (x) ⊕ t 1 for some x that is not a vertex of cval (t 1 ); otherwise a ∈ τ (t ) and, by induction (and because t is simple), cval (t 1 ) has a unique a-port y, which is described by a unique occurrence in t 1 of a constant symbol b(y) for some b ∈ [k] (because of renamings, we may have b = a); then we obtain t by replacing in t 1 this symbol by b (y). --→ add a,b,λ (t 1 ). (Clearly, the power of the operation --→ add a,b to create simultaneously several edges is not used in this construction.) Vertex labels and labelled loops are handled by obvious modifications of the one-before-last case. In fact, if t is a κ t 1 and a / ∈ τ (t 1 ), then t := a {κ} (x) ⊕ t 1 ; otherwise a ∈ τ (t 1 ) and t is obtained from t 1 by replacing b M (y) by b M ∪{κ} (y) where y is the a-port of cval (t 1 ). And similarly with a λ instead of a κ . Hence, the same inequality holds for labelled graphs.

• If t is -→ ab t 1 ,
(2) is proved in [CorRot]. Hence, the exponential function in the comparison of tree-width and clique-width cannot be replaced by a linear or even a polynomial function.

(3) The case of cliques follows from Example 2.56(3) and Proposition 2.106. For tournaments, we use a counting argument: for each n there exist 2 n(n-1)/2 (concrete) tournaments with vertex set [n], but for each finite set C there are only 2 O(n•log(n)) graphs with this vertex set that are the values of terms in T (F cVR

C

). This fact follows from Corollary 2.122 below (in Section 2.5.6). Hence, for each finite set C, some tournaments cannot be defined by terms in T (F cVR

C

). Another proof using monadic second-order transductions will be given in Section 7.2, Proposition 7.39 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF].

The proof of Inequality (1.2) given in [CorRot] extends easily to undirected edge-labelled graphs. If is the number of edge labels and k = twd (G), we get:

cwd (G) ≤ (2 -1) • 2 (k-1) + 2 k + 1 -(2 -1) k ,
which gives, more simply:

cwd (G) ≤ 2 k+1 -(2 -1) k .
Directed graphs can be handled as undirected graphs with two edge labels. We obtain thus, with = 2 in the first formula, and for k ≥ 2:

cwd (G) ≤ 7 • 2 2k-2 + 1 -3 k .
These upper-bounds are different from (and better than) those arising from the proof of Section 4.3.4 because they are based on the characterization of graphs of tree-width at most k using the operations of H k defined in Remark 2.84(4).

There is a striking difference between clique-width and tree-width regarding their linear versions: just compare (1.2) and (1.3). These results also show that every set of simple graphs of bounded tree-width has bounded clique-width, and not conversely. However, for particular types of graphs like planar graphs or graphs of degree at most d for any fixed d, clique-width and tree-width are equivalent in the sense that the same sets of simple planar graphs and of simple graphs of bounded degree have bounded tree-width and bounded clique-width. This is made precise in the following proposition.

If p ≥ 2, we say that a graph G is without K p,p if core(G) has no subgraph isomorphic to K p,p . If G is labelled and λ is an edge label, we let G λ be the subgraph of G consisting of its edges labelled by λ (and all its vertices). The following result is essentially from [GurWan].

Proposition 2.115 Let p ≥ 2.

(1) For every simple graph G without K p,p , we have:

twd (G) ≤ 3(p -1) • cwd (G) -1. If G has degree at most p, then twd (G) ≤ 3p • cwd (G) -1. If G is planar, then twd (G) ≤ 6 • cwd (G) -1.
(2) If G is (K, Λ)-labelled, simple and G λ is without K p,p for every λ ∈ Λ, then:

twd (G) ≤ 3(p -1) • |Λ| • cwd (G) -1.
(3) The same results hold for path-width and linear clique-width, with 3 replaced by 6.

Before proving Proposition 2.115, we need some preliminary definitions and results (that will also be useful in Section 7.4). We first consider unlabelled graphs. We let G without K p,p be equal to cval (t) with t ∈ T (F VR C ), so that V G = Occ 0 (t). (We will use the notation and results of Section 2.5.2). For u ∈ N t , we let G(u) denote the p-graph cval (t)/u with vertex set {x ∈

V G | x ≤ t u}. Up to port labels, G(u) is a subgraph of G, i.e., G(u) • ⊆ G. A vertex
x of G(u) belongs to the set of a-ports of G(u), denoted by Pt(u, a), if and only if port t (u, x) = a (cf. Definition 2.94). We say that a is small at u if |Pt(u, a)| ≤ p -1. Otherwise it is large at u. We let Ext(u, a) be the set of vertices in V G -V G(u) that are adjacent (in G) to an a-port of G(u). We let T be the syntactic tree of t and we will define a mapping f : N t = N T → P(V G ) and prove that (T, f ) is a tree-decomposition of G. We let:

f (u) := {u} if u ∈ Occ 0 (t); otherwise: f (u) := {Pt(u , a) | a ∈ C, u is a son of u and |Pt(u , a)| ≤ p -1} ∪ {Ext(u, a) | a ∈ C, |Ext(u, a)| ≤ p -1}. It is clear that V G ⊆ {f (u) | u ∈ N T }.
With these definitions and notation we have: (2) Let x ∈ V G , let Y be the set of vertices of G that are adjacent to x, and let u be the father of the leaf

Lemma 2.116 (
x of T . If |Y | ≤ p -1, then {x} ∪ Y ⊆ f (u).
Proof: (1) All vertices of Pt(u, a) are subject to the same relabellings and edge additions defined by operations at occurrences strictly above u in t. Hence every vertex of Pt(u, a) is adjacent to every vertex of Ext(u, a). (This follows easily from Lemmas 2. 95 and 2.96). We would get a subgraph of core(G) isomorphic to K p,p if Pt(u, a) and Ext(u, a) would have both at least p elements.

(2) Since Pt(x, a) = {x} where a is the port label of x in G(x), so that

|Pt(x, a)| = 1 ≤ p -1, we have Pt(x, a) ⊆ f (u) hence x ∈ f (u). Let l be the port label of x in G(u). Then Ext(u, l) = Y ∩ (V G -V G(u) ). Since |Ext(u, l)| ≤ |Y | ≤ p-1, we have Ext(u, l) ⊆ f (u), and so Y ∩(V G -V G(u) ) ⊆ f (u). It remains to show that Y ∩ V G(u) ⊆ f (u). Consider y ∈ Y ∩ V G(u)
. Let u be the son of u such that y ≤ T u , and let h be the port label of y in G(u ). Then y ∈ Pt(u , h) and x ∈ Ext(u , h). Since every vertex of Pt(u , h) is adjacent to every vertex of Ext(u , h) by ( 1), we have Pt(u , h) ⊆ Y . Hence |Pt(u , h)| ≤ p -1, and so Pt(u , h) ⊆ f (u), and y ∈ f (u).

Proof of Proposition 2.115:

(1) The assertions about graphs of bounded degree and planar graphs follow from the main statement because if G has degree at most p then it is without K p+1,p+1 , and planar graphs are without K 3,3 .

We now prove that (T, f ) defined before the previous lemma is a treedecomposition of G. This will give the first assertion since |f (u)| ≤ 3|C| • (p -1) for every u. Some claims will be necessary.

Claim 2.115.1 Let x ∈ Occ 0 (t) and let (u n , u n-1 , . . . , u 1 ) be the path in T from the root u n to u 1 = x. Let l 1 , . . . , l n be the successive port labels of x in G(u 1 ), G(u 2 ), . . . , G(u n ) = G. We have:

{x} = Pt(u 1 , l 1 ) ⊆ Pt(u 2 , l 2 ) ⊆ • • • ⊆ Pt(u n , l n ) (2.5)
and

Ext(u 1 , l 1 ) ⊇ Ext(u 2 , l 2 ) ⊇ • • • ⊇ Ext(u n , l n ) = ∅. (2.6)
If m is the largest index such that l m is small at u m , we have |Ext(u j , l j )| ≤ p-1 for every j, m < j ≤ n.

Proof: The inclusions of (2.5) are clear from Lemma 2.95. We may have Pt(u i , l i ) ⊂ Pt(u i+1 , l i+1 ) but only if u i+1 is an occurrence of a disjoint union or of a relabelling. The inclusions Ext(u i+1 , l i+1 ) ⊆ Ext(u i , l i ) of (2.6) follow from the fact that, by (2.5) and Lemma 2.116(1), a vertex y of G belongs to Ext(u i , l i ) if and only if y T u i and y is adjacent to x in G, and similarly for i + 1. Note that we have an equality if u i+1 is an occurrence of an edge addition operation. If u i+1 is an occurrence of a relabelling that transforms some label l into l i+1 and if

Pt(u i , l) = ∅, then Ext(u i+1 , l i+1 ) = Ext(u i , l i ) = Ext(u i , l).
By the definition of m, |Pt(u j , l j )| ≥ p for every j such that m < j ≤ n. By Lemma 2.116 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF], this implies |Ext(u j , l j )| ≤ p -1 for all these indices.

Let x, y be adjacent vertices of G (they are leaves of T ). Let w be their least common ancestor in T , let (u q , u q-1 , . . . , u 1 ) be the path in T from w to x where u q = w, u 1 = x and let l 1 , . . . , l q be the corresponding port labels of x as in Claim 2.115.1; let (v q , v q -1 , . . . , v 1 ) with v q = w and v 1 = y, and h 1 , . . . , h q be the analogous sequences relative to y. Note that w is an occurrence of ⊕ and that the edge between x and y is created by an edge addition at some occurrence w between w and the root.

Claim 2.115.2 Pt(u q-1 , l q-1 ) ⊆ Ext(v j , h j ) for every j, 1 ≤ j ≤ q -1.

Proof: We have x ∈ Pt(u q-1 , l q-1 ) and y ∈ Ext(u q-1 , l q-1 ). By Lemma 2.116 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF], the operation that creates the edge between x and y also creates edges between all vertices of Pt(u q-1 , l q-1 ) and y. Hence Pt(u q-1 , l q-1 ) ⊆ Ext(v j , h j ).

Claim 2.115.3 If x and y are adjacent in G, then {x, y} ⊆ f (u) for some u ∈ N T .

Proof: If x has degree at most p-1, the claim follows from Lemma 2.116(2). For proving the general case, we use the notation of Claim 2.115.2. By this claim (for j = q -1) and by Lemma 2.116(1), it is not possible that |Pt(u q-1 , l q-1 )| ≥ p and |Pt(v q -1 , h q -1 )| ≥ p. If |Pt(u q-1 , l q-1 )| ≤ p -1, then Pt(u q-1 , l q-1 ) ⊆ f (u q ) = f (w) and so x ∈ f (w). If we have also |Pt(v q -1 , h q -1 )| ≤ p -1, then similarly, y ∈ f (w). Next we consider the case where |Pt(v q -1 , h q -1 )| ≥ p. Let m be the largest integer such that |Pt(v m , h m )| ≤ p -1. We have m < q -1 and

x ∈ Ext(v m +1 , h m +1 ). By Claim 2.115.1, |Ext(v m +1 , h m +1 )| ≤ p -1 and so Ext(v m +1 , h m +1 ) ⊆ f (v m +1 ), so that x ∈ f (v m +1 ). Since |Pt(v m , h m )| ≤ p -1, we have also Pt(v m , h m ) ⊆ f (v m +1 ), hence y ∈ f (v m +1
). The last possible case is when l q-1 is large at u q-1 and h q -1 is small at v q -1 . The proof is the same by exchanging the roles of x and y.

Claim 2.115.4 The pair (T, f ) satisfies the connectivity condition, hence is a tree-decomposition of G.

Proof: Let x ∈ V G and let u 1 , . . . , u n , l 1 , . . . , l n and m be as in Claim 2.115.1. It follows from the definitions that x ∈ f (u i ) for every i such that 1 ≤ i ≤ min{n, m + 1} (we may have m = n), and x / ∈ f (u i ) if i > m + 1. Assume now that x ∈ f (v) for v / ∈ {u 1 , . . . , u n }. This means that x is adjacent to y in Pt(v, h), x belongs to Ext(v, h) and |Ext(v, h)| ≤ p -1. We let q, v 1 , . . . , v q , h 1 , . . . , h q , m be as in Claims 2.115.2 and 2.115.3. We have v = v j and h = h j for some j, 1 ≤ j ≤ q -1. By Claim 2.115.2, Pt(u q-1 , l q-1 ) ⊆ Ext(v j , h j ) = Ext(v, h). Hence l q-1 is small at u q-1 . We have |Ext(v j , h j )| ≤ p -1 and by Claim 2.115.1, Ext(v j , h j ) ⊆ Ext(v j , h j ) if j > j, so that Ext(v j , h j ) ⊆ f (v j ) for every j = j, . . . , q -1. We also have x ∈ Ext(v j , h j ) by Claim 2.115.2, and so x ∈ f (v j ) for all these indices j . Since x ∈ f (u q ) (because l q-1 is small at u q-1 and u q is the father of u q-1 ), we have x ∈ f (u) for every u ∈ {u 1 , . . . , u q-1 , u q , v q -1 , . . . , v j } and this set induces the path between x and v in T . We have proved that every node u in f -1 (x) belongs to a path linking x and u, all nodes of which are in f -1 (x). Hence the connectivity condition holds.

We have defined a tree-decomposition (T, f ) with wd (T,

f ) ≤ 3|C|•(p-1)-1 from a term t over F VR C such that G = val (t) is without K p,p . Hence twd (G) ≤ 3(p-1)•cwd (G)-1.
This completes the proof of Proposition 2.115 for unlabelled graphs.

(2) If G has edge labels (vertex labels do not matter), it is the union of its subgraphs G λ for all edge labels λ. The above proof yields for the graphs G λ tree-decompositions (T, f λ ) that have the same underlying tree T . This tree is the syntactic tree of the given term t in T (F VR C, [K,Λ] ) that evaluates to G. We get a tree-decomposition (T, f ) of G by taking f (u) equal to the union of the sets f λ (u) for each node u of T .

(3) Let us now assume that t is a slim term in T (F VR C ), cf. Definition 2.89. Then the tree-decomposition (T, f ) can be turned into a path-decomposition by contracting all edges (u, v) of T such that u is an occurrence of ⊕ in t, v is a leaf of t and the other son of u (i.e., the son = v) is not a leaf of t. If the two sons of u are leaves, one contracts only one of the two corresponding edges. This doubles (at most) the number of vertices in each box, by Lemma 2.64. This completes the proof of Proposition 2.115.

We have seen in Example 2.108 that clique-width is sensitive to the reversal of edge directions while tree-width is not. This observation can be made more precise by the following result of [START_REF] Courcelle | The monadic second-order logic of graphs VIII: Orientations[END_REF]. Its proof which uses monadic secondorder transductions will be sketched in Section 7.2, Proposition 7.40. We recall that und -1 (G) is the set of orientations of G, i.e., the set of directed graphs G such that G = und (G ), the graph obtained from G by forgetting edge directions. Since G is assumed to be simple, the condition und (G ) = G implies that G has no pairs of opposite edges.

Proposition 2.117 There exists a function f : N → N such that, for every simple undirected graph G, we have:

twd (G) ≤ f (max{cwd (G ) | G ∈ und -1 (G)}).
By this proposition, if a set of directed graphs has bounded clique-width and is closed under the reversal of directions of any set of edges, then it has bounded tree-width.

Variations on F VR

The operations forming the signature F VR have been chosen so as to be as simple and as few as possible. The signature F VR has many variants that are equivalent in the sense that the same sets of graphs have bounded clique-width and bounded width with respect to these alternative signatures. We present here three of these variants. They are formulated for unlabelled graphs but their statements and proofs extend easily to labelled graphs. We will not detail these extensions.

Elementary relabellings

Clique-width is defined in Definition 2.89 with respect to a finite set C ⊆ A and the operations ⊕, add a,b , --→ add a,b , relab h where a, b belong to C and h : C → C. The following proposition shows that this definition is equivalent to the original one of [CouOla] that is used in many subsequent works (see Section 2.7 for references). We define

F VRu C := {⊕, add a,b , relab a→b , a, a , ∅ | a, b ∈ C, a = b}, and
F VR C := F VRu C ∪ { --→ add a,b | a, b ∈ C, a = b}. Proposition 2.118 The clique-width of a p-graph G is the minimal cardinality of a set C such that G = val (t) for some term t in T (F VR C ) or in T (F VRu C ) if G is undirected.
Proof: We wish to replace an operation relab h for h in [C → C] f by a composition of elementary relabellings relab a→b for some a, b in C. This is not possible if h is a bijection that is not the identity. Consider C = {a, b} with h(a) = b, h(b) = a. We need another port label c to express relab h as

relab c→b • relab b→a • relab a→c . However, this is possible if h is not a bi- jection. For example if h(a) = b, h(b) = c, h(c) = a and h(d) = a, then relab h = relab d→b • relab b→c • relab c→a • relab a→d • relab d→c .
We omit the proof of this fact.

For completing the proof we observe that the operations relab h such that h : C → C is a bijection can be eliminated. We can use Equalities ( 4) -( 8) and ( 12) of Proposition 2.101 to eliminate them, as we have used some equalities of Proposition 2.48 to eliminate the operations ren h in Proposition 2.49.

We have just proved that clique-width is not modified by a certain restriction of the signature F VR . We now examine the effect of extending it.

New edge addition operations

For a directed or undirected p-graph G and a ∈ A, we let add a,a (G) be the p-graph G defined by:

V G := V G , edg G := edg G ∪ {(x, y) | x, y ∈ V G , x = y, port G (x) = port G (y) = a}, port G := port G .
This new operation adds undirected edges, or equivalently pairs of opposite directed edges, but no loops. We let F iVR C be the signature F VR C augmented with the operations add a,a for all a ∈ C, and we let cwd i (G) be the corresponding width defined by

cwd i (G) := min{|C| | G = val (t), t ∈ T (F iVR C )}.
Cliques are the values of the terms add a,a (a ⊕ • • • ⊕ a) written with a single port label. Hence

cwd i (K n ) = 1 whereas cwd (K n ) = 2 for n ≥ 2.
The graphs K n ⊕I m are the only simple loop-free undirected graphs G such that cwd i (G) = 1. (We recall that I m has m vertices and no edge). We have cwd i (P 4 ) = 2 < cwd (P 4 ) =

3 because P 4 = relab 2→1 (add 1,1 (add 1,2 (1 ⊕ 2) ⊕ add 1,2 (1 ⊕ 2))). We have cwd i (K n,m ) = cwd (K n,m ) = 2 for n, m ≥ 2.
Proposition 2.119 For every p-graph G, we have

cwd i (G) ≤ cwd (G) ≤ 2 • cwd i (G).
Proof: Since cwd i is defined in terms of more operations than cwd , the inequality cwd i (G) ≤ cwd (G) is trivial. We now prove the other direction. Let G be such that cwd i (G) = k. Without loss of generality we assume that the port labels used to define G are 1, . . . , k. We let F be the set of operations consisting of ⊕, add i,j for i

∈ [k], j ∈ [k] ∪ {k + i}, relab h where h: [2k] → [2k] and i and i for all i ∈ [k]. For P ⊆ [k],
we let ADD P be the derived operation defined as i∈P add i,i , i.e., as the composition in any order of the operations add i,i for all i in P . (Hence ADD ∅ is the identity.) We have the following equalities, for all i, j in

[k], h : [k] → [k], and all p-graphs G, H of type included in [k]: (a) ADD P (G ⊕ H) = relab g -1 [( i∈P add i,k+i )(ADD P (G) ⊕ relab g (ADD P (H)))] where g : [k] → [k + 1, 2k] is defined by g(j) := k + j for j ∈ [k], (b) ADD P (add i,i (G)) = ADD P ∪{i} (G), (c) ADD P ( --→ add i,j (G)) = --→ add i,j (ADD P (G)) if i = j (and the same for add i,j ), (d) ADD P (relab h (G)) = relab h (f (ADD P (G)))
where P = {i | h(i) ∈ P } and f is the composition of all operations add i,j such that i, j ∈ [k], i = j and h(i) = h(j) ∈ P .

These equalities entail the following claim. Its proof is easy by induction on the structure of t, by using equalities (a)-(d).

Claim 2.119.1 For every term t ∈ T (F iVR [k] ) and every P ⊆ [k], there exists a term t in T (F ), hence in T (F VR [2k] ), such that val (ADD P (t)) = val (t ). By taking P = ∅, we obtain that cwd (G) ≤ 2 • cwd i (G).

Binary derived operations replacing unary operations

Let C be a finite set of port labels. Let us consider the derived operations defined as compositions of unary operations of F VR C . There are infinitely many such compositions but they only define finitely many different operations. In fact, we have shown in Proposition 2.103 that every context in Ctxt(F VR C ) that is written without ⊕, and hence with unary operations only, is equivalent to a context of the form relab h (ADD R (x 1 )) with h : C → C and R ⊆ C × C (and ADD R is the composition, in any order, of the operations --→ add a,b with (a, b) ∈ R, a = b). Obviously, we may also assume that R ∩ Id C = ∅, where

Id C := {(a, a) | a ∈ C}. There are k k • 2 k 2 -k contexts of that form, where k = |C|. We now show that they are all inequivalent. Lemma 2.120 Let c = relab h (ADD R (x 1 )) and c = relab h (ADD R (x 1 )) be contexts with h, h : C → C and R, R ⊆ (C × C) -Id C . Then c GP = c GP if and only if h = h and R = R .
Proof: One direction is trivial. For the other direction, let us assume that

c GP (G) = relab h (ADD R (G)) = relab h (ADD R (G)) = c GP (G)
1 ⊗ R,h t 2 by relab h (ADD R (t 1 ⊕ t 2 )). In the other direction, subterms relab h (t 1 ) can be replaced by t 1 ⊗ ∅,h ∅, subterms --→ add a,b (t 1 ) by t 1 ⊗ {(a,b)},
(ADD R (t 1 )) with h : C → C and R ⊆ C × C. If t 1
is a or a and h(a) = b, then we define t as b or b . If t 1 = t 2 ⊕ t 3 , then, using the induction hypothesis, we define t := t 2 ⊗ R,h t 3 .

All these transformations can be done in linear time for fixed C.

A term t over F κVR C -{∅} has length 2|V val(t) | -1 because F κVR C
consists only of binary operations and constant symbols, and V val(t) is in bijection with the leaves of t. Such a term is in general smaller than those in T (F VR C ) that denote the same p-graph. However a data structure representing the operations of F κVR C must, essentially, represent a p-graph with |C| vertices for each occurrence of a binary function symbol ⊗ R,h , viz. the p-graph H with H • := C, R and port H := h. It is not clear that this would be really more efficient than storing a term from T (F VR C ) from which redundancies like

--→ add a,b ( --→ add a,b (• • • )) are elim- inated.
This aspect is important for algorithmic applications to be considered in Chapter 6. The signature F κVR C will be useful anyway for certain proofs in Chapter 7 (in particular for proving the Equationality Theorem, see the proof of Theorem 7.34). The following corollary is analogous to Corollary 2.74(2).

Corollary 2.122 For all k, n > 0, the number of concrete graphs of cliquewidth at most k with vertex set [n] is less than 2 n•log(n)+2k 2 •n .

Proof: For k = 1 the statement follows easily from Remark 2.107 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. Now let k ≥ 2. We let and * be symbols of respective arities 0 and 2. The number C n of terms in T ({ * , }) having n + 1 occurrences of is the n-th Catalan number. Its value is less than 2 2n (see, e.g., [*FlaSed]). The number

N k (n) of terms in T (F cκVR [k]
-{∅}) that define concrete directed p-graphs (possibly with loops) with vertex set [n] can be evaluated as

n! • C n-1 • c n • f n-1 where f is the number of inequivalent binary operations in F κVR [k]
and c is the number of constants in this set different from ∅. We have thus c = 2k,

f = k k • 2 k 2 -k and C n-1 < 2 2n-2 . Since n! < 2 n•log(n) , we get log(N k (n)) < n • log(n) + 2n -2 + n • log(2k) + (n -1) • (k • log(k) + k 2 -k) < n • log(n) + 2k 2 • n, which gives the result 53 .
This corollary entails that the set of all graphs, and even that of undirected graphs has unbounded clique-width. Because otherwise, the number of concrete directed (or undirected) graphs with vertex set [n] would be 2 O(n•log(n)) whereas it is 2 Ω(n 2 ) . However, Proposition 2.106 is more precise for proving the unboundedness of clique-width over all graphs because it gives the exact clique-width of rectangular undirected grids.

We now use Proposition 2.121 to prove Statement (4) of Proposition 2.105.

Proof of Proposition 2.105(4): We will prove that the edge-complement G of a (directed) p-graph G has clique-width at most 2 • cwd (G). The proof will extend easily to labelled p-graphs. Furthermore, we will give a linear-time algorithm that constructs a term t evaluating to G from a term t in T (F κVR

C

) that evaluates to G. For the purpose of readability we will denote G also by ec(G).

Let be given t ∈ T (F κVR C

). For every position u in t, we define Edg(t ↑ u) ⊆ C × C by the following top-down induction:

-if u is the root, then Edg(t ↑ u) := ∅, -if u is a son of an occurrence w of ⊗ R,h , then Edg(t ↑ u) := R ∪ h -1 (Edg(t ↑ w)), where h -1 (S) := {(a, b) | (h(a), h(b)) ∈ S} for every S ⊆ C × C.
The operations above u in t add to the p-graph cval (t)/u the edges from x to y such that x is an a-port and y is a b-port of cval (t)/u, and (a, b) ∈ Edg(t ↑ u) with a = b. 54 (For the notation cval (t)/u see Section 2.5.2.) The sets Edg(t ↑ u) 53 The last inequality uses the fact that 2 + log(2k

) + k • log(k) + k 2 -k ≤ 2k 2 for every k ≥ 2.
54 Similar sets, satisfying the same property, can be defined for t ∈ T (F VR C ) by the following clauses:

if u is the root, then

Edg(t ↑ u) := ∅, if u is a son of an occurrence w of ⊕, then Edg(t ↑ u) := Edg(t ↑ w),
can be computed in linear time along a depth-first traversal of t starting from the root. The construction of t will be based on the following obvious fact.

Claim 2.105.1 Let C be disjoint with C, let G 1 and G 2 be p-graphs with

π(G 1 ) ⊆ C and π(G 2 ) ⊆ C , and let R ⊆ (C × C ) ∪ (C × C). Then we have ec(G 1 ⊗ R,h G 2 ) = ec(G 1 )⊗ R c ,h ec(G 2 ) where R c = ((C ×C )∪(C ×C))-R.
In order to use it, we will change some port labels in the given term in such a way that, in every subterm t 1 ⊗ R,h t 2 of the modified term, we have π(t 1 ) ⊆ C and π(t 2 ) ⊆ C where C := {a | a ∈ C} is a disjoint copy of C. We define also: For R ⊆ C × C, we define:

p and p -: C ∪ C → C ∪ C such that,
R p := {(a, b ), (a , b) | (a, b) ∈ R, a = b}, R pc := ((C × C ) ∪ (C × C)) -R p = {(a, b ), (a , b) | a, b ∈ C, (a, b) / ∈ R, a = b} ∪ {(a, a ), (a , a) | a ∈ C}. We are ready to define t ∈ T (F κVR C∪C ) from t ∈ T (F κVR C
). For each u ∈ Pos(t), we replace the symbol f that occurs at u by a symbol f of the same arity according to the following clauses:

if f = ∅, then f := ∅, if f = a, then f := if u is a right son then a else a , if f = a , then f := if u is a right son then a else a, if f = ⊗ R,h , then f := if u is a right son then ⊗ S,p•h•p -else ⊗ S,h•p -,
where

S := (R ∪ h -1 (Edg(t ↑ u))) pc .
Note that Pos( t ) = Pos(t).

The first statement of the next claim yields the result if we take u = root t because then Edg(t ↑ u) = ∅.

Claim 2.105.2

(1) For every u ∈ Pos(t) that is the root or a left son:

π( t/u) ⊆ C and cval ( t )/u = ec(ADD Edg(t↑u) (cval (t)/u)), and
(2) for every u ∈ Pos(t) that is a right son:

π( t/u) ⊆ C and cval ( t )/u = relab p (ec(ADD Edg(t↑u) (cval (t)/u))). if u is the son of an occurrence w of --→ add a,b , then Edg(t ↑ u) := Edg(t ↑ w) ∪ {(a, b)}, if u is the son of an occurrence w of add a,b , then Edg(t ↑ u) := Edg(t ↑ w) ∪ {(a, b), (b, a)}, if u is the son of an occurrence w of relab h , then Edg(t ↑ u) := h -1 (Edg(t ↑ w)).
Proof: For fixed t, by bottom-up induction on u. The cases where u is a leaf are clear from the definitions. Let u be an occurrence of ⊗ R,h that is the root or a left son, and let u 1 and u 2 be the left and right son of u. Then, by the definition of t:

cval ( t )/u = relab h•p -(ADD S (cval ( t )/u 1 ⊕ cval ( t )/u 2 ))
where

S := (R ∪ h -1 (Edg(t ↑ u))) pc . On the other hand, ADD Edg(t↑u) (cval (t)/u) = ADD Edg(t↑u) (relab h (ADD R (cval (t)/u 1 ⊕ cval (t)/u 2 ))) = relab h (ADD h -1 (Edg(t↑u)) (ADD R (cval (t)/u 1 ⊕ cval (t)/u 2 ))) = relab h (relab p -(ADD (h -1 (Edg(t↑u))∪R) p (G 1 ⊕ G 2 ))) = relab h•p -(ADD (h -1 (Edg(t↑u))∪R) p (G 1 ⊕ G 2 )),
where

G 1 := ADD h -1 (Edg(t↑u)∪R (cval (t)/u 1 ) = ADD Edg(t↑u1) (cval (t)/u 1 ), and
G 2 := relab p (ADD h -1 (Edg(t↑u)∪R (cval (t)/u 2 )) = relab p (ADD Edg(t↑u2) (cval (t)/u 2 )), because R ∪ h -1 (Edg(t ↑ u)) = Edg(t ↑ u 1 ) = Edg(t ↑ u 2 )
. By the induction hypothesis, and the remark that ec(relab g (H)) = relab g (ec(H)) for all g and H, we have: ec(G 1 ) = cval ( t )/u 1 and ec(G 2 ) = cval ( t )/u 2 . By Claim 2.105.1, and the same remark, we have:

ec(ADD Edg(t↑u) (cval (t)/u)) = relab h•p -(ADD S (ec(G 1 ) ⊕ ec(G 2 ))) = relab h•p -(ADD S (cval ( t )/u 1 ⊕ cval ( t )/u 2 ))
which is equal to cval ( t )/u, as was to be proved. The proof is fully similar if u is an occurrence of ⊗ R,h that is a right son.

Hence, for t ∈ T (F κVR

C

) we have constructed a term t in T (F κVR C∪C ) that evaluates to the edge-complement of cval (t). It follows that for every p-graph G, cwd ( G) ≤ 2 • cwd (G). We have given a construction of t that can be done in linear time for each fixed set C.

For labelled graphs, we use one set Edg(t ↑ u) λ for each edge label λ, and we use operations ⊗ R,h where R is replaced by a family of binary relations on C, with one relation for each λ. We need no other auxiliary port labels than those in C . Vertex labels are not modified by the construction. Hence, we still have cwd ( G) ≤ 2 • cwd (G).

Many-sorted graph algebras

In order to minimize the underlying formal framework, we have defined F HR and F VR as signatures with a single sort. We now define many-sorted variants of these signatures, and we will turn JS and GP into many-sorted algebras.

The basic idea is to formalize at an abstract level the notion of type of an s-or p-graph that has emerged naturally from the initial definitions: in the case of JS, the type of an s-graph G is τ (G), the set of names of its sources and, in the case of GP, the type of a p-graph G is π(G), the set of labels of its ports. In each case, the class of all graphs with sources or ports is partitioned according to types, and the operations of the signatures are specialized accordingly. In the terminology of Section 1.2, the properties "G has type C" for C ∈ P f (A) form inductive sets relative to each of the signatures F HR and F VR . The type of an s-or p-graph will be its sort in the many-sorted formal framework. This technicality will be useful for dealing with derived operations, for defining equation systems and for defining the notion of recognizability.

Many-sorted algebras

Algebras with a single sort have been defined in Section 2.1 and are subsumed by the following definitions.

Definition 2.123 (Many-sorted algebras) Let S be a set of sorts. A functional S-signature is a set F of function symbols where each f ∈ F has an associated input type α(f ) in Seq(S) (the set of finite, possibly empty sequences of elements of S) and an output type σ(f ) in S. The length of α(f ) is the arity of f and is denoted by ρ(f ). A constant symbol is a symbol of arity 0. We let

F i := {f ∈ F | ρ(f ) = i}, F + := F -F 0 and ρ(F ) := max{ρ(f ) | f ∈ F }.
We say that F is finite if S and F are finite.

An F -algebra is an object M = (M s ) s∈S , (f M ) f ∈F where (M s ) s∈S is the family of domains of M and (f M ) f ∈F is its family of operations. The (possibly empty) sets M s are pairwise disjoint and for each f

, f M is a total function M α(f ) → M σ(f ) where M (s1,...,sn) denotes M s1 × • • • × M sn . We also say that f has type s 1 × • • • × s n → s if α(f ) = (s 1 , . . . , s n ) and σ(f ) = s. If α(f ) = () (the empty sequence), then f is a constant symbol and f M is an element of M σ(f ) called a constant of M. If M = (M s ) s∈S , (f M ) f ∈F is an F -algebra, we let M denote {M s | s ∈ S}. The sort σ(m) of an element m of M is the unique sort s such that m ∈ M s . A subset of M is homogenous if its elements all have the same sort. Each operation f M is a partial function : M ρ(f ) → M .
Dealing with partial functions is always a source of difficulties that is avoided by using sorts, whenever possible. But not every partial function g : A n → A can be expressed as f A for some many-sorted algebra A. As a counter-example, consider A = {0, 1} and g : A 2 → A such that g(0, 0) = 0, g(1, 1) = 1 and g is undefined for the other pairs of arguments.

Let F be an S-signature (we will frequently omit "functional"). A subsignature H of F is an S -signature such that S ⊆ S and every symbol of H is a symbol of F with the same input and output types as with respect to F . We write this H ⊆ F . If M is an F -algebra and N is an H-algebra, we say that N is a subalgebra of M, which we denote by

N ⊆ M, if H is a subsignature of F , N s ⊆ M s for every sort s of H and f N = f M N α(f ) for every f ∈ H.
For an F -algebra M and a subsignature F of F with set of sorts S , we define the subalgebra M F := (M s ) s∈S , (f M ) f ∈F of M. For a set of sorts S ⊆ S, we define the subsignature

F S := {f ∈ F | α(f ) ∈ Seq(S ), σ(f ) ∈ S } and the subalgebra M S := M (F S ). A homomorphism h : M → N where M and N are F -algebras is a mapping h : M → N such that h maps M s to N s for each s and h(f M (m 1 , . . . , m ρ(f ) )) = f N (h(m 1 ), . . . , h(m ρ(f ) )) for every (m 1 , . . . , m ρ(f ) ) in M α(f ) . 55 If h is a bijection, it is an isomorphism and M, N are isomorphic algebras. The Cartesian product M × N of F -algebras M and N is defined as the F - algebra (M s × N s ) s∈S , (f M×N ) f ∈F with f M×N ((m 1 , n 1 ), . . . , (m ρ(f ) , n ρ(f ) )) := (f M (m 1 , . . . , m ρ(f ) ), f N (n 1 , . . . , n ρ(f ) )) for every (m 1 , . . . , m ρ(f ) ) in M α(f ) and (n 1 , . . . , n ρ(f ) ) in N α(f ) .
Definition 2.124 (Terms over many-sorted signatures) Let F be an S-signature. For each s in S, let L s denote a subset of F * . The following system of |S| equations:

       . . . L s = f L α(f )[1] L α(f )[2] • • • L α(f )[ρ(f )] . . .
where, in each equation, the union extends to all f in F such that σ(f ) = s, has a unique solution because the unicity result of Proposition 3.15 is valid, even if the system has infinitely many equations. The component L s of the solution is the set of terms over F of sort s, denoted by

T (F ) s . If F is finite, then each language T (F ) s is context-free. We let T (F ) := {T (F ) s | s ∈ S}.
Even if F is infinite, these languages enjoy the same unambiguity of parsing as in the one-sorted case. The definition of the value of a term over F in an Falgebra M is the same as in the one-sorted case: the mapping val M maps T (F ) s to M s for each s in S, hence val M is a sort-preserving mapping from T (F ) to M . We also denote val

M (t) by t M . Let F ⊆ F . A subset of M is generated by F if it is a subset of val M (T (F )). The subalgebra of M generated by F is the subalgebra M with signature F such that M s = val M (T (F ) s ) for every sort s of F . (It is the smallest subalgebra of M with signature F ; it is empty if F has no constant symbols.) In particular, we say that M is generated by F if M s = val M (T (F ) s ) for every s ∈ S.
We say that it is finitely generated if it is generated by a finite subsignature of F ; this implies that S is finite.

We let

T(F ) denote the F -algebra (T (F ) s ) s∈S , (f T(F ) ) f ∈F of terms, where f T(F ) (t 1 , . . . , t ρ(f ) ) := f t 1 • • • t ρ(f ) for every f in F and (t 1 , . . . , t ρ(f ) ) in T (F ) α(f ) .
The evaluation mapping val M is the unique homomorphism from T(F ) to M, and for this reason the algebra T(F ) is called the initial F -algebra.

Definition 2.125 (Derived operations)

A set X is S-sorted if it is equipped with a mapping σ : X → S; for x ∈ X, we say that σ(x) is the sort of x. If X is an S-sorted set of variables and F is an S-signature, we denote by T (F, X) s the set of terms T (F ∪ X) s , and T (F, X) := T (F ∪ X). Note that if t belongs to T (F, X) -X, then the sorts of the variables having occurrences in t are determined in a unique way. Hence the mapping σ : X → S need not be specified if |X| ≥ 2 and all variables of X have occurrences in t.

Let the standard set of variables X n = {x 1 , . . . , x n } be S-sorted (but the following definitions extend in an obvious way to a set X of n variables, linearly ordered in some specified or implicit way). In every

F -algebra M, a term t in T (F, X n ) s defines a total function: M σ(x1) × • • • × M σ(xn) → M s denoted by t M and
called a derived operation of M. Its definition is the same as for onesorted algebras, and it will also be denoted by λm

1 , . . . , m n • t M (m 1 , . . . , m n ), or by λx 1 , . . . , x n • t if M is clear from the context. It is linear if t is linear (see Definition 2.5) and it is strict if every x i ∈ X n has an occurrence in t.
An extended derived operation is an n-ary function g defined from an n + k-ary derived operation t M and k fixed elements a 1 , . . . , a k of M of appropriate sorts, by g(m 1 , . . . , m n ) := t M (m 1 , . . . , m n , a 1 , . . . , a k ). If a 1 , . . . , a k are the values of terms t 1 , . . . , t k ∈ T (F ), then g is a derived operation defined by the term t[t i /x n+i ; i ∈ [k]] (cf. Definition 2.6 for the substitution of terms).

It will be useful to extend the signature of an algebra M by adding derived operations designated by new symbols. Here is a more precise definition. Let F be an S-signature. A derived operation declaration is a 4-tuple g, w, s, t g consisting of -a symbol g possibly in F , which is the name of the declared operation, -a sequence w in Seq(S), its input type, denoted by α(g), -an element s of S, its output type, denoted by σ(g), -and a term t g in T (F, X n ) s , called its defining term, written with the symbols of F and the standard set of variables

X n = {x 1 , . . . , x n } which is S-sorted such that (σ(x 1 ), . . . , σ(x n )) = α(g).
If g ∈ F , we impose that α(g) and σ(g) are as in F and that t g = g(x 1 , . . . , x n ). An operation g, α(g), σ(g), t g is linear if the term t g is linear, i.e., if each variable x i has at most one occurrence in t g . This operation is strict if x i has at least one occurrence in t g for each i = 1, . . . , n, where n = |α(g)|.

A derived signature of F is a set H of derived operation declarations such that no two of them have the same name. (A variable x i may have different sorts in different declarations.) It is an S-signature. We say that H is linear and/or strict if all its operations are.

Let M be an F -algebra. For given H, and in order to simplify notation, we identify a derived operation declaration g, α(g), σ(g), t g with its name g, and we denote by g M the derived operation (t g ) M : M α(g) → M σ(g) . From a derived signature H of F and an F -algebra M, we obtain the H-algebra M H = (M s ) s∈S , (g M ) g∈H . Such an algebra is called a derived algebra of M.

The next proposition shows that the derived operations of M H are derived operations of M. For every term t in T (H, Y m ) s (where Y m is the S-sorted standard set of variables {y 1 , . . . , y m }), we let θ H (t) in T (F, Y m ) s be the term obtained from t by substituting for each function symbol g in t its defining term t g . Formally:

θ H (y i ) = y i θ H (g(t 1 , . . . , t n )) = t g [θ H (t 1 )/x 1 , . . . , θ H (t n )/x n ] where i ∈ [m], t g ∈ T (F, X n ) σ(g) and t j ∈ T (F, Y m ) σ(xj ) for j ∈ [n]. We recall that • • • [• • • /x 1 , . . . , • • • /x n ]
denotes the substitution of terms for (first-order) variables; its semantic meaning is explained in Definition 2.6. The mapping θ H is a second-order substitution 56 . If H is linear, then the mapping θ H can be computed in linear time. (By a bottom-up computation on t, one can construct the syntactic tree of θ H (t) and then, by depth-first traversal of this tree, one can obtain θ H (t) itself. Both steps can be done in linear time. For further processing, the syntactic tree of θ H (t) is actually more useful than (the word) θ H (t).) Proposition 2.126 Let H be a derived signature of a signature F and let M be an F -algebra. For every term t in T (H, Y m ), we have t M H = (θ H (t)) M .

Proof: Straightforward induction on the structure of t.

Definition 2.127 (Effectively given many-sorted algebras) We extend Definition 2.8 to many-sorted algebras. To be encoded and (semi-) effectively given, sets of sorts, signatures and algebras must be finite or countable.

An S-sorted signature F is effectively given if the sets S and F are effectively given, and the input and output type mappings α and σ are computable (and algorithms computing these mappings must be specified, cf. Definition 2.8). It implies that the arity mapping is computable.

An F -algebra M is semi-effectively given if the signature F is effectively given, the set M is semi-effectively given, the sort mapping σ : M → S is computable and the operations of M are computable in a uniform way by the mapping ζ M as in Definition 2.8 (and algorithms computing these mappings 56 In Formal Language Theory, terms are usually called "trees", and the mapping θ H is called a tree homomorphism, cf. [*Com+] Section 1.4. It reduces to a word homomorphism if F = F 1 and H = H 1 (cf. Definition 2.7). If tg = f (x 1 , . . . , x ρ(g) ) for every g, then the mapping θ H replaces function symbols by function symbols of the same arity. Such a mapping is called an alphabetic relabelling. must be specified). It is effectively given if, additionally, M is effectively given (i.e., |M | is specified) and the mapping s → |M s | from S to N ∪ {ω}, that defines the cardinality of M s for each s in S, is computable (and an algorithm computing it must be specified).

As in the one-sorted case, if F is effectively given, then the algebra T(F ) is semi-effectively given and the mapping val M is computable. If F generates M, then a computable mapping can determine for each element of M a term in T (F ) that evaluates to it.

If M is (semi-)effectively given, then the domains M s are decidable subsets of M because the sort mapping σ of M is computable, and hence they are (semi-)effectively given by their standard encodings (see Definition 2.8). From a specification of M, an algorithm can be constructed that, on input s ∈ S, computes a specification of M s .

It is easy to check that the Cartesian product of two (semi-)effectively given algebras M and N is (semi-)effectively given, using the standard encoding of M × N . A specification of the product algebra can be constructed from those of M and N.

A derived signature H of an S-signature F can be viewed as a pair H = H • , δ H where H • is an ordinary S-signature and δ H is a mapping :

H • → T (F, X × S) such that X × S is the S-sorted set of variables with X := {x 1 , x 2 , . . . } and σ( x i , s ) = s for every x i , s ∈ X × S, and such that for every g ∈ H • of type s 1 × • • • × s n → s we have δ H (g) ∈ T (F, { x 1 , s 1 , . . . , x n , s n }) s . If g, w, s, t g is a derived operation declaration in H, then g ∈ H • with α(g) = w and σ(g) = s, and δ H (g) = t g [ x 1 , w[1] /x 1 , . . . , x n , w[n] /
x n ] with n := |w|; note that (δ H (g)) M = (t g ) M for every F -algebra M. We say that the derived signature H is effectively given if F and H • are effectively given and δ H is computable (and an algorithm computing it must be specified).

The many-sorted HR algebra

Although the operations of the algebra JS are total, we turn this algebra into a many-sorted one. We write definitions and statements for unlabelled graphs only. The extension to labelled graphs is straightforward since the only modifications for this extension concern the constant symbols and the associated basic graphs.

Definition 2.128 (Turning F HR into a many-sorted signature) As in Section 2.3, we let A be the countable set of source names. We let S := P f (A) be the countable set of sorts. For each C ∈ S, we let J S C be the set57 {G ∈ J S | τ (G) = C}. This set will be the domain of sort C of the many-sorted HR algebra. We now define the operations of that algebra. (c) If C, D ∈ S and h is a bijection : C → D, then we let ren h,C of type C → D be the restriction to J S C of ren h where h is the permutation of C ∪ D that extends h and is defined in Lemma 2.37.

(d) If a constant symbol in F HR defines an s-graph of type C, then we let its sort be C.

Hence we have defined an S-signature that we will denote by F tHR . The associated F tHR -algebra JS t has domains J S C for each C ∈ S and its operations have been defined above as restrictions of operations of JS. Clearly, both F tHR and JS t are effectively given. If E is a finite set of source labels, we let JS t [E] be the subalgebra of JS t with the finite set of sorts P(E), with domains J S C for C ⊆ E, and the operations of

F tHR restricted to C, D ⊆ E (cf. (a)-(d) above).
To be precise, these operations are C,D , fg B,C for B ⊆ C, ren h,C for h such that h(C) ⊆ E and the constant symbols defining s-graphs of type included in E. This finite signature is denoted by 1)).

F tHR E . It generates the subalgebra JS t,gen [E] of JS t [E] (cf. Remark 2.39(
We will compare the derived operations of JS and of JS t , and in particular, the terms of T (F HR ) and T (F tHR ) that all evaluate to s-graphs in J S.

Definition 2.129 (Untyping)

We recall that X n is the standard set of variables {x 1 , . . . , x n }, now assumed to be P f (A)-sorted. Untyping is the mapping Unt : T (F tHR , X n ) → T (F HR , X n ) that omits subscripts relative to sorts. Formally:

Unt(t) := t if t is a constant symbol or a variable (in X n ), Unt(t 1 C,D t 2 ) := Unt(t 1 ) Unt(t 2 ), Unt(fg B,C (t)) := fg B (Unt(t)), Unt(ren h,C (t)) := ren h (Unt(t)),
where in the last case, h is a bijection : C → h(C) and h is the permutation of C ∪ h(C) that extends h and is defined in Lemma 2.37.

Proposition 2.130 For every term t in T (F tHR , X n ) the mapping Unt(t) JS : J S n → J S extends the mapping

t JS t : J S σ(x1) × • • • × J S σ(xn) → J S σ(t) .
If n = 0, then Unt(t) JS and t JS t are the same s-graph in J S σ(t) .

Proof: By induction on the structure of t; straightforward from the definitions.

We now consider an inverse typing mapping.

Definition 2.131 (Typing) Let the variables x 1 , . . . , x n of X n have respective sorts β(x 1 ), . . . , β(x n ) in P f (A). We define two mappings on T (F HR , X n ), denoted by σ and Typ, whose respective values are a sort and a term in T (F tHR , X n ). They are defined as follows:

σ(x i ) := β(x i ), σ(c) := τ (c JS ) if c is a constant symbol, σ(t 1 t 2 ) := σ(t 1 ) ∪ σ(t 2 ), σ(fg B (t)) := σ(t) -B, σ(ren h (t)) := h(σ(t)), Typ(t) := t if t is a constant symbol or a variable, Typ(t 1 t 2 ) := Typ(t 1 ) σ(t1),σ(t2) Typ(t 2 ), Typ(fg B (t)) := fg B∩σ(t),σ(t) (Typ(t)), Typ(ren h (t)) := ren h ,σ(t) (Typ(t)),
where in the last case,

h := h σ(t) (hence h is a bijection : σ(t) → h(σ(t)) ).
The term Typ(t) may contain operations of the form fg ∅,C or ren h,C such that h is the identity on C. Such operations define identity mappings on J S C and hence can be deleted from the term Typ(t). Note that σ and Typ depend on the mapping β that assigns sorts to variables; we write them σ β and Typ β if we need to make this dependency explicit. Note also that σ(t) = τ (t) for t ∈ T (F HR ) (see Definition 2.35).

Proposition 2.132 Let β assign sorts to the variables of X n . For every term t in T (F HR , X n ) and all s-graphs G 1 , . . . , G n of respective types β(x 1 ), . . . , β(x n ) we have:

(1) τ (t JS (G 1 , . . . , G n )) = σ β (t), (2) Typ β (t) ∈ T (F tHR , X n ) σ β (t) , (3) Typ β (t) JS t (G 1 , . . . , G n ) = t JS (G 1 , . . . , G n ).
If n = 0, then the mappings σ β and Typ β do not depend on β, and we have:

(4) τ (t JS ) = σ(t), (5) Typ(t) ∈ T (F tHR ) σ(t) , (6) Typ(t) JS t = t JS .
Proof: As for the previous proof, by a straightforward induction on the structure of t.

Note that Unt(Typ(t)) = t for every term t in T (F HR ) where t is the reduced term of Proposition 2.38. Note also that the mappings Unt and Typ can be computed in linear time by straightforward implementations of their inductive definitions.

We now consider the restriction of these definitions and results to s-graphs of type included in some finite subset E of A. It is clear (by a quick inspection) that, for every finite set E of source names, all definitions of this section can be adapted (let us say restricted ) to s-graphs of type included in E, to the finite signatures F HR )) = val (T (F HR C )), hence, that the width of an s-graph is the same whether it is defined with respect to F tHR or to F HR (cf. Section 2.4.5).

Example 2.133 (Series-composition) We recall from Section 1.1.3 that, for directed s-graphs, series-composition maps J S

[2] × J S [2] to J S [2]
.58 As observed in Section 1.4.2, it can be defined by the term t = fg 3 (ren 2↔3 (x 1 ) ren 1↔3 (x 2 )) over F HR . The corresponding binary derived operation t JS applies to any two s-graphs G, H given as arguments. However, it corresponds to the graph-theoretical series-composition only if G and H both have type {1, 2}. The term t = fg 4 (ren 2↔4 (x 1 ) ren 1↔4 (x 2 )) defines the same binary operation on J S [2] . But t JS = t JS , as one checks by considering s-graphs of type {1, 2, 3}. With the above definitions, we can see that series-composition is Typ β (t) JS t as well as Typ β (t ) JS t where β assigns sort {1, 2} to x 1 and to x 2 . It is clear that σ β (t) = σ β (t ) = {1, 2}. The term Typ β (t) looks as follows:

fg 3,{1,2,3} (ren 2↔3,{1,2} (x 1 ) {1,3},{2,3} ren 1↔3,{1,2} (x 2 )).
Let us abbreviate {1, 2} by s. If H is the set of derived operation declarations consisting of •, (s, s), s, Typ β (t) , , (s, s), s, x 1 s,s x 2 and e, (), s, -→ 12 , then H is a derived signature of (the directed version of) F tHR , and the (one-sorted) subalgebra JS t H {s} of the derived H-algebra JS t H is equal to the algebra J d 2 of Section 1.1.3. The domain of the subalgebra of J d 2 generated by its signature H {s} is the set of series-parallel graphs.

The following example anticipates on Chapters 3 and 4 where we will study in detail the equation systems introduced in Section 1.1.4.

Example 2.134 We consider the equation written with the series-composition operation • that is defined by the term t of Example 2.133 (not the one defined by Typ β (t)):

X = (X X) ∪ (X • X) ∪ fg 1 (X) ∪ fg 2 (X) ∪ {e} (2.7)
where e is the constant symbol -→ 12 with value 1• → •2. The variable X ranges over sets of s-graphs. It is not hard to see that all graphs in the set L defined as the least solution in P(J S) of Equation (2.7), have types ∅, {1}, {2} or {1, 2}. Since they have no other type like {1, 2, 3}, series-composition can be defined in this equation by t as well as by t (these terms are defined in Example 2.133). If we impose a "type discipline", we cannot use this equation. Equation systems relative to many-sorted signatures are defined so that all terms in an equation have the same sort, and this is not the case for Equation (2.7). However, by using the method of Section 1.2.5 and the observation that types have an "inductive behaviour", we can transform Equation (2.7) into a system of equations over F tHR . In what follows we write 12 for {1, 2}, 1 for {1}, 2 for {2}, and 0 for ∅. For

s 1 , s 2 ∈ {0, 1, 2, 12} we define • s1,s2 := Typ β (t) with β(x i ) := s i for i = 1, 2; it is the restriction of • to J S s1 × J S s2 . For s ∈ {0, 1, 2, 12} we let L s := {G ∈ L | τ (G) = s}.
These sets L s satisfy the following equations:

L 12 = L 12 12,12 L 12 ∪ L 1 1,12 L 12 ∪ L 2 2,12 L 12 ∪ L 0 0,12 L 12 ∪ L 1 1,2 L 2 ∪ L 12 • 12,12 L 12 ∪ L 12 • 12,2 L 2 ∪ L 1 • 1,12 L 12 ∪ L 1 • 1,2 L 2 ∪ {e}, L 1 = L 1 1,1 L 1 ∪ L 1 1,0 L 0 ∪ L 12 • 12,1 L 1 ∪ L 12 • 12,0 L 0 ∪ L 1 • 1,1 L 1 ∪ L 1 • 1,0 L 0 ∪ fg 2 (L 12 ).
In writing these equations we use the fact that is commutative and we let set union have lower priority than the other binary operations. Similar equations can be written for L 2 and L 0 . We obtain thus a "typed" system of four equations written over F tHR , the least solution of which in P(J S)

is the 4- tuple (L 12 , L 1 , L 2 , L 0 ). Then L = L 12 ∪ L 1 ∪ L 2 ∪ L 0 . Equation (2.7
) is clearly much shorter and more readable than this system. In general, for every untyped equation system, the types of the s-graphs it defines are not immediate from the syntax but can be computed by an algorithm. We will discuss this aspect in Chapter 4, Proposition 4.10.

The many-sorted VR algebra

The definitions and results of the previous section can be adapted to the signature F VR , to the algebra GP and to their restrictions F VR E and GP[E] for a finite set E of port labels in a straightforward way.

The relevant notion of type of a p-graph G is π(G) = port G (V G ) and will be the sort of G. Hence the set of sorts is S := P f (A), as in the case of JS t . For each C ∈ S, we let GP C be the set

{G ∈ GP | π(G) = C}.
→ C. Since --→ add a,b (G) = G if {a, b} is not included in π(G), we need not consider --→ add a,b,C
or add a,b,C for that case. The unary operation relab g for g ∈ [A → A] f yields unary operations relab h,C with h = g C, of type C → h(C); thus, there is an operation relab h,C for every mapping h : C → A. Finally the constants a, a (used to define abstract p-graphs) and a(x), a (x) (for defining concrete p-graphs) are of sort {a}, and the constant ∅ has sort ∅.

We obtain in this way S-signatures F tVR and F tcVR and a many-sorted F tVR -algebra denoted by GP t . We obtain also subalgebras GP t [E] and GP t,gen [E] of GP t by restriction to p-graphs with port labels in a set E, and in the latter case to p-graphs that are defined by terms over F tVR E . Definitions 2.129 and 2.131 and Propositions 2.130 and 2.132 have analogs that are easy to spell out. As in the case of the HR algebra, we have that val

(T (F tVR C )) = val (T (F VR C ))
, hence, that the clique-width of a p-graph is the same whether it is defined with respect to F tVR or to F VR . The extensions to labelled p-graphs are also straightforward.

The literature about tree-width, clique-width and related complexity measures is expanding each year by scores of articles and communications to conferences. Concerning tree-width, the articles by Bodlaender et al. [*Bod93,[START_REF] Bodlaender | A partial k-arboretum of graphs with bounded treewidth[END_REF][START_REF] Bodlaender | A linear-time algorithm for finding treedecompositions of small treewidth[END_REF] and [BodGHK] cover the main results. The situation concerning cliquewidth is much less "stable", however, [*KamLM] surveys recent results about clique-width.

Whereas a graph class has bounded tree-width if and only if it excludes a fixed planar graph as a minor (Proposition 2.61), there is no such clear-cut result characterizing bounded clique-width. Undirected graphs excluding P 4 as an induced subgraph have clique-width at most 2. Many efforts have been devoted to finding generalizations of this result. The undirected graphs, every induced subgraph of which with q vertices has at most q -3 induced paths isomorphic to P 4 , have clique-width at most q if q ≥ 7 and unbounded cliquewidth if q ∈ {4, 5, 6} ( [MakRot]).

A complete classification of graph classes defined by excluding one or more 4-vertex graphs as induced subgraphs is established in [BraELL]: in each case, either an upper-bound to the clique-width is given or a proof that the cliquewidth is unbounded. A similar classification is presented in [BraDLM] for graph classes defined by excluding one or more 1-vertex extensions of P 4 . For having a class of bounded clique-width, one must exclude at least two such graphs, for instance 1 ⊕ P 4 and 1 ⊗ P 4 , yielding clique-width at most 16. Excluding P 5 and 1 ⊗ P 4 yields clique-width at most 5 but excluding 1 ⊕ P 4 and P 5 yields no bound on the clique-width.

Unit interval graphs have unbounded clique-width [GolRot] but every hereditary proper class of unit interval graphs (i.e., closed under taking induced subgraphs and not containing all unit interval graphs) has bounded clique-width ( [Loz]).

It is not yet completely clear what properties imply that a class of graphs has bounded clique-width. Lower bounds to clique-width are difficult to establish: some tools are given in [CorRot, GolRot, MakRot]. By indirect arguments using monadic second-order transductions (Chapter 7), one can sometimes prove quickly that a class of graphs has unbounded clique-width without obtaining a specific lower bound for the clique-width of particular graphs of this class.

The first article introducing the notion of a term evaluating to a graph and the algebraic view of context-free graph grammars is [BauCou], where such terms are called graph expressions. The grammars in [BauCou] are based on rewriting by Hyperedge Replacement; this notion will be presented in Section 4.1.5 (see also Section 4.6). The signature F HR , first defined in [START_REF] Courcelle | Graph grammars, monadic second-order logic and the theory of graph minors[END_REF], simplifies the one defined in [BauCou] and yields the exact characterization of tree-width (Theorem 2.83). The one of [BauCou] yields no such characterization.

The notion of clique-width is implicit in [CouER] where graph operations are defined for giving an algebraic formulation of certain context-free graph grammars that are based on rewriting by hyperhandle replacement, where a hyperhandle is a hyperedge together with its incident vertices. It is shown in [CouER] that these grammars have the same power as context-free Vertex Replacement graph grammars (technically called C-edNCE graph grammars59 , see the book chapter [*EngRoz] for a detailed exposition). Clique-width is defined and studied in [CouOla]. The closely related notion of NLC-width (denoted by nlcwd ) has been introduced in [Wan]. The graph operations defined in this article model the rewriting mechanism of NLC graph grammars60 . NLC-width and clique-width are related by cwd (G) ≤ nlcwd (G) ≤ 2 • cwd (G), and these inequalities are proved by effective linear time transformations. It follows that the same sets of graphs have bounded clique-width and NLC-width.

A variant of clique-width can be defined by allowing vertices to have several port labels from a finite set C. This variant is used in [CouOla] as an auxiliary notion, and in a more important way, in [CouTwi] where a result corresponding to Proposition 2.103 is proved. The proof of Proposition 5.4 of [CouOla] is incorrect. It shows that, roughly speaking, if the "width" of a graph is k with respect to the operations of F VR generalized so as to handle multiple labels, then its clique-width is at most 2 k . The idea is to encode a set of at most k labels attached to a vertex by a single label. An operation add a,b is then replaced by the composition of the operations add A,B such that a ∈ A and b ∈ B, where A and B are (or encode) subsets of C. This is incorrect because one should have A = B in add A,B . Proposition 2.119 "fixes the bug" and yields the bound of 2 k+1 instead of 2 k . This proposition is used for proving Theorem 5.5 of [CouOla] (cf. Proposition 2.114, Footnote 52) but, in the particular terms used in this proof, the operations add A,A do not occur, hence this proof is correct.

The notion of modular decomposition (also called substitution decomposition) is surveyed in [*MöhRad] and presented with another terminology in [*EhrHR]. A corresponding algebra of graphs is studied in [START_REF] Courcelle | The monadic second-order logic of graphs X: Linear orderings[END_REF], [CouWei] and [LodWei].

Many-sorted algebras are presented in detail in the book [*Wec]. Secondorder substitutions are studied in the survey article [*Cou83].

Chapter 3

Equational and recognizable sets in many-sorted algebras

This chapter deals with many-sorted algebras in general. We define and study their equational and recognizable sets. These algebras may have infinitely (but countably) many sorts and operations. The use of infinite signatures, even in the case of a single sort, is motivated by the intended applications to the graph algebras JS and GP. In the framework of these two algebras, equational and recognizable sets of graphs will be studied in Chapter 4. We will pay special attention to effectivity questions: in view of the algorithmic applications, the equational and recognizable sets must be specified in finitary ways.

Here are the summary and the main results of this chapter. In Section 3.1 we define the equational sets of a many-sorted algebra; the definition is based on the well-known Least Fixed-Point Theorem; the context-free languages and the regular sets of terms form the motivating examples. An easy but fundamental result is that the image of an equational set under an algebra homomorphism is equational. In Section 3.2 we present some tools to transform and simplify equation systems, and we define derivation trees. We conclude with observations on the usefulness of equation systems and we compare them with closely related specification devices. Section 3.3 is a review of definitions and basic results about automata on terms (usually called tree automata, and assumed to be known from, e.g., [*Com+] or [*GecSte]). Section 3.4 introduces the recognizable sets of a many-sorted algebra; several equivalent definitions are given in terms of homomorphisms, of congruences and of inductive sets of predicates. (The latter definition has a clear intuitive meaning for the verification of properties of the elements of equational sets). The regular languages and the regular sets of terms form the motivating examples. Several types of effective specifications of recognizable sets are defined and compared. The main closure result states that the intersection of an equational and a recognizable set is equational, with an effective construction. It generalizes the classical result that the intersection of a context-free and a regular language is context-free, and it will be essential for the applications to graphs. We conclude the section with a discussion of recognizability.

The equational sets of an algebra

Algebras and many-sorted algebras are defined in Sections 2.1 and 2.6.1.

Powerset algebras

In order to specify by equations certain subsets of algebras, we extend their operations to their powersets.

Definition 3.1 (Powerset algebras)

Let F be an S-signature. We enlarge it into F ∪ by adding, for every sort s in S, a new symbol ∪ s of type s × s → s and a new constant Ω s of sort s. With an F -algebra M, we associate its powerset algebra:

P(M) := (P(M s )) s∈S , (f P(M) ) f ∈F∪ where Ω sP(M) := ∅, A 1 ∪ sP(M) A 2 := A 1 ∪ A 2 for A 1 , A 2 ⊆ M s , f P(M) (A 1 , . . . , A k ) := {f M (a 1 , . . . , a k ) | a 1 ∈ A 1 , . . . , a k ∈ A k } for A i ⊆ M si where α(f ) = (s 1 , . . . , s k ).
Hence P(M) is an F ∪ -algebra (let us not worry that ∅ has several sorts1 ). An F ∪ -algebra of the form P(M) as above will be called a powerset F-algebra. Its operations are monotone, which means that if

f ∈ F ∪ has type s 1 × • • • × s k → s and A i ⊆ B i ⊆ M si for each i, then f P(M) (A 1 , . . . , A k ) ⊆ f P(M) (B 1 , . . . , B k ).
They are even additive:

if A i = j∈J B j , then f P(M) (A 1 , . . . , A i , . . . , A k ) = j∈J f P(M) (A 1 , . . . , A i-1 , B j , A i+1 , . . . , A k ).
We recall from Definition 2.5 that X n , Y k denote standard sets of variables, respectively {x 1 , . . . , x n } and {y 1 , . . . , y k }. For every term t ∈ T (F, X n ) s where X n is S-sorted and s ∈ S, we obtain a derived operation of M, denoted by t M , and also a derived operation of P(M), denoted by t P(M) , that maps

P(M σ(x1) ) × • • • × P(M σ(xn) ) into P(M s )
. The operations t P(M) are monotone. This follows from the monotonicity of the operations of P(M) and an induction on the structure of t.

In the following lemma which relates these derived operations, we write

t = t [x i1 /y 1 , . . . , x i k /y k ] for some term t in T (F, Y k ) such that ListVar ( t ) = y 1 • • • y k , cf. Definition 2.6.
There is actually a unique term t satisfying these conditions. The sort of y j is necessarily σ(x ij ).

Lemma 3.2 For all A 1 , . . . , A n with A i ⊆ M σ(xi) for i = 1, . . . , n, we have:

(1) t P(M) (A 1 , . . . , A n ) ⊇ {t M (a 1 , . . . , a n ) | a 1 ∈ A 1 , . . . , a n ∈ A n };
(2) equality holds in (1) if, for every i = 1, . . . , n, |A i | ≤ 1 whenever the variable x i has more than one occurrence in t, and A i = ∅ whenever x i has no occurrence in t.

(3) t P(M) (A 1 , . . . , A n ) = ∅ if for some i, we have A i = ∅ and x i has at least one occurrence in t.

(

) t P(M) (A 1 , . . . , A n ) = { t M (a 1 , . . . , a k ) | a 1 ∈ A i1 , . . . , a k ∈ A i k }. 4
Proof: By induction on the structure of t. For proving (4) we observe that

t P(M) (A 1 , . . . , A n ) = t P(M) (A i1 , . . . , A i k ) and we use (2).
The inclusion in ( 1) may be strict: if L ⊆ A * is a language consisting of at least two words and t =

x 1 • x 1 , then t = y 1 • y 2 (with i 1 = i 2 = 1) and L • L = t P(W(A)) (L) = t P(W(A)) (L, L) = { t W(A) (w 1 , w 2 ) | w 1 , w 2 ∈ L} = {w 1 • w 2 | w 1 , w 2 ∈ L} ⊃ {w 2 | w ∈ L} = {t W(A) (w) | w ∈ L}
where the word algebra W(A) is defined in Definition 2.7. This also shows that, in general, t P(M) is not additive.

Two terms t and t in T (F ∪ , X n ) are equivalent in P(M) which is denoted by t ≡ P(M) t , if t P(M) = t P(M) . They are P-equivalent, denoted by t ≡ P t , if t ≡ P(M) t for every F -algebra M.

Definition 3.3 (Polynomials)

Let F be an S-signature, let X be an S-sorted set of variables and let s ∈ S. A monomial is a term in T (F, X). A polynomial of sort s is a term in T (F ∪ , X) s of the form either Ω s , or t 1 , or t 1 ∪ s • • • ∪ s t p for some pairwise distinct monomials t 1 , . . . , t p ∈ T (F, X) s with p ≥ 2. We denote by Pol (F, X) s the set of polynomials of sort s, built with F, ∪ s , Ω s and X, and by Pol (F, X) the union of the sets Pol (F, X) s for all sorts s. We use infix notation for the binary symbol ∪ s and we omit parentheses (as explained in Definition 2.4). We can do so since it denotes set union which is associative. We will frequently omit the subscript s in ∪ s and Ω s .

If D is a finite subset of T (F, X) s , D = {t 1 , . . . , t q }, we will denote by D the polynomial

t 1 ∪ t 2 ∪ • • • ∪ t q .
Since set union is commutative, we make the convention that D is the same polynomial for every enumeration of D. If q = 0, then D = Ω, and if q = 1, then D = t 1 . We will say in all cases that this polynomial is the union of the set of terms D, even if |D| ≤ 1. For every t ∈ T (F ∪ , X), we define the set of monomials of t, a subset of T (F, X) called its expansion and denoted by Mon(t):

Mon(x) := {x} for x ∈ X, Mon(Ω) := ∅, Mon(t 1 ∪ t 2 ) := Mon(t 1 ) ∪ Mon(t 2 ), Mon(f (t 1 , . . . , t k )) := {f (m 1 , . . . , m k ) | m i ∈ Mon(t i ), 1 ≤ i ≤ k}.
Using the additivity of the operations of P(M), it is easy to show by induction on the structure of t that for all A 1 , . . . , A n with A i ⊆ M σ(xi) for i = 1, . . . , n, we have:

t P(M) (A 1 , . . . , A n ) = {m P(M) (A 1 , . . . , A n ) | m ∈ Mon(t)}.
Lemma 3.4 Every term t is P-equivalent to the polynomial Mon(t).

Definition 3.5 (Homomorphisms of powerset algebras)

Let F be an S-signature, M and N be two F -algebras and h : M → N be a homomorphism. We let P h : P(M) → P(N) be defined by:

P h(A) := h(A) = {h(a) | a ∈ A} ⊆ N s
for every s ∈ S and A ⊆ M s . It is a homomorphism of F ∪ -algebras. (We use the notation P h to stress that this mapping is a homomorphism of F ∪ -algebras.)

Equation systems and equational sets

We now define equation systems and their solutions in powerset algebras.

Definition 3.6 (Equation systems)

Let S be a set of sorts and F be an S-signature. Let X be a finite S-sorted set of variables. An equation is an ordered pair (x, t) such that x ∈ X and t ∈ T (F ∪ , X) σ(x) . It will be written x = t and will be said to define x. An equation system over F with set of unknowns X is a set of equations consisting of one equation that defines each unknown. The set of unknowns of an equation system S is denoted by Unk (S). It will be useful to assume that the set Unk (S) is linearly ordered. In most cases, it will be the standard set X n = {x 1 , . . . , x n } ordered by increasing indices. The sorts of these unknowns are not fixed, they are specified by a mapping σ : X n → S, depending on the considered system. The generic equation system S over F is thus denoted by:

S = x 1 = t 1 , . . . , x n = t n (3.1)
In examples, it will also be written as follows, in a more readable way:

     x 1 = t 1 . . . x n = t n
Here is for example an equation system T (with ρ(f ) = 2 and ρ(a) = ρ(b) = 0):

     x 1 = f x 1 (x 2 ∪ x 3 ) ∪ a x 2 = x 1 ∪ f x 1 a x 3 = f (x 1 ∪ x 2 )x 3 ∪ b
We denote by F (S) the finite subsignature of F consisting of the symbols having occurrences in S. Its set of sorts is the finite set Sort(S) consisting of all sorts of S that occur as σ(f ) or in the sequence α(f ) for some f in F (S), together with the sorts of the unknowns of S. (We may have in S an equation x = x ∪ y where the common sort of x and y does not occur in the type of any symbol in F (S). In this case, x defines the empty set because the corresponding component of the least solution of S is empty). Hence S is an equation system over F (S); in fact, F (S) is the smallest subsignature F of F such that S is an equation system over F . As an example, F (T ) = {f, a, b} for the above system T .

A polynomial system is an equation system whose equations have righthand sides that are polynomials. A polynomial system is uniform if each monomial of the righthand side of an equation has exactly one occurrence of a function symbol (hence is of the form f (x i1 , . . . , x i k ) for f ∈ F k ). It is quasi-uniform if each such monomial has at most one occurrence of a function symbol (hence can also be an unknown).

Let M be an

F -algebra. A solution of S in P(M) is an n-tuple (L 1 , . . . , L n ) such that L i ⊆ M σ(xi) and L i = t iP(M) (L 1 , . . . , L n ) for each i = 1, . . . , n. We say that (L 1 , . . . , L n ) is an oversolution of S if L i ⊇ t iP(M) (L 1 , . . . , L n ) for each i.
We will mainly be interested in the least solution (that turns out to be also the least oversolution), where n-tuples of sets are ordered componentwise:

(L 1 , . . . , L n ) ⊆ (L 1 , . . . , L n ) if and only if L j ⊆ L j for each j. A solution (L 1 , . . . , L n ) is the least solution if and only if (L 1 , . . . , L n ) ⊆ (L 1 , . . . , L n ) for every solution (L 1 , . . . , L n ),
and it is unique with this minimality property; similarly for the least oversolution.

If S = x 1 = t 1 , . . . , x n = t n is another system over F such that t i ≡ P t i for each i = 1, . . . , n, then S and S have the same solutions and the same oversolutions in P(M), hence also the same least solution. In particular, Lemma 3.4 says that each term t in T (F ∪ , X) is P-equivalent to a polynomial. Hence, if we replace in an equation system S each righthand side of an equation by an equivalent polynomial, we obtain a polynomial system that has the same solutions and oversolutions as S. For example, here is the (quasi-uniform) polynomial system T associated with the above system T :

     x 1 = f x 1 x 2 ∪ f x 1 x 3 ∪ a x 2 = x 1 ∪ f x 1 a x 3 = f x 1 x 3 ∪ f x 2 x 3 ∪ b
Hence there is no loss of generality in considering only polynomial systems, which we will do in the sequel.

It is convenient to order linearly the set of variables of an equation system, but this order is essentially irrelevant: if a system S is obtained from a system S by permuting its equations, hence by changing the ordering of Unk (S), then its solutions and its oversolutions are obtained from those of S by permuting their components. In particular, if we are interested in the set associated with a particular unknown, there is no loss of generality in assuming that this unknown is x 1 .

We will be interested in the least solutions of equation systems, because we consider them as systems of mutually recursive definitions. An equation in languages, for instance x = axx ∪ b where a, b are letters and the unknown x denotes a language over {a, b}, can be seen as a recursive definition of a language. More generally, an equation system is a set of mutually recursive definitions. Such systems may have several solutions. For instance, the equation y = yy ∪ a has for solutions the languages a * (= {a} * ), a + (= aa * ), {a, b} * and {a, bb} * among others. However, a + is the (unique) least solution. As in Semantics for defining the meaning of a recursive definition, we will take the least solution as the (canonical) solution.

With every system S as in (3.1), we associate a function S P(M) that maps

P(M σ(x1) ) × • • • × P(M σ(xn)
) into itself and is defined by:

S P(M) (L) := (t 1P(M) (L), . . . , t nP(M) (L))
where L stands for (L 1 , . . . , L n ). A solution (resp. an oversolution) of S in P(M) can also be defined as a solution of the equation x = S P(M) (x) (resp. of the inequation x ⊇ S P(M) (x)) where x stands for (x 1 , . . . , x n ). They are called respectively a fixed-point of the function S P(M) and a pre-fixed-point of this function.

A sequence of n-tuples (L

(i) 1 , . . . , L (i) n ) i∈N is increasing 2 if (L (i) 1 , . . . , L (i) n ) ⊆ (L (i+1) 1 , . . . , L (i+1) n
) for every i ∈ N . It has a least upper-bound (for componentwise inclusion) denoted like a union and defined by:

i∈N (L (i) 1 , . . . , L (i) n ) := ( i∈N L (i) 1 , . . . , i∈N L (i) n ).
The following result is well known (see the book [*ArnNiw] that studies in detail least and greatest fixed-points) but we will sketch its proof for completeness. It is an instance of the Least Fixed-Point Theorem3 . Theorem 3.7 Let S be an equation system over an S-signature F . Let M be an F -algebra. The sequence (S i P(M) (∅, . . . , ∅)) i∈N is increasing. Its least upper bound is the (unique) least solution, and also the (unique) least oversolution of S in P(M).

Proof: The partially ordered set

E := P(M σ(x1) ) × • • • × P(M σ(xn) ) has least element ∅ := (∅, . . . , ∅)
and is ω-complete, which means that every increasing sequence has a least upper-bound. We have noted above that the derived operations t P(M) are monotone. It follows that the mapping S P(M) :

E → E is monotone, which means that S P(M) (L) ⊆ S P(M) (L ) if L, L ∈ E and L ⊆ L . The mapping S P(M) is also ω-continuous, which means that S P(M) ( i∈N L (i) ) = i∈N S P(M) (L (i) ) whenever (L (i)
) i∈N is an increasing sequence. This fact can be proved for the operations f P(M) (which are even additive), the derived operations t P(M) and then the mapping S P(M) . The detailed proof is routine.

We have ∅ ⊆ S P(M) (∅), hence S i P(M) (∅) ⊆ S i+1 P(M) (∅) for every i (by using i times the monotonicity of S P(M) ). We let A := i∈N S i P(M) (∅). By the ωcontinuity of S P(M) , we have A = S P(M) (A), hence A is a solution, and also an oversolution. If B is any oversolution of S in P(M), then we have S i P(M) (∅) ⊆ B for each i (easy proof by induction on i), so that A ⊆ B. Hence A is the least oversolution of S in P(M) and also the least solution.

We denote by µx • S P(M) (x) the least solution (oversolution) of an equation system S in P(M), where x stands for some ordering of Unk (S) (and not necessarily Unk (S) = X n ). Two systems S and S with the same set of unknowns are equivalent in

P(M) if µx • S P(M) (x) = µx • S P(M) (x)
. This is the case in particular if S P(M) = S P(M) , because then S and S have the same solutions, and thus the same least solution in P(M).

Two systems S and S as above are equivalent if they are equivalent in every powerset algebra P(M). We have already noted that every system is equivalent to a polynomial system. Transformations of systems into equivalent ones will be studied in Section 3.2.

Definition 3.8 (Equational sets of an algebra)

We will denote by µx • S P(M) (x) y the component of the tuple µx • S P(M) (x) corresponding to the unknown y. (It is the i-th component if y = x i and x = (x 1 , . . . , x n ).) Such a set is said to be defined by (S, y) in P(M), or in M in order to simplify the notation. More generally, we say that a set L ⊆ M is defined by (S, Y ) in M if it is the union of the sets defined by (S, y) in M for all y ∈ Y ⊆ Unk (S). We will also say that L is defined by S in M (without specifying Y ). Note that if all unknowns in Y have the same sort, then L is defined by (S , z) in M where S is obtained by adding to S the equation z = Y .

An equational set of an F -algebra M is a set defined in M by an equation system over F . By the definitions, every equational set L can be defined by (S, Y ) in M for some equational system S and some set Y consisting of unknowns of S with pairwise distinct sorts (and such

that Y = X k , k ≤ n and Unk (S) = X n ). If L is homogenous (i.
e., all its elements have the same sort), then it can be defined by (S, z) in M for some equational system S and some unknown z of S (in particular z = x 1 ). We denote by Equat(M) the set of equational sets of M and by Equat(M) s for s ∈ S, the set of those included in M s . We will also say that a set in Equat(M) is M-equational or equational in M. Examples of equational sets have been given in Sections 1. 1.1, 1.1.2 and 1.1.3. If D is a finite subset of T (F ) s for some sort s, then the equation x = D defines in P(M) the finite set of values in M of the terms of D. Every finite subset of M whose elements are defined by terms is thus equational in M. (This fact will be restated in Proposition 3.45(2).)

An equation system S over F only uses the finite subsignature F (S) of F (its set of sorts is Sort(S) ⊆ S). Hence, we need only study the equational sets of algebras over finite signatures, as shown in the next proposition. (By contrast, the infiniteness of the signature will be important for recognizable sets).

Proposition 3.9 Let M be an F -algebra.

(1) Let S be an equation system over a subsignature F of F and let M be an F -algebra such that M ⊆ M. Then:

µx • S P(M ) (x) = µx • S P(M) (x).
Moreover, every solution of S in P(M ) is a solution of S in P(M).

(

) If M ⊆ M, then Equat(M ) ⊆ Equat(M). 2
(3) Every equational set of M is equational in a finitely generated subalgebra of M.

Proof:

(1) Let Unk (S) = {x 1 , . . . , x n } and E := P(M σ(x1) ) × • • • × P(M σ(xn) ), cf. the proof of Theorem 3.7. If L ∈ E , then S P(M ) (L) = S P(M) (L)

and this

n-tuple belongs to E . This implies the second statement. It also implies that, for every i, we have S i P(M ) (∅) = S i P(M) (∅) (by induction on i). Hence these two sequences have the same least upper-bound and µx

• S P(M ) (x) = µx • S P(M) (x).
(2) Immediate from ( 1).

(3) Let L be defined by S in M. We let M be the subalgebra of M generated by the signature F (S). It is a finitely generated subalgebra of M. Since S is an equation system over F (S), it follows from (1) that L is equational in M .

Equational sets in semi-effectively given algebras

Let F be an effectively given S-signature. The set of sorts S is thus also effectively given, cf. Definitions 2.8 and 2.127, and S ∪ F is at most countable. An equation system S over F is specified in the obvious way as a set of equations x = t with x ∈ X and t ∈ T (F ∪ , X) σ(x) , where we may assume that X = X n for some n. The set X n is effectively given by its standard encoding (that encodes x i as i) and an algorithm must be specified that computes the mapping σ : X n → S (usually by means of a table, of course). Assuming that each function symbol ∪ s is encoded by the same integer as s, the terms t can be specified through the standard encoding of the semi-effectively given set T

(F ∪ , X n ), since F ∪ is the disjoint union of F and {∪ s | s ∈ S}.
Let us consider the least solution of S in P(M) where M is a semi-effectively given F -algebra. By Lemma 3.2(4), each iterate S i P(M) (∅) is a tuple of finite subsets of M . Since the derived operations of M are computable via an encoding ξ M of the elements of M by integers, we can compute the tuple S i P(M) (∅) (or rather the tuple of finite sets of integers that encode it via ξ M ; we will omit this precision in the sequel) by an algorithm that takes as input the system S, the integer i and the computable function ζ M of Definitions 2.8 and 2.127 that encodes the operations of M.

We say that an n-tuple

(L 1 , . . . , L n ) in P(M ) n is finite if the set L 1 ∪• • •∪L n is finite.
Proposition 3.10 Let M be a semi-effectively given F -algebra and S be an equation system over F . If the least solution of S in P(M) is finite, then it can be computed.

Proof: The least solution of S in P(M) is the least upper-bound of the increasing sequence S i P(M) (∅) for i ≥ 0. Each tuple of this sequence is finite and, furthermore, computable. By the finiteness assumption, and since the sequence is increasing, there exists an integer i such that S i+1 P(M) (∅) = S i P(M) (∅). The first one, let us denote it by i 0 , can be computed. Then

S j P(M) (∅) = S i0 P(M) (∅) for each j ≥ i 0 . Hence µx•S P(M) (x) = S i0 P(M) (∅)
and this tuple can be computed.

The finiteness of µx • S P(M) (x) is guaranteed if each domain M s such that s is the sort of an unknown of S is finite.

One might expect that the membership of an element of an effectively given algebra in an equational set given by an equation system is decidable. This is not the case. As a counter-example, take a computable total function f : N → N such that the membership of an integer in the set f (N ) is undecidable. Then consider the effectively given algebra M := N , f, Suc, 0 where Suc is the successor function. The set f (N ) is equational in M because (f (N ), N ) is the least solution in P(M) of the system x = f (y), y = 0 ∪ Suc(y) .

Context-free languages

We examine context-free grammars for several reasons. First because the notion of an equational set arises from the Least Fixed-Point Characterization of context-free languages and yields a generalization of context-free languages to arbitrary algebras, cf. Section 1.1.1. Second because the equational sets of terms are (particular) context-free languages and also "generate", as shows Proposition 3.23( 1) below, all equational sets. Finally, technical notions about derivation sequences will be useful for studying transformations of equation systems.

Definition 3.11 (Context-free grammars and languages)

A context-free grammar over a terminal alphabet A is a triple G = A, X, R such that X is a finite set of variables (disjoint with A) called the nonterminal alphabet of G and R is a finite subset of X × (A ∪ X) * called the set of derivation rules. A rule (x, w) is also written x → w for readability. The one-step derivation relation, denoted by ⇒ G , is defined as follows for u, u in (A ∪ X) * : u ⇒ G u if and only if u = vxv and u = vwv for some v, v ∈ (A ∪ X) * and some rule (x, w) in R.

The language generated by G from a word u in

(A ∪ X) * is L(G, u) := {w ∈ A * | u ⇒ * G w}.
In many cases an initial nonterminal x ∈ X is specified and the language of interest L(G, x) is called the language generated by the grammar.

A language L ⊆ A * is context-free if it is L(G, x) for some context-free grammar G and some nonterminal x of G. Note that we allow the terminal alphabet A to be countably infinite. However, since the set of rules of a grammar is finite, we have L ⊆ B * for some finite subset B of A.

For a context-free grammar G and a set Y of nonterminals of G, we denote the language y∈Y L(G, y) by L(G, Y ) and we say that it is generated by G from Y . Since the family of context-free languages is closed under union, every language L(G, Y ) is context-free. Definition 3.12 (Equational sets in the free monoid) We recall from Definition 2.7 that, for every alphabet A, we let F A := {•, }∪A be the (one-sorted) functional signature such that • is binary and the other symbols are nullary. We let W(A) be the F A -algebra A * , •, ε, (a) a∈A (it is actually the free monoid generated by A, augmented with constants). We use infix notation for • and we may omit parentheses (cf. Definition 2.4). The mapping val W(A) : T (F A ) → A * that evaluates a term over F A into a word over A (by interpreting as the empty word ε, a as the word a and • as concatenation) will be simply denoted by val . We extend it into a mapping val : T (F A , X) → (A ∪ X) * , where X is a set of variables, by evaluating x in X into the word x. For t ∈ T (F A , X), val (t) is obtained from t by erasing all occurrences of the symbols • and .

With every equation system S over F A , we associate the context-free grammar G[S] := A, X, R such that X = Unk (S) and R is the set of rules x → w such that w = val (m) for some monomial m ∈ Mon(t) (⊆ T (F A , X)) and some equation x = t of S. Conversely, for every context-free grammar G over A, there exists an equation system S over F A such that G[S] = G. There are actually several such systems for a given grammar.

For an example of an equation system S over F A see Example 1.2 (where ε should be changed into ); the context-free grammar G[S] is given in Example 1.1 (with nonterminals S and T instead of x 1 and x 2 ). Theorem 3.13 (Least Fixed-Point Characterization) For every equation system S = x 1 = t 1 , . . . , x n = t n over F A , we have:

µx • S P(W(A)) (x) = (L(G[S], x 1 ), . . . , L(G[S], x n )). Proof sketch: We let G := G[S] = A, X, R . We first prove that the sequence of languages (L(G, x 1 ), . . . , L(G, x n )) is an oversolution of S in P(W(A)). It suffices to observe that, if x i → w belongs to R and w = u 0 x i1 u 1 • • • u k-1 x i k u k for i 1 , . . . , i k in [n] and u 0 , u 1 , . . . , u k in A * , then u 0 L(G, x i1 )u 1 • • • u k-1 L(G, x i k )u k ⊆ L(G, w) ⊆ L(G, x i ).
This fact is a consequence of the if-direction of the following Fundamental Property of Derivation Sequences of context-free grammars4 . For every p ∈ N and every word v ∈ A * , we have:

w ⇒ p G v if and only if there exist p 1 , . . . , p k in N and v 1 , . . . , v k in A * such that v = u 0 v 1 u 1 • • • u k-1 v k u k , p = p 1 + • • • + p k and x ij ⇒ pj G v j for each j = 1, . . . , k. Hence, t iP(W(A)) (L(G, x 1 ), . . . , L(G, x n )) ⊆ L(G, x i ) for each i.
For proving the opposite inclusion, we let (L 1 , . . . , L n ) be any oversolution of S in P(W(A)). For every j ∈ N , we have:

∀i ∈ [n], ∀v ∈ A * , ∀p ∈ [0, j] (if x i ⇒ p+1 G v then v ∈ L i ).
This can be proved by induction on j, using the only-if direction of the Fundamental Property of Derivation Sequences. It follows that L(G, x i ) ⊆ L i for every i, hence that (L(G, x 1 ), . . . , L(G, x n )) is the least oversolution of S in P(W(A)). This gives the result by Theorem 3.7.

Corollary 3.14 A language over A is context-free if and only if it is equational in W(A).

Proof: Theorem 3.13 shows that every W(A)-equational language is contextfree. Let conversely L = L(G, x) be a context-free language over A. There exists an equation system S such that G[S] = G. The component of its least solution that corresponds to x is L(G, x) by Theorem 3.13, hence L is equational in W(A).

Equation systems have in most cases several solutions, and we will only be interested in their least ones. However, some context-free grammars yield systems having unique solutions, and this observation shortens some proofs (in particular, that two grammars are equivalent when one is obtained from the other by a transformation of the corresponding systems). It is also more satisfactory to know that an equation system defines completely a tuple of languages without having to take into account any minimization principle.

A context-free grammar is strict if the righthand side of each derivation rule is the empty word or contains at least one terminal symbol.

Proposition 3.15 Let G be a strict context-free grammar over an alphabet A and nonterminal alphabet X n , and S be an equation system such that G

[S] = G. The n-tuple (L(G, x 1 ), . . . , L(G, x n )) is the unique solution of S in P(W(A)). Proof sketch: The n-tuple (L(G, x 1 ), . . . , L(G, x n )) is the least solution of S in P(W(A)) by Theorem 3.13. If (M 1 , . . . , M n ) is any solution of S in P(W(A)), then L(G, x j ) ⊆ M j for each j. We prove by induction on |v| that for all i ∈ [n] and v ∈ A * , if v ∈ M i then v ∈ L(G, x i ). Let v ∈ M i . Since (M 1 , . . . , M n ) is a solution of S, we have v ∈ u 0 M i1 u 1 • • • u k-1 M i k u k for some rule of G of the form x i → u 0 x i1 u 1 • • • u k-1 x i k u k with u 0 , . . . , u k in A * . Hence v = u 0 v 1 u 1 • • • u k-1 v k u k for some v 1 in M i1 , . . . , v k in M i k . Since G is strict, |v j | < |v| for each j = 1, . . . , k, and v j ∈ L(G, x ij ) by the induction hypothesis. Hence v ∈ L(G, x i ). So, (L(G, x 1 ), . . . , L(G, x n )) is the unique solution of S.
We have defined two other algebras with domain A * in Definition 2.7, viz. W left (A) and W right (A). The equational sets of these algebras are actually the regular languages over A, as we will prove in the next section.

Equational sets of terms

The next natural family of equational sets to consider is that of sets of terms. An immediate consequence of Proposition 3.9 is that a set of terms over a signature F is equational in T(F ) if and only if it is equational in T(F ) for some finite subsignature F of F . This proposition is applicable because if F ⊆ F , then T(F ) is the subalgebra of T(F ) generated by F . Proposition 3.16 Let F be a finite signature. For every sort s, the set of terms T (F ) s is equational in T(F ).

Proof: For every sort s we define an unknown x s of sort s. We let its defining equation be x s = D where D is the set of monomials of the form f (x α(f ) [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] , . . . , x α(f )[ρ(f )] ) for all f ∈ F such that σ(f ) = s. We obtain an equation system S. It is clear that:

µx • S P(T(F )) (x) x s ⊆ T (F ) s
for every sort s. For the opposite inclusion, we have, for every term t ∈ T (F ) s (we recall that ht(t) is its height; a constant symbol has height 0):

t ∈ S ht(t)+1 P(T(F )) (∅) x s ,
which is easily proved by induction on the structure of t. It follows that

T (F ) s ⊆ µx • S P(T(F )) (x)
x s for every sort s, which gives the result.

We now consider particular context-free grammars, that will characterize equational sets of terms.

Definition 3.17 (Regular grammars over a signature) Let F be an S-signature. A regular grammar over F is a context-free grammar over F (used here as an alphabet) of the form G = F, X, R such that:

(1) the nonterminal alphabet X is S-sorted with sort mapping σ,

(2) each rule in R is a pair (x, t) where t ∈ T (F, X) σ(x) , also written x → t. We say that G is quasi-uniform (resp. uniform) if each righthand side of a rule has at most one (resp. exactly one) occurrence of a symbol in F .

We have

L(G, x) ⊆ T (F ) σ(x) for every nonterminal x ∈ X, because if w ∈ T (F, X) σ(x) and w ⇒ G w , then w ∈ T (F, X) σ(x) .
A set of terms is regular over F if it is L(G, Y ) for some regular grammar G over F and some set Y of nonterminals of G. Since the set of rules of a grammar is finite, a set of terms is regular over F if and only if it is regular over F for some finite subsignature F of F .

The regular grammar G(S) associated with an equation system S over F is defined as F, Unk (S), R where R is the set of rules x → t such that x ∈ Unk (S) and t ∈ Mon(p) where x = p is the equation of S that defines x. It is uniform or quasi-uniform if S is so. It is clear that conversely, every regular grammar is G(S) for some equation system S over the same signature. Hence, regular grammars are in bijective correspondence with polynomial equation systems.

The following theorem is similar to Theorem 3.13. Theorem 3.18 For every equation system S over a signature F , we have:

µx • S P(T(F )) (x) = (L(G(S), x 1 ), . . . , L(G(S), x n )).
Easy modifications of the proof of Theorem 3.13 can yield a proof of this theorem. However, we will prove it as a corollary of Theorem 3.13 with the help of some notions to be introduced after a corollary and some remarks.

Corollary 3.19 Let F be a signature. A set of terms is regular over F if and only if it is equational in T(F ).

Although the equational sets of terms are the same as the regular ones, we will call them frequently "regular sets" to emphasize their language theoretical specifications by grammars and also by automata that we will define in Section 3.3.

Remarks 3.20

(1) Every equational set of T(F ) is a regular set of terms over F hence a context-free language over F . But a subset of T (F ) that is a context-free language over F need not be T(F )-equational. For example consider F := {f, g, a, b} with ρ(f

) := 2, ρ(g) := 1 and ρ(a) := ρ(b) := 0. The subset {f g n ag n b | n ≥ 0} of T (F ) is a context-free
language but it is not T(F )equational because it is not a regular set of terms. This last fact will be proved in Example 3.54 by means of a "pumping argument".

A regular subset of T (F ) may be a context-free language over the alphabet F that is not a regular one: this is the case for the set L ⊆ T (F ) defined by the regular grammar over F (as above) with rules x → f af xa and x → a because

L = {(f af ) n a n+1 | n ≥ 0}.
A set of terms can be regular over a signature F and, at the same time, be not regular over a signature F obtained by changing the arities of the symbols of F . For example, the set of terms f Lb is regular (where L is as above), but it is not regular if f, a have arity 1 and b has arity 0 (although it is also a set of terms for the new arity mapping); this follows from (4) below.

(2) The context-free grammars G(S) and G[S] associated with an equation system S over F A are not the same. For example, if S is the system of Example 1.2, then G(S) is the regular grammar over F A with the following rules (written for more readability in infix notation with parentheses): and G[S] is the context-free grammar G over A of Example 1.1 with nonterminals x 1 and x 2 instead of S and T . Its rules are: andx 2 → ε. (3) Let G = A, X, R be a context-free grammar and S be an equation system over

x 1 → a • (x 1 • x 2 ), x 1 → x 1 • x 1 , x 1 → a, x 2 → b • ((x 2 • x 1 ) • x 2 ), x 2 → a, x 2 → c and x 2 → ,
x 1 → ax 1 x 2 , x 1 → x 1 x 1 , x 1 → a, x 2 → bx 2 x 1 x 2 , x 2 → a, x 2 → c,
F A such that G[S] = G. Let x ⇒ * G(S) t with t ∈ T (F A , X
) be a derivation sequence relative to the regular grammar G(S). Its image under the evaluation mapping val , i.e., the corresponding sequence of images by val (where val evaluates a term in T (F A , X) into a word over A ∪ X) is a derivation sequence x ⇒ * G val (t) of the word val (t) relative to the context-free grammar G. Conversely every derivation sequence of G is the image under val of a derivation sequence of G(S). Thus, L(G[S], x) = val (L(G(S), x)) for every nonterminal x.

To illustrate this observation, we use again the system S and the grammar G = G[S] as in (2). The image under val of the derivation sequence of G(S):

x 1 ⇒ a•(x 1 •x 2 ) ⇒ a•((x 1 •x 1 )•x 2 ) ⇒ a•((x 1 •x 1 )• ) ⇒ a•((a•x 1 )• ) ⇒ a•((a•a)• ) is x 1 ⇒ ax 1 x 2 ⇒ ax 1 x 1 x 2 ⇒ ax 1 x 1 ⇒ aax 1 ⇒ aaa.
(4) The set of words over a finite alphabet A is in bijection (in two ways) with the set of terms over U A , where U A is the associated unary signature of Definition 2.7. Via these bijections, the regular languages over A correspond to the regular sets of terms over U A , and the equational sets of the U A -algebras W left (A) and W right (A) correspond to the equational sets of T(U A ). Hence, the equational sets of the algebras W left (A) and W right (A) are the regular languages over the alphabet A.

In order to obtain Theorem 3.18 from Theorem 3.13 and Proposition 3.9(1), we make some technical observations about sorts. If F is an S-signature, we let F -be the one-sorted signature obtained by making all sorts identical. It follows that T (F ) defined as s∈S T (F ) s is a subset of T (F -). Every equation system over F is also one over F -. Lemma 3.21 For every equation system S over a signature F , we have that µx • S P(T(F )) (x) = µx • S P(T(F -)) (x). Moreover, every solution of S in P(T(F )) is a solution of S in P(T(F -)).

Proof: Let S be a system with Unk (S) = X n and E :

= P(T (F ) σ(x1) ) × • • • × P(T (F ) σ(xn)
). It is clear from the definitions that if L = (L 1 , . . . , L n ) belongs to E, then S P(T(F -)) (L) also belongs to E and is equal to S P(T(F )) (L). This implies the second statement. It also implies, by induction on i, that

S i P(T(F )) (∅) = S i P(T(F -)) (∅)
for each i ∈ N . This yields the result.

This lemma proves that Equat(T(F

)) ⊆ Equat(T(F -)). Conversely, if L is equational in T(F -) and is contained in T (F ), then it is equational in T(F ).
This fact will be proved below in Remark 3.38(4).

Let S = x 1 = p 1 , . . . , x n = p n be an equation system over an S-signature F . We will use the regular grammar G(S) over F . Since this grammar is contextfree, there exists an equation system S over the signature

F F = {•, } ∪ F (cf. Definition 3.12) such that the associated context-free grammar G[S] is equal to G(S). For example, if S = x = f xgxx ∪ a (with f, g binary), then G(S) = {f, g, a}, {x}, {x → f xgxx, x → a} and S can be (it is not uniquely defined) the equation x = (f • x) • ((g • x) • x) ∪ a (we use infix notation for •).
With these definitions we have: Lemma 3.22 For every system S over a signature F :

µx • S P(T(F )) (x) = µx • S P(W(F )) (x).
Moreover, every solution of S in P(T(F )) is a solution of S in P(W(F )).

Proof: We have the following equalities:

µx • S P(T(F )) (x) = µx • S P(T(F -)) (x) = µx • S P(S(F -)) (x) = µx • S P(W(F )) (x)
which follow respectively from Lemma 3.21, from Proposition 3.9(1) (because T(F -) ⊆ S(F -)) (cf. Definition 2.2) and from the fact that S P(S(F -)) and S P(W(F )) are the same function from (P(F * )) n to itself (n := |x|) by the definition of S.

Proof of Theorem 3.18: We have:

µx • S P(T(F )) (x) = µx • S P(W(F )) (x) = (L(G[S], x 1 ), . . . , L(G[S], x n )) = (L(G(S), x 1 ), . . . , L(G(S)), x n )),
respectively by Lemma 3.22, by Theorem 3.13 and by the definition of S.

From Lemma 3.22 and Proposition 3.15 we obtain: if S is an equation system over F such that G(S) is strict, then S has a unique solution in P(T(F )).

As another consequence of Lemma 3.22, consider the equation system S in the proof of Proposition 3.16. In Definition 2.124, T (F ) s is defined as the x s component of the unique solution of the equation system S in W(F ) (and note that it has a unique solution by Proposition 3.15). Hence, by Lemma 3.22, T (F ) s = µx • S P(T(F )) (x) x s . This proves, again, Proposition 3.16.

Homomorphic images of equational sets

We now establish some algebraic properties of equational sets. We recall from Definition 2.124 that val M denotes the mapping that associates with a term t in T (F ) its value val M (t) in the F -algebra M; it is the unique homomorphism from T(F ) to M. Proposition 3.23 Let M, M be F -algebras and h : M → M be a homomorphism5 . We have:

(1) If S is an equation system over F , then

µx • S P(M ) (x) = P h(µx • S P(M) (x)).
In particular:

µx • S P(M) (x) = val M (µx • S P(T(F )) (x)).
(2) A set is equational in M if and only if it is the image under h of an equational set in M.

(3) A set L is equational in M if and only if L = val M (K) for some regular set of terms K ⊆ T (F ). In particular, every equational set of M is generated by a finite subsignature of F .

(4) The set M s is equational in M if and only if it is generated by a finite subsignature of F .

Proof: (1) Since P h is a homomorphism : P(M) → P(M ), we have:

P h(f P(M) (L)) = f P(M ) ( P h(L))
for every f ∈ F and every tuple L of appropriate type. This equality extends to the derived operations t P(M) and t P(M ) (routine induction on the structure of t) and to the mappings S P(M) and S P(M ) , that is, we have P h(S P(M) (L)) = S P(M ) ( P h(L)). By using an induction on i, we get that P h(S i P(M) (∅)) = S i P(M ) (∅) for each i. The result follows then since P h is additive.

(2) is immediate from ( 1).

(3) The first assertion follows from (2) and Corollary 3.19. The second assertion is a consequence of Proposition 3.9(3).

(4) Follows from (3) and Proposition 3.16. Note that if

M s ⊆ val M (T (F )) then M s = val M (T (F ) s ).
As an example of the second statement of ( 1), consider an equation system S over F A , for an alphabet A, and an unknown x of S. We know that µx

• S P(W(A)) (x) x = L(G[S],
x) from Theorem 3.13, and we know that µx

• S P(T(F A )) (x) x = L(G(S), x) from Theorem 3.18. In Remark 3.20(3) we have already seen that L(G[S], x) = val W(A) (L(G(S), x)).
As another example, consider the U A -algebras W left (A) and W right (A). It is straightforward to show that a set of terms L ⊆ T (U A ) is regular over U A if and only if it is of the form K for some regular language K over the alphabet A. In that case val W left (A) (L) = K, and val W right (A) (L) is the mirror image of K. Since the class of regular languages is closed under mirror image, it follows from Proposition 3.23(3) that the equational sets of the algebras W left (A) and W right (A) are the regular languages over the alphabet A, as we have already seen in Remark 3.20(4) (where the mentioned bijections are the mappings val W left (A) and val W right ).

Corollary 3.24 For every equation system S over a signature F and every unknown y of S, the following are equivalent:

(1) L(G(S), y) = ∅, (2) µx • S P(M) (x) y = ∅ for some F -algebra M, (3) µx • S P(M) (x) y = ∅ for every F -algebra M.
These conditions are decidable if F is effectively given.

Proof: Theorem 3.18 and Proposition 3.23 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] entail that, for every F -algebra M, we have µx • S P(M) (x) y = val M (L(G(S), y)). This implies the equivalence of ( 1), ( 2) and (3). Since G(S) is a context-free grammar, the emptiness of L(G(S), y) is decidable, which proves the last assertion.

Equational sets of commutative words

For each k ≥ 1, we let N k be the set of k-tuples of natural numbers equipped with componentwise addition. We denote by u the generic element of N k and by 0 the null k-tuple (0, . . . , 0) which is the unit of the monoid 6 N k . For each i ∈ [k], we let a i be a constant symbol denoting (0, . . . , 0, 1, 0, . . . , 0) with a single 1 at the i-th position and A := {a 1 , . . . , a k }. Hence N k is an F A -algebra (with addition as operation • N k and 0 as constant N k ). It is isomorphic to the quotient algebra 7 of W(A) by the congruence generated by the equalities a i • a j = a j • a i for all i, j ∈ [k], hence is the free commutative monoid generated by A. With this identification, we can say that the unique homomorphism h : W(A) → N k "makes the letters of A commute", in other words, only counts the numbers of occurrences of letters regardless of their positions: h(w) = (n 1 , . . . , n k ) where

n i = |w| ai for each i. For λ ∈ N and u ∈ N k , we let λ • u (or just λ u) denote u + u + • • • + u with λ times u. A subset L of N k is linear (affine would be a better word, but "linear" is usual) if it is of the form { u + λ 1 v 1 + • • • + λ p v p | λ 1 , . . . , λ p ∈ N } for some u, v 1 , . . . , v p in N k . A set is semi-linear if it is a finite union of linear sets.
Its description is the finite set of tuples ( u, v 1 , . . . , v p ) from which it is defined. From the description of a semi-linear set, one can check if it is finite, because a linear set described by u, v 1 , . . . , v p is finite if and only if all tuples v i are null.

The following proposition reformulates a classical result of formal language theory8 . Proposition 3.25 For every k ≥ 1, Equat(N k ) is the set of semi-linear subsets of N k . There exists an algorithm that transforms a description of a semi-linear set into an equation system over F A defining this set in N k , and another one that converts an equation system over F A into descriptions of the semi-linear sets that form its least solution in P(N k ).

Proof: Let L = L 1 ∪ • • • ∪ L n be a semi-linear set, where each L i is linear. Each element u of N k can be expressed as a sum of constant symbols. A linear set L i of the form { u + λ 1 v 1 + • • • + λ p v p | λ 1 , . . . , λ p ∈ N } ⊆ N k is the least solution of the equation x i = u ∪ ( v 1 + x i ) ∪ • • • ∪ ( v p + x i ).
If S is the equation system consisting of these n equations, then L is defined by (S, X n ) in N k . This gives the first algorithm.

The opposite construction is done in a clean way in [AceEI] (on the basis of a previous proof in [Pil]) in terms of equation systems. It can also be done as follows in terms of context-free grammars. By Proposition 3.23(2) and Corollary 3.14, a set is equational in N k if and only if it is the commutative image h(L) of a context-free language L ⊆ A * where h is the above defined homomorphism h : W(A) → N k . A description of h(L) can be constructed from a grammar defining L: an elementary proof is in Section 6.9 of [*Har]. Both constructions are effective.

Let g F be a mapping : F → N k and let g : T (F ) → N k be the mapping defined by:

g(t) = f ∈F |Occ(t, f )| • g F (f ).
Then g is a homomorphism of F -algebras : T(F ) → P where P is the F -algebra that is the derived algebra of N k with operations defined by:

f P ( u 1 , . . . , u ρ(f ) ) = g F (f ) + u 1 + • • • + u ρ(f ) .
We call such a mapping g an affine mapping : T (F ) → N k .

Corollary 3.26 The image of a regular set of terms under an affine mapping is a semi-linear set, and a description of this set can be computed from the affine mapping and a regular grammar.

Proof: Let g be an affine mapping :

T (F ) → N k based on g F : F → N k , and consider L := L(G, x) where G = F, X, R is a regular grammar and x ∈ X. For every f ∈ F , let w f be a word in A * such that h(w f ) = g F (f ), and let π : (F ∪ X) * → (A ∪ X) * be the mapping such that, for t ∈ (F ∪ X) * , π(t)
is obtained from t by replacing every occurrence of every f by w f (i.e., π is the unique monoid homomorphism such that π(f

) = w f for f ∈ F ). Obvi- ously, g(t) = h(π(t)) for every t ∈ T (F ). Now define the context-free grammar G = A, X, R such that R consists of all rules x → π(t) with x → t in R. Then L(G , x) = {π(t) | t ∈ L(G, x)} = π(L). Hence g(L) = h(π(L)) = h(L(G , x)), i.e., g(L)
is the image under h of a context-free language over A. Thus, g(L) is equational in N k and hence semi-linear by the previous proposition. All constructions are effective.

An algebraic presentation of this proof will be given in Example 3.42(3).

Transformations of equation systems

We present some transformations of equation systems that normalize or simplify them while preserving the "main components" of their least solutions. We also establish some closure properties of the family of equational sets. All proofs are constructive (provided the considered signatures are effectively given), unless mentioned otherwise.

Unfolding

Unfolding is a very natural transformation of context-free grammars that we generalize to equation systems. Further transformations are based on it. In particular, we will obtain a generalization of the transformation that puts a context-free grammar in Chomsky normal form. We say that a system S is a subsystem of S, denoted by S ⊆ S, if Unk (S ) ⊆ Unk (S) and each equation of S is an equation of S.

Lemma 3.27 If S ⊆ S, then µy • S P(M) (y) z = µx • S P(M) (x) z for every z ∈ Unk (S ).
Proof: Let S be an equation system of the form (3.1) with set of unknowns Unk (S) = X n = {x 1 , . . . , x n } and let Y := Unk (S ) be ordered as in

Unk (S), that is, Y = {x i1 , . . . , x ip } with i 1 < i 2 < • • • < i p . For any n-tuple of sets L = (L 1 , . . . , L n ), we let L Y denote the p-tuple (L i1 , . . . , L ip ). Then, for each i ≥ 0, we have S i P(M) (∅) Y = S i P(M) (∅)
. This is easily proved by induction on i, and yields the result.

Definition 3.28 (Equivalent systems) Let S and S be two equation systems over F , and let Z ⊆ Unk (S) ∩ Unk (S ). The systems S and S are Z-equivalent in P(M) if µx • S P(M) (x) z = µy • S P(M) (y) z for every z ∈ Z. They are Z-equivalent if they are Z-equivalent in P(M) for every F -algebra M. We delete the prefix Z when Z = Unk (S) = Unk (S ).

That two systems are equivalent in P(M) may depend on particular properties of M. However there exist syntactic criteria ensuring that two systems are equivalent. We first consider unfolding: this transformation consists in replacing (several times) in the righthand sides of some equations of a system unknowns by their defining terms. It is a standard transformation of recursive definitions; it preserves the defined sets, i.e., the least solutions of the corresponding equation systems.

Definition 3.29 (Unfolding) Let S = x 1 = p 1 , . . . , x n = p n be an equation system where p 1 , . . . , p n are polynomials. We let ⇒ S be the rewriting relation on T (F ∪ , X n ) defined by:9

t ⇒ S t :⇐⇒ t = c[x i ] and t = c[p i ]
for some i ∈ [n] and some context c in Ctxt(F ∪ , X n ) (cf. Definition 2.6). We say that S = x 1 = q 1 , . . . , x n = q n is obtained from S by unfolding if p i ⇒ * S q i for each i = 1, . . . , n. We denote this by S S . The terms q i are not necessarily polynomials. However, they can be expanded into polynomials by Lemma 3.4. If S is obtained from S by this lemma, we also say that S is obtained from S by unfolding and we use the same notation S S . Note that S and S are equivalent.

Example 3.30 We let S be the system

x 1 = f (x 1 , x 2 ) ∪ a x 2 = g(x 1 , x 1 , x 2 ) ∪ b.
The system S :

x 1 = f (f (x 1 , x 2 ) ∪ a, g(x 1 , x 1 , x 2 ) ∪ b) ∪ a x 2 = g(f (x 1 , x 2 ) ∪ a, x 1 , x 2 ) ∪ b
is obtained from S by unfolding. The righthand sides of its equations can then be expanded into polynomials, which gives the following system S equivalent to S :

     x 1 = f (f (x 1 , x 2 ), g(x 1 , x 1 , x 2 )) ∪ f (a, g(x 1 , x 1 , x 2 )) ∪ f (f (x 1 , x 2 ), b) ∪ f (a, b) ∪ a x 2 = g(f (x 1 , x 2 ), x 1 , x 2 ) ∪ g(a, x 1 , x 2 ) ∪ b.
Proposition 3.31 If a system S is obtained from a system S by unfolding, then S and S are equivalent.

We need for the proof two technical observations. Let S = x 1 = p 1 , . . . , x n = p n and let t, t ∈ T (F ∪ , X n ) be such that t ⇒ * S t . If L is a solution of S in P(M), then t P(M) (L) = t P(M) (L): this is clear because at any rewriting step, one replaces x i having value L i (where L = (L 1 , . . . , L n )) by p i which has the same value in P(M) since L is a solution of S.

Our second observation is that if t is the unique term in

T (F ∪ , {y 1 , . . . , y k }) such that ListVar ( t ) = y 1 y 2 • • • y k and t = t [x ir /y r ; 1 ≤ r ≤ k] for some i 1 , . . . , i k in [n], then t = t [s r /y r ; 1 ≤ r ≤ k]
where for each r we have x ir ⇒ * S s r . This is a reformulation of the only-if direction of the Fundamental Property of Derivation Sequences (mentioned in the proof of Theorem 3.13) for the context-free grammar with rules x 1 → p 1 , . . . , x n → p n . We illustrate this fact with an example, where S is the system of Example 3.30.

Example 3.32 Let t = f (x 1 , h(x 1 , x 2 )) and t = f (x 1 , h(f (x 1 , x 2 ) ∪ a, g(x 1 , f (x 1 , x 2 ) ∪ a, x 2 ) ∪ b)).
Then we have t ⇒ * S t with t, y 1 , y 2 , y 3 , s 1 , s 2 , s 3 , i 1 , i 2 , i 3 as follows:

t = f (y 1 , h(y 2 , y 3 )), t = t [x 1 /y 1 , x 1 /y 2 , x 2 /y 3 ], t = t [s 1 /y 1 , s 2 /y 2 , s 3 /y 3 ],
with

s 1 = x 1 , s 2 = f (x 1 , x 2 ) ∪ a, s 3 = g(x 1 , f (x 1 , x 2 ) ∪ a, x 2 ) ∪ b, i 1 = i 2 = 1 and i 3 = 2. It is clear that x 1 ⇒ * S s 1 , x 1 ⇒ * S s 2 and x 2 ⇒ * S s 3 .
Proof of Proposition 3.31:

Let S = x 1 = p 1 , . . . , x n = p n and S = x 1 = q 1 , . . . , x n = q n be such that p i ⇒ * S q i for each i, so that S S . Let M be an F -algebra. Every solution L of S in P(M) is a solution of S because if p i ⇒ * S q i , then p iP(M) (L) = q iP(M) (L). Hence µx • S P(M) (x) ⊆ µx • S P(M) (x).
We now prove the other direction. We let:

L (j) = (L (j) 1 , . . . , L (j) n ) := S j P(M) (∅), so that L = (L 1 , . . . , L n ) = µx • S P (M (x) if L i := j∈N L (j) i
for each i. We let also:

L = (L 1 , . . . , L n ) := µx • S P(M) (x).
We will prove that L i ⊆ L i for all i by proving that, for all i and j, we have

L (j) i ⊆ L i .
We prove by induction on j the following stronger statement, from which the previous one is obtained by taking t = x i .

Claim 3.31.1 For every j ∈ N , every i = 1, . . . , n and every

t ∈ T (F ∪ , X n ) such that x i ⇒ * S t, we have L (j) i ⊆ t P(M) (L ). Proof: This is clear for j = 0 because L (0) i = ∅. We consider the inductive step. We have L (j+1) i = p iP(M) (L (j) ). The hypothesis x i ⇒ * S t yields two cases. Case 1 : x i ⇒ S p i ⇒ * S t. If p i ∈ T (F ∪ , {y 1 , . . . , y k }) with ListVar ( t ) = y 1 y 2 • • • y k and p i = p i [x ir /y r ; 1 ≤ r ≤ k], then we have t = p i [s r /y r ; 1 ≤ r ≤ k]
where x ir ⇒ * S s r for each r. We must prove that

L (j+1) i = p iP(M) (L (j) ) ⊆ t P(M) (L ). Since p iP(M) (L (j) ) = p iP(M) (L (j) i1 , . . . , L (j)
i k ) and

t P(M) (L ) = p iP(M) (s 1P(M) (L ), . . . , s kP(M) (L )),
and since the derived operations of P(M) are monotone (we have used this fact in Theorem 3.7), it suffices to prove that:

L (j)
ir ⊆ s rP(M) (L ) for every r = 1, . . . , k.

But this follows from the induction hypothesis.

Case 2: t = x i . We must prove that

L (j+1) i ⊆ t P(M) (L ) = L i . But L i = q iP(M) (L ) (because L is a solution of S ) and p i ⇒ * S q i . So this follows from Case 1 with q i instead of t.
This completes the proof of the claim and thus, of the proposition.

Uniform and quasi-uniform systems are defined in Definition 3.6. We denote by F (X n ) the set of terms in T (F, X n ) having a single occurrence of a symbol in F (which is thus the leading symbol).

Proposition 3.33 For every equation system S, one can construct a uniform system that is Unk (S)-equivalent to S.

Proof: We first transform S into a quasi-uniform system S by repeating the following transformation step as many times as necessary (i.e., as possible).

Transformation Q: Let S = x 1 = p 1 , . . . , x n = p n be an equation system over F where each p i belongs to Pol (F, X n ). Assume that for some i, some monomial m in Mon(

p i ) is not in F (X n ) ∪ X n .
Then m = f (m 1 , . . . , m k ) and at least one of the m j 's is not an unknown. For each such term m j we introduce a new unknown y j of the same sort as m j , we introduce the new equation y j = m j and we replace in m the term m j by y j . We let Y be the set of these new unknowns. We have transformed m into m ∈ F (X n ∪ Y ), and the system S into a system

Q(S) with Unk (Q(S)) = Unk (S) ∪ Y . It is clear that Q(S)
S where S is S augmented with the new equations y j = m j , so that S ⊆ S . It follows then from Proposition 3.31 and Lemma 3.27 that S and Q(S) are Unk (S)-equivalent.

Let S be the system that we want to transform into an equivalent quasiuniform system. We define a sequence S = S 0 , S 1 , . . . , S r of equation systems such that S i+1 = Q(S i ) for each i < r. This sequence terminates when it reaches a quasi-uniform system S r . For each i we have Unk (S) ⊆ Unk (S i ) and the systems S i+1 and S i are Unk (S i )-equivalent. Hence they are Unk (S)equivalent. It remains to verify that a quasi-uniform system S r is actually obtained.

For

m ∈ T (F, X n ), we define δ(m) := if m ∈ X n then 0 else |m| F -1, where |m| F is the number of occurrences in m of symbols from F . For a polynomial p = m 1 ∪ m 2 ∪ • • • ∪ m s we let δ(p) := δ(m 1 ) + • • • + δ(m s ) and δ(Ω) := 0. For an equation system S = x 1 = p 1 , . . . , x n = p n we let δ(S) := δ(p 1 )+• • •+δ(p n ).
It is clear that S is quasi-uniform if and only if δ(S) = 0 and that δ(Q(S)) < δ(S). These facts ensure that a quasi-uniform system S r is obtained in r steps with r ≤ δ(S). We will call Q * the transformation consisting in iterating Q as much as possible. It produces a quasi-uniform system.

Next we show how to transform a quasi-uniform system S into an equivalent uniform system without introducing new variables. For a quasi-uniform equation system S = x 1 = p 1 , . . . , x n = p n we denote by C(S) the set of indices of unknowns that are monomials of S, formally C(S)

:= {i ∈ [n] | x i ∈ Mon(p j ) for some j ∈ [n]}. Note that S is uniform if and only if C(S) = ∅. The follow- ing transformation U constructs an equivalent quasi-uniform system U (S) such that |C(U (S))| < |C(S)|.
Consequently, as in the first part of the proof, the transformation U * that consists in repeating U as much as possible leads to an equivalent uniform system, in at most n steps.

Transformation U : Let S = x 1 = p 1 , . . . , x n = p n be a quasi-uniform equation system, and assume that i belongs to C(S). We first change p i into p i by removing x i from p i in the case where x i is a monomial of p i ; otherwise p i = p i . It is clear that the resulting system S has the same oversolutions as S in any powerset algebra P(M); thus S and S are equivalent by Theorem 3.7. Now we construct U (S) = x 1 = p 1 , . . . , x n = p n where, for every j = 1, . . . , n with j = i, polynomial p j is obtained by replacing in p j the monomial x i by p i in the case where x i is a monomial of p j ; otherwise p j = p j ). Clearly, S U (S) and hence they are equivalent by Proposition 3.31. In the construction of U (S), we can of course replace m ∪ m by m in a polynomial p j . It is clear that C(U (S)) = C(S) -{i} and that U (S) is quasi-uniform and equivalent to S.

Example 3.34 We let S be the system:

x 1 = x 2 ∪ f (x 1 , g(x 1 , x 2 )) ∪ a x 2 = x 1 ∪ g(x 2 , h(x 1 , x 1 )).
The first step of the construction produces the quasi-uniform system S :

         x 1 = x 2 ∪ f (x 1 , x 3 ) ∪ a x 2 = x 1 ∪ g(x 2 , x 4 ) x 3 = g(x 1 , x 2 ) x 4 = h(x 1 , x 1 ).
The associated uniform system is S :

         x 1 = f (x 1 , x 3 ) ∪ g(x 2 , x 4 ) ∪ a x 2 = f (x 1 , x 3 ) ∪ g(x 2 , x 4 ) ∪ a x 3 = g(x 1 , x 2 ) x 4 = h(x 1 , x 1 ). Note that since x 1 ⇒ * G(S) x 2 and x 2 ⇒ * G(S)
x 1 , the unknowns x 1 and x 2 are defined by the same equation in S .

Remarks 3.35

(1) The transformation U * corresponds for context-free grammars to eliminating the rules of the form x → y where y is a nonterminal.

(

) A context-free grammar G = A, X, R is in Chomsky normal form (see, e.g., [*Har]) if R ⊆ X × (A ∪ XX). 2
For such a grammar, there is a uniform system S over

F A -{ } such that G[S] = S. Conversely, if S is a uniform system over F A -{ }, then G[S]
is in Chomsky normal form. The construction of the proof of Proposition 3.33 generalizes the one that puts a context-free grammar without rules x → ε into an equivalent one in Chomsky normal form. The rules x → ε can be eliminated by a specific step that is not covered by Proposition 3.33.

(3) In the algorithm of Proposition 3.33, the transformation U * can be done before the transformation Q * .

Simplifications of equation systems

We consider transformations of equation systems that delete unknowns hence that reduce the number of equations while preserving the main components of the least solution.

Definition 3.36 (Trim systems) An unknown x i of a system S = x 1 = p 1 , . . . , x n = p n is productive if L(G(S), x i ) = ∅ or, by Corollary 3.24, the i-th component of the least solution of S in any powerset algebra P(M) is nonempty. We say that S is trim if all its unknowns are productive. For arbitrary S, we let Y ⊆ Unk (S) be the set of its productive unknowns. We let Trim(S) be the system obtained from S by deleting the equations x i = p i for x i ∈ Unk (S) -Y and, in the remaining equations (we assume that p 1 , . . . , p n are polynomials), all monomials containing unknowns not in Y . Its construction is effective by Corollary 3.24.

Let Z ⊆ Unk (S). An unknown u of S is useful for Z if there exists a derivation sequence z ⇒ * G(S) t such that z ∈ Z and u occurs in t. This implies that u is an unknown of every subsystem S of S such that Z ⊆ Unk (S ). We let Cut(S, Z) be the subsystem of S whose unknowns are those that are useful in S for Z. Thus, Cut(S, Z) is the smallest subsystem S of S such that Z ⊆ Unk (S ). Hence it can be constructed effectively. We let Trim(S, Z) := Cut(Trim(S), Z ∩ Unk (Trim(S))).

Proposition 3.37 The system Trim(S) is trim and Unk (Trim(S))-equivalent to S. For every subset Z of Unk (T rim(S)), the system T rim(S, Z) is trim, it is Z-equivalent to S, and all its unknowns are useful for Z. There exists an algorithm that constructs Trim(S) and Trim(S, Z). If S is (quasi-)uniform, then so are T rim(S) and T rim(S, Z).

Proof: Let Y := Unk (Trim(S)). It follows from the definitions that the regular grammar G(Trim(S)) is the one obtained from G(S) by deleting the nonterminals in Unk (S)-Y (i.e., those that are not productive) and the rules where they occur. It follows that L(G(Trim(S)), y) = L(G(S), y) for every y ∈ Y , whence we get that Trim(S) is trim and, by Theorem 3.18 and Proposition 3.23 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF], that S and Trim(S) are Y -equivalent. The second assertion follows from Lemma 3.27 since Trim(S, Z) is a subsystem of Trim(S).

Remarks 3.38

(1) The transformation of S into Trim(S, Z) corresponds for a context-free grammar G = A, X, R to reducing it, i.e., to removing the nonterminals that do not occur in any derivation sequence z ⇒ * G w with z ∈ Z and w ∈ A * . (2) Proposition 3.37 is useful for other purposes than reducing the size of an equation system. Here is an example. If u is an unknown of Trim(S, Z), then z ⇒ * G(S) t for some z ∈ Z and some term t in T (F, {u}) that has a unique occurrence of u (hence t ∈ Ctxt(F ) if we use u as special variable for defining contexts) and for every w in L(G(S), u), the term t[w/u] belongs to L(G(S), z). Let M be an F -algebra and d be any element of µx • S P(M) (x) u. Then, by Theorem 3.18 and Proposition 3.23 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]

, t M (d) ∈ µx • S P(M) (x) z.
(3) As an application of this fact, we prove a variant of Proposition 3.10. An operation f of an F -algebra M is infinity-preserving if for every L 1 , . . . , L ρ(f )

such that ∅ = L i ⊆ M α(f )[i] and at least one of the sets L 1 , . . . , L ρ(f ) is infi- nite, the set f P(M) (L 1 , . . . , L ρ(f ) ) is infinite.
On integers, addition is infinitypreserving, but multiplication is not because {0} • L = {0} for every set L. We say that M is infinity-preserving if all its operations are.

If M is semi-effectively given and infinity-preserving, then every finite Mequational set can be computed.

Here is the proof. Suppose that L := µx • S P(M) (x) x 1 is finite. By Proposition 3.37 we may assume that S is trim and that all its unknowns are useful for {x 1 }. We claim that each component L u := µx • S P(M) (x) u of the least solution of S is finite. By the above remark (2), there is a term

t ∈ T (F, {u}) with one occurrence of u, such that if d is in L u then t M (d) ∈ L. Thus, if L u would be infinite, then, since M is infinity-preserving, t P(M) (L u ) = {t M (d) | d ∈ L u } ⊆ L would be infinite. Hence the least solution of S in P(M)
is finite, and it can be computed by Proposition 3.10.

(4) As another application, we prove the following converse of Lemma 3.21:

If L ⊆ T (F ) is equational in T(F -), then it is equational in T(F ).
By Theorem 3.18 and Propositions 3.33 and 3.37, we have that L = L(G(S), Y ) for a polynomial system S = x 1 = p 1 , . . . , x n = p n over F -that is uniform and trim with all unknowns useful for Y ⊆ X n . We will show that S is also an equation system over F , hence that L is equational in T(F ). We first claim that there exist sorts s 1 , . . . , s n such that L(G(S), x i ) ⊆ T (F ) si for i = 1, . . . , n. The sort s i will be defined as the sort of x i . Obviously, s 1 := s. Now let 2 ≤ i ≤ n, and let w ∈ L(G(S), x i ). Since x i is useful for {x 1 }, there exists a derivation sequence x 1 ⇒ * G(S) t such that the term t ∈ T (F -, {x i }) has a unique occurrence of x i . Hence t[w/x i ] ∈ L(G(S), x 1 ) and so t[w/x i ] ∈ T (F ) s . Then w is in T (F ) r for a sort r that is determined from t: it is r = α(f )[j] where x i occurs in t as j-th argument of some f in F . (Since S is uniform, we cannot have t = x i .) Since r does not depend on w, the sort s i := r satisfies the claim, and is taken as sort of x i . Now, each unknown of S has a sort. It remains to check that Mon(p i ) ⊆ T (F, X n ) si for i = 1, . . . , n, i.e., that all monomials of S satisfy the sort constraints. Let m ∈ Mon(p i ) and let m be the unique term in

T (F -, Y k ) such that ListVar ( m) = y 1 • • • y k and m = m[x ir /y r ; 1 ≤ r ≤ k] for i 1 , . . . , i k ∈ [n]. Since S is trim, there exists a term w r ∈ L(G(S), x ir ) for every r ∈ [k], and so m ⇒ * G(S) m[w r /y r ; 1 ≤ r ≤ k] ∈ L(G(S), x i ). Then w r ∈ T (F ) si r and m[w r /y r ; 1 ≤ r ≤ k] ∈ T (F ) si . This implies that m[x ir /y r ; 1 ≤ r ≤ k] ∈ T (F, X n ) si , i.e., that m ∈ T (F, X n ) si .
One can eliminate an unknown x of an equation system that defines a finite set L: it suffices to replace it in the righthand sides of all equations by finitely many terms that define L. The corresponding transformation (it uses unfolding) is opposite to the one done in Proposition 3.33: it eliminates certain equations but increases the sizes of the remaining ones.

Proposition 3.39 Every infinite homogenous equational set of an F -algebra M is defined by an equation system, each unknown of which defines an infinite subset of M .

Proof: It follows from Proposition 3.23(1) that if an equational set of M is finite, then it is the set of values of a finite set of terms.

Let S be an equation system of the form (3.1) with least solution L = (L 1 , . . . , L n ) in P(M) and such that the given infinite equational set equals L i for some

i ∈ [n]. Let m ∈ [n] be such that L m is finite. By the preliminary remark, L m = {t M | t ∈ D} where D is a finite subset of T (F ).
Let S be the system obtained from S by replacing the equation x m = t m by x m = D. We claim that L is the least solution of S in P(M). It is clear that it is a solution of S , hence that µx • S P(M) (x) ⊆ L. For proving the converse, we observe that S i P(M) (∅) ⊆ S i P(M) (∅) for every i (easy proof by induction on i).

Hence L = µx • S P(M) (x) ⊆ µx • S P(M) (x)
, which gives the desired equality and proves the claim. It follows then from Proposition 3.31 that we can also replace each occurrence of x m in the righthand sides of the equations of S by D, and that we obtain a system S equivalent to S and to S. But then we can delete the equation x m = D from S and we get a subsystem that is (Unk (S) -{x m })-equivalent to S in P(M) by Lemma 3.27.

This step can be repeated for each unknown that defines a finite set. Since we assumed that some unknown defines an infinite set, we end up with a system having at least one equation. Its least solution is (L i1 , . . . , L i k ) where L i1 , . . . , L i k are the infinite components of L and i

1 < • • • < i k .
Remarks 3.40

(1) If S is a system as in the previous proof such that the m-th component T m of its least solution in P(T(F )) is finite, then the set L m is finite by Proposition 3.23(1), and we can take D := T m in order to eliminate x m . However, the converse need not be true, as shows the example of the equation system

x 1 = x 1 • x 2 ∪ a, x 2 = x 2 • x 2 ∪
associated with a context-free grammar with terminal alphabet A = {a}, to be solved in P(W(A)). In this case, T 2 = T ({•, }) is infinite but L 2 ⊆ A * consists only of the empty word.

(2) The construction described in the proof Proposition 3.39 is effective provided we know, for each m ∈ [n], whether L m is finite and, when it is, we also know a finite set of terms D that evaluate to its elements. The second condition is ensured when M is semi-effectively given and infinity-preserving, see Remark 3.38(3). Then we can compute the elements of L m , and for each element d of L m we can compute a term that evaluates to d by enumerating all terms of T (F ) and computing their value, cf. Definitions 2.8 and 2.127. The HR algebra JS and the VR algebra GP are effectively given and infinity-preserving, and it will be shown in Sections 4. 1.4 and 4.3.3 that the finiteness problem is decidable for their equational sets. Thus, Proposition 3.39 is effective for these algebras.

Using derived operations

We now examine the possibility of using in equation systems derived operations like series-composition in the equation that defines series-parallel graphs (cf. Sections 1.1.3 and1.4.2). This is interesting for several reasons: equation systems are in this way shorter and more clear, inductive proofs like those considered in Section 1.2.3 use less auxiliary inductive hypotheses and we will obtain a general notion of derivation tree that generalizes the classical one for context-free grammars (cf. Section 1.1.5).

We recall from Definition 2.125 that if H is a set of derived operation declarations of an S-signature F , then for every F -algebra M, we obtain an H-algebra M H . Its domains are those of M and its operations are the associated derived operations defined in M by H. A derived operation g is linear if its defining term t g is linear (i.e., no variable occurs twice or more in it). It is strict if each variable y i for i ∈ [ρ(g)] has an occurrence in t g . This condition implies that the corresponding function depends on all its ρ(g) arguments. A derived signature H is linear and/or strict if all its operations are linear and/or strict.

Proposition 3.41 Let H be a linear derived signature of an S-signature F . For every F -algebra M, we have

Equat(M H ) ⊆ Equat(M). If furthermore F ⊆ H, then Equat(M H ) = Equat(M).
Proof: Let L in Equat(M H ) be nonempty. Let S be an equation system over H such that L is defined by (S, Y ) in M H for some Y ⊆ Unk (S). By Proposition 3.33, we can assume that S is uniform. Let us write S = x 1 = p 1 , . . . , x n = p n where, for each i,

p i = • • • ∪ g(x i1 , . . . , x i k ) ∪ • • • . We let p i := • • • ∪ t g [x i1 /y 1 , . . . , x i k /y k ] ∪ • • •
where we assume that the linear term t g defining g is in T (F, Y k ) σ(xi) with Y k = {y 1 , . . . , y k } and that σ(y j ) = σ(x ij ) for each j. We let S be the equation system x 1 = p 1 , . . . , x n = p n over F .

We first assume that H is strict. The proof is easier, and this particular case will be useful. By Lemma 3.2(1) we have:

g P(M H ) (L i1 , . . . , L i k ) ⊆ t gP(M) (L i1 , . . . , L i k ) (3.2)
for all sets L 1 , . . . , L n of appropriate sorts. However, since H is linear and strict each variable y j has a unique occurrence in t g so that by Lemma 3.2(2) we have an equality in (3.2) (even if some of the sets L 1 , . . . , L n are empty).

It follows that S P(M) = S P(M H ) and that S P(M) and S P(M H ) have the same least fixed-point. Hence, the set L is defined by ( S, Y ) in M and belongs to Equat(M).

We now consider the case where H is linear but not necessarily strict. By Proposition 3.37, we can assume that the system S is trim and still uniform. From inequality (3.2) we get that:

S P(M H ) (L) ⊆ S P(M) (L) (3.3)
for every n-tuple L = (L 1 , . . . , L n ) of sets of appropriate sorts. It follows that:

µx • S P(M H ) (x) ⊆ µx • S P(M) (x).
However, it follows from Lemma 3.2(2) that S P(M H ) (L) = S P(M) (L) if L is nonempty, i.e., if its components are all nonempty. Since S is trim, the tuple

K := µx • S P(M H ) (x) is nonempty. Hence we have K = S P(M H ) (K) = S P(M) (K)
and so K is a solution of S in P(M). Hence, by Theorem 3.7, we have µx

• S P(M) (x) ⊆ K = µx • S P(M H ) (x)
, hence the equality which, as above, gives the desired conclusion.

The second assertion follows from Proposition 3.9(2) because M is a subalgebra of M H .

The hypothesis that the derived operations are linear is essential as shows the following example.

Examples 3.42

(1) By Corollary 3.14, the context-free languages over A := {a, b} are exactly the equational sets of W(A). Let us now enrich W(A) into W(A) sq by adding the derived unary operation sq defined by sq(u) := u • u for all u ∈ {a, b} * . The equation

x 1 = sq(x 1 ) ∪ a defines the set {a 2 n | n ≥ 0} that is equational in W(A) sq . It is not a context-free language because {2 n | n ≥ 0} is not semi-linear (cf. Section 3.1.6), hence is not equational in W(A).
(2) Next, we consider the system S = x = g(y, z), y = a, z = f (z) that is not trim, and we let g be defined by t g = f (y 1 ). The unknowns x and z of S define the empty set. If we replace g by its definition, we get the system x = f (y), y = a, z = f (z) for which x no longer defines the empty set. This shows that it is important to use a trim system if H is not strict.

(3) The proof of Corollary 3.26 can be presented in the following way. Let g be an affine mapping : T (F ) → N k , and let P be the associated F -algebra, as defined before Corollary 3.26. The operations of P are linear derived operations of N k and g = val P . If K ⊆ T (F ) is regular, then g(K) is equational in P by Proposition 3.23(3), hence equational in N k by Proposition 3.41 and semi-linear by Proposition 3.25.

We now use derived signatures to generalize the algebraic definition of derivation trees that has been given informally in Example 1.3 (Section 1.1.5) for the context-free grammar G of Example 1.1.

Definition 3.43 (Derivation trees and parsing)

Let S = x 1 = p 1 , . . . , x n = p n be an equation system over an S-signature F , where, for each i, [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]4,[START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF].) This implies that σ(y l ) = σ(x i l ) for each l. 10 We let q i,j be a function symbol of type σ(y

p i = m i,1 ∪ • • • ∪ m i,ri for some monomials m i,j . For 1 ≤ i ≤ n, 1 ≤ j ≤ r i , we let m i,j ∈ T (F, {y 1 , . . . , y k }) be the (unique) term such that ListVar ( m i,j ) = y 1 • • • y k and m i,j = m i,j [x i1 /y 1 , . . . , x i k /y k ] for some i 1 , . . . , i k . (For example, if m i,j = f (g(x 2 , x 1 ), h(x 4 , x 1 )), then m i,j = f (g(y 1 , y 2 ), h(y 3 , y 4 )) and (i 1 , i 2 , i 3 , i 4 ) = (2,
1 )ו • •×σ(y k ) → σ(x i ).
We obtain thus an S-signature

Q := {q i,j | 1 ≤ i ≤ n, 1 ≤ j ≤ r i }
, associated with the system S. We turn each q i,j ∈ Q into a linear and strict derived operation of F , defined as λy 1 , . . . , y k • m i,j . And we let S be the uniform system x 1 = p 1 , . . . , x n = p n where p i is obtained from p i by replacing m i,j by q i,j (x i1 , . . . , x i k ).

For every F -algebra M, we get a Q-algebra M Q with the same sorts and the same domains (cf. Definition 2.125). It is a derived algebra of M. By the definitions and Lemma 3.2(4), we have S P(M) = S P(M Q ) . For checking this fact we observe that:

m i,j P(M) (A 1 , . . . , A n ) = { m i,j (a 1 , . . . , a k ) | a 1 ∈ A i1 , . . . , a k ∈ A i k } = q i,j P(M Q ) (A i1 , . . . , A i k ),
where the sets A 1 , . . . , A n may be empty, since Q is a strict and linear derived signature (cf. the proof of Proposition 3.41). Hence we have:

µx • S P(M Q ) (x) = µx • S P(M) (x).
We now compare the solutions of S and S in their respective term algebras. The least solution of

S in P(T(Q)) is an n-tuple of sets of terms (D 1 , . . . , D n ) such that D i ⊆ T (Q) σ(xi)
for each i. We have by Proposition 3.23 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]:

µx • S P(M Q ) (x) = (val M Q (D 1 ), . . . , val M Q (D n )). If d ∈ D i and val M Q (d) = m (
which implies that m belongs to µx•S P(M) (x) x i ), then we say that d is a derivation of tree of m relative to (S, x i ). Each element of a set µx • S P(M) (x) x i has at least one derivation tree relative to (S, x i ). If it has a unique one, we will say that S is unambigous in M. However, for dealing with graphs, we will almost never be able to use unambiguous systems.

The elements of D i are called the derivation trees of S relative to x i . A derivation tree d ∈ D i can be evaluated in the derived algebra M Q , but also in M as follows: by Proposition 2.126, we have val

M Q (d) = val M (θ Q (d)) where θ Q is the second-order substitution : T (Q) → T (F ) associated with the derived signature Q. It follows that: µx • S P(M) (x) = (val M (θ Q (D 1 )), . . . , val M (θ Q (D n ))).
In particular, the least solution of

S in P(T(F )) is (θ Q (D 1 ), . . . , θ Q (D n )), and θ Q = val T(F ) Q by Proposition 2.126.
Let M be a semi-effectively given F -algebra and S be an equation system as above with least solution (L 1 , . . . , L n ) in P(M). A parsing algorithm for (S, M) takes as input an unknown x i of S and an element m of M and outputs either the answer that m is not in L i or a derivation tree d of m relative to (S, x i ). In the latter case, one can compute in linear time in |d| the term θ Q (d) ∈ T (F ) that evaluates to m (cf. the discussion before Proposition 2.126).

Example 3.44 We consider the equation

T = (T (T T )) ∪ (T • (T T )) ∪ e (3.4)
over the algebra J d 2 in which we have defined series-parallel graphs in Section 1.1.3. It defines a particular set of series-parallel graphs. This equation can be written:

T = q 1 (T, T, T ) ∪ q 2 (T, T, T ) ∪ q 3 (3.5)
where q 1 := λy 1 , y 2 , y 3 • y 1 (y 2 y 3 ), q 2 := λy 1 , y 2 , y 3 • y 1 • (y 2 y 3 ) and q 3 := e. Equation (3.4) defines a set of terms in T ({ , •, e}) containing, to take an example, the term t = (e • (e e)) (e (e (e e))). The corresponding derivation tree is the term d = q 1 (q 2 (q 3 , q 3 , q 3 ), q 3 , q 1 (q 3 , q 3 , q 3 )), and we have t = θ Q (d) where θ Q is the second-order substitution associated with the above definitions of q 1 , q 2 , q 3 .

Closure properties of the class of equational sets

We prove some closure properties of the class of equational sets of general algebras. Further properties particular to graph algebras will be proved in Chapter 4.

Proposition 3.45 Let M be an F -algebra.

(

) If L 1 , L 2 ∈ Equat(M), then L 1 ∪ L 2 ∈ Equat(M). 1
(2) Every finite subset of val M (T (F )) is equational in M.

(

) If f ∈ F has type s 1 × s 2 × • • • × s k → s and L i ∈ Equat(M) si for each i = 1, . . . , k, then f P(M) (L 1 , . . . , L k ) ∈ Equat(M) s . 3
Proof: (1) Let L 1 be defined by (S 1 , Y 1 ) in M, and L 2 by (S 2 , Y 2 ). By renaming the unknowns of one of the systems if needed, we may assume that Unk (S 1 ) and Unk (S 2 ) are disjoint. Let S be the union of S 1 and S 2 . By Lemma 3.27,

L 1 is defined by (S, Y 1 ) and L 2 is defined by (S, Y 2 ) in M. Hence L 1 ∪ L 2 is defined by (S, Y 1 ∪ Y 2 ).
(2) By ( 1), it suffices to prove this for a homogenous subset. If t 1 , . . . , t p ∈ T (F ) s , then the set {t 1M , . . . , t pM } = val M ({t 1 , . . . , t p }) is defined by the equation

x 1 = t 1 ∪ s • • • ∪ s t p .
(3) For k = 2 the proof is similar to the one for ( 1), but we add to S the new equation

z = {f (y 1 , y 2 ) | y 1 ∈ Y 1 , y 2 ∈ Y 2 }. Then f P(M) (L 1 , L 2 ) is defined by (S, z) in M.
The generalization to functions f of any positive arity is clear. The case k = 0 follows from (2) (we have in this case f P(M) = {f M }).

Concluding remarks on equational sets

What are equation systems good for?

What are the benefits of defining a set L of words, of graphs or of other combinatorial objects by an equation system? First, such a set L has a finite description that can be used by algorithms, e.g., for deciding its emptiness, for computing it in certain cases or for extracting numerical information; Proposition 3.10, Corollary 3.24 and Corollary 3.26 have given such algorithms. Second, every element of L has a denotation by at least one term over the signature of the relevant algebra (by Proposition 3.23( 1)) and has a hierarchical structure expressed by its derivation trees and by the corresponding terms (cf. Definition 3.43). Third, certain universal properties of L can be proved inductively as we have seen in Proposition 1.6. This proposition will be generalized below in Proposition 3.91 (Section 3.4.7). Finally, the Filtering Theorem (Theorem 1.8 and Theorem 3.88 below) yields effective constructions of equation systems that define certain subsets of given equational sets.

Applications to graphical objects are developed by Drewes in [*Dre06]. He defines grammars that generate pictures, i.e., drawn graphs or images in an abstract setting. His "tree-based approach" is algebraic and the context-free sets he defines are equational.

Some difficulties

Here are some of the problems raised by equation systems and equational sets. First the parsing problem (cf. Definition 3.43): we have observed at the end of Section 3.1.2 that the membership problem may be undecidable for equational sets of effectively given algebras; the existence of efficient parsing algorithms depends on the considered algebras. For the equational sets of the HR and the VR algebras, the membership problem is always decidable but sometimes NPcomplete (see Sections 4. 1, 4.3 and 6.2). Every element of an equational set has at least one derivation tree. The non-ambiguity of the corresponding system, that is, the case where each generated element has a unique derivation tree, is interesting, in particular for counting the elements of a given size (cf. the book [*FlaSed]). However, even for context-free languages the non-ambiguity is a difficult notion: it is undecidable and certain context-free languages have no unambiguous grammar. Nothing can be said in general, and equational sets of graphs are very seldom defined by unambiguous equation systems. A last question concerns the closure of the class of equational sets under transformations that would generalize the rational transductions of words. Apart from the closure under homomorphisms, an easy but fundamental result proved in Proposition 3.23 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF], not much can be said for general algebras. But a theory of graph transductions, based on monadic second-order logic, informally presented in Section 1.7, will be developed in Chapter 7. These transductions preserve the equationality of sets of graphs.

We now review some notions related to equation systems.

µ-calculus

The µ-calculus, studied in the book by Arnold and Niwinski [*ArnNiw], offers notation for equational sets. For example, the least solution of the system S = x = f (x, y) ∪ a, y = g(x, y) ∪ b in every powerset {f, g, a, b}-algebra is denoted by the µ-term11 µ(x, y)

• (f (x, y) ∪ a, g(x, y) ∪ b) of the vectorial µ- calculus (Section 2.7 of [*ArnNiw]
). This term evaluates to µ(x, y) • S P(M) (x, y) in each powerset {f, g, a, b}-algebra P(M).

Furthermore, each component of the least solution of an equation system is the value of a µ-term that only uses least fixed-points over variables, not over tuples of variables. For example, µ(x, y)

• S P(M) (x, y) x is the value in P(M) of the µ-term µx • (f (x, µy • (g(x, y) ∪ b)) ∪ a) (Lemma 1.4.2 of [*ArnNiw]).
However, the general µ-terms can be written with set intersection and a greatest fixed-point operator (that is dual in some sense to the least fixed-point one). Hence, they can also define sets that are not equational: for example, the intersection of two context-free languages (even without using greatest fixedpoints). The emptiness of the corresponding sets is thus undecidable, whereas that of equational sets is decidable.

Rational expressions

The rational sets of a monoid M are the members of the least class of subsets of M that contains the finite sets and is closed under union, the multiplication of M extended to sets and denoted by • P(M) , and the star operation, that is defined as follows (where • denotes • P(M) and 1 denotes 1 M ):

if L ⊆ M , then L * is the least subset X of M such that: X = L • X ∪ {1} (or equivalently X = X • L ∪ {1} or X = X • X ∪ L ∪ {1}).
Rational sets can thus be defined by µ-terms, but a regular expression like a(ab * ) * ac * that defines a regular (also called rational ) language is more readable than its translation into a µ-term.

The rational sets of a monoid M are equational in M and form in most cases a proper subclass of Equat(M), denoted by Rat(M). However, in a commutative monoid every equational set is rational (this is proved in [AceEI] and entails Proposition 3.25).

If M is the monoid of words over a finite alphabet, then Rat(M) is the class of regular languages by a well-known result due to Kleene (cf. [*Eil, *Sak]). For this reason, rational sets are frequently presented in connection with finite automata 12 . However, Rat(M) is more relevant to Equat(M) than to the class Rec(M) of recognizable sets that generalizes the class of regular languages. (We will define and study this class in Section 3.4). More will be said about rational sets in Section 3.4.10.

Intermezzo on automata

Finite automata on terms correspond to regular grammars, hence they define the equational sets of terms. The deterministic automata have the same expressive power as the general ones, but furthermore, they correspond to finite congruences. Hence they define the recognizable sets of terms, which turn out to be the same as the equational sets. Recognizability has been introduced in Section 1.2 and will be the subject of Section 3.4. Here, we only review the definitions and properties of those automata on terms that are closely linked (in different ways) to the equational and to the recognizable sets in general algebras. Automata on terms are studied in detail in the book [*Com+] and in the book chapter [*GecSte].

The equational sets of the term algebra T(F ) are important (by Proposition 3.23( 1)) because for every F -algebra M, a subset L of M is equational if and only if it is val M (K) for some equational set K of T(F ). Hence every term in K can be used as a linear notation for an element of L. Furthermore, if t ∈ K and val M (t) = m, then t defines a kind of hierarchical decomposition of m because if t = f (t 1 , t 2 ), then m is the composition of val M (t 1 ) and val M (t 2 ) by f M and the same holds for t 1 , t 2 and all their subterms. Algorithms for checking properties of elements of equational sets can be based on such decompositions, as we will see for graphs in Chapter 6. Thus, we obtain linear and structured notations for the elements of equational sets.

The relationships between recognizability and deterministic automata will be developed in Section 3.4.2. We review, and even slightly extend, the classical notion of an automaton to be run on terms.

Automata on terms

In this section and the next, sets of sorts and signatures are finite.

Definition 3.46 (Automata)

Let F be a finite S-signature13 . An F -automaton (or just automaton if F need not be specified)

14 is a 4-tuple A = F, Q A , δ A , Acc A such that Q A is a finite or infinite S-sorted set called the set of states (σ(q) ∈ S is the sort of q ∈ Q A ), Acc A is a subset of Q A called
the set of accepting states and δ A is a set of tuples called the set of transition rules, satisfying the following two conditions (we recall that F k denotes the set of symbols of F of arity k):

(1) Each element of δ A is of one of the two possible forms:

(1.1) (q 1 , . . . , q k , f, q) for k ≥ 0, q 1 , . . . , q k , q ∈ Q A , f ∈ F k , (1.2) (q, q ) for q, q ∈ Q A ; these pairs are called the ε-transitions.

(2) The sort mapping σ : Q A → S satisfies the following conditions:

(2.1) f has type σ(q 1 ) × • • • × σ(q k ) → σ(q) in any tuple of the form (1.1), (2.2) σ(q) = σ(q ) for every ε-transition (q, q ). For better readability, we will denote by f [q 1 , . . . , q k ] → A q (and by f → A q if f ∈ F 0 ) a transition rule of type (1.1) and by q → A q an ε-transition. Each of these transition rules is said to yield q (the last component of the tuples).

A triple A = F, Q A , δ A where F , Q A and δ A are as above is called an F -semi-automaton. Hence, it is just an F -automaton without accepting states. The definitions given below for semi-automata extend to automata in the obvious way.

A semi-automaton

A is ε-free if it has no ε-transitions. It is finite if its set of states Q A is finite (which implies that δ A is finite).
We denote by A := |Q A | the cardinality of Q A . We define the size of A , denoted by A , as the sum of weights of its transition rules where the weight of a rule relative to a function symbol f is ρ(f ) + 1 and that of an ε-transition is 2. Hence we have:

A ≤ 2 • ( A ) 2 + Σ f ∈F (ρ(f ) + 1) • ( A ) ρ(f )+1 .
If the function symbols are at most binary, which will be frequently the case for the automata of Chapter 6, then

A = O(|F | • ( A ) 3 ).
The size of A is thus proportional to the space needed to store its transition rules as a list of tuples, where we assume that states use constant space. If the number of states is very large (which will be the case in Chapter 6), then a state may need log( A ) bits to be stored15 .

A run of an ε-free semi-automaton A on a term t ∈ T (F ) is a mapping r :

Pos(t) → Q A such that: (i) if u is an occurrence of a constant symbol f , then f → A r(u), (ii) if u is an occurrence of a function symbol f ∈ F k , for k > 0, with sequence of sons 16 u 1 , . . . , u k , then f [r(u 1 ), . . . , r(u k )] → A r(u).
If A is not ε-free, then → * ε is the reflexive and transitive closure of the set of ε-transitions. We let δ ε A be the set of transition rules f [q 1 , . . . , q k ] → q such that f [q 1 , . . . , q k ] → A q for some q such that q → * ε q. We have

δ A ⊆ δ ε A . A run of A is defined as a run of the ε-free semi-automaton F, Q A , δ ε A . For q ∈ Q A , we let L(A , q) be the set of terms t in T (F ) on which there is a run r of A such that r(root t ) = q. It is clear that L(A , q) ⊆ T (F ) σ(q) for every q in Q A .
If A is an automaton, then a run r on t is accepting if r(root t ) is an accepting state. We let L(A ) := q∈Acc A L(A , q) ⊆ T (F ). It is the set of terms on which A has an accepting run. We say that L(A ) is the language accepted (or recognized ) by A . Two automata are equivalent if they accept the same language.

Regular grammars

We now relate automata with regular grammars and equation systems. With every finite F -semi-automaton A = F, Q, δ , we associate a regular grammar G(A ) over F (without initial nonterminal) as follows: its set of nonterminals is Q and its rules are q → q if q → A q and q → f (q 1 , . . . , q k ) if f [q 1 , . . . , q k ] → A q. It is clear that L(G(A ), q) = L(A , q) for every state q. If A is an automaton, then L(A ) is the union of the languages generated by G(A ) from its nonterminals that are the accepting states of A , i.e., L(A ) = L(G(A ), Acc A ).

By Definition 3.17, there is an equation system S(A ) such that G(S(A )) = G(A ). The grammar G(A ) and the equation system S(A ) are quasi-uniform. If A is ε-free, then they are uniform. Conversely, every quasi-uniform (resp. uniform) regular grammar is G(A ) for some finite semi-automaton (resp. some finite ε-free semi-automaton) A , and similarly for S(A ). From Proposition 3.33 we get the following proposition17 that subsumes Corollary 3.19 for a finite Ssignature F : Proposition 3.47 Let F be finite and L ⊆ T (F ).

(1) The language L is accepted by a finite F -automaton if and only if it is regular over F , if and only if it is equational in T(F ).

(2) It is accepted by an automaton with n states if and only if it is defined by a uniform equation system with n unknowns, if and only if it is generated by a uniform regular grammar with n nonterminals.

The term "regular" for a language will refer to its definition by finite automata as well as by regular grammars (in the case where F is finite).

Special types of automata Definition 3.48 (Trim and reduced automata)

A state q of a semi-automaton A is accessible if L(A , q) = ∅, i.e., if it occurs in a run of A on some term, equivalently if it is a productive nonterminal of the grammar G(A ). We say that A is trim if its states are all accessible. An automaton A is reduced if each state belongs to the image of an accepting run, i.e., is useful for accepting some term.

Obviously, one can trim a semi-automaton A by trimming the corresponding equation system S(A ), i.e., by constructing Trim(S(A )) and turning that system back into a semi-automaton. Similarly, one can reduce an automaton A by constructing Trim(S(A ), Acc A ) and turning that back into an automaton. Thus, by Proposition 3.37, one can effectively transform each semi-automaton A into a trim semi-automaton B such that

Q B = {q ∈ Q A | L(A , q) = ∅} and L(B, q) = L(A , q) for every q ∈ Q B .
Similarly, every automaton can be effectively transformed into an equivalent reduced automaton.

Definition 3.49 (Deterministic and complete automata) An F -semi-automaton A is deterministic if it is ε-free and for every q 1 , . . . , q k and every f ∈ F k , there is at most one state q such that f [q 1 , . . . , q k ] → A q. It is complete if for every q 1 , . . . , q k and every f in F k such that α(f ) = (σ(q 1 ), . . . , σ(q k )), there is a state q such that f [q 1 , . . . , q k ] → A q. If A is deterministic and complete, then its size A (cf. Definition 3.46) is exactly

Σ f ∈F (ρ(f ) + 1) • ( A ) ρ(f ) .
By the addition of at most one state of each sort (such states are usually called sinks), one can transform a deterministic semi-automaton A into a complete and deterministic one B such that L(B, q) = L(A , q) for every state q of A .

Let A be deterministic and complete: on each t ∈ T (F ) it has a unique run, which will be denoted by run A ,t . If the transition relation is a computable function18 , which means that for given function symbol f and states q 1 , . . . , q ρ(f ) of appropriate sorts the unique state q such that f [q 1 , . . . , q ρ(f ) ] → A q can be computed by an algorithm, then this run can be computed during a bottom-up traversal of t. This computation takes time a • |t| where a is an upper-bound to the time taken to perform a transition, that is, to find or compute from f, q 1 , . . . , q k the state q such that f [q 1 , . . . , q k ] → A q. This value a is significant if the transition has to be computed, but also if the automaton is finite but is so large that some time (that is no longer considered as constant) is required to find the appropriate transition in a table. 19We recall the classical determinization of automata (cf. Section 5 of [*GecSte] or Theorem 1.1.9 of [*Com+]).

Proposition 3.50 For every finite automaton A , one can construct a trim, complete and deterministic finite automaton B that is equivalent to A .

We only recall that the states of B of sort s are sets of states of A of sort s and that |Q B,s | ≤ 2 |Q A ,s | where Q A ,s is the set of states of sort s of A and similarly for B.

Assuming fixed some determinization algorithm, we will denote B by det(A ). In particular, we will assume that det(A ) = A if A is already trim, complete and deterministic.

Remarks 3.51

(1) For every many-sorted signature F , we let F -be the one-sorted signature obtained from F by forgetting sorts (cf. Lemma 3.21). Every F -automaton A is an F --automaton, and thus, every regular language L ⊆ T (F ) is regular over F -. Conversely, a regular language L over F -such that L ⊆ T (F ), is regular over F by Corollary 3.19 and the observations made in Remark 3.38(4).

(2) Automata on words are just particular automata on terms, because words over an alphabet A correspond bijectively to terms over the unary functional signature U A , as explained in Definition 2.7. More precisely, a word w :=

a 1 • • • a n with a 1 , . . . , a n in A is the value of the term t := a n (• • • (a 1 ( )) • • • ) in the U A -algebra W right (A).
The runs of a U A -automaton A on the term t correspond bijectively to those of an automaton B (with the same set of states) on the word w. We do not detail the obvious correspondence between the automaton A on terms and the automaton B on words. Thus, as already explained in Remark 3.20(4) and after Proposition 3.23, a language over the alphabet A is regular if and only if the corresponding set of terms is regular over U A .20

Allowing infinite sets of states in automata makes it possible to enrich them so that, in addition to checking if a term t belongs to a regular language, an automaton can compute some value attached to t. This feature will be used in Chapter 6, but we give immediately an example.

Example 3.52 We let F = {f, a, b}, ρ(f ) = 2, ρ(a) = ρ(b) = 0 and L be the set of terms in T (F ) that have an even number of occurrences of a. The following automaton A accepts L and computes ht(t), the height of t. It is defined as follows:

Q A := {q 0 , q 1 } × N , Acc A := {q 0 } × N , δ A is the set of rules: a → (q 1 , 0), b → (q 0 , 0), f [(q i , n), (q j , p)] → (q l , r) such that r = max{n, p} + 1, i, j, l ∈ {0, 1}, l = mod 2 (i + j).
It is clear that A is complete and deterministic, that L(A ) = L and that, for t ∈ L, we have ht(t) = n if and only if t ∈ L(A , (q 0 , n)). Hence the unique run of A on a term t not only evaluates the relevant parity information (by means of the first components of the states) but it also evaluates the heights of the subterms of t. Whether t is accepted or not by A depends only on the parity information and not on the heights of subterms. Hence the language L(A ) is regular.

Pumping arguments

The following proposition collects results proved by so-called pumping arguments. The size of a term is the number of its positions, or its length if it is considered as a word (without commas and parentheses, cf. Definition 2.3). We let F be a finite signature of maximal arity ρ(F ) = k ≥ 1, consisting of c constant symbols and d symbols of positive arity. The size of a term in T (F ) of height m ≥ 0 (a constant has height 0) is bounded by k (m) where:

k (m) := 1 + k + k 2 + • • • + k m .
The number of terms of height at most m is bounded by k,c,d (m) defined by

k,c,d (m) := (c + d + 1) k (m) ,
which gives:

k,c,d (m) ≤ (c + d + 1) k m+1 for k ≥ 2, and for k = 1: 1,c,d (m) ≤ (c + d + 1) m+1 .
However, to have better bounds, we can use instead: 1) for m ≥ 1.

k,c,d (0) := c and k,c,d (m) := c k m • (d + 1) k (m-
Proposition 3.53 Let F be a finite signature of maximal arity k ≥ 1 having c constant symbols and d symbols of positive arity. Let L ⊆ T (F ) be nonempty and accepted by a finite F -automaton A with m + 1 states or defined by a uniform equation system with m + 1 unknowns (m ≥ 0).

(1) The height of a term of minimal size in L is at most m and its size is at most k (m).

(2) The finiteness of L is decidable. If L is finite, then the height of a term in L is at most m and its size is at most k (m). Furthermore, L can be computed and its cardinality is at most k,c,d (m).

Proof: By Proposition 3.47, we need only consider the case where L = L(A ). We use a classical argument (cf. Chapter 1 of [*Com+] or Proposition 5.2 of [*GecSte]). If A has an accepting run r on a term t such that r(u) = r(v) for some positions u, v with u < t v, then L = L(A ) contains a term smaller than t and infinitely many terms larger than t.

To prove this, we write

t = c[c [t ]] where c, c ∈ Ctxt(F ), c is not empty, t = t/u and c [t ] = t/v. Then c[t ] belongs to L(A ) and is smaller than t, whereas all terms c[c [c [• • • [c [t ]] • • • ]]
] with at least two copies of c belong to L(A ), are pairwise different and larger than t.

The bounds on heights, sizes and numbers of terms in the statement follow immediately. It is straightforward to show that L is infinite if and only if it contains a term of height at least m + 1 and at most 2m + 2 (by choosing c such that the length of the path from the root to the context variable is at most m + 1). This implies the decidability of finiteness21 .

By such arguments, one can prove that certain languages are not regular.

Here is an example to be used later.

Example 3.54 We prove the claim made in Remark 3.20(1) that the language

L = {f g n ag n b | n ≥ 0} (with ρ(f ) = 2, ρ(g) = 1, ρ(a) = ρ(b) = 0) is not regular.
Assume it is: then it is accepted by a complete deterministic finite automaton (by Proposition 3.50). There exist two integers n and m < n such that the unique runs of this automaton on the terms g m a and g n a yield the same state. It follows that the term f g m ag n b is accepted by this automaton but does not belong to L. This contradicts the initial assumption. Hence L is not regular.

The recognizable sets of an algebra

In the previous three sections, we have defined and studied the equational sets of an algebra. These sets generalize the context-free languages, and also the regular languages (of words and terms). We now define the recognizable sets: they generalize the characterization of regular languages formulated in terms of finite congruences.

Definitions and examples

An F -algebra A is locally finite if each domain A s is finite. It is finite if, furthermore, its set of sorts S is finite (although F may be infinite).

Definition 3.55 (Recognizable sets of an algebra) Let M be an F -algebra. A recognizable set of M is a set L ⊆ M of the form L = h -1 (C) where h : M → A is a homomorphism of F -algebras, A is locally finite and C ⊆ A. We will say that h witnesses the recognizability of L. We may in addition require that h is surjective. If this is not the case, we replace A by its subalgebra that is the image of M under h, and the set C by its intersection with h(M ). The requirement that h is surjective does not change the notion of recognizability.

We denote by Rec(M) the set of recognizable sets of M and by Rec(M) s the set of those included in M s for s in S. We will also say that a set in Rec(M) is M-recognizable or recognizable in M. Just as equational sets, recognizable sets need not be homogenous, i.e., they may have elements of different sorts; unlike equational sets, they may have elements of countably many different sorts.

Proposition 3.56

(1) Let M be an F -algebra and M be an

F -algebra such that M ⊆ M. If L ∈ Rec(M), then L ∩ M ∈ Rec(M ). In particular, Rec(M) ∩ P(M ) ⊆ Rec(M ).
(

) Let k : M → M be a homomorphism of F -algebras. If L ∈ Rec(M), then k -1 (L) ∈ Rec(M ). (3) If H is a derived signature of F and M is an F -algebra, then Rec(M) ⊆ Rec(M H ). If furthermore F ⊆ H, then Rec(M) = Rec(M H ). Proof: (1) Let the homomorphism h : M → A of F -algebras witness the recognizability of L in M. Thus, L = h -1 (C) with C ⊆ A. Let A := A F , cf. Definition 2.123. Then the restriction h of h to M is a homomorphism : M → A that witnesses the recognizability of L ∩ M in M , because L ∩ M = (h ) -1 (C ∩ A ). 2
(2) If h is as in ( 1), then the homomorphism h • k : M → A witnesses the recognizability of k -1 (L), with the same C.

(3) Let h :

M → A witness the recognizability in M of a set L. Since h is a homomorphism, we have h(t M (m 1 , . . . , m n )) = t A (h(m 1 ), . . . , h(m n )) for every t ∈ T (F, X n ) and m 1 , . . . , m n ∈ M of appropriate sorts. Hence, h is a homo- morphism : M H → A H . It witnesses the recognizability of L in M H , with the same C. The last assertion follows from (1) because then M ⊆ M H .
Note that, by the first assertion of this proposition, if we enrich an algebra by adding new operations, then the class of recognizable sets decreases or remains the same. It remains the same if we add or delete constants. In fact, if h : M → A is a homomorphism and c M is a new constant added to M, then h remains a homomorphism if we define c A := h(c M ).

We had a statement similar to the first assertion for equational sets in Proposition 3.9(2), but with an opposite inequality. The second assertion is similar to the one in Proposition 3.23(2), but in the opposite direction. Finally, a statement similar to the third assertion is in Proposition 3.41 but only for linear derived operations, and with an opposite inequality. Other results of this kind will be stated in Proposition 3.85.

Examples 3.57

(1) Let A be the alphabet {a, b}. The language L = a * b * is recognizable in the unary algebra W right (A) (cf. Definition 2.7). To see this we consider the U A -algebra B with domain {1, 2, Error }, with constant B := 1 and operations such that:

a B (1) := 1, a B (2) := a B (Error ) := Error , b B (1) := b B (2) := 2, b B (Error ) := Error . Then L = h -1 ({1, 2}) where h is the unique homomorphism of W right (A) (isomorphic to T(U A )) into B. We have h -1 (1) = a * , h -1 (2) = a * b + and h -1 (Error ) = A * baA * .
(2) We let A and L be as in [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. The language L is also recognizable in W(A) because L = l -1 ({0, 1, 2, 3}) where l is the unique homomorphism of W(A) into the F A -algebra D such that D := {0, 1, 2, 3, Error }, D := 0, a D := 1, b D := 2 and the operation • D is defined by: 0 We have then l

• D x := x • D 0 := x for every x in D, 1 • D 1 := 1, 1 • D 2 := 3, 1 • D 3 := 3, 2 • D 2 := 2, 3 • D 2 := 3,
-1 (0) = {ε}, l -1 (1) = a + , l -1 (2) = b + , l -1 (3) = a + b + and l -1 (Error ) = A * baA * .
These two examples are particular cases of theorems that relate recognizability and finite automata. In particular, for every finite alphabet A, we have:

Rec(W(A)) = Rec(W left (A)) = Rec(W right (A))
and this is the class of regular languages over A (see [*Eil], or [*Sak], Chapter II, Theorem 2.3).

(3) We let

K := {4 + 3 • λ | λ ∈ N } ⊆ N .
This set is recognizable in the monoid N , +, 0 (which we also denote by

N) because K = k -1 ({4})
where k is the unique homomorphism of N into the monoid E such that E := {0, 1, 2, 3, 4}, k(1) := 1, the unit of E is 0 (so that k(0) = 0) and the addition in E is defined by:

x

+ E y :=      x + y if x + y ≤ 4 x + y -3 if 4 < x + y ≤ 7 x + y -6 if x + y > 7. We have then k -1 (0) = {0}, k -1 (1) = {1}, k -1 (2) = {2 + 3 • λ | λ ∈ N }, k -1 (3) = {3 + 3 • λ | λ ∈ N } and k -1 (4) = K.
This is a particular case of a characterization of the N-recognizable sets (cf. Proposition 3.93 below in Section 3.4.8).

(4) Let S be a finite set of sorts and F be a (possibly infinite) S-signature. For each sort s in S the set T (F ) s is recognizable in T(F -) and so is T (F ). We recall, cf. Remark 3.51 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF], that F -is the one-sorted signature obtained from F by "forgetting sorts". For proving this, we define an F --algebra S ⊥ with domain S ⊥ := S ∪ {⊥} and operations f S defined by:

f S ⊥ (s 1 , . . . , s ρ(f ) ) := σ(f ) if α(f ) = (s 1 , . . . , s ρ(f ) ) ⊥ otherwise.
It is clear that the mapping h : T (F -) → S ⊥ such that:

h(t) := s if t ∈ T (F ) s for s ∈ S ⊥ otherwise, is a homomorphism. Hence the sets T (F ) s = h -1 ({s}) and the set T (F ) = h -1 (S) are recognizable in T(F -).
(5) Let M be an F -algebra for an S-signature with S possibly infinite. Each domain M s is recognizable in M and so is M . A similar statement for equationality is in Proposition 3.23(4). For proving this, we use the F -algebra S defined as S ⊥ in the previous example but without ⊥, and where {s} is the domain of sort s for each s in S. We omit the easy verification.

(6

) If L is recognizable in M, then L ∩ M s is also recognizable in M for each sort s, because, if L is as in Definition 3.55, then we have L∩M s = h -1 (C ∩A s ). The converse is false. Let S := N , F := {a, f, g 1 , . . . , g n , . . . } with ρ(a) := 0, σ(a) := 0, f of type 0 → 0 and g i of type 0 → i for each i ≥ 1. Let L := {g i f i a | i ≥ 1}.
For each i ≥ 0 the set L ∩ T (F ) i is the singleton set {g i f i a} or the empty set, hence is recognizable in T(F ) (say by Theorem 3.62 below) but L is not. We will prove this last fact by means of congruences in Example 3.71 in Section 3.4.3.

Recognizable sets of terms

Before exposing the general properties of recognizable sets, we show that a set of terms over a finite signature is recognizable if and only if it is accepted by a finite, complete and deterministic automaton (cf. Section 1.2.4).

Definition 3.58 (Deterministic automata and algebras)

Let F be a finite S-signature, let B = (B s ) s∈S , (f B ) f ∈F be an F -algebra and let C ⊆ B. We let A := A (B, C) be the complete and deterministic F -automaton such that Q A := B, Acc A := C and

δ A := {f [b 1 , . . . , b ρ(f ) ] → f B (b 1 , . . . , b ρ(f ) ) | f ∈ F, b i ∈ B α(f )[i] for i ∈ [ρ(f )]}.
The set of states of A is S-sorted with sort mapping σ such that σ(b) = s if and only if b ∈ B s . 22 We let A (B) be the corresponding semi-automaton.

Conversely every complete and deterministic F -automaton A is A (B, C) for some F -algebra B with B s := {q ∈ Q A | σ(q) = s} and C := Acc A . The following lemma is clear from the definitions. Lemma 3.59 Let F be a finite signature and B be an F -algebra.

(1) For every term t ∈ T (F ), the unique run run A (B),t :

Pos(t) → B of the semi-automaton A (B) on t verifies run A (B),t (u) = val B (t/u) for all u ∈ Pos(t). We have L(A (B, C)) = val -1 B (C) for every subset C of B.
(2) The semi-automaton A (B) is trim if and only if the algebra B is generated by F .

Note that B need not be finite for this lemma to be valid. If B is finite (equivalently, is locally finite since S is assumed finite) then A (B, C) is a finite automaton, and vice versa. We obtain that a subset of T (F ) is recognizable in T(F ) if and only if it is accepted by a finite F -automaton. Before stating this as a theorem that will extend Corollary 3.19 and Proposition 3.47(1), we consider sets of terms over infinite signatures. A recognizable set of T(F ) such that F is infinite is not necessarily a subset of T (F ) for some finite subsignature F of F because T (F ) itself is recognizable (by Example 3.57( 5)). For the sake of comparison, we recall from Proposition 3.9 that an equational set of terms over an infinite signature F uses only a finite subsignature F of F and is equational in T(F ).

We first prove that the recognizability of a set of terms over a signature F is the same when considered with respect to T(F ) and to T(F ), where F is any signature containing F as a subsignature. Hence the recognizability of a set of terms is an intrinsic property23 , although this is not completely evident from the definition.

Proposition 3.60 Let F be a subsignature of a signature F . A subset L of T (F ) is T(F )-recognizable if and only if it is T(F )-recognizable.
Proof: Let S be the set of sorts of F . The term algebra T(F ) has no domain of sort s if s ∈ S -S , and

T (F ) s ⊆ T (F ) s if s ∈ S .
Since T(F ) ⊆ T(F ), Proposition 3.56 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] implies that every T(F )-recognizable subset of T (F ) is T(F )-recognizable. Let us conversely assume that L = val -1 A (C) for a locally finite F -algebra A and C ⊆ A . For every s ∈ S, let ⊥ s be a new element of sort s. Let A be the locally finite F -algebra with domains A s = A s ∪ {⊥ s } for s ∈ S , and A s = {⊥ s } for s ∈ S -S , and with operations f A , for f ∈ F , defined as follows (where f has type

s 1 × • • • × s k → s): for all a 1 , . . . , a k ∈ A such that a i ∈ A si for every i ∈ [k], we let f A (a 1 , . . . , a k ) := f A (a 1 , . . . , a k ) if a 1 , . . . , a k ∈ A and f ∈ F , and f A (a 1 , . . . , a k ) := ⊥ s otherwise. Obviously, val A (t) = val A (t) for every t ∈ T (F ). Hence L = val -1 A (C) is recognizable in T(F ).
Example 3.61 (Recognizable sets of words over infinite alphabets)

If A is a finite or infinite alphabet, then W(A) is the F A -algebra A * , •, ε, (a) a∈A
where each letter a is a constant symbol denoting itself. (It is the free monoid generated by the set of constants A.)

A recognizable subset of W(A) is a lan- guage L ⊆ A * of the form h -1 (C) where h is a homomorphism : W(A) → B = B, • B , B , (h(a)) a∈A such that B, • B , B is a finite monoid and C ⊆ B. If A is finite, then L ⊆ A * is recognizable in W(A) if and only if it is regular, see Example 3.57(2).
We now assume that A is (countably) infinite. For each b ∈ B, we let This shows that recognizable sets of words over infinite alphabets can be described, via the substitution σ, in terms of regular languages hence of finite automata. A similar description could be done for recognizable subsets of T(F ) where F is an infinite signature.

A b := A ∩ h -1 (b).
To complete the picture, we observe that if A is infinite and L ∈ Rec(W(A)), then L∩B * is recognizable for every finite subset B of A (by Proposition 3.56 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] because W(B) ⊆ W(A)). However the converse is false. Let A be the infinite alphabet {a, b 0 , b 1 , . . . , b n , . . . }. The set L := {a n b n | n ∈ N } is not recognizable in W(A) (the proof will be given in Example 3.71) but L ∩ B * is finite, hence recognizable for every finite set B ⊆ A.

The following theorem extends Corollary 3.19 and Proposition 3.47 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF].

Theorem 3.62 Let F be a signature and let L ⊆ T (F ). The following properties are equivalent:

(1) L is equational in T(F ),

(2) L is regular over F , (3) L is recognizable in T(F ) for some finite subsignature F of F .

(4) L is recognizable in T(F ) and L ⊆ T (F ) for some finite subsignature F of F .

If additionally F is finite, then the following two properties are equivalent to properties ( 1)-( 4):

(5) L is recognizable in T(F ), (6) L is accepted by a finite F -automaton.

Proof: The equivalence of ( 1) and (2) follows from Corollary 3.19. We now prove the implication (2) =⇒ (3). If L ⊆ T (F ) is regular, then L ⊆ T (F ) for some finite subsignature F of F and (by Propositions 3.47 and 3.50) is defined by a complete and deterministic finite F -automaton equal to A (B, C) for some (B, C) (cf. Definition 3.58). It follows from Lemma 3.59 that L = L(A (B, C)) is recognizable in T(F ). The opposite implication follows from Definition 3. 58 and Lemma 3.59

: if L = val -1 B (C), then L = L(A (B, C))
. The equivalence of (3) and ( 4) is an immediate consequence of Proposition 3.60. If F is finite then (4) and ( 5) are obviously equivalent, and the equivalence of (2) and (6) follows from Proposition 3.47 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF].

Thus, for a finite signature, the families of equational, regular and recognizable sets of terms are all equal to the family of languages accepted by finite automata.

Recognizability and congruences

Definition 3.63 (Locally finite congruences) Let M be an F -algebra with set of sorts S. An equivalence relation ∼ on M is sort-preserving if any two equivalent elements have the same sort. We write

m ∼ s m if m ∼ m and σ(m) = σ(m ) = s. The index of a sort-preserving equivalence relation ∼ is the mapping γ ∼ : S → N ∪ {ω} such that γ ∼ (s) is the number of equivalence classes of ∼ s . The equivalence ∼ is locally finite if γ ∼ (s) ∈ N for each s.
If the set of sorts is finite, a sort-preserving equivalence relation is locally finite if and only if it is finite i.e., has finitely many classes. Finally, an equivalence relation saturates a subset of M if this set is a union of equivalence classes, not necessarily all of the same sort.

A congruence on M (or an F -congruence if we need to specify the relevant signature) is a sort-preserving equivalence relation on M such that, for every f in F of positive arity, the following holds (where 25The canonical surjective mapping h ∼ such that h ∼ (m) = [m] is an F -algebra homomorphism : M → M/∼. The quotient algebra M/∼ is locally finite if and only if the congruence ∼ is locally finite.

s 1 × • • • × s k → s is the type of f ): for every m 1 , . . . , m k , m 1 , . . . , m k in M , if m 1 ∼ s1 m 1 , . . . , m k ∼ s k m k then 24 : f M (m 1 , . . . , m k ) ∼ s f M (m 1 , . . . , m k ). If ∼ is a congruence on M, the quotient F -algebra M/ ∼ is defined as (M s / ∼ s ) s∈S , (f M/∼ ) f ∈F where f M/∼ ([m 1 ], . . . , [m k ]) := [f M (m 1 , . . . , m k )].
Proposition 3.64 Let M be an F -algebra. A subset L of M is recognizable in M if and only if it is saturated by a locally finite congruence on M.

Proof: Let L = h -1 (C) where h : M → A is a homomorphism and A is locally finite. The equivalence relation on M defined by m ∼ h m if and only if h(m) = h(m ) is a locally finite congruence and L is the union of the equivalence classes h -1 (a) for a ∈ C.

Conversely, if L ⊆ M is a union of classes of a locally finite congruence ∼, then we let A := M/∼ be the quotient algebra with domains

A s = M s /∼ s . It is locally finite and L = h -1 ∼ ([L] ∼ ) where [L] ∼ ⊆ A and h ∼ is the canonical surjective homomorphism : M → A.
We will say that a locally finite congruence ∼ that saturates L, witnesses the recognizability of L.

We now associate with every set a canonical congruence that saturates it.

m i ∈ M σ(yi) , i = 2, . . . , p: c M (m, m 2 , . . . , m p ) ∈ L ⇐⇒ c M (m , m 2 , . . . , m p ) ∈ L.
It is clear that ≈ L is a sort-preserving equivalence relation. It saturates L: by taking c = y 1 , we get that m ∈ L and m ≈ L m imply m ∈ L. If F generates M one can take p = 1 to define ≈ L (cf. the remarks on extended derived operations in Definition 2.125); in other words, it suffices to consider contexts c ∈ Ctxt(F ).

The equivalence ≈ L (denoted by ≈ if L is clear from the context) is called the syntactic congruence of L. The index of ≈ L , denoted by γ L , is called the recognizability index of L. The following proposition generalizes a well-known result for regular (word) languages.

Proposition 3.66 Let M be an F -algebra and L ⊆ M .

(1) The equivalence relation ≈ L is a congruence on M. The set L is recognizable in M if and only if this congruence is locally finite.

(2) The syntactic congruence ≈ L of a recognizable set L is the unique congruence ≈ that saturates L and is such that γ ≈ (s) ≤ γ ∼ (s) for every sort s and every congruence ∼ that witnesses the recognizability of L.

Proof:

(1) We write ≈ instead of ≈ L . If f ∈ F k , m 1 ≈ m 1 , . . . , m k ≈ m k and α(f ) = (σ(m 1 ), . . . , σ(m k )) then: f M (m 1 , m 2 , . . . , m k ) ≈ f M (m 1 , m 2 , . . . , m k ), f M (m 1 , m 2 , m 3 , . . . , m k ) ≈ f M (m 1 , m 2 , m 3 , . . . , m k ), . . . f M (m 1 , m 2 , . . . , m k-1 , m k ) ≈ f M (m 1 , . . . , m k-1 , m k ), which gives f M (m 1 , . . . , m k ) ≈ f M (m 1 , . . . , m k ). Hence, ≈ is a congruence. It saturates L and (by Proposition 3.64) L is recognizable if ≈ is locally finite.
Conversely let L be a union of classes of a locally finite congruence ∼ on M. We claim that for all all m, m ∈ M , we have:

m ∼ m =⇒ m ≈ m .
Let m and m be such that m ∼ m . For all c ∈ T (F, Y p ) and all m 2 , . . . , m p , we have:

c M (m, m 2 , . . . , m p ) ∈ L =⇒ c M (m , m 2 , . . . , m p ) ∈ L. (3.6)
This is so because ∼ is a congruence, so that for c, m 2 , . . . , m p as above we have c M (m, m 2 , . . . , m p ) ∼ c M (m , m 2 , • • • , m p ), and hence (3.6) holds, since ∼ saturates L. It follows from the claim that each equivalence class of ≈ is a union of equivalence classes of ∼ and so γ ≈ (s) ≤ γ ∼ (s) for every sort s. Since ∼ is locally finite, the same holds for ≈.

(2) The minimality property of ≈ L was shown in the proof of [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. For proving the unicity, we consider any congruence ∼ with the same minimality property. Each equivalence class of ≈ s is a union of equivalence classes of ∼ s . If ∼ = ≈, then γ ≈ (s) < γ ∼ (s) for some s, hence ∼ is not minimal. Hence ∼ = ≈, as was to be proved.

Example 3.67 (Recognizable languages of words) Let L ⊆ A * where A is a finite alphabet. We will examine the syntactic congruences ≈ L relative to the three algebras of words that we have defined in Definition 2.7. We first consider the F A -algebra W(A). Since W(A) is generated by F A , it suffices to consider contexts. For every context c in Ctxt(F A ) there exist words x and y in A * such that c W(A) (w) = xwy for every w in A * . For every x and y in A * , the function λw

∈ A * • xwy is c W(A) for some c in Ctxt(F A ). It follows that the equivalence relation ≈ L is such that, for w, w ∈ A * : w ≈ L w if and only if xwy ∈ L ⇐⇒ xw y ∈ L for all x, y ∈ A * ,
which is the standard definition of the syntactic congruence of a language. This congruence is finite if and only if L is defined by a finite automaton (see Theorem 2.3 in Chapter II of [*Sak] or see [*Eil] for the constructions that establish this equivalence).

We now consider the algebra W right (A) that is generated by its signature U A . The contexts in Ctxt(U A ) are the terms of the form c = xu with x ∈ A * (and u is the context variable). Such a context defines the function λw ∈ A * • wy where y is the mirror image of x, and every such function is defined by a context. It follows that for every language L ⊆ A * the syntactic congruence ≈ L right relative to this algebra satisfies for all w, w ∈ A * : w ≈ L right w if and only if wy ∈ L ⇐⇒ w y ∈ L for all y ∈ A * . Its finiteness, i.e., the recognizability of L in W right (A) is equivalent to its definability by a finite automaton.

The function defined by

c = xu in W left (A) is λw ∈ A * • xw. The syntactic congruence ≈ L
left relative to this algebra satisfies for all w, w ∈ A * :

w ≈ L left w if and only if xw ∈ L ⇐⇒ xw ∈ L for all x ∈ A * , and its finiteness is equivalent to regularity. The last two characterizations of regular languages are due to Myhill and Nerode. (See [*Sak], Theorem 2.3, Chapter II for their proofs in a language theoretic framework.)

We now consider the recognizable sets of an algebra that is generated by its signature.

Lemma 3.68 Let h : M → N be a homomorphism of F -algebras, where M and N are generated by F . Let L ⊆ N and

K = h -1 (L) ⊆ M . Then, for all m and m in M , m ≈ K m if and only if h(m) ≈ L h(m ). The homomorphism g : M/≈ K → N/≈ L induced by h, is an isomorphism, and g([K] ≈ K ) = [L] ≈ L .
The sets K and L have the same recognizability index, i.e., γ K = γ L .

Proof: Since N is generated by F , h is surjective. Let m and m be such that m ≈ K m . For proving that h(m) ≈ L h(m ), we consider an arbitrary context c in Ctxt(F ). We have

c N (h(m)) = h(c M (m)). Hence, if c N (h(m)) ∈ L, we have c M (m) ∈ K and thus c M (m ) ∈ K and c N (h(m )) ∈ L. Since F generates N,
the syntactic congruence of L can be defined in terms of contexts, hence we have h(m) ≈ L h(m ). That h(m) ≈ L h(m ) implies m ≈ K m can be proved similarly. We get from h a homomorphism : M → N/≈ L that factorizes through M/≈ K and induces an isomorphism g by the first assertion. Since g is defined by

g([m]) := [h(m)], we have g([K] ≈ K ) = [L] ≈ L . Since g is sort-preserving, there is a bijection from M s /≈ K s to N s /≈ L s for each sort s.
Thus, the recognizability indices of K and L are the same.

Proposition 3.69 Let M be an F -algebra generated by F and let L ⊆ M . The set L and the language val -1 M (L) have the same recognizability index. Thus, L is recognizable in M if and only if val -1 M (L) is recognizable in T(F ). Proof: Since F generates both M and T(F ), we can apply Lemma 3.68 to the homomorphism val M : T(F ) → M. Hence K := val -1 M (L) and L have the same recognizability index. The second assertion is an immediate consequence of the first assertion and Proposition 3.66 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF].

Remarks 3.70

(1) Proposition 3.69 is somehow "dual" to Proposition 3.23(3) that characterizes the M-equational sets as the images under val M of the recognizable sets of terms over the relevant finite subsignature (see Theorem 3.62(2,3,4)). The present characterization of the recognizable sets of M is also based on the recognizable sets of terms (over a possibly infinite signature), but uses their inverse images under the mapping val M . Similarly, Lemma 3.68 is "dual" to Proposition 3.23(2).

(2) In the statement of Proposition 3.69, it is not enough to assume that L (instead of M) is generated by F in order to have

L ∈ Rec(M) if val -1 M (L) ∈ Rec(T(F )).
Here is a counter-example. We take Z consisting of the integers with F 2 = {-} and F 0 = {0} (we have x + y = x -(0 -y)). Then Z is not generated by F , but {0} is. The set val -1 Z (0) is equal to T (F ), hence is recognizable in T(F ) but {0} is not recognizable in Z, which we prove as follows. Assume it is, with witnessing congruence ∼. At least one of the equivalence classes of ∼ is infinite. Since {0} is saturated, [0] ∼ = {0}. Hence there exist n, p in Z such that n < p with p ∼ n ∼ 0. Since ∼ is a congruence, this implies that p -n ∼ n -n = 0. Hence [0] ∼ would contain p -n = 0, which contradicts the fact that [0] ∼ = {0}.

Example 3.71 We have claimed in Example 3.57(6) that the language L = {g i f i a | i ≥ 1} is not recognizable. This follows from Proposition 3.66(1) and the observation that the congruence ≈ L has infinitely many equivalence classes of sort 0. This is so because, for all i, j with 0 < i < j, we have g i f i a ∈ L and g i f j a / ∈ L so that f i a ≈ L f j a. The proof is similar for the language L = {a n b n | n ≥ 0} of Example 3.61, cf. Example 3.67. For every i > 0 and j > i we have

a i ≈ L a j because a i • b i ∈ L and a j • b i / ∈ L.
Our aim is now to review the classical relation between syntactic congruences and minimal automata.

Definition 3.72 (Minimal automata)

Let M be a finitely generated F -algebra. For every (locally) finite congruence ∼ on M, the F -semi-automaton A (M/∼) is finite, trim, complete and deterministic. Conversely, every F -semi-automaton A with these properties is of this form, and more precisely is (up to renaming of states) A (T(F )/∼), where ∼ is defined by: t ∼ t if and only if t and t belong to L(A , q) for some q ∈ Q A .

If

L ⊆ M is recognizable, then the F -automaton A (M/≈ L , [L]
) is called the minimal automaton of L and is denoted by M (L). By Lemma 3.68 (applied to val M ), it is27 the automaton A (T(F )/≈ K , [K]) where K := val -1 M (L). Thus, M (L) is also the minimal automaton of val -1 M (L), and it accepts the language val -1 M (L).

Proposition 3.73 Let F be a finite signature and K be a recognizable set of T(F ).

(1) If A is any (possibly infinite) trim, complete and deterministic automaton recognizing K, then it is of the form A (B, C) for some F -algebra B and some set C ⊆ B, and furthermore A (B/≈ C , [C]) is the minimal automaton of K.

(2) The minimal automaton of K is the unique complete and deterministic F -automaton with a minimal number of states that recognizes K. Its number of states is s∈S γ K (s), where S is the set of sorts of F .

Proof: (1) By Lemma 3.59(2), the algebra B is generated by F . Hence Lemma 3.68 is applicable to h := val B and L := C, and yields the result

(because K = val -1 B (C)).
(2) Let A be a complete and deterministic F -automaton with a minimal number of states that recognizes K. It is trim because otherwise, it can be replaced it by a smaller complete and deterministic one that recognizes K. Hence, A = A (B, C) with B and C as in [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. We have a canonical surjective homomorphism h from B to B/≈ C . The automaton A (B/≈ C , [C]) is, by [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF], the same as M (K). If h is not an isomorphism, then the automaton A (B, C) does not have a minimal number of states. Hence A is the same as M (K), and M (K) is the unique (up to renaming of states) complete and deterministic F -automaton with a minimal number of states that recognizes K. The last assertion follows from its definition.

Assertion [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] of this proposition shows how the minimal automaton can be obtained from any finite, trim, complete and deterministic automaton recognizing K, hence from any finite automaton by Proposition 3.50. A minimization algorithm taking time O( A 2 ) (for A deterministic) is described in [CarDF].

Effective recognizability

Effectively given one-sorted and many-sorted algebras have been defined in Definitions 2.8 and 2.127, and an application to equational sets has been given in Section 3.1.2. We now extend these definitions to recognizability.

Throughout this section we assume that every signature F is effectively given, with a fixed encoding ξ F (and a fixed encoding ξ S of its set of sorts S).28 Definition 3.74 (Effectively recognizable sets) Let M be an F -algebra. A set L in Rec(M) is effectively recognizable (resp. semi-effectively recognizable) if L = h -1 (C) where h : M → A is a homomorphism to a locally finite and effectively given (resp. semi-effectively given) F -algebra A and C ⊆ A, and furthermore:

(1) C is a decidable subset of A (cf. Definition 2.8), and

(2) M is semi-effectively given and the homomorphism h is computable (cf. Definition 2.8).

These conditions imply that L is a decidable subset of M : for m ∈ M , one computes h(m) and checks whether it is in C (or more precisely, if m is given by its code number m = ξ M (m), one computes the integer h(m

) = ξ A (h(ξ -1 M (m ))) = ξ A (h(m))
and one checks whether it encodes an element of C).

If Condition (2) is dropped in the above definition of an effectively recognizable set L, then we will say that L is effectively term-recognizable. In this case it is decidable for any term t in T (F ) whether val M (t) is in L: since h • val M = val A , one computes val A (t), cf. Definition 2.8, and checks whether it is in C. Moreover, as shown below in Proposition 3.76(4), if F is finite then a finite F -automaton can be constructed that implements this algorithm.

Effectively recognizable sets (and their variants) will be used as input and output of algorithms. Such a set L is specified by the specification of A, an algorithm that decides membership in C and, if Condition (2) holds, a specification of M and an algorithm that computes h.

In the definition of an effectively recognizable set (and its two variants), we may assume that every domain A s of A is nonempty. In fact, if A is semieffectively given, then we define the F -algebra A such that A s := A s ∪ {⊥ s } and, for every 1) and (2) hold for A, then they also hold for A (with the same h and C).

f ∈ F k and a 1 , . . . , a k ∈ A of appropriate sorts, f A (a 1 , . . . , a k ) := f A (a 1 , . . . , a k ) if a 1 , . . . , a k ∈ A and f A (a 1 , . . . , a k ) := ⊥ σ(f ) otherwise. If A is encoded by ξ A and the set S of sorts of F is encoded by ξ S , then we encode A as follows: ξ A (a) := 2 • ξ A (a) for a ∈ A and ξ A (⊥ s ) := 2 • ξ S (s) + 1 for s ∈ S. It is easy to verify that A is semi-effectively given with this encoding ξ A . If A is effectively given, then so is A , because |A | = ω if |S| = ω and |A | = s∈S (|A s | + 1) if S is finite. If Conditions (
The following lemma shows that every finitely generated subalgebra of a semi-effectively given algebra satisfies Condition (2) above.

Lemma 3.75

(1) Let M be an F -algebra generated by F and let h : M → A be a homomorphism. If M and A are semi-effectively given, then h is computable.

(2) Let M be a semi-effectively given F -algebra and let M be the subalgebra of M generated by a finite subsignature F of F .29 Then M is semieffectively given and the mapping in M ,M is computable.30

Proof: [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] The image h(m) of any element m of M is equal to val A (t) for any t in val -1 M (m). Since M is semi-effectively given and generated by F , some term t in val -1 M (m) can be computed as observed in Definition 2.8. Then ξ A (val A (t)) = ξ A (h(m)) can also be computed since A is semi-effectively given, which completes the proof.

(2) Since F is effectively given, the set T (F ) is semi-effectively given and T (F ) is a decidable subset of T (F ). Let t 0 , t 1 , . . . be an enumeration of the elements of T (F ) such that the mapping i → t i is computable. We define the encoding ξ M (m) of an element m of M to be the smallest integer i such that val M (t i ) = m. Since M is semi-effectively given, the mapping val M and hence the mapping in M ,M and its inverse are computable. From this it is easy to see that M is semi-effectively given with encoding ξ M . This lemma is meant to be constructive. For instance, for the first assertion this means that from the specifications of M and A an algorithm can be constructed that computes h. In what follows, all such results are meant to be constructive.

If F is finite and A is locally finite, then it is finite (because S is finite, cf. Definition 2.123). Hence, if A is given as a finite set A with its operations in tabular form, then it is effectively given (and vice versa). This shows that every recognizable set L that is specified by a given finite algebra A and a subset C of A, is effectively term-recognizable (and vice versa). By Lemma 3.75( 1), if M is semi-effectively given and generated by F , then L is even effectively recognizable and hence a decidable subset of M . It will be shown in Section 4.2.3 that there exist homogenous recognizable sets of the HR algebra JS t that are not decidable subsets of J S and hence cannot be specified as (semi-)effectively (term-)recognizable sets.

We now formulate an effective version of Proposition 3.56. For the notion of an effectively given derived signature see Definition 2.127.

Proposition 3.76

(1) Let M be an F -algebra and M be an F -algebra such that M ⊆ M. Let S be a decidable subset of S, and let the mappings in S ,S and in F ,F be computable

31 . If L is effectively term-recognizable in M, then L ∩ M is effectively term-recognizable in M .
Moreover, let M and M be semi-effectively given and the mapping in

M ,M be computable. If L is (semi-) effectively recognizable in M, then L ∩ M is (semi-) effectively recognizable in M . (2) Let k : M → M be a homomorphism of F -algebras. If L is effectively term-recognizable in M, then k -1 (L) is effectively term-recognizable in M .
Moreover, let M and M be semi-effectively given and k be computable. If L is (semi-) effectively recognizable in M, then k -1 (L) is (semi-) effectively recognizable in M .

(3) Let H be an effectively given derived signature of F and M be an

F - algebra. If L is effectively term-recognizable in M, then L is effectively term-recognizable in M H . If L is (semi-) effectively recognizable in M, then L is (semi-) effectively recognizable in M H . If furthermore F ⊆ H
and in F,H is computable, then the converse implications also hold.

Additionally we state the following special case of (2):

(4) Let M be an F -algebra with finite F . If L is effectively term-recognizable in M, then a finite F -automaton recognizing the language val -1 M (L) can be computed from a specification of L.

Proof: The proof is based on that of Proposition 3.56.

(1) Let L = h -1 (C) with h : M → A and C ⊆ A, as in Definition 3.74. We may assume that the domains A s of A are nonempty. Let A := A F . Since membership in S is decidable, so is membership in A (because A = {a ∈ A | σ(a) ∈ S }). Hence, to make A semi-effectively given, we can use its standard encoding as a decidable subset of A. Since in -1 S ,S and in F ,F are computable 32 , it is easy to verify that A is semi-effectively given. If A is effectively given, then so is A . In fact, the mapping s → |A s | is computable because it is the composition of in S ,S and of the mapping s → |A s |. By the above assumption,

|A | is infinite if S is infinite. If S is finite, then |A | = s ∈S |A s |. Hence |A | can be computed. The restriction h of h to M is a homomorphism : M → A and L ∩ M = (h ) -1 (C ∩ A ). Since C is a decidable subset of A, the set C ∩ A is obviously one of A . Since h = h • in M ,M , it is computable if in M ,M and h are.
(2) This is obvious from the proof of Proposition 3.56(2).

(3) In general, if H is effectively given and M is (semi-) effectively given, then M H is (semi-) effectively given (with respect to the same encoding of M ): to compute g M H (m 1 , . . . , m k ), first compute δ H (g) and then use ζ M to compute δ H (g) M (m 1 , . . . , m k ). The result is now immediate from the proof of Proposition 3.56(3).

(4) Let L = h -1 (C) for an effectively given finite algebra A, a homomorphism h : M → A and a decidable subset C of A. Since A is finite and effectively given, it can be computed (or more precisely, an algebra A isomorphic to A, with A = enc A , can be computed). Since membership in C is decidable, C can also be computed. Hence the finite automaton A (A, C) can be computed that recognizes val -1 M (L) by Lemma 3.59 (because We now state an effective version of Proposition 3.64. Also, we examine conditions that ensure that semi-effective recognizability implies effective recognizability (the converse implication being trivial).

val A = h • val M ).
Proposition 3.78 Let M be a semi-effectively given F -algebra and let L ⊆ M .

(1) L is semi-effectively recognizable if and only if membership in L is decidable 35 and L is saturated by a locally finite and decidable congruence.

32 In general, if A, B are encoded sets with B ⊆ A and in B,A is computable (i.e., ξ A • ξ -1 B is computable), then so is in -1 B,A (i.e., ξ B • ξ -1 A is): for b ∈ B, ξ B (b) is the smallest integer i such that ξ A (ξ -1 B (i)) = ξ A (b). 33 In other words, the mapping f : M × M → {True, False} such that m ∼ m if and only if f (m, m ) = True is computable.
34 Recall from Definition 3.63 that γ∼ is the mapping s → |Ms/∼s |. The phrase "|M/∼ | is given" means that |M/∼ | is part of the specification of an effectively given congruence ∼ (which also consists of algorithms to decide ∼ and to compute γ∼). A decidable equivalence relation ∼ is specified by an algorithm that decides ∼.

35 Since this equivalence is meant to be constructive, a membership algorithm for L must be specified.

(2) If membership in L is decidable and L is saturated by a locally finite and effectively given congruence, then L is effectively recognizable.

(3) Let M be finitely generated by F . Then:

(3.1) If ∼ is a decidable and finite congruence, then ∼ is effectively given and the finite quotient algebra M/∼ is effectively given. (3.2) If L is semi-effectively recognizable, then it is effectively recognizable.

Proof: [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] The "only if" direction is clear from the definitions and the proof of Proposition 3.64: since h is computable, the congruence ∼ h is decidable. For proving the "if" direction, we let ∼ be a locally finite and decidable congruence that saturates L. From the proof of Proposition 3.64 we know that

L = h -1 ∼ (C) where h ∼ is the canonical surjective homomorphism : M → A := M/ ∼ and C := {[m] ∼ | m ∈ L}.
In order to make the locally finite algebra A semi-effectively given, we need an encoding ξ A of the elements of A = M/∼ by integers. For each i in enc M , we let h(i) be the smallest integer

j ∈ enc M such that ξ -1 M (j) ∼ ξ -1 M (i). Since ∼ is decidable (and enc M is a decidable subset of N ), the mapping h : enc M → enc M is computable. We now define the encoding ξ A by ξ A ([m] ∼ ) := h(ξ M (m)) for every m ∈ M . Since h is computable, enc A = {i ∈ enc M | h(i) = i} is a decidable subset of N .
Let us show that, with this encoding, the algebra A is semi-effectively given (cf. Definition 2.8). An integer i ∈ N encodes an element of A s (through ξ A ) if and only if i encodes an element of M of sort s (through ξ M ), and this can be determined by an algorithm because M is semi-effectively given. (Sorts are handled through the encoding ξ S ). If i 0 encodes an element f of F (through ξ F ) and i 1 , . . . , i p encode elements of A, with p := ρ(f ), then ζ A (i 0 , i 1 , . . . , i p ) = h( ζ M (i 0 , i 1 , . . . , i p )). Hence ζ A is computable and A is semieffectively given.

It remains to show Conditions (1) and (2) of Definition

3.74. Membership in C is decidable, because membership in L is: if i encodes an element [m] of A, then [m] ∈ C if and only if i encodes an element of L. The homomorphism h ∼ is computable: if i encodes an element m of M , then h(i) encodes h ∼ (m) = [m].
(2) The proof is the same as in [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. If ∼ is effectively given, then A is effectively given, because

|A| = |M/∼ | and |A s | = |M s /∼ s | = γ ∼ (s) for every sort s.
(3.1) We now assume that M is generated by its finite signature F , hence has finitely many sorts, and that ∼ is a decidable and finite congruence. As before, let A := M/∼. Obviously, the finite algebra A is also generated by F and, as shown in the proof of ( 1), it is semi-effectively given. It suffices to compute |A s | for every sort s, because then |A| is the sum of those cardinalities and hence ∼ and A are effectively given. Let S be the equation system constructed in the proof of Proposition 3.16 such that µx • S P(T(F )) (x) x s = T (F ) s for every sort s. Since A is generated by F , we have that A s = val A (T (F ) s ) which equals µx • S P(A) (x) x s by Proposition 3.23 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. Since A is semi-effectively given, the least solution of S in P(A) can be computed by Proposition 3.10, and so A s and |A s | can be computed for every s.

(3.2) This is immediate from ( 1), ( 2) and (3.1).

Remarks 3.79

(1) Without its first two hypotheses (F is finite and generates M), Assertion (3.1) of Proposition 3.78 is false. Consider for example the set N equipped with one constant symbol with value i for each i ∈ N . Let h : N → N be a computable mapping such that h(N ) is finite. The algebra M := N , (i) i∈N is generated (trivially) by its signature F that consists only of constant symbols. The equivalence relation defined by n ∼ m if and only if h(n) = h(m) is decidable and has finitely many classes, but one cannot determine the number of classes, because the knowledge of an algorithm computing h is not enough to determine the cardinality of the set h(N ). The same holds if F is replaced by a finite subsignature of it, hence that does not generate the corresponding algebra.

(2) We now consider a similar case. We assume that h is a computable mapping : N → {0, 1}. Hence h is a computable homomorphism : M → A where A := {0, 1}, (h(i)) i∈N . Then A is effectively given but we cannot decide if h is surjective. Even if we know that a decidable congruence has at most two classes, we cannot compute its number of classes. This shows that we cannot restrict A in an effective manner so as to make h surjective, as in the general case (cf. Definition 3.55). It is the reason that the converse direction of implication (2) of Proposition 3.78 does not hold; one easily shows that it does hold when the witnessing homomorphism is surjective.

(3) We use Proposition 3.78 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] to show that for semi-effectively recognizable sets Proposition 3.76(1) holds without its requirements on S , S, F and F . Let L be a decidable subset of M and let ∼ be a decidable congruence on M witnessing the recognizability of L. Then ∼ := ∼ ∩ (M × M ) is a congruence on M that witnesses the recognizability of L ∩ M (it is locally finite because

|M s /∼ s | ≤ |M s /∼ s | for every sort s of F ). Since in M ,M is computable, ∼ is decidable and L ∩ M is a decidable subset of M .
Proposition 3.80 Let M be a finitely generated and semi-effectively given Falgebra and let L ⊆ M be recognizable. From an integer p ≥ M (L) and a membership algorithm for L, one can compute a finite F -automaton that recognizes the language val -1 M (L). Proof: Let M and L be as in the statement. By Proposition 3.73(2), there exists a complete and deterministic F -automaton A with at most p states such that L(A ) = val -1 M (L). We will use the set Ctxt(F ) of contexts over F , defined as terms in T (F, {x}). Proof: Let t be a term in T (F ) that evaluates to m. Let q be the unique state of A such that t ∈ L(A , q). Let B be the (F ∪ {x})-automaton obtained from A by the addition of the transition rule x → q. It is clear that

L(B) ∩ Ctxt(F ) is the set of contexts c such that c[t] ∈ L(A ), i.e., such that c M (m) ∈ L. Claim 3.80.2 For every m, m ∈ M , we have m ≈ L m if and only if c M (m) ∈ L ⇐⇒ c M (m ) ∈ L for every c ∈ Ctxt(F ) of height at most 3 • p 2 .
Proof: Let B and B be associated with m and m by the previous claim.

Then

K := Ctxt(F ) ∩ (L(B) -L(B )) is the set of contexts in Ctxt(F ) such that c M (m) ∈ L but c M (m ) / ∈ L. Since Ctxt(F
) is recognized by a complete and deterministic (F ∪ {x})-automaton with 3 states of each sort, K can be recognized by such an automaton with at most 3 • p 2 states (the detailed construction is easy to work out with the product construction of automata recalled below in the proof of Proposition 3.85). If K is nonempty, it contains a context of height at most 3 • p 2 by Proposition 3.53. By considering in a similar way the set Ctxt(F ) ∩ (L(B ) -L(B)), we get the result.

We complete the proof of the proposition as follows. There are finitely many contexts in Ctxt(F ) of height at most 3 • p 2 . Since M is semi-effectively given, c M (m) can be computed for each context c, and since we have a membership algorithm for L, we can decide if c M (m) ∈ L. It follows from Claim 3.80.2 that the syntactic congruence ≈ L of L is decidable. Hence, by Propositions 3.66(1), 3.78(1) and 3.78(3.2), L is effectively recognizable and so the required automaton can be computed by Proposition 3.76(4). In fact, following the line of this proof, the finite

F -automaton A (M/≈ L , [L]) is computed, which is the minimal automaton M (L) of L by definition.
Here is a concrete application of this proposition. Let L ⊆ A * be a regular language that is recognized by an unknown, possibly nondeterministic automaton with at most p states. Hence some deterministic and complete automaton with at most 2 p states recognizes L. From p and any membership algorithm for L, one can compute by the previous proposition a finite automaton recognizing L. Hence, provided we know an upper-bound p, we get from an arbitrary membership algorithm a linear-time one. (This follows from Proposition 3.80 applied to the algebra M = W right (A), cf. Remark 3.51(2)).

In Section 3.4.10 we will review the concrete and effective ways to specify recognizable sets in semi-effectively given algebras.

Inductive predicates

Recognizability can be formulated in a more intuitive way in terms of inductive sets of properties. This notion has been presented in Section 1.2, but in place of the informal term "property", we will use the term "predicate", from logic. We will characterize the homogenous recognizable sets in terms of inductive sets of predicates.

Definition 3.81 (Inductive sets of predicates)

A predicate on a set E is a mapping : E → {True, False}. Let M be an F -algebra with set of sorts S. A family of predicates on M is an indexed set ( p ) p∈P , given with a mapping α : P → S such that each p is a predicate on M α(p) . We call α(p) the (input) type of p, and for every s ∈ S we denote by P s the set {p ∈ P | α(p) = s}. Such a family will also be denoted by P . The notation P for a family of predicates refers to the set of symbols P , to the type mapping α and to the predicates p for p in P . The family P is locally finite if for each s ∈ S the set P s is finite. We say that P is f -inductive where f ∈ F n , if for every

p ∈ P of type s = σ(f ) there exist k 1 , . . . , k n in N , a Boolean function B with (k 1 +• • •+k n ) arguments and a sequence (p 1,1 , . . . , p 1,k1 , p 2,1 , . . . , p 2,k2 , . . . , p n,kn ) of k 1 +• • •+k n predicates in P , such that, if the type of f is s 1 ×s 2 ו • •×s n → s, then:
1. α(p i,j ) = s i for all i = 1, . . . , n and j = 1, . . . , k i , and 2. for all m 1 ∈ M s1 , . . . , m n ∈ M sn we have:

p(f M (m 1 , . . . , m n )) = B( p 1,1 (m 1 ), . . . , p 1,k1 (m 1 ), p 2,1 (m 2 ), . . . , p n,kn (m n )).
Formally, we let k denote the sequence (k 1 , . . . , k n ) and we let Y k be the set of Boolean variables y i,j for 1 ≤ i ≤ n and 1 ≤ j ≤ k i . Then B is a term in T ({∨, ∧, ¬, True, False}, Y k ) and, in the above expression of p(f M (m 1 , . . . , m n )), the variable y i,j takes value p i,j (m i ). The tuple (B, p 1,1 , . . . , p 1,k1 , p 2,1 , . . . , p n,kn ) is called a splitting of p relative to f . 36 Intuitively, this means that the validity of p for any element of M of the form f M (m 1 , . . . , m n ) where m 1 , . . . , m n ∈ M , can be computed from the truth values of finitely many predicates of P for m 1 , . . . , m n . This computation can be done by a Boolean expression that depends only on p and f . For F ⊆ F , we say that P is F -inductive if it is f -inductive for every f in F .

σ(G • H) = (σ(G) ∧ σ(H)) ∨ (δ(G) ∧ δ(H)), formally expressed by the 5-tuple ((y 1,1 ∧ y 2,1 ) ∨ (y 1,2 ∧ y 2,2 ), σ, δ, σ, δ). Thus, k 1 = k 2 = 2. Equalities (1.10) show that {σ, δ} is an { , •}-inductive family of predicates on the algebra J d 2 .
Proposition 3.83 Let M be an F -algebra and s ∈ S. A subset L of M s is recognizable in M if and only if L = sat(M, p 0 ) for some predicate p 0 of type s belonging to a locally finite F -inductive family of predicates on M.

Proof: "Only if". Let L = h -1 (C) ⊆ M s , for some homomorphism h : M → A
where A is a locally finite F -algebra and C ⊆ A s . We let P = A ∪ {p 0 }. Each element a of A u has type u (considered as a member of P ) and p 0 has type s.

For m ∈ M u and a ∈ A u , we let a (m) := True if and only if h(m) = a, and, for m ∈ M s , we let p 0 (m) := True if and only if h(m) ∈ C.

We check that the family P is F -inductive. For all n-ary f ∈ F , all elements m 1 , . . . , m n of M of appropriate sorts and all a ∈ A σ(f ) , we have:

a (f M (m 1 , . . . , m n )) = True ⇐⇒ h(f M (m 1 , . . . , m n )) = a ⇐⇒ f A (h(m 1 ), . . . , h(m n )) = a. Hence a (f M (m 1 , . . . , m n )) = a 1 (m 1 ) ∧ • • • ∧ a n (m n )
where the disjunction ranges over all n-tuples (a 1 , . . . , a n ) in

A n such that f A (a 1 , . . . , a n ) = a. (For c ∈ F 0 , we have a (c M ) = True if and only if c A = a).
We have p 0 (m) = a∈C a (m) for all m ∈ M . The splitting of a relative to f is thus the tuple (B, p 1,1 , . . . , p n,k ) where (a

(j) 1 , . . . , a (j) n ) 1≤j≤k is an enumera- tion of the set {(a 1 , . . . , a n ) | f A (a 1 , . . . , a n ) = a}, B is the Boolean expression 1≤j≤k (y 1,j ∧ • • • ∧ y n,j ) and p i,j = a (j) i . Hence P is F -inductive.
It is clear that it is locally finite. We have L = sat(M, p 0 ). Hence L satisfies the required property.

"If". Let P be a locally finite F -inductive family of predicates. Let L = sat(M, p 0 ) for some p 0 ∈ P . For u ∈ S, we let ∼ u be the equivalence relation on M u defined by m ∼ u m if and only if p (m) = p (m ) for every p ∈ P u . It follows from Condition 2 of Definition 3.81 that ∼ is a congruence. It has at most 2 |Pu| equivalence classes of each sort u. The set L = sat(M, p 0 ) is a union of equivalence classes, hence is recognizable by Proposition 3.64.

Let P be a locally finite F -inductive family of predicates on a semi-effectively given F -algebra M. It is computable if the set P is effectively given and the mapping α, the mapping (p, m) → p (m) (for p ∈ P and m ∈ M α(p) ) and the mapping s → |P s | are computable. It is effectively F-inductive if, in addition, there is a computable mapping that associates with every p ∈ P and f ∈ F such that α(p) = σ(f ), a splitting of p relative to f . Corollary 3.84 Let M be a semi-effectively given F -algebra and let p 0 belong to a locally finite F -inductive family of predicates P on M. If P is computable, then sat(M, p 0 ) is semi-effectively recognizable. If P is effectively F -inductive, then sat(M, p 0 ) is effectively recognizable.

Proof: To prove the first assertion we use Proposition 3.78 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. Since membership in sat(M, p 0 ) is obviously decidable, it suffices to show that the locally finite congruence ∼ from the "if" part of the proof of Proposition 3.83 is decidable. This follows from the fact that for every sort u the finite set P u can be computed: enumerate the elements p of P , test whether α(p) = u, and halt when |P u | elements of P u have been found.

For proving the second assertion, we let P be effectively F -inductive. We construct a locally finite F -algebra A and a homomorphism h from M to A. For each s, we define A s as the set of all mappings : P s → {True, False}. For a constant symbol c ∈ F , we define c A as the mapping p → p (c M ) for p in P σ(c) . For f ∈ F of arity n > 0 and g 1 , . . . , g n respectively in A s1 , . . . , A sn , where α(f ) = (s 1 , . . . , s n ), we define f A (g 1 , . . . , g n ) as the mapping that maps each p in P σ(f ) to:

B(g 1 (p 1,1 ), . . . , g 1 (p 1,k1 ), g 2 (p 2,1 ), . . . , g n (p n,kn ))
where (B, p 1,1 , . . . , p 1,k1 , p 2,1 , . . . , p n,kn ) is the computed splitting of p relative to f . It is clear that A is effectively given37 and locally finite. We let h : M s → A s be defined as follows: h(m) is the function that maps p to p (m). It is clear that h is computable and that, for each p, sat(M, p) = h -1 (C p ) where C p is the set of mappings g such that g(p) = True. Obviously, membership in C p is decidable. It remains to prove that h is a homomorphism. We have for all objects f, p, m 1 , . . . , m n of relevant types:

h(f M (m 1 , . . . , m n ))(p) = p (f M (m 1 , . . . , m n )) = B( p 1,1 (m 1 ), . . . , p 1,k1 (m 1 ), p 2,1 (m 2 ), . . . , p n,kn (m n )) = B(h(m 1 )(p 1,1 ), . . . , h(m 1 )(p 1,k1 ), h(m 2 )(p 2,1 ), . . . , h(m n )(p n,kn )) = f A (h(m 1 ), . . . , h(m n ))(p),
which gives the result.

In fact, it can easily be shown by inspection of the "only if" part of the proof of Proposition 3.83, that a subset L of M s is effectively recognizable in M if and only if L = sat(M, p 0 ) for some predicate p 0 of type s belonging to a locally finite effectively F -inductive family of predicates on M. The corresponding statement for semi-effectively recognizable sets and computable F -inductive families only holds in one direction, due to the requirement that the mapping s → |P s | must be computable.

If the signature F of M is finite and if P is, as in Corollary 3.84, locally finite and effectively F -inductive, then a finite F -automaton as in Proposition 3.76(4) can be constructed for val -1 M (L) where L := sat(M, p 0 ). If M is moreover generated by F , then it suffices that P is computable (by Proposition 3.78(3.2)).

Closure properties

We now consider some closure properties of the family of recognizable sets. We already know from Propositions 3.56(2) and 3.76(2) that it is closed under inverse homomorphisms. Extended derived operations are defined in Definition 2.125. Proposition 3.85

(1) Let F be an S-signature and M be an F -algebra. The family of sets Rec(M) is closed under union, intersection and difference; it contains the set s∈S M s for every set of sorts S ⊆ S (in particular, the empty set and the set M ). If g : M u → M s is a unary extended derived operation and L ∈ Rec(M), then g -1 (L) ∈ Rec(M) u .

(

) Let M, M be F -algebras. If L ∈ Rec(M) and L ∈ Rec(M ), then L×L ∈ Rec(M × M ). 2
Proof: (1) Let L, L ∈ Rec(M) be defined as h -1 (C) and h -1 (C ) respectively for homomorphisms h : M → A and h : M → A to locally finite F -algebras A and A , and for subsets C and C of A and A respectively.

Then L ∪ L = h -1 ((C × A ) ∪ (A × C )) where h is the homomorphism : M → A × A such that h (m) = (h(m), h (m)). We have also L ∩ L = h -1 (C × C ) and L-L = h -1 ((C ×A )-(A×C )
). These three sets are M-recognizable because A×A is locally finite38 . Let S be the unique F -algebra with domain {s} for s ∈ S and let h be the unique homomorphism :

M → S. Then s∈S M s = h -1 (S )
and hence is M-recognizable, cf. Example 3.57(5).

Consider now an extended derived operation defined, for m ∈ M , by g(m) := t M (m, m 2 , . . . , m p ) for some term t in T (F, X p ) s with σ(x 1 ) = u and m 2 , . . . , m p in M of appropriate sorts. Let L, h, A, C be as above. Let g :

A u → A s be defined by g (a) := t A (a, h(m 2 ), . . . , h(m p )). We have g • h = h • g (both are mappings : M u → A s ). Since L = h -1 (C), we obtain that g -1 (L) = g -1 (h -1 (C)) = h -1 (g -1 (C)) = h -1 (C ), where C = g -1 (C) ⊆ A u . Hence g -1 (L) is recognizable in M.
(2) Let L and L be defined as in [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF], except that h :

M → A . Then L × L = h -1 (C × C ) where h is now the homomorphism : M × M → A × A such that h (m, m ) = (h(m), h (m )).
With the hypotheses and notations of the previous proposition, we have the following corollary: Corollary 3.86 If L and L are effectively recognizable, then L ∪ L , L ∩ L , L-L , g -1 (L) and L×L are effectively recognizable. The analogous statements hold for effectively term-recognizable sets and for semi-effectively recognizable sets.

Proof: The algebra A × A is (semi-)effectively given if A and A are so (see Definition 2.8), and membership in C × A , A × C and g -1 (C) is decidable if that holds for C and C . Moreover, h is computable if h and h are so. We omit the details.

These propositions generalize some well-known closure properties of the family of regular (recognizable) word languages. However, the closure under concatenation of regular languages does not extend to the closure of recognizable sets under the operations of the considered algebra: it is not always true that if f ∈ F k and L 1 ∈ Rec(M) s1 , . . . , L k ∈ Rec(M) s k where α(f ) = (s 1 , . . . , s k ), then the set f P(M) (L 1 , . . . , L k ) is in Rec(M). Singleton sets are not always recognizable. (These facts can be contrasted with Proposition 3.45(2,3) about equational sets). We give here some counterexamples.

Example 3.87 An example of a singleton that is not recognizable is given in Remark 3.70(2). For an example of nonclosure under an operation, we consider again the algebra W(A) sq which is the free monoid W(A) augmented with the squaring function: sq(u) = u • u, cf. Example 3.42 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. It follows from Proposition 3.56(3) that Rec(W(A) sq ) = Rec(W(A)). However the language sq(L) = {ab n ab n | n ≥ 0}, that is the image of the recognizable (i.e., regular) language ab * under sq is not recognizable. Hence the operation sq does not preserve recognizability in W(A) sq . Algebraic conditions on an algebra M ensuring that Rec(M) is closed under its operations are considered in [START_REF] Courcelle | Recognizable sets of graphs: equivalent definitions and closure properties[END_REF].

The Filtering Theorem

The following theorem (stated as Theorem 1.8 in Section 1.2.3) extends the classical result that the intersection of a context-free language and a regular one is context-free. Associated with the Recognizability Theorem, even in its weak form stated as Theorem 1.21 in Section 1.4.3, its yields the decidability of the monadic second-order satisfiability problems for the VR-and HR-equational sets of graphs.

Theorem 3.88 (Filtering Theorem, algebraic version) Let M be an F -algebra, let L ∈ Equat(M) and K ∈ Rec(M). Then L ∩ K ∈ Equat(M). If K is semi-effectively recognizable or effectively term-recognizable, then an equation system defining L ∩ K can be constructed from one defining L.

Proof: First, we prove that we can assume that F is finite and that K is effectively term-recognizable. By (the proof of) Proposition 3.9(3), there is a finite subsignature F of F such that L is equational in the subalgebra M of M that is generated by F (which is an F -algebra): this signature F is F (S) where S is any equation system that defines L. The set K := K ∩ M is recognizable in M by Proposition 3.56 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. If K is effectively term-recognizable in M, then so is K in M by Proposition 3.76 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. If K is semi-effectively recognizable in M, then so is K in M by Lemma 3.75(2) and Proposition 3.76 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] (see also Remark 3.79(3)) and even effectively recognizable in M by Proposition 3.78(3.2). Since L ⊆ M , we have that L ∩ K = L ∩ K . Thus, it suffices to prove that L∩K is M -equational, because then it is M-equational, with the same equation system, by Proposition 3.9(1).

In the remainder of the proof we assume that F is finite, and we only consider the assumption that K is effectively term-recognizable. Let M be an F -algebra, let L be M-equational and defined by an equation system S over F , and let K be M-recognizable. Then L = val M (R) for the equational set of terms R defined by S in P(T(F )), by Proposition 3.23 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. The set

R := val -1 M (K) is recognizable in T(F ) by Proposition 3.56(2). Then L ∩ K = val M (R) ∩ K = val M (R ∩ val -1 M (K)) = val M (R ∩ R ).
The set R ∩ R is regular by Theorem 3.62 and Proposition 3.85 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. Hence L ∩ K is M-equational by Proposition 3.23(3).

We now assume that K is effectively term-recognizable in M. Then a finite F -automaton B = A (B, Acc B ) recognizing R can be constructed by (the proof of) Proposition 3.76(4). It remains to prove that from S and B an equation system S can be constructed that defines R ∩ R in T(F ), and hence defines L ∩ K in M by Proposition 3.23 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. We will give two, closely related, proofs. The first one is very short but its drawback is that it gives no direct construction of the equation system S . Our second proof details such a construction. 1). An equation system S defining R ∩ R can be computed from this automaton, again because Theorem 3.62 is constructive.

First construction: Since Theorem 3.62 is constructive, a finite F -automaton A (A, C) recognizing R can be computed from S. Hence the set R ∩ R is rec- ognized by the F -automaton A (A × B, C × Acc B ), cf. the proof of Proposi- tion 3.85(
Second construction: We let S be of the general form x 1 = p 1 , . . . , x n = p n where the p i 's are polynomials and L is defined by (S, Y ) in M for some Y ⊆ X n . We recall from Theorem 3.18 that the least solution of S in P(T(F )) is the n-tuple (L(G(S), x 1 ), . . . , L(G(S), x n )) where G(S) is the regular grammar associated with S (see Definition 3.17, Section 3.1.4). Thus, R = L(G(S), Y ).

For every i ∈ [n] and every state q ∈ Q B such that σ(q) = σ(x i ) (where Q B = B), we let T i,q := L(G(S), x i ) ∩ L(B, q). Our objective is to construct the system S with set of unknowns Unk (S ) :

= {x i,q | i ∈ [n], q ∈ Q B , σ(q) = σ(x i )} such that L(G(S ), x i,q ) =
T i,q for each x i,q in Unk (S ). We let σ(x i,q ) := σ(x i ). The construction of S is essentially the product of two finite automata, as in the first construction.

For each x i,q in Unk (S ), we will define a polynomial p i,q in Pol (F, Unk (S )) intended to be the righthand side of the equation of S that defines x i,q . First, for every monomial m ∈ T (F, X n ) of a righthand side of S and every q ∈ Q B such that σ(q) = σ(m), we define as follows a polynomial p(m, q

): if m = t[x i1 /y 1 , . . . , x i k /y k ] where t ∈ T (F, Y k ) and ListVar (t) = y 1 • • • y k , then we let p(m, q) := D where D is the set of all terms t[x i1,q1 /y 1 , . . . , x i k ,q k /y k ] such that q 1 , . . . , q k ∈ Q B and t B (q 1 , . . . , q k ) = q. 39 Then, if p i = m 1 ∪ • • • ∪ m r (for i ∈ [n]) we define p i,q as p(m 1 , q) ∪ • • • ∪ p(m r , q) whenever q ∈ Q B and σ(q) = σ(p i ) = σ(x i ).
It is clear that S can be constructed from S and B.

Claim 3.88.1 For every x i,q in Unk (S ) we have T i,q = L(G(S ), x i,q ). Proof sketch: One can verify that the sets T i,q form an oversolution of S in P(T(F )). 40 It follows from the Least Fixed-Point Theorem (Theorem 3.7) that L(G(S ), x i,q ) ⊆ T i,q for each x i,q in Unk (S ).

We complete the proof by proving (by induction on j) that T (j) i ∩ L(B, q) ⊆ L(G(S ), x i,q ) for all x i,q ∈ Unk (S ) and j ∈ N , where (T (j) 1 , . . . , T (j) n ) := (S P(T(F )) ) j (∅). All proofs are routine from the definitions.

Hence the system S defines in T(F ) the sets of terms T i,q . It follows that

R ∩ R = L(G(S), Y ) ∩ R = {L(G(S), x ) ∩ L(B, q) | x ∈ Y, q ∈ Acc B } = {T ,q | x ∈ Y, q ∈ Acc B , σ(q) = σ(x )}.
Thus, R ∩ R is defined by (S , X) in T(F ) where

X := {x ,q | x ∈ Y, q ∈ Acc B , σ(q) = σ(x )}.
Then L ∩ K is defined by (S , X) in M.

Corollary 3.89 Let M be an F -algebra where F is finite and let (L 1 , . . . , L n ) be the least solution in P(M) of an equation system S over F with Unk (S) = X n .

Let h : M → B be a homomorphism into a finite F -algebra B. There exists an equation system that defines the sets L i ∩ h -1 (q) for i ∈ [n] and q ∈ B with σ(q) = σ(x i ). It can be constructed from S and B, if B is effectively given.

Proof: One can perform the second construction in the proof of the Filtering Theorem, i.e., construct the system S from S and the automaton B := A (B, Acc B ), for any Acc B (because the construction does not depend on Acc B ).

Taking L = L i and so Y = {i}, and taking K = h -1 (q) and so

R = val -1 M (h -1 (q)) = val -1 B (q) = L(B)
with Acc B = {q}, the proof shows that L ∩ K is defined by (S , x i,q ) in M.

Remarks 3.90

(1) The system S constructed in the second proof of the Filtering Theorem has at most n • B equations but it is not necessarily trim, even if S is assumed to be. Trimming is interesting in several respects. First, this operation results in a system defining L ∩ K of smaller (or at least not larger) size than S . Second, in the case of a system constructed by Corollary 3.89, it produces the set of unknowns x i,q such that L i ∩ h -1 (q) = ∅ (by Corollary 3.24). This will help to construct proofs of facts of the form L i ⊆ K for sets K that are recognizable in M, as we did in Proposition 1.6 (see Proposition 3.91 below). We have proved 40 and even a solution. If the system S has no monomial equal to an unknown, then the regular grammar G(S ) is strict and the system S has a unique solution in P(T(F )) by Proposition 3.15 (cf. the observation after Lemma 3.22). Hence the sets T i,q form this unique solution and we have the desired equalities. But the proof of this fact is essentially the same as the one for the general case.

in a similar way in Section 1.2.5 that no series-parallel graph can satisfy the two 2-coloring properties σ and δ of Example 1.11.

(2) From the above observation on the number of equations, and the second construction in the proof of the Filtering Theorem, we get (with the notation of that proof) that L ∩ K is nonempty if and only if it contains an element defined by a term of height at most n • B where n is the number of equations of a uniform system that defines L. This fact follows from Proposition 3.53 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF].

(3) We may have a computable homomorphism h : M → B without knowing if h -1 (q) = ∅ for given q in B (cf. Remark 3.79(2)). The second construction in the proof of the Filtering Theorem works nevertheless but we have

L i ∩h -1 (q) = ∅ if q / ∈ h(M ).
As discussed in ( 1), we can determine the pairs (i, q) such that L i ∩ h -1 (q) = ∅, hence for each i, the finite set h(L i ).

(4) The proof of the Filtering Theorem defines L as well as K (to simplify the discussion we assume that F is finite) by finite, possibly nondeterministic, automata on terms, but it does not extend to the case where K is equational. Let L and S be as in the second construction in the proof, with L = val M (L(G(S), x 1 )). Assume that K = val M (L(G(S), x 1 )) for another equation system S with set of unknowns X m . One can build a system S that defines in

T(F ) the sets L(G(S), x i ) ∩ L(G(S), x j ) for i ∈ [n] and j ∈ [m]. Then val M (L(G(S), x i ) ∩ L(G(S), x j )) ⊆ val M (L(G(S), x i )) ∩ val M (L(G(S), x j
)) but the inclusion may be strict, hence the system S does not define in general the set L ∩ K. This is not a surprise because we know that the intersection of two context-free languages is not always a context-free language.

The Filtering Theorem is stated in Chapter 1 (Theorem 1.8) in terms of finite inductive sets of properties instead of recognizable sets. By Proposition 3.83, this is equivalent to the formulation of Theorem 3.88 (cf. Theorem 1.12). In Chapter 5, we will state a logical formulation of the Filtering Theorem where the recognizable sets K are defined by monadic second-order sentences.

We now generalize Proposition 1.6 and Corollary 1.9 and we show how inclusions of the form L ⊆ K where L is equational and K is recognizable can be proved (by fixed-point induction, see Section 1.2).

Proposition 3.91

(1) Let L be equational in an algebra M and be defined by (S, X µ ) for some equation system S with Unk (S) = X n and some µ ∈ [n]. Let K be recognizable in M. Then L ⊆ K if and only if there exists an n-tuple

(K 1 , . . . , K n ) of M-recognizable sets that is an oversolution of S and is such that K ⊆ K for every ∈ [µ].
(2) If furthermore K is effectively recognizable, and S is given, one can decide whether L ⊆ K, and if this is the case, one can construct the effectively recognizable sets K 1 , . . . , K n . The analogous statements hold for effective term-recognizability and for semi-effective recognizability.

Proof: (1) Let (L 1 , . . . , L n ) be the least solution of S in P(M), with L = ∈[µ] L . Let K be defined as h -1 (C) where h is a homomorphism of M into a locally finite algebra B and C ⊆ B.

Let us assume that L ⊆ K. For each i = 1, . . . , n, we define the recognizable set

K i := h -1 (h(L i )). In other words, K i is the union of the sets h -1 (q) such that L i ∩ h -1 (q) = ∅, for q ∈ B. Since K is a union of pairwise disjoint sets h -1 (q), we have L ⊆ K ⊆ K for every ∈ [µ] (and K -∈[µ] K is the union of the sets h -1 (q) such that q ∈ C and L ∩ h -1 (q) = ∅).
It remains to prove that for each i, we have:

p iP(M )(K 1 , . . . , K n ) ⊆ K i
where p i is the polynomial that is the righthand side of the equation of S that defines x i . It suffices actually to prove:

t P(M) (K 1 , . . . , K n ) ⊆ K i for each monomial t of p i . Let us write t = t [x i1 /y 1 , . . . , x i k /y k ] where t ∈ T (F, Y k ) and ListVar ( t ) = y 1 • • • y k . By Lemma 3.2(4), an element m of t P(M) (K 1 , . . . , K n ) is of the form t M (m 1 , . . . , m k ) with m j ∈ K ij for j = 1, . . . , k.
For each such j, there is in L ij an element m j such that h(m j ) = h(m j ). Then, the element of M defined as m := t M (m 1 , . . . , m k ) belongs to t P(M) (L 1 , . . . , L n ) and hence to L i since t is a monomial of the equation that defines x i . Since h is a homomorphism, we have h(m ) = h(m). Hence m belongs to K i . This shows that (K 1 , . . . , K n ) is an oversolution of S.

The opposite implication follows from Theorem 3.7: if (K 1 , . . . , K n ) is an oversolution of S, then L i ⊆ K i for each i, and since K ⊆ K for every ∈ [µ], we get L = ∈[µ] L ⊆ K as desired.

(2) Assume now that K is effectively recognizable and is defined as above. By Corollary 3.86, M -K is effectively recognizable (M is effectively recognizable by the proof of Proposition 3.85( 1)). Hence an equation system for the set L ∩ (M -K) can be constructed by Theorem 3.88 and one can decide if that set is empty, i.e., if L ⊆ K (by Corollary 3.24). For each i ∈ [n] and each element q of B, the set L i is defined by S and the set h -1 (q) is effectively recognizable. Hence, by the same procedure, it can be decided whether L i ∩ h -1 (q) = ∅, i.e., whether q ∈ h(L i ). Thus, K i is effectively recognizable. The same proof holds in the other two cases.

Hence, as soon as some correct n-tuple (K 1 , . . . , K n ) has been guessed, it remains to prove properties of the forms t P(M) (K 1 , . . . , K n ) ⊆ K and K ⊆ K for recognizable sets K, K , K 1 , . . . , K n to complete the proof.

We conclude this section by comparing the equational and the recognizable sets of an algebra.

Corollary 3.92 A domain M s of an F -algebra M is generated by a finite subsignature of F if and only if Rec(M) s ⊆ Equat(M) s .

Proof: Let M s be generated by a finite subsignature of F . Then M s ∈ Equat(M) s by Proposition 3.23(4). For every set K ∈ Rec(M) s we have K = M s ∩ K ∈ Equat(M) s by Theorem 3.88. Assume conversely that Rec(M) s ⊆ Equat(M) s . Since M s is recognizable by Proposition 3.85 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF], it is equational, hence it is generated by a finite subsignature of F , again by Proposition 3.23(4).

The inclusion Rec(M) s ⊆ Equat(M) s may be false without the hypothesis that M s is finitely generated. To prove this it suffices to consider an algebra M with a countably infinite domain M and a signature F consisting of one constant symbol to denote each element. Hence, M is generated by F but not by any finite subset of F . The set M is recognizable but it is not equational.

Since some context-free languages are not regular, we do not always have Equat(M) s ⊆ Rec(M) s . The families Rec(M) s and Equat(M) s are thus incomparable in general.

Recognizable sets of commutative words

We have described in Section 3.1.6 the equational sets of the additive monoid N k = N k , +, 0 , where 0 = (0, . . . , 0). We now describe its recognizable sets. A subset of N is ultimately periodic if it is of the form

P ∪{u+λ•v | u ∈ Q, λ ∈ N } where P, Q ∈ P f (N ) and v ∈ N .
Proposition 3.93

(1) A subset of N is recognizable in N if and only if it is ultimately periodic if and only if it is equational in N.

(

) If k ≥ 2, a set is recognizable in N k if and only if it is a finite union of Cartesian products R 1 × • • • × R k such that R 1 , . . . , R k ∈ Rec(N). 2
Proof sketch: (1) The length is an isomorphism from W({a}) to the additive monoid N = N , +, 0 . Using this fact, the first equivalence is proved in [*Eil], Proposition 1.1 of Chapter V, by means of deterministic finite automata over the alphabet {a}. The second equivalence is a special case of Proposition 3.25.

(2) The second assertion follows from the fact that for every two monoids

M 1 and M 2 , Rec(M 1 × M 2 ) is the set of finite unions of sets R 1 × R 2 where R 1 ∈ Rec(M 1 ) and R 2 ∈ Rec(M 2 ) (Proposition 12.2 of Chapter III of [*Eil]).
One direction of this equality is immediate from Proposition 3.85(2). The proof of the other direction can be sketched as follows: let

L ∈ Rec(M 1 × M 2 ) with finite congruence ∼ ; then L = {(m, m ) | (m, M2 ) ∼ (p, M2 ) and ( M1 , m ) ∼ ( M1 , p ) for some (p, p ) ∈ L}, hence L is a union of sets L p × L p where L p = {m ∈ M 1 | (m, M2 ) ∼ (p, M2 )} and L p = {m ∈ M 2 | ( M1 , m) ∼ ( M1 , p )};
there are finitely many such sets L p , L p and they are recognizable.

It follows that the linear set

{(n, n) | n ∈ N } is equational in N × N but is not recognizable in this algebra.
Remark 3.94 That Rec(M 1 × M 2 ) is the set of finite unions of products of recognizable sets of M 1 and M 2 is true for monoids but not for arbitrary algebras. Let N := N , Suc, 0 where Suc(n) = n+1 for all n ∈ N . Then, the set

{(n, n) | n ∈ N } is recognizable in N × N

Decidability questions

It is well known that the emptiness problem for finite automata is decidable, that is, there exists an algorithm that decides whether the set of terms accepted by a given finite automaton is empty or not: see Chapter 1 of [*Com+] or Proposition 5.3 of [*GecSte]. This is actually a consequence of the equivalence of regular grammars and automata, established in Proposition 3.47. However, this result does not extend to general recognizable sets, not even to those that are effectively recognizable. This should be contrasted with Proposition 3.24 relative to equational sets.

Proposition 3.95 The emptiness of an effectively recognizable set is not decidable in general, not even if the algebra has a single sort. It is decidable if the signature is finite and generates the considered algebra (even for semi-effectively recognizable and effectively term-recognizable sets).

Proof: In order to prove the first assertion, we give two counterexamples. We let F be the infinite one-sort signature consisting of a constant symbol a and of unary function symbols f n , for all n ∈ N . Let g be a computable mapping : N → {0, 1}. Let A be the finite F -algebra associated with g by:

A = {0, 1}, a A = 0, f nA (1) = 1, f nA (0) = g(n). The set L := val -1 A ({1}) ⊆ T(F ) is effectively recognizable in T(F ).
It is clear that L = ∅ if and only if g(n) = 1 for some n ∈ N , and this not decidable.

Here is the second example. We let F be reduced to the constant symbol a and M := N , a M with a M := 0. This algebra is not generated by F . Let A and g be as above. The mapping h such that h(0) = 0 and

h(i) = g(i) if i ≥ 1, is a homomorphism : M → A. Hence h -1 ({1}) is effectively recognizable in M.
It is nonempty if and only if g(i) = 1 for some i ≥ 1. And this is not decidable.

The decidability assertion is an immediate consequence of Theorem 3.88 and Propositions 3.23(4) and 3.24 (because if K ∈ Rec(M), then K = ∅ if and only if M s ∩ K = ∅ for every sort s). The two counter-examples show that none of the two hypotheses can be omitted.

Concluding remarks on recognizability

The two results that motivate the introduction and the study of recognizability are the linear-time membership algorithm (where linearity is meant with respect to the size of a term denoting the considered object) and the Filtering Theorem. Both of them are based on the local finiteness properties that characterize recognizability.

We now review the concrete and effective ways to specify recognizable sets and the uses of such specifications. Then we discuss when the notion of recognizability becomes void, and finally we come back to rational sets and regular expressions already discussed in Section 3.2.5.

Specification of recognizable sets

Let M be an algebra that is generated by its signature F , and let F be effectively given. We distinguish two cases.

The first case is when F is finite, hence M is finitely generated. Then a subset L of M is recognizable if and only if the language val -1 M (L) is regular (by Proposition 3.69 and Theorem 3.62). The most convenient way to specify L is by a finite complete and deterministic F -automaton

A recognizing val -1 M (L). It is decidable for a term t ∈ T (F ) if val M (t) is in L: one just runs A on t.
If M is semi-effectively given, then membership in L is decidable by an algorithm using two steps: first one looks for a term t ∈ T (F ) that evaluates 41 to the given element m of M . We know that a (possibly inefficient) algorithm exists for finding such t (see Definitions 2.8 and 2.127). Then, by running A on t, one obtains the answer that m belongs to L or not. The emptiness problem for L is decidable since it reduces to the emptiness problem for the language L(A ). The effectivity statement of the Filtering Theorem and its Corollary 3.89 are applicable.

Such an automaton can be constructed from the following data:

-a specification of L as a semi-effectively recognizable or effectively termrecognizable set 42 by a finite algebra A and a subset C of A (by Propositions 3.76(4) and 3.78(3.2)), or -a membership algorithm for L and a decidable finite congruence witnessing the recognizability of L (by Proposition 3.78), or -a membership algorithm for L and an upper-bound to γ L (s) for each sort s (by Proposition 3.80), 43 or -a computable finite F -inductive family of predicates (by Corollary 3.84).

The second case is when F is infinite. Let L be semi-effectively recognizable or effectively term-recognizable in M. Then, for every finite subsignature F of F , the set L ∩ M is effectively recognizable in the subalgebra M of M generated by F (by the first paragraph of the proof of Theorem 3.88). Hence, by the first case, one can construct a finite F -automaton A F that recognizes 41 Any such term will give the correct answer. The corresponding parsing problem is less constrained than for equational sets. 42 In the first case, M and A must be semi-effectively given; the homomorphism : M → A need not be specified, by Lemma 3.75 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. In the second case, A must be effectively given; M need not be semi-effectively given. In both cases a membership algorithm for C must be specified.

43 Recall that γ L is the recognizability index of L, cf. Definition 3.65.

the language val -1 M (L ∩ M ), which equals val -1 M (L) ∩ T (F ). It is decidable for a term t ∈ T (F ) if val M (t) is in L: letting F be the (finite) minimal subsignature of F such that t ∈ T (F ), one gets the desired answer by running A F on t. If M is semi-effectively given, then membership in L is decidable: given m in M , an algorithm can find a term t in T (F ) that evaluates to m (cf. Definitions 2.8 and 2.127); then one decides whether val M (t) is in L. The emptiness problem is undecidable (Proposition 3.95), however, the two constructions in the proof of the Filtering Theorem can be done by algorithms.

The automaton A F can be constructed from the same data as in the finite case, with 'finite' replaced by 'locally finite'. For the third kind of data, an algorithm must be specified that computes an upper-bound to γ L (s) for each sort s of F . Then we can use Proposition 3.80 (applied to M and L ∩ M ) because, by Remark 3.79(3), γ L∩M (s) ≤ γ L (s) for every s ∈ S (where S is the set of sorts of F ) and hence

M(L ∩ M ) ≤ Σ s∈S γ L (s).
Let us finally observe that if M is semi-effectively given (hence countable) but not generated by its signature, then one can enrich the signature by adding one constant symbol for denoting each element: the recognizable sets are the same (cf. the remark after Proposition 3.56), and we can obtain effective constructions under the conditions of the second case.

Recognizability is void in certain algebras

The notion of recognizability depends on the relevant algebra. It may become void in two opposite cases. If the algebraic structure is "poor", for example in the absence of functions of positive arity, then every set L is recognizable (the corresponding congruence has two classes, L and its complement). The notion of recognizability becomes trivial.

The opposite case is when the algebraic structure is so rich that there are very few recognizable sets. If one enriches an algebra by adding new operations, one gets fewer (or the same) recognizable sets. For example, consider the set N of nonnegative integers equipped with the successor and the predecessor functions (where the predecessor is defined by pred (0) = 0, pred (n + 1) = n). The only recognizable sets are N and the empty set. Indeed, if ∼ is a congruence and if n ∼ n + p for some n ≥ 0, p > 0, then by using n + p -1 times the function pred , we find that 0 ∼ 1. It follows (using the successor function repeatedly) that any two integers n and n + 1 are equivalent, hence any two integers are equivalent.

As another example, consider the monoid W({a, b}) of words over two letters. Let us add a unary operation, the circular shift, defined by: sh(ε) = ε and sh(aw) = wa, sh(bw) = wb, for every word w. The language ba * is no longer recognizable in this algebra, denoted by W({a, b}) sh . Here is the proof. Assume it is with finite congruence ∼. We have a m b ∼ a m+n b for some m and n > 0. Then ba m = sh m (a m b) ∼ sh m (a m+n b) = a n ba m but this word is not in ba * . Hence ba * is not saturated by any finite congruence on W({a, b}) sh . However recognizability does not degenerate completely since every commutative language L that is recognizable in W({a, b}) remains recognizable in W({a, b}) sh . To see this, let ≈ L be the syntactic congruence of L. We recall from Example 3.67 that for w, w ∈ {a, b} * :

w ≈ L w if and only if xwy ∈ L ⇐⇒ xw y ∈ L for all x, y ∈ {a, b} * .
It is finite since L is recognizable. Since L is commutative44 , it is also a congruence for sh(w): if w ≈ L w and x sh(w) y ∈ L then x w y ∈ L, hence x w y and x sh(w ) y belong to L; this proves that sh(w) ≈ L sh(w ).

Rational sets

We have defined the rational sets of monoids in Section 3.2.5. More generally, star operations, and thus regular expressions and sets that can be called rational, can be defined whenever we have binary associative operations like ⊕, ⊗, , • (cf. Chapter 1). Such operations have been defined and investigated for planar directed acyclic graphs in [BosDW] and for pictures in [*GiaRes] (a picture in this work is a directed vertex-labelled rectangular grid, cf. Example 2.56(3) and Section 5.2.3; they are different from those considered in [*Dre06]). In most cases, the corresponding class of rational sets contains properly the one of recognizable sets.

The equational and the recognizable sets of a one-sorted algebra have been defined by Mezei and Wright in [MezWri]. Many results presented in this chapter, in particular Proposition 3. Chapter 4

Equational and recognizable sets of graphs

The general algebraic notions of an equational and of a recognizable set have been defined in Chapter 3. We apply them to the graph algebras of Chapter 2.

We give examples that are interesting from the graph theoretic point of view. We review the consequences of the results of Chapter 3 and we establish some properties that are particular to graph algebras.

The organization of this chapter and its main results are as follows. In Section 4.1, we study the equational sets of the algebra JS; they are called the HR-equational sets. We establish decidability results for membership, emptiness and finiteness. We show some relationships between tree-width and HR-equationality. We compute the types of the elements of an HR-equational set and we prove that the equational sets of the one-sorted algebra JS are the same as those of the many-sorted algebra JS t . The HR-equational sets are also defined by the hyperedge replacement graph grammars: this grammatical characterization was actually their original definition.

In Section 4.2 we study the recognizable sets of the many-sorted algebra JS t ; they are called the HR-recognizable sets. We generalize to them the characterization of regular languages due to Myhill and Nerode. We also prove that there are uncountably many HR-recognizable sets of graphs.

In Section 4.3, we study similarly the equational sets of the one-sorted algebra GP, that are called the VR-equational sets. We establish for them decidability results similar to those for HR-equational sets. The VR-equational sets are related to clique-width as the HR-equational sets are to tree-width. Every HR-equational set of simple graphs is VR-equational: this is not surprising since the clique-width of a simple graph is bounded in terms of its tree-width but this observation does not replace a proof. The converse implication holds for sparse graphs.

In Section 4.4, we study the recognizable sets of the many-sorted algebra GP t : they are called the VR-recognizable sets. We generalize to them the char-acterization of regular languages by Myhill and Nerode. Every VR-recognizable set of graphs is HR-recognizable and the converse implication holds for the sets of simple graphs that are sparse. These implications are similar but opposite to those that relate the different types of equational sets.

In Chapter 5, we will prove that the sets of graphs defined by monadic second-order sentences are recognizable: this will give an easy way to specify recognizable sets and to use this notion.

Before starting the formal exposition, let us state as a rule of thumb that most of the definitions and results apply to labelled graphs (possibly with sources or ports) with essentially the same proofs as for unlabelled graphs (or s-graphs or p-graphs). By "labelled" graphs, s-graphs or p-graphs, we mean (K, Λ)labelled graphs, s-graphs or p-graphs, for some finite sets K and Λ. In order to facilitate reading, we will not specify always these technical details. The writing "(labelled) graphs" in statements is intended to remind the reader of this convention.

HR-equational sets of graphs

We recall from Section 2.3 that the acronym HR refers to the (one-sorted) algebra of (labelled) graphs with (and without) sources (called s-graphs), denoted by JS. Its signature F HR is countable and consists of the following operations:

-the parallel-composition denoted by , -the operation fg B that "forgets" the sources with names in a finite set B, (i.e, turns these sources into internal vertices),

-the operation ren h that renames sources according to a finite permutation h of the set of source names, -constant symbols denoting edges, loops and isolated vertices; the eventual vertex and edge labels are specified by the constant symbols.

We denote by F HR [K,Λ] the variant of F HR with which (K, Λ)-labelled graphs can be defined as values of terms, and the corresponding algebra by JS [K,Λ] . The many-sorted variants of these algebras are denoted by JS t and JS t [K,Λ] , see Section 2.6.2. We will recall more details about them when appropriate.

HR equation systems

The operations of F HR can be used to write equation systems according to the definitions of Section 3.1, from which we get the notion of an HR-equational set of s-graphs. By "a set of s-graphs", we mean a set of abstract s-graphs. If a set of concrete s-graphs L is specified in one way or another, we say that

L is HR-equational if the set {[G] iso | G ∈ L} is HR-equational.
Definition 4.1 (HR-equational sets of s-graphs) A set of s-graphs is HR-equational if it is equational in the algebra JS. We now review the relevant specializations of some definitions of Chapter 3. An HR equation system is an equation system over the signature F HR . Its general form is (without loss of generality by Lemma 3.4, see Definition 3.6) S = x 1 = p 1 , . . . , x n = p n where each p i is a polynomial over the signature F HR , i.e., p i ∈ Pol (F HR , X n ). According to Section 3.1.2, we will denote its least solution in the powerset algebra P(JS) by µx • S P(JS) (x) (with x denoting (x 1 , . . . , x n )). In order to get closer to the usual notation for context-free grammars, we will denote by L(S, x i ) the component µx • S P(JS) (x) x i of µx • S P(JS) (x). We will call it the set defined by (S, x i ), or generated by S from x i . We will denote by L Term (S, x i ) the corresponding set when S is solved in the powerset term algebra P(T(F HR )). By Theorem 3.18, L Term (S, x i ) = L(G(S), x i ) where G(S) is the regular grammar associated with S. For Y ⊆ Unk (S), we denote the set y∈Y L(S, y) by L(S, Y ), and similarly for L Term (S, Y ). Since JS is a one-sorted algebra, every HR-equational set is of the form L(S, x) for some HR equation system S and some unknown x of S.

For defining HR-equational sets of (K, Λ)-labelled s-graphs, we use the signature F HR [K,Λ] , the algebra JS [K,Λ] and the term algebra T(F HR [K,Λ] ) instead of F HR , JS and T(F HR ) respectively. Every HR equation system S is an equation system over the finite signature F (S) and hence over

F HR C (or F HR C,[K,Λ]
) for some finite set of source names C ⊆ A. 1 We denote the smallest such C by A(S) (so that Sort(S) ⊆ P(A(S))). It is the set of source names that occur in S and it can be computed as the union of the sets µ(t) such that t is a monomial in an equation of S, where Definition 2.35 is generalized to terms with variables in the obvious way (adding µ(x) = ∅ to the rules that compute µ(t), for every variable x). Thus, F (S) ⊆ F HR A(S) (or

F (S) ⊆ F HR A(S),[K,Λ] ).
The system S has the same least solution in the powerset algebras of T(F (S)) and T(F HR ) (or T(F HR [K,Λ] )), by Proposition 3.9 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. We obtain the following result from Proposition 3.23 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF], where we denote by val the mapping val JS (or val JS [K,Λ] ) that evaluates a term into the corresponding s-graph.

Proposition 4.2 For every HR equation system S and every unknown x of S, we have L(S, x) = val (L Term (S, x)) and L Term (S, x) ⊆ T (F (S)).

It follows that every s-graph G belonging to an HR-equational set L(S, x) is the value of some term in T (F (S)). Such a term yields a linear notation for G. Furthermore, it can be used as input to an algorithm checking certain properties of G or computing certain values attached to it, in polynomial time, as we will see in Chapter 6. 1 This uses the obvious fact that every finite subsignature of F HR is a subsignature of F HR C for some finite set C (and similarly for the labelled case). The definition of the signature F (S) is in Definition 3.6.

It follows also from Proposition 3.9(1) that an HR-equational set of s-graphs L is equational in the subalgebras JS[A(S)] and JS gen [A(S)] (cf. Remark 2.39( 1)) where S is an equation system that defines L, and similarly in the labelled case. We will use this fact in the proofs of Propositions 4. 10 and 4.13(3) below.

All closure results for equational sets established in Sections 3.1.5 and 3.2.4 hold for the HR-equational sets. For example, the mapping und that forgets edge directions (cf. Definition 2.9) is a homomorphism :

JS d → JS u . It follows from Proposition 3.23(2) that und (L) is HR-equational if L is an HR-equational set of directed s-graphs.
We now present or recall a few examples.

Examples 4.3

(1) Series-parallel graphs. The set of (directed) series-parallel graphs is defined by the equation:

x = (x x) ∪ fg 3 (ren 2↔3 (x) ren 1↔3 (x)) ∪ -→ 12.
The second term in the righthand side of this equation is the expanded expression of the monomial x • x, written with • (series-composition), a derived operation of JS (cf. Example 2.133, Section 2.6.2). The undirected series-parallel graphs are obtained similarly with 12 instead of -→ 12.

(2) Rooted trees. The root of a tree is defined as its 1-source. (We recall from Definition 2.13 that edge directions follow from the choice of a root.) The defining equation is:

y = (y y) ∪ fg 2 ( -→ 12 ren 1↔2 (y)) ∪ 1.
(3) Trees. Trees, as defined in Definition 2.13, form the set L(S, u) where S is the following system:

u = fg 1 (z) z = (z z) ∪ fg 2 (12 ren 1↔2 (z)) ∪ 1.
(4) Syntactic trees of terms. We consider the syntactic trees of the terms in T (F ) where F := {f, g, a, b}, ρ(f ) := 2, ρ(g) := 1, ρ(a) := ρ(b) := 0. Each node of such a tree T has a label in F ; each edge has also a label, := 1 or r := 2, used to indicate whether it leads to the first (left) or to the second (right) son. The defining equation is:

t = (1 f fg 2 ( -→ 12 ren 1↔2 (t) fg 2 ( -→ 12 r ren 1↔2 (t)))) ∪ (1 g fg 2 ( -→ 12 ren 1↔2 (t))) ∪ 1 a ∪ 1 b .
The constant symbols 1 κ and -→ 12 λ denote respectively an isolated vertex that is a 1-source labelled by κ and an edge from a 1-source to a 2-source labelled by λ. (We have defined labelled s-graphs in Chapter 2, Definitions 2.11 and 2.32.) where u denotes any s-graph. However, we will only use f (u) for graphs u of type {1, 2}. One can do better, with less source names:

f (u) = ren 2↔3 (fg 2 [ren 1↔3 (fg 1 (u 13)) 23]) 12.
As we will see in Section 4.1.2, the second expression of the function f yields a better estimate of the maximal tree-width of a ladder.

(6) Cycles. The set of cycles C n , n ≥ 2, is defined as L(T, w) where T is the following system:

w = fg 12 (v 12) v = 12 ∪ (v • 12).
and • is series-composition, see [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. The last equation can also be written as follows by expanding the definition of • and replacing ren 1↔3 (12) by 23:

v = 12 ∪ fg 3 (ren 2↔3 (v) 23).
Note that if we replace in T the monomial v • 12 by v • v, then the same sets are generated. (7) Outerplanar graphs. A biconnected outerplanar graph consists of one cycle C n for some n ≥ 2, called the external cycle, and of edges that can be drawn without crossings inside a circle representing the external cycle. It is thus planar. The set of biconnected outerplanar graphs is L(S, u) where S is the equation system:

u = fg 12 (v 12 a ) v = 12 a ∪ (12 v) ∪ (v • v).
The edges labelled by a (which are defined by the constant symbol 12 a ) are those of the external cycle. Note that L(S, v) is a set of undirected series-parallel graphs (disregarding the edge label a).

(8) Graphs of bounded tree-width. Theorem 2.83 has characterized the s-graphs of tree-width at most k -1 and of type included in [k] as those defined by terms in T (F HR [k] ), where F HR [k] is the finite subsignature of F HR consisting of the operations using source names in [k]. It follows then from Propositions 3.16, 3.9(1) and 3.23(2) that the set

TWD(≤ k -1, [k]) is HR-equational. 3
For directed s-graphs, the set TWD(≤ k -1, [k]) is defined, for k ≥ 2, by the equation:

x = (x x) ∪ ( B⊆[k] fg B (x)) ∪ ( h∈Perm f ([k]) ren h (x)) ∪ -→ 12 ∪ 1 ∪ 1 ∪ ∅.
Since this equation contains the terms ren h (x), we need not use the constant symbols -→ ab for (a, b) = (1, 2) because they can be defined by terms of the form ren h ( -→ 12). For example

-→ 32 = ren h ( -→ 12) where h(1) = 3, h(2) = 2, h(3) = 1
. For generating undirected s-graphs, we replace -→ 12 by 12. We have proved in Proposition 2.49 that the operations ren h are dispensable. This fact shows that the above equation is equivalent to the system of two equations (we could write it as a single equation but it is clearer in this way):

x = y ∪ (x x) ∪ ( B⊆[k] fg B (x)) y = ( a,b∈[k],a =b -→ ab) ∪ ( a∈[k] a) ∪ ( a∈[k] a ) ∪ ∅.
If we wish to define the set TWD(≤ k -1) of graphs of tree-width at most k -1, we use the additional equation z = fg (9) Graphs of bounded path-width. The characterization of graphs of path-width at most k -1 given in Proposition 2.85 can be translated into an HR equation system. From this proposition we get immediately the equation:

x = y ∪ (x y) ∪ ( B⊆[k] fg B (x)) ∪ ( h∈Perm f ([k]) ren h (x)),
to which we add the equations of (8) that define z and y. As in (8), we can omit in the equation defining x the terms ren h (x).

(10) Graphs of bounded bandwidth. A simple, loop-free undirected graph G has bandwidth at most k where k ≥ 1 if its vertex set can be enumerated as {v 1 , . . . , v n } in such a way that for every edge v i -v j with i < j we have j -i ≤ k. The bandwidth of G is defined as the smallest such k. The set of graphs of bandwidth ≤ k that have at least k + 1 vertices is L(S, x) where S is the HR equation system:

               x = fg [k] (y) y = b ∪ f (z) z = y e b = g 1 ∪ • • • ∪ g m e = e 1 ∪ • • • ∪ e p .
In this system, {g 1 , . . . , g m } is a set of terms denoting the simple loop-free undirected s-graphs with k + 1 vertices and of type [k] (cf. Proposition 2.33), f is the derived operation defined by the term ren h (fg 1 (x 1 )) where h( 1) The unknown e defines s-graphs of several types: each subset of [k + 1] that contains k + 1 is the type of some s-graph in L(S, e).

:= k + 1, h(i) := i-1 for i = 2, . . . ,
Since the system S defines slim terms, the graphs of bandwidth at most k have path-width at most k (by Propositions 2.85 and 4.2).

(11) Graphs of bounded cyclic bandwidth. An undirected loop-free graph G has cyclic bandwidth at most k where k ≥ 1 if its set of vertices can be enumerated as {v 0 , . . . , v n } in such a way that for every edge It is not hard to construct for each k an HR equation system that defines the set CB (≤ k) of simple graphs of cyclic bandwidth at most k. The problem of recognizing if a graph belongs to CB (≤ k) is NP-complete for each k ≥ 2 [LeuVW]. This shows that certain HR-equational sets have an NP-complete membership problem.

v i -v j with 0 ≤ i < j ≤ n, we have j -i ≤ k or i + n + 1 -j ≤ k. See
(12) Context-free languages. Every word over a finite alphabet A can be considered as a directed vertex-labelled graph: this graph is a directed path, each vertex of which has a label from A. The empty word is an isolated vertex with no label (we can also label this vertex by ). Hence a language can be considered as a set of labelled graphs. With this convention, every context-free language is HR-equational, but some HR-equational languages like {a n b n c n | n ≥ 0} or {ww | w ∈ A * } are not context-free. The HR-equational languages will be studied in Chapter 8.

Definition 4.4 (Derivation trees and parsing)

The notion of derivation tree, defined in Definition 3.43 (Section 3.2.3) for general equation systems, is applicable to HR equation systems.

The parsing problem for (S, x) where S is an HR equation system and x one of its unknowns consists, for a given (labelled) s-graph G, in finding a derivation tree of it or to report that no such tree does exist, i.e., that G does not belong to L(S, x).

Example 4.3(11) has shown that this problem can be NP-complete for certain HR equation systems. This fact should be contrasted with the case of context-free languages, since every context-free language has a cubic membership algorithm. We will come back to the parsing problem in Chapter 6.

Let S be an HR equation system. If G has a derivation tree d relative to S, then this tree can be transformed by a second-order substitution into a term t in T (F HR ) or in T (F HR (1) The membership problem for an HR-equational set is decidable.

(2) The emptiness of an HR-equational set (given by an equation system) is decidable.

(3) If a nonempty HR-equational set is defined by a uniform system with n unknowns, then it contains an s-graph of size at most 3 • 2 n-1 .

Proof: [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] The proof is similar to the one of Proposition 3.10. Let S be a uniform HR equation system with set of unknowns X n and let L = L(S, x 1 ). For a given s-graph H, we define M as the finite set of s-graphs Since the sequence S i P(JS) (∅) is increasing (cf. the Least Fixed-Point Theorem, Theorem 3.7), so is the sequence S i P(JS) (∅) ∩ M . Claim 4.5.1 For every i ∈ N , if

G of type included in A(S) such that G • ⊆ H • . If L = (L 1 , . . . , L n ) is an n-tuple
S i+1 P(JS) (∅) ∩ M = S i P(JS) (∅) ∩ M, then S i+2 P(JS) (∅) ∩ M = S i+1 P(JS) (∅) ∩ M.
Proof: It is clear from the definitions that, for all s-graphs G and K of type included in

A(S), if G K ∈ M then G, K ∈ M , and if f (G) ∈ M
where f is a unary operation of F HR , then G ∈ M . Hence, for every tuple L with L i ⊆ J S[A(S)], we have:

S P(JS) (L) ∩ M ⊆ S P(JS) (L ∩ M ).
It suffices to prove that S i+2 P(JS) (∅) ∩ M ⊆ S i+1 P(JS) (∅). Let L := S i P(JS) (∅) and assume that S P(JS) (L) ∩ M = L ∩ M . Then we have by the initial observation and the assumption:

S P(JS) (S P(JS) (L)) ∩ M ⊆ S P(JS) (S P(JS) (L) ∩ M ) = S P(JS) (L ∩ M ),
which is included in S P(JS) (L) by the monotonicity of S P(JS) , as was to be proved.

In order to decide if H belongs to L, we compute the sequence of n-tuples of finite sets S i P(JS) (∅) for i := 1, 2, . . . until one of the following two cases holds: In Case (a) we return a positive answer and in Case (b) a negative one. This algorithm terminates because M is finite and the sequence S i P(JS) (∅) is increasing. It is correct because if it terminates in Case (b), then, by the Claim,

S j P(JS) (∅) ∩ M = S i P(JS) (∅) ∩ M for every j > i, hence µx • S P(JS) (x) ∩ M = S i P(JS) (∅) ∩ M , so that H does not belong to L.
We do not claim that this is an efficient algorithm. The existence of polynomial algorithms for the membership problem will be discussed in Section 6.2.

(2) This is a special case of Corollary 3.24.

(3) We use Proposition 4.2. Let L = L(S, x 1 ) be nonempty and defined by a uniform system S. Let t be a term in L Term (S, x 1 ) of minimal size. Its height is at most n -1 by Proposition 3.53 (applied to F (S)), and it has at most 2 n-1 occurrences of constant symbols (or leaves). Since, as observed above, each such occurrence describes at most one edge and at most two vertices, the size of the s-graph val (t) is at most 3 • 2 n-1 .

We conclude this section with a small technical observation.

Remark 4.6 Let L be an HR-equational set defined as L(S, x 1 ) for some equation system S and let C be the union of the types of the s-graphs in L. We have C ⊆ A(S).

The source names in A(S) -C are auxiliary and can be changed by others. More precisely, if h is a finite permutation of A (the set of all source names) that is the identity on C, then the equation system S obtained from S by replacing, in each operation symbol that occurs in S, each source name a by h(a) is such that A(S ) = h(A(S)). It is clear that, for each unknown x of S, we have L(S , x) = ren h (L(S, x)). Hence, L(S , x 1 ) = L(S, x 1 ) = L since h is the identity on C. In particular, if L is a set of graphs, one can define it by a system S such that A(S) = [k] for some k. This remark extends Remark 2.39(2).

HR-equational sets and tree-width

We have proved in Proposition 2.76 that if

G = val (t) where t ∈ T (F HR C ) or t ∈ T (F HR C,[K,Λ]
), which means that the source names used in the operations occurring in t belong to C, then the tree-width of G is at most |C|-1. This result has consequences for HR-equational sets. We recall that if S is an HR equation system, then

F (S) ⊆ F HR A(S) (or F (S) ⊆ F HR A(S),[K,Λ]
). Hence, by Proposition 4.2, we obtain the following result.

Proposition 4.7 Every HR-equational set of (labelled) s-graphs has bounded tree-width. More precisely, for every HR equation system S and x ∈ Unk (S), we have twd (L(S, x)) ≤ |A(S)| -1.

This proposition gives an upper-bound on the tree-width of any s-graph in L(S, x). The upper-bound depends on the system S and is not necessarily the exact one, defined as twd (L(S, x)) := max{twd (G) | G ∈ L(S, x)}. In the example of ladders (Example 4.3(5)), the equation based on the first expression of f yields the upper-bound 3 (= 4-1) whereas the second expression of f yields the upper-bound 2 (= 3 -1) which is the exact one. Two natural questions can be raised:

(1) Can one compute twd (L(S, x)) from an HR equation system S and x in Unk (S) ?

(2) Can every HR-equational set of s-graphs L be defined as L(S, x) for some HR equation system S such that |A(S)| -1 = twd (L)?

The answers to these questions are respectively yes and no. The first answer is based on the fact that L(S, x) is equational in the many-sorted algebra JS t (as will be shown in Proposition 4.13) and the fact that each set4 TWD(≤ k, A(S)) is effectively recognizable in JS t , i.e., is effectively HR-recognizable (as will be shown in Proposition 4.31(7) using the Recognizability Theorem to be proved in Section 5.3).

From a system S, we have an upper-bound on the tree-width of the sgraphs in L(S, x). By Proposition 3.91(2) one can test, for each k < , if all s-graphs in L(S, x) have tree-width at most k which gives the exact value twd (L(S, x)). Actually, this algorithm is intractable for reasons discussed after Proposition 4.31.

We now give a counter-example showing the negative answer to the second question.

Counterexample 4.8 We consider the set L of odd paths with middle vertex as 1-source. Examples of such paths are

•1, • -•1 -•, • -• -•1 -• -•.
These s-graphs have tree-width 1 and can be expressed as P P where P is any path one end of which is the 1-source. However a system of equations based on this description, say S := x = y y, y = ren 1↔2 (fg 1 (y 12)) ∪ 1 , defines too many elements (L is a proper subset of L(S, x)), and no finite set of equations similar to this one can impose that two paths to be connected by their ends have equal length. However L = L(T, x) where T is the system:

x = ren 1↔3 (fg 12 (23 13 y)) ∪ 1 y = (1 2) ∪ f (y)
and L(T, y) is the set of ladders without "steps" (cf. Example 4.3( 5)). In this system, f is defined by f (y) := ren 2↔3 (fg 2 [ren 1↔3 (fg 1 (y 13)) 23]). But no system of equations using only two source names can define exactly L. (We do not give the technical proof of this fact.) Remarks 4.9

(1) We know from Example 4.3(8) that the set of graphs of tree-width at most k is HR-equational, but what about the set TWD(k) of those of tree-width exactly k? This set is also HR-equational. In fact, it can be expressed as follows:

TWD(k) = {G ∈ TWD(≤ k) | G / ∈ TWD(≤ k -1)},
hence as the intersection of a JS t -equational and a JS t -recognizable set (see the discussion on Question (1) above; the complement of TWD(≤ k -1) is JS trecognizable by Proposition 3.85). Thus, it is JS t -equational by the Filtering Theorem (Theorem 3.88) and hence HR-equational by Proposition 4.13 below.

Although an HR equation system defining TWD(k) can be constructed, the corresponding algorithm is intractable (see the discussion after Proposition 4.31). Similar observations hold for the set PWD(k) of graphs of path-width exactly k.

(2) Proposition 4. 7 and Example 4.3(8) show that a set L of (labelled) graphs may not be HR-equational for two reasons: either it has unbounded tree-width or it has bounded tree-width, but has a too complex internal structure for being described by a finite set of equations. In the first case, illustrated by the set of planar graphs (Example 2.56(4)), L is not a subset of any HR-equational set. In the second case, illustrated by the set of paths of length 2 n for some n (see Proposition 4.16 below), L is a subset of an HR-equational set, the set of graphs of tree-width at most k (and labelled with the same labels as the graphs in L). In the case of context-free languages, which are the equational sets of free monoids, only the second case can occur because the set A * is context-free for each finite alphabet A.

Type analysis of HR equation systems

In Examples 2. 134 and 4.3(8,10), we have given examples of HR equation systems that define s-graphs, not all of the same type5 . We now show how to compute the (finite) set τ (L) of types of the s-graphs of an HR-equational set L by using the preservation of least solutions of equation systems under homomorphisms (Proposition 3.23( 1)).

Proposition 4.10 For every HR-equational set L given by an HR equation system S, the finite set τ (L) ⊆ P(A(S)) can be computed.

As a preparation for the proof, we turn the type mapping τ : J S → P f (A) into a homomorphism : JS → T where T is an F HR -algebra called the type algebra, that we now define. Its domain is P f (A). Its operations are defined as follows, for X, Y ⊆ A:

X T Y := X ∪ Y, fg B T (X) := X -B, where B ∈ P f (A), ren h T (X) := h(X),
where h is a finite permutation of A, and

Proof: From Section 2.3.1, we know that τ (G H) = τ (G)∪τ (H), τ (fg B (G)) = τ (G) -B and τ (ren h (G)) = h(τ (G)
). This gives the result.

Proof of Proposition 4.10: We let L be defined by S, and A(S) be the set of source names occurring in S (cf. Definition 4.1). By the definitions we have

(τ (L(S, x 1 )), . . . , τ (L(S, x n ))) = τ (µx • S P(JS) (x)).
By Proposition 3.9(1), S has the same least solution in P(JS) and in P(JS[A(S)]). Hence:

τ (µx • S P(JS) (x)) = τ (µx • S P(JS[A(S)]) (x)).
Since τ is a homomorphism from JS[A(S)] to T[A(S)] by Lemma 4.11, Proposition 3.23(1) implies that the above tuple is equal to µx • S P(T[A(S)]) (x), which is computable by Proposition 3.10 since its components are all finite (as they are subsets of the finite set P(A(S)) ).6

Note that L(S, x i ) = ∅ if and only if τ (L(S, x i )) is empty7 . This algorithm yields also an emptiness test as a by-product. Another consequence of Lemma 4.11 is that the set J S C of s-graphs of type equal to some finite subset C of A(S) is recognizable in the algebra JS[A(S)]. Hence, by the Filtering Theorem (Theorem 3.88) applied to

M := JS[A(S)], if L is HR-equational then L ∩ J S C is HR-equational for every C ∈ τ (L).
Definition 4.12 (Typed HR equation systems) A set of (labelled) s-graphs is homogenous if all its elements have the same type. An HR-equational set is thus a finite union of homogenous HR-equational sets. A typed HR equation system is an equation system S over the many-sorted signature F tHR (or F tHR [K,Λ] ). Such systems define the JS t -equational sets, which are also finite unions of homogenous sets because the sort of an s-graph G in the many-sorted algebra JS t is its type τ (G). We define L(S, x i ), L Term (S, x i ), L(S, Y ) and L Term (S, Y ) as in Definition 4.1, for JS t and T(F tHR ) instead of JS and T(F HR ).

Although they are not solved in the same algebra, an HR equation system and a typed HR equation system will be said to be equivalent if they have the same least solution, respectively in P(JS) and in P(JS t ).

We will prove that a set of s-graphs is HR-equational (i.e., JS-equational) if and only if it is JS t -equational. That means that the HR equation systems and the typed HR equation systems define the same sets of s-graphs.

An HR equation system S is homogenous if each set L(S, x) for x ∈ Unk (S) is homogenous. We will prove that a trim and homogenous equation system can be transformed into an equivalent typed HR equation system. We extend to HR equation systems the typing and untyping transformations of terms described in Section 2.6.2. If S is a typed HR equation system of the general form x 1 = p 1 , . . . , x n = p n , we let Unt(S) be the system obtained from S by replacing, in each polynomial p i , a monomial t by Unt(t) (cf. Definition 2.129). We will prove that S and Unt(S) are equivalent. Conversely, let S be a homogenous and trim HR equation system (cf. Definition 3.36). We define the type τ (x) of an unknown x of S as the common type of all s-graphs in L(S, x). Then, we transform S into a typed system Typ(S) by replacing in each righthand side of an equation of S a monomial t by Typ τ (t), where the typing of Definition 2.131 is done with τ as type assignment (the mapping β in that definition). An HR equation system S is typable if S = Unt(T ) for some typed HR equation system T . If S is trim, then T = Typ(S). If an HR equation system S is trim and homogenous, then it can be typed (i.e., Typ(S) is defined), but it need not be typable because Unt(Typ(S)) need not be equal to S. For a typable HR equation system S, the sets L Term (S, x i ) consist of reduced terms (cf. Proposition 2.38), i.e., the operations fg B and ren h are only applied to terms t such that B ⊆ τ (t) and h is a permutation of τ (t) ∪ h(τ (t)) respectively. It follows from the next proposition that every HR-equational set can be defined by a typable HR equation system.

Proposition 4.13

(1) A typed HR equation system S is equivalent to its associated typable system Unt(S). For every unknown x, L Term (Unt(S), x) consists of reduced terms.

(2) If S is a trim and homogenous HR equation system, then Typ(S) is a typed system, and it is equivalent to S.

(3) Every HR-equational set is defined by a typed HR equation system that can be effectively constructed from any HR equation system defining the considered set.

(4) A set of s-graphs is HR-equational if and only if it is JS t -equational.

Proof: (1) Since Unt is the restriction to T (F tHR ) of a word homomorphism : W(F tHR ) → W(F HR ), cf. Definition 2.129, it is immediate from a comparison of the context-free grammars G(S) and G(Unt(S)) that L Term (Unt(S), x) = Unt(L Term (S, x)) for every unknown x. This implies the first statement by Proposition 3.23(1) (cf. Proposition 4.2) and Proposition 2.130. It also implies the second statement, because Unt(t) is reduced for every term t ∈ F tHR , as one easily shows by induction on the structure of t.

(2) We first prove that Typ(S) is typed: we need only verify that if t is a monomial of the righthand side of an equation x i = p i of S, then the sort of Typ τ (t) is τ (x i ). Let G j be an (arbitrary) element of L(S, x j ) for each j = 1, . . . , n; its type is τ (x j ). By Proposition 2.132(1,2) the sort of Typ τ (t) equals the type of the s-graph

t JS (G 1 , . . . , G n ). Since t JS (G 1 , . . . , G n ) belongs to L(S, x i ), it has type τ (x i ).
For proving that S and Typ(S) have the same least solution, we observe that, for every i ∈ N , we have:

S i P(JS) (∅) = Typ(S) i P(JS t ) (∅).
This is easily proved by induction on i by using Proposition 2.132(3) (and Lemma 3.2(4)). By taking the least upper-bounds over all i of both sides of the equation, we get by Theorem 3.7 the equality of the least solutions of S and Typ(S).

(3) Let L be HR-equational and nonempty, defined as L(S, x) for an HR equation system S. Since S has the same least solution in P(JS) and in P(JS[A(S)]) and since the type mapping τ is a homomorphism from JS[A(S)] to T[A(S)] (as in the proof of Proposition 4.10), we can apply Corollary 3.89 and trim the resulting system by using Proposition 3.37. We obtain a trim equation system S with an unknown y C for every y ∈ Unk (S) and C ⊆ A(S) such that C ∈ τ (L(S, y)); moreover, L(S , y C ) is the set of s-graphs in L(S, y) of type C. It is homogenous, hence, we get by (2) an equivalent typed system Typ(S ). Then L, initially defined as L(S, x), is L(Typ(S ), Y ) where Y consists of all unknowns x C ∈ Unk (S ).

(4) follows directly from ( 1) and (3).

The construction in the proof of (3) has already been sketched in Example 2.134. The typed system resulting from it can be much larger than the original one.

Example 4.14 (A large typed system) Let E n for n ≥ 2 be the equation

x = fg 1 (x) ∪ • • • ∪ fg n (x) ∪ s n where s n is the term -→ 12 -→ 23 • • • --→ mn with m = n -1. The size of E n is O(n) but the size of the corresponding typed system S n is O(2 n ): we have L(E n , x) = {val (fg B (s n )) | B ⊆ [n]},
hence it consists of 2 n s-graphs of pairwise different types. The system S n has thus one equation for each element of L(E n , x).

All these definitions and results extend to labelled graphs. We recall from Definition 2.9 that the size of a graph G is the integer

Sizes of graphs and the finiteness problem

G := |V G | + |E G |.
We define the size of an s-graph G as G • . We will prove that if L is an HR-equational set, then the set L := { G | G ∈ L} is semi-linear and hence its finiteness can be tested. As shown in Section 3.1.6, the semi-linear sets are the equational sets of N, the free commutative monoid N , +, 0, 1 generated by the constant 1. We will use the auxiliary size function defined by

G i := G -|τ (G)|.
Hence G i is the number of internal vertices of G plus its number of edges. This function satisfies the following properties:

G H i = G i + H i , (4.1) fg B (G) i = G i + |B ∩ τ (G)|, (4.2) ren h (G) i = G i . (4.3)
Proposition 4.16 For every HR-equational set L, the set L is semi-linear.

A description of L can be computed from a system that defines L.

Proof: If L is defined by a system S, then fg A(S) (L) is an HR-equational set of graphs by Proposition 3.45(3), and

L = fg A(S) (L) = fg A(S) (L) i .
Thus, in what follows, it suffices to show that L i is semi-linear. Moreover, by Proposition 4.13 (and the fact that the class of semi-linear sets is closed under union), we may assume that L is defined by (S, x) where S is a typable HR equation system and x ∈ Unk (S).

By Proposition 4.2 and Corollary 3.19, L = val (K) where K is the regular set of terms L Term (S, x) which, by Proposition 4.13 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF], consists of reduced terms. We will use Corollary 3.26 of Section 3.1.6. Taking F := F HR , let g : T (F ) → N be the affine mapping defined by g F ( ) := 0, g F (fg B ) := |B|, g F (ren h ) := 0 and g F (c) := c i for every constant symbol c. Then g(t) = val (t) i for every reduced term t ∈ T (F HR ) by Equalities (4.1), (4.2) and (4.3) above. Hence g(K) = L i and L i is semi-linear by Corollary 3.26.

Example 4.17 We let S be the typable system of Example 4.3(3) that defines trees. In order to have a more clear construction, we turn it into the following typable and uniform system S :

         u = fg 1 (z) z = (z z) ∪ fg 2 (z ) ∪ 1 z = 12 z z = ren 1↔2 (z)
where u has type ∅, z has type {1}, z has type {1, 2} and z has type {2}. We follow the proof of Corollary 3.26 as presented in Example 3.42(3). By the proof of Proposition 3.41 we obtain from S the following system S , to be solved in

P(N):          u = z + 1 z = (z + z) ∪ (z + 1) ∪ 0 z = 1 + z z = z.
Every unknown that defines a set of s-graphs L in S , defines the set of integers L i in S . By unfolding and by removing unknowns that are not useful for {u} (Sections 3.2. 1 and 3.2.2,and in particular Propositions 3.31 and 3.37), one can simplify S into the following system:

u = z + 1 z = (z + z) ∪ (1 + z + 1) ∪ 0. This equation system defines in N the semi-linear set L(S, u) = {2n + 1 | n ∈ N }.
Remarks 4.18

(1) It is important that systems are typable so that terms are reduced and hence Equality (4.2) can be used to define an affine mapping.

(2) We will generalize this result 8 by replacing the sizes of s-graphs of an HRequational set by tuples of integers (|X 1 |, . . . , |X k |) where X 1 , . . . , X k are sets of vertices and/or edges defined by a monadic second-order formula. In particular, the set of cardinalities of the vertex sets of the graphs of an HR-equational set is semi-linear. This fact can be proved by modifying the size functions of Definition 4.15: it suffices not to count edges. The proof of Proposition 4.16 is then the same.

Proposition 4.19 There is an algorithm that decides the finiteness of an HRequational set L given by an equation system S; if L is finite, it can be computed from S. Furthermore, if L is finite and S is uniform and typable, then the size of an s-graph in L is at most 3 • 2 n-1 and the cardinality of L is at most (|F (S)| + 1) 2 n , where n is the number of unknowns of S.

Proof: We consider unlabelled s-graphs; the proof for (K, Λ)-labelled s-graphs is entirely similar. Let L be an HR-equational set. Since τ (L) is finite, L is finite if and only if L is finite, and this can be decided by Proposition 4.16 (because one can check from the description of L as a semi-linear set if that set is finite).

Let us now assume that L is finite. To prove that L can be computed, it suffices to show, by Remark 3.38(3) and Proposition 4.13(4), that the effectively given algebra JS t is infinity-preserving. A homogenous set of s-graphs L is finite if and only if L i is finite. Thus, it follows from Equalities (4.1), (4.2) and (4.3) that all the operations of JS t are infinity-preserving.9

To prove the last assertion, we use a pumping argument similar to the one in the proof of Proposition 3.53. Let X ⊆ Unk (S) be such that L = L(S, X) and let K := L Term (S, X). Then L = val (K) and K ⊆ T (F (S)) by Proposition 4.2. Note that K need not be finite. Let A be a finite F (S)-automaton with n states that accepts K, see Proposition 3.47 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. Since S is typable, we may assume that all terms in L(A , q) have the same type, for each q ∈ Q A .

Claim 4.19.1 For every s-graph G in L there exists a term t ∈ K of height at most n -1 such that val (t) = G.

Proof: Let t ∈ K be such that val (t) = G. If ht(t) ≥ n, then A has an accepting run r on a term t such that r(u) = r(v) for some positions u, v with

u < t v. Hence t = c[c [t ]] where c, c ∈ Ctxt(F (S)), c is not empty, t = t/u, c [t ] = t/v
(G ) = ren h (fg B (G H)) for every s-graph G with τ (G ) ⊆ A(S). Then τ (H) ⊆ τ (G )

Hyperedge replacement

The purpose of this section is to describe the link between graph grammars defined in terms of rewritings and HR equation systems. We do not intend to develop the theory of context-free graph grammars based on graph rewritings. This theory is presented in detail in the handbook [*Roz].

We will show that the monomials forming the polynomials p i of a typed HR equation system S = x 1 = p 1 , . . . , x n = p n can be seen as certain hypergraphs with sources, and that the s-graphs defined by S can be obtained by finite sequences of rewritings based on replacements of hyperedges by such hypergraphs, like the words generated by a context-free grammar are defined by sequences of replacements of letters by words.

We first explain this construction from the algebraic point of view of Chapter 3, cf. Remark 3.20(3). Let L be an equational set of an F -algebra M defined by an equation system S. Every element m of L is defined by a derivation sequence relative to the regular grammar G(S): x ⇒ t 1 ⇒ • • • ⇒ t n such that x is a nonterminal symbol of G(S) (hence an unknown of S), t 1 , . . . , t n are terms in T (F, Unk (S)), t n ∈ T (F ) and m = val M (t n ). In the case of words, i.e., of the F A -algebra M = W(A), the mapping val M extends in a natural way into a homomorphism : T(F A ∪ Unk (S)) → W(A ∪ Unk (S)), so that the image of the derivation sequence x ⇒ t 1 ⇒ • • • ⇒ t n under this mapping is a derivation sequence of the context-free grammar G[S]. So the words of an equational set of W(A) are produced by sequences of rewritings of words, and not only of terms.

In a general F -algebra M, the main task in order to get a similar notion of generation by rewriting is to define, for every equation system S, a superalgebra M of M and a value mapping T (F ∪ Unk (S)) → M that is a homomorphism. The appropriate superalgebra of JS t is an F tHR -algebra of hypergraphs with sources.

Definition 4.20 (Hypergraphs with sources)

We do not define general hypergraphs but only the very particular ones needed for defining hyperedge replacement. We let S := P f (A) be our usual set of sorts and we let U be a finite S-sorted set of variables10 , i.e., each We describe an operation that generalizes the replacement of a nonterminal symbol by a word in a derivation sequence of a context-free grammar.

x ∈ U has a sort τ (x) ∈ S. A U -hypergraph is a 5-tuple H = V H , E H , vert H ,
Let G and H be U -hypergraphs (both directed or both undirected). If e ∈ E G is a hyperedge of type τ (H), then we define as follows the U -hypergraph G[e ← H] resulting from the substitution of H for e in G. We assume G and H disjoint (if they are not we take disjoint copies in the usual way). We let:

G[e ← H] := [(G -e) ⊕ fg τ (H) (H)]/≈
where G -e is G minus the hyperedge e, and ≈ is the equivalence relation on V G ∪ V H generated by the set of pairs {(vert G (e)(a), src H (a)) | a ∈ τ (H)}. We denote by ⊕ the disjoint union; it is well defined since the two arguments are disjoint and of disjoint types. If

τ (H) = τ (e) = ∅, we have G[e ← H] = (G -e) ⊕ H. The type of G[e ← H] is τ (G).
The transformation of G into G[e ← H] is also called a hyperedge replacement.

G ⇒ G if and only if G = G[e ← H]
where e is a hyperedge of G labelled by some x and (x, H) ∈ R. For each x ∈ U , we let x denote the concrete hypergraph of type τ (x) with a unique hyperedge e labelled by x such that V x = τ (x) and vert x (e)(a) = src x (a) = a for every a in τ (x). We view x also as a constant symbol and we denote by U the set of these symbols for all x in U . The set generated from x ∈ U by Γ is the set L(Γ, x) of s-graphs (i.e., of U -hypergraphs without hyperedges) G such that x ⇒ * G. For Y ⊆ U , we denote the set y∈Y L(Γ, y) by L(Γ, Y ). We call such a set an HR set of s-graphs.

Our objective is to prove that the HR-equational and the HR sets of s-graphs are the same. We need a few more definitions and results. Proof: Straightforward induction on the structure of t based on the following facts (where, for readability, the types of the operations are not shown):

(1) x[e ← H] = H, (2) fg B (G)[e ← H] = fg B (G[e ← H]), (3) ren h (G)[e ← H] = ren h (G[e ← H]), (4) (G G )[e ← H] = G[e ← H] G if e ∈ E G ,
which hold for all G, G , H, e, fg B , ren h of appropriate types.

Definition 4.25 (From HR equation systems to HR grammars and vice-versa) Let S = x 1 = p 1 , . . . , x n = p n be a typed HR equation system. Let G(S) be the corresponding regular grammar (cf. Section 3.1.4, Definition 3.17). Its rules are the pairs (x i , m) such that m is one of the monomials of p i ; they form the set R(S). We let Γ[S] := U, R be the HR grammar such that U := {x 1 , . . . , x n } and:

R := {(x, val (m[x 1 /x 1 , . . . ,

x n /x n ])) | (x, m) ∈ R(S)}.
Conversely, for every HR grammar Γ = U, R , there exists a typed HR equation system S such that Γ[S] = Γ. To define it, it suffices to construct a term m H ∈ T (F tHR ∪ U) denoting H for each righthand side of a rule (x i , H) in R, cf. Propositions 2.33 and 2.132. Such a system S is not defined in a unique way. The grammar Γ[S] is analogous to the context-free grammar G[S] of Definition 3.12.

Lemma 4.26 Let S be a typed HR equation system and Γ[S] be the associated HR grammar.

(1) If

x i ⇒ t 1 ⇒ • • • ⇒ t p is a derivation sequence of the regular grammar G(S), then x i ⇒ val (t 1 ) ⇒ • • • ⇒ val (t p ) is a derivation sequence of the HR grammar Γ[S].
(2) Conversely, for every derivation sequence

x i ⇒ H 1 ⇒ • • • ⇒ H p of Γ[S],
there exists a derivation sequence

x i ⇒ t 1 ⇒ • • • ⇒ t p of G(S)
such that H j = val (t j ) for each j = 1, . . . , p.

Proof: Straightforward from the definitions and Proposition 4.24. (2) A set of s-graphs is HR if and only if it is HR-equational.

Proof: (1) Let (L 1 , . . . , L n ) be the least solution of S in P(JS t ). We know from Propositions 3.18 and 3.23(1) that each component

L i is {val (t) | t ∈ L(G(S), x i )}. It follows from Lemma 4.26(1) that L i ⊆ L(Γ[S], x i ).
The opposite inclusion follows similarly from Lemma 4.26(2).

(2) Immediate consequence of ( 1) and the two constructions of Definition 4.25, by Proposition 4.13(4). We leave to the interested reader the easy task of extending the definitions and results of this section to labelled graphs.

HR-recognizable sets of graphs

The notion of HR-recognizability is a particular case of the general algebraic notion defined and studied in Chapter 3, applied to the many-sorted algebra JS t (where the sort of an s-graph G is its type τ (G)) and not to the algebra JS.

Definitions and first examples

In this section, we detail the definitions and we give examples of sets of s-graphs that are HR-recognizable and of sets that are not. Definition 4.29 (HR-recognizable sets of s-graphs) An equivalence relation ∼ on the one-sorted F HR -algebra JS is type-preserving if every two equivalent (labelled) s-graphs G, G have the same sort, i.e., τ (G) = τ (G ). We call τ (G) the type of the equivalence class [G] ∼ . A type-preserving equivalence relation is locally finite if it has finitely many classes of each type. Hence a type-preserving congruence ∼ on JS is a union of equivalence relations ∼ C on the domains J S C and (by Definition 3.63) a congruence on the manysorted F tHR -algebra JS t defined in Section 2.6.2.

A set of s-graphs is HR-recognizable if it is recognizable in the many-sorted algebra JS t . We denote by Rec(JS t ) the family of HR-recognizable sets. 13Since JS t is effectively given, the notions of an effectively HR-recognizable, a semi-effectively HR-recognizable and an effectively HR-term-recognizable set make sense and are instances of the general definitions. By Proposition 2.33 and Lemma 3.75(1), a set is effectively HR-recognizable if and only if it is effectively HR-term-recognizable. The notion of HR-recognizability can also be characterized in terms of the one-sorted algebra JS: it follows from Proposition 3.64 that a set of s-graphs is HR-recognizable if and only if it is saturated by a type-preserving and locally finite congruence on JS. The HR-recognizable sets of (K, Λ)-labelled s-graphs are defined similarly with respect to the algebra

JS t [K,Λ] . If L is a subset of J S[E]
for some finite set E of source names, that is, if all s-graphs in L have a type included in E, then its recognizability can be considered with respect to JS t or to JS t [E]. If L is HR-recognizable, then it is also recognizable in JS t [E] by Proposition 3.56 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. If furthermore L ⊆ J S gen [E], then it is also recognizable in JS t,gen [E] by the same proposition. We will come back to such comparisons in Proposition 4.39 below.

The many-sorted algebra JS 1), they also have the same semi-effectively recognizable sets. The same proof gives that JS t,gen [E] and JS gen [E] have the same recognizable sets and the same semieffectively recognizable sets, and hence, by Proposition 3.78(3), also the same effectively recognizable sets. 14All closure results for recognizable sets established in Proposition 3.56 and Section 3.4.6 hold for the HR-recognizable sets. As noticed when considering the HR-equational sets, the mapping und that forgets edge directions is a homomorphism : JS t,d → JS t,u . It follows from Proposition 3.56(2) that und -1 (L) is HR-recognizable if L is an HR-recognizable set of directed s-graphs.

Congruences witnessing recognizability are usually not easy to construct, even for "simple" sets like the set of paths. The reason is that one has to describe congruence classes of countably many types and, usually, many classes of each type. Our main tool for proving that a set of (labelled) graphs is recognizable is to characterize it as the set of (finite) models of a sentence of monadic second-order logic. For some sets given below we can define a congruence and for the others we rest on their monadic second-order definability and on the Recognizability Theorem (Section 5.3) to claim that they are recognizable.

Examples 4.30

(1) Graphs with an even number of edges or of vertices. For the set L e of s-graphs with an even number of edges, the congruence is easy to define. We let

G ∼ e G if and only if τ (G) = τ (G ) and |E G | -|E G | is even. That ∼ e is indeed a congruence follows from the fact that |E G G | = |E G |+|E G | and E f (G) = E G
for every unary operation f . There are two equivalence classes of each type. Since ∼ is effectively given (as one easily checks), L e is effectively recognizable by Proposition 3.78(2).

For the set L v of s-graphs with an even number of vertices, the definition is similar:

G ∼ v G if and only if τ (G) = τ (G ) and |V G | -|V G | is even. This equivalence relation is a congruence because |V G G | = |V G | + |V G | - |τ (G) ∩ τ (G )| and V f (G) = V G
for every unary operation f . Again we have two equivalence classes of each type, and L v is effectively recognizable.

If, in the definition of ∼ e , we omit the condition τ (G) = τ (G ), then we get a congruence for the algebra JS that has two classes (but is not type-preserving). The set of s-graphs with an even number of edges is thus recognizable in the one-sorted algebra JS. This is not the same for ∼ v as one checks easily. The set of s-graphs with an even number of vertices is not recognizable in JS. This explains why we define recognizability with respect to the many-sorted algebra JS t . If we would define it with respect to JS, then many "simple" sets of s-graphs would not be recognizable.

(2) Connected graphs. In Section 4.1.3 we have characterized the type function τ as a homomorphism of JS into an F HR -algebra with domain P f (A). We now refine this function. We let the connectedness type of an s-graph G be defined by θ(G) := τ (CC (G)), i.e., θ(G) is the multiset of types of the s-graphs in CC (G), the set of connected components of G. In θ(G), we limit to 2 the number of occurrences of ∅. Hence ∅ ∈ θ(G) if and only if G has one connected component without sources, and ∅ has 2 occurrences in θ(G) if and only if G has at least two such connected components. The elements of θ(G) form a partition of τ (G). The multiset character of θ(G) is limited to at most two occurrences of ∅. The following statement is easy to prove:

There exist mappings θ , fg θ B , ren θ h such that for all s-graphs G, H we have:

θ(G H) = θ(G) θ θ(H), θ(fg B (G)) = fg θ B (θ(G)), θ(ren h (G)) = ren θ h (θ(G)),
where B and h range over P f (A) and Perm f (A) respectively. The desired congruence is defined by: G ∼ G if and only if θ(G) = θ(G ). Since τ (G) can be defined from θ(G), this congruence is type-preserving. We can replace in the definition of the mapping θ any value θ(G) containing ∅ and another set, either empty or not, by the unique value "NC" meaning "not connected". The values of this alternative function, call it θ (G), can be the empty set (for the empty graph), {∅}, NC or a partition of τ (G) with nonempty sets. A congruence ∼ can be defined by G ∼ G if and only if τ (G) = τ (G ) and θ (G) = θ (G ). We obtain a congruence with less classes of each type that witnesses also the recognizability of the set of connected s-graphs. It has 3 classes of type ∅ and B(|C|) + 1 classes of type C if C is not empty.

(3) One graph. Let H be an s-graph. To show that the singleton {H} is effectively HR-recognizable, we define χ(G) for an s-graph G by

χ(G) = G if G • ⊆ H • ⊥ otherwise.
We define ∼ by:

G ∼ G if and only if τ (G) = τ (G ) and χ(G) = χ(G ). It is a congruence because G • is a subgraph of (G G ) • , fg B (G) • and ren h (G) • . Clearly, {H} = {G ∈ J S | τ (G) = τ (H), χ(G) = H} hence is saturated by ∼.
It is effectively recognizable by Proposition 3.78(2). Thus, by Corollary 3.86, all finite sets are effectively HR-recognizable.

The last example implies Proposition 4.5 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] stating that the membership problem is decidable for every HR-equational set L: since {H} is effectively recognizable, so is the set J S -{H} (by Corollary 3.86) and one can decide whether L ⊆ J S-{H} by Propositions 3.91(2) and 4.13(4), i.e., whether H does not belong to L. This algorithm uses the Filtering Theorem (Theorem 3.88). Its application uses essentially the same computations as the algorithm in the proof of Proposition 4.5 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF].

Proposition 4.31 The following sets are effectively HR-recognizable (for all k):

(1) the set of graphs of degree at most k,

(2) the sets of trees and of paths, Proof: Each of these sets is characterized by a monadic second-order sentence. The Recognizability Theorem (Section 5.3) entails that they are all HRrecognizable. They are effectively so, since the sentences can be constructed.

Graphs of degree at most k are actually characterized by first-order sentences, one for each k. For the monadic second-order characterization of Case (6), see Corollary 1.15. For Case (7), see Section 5.2.2 (Proposition 5.11). A set as in Case ( 8) is characterized among the simple, loop-free and undirected graphs by finitely many excluded minors (see the observations after Proposition 2.21), so that it is characterized by a monadic second-order sentence using edge quantifications (by Corollary 1.14; the edge set quantifications are needed to express that the considered graph is simple, and only for this condition). If the excluded minors are known, the sentence can be constructed. The set of Hamiltonian graphs is characterized by a monadic second-order sentence using edge set quantifications.

As the reader may guess, the corresponding classes of labelled graphs are also effectively HR-recognizable.

For proving Proposition 4.31, the direct construction of congruences is feasible for Cases (1) -(5) and ( 9) along the lines of the previous examples. It would be extremely complicated (and uninteresting to work out) for Cases (6) and ( 7).

The proof of Case ( 7) is based on the characterizations of the sets TWD(≤ k) by finite sets of excluded minors (cf. Corollary 2.60(2) in Section 2.4.2), hence by a monadic second-order sentence (cf. Corollary 1.14). From this sentence one can easily build a monadic second-order sentence characterizing the set TWD(≤ k, C), as shown in the proof of (P7) of Proposition 5.11. And finally the Recognizability Theorem is used to construct a specification of TWD(≤ k, C) as an effectively HR-recognizable set. Although such a specification can be constructed, the corresponding algorithm is intractable for two reasons. First because the excluded minors characterizing the set TWD(≤ k) are numerous and presumably very large for k > 3 (see [Lag] and [Din]) and second, because the constructions of the Recognizability Theorem are intractable, even for relatively "small" monadic second-order formulas.

We now present examples of sets that are not HR-recognizable, together with some tools allowing to establish these facts. (where ρ(f ) = 2, ρ(g) = 1, ρ(a) = ρ(b) = 0) is not regular, hence is not recognizable in the algebra of terms, as proved in Example 3.54. We will also use the fact that if H := {f, g, a, b} is a derived signature of a signature F , M is an F -algebra and

L ⊆ M is recognizable in M, then {t ∈ T (H) | val M H (t)
∈ L} is a recognizable, hence regular, set of terms by Theorem 3.62 and Proposition 3.56(2,3). We will use this fact for M := JS t . For proving the three statements, we need only replace in the set N defined by (4.4) the operations f, g, a, b by appropriate derived operations.

Case of L 1 : We let a and b denote 1, we let g denote the derived operation such that g(u) := ren 1↔2 (fg 1 (u 12)) and we let f denote . We let val : T ({f, g, a, b}) → J S be the associated value mapping. Let K be the regular set of terms {f g n ag m b | n, m ≥ 0}. If L 1 would be HR-recognizable, then val -1 (L 1 ) ⊆ T ({f, g, a, b}) would be recognizable, hence regular, and so would K ∩ val -1 (L 1 ) by Proposition 3.85 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. But this set is N , which is not regular. Hence L 1 is not HR-recognizable.

Cases of L 2 , L 3 : The proofs are similar. Instead of , we take for f the binary derived operation f (u, v)

:= fg 1 (u) fg 1 (v).
These examples prove that the families of HR-recognizable and of HRequational sets are incomparable: the set L 1 is HR-equational (cf. Counterexample 4.8) but not HR-recognizable, whereas the set of planar graphs is HR-recognizable (cf. Proposition 4.31(6)) but not HR-equational (cf. Remark 4.9(2)). This fact should be contrasted with the case of words: every recognizable, hence regular language is context-free, hence is equational in W(A). However, we find again the familiar situation with the following fact: every HR-recognizable set of graphs of bounded tree-width is HR-equational, as will be shown in Corollary 4.38.

The recognizability index can also be used to prove that certain sets are or are not HR-recognizable.

Definition 4.33 (The recognizability index of a set of s-graphs)

The index of a type-preserving equivalence relation ∼ has been defined in Definition 3.63, Section 3.4.3, for general many-sorted algebras. It is the function γ ∼ that defines for each sort s the number (possibly ω) of equivalence classes of ∼ of sort s. If ∼ is a congruence of the many-sorted HR algebra JS t , then for each C ∈ P f (A), the number γ ∼ (C) depends only on |C|. 18 This is so be-

cause if C ∈ P f (A) has cardinality |C| and h is a finite permutation of A such that h(C) = C , then for all G, G of type C we have ren h (G) ∼ ren h (G ) if G ∼ G (because ∼ is a congruence).
Since ren h has for inverse ren h -1 , we also have the opposite implication. Hence, ren h is a bijection from the equivalence classes of type C to those of type C and thus, γ ∼ (C) = γ ∼ (C ). We define γ ∼ (k) := γ ∼ (C) where C is any set of cardinality k. We also call γ ∼ the index of the congruence ∼.

The HR-recognizability index of a set L of (labelled) s-graphs is the mapping γ ≈ L , denoted simply by γ L , where ≈ L is the syntactic congruence of L with respect to JS t (cf. Definition 3.65). Hence, L is HR-recognizable if and only if γ L (k) ∈ N for every k (by Proposition 3.66 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]). If this is the case, then γ L (k) ≤ γ ∼ (k) for every k, if ∼ is any congruence witnessing the recognizability of L (by Proposition 3.66(2)).

The HR-recognizability index of a set L is thus a measure of its complexity as an HR-recognizable set. (Another recognizability index will be defined in a similar way with respect to the VR algebra, cf. Section 4.4.) It is relevant to the recognition of HR-recognizable sets of s-graphs by finite automata on terms since it defines the number of states of their associated minimal automata (cf. Section 3.4.3, Propositions 3.69 and 3.73(2)). Going back to Examples 4.30, we can see that γ L (k) ≤ 2 for the sets of Example 4.30 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. For the set L of connected graphs (Example 4.30(2)) we get γ L (0) = 3 and γ L (k) ≤ B(k) + 1 for k > 0. For the set L 1 of Proposition 4.32 we get γ L1 (1) = ω, and thus another proof that this set is not HR-recognizable.

A simpler HR-recognizability criterium

We give a characterization of HR-recognizability that is similar to the characterization by Myhill and Nerode of the regular languages (cf. [*Sak], Theorem 2.3 of Chapter II). It makes some proofs of recognizability or of non-recognizability easier because it involves "simple" graph operations, related to the well-understood notion of vertex separator.

We consider (labelled) s-graphs of type [k] for k ≥ 0. We denote by P k the following derived operation of JS t :

G P k H := fg [k] (G H)
for G, H both of type [k]. Thus, G P k H has type ∅. We let J N := k≥0 J N k , where J N k is the set of (labelled) s-graphs of type [k]. We let JN t be the corresponding many-sorted algebra. Its set of sorts is N , and its signature

{P k | k ∈ N } is denoted by F 2 .
For every subset L of J N 0 , we let ≡ L be the equivalence relation on J N defined by:

G ≡ L G if and only if there exists k ∈ N such that τ (G) = τ (G ) = [k] and G P k H ∈ L ⇐⇒ G P k H ∈ L for all H ∈ J N k .
We will compare three equivalences associated with L that will turn out to be essentially the same: its syntactic congruence relative to JS t , denoted by ≈ L , its syntactic congruence relative to JN t , denoted by ∼ L , and the equivalence ≡ L .

Theorem 4.34 For every set L of (labelled) graphs:

(1) the equivalence ≡ L is the syntactic congruence ∼ L of L with respect to JN t ,

(2) L is HR-recognizable if and only if it is recognizable in JN t if and only if the equivalence ≡ L is locally finite; the HR-recognizability index of L is equal to the index of ≡ L .

Proof:

(1) It is clear that G ∼ L G implies G ≡ L G
because the latter congruence is defined like the syntactic congruence of L with respect to JN t , but with terms c of the particular form y 1 P k y 2 . (We use the notation of Definition 3.65 where syntactic congruences are defined.) For the opposite implication, we observe that for every linear term c in

T (F 2 , Y p ) that has an occurrence of y 1 , if G ∈ J N k , H 2 , . . . , H p ∈ J N and the type of K := c JN t (G, H 2 , . . . , H p ) is ∅, then K = G P k H
) ∈ L, then c JN t (G , H 2 , . . . , H p ) ∈ L. Hence, G ≡ L G implies G ∼ L G .
(2) By ( 1) and Proposition 3.66 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF], it suffices to show the equality of the two indices. Since the set A of source names is linearly ordered, for every set C ⊂ A of cardinality k there exists an order preserving bijection h

C : C → [k].
Let ∼ ren be the type-preserving equivalence relation on J S defined by

G ∼ ren G if and only if τ (G) = τ (G ) and ren h τ (G) (G) ∼ L ren h τ (G) (G ).
The equivalence classes of ∼ ren of type C are in bijection by ren h C with those of ∼ L of type [k] where k := |C|. Hence ∼ ren has the same index as ∼ L , and so the same index as ≡ L by [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF].

We now prove that ∼ ren is the syntactic congruence ≈ L of L with respect to JS t . Let G, G be such that G ∼ ren G , let C be their common type, let k := |C| and let c be a context in Ctxt(F tHR ) such that c(G) ∈ L. By Propositions 2.130 and 2.51 (for c of sort ∅ and A = C: one can take A = A and ren h can be omitted) we have

c JS t (G) = fg C (G H) for some s-graph H of type τ (G) = C. Then we have c JS t (G) = ren h C (G) P k ren h C (H), and also c JS t (G ) = ren h C (G ) P k ren h C (H). By these equalities, since G ∼ ren G , c JS t (G) ∈ L implies c JS t (G ) ∈ L.
This proves that G ≈ L G . Now assume that G ≈ L G with C and k as before. By [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF], it suffices to show that ren h C (G) ≡ L ren h C (G ). This is obvious because for every H ∈ J N k we have ren h C (G) P k H = c JS t (G, H) for the term c(y 1 , y 2 ) = fg [k] (ren h C (y 1 ) y 2 ), and similarly for G . Hence, ∼ ren is equal to ≈ L .

As an example, we get that the singleton {H} is HR-recognizable if H is a graph, with a similar proof as in Example 4.30(3): if G and G are s-graphs of type [k] such that G ∼ G , then G ≡ {H} G .

We get also that every finite set of graphs is HR-recognizable. Another less immediate consequence is that the set of graphs of bandwidth at most k is not HR-recognizable for k ≥ 2: see Theorem 6.79 of [*DowFel].

Uncountably many HR-recognizable sets

Since we allow an HR-recognizable set to have elements of countably many different sorts, it is not so surprising that there are uncountably many HRrecognizable sets. For example: let I consist of the s-graphs of type [n] with n vertices and no edges, for n > 0. Every subset of I is HR-recognizable as one checks easily by considering the equivalence ∼ such that G ∼ G if and only if τ (G) = τ (G ) and, either G = G ∈ I or G and G do not belong to I. However, there are also uncountably many (homogenous) HR-recognizable sets of graphs. This prevents any attempt of characterizing these sets by finite graph automata or logical formulas (as this is possible for words, terms and trees). 19For proving this fact we give a condition ensuring that a set of (labelled) graphs is HR-recognizable. It is formulated with the operations P k of Theorem 4.34 (which is used to prove the next lemma).

Condition REC : Let L ⊆ J N 0 be a set of (labelled) graphs. For each k ≥ 0 there exists a finite set

B k ⊆ J N k such that: if G ∈ L and G = H P k K, then at least one of H and K is in B k .
Lemma 4.35 Every set L of connected (labelled) graphs that satisfies Condition REC is HR-recognizable.

Proof: Since all graphs in L are connected and P 0 is the disjoint union of graphs, we may assume that B 0 = {∅}. (The case k = 0 of REC is satisfied whenever L is a set of connected graphs.)

We let ∼ be the binary relation on graphs in J N defined as follows:

H ∼ H if and only if there exists k ∈ N such that τ (H) = τ (H ) = [k] and either H, H ∈ B k and H = H or H, H / ∈ B k and for every K ∈ B k , H P k K ∈ L ⇐⇒ H P k K ∈ L.
P k K ∈ L implies H P k K ∈ L. Assume H P k K ∈ L and H, K ∈ B k : then H = H and K = K by the definition of ∼ and H P k K = H P k K ∈ L. Otherwise, by Condition REC , exactly one of H and K, say K, is in B k . Hence K = K. Since H ∼ H we have H, H / ∈ B k . Hence, H P k K ∈ L implies H P k K ∈ L by the definition of ∼. Then H P k K belongs to L because K = K.
If Condition REC holds for a set L, then it holds for all its subsets. Hence, if it holds for an infinite set, there are, by Lemma 4.35, uncountably many recognizable sets of graphs.

Proposition 4.36 Every set of cliques and every set of square grids is HRrecognizable. So is every set of complete bipartite graphs K n,n .

Proof: We first consider cliques. If K n = G P k H where τ (G) = τ (H) = [k],
then at least one of G and H has no internal vertices. We let U k be the finite set of simple loop-free undirected s-graphs in J N k that have no internal vertices. We obtain the result by Lemma 4.35, by taking B k := U k .

Next we consider the complete bipartite graphs K n,n . If K n,n = G P k H where τ (G) = τ (H) = [k] and A, B are such that K n,n = A⊗B (cf. Section 2.4.2 for this notation), then, either at least one of G and H has no internal vertices, or at least one of A and B is a set of sources of G (and of H). The latter implies n ≤ k, and there are only finitely many possible s-graphs G and H in such a decomposition, forming a set D k . We obtain the result by Lemma 4.35 by taking B k := U k ∪ D k where U k is as above.

Finally we consider the case of square grids. Lemma 2.17 of [START_REF] Courcelle | The monadic second-order logic of graphs I: Recognizable sets of finite graphs[END_REF] establishes that if G n×n = G P k H where τ (G) = τ (H) = [k] and n ≥ 2k + 3, then at least one of G and H has at most k + k 2 vertices. We let B k be the set of simple loop-free s-graphs in J N k of degree at most 4 with at most (2k + 2) 2 vertices. Hence, if

G n×n = G P k H and τ (G) = τ (H) = [k], then either n ≤ 2k + 2 and |V G |, |V H | ≤ (2k + 2) 2 ,
A := {K 1,n | n ∈ A} is HR- recognizable if and only if A is recognizable in N. (If A is recognizable, then L A
is CMS-definable by Proposition 5.25, hence HR-recognizable by the Recognizability Theorem (Theorem 5.68). Conversely, let L A be HR-recognizable with syntactic congruence ∼. For every positive integer n, let g(n) be the s-graph K 1,n with an r-source of degree n; the equivalence relation on N defined by n ≡ m if and only if g(n) ∼ g(m) witnesses the recognizability of A.) Hence, in the previous proposition, one cannot replace the set of graphs K n,n by the set of all complete bipartite undirected graphs.

HR-recognizability and bounded tree-width

For further reference, we make explicit the following consequence of the algebraic version of the Filtering Theorem (Theorem 3.88, Section 3.4.7):

Theorem 4.37 The intersection L ∩ K of an HR-equational set L and an HRrecognizable set K is HR-equational. If K is semi-effectively HR-recognizable and L is given by an HR equation system, then an equation system defining L ∩ K can be constructed.

Proof: Immediate from Proposition 4.13 and the Filtering Theorem which says that the intersection of a JS t -equational set with a JS t -recognizable set is JS tequational.

Corollary 4.38 Let L be a set of (labelled) s-graphs of type included in a finite set C. If L is HR-recognizable and has tree-width at most k, then it is HR-equational.

Proof: Let L be as in the statement. The set TWD(≤ k, C) is HR-equational (Example 4.3(8)). Since L = TWD(≤ k, C) ∩ L, L is also HR-equational by Theorem 4.37.

We now compare HR-recognizability to recognizability in a finitely generated algebra.

Proposition 4.39 Let k ∈ N and let C be a set of source labels of cardinality k + 1. Let L be a set of (labelled) s-graphs of type included in C and of treewidth at most k. Then L is HR-recognizable if and only if it is recognizable in the

F tHR C -algebra JS t,gen [C], if and only if γ L (n) is finite for every n ≤ k + 1.
Proof: First observe that L ⊆ J S t,gen [C]. This follows from the algebraic characterization of tree-width given in Theorem 2.83 and from the discussion after Proposition 2.132. (The domains of JS t,gen [C] consist of the graphs of tree-width at most k and of type included in C).

Let L be HR-recognizable. It is, by definition, recognizable in JS t , hence by Proposition 3.56 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF], it is recognizable in the subalgebra JS t,gen [C] of JS t generated by the subsignature F tHR C of F tHR (see Section 2.3.1, Remark 2.39( 1)). Furthermore, the value of its HR-recognizability index γ L (n) is finite for every n, hence in particular for every n ≤ k + 1.

We now discuss the converse implications. If γ L (n) is finite for each n ≤ k+1, then the restriction of the syntactic congruence ≈ L to J S t,gen [C] is finite and hence witnesses the recognizability of L in the algebra JS t,gen [C]. It remains to prove that the recognizability of L in JS t,gen [C] implies its HR-recognizability. The proof, done in [CouLag], is quite complicated.

We will say a few words on HR-recognizable sets of unbounded tree-width. If L is an HR-recognizable set of graphs, then each set L ∩ TWD(≤ k) is HRrecognizable by Proposition 3.85 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF], because TWD(≤ k) is HR-recognizable by Proposition 4.31. The converse implication is actually not true, as shown below.

Proposition 4.40 There exists a set of graphs L that is not HR-recognizable but is such that L ∩ TWD(≤ k) is HR-recognizable for each k.

Proof: We take L = {G n×n ⊕ G n×n | n ≥ 1}. Since twd (G n×n ) = twd (G n×n ⊕ G n×n ) = n (

VR-equational sets of simple graphs

We now consider the equational sets of the algebra GP, defined in Chapter 2, Section 2.5.1. Its elements are simple graphs or, more generally, simple (K, Λ)-labelled graphs, where K is a finite set of vertex labels and Λ is a finite set of edge labels. Their vertices have other labels, called port labels, belonging to a (countably infinite) set A. Port labels are used by unary operations reviewed below to add edges to a graph. Graphs with ports are called p-graphs to recall this particular type of labelling. As for HR-equational sets, most of the results can be stated for ((K, Λ)-)labelled graphs and their proofs are not more difficult than for unlabelled graphs. We will not detail the extensions of the proofs to labelled graphs.

VR equation systems

A set of (labelled) p-graphs is VR-equational if it is equational in the algebra GP. We recall that the operations of GP are:

-the disjoint union, denoted by ⊕, -the operations --→ add a,b and add a,b that add, respectively, directed and undirected, unlabelled edges 20 between vertices with port labels a and b; for adding edges labelled by λ, we use --→ add a,b,λ and add a,b,λ , -the operations relab h that modify port labels by using a mapping h : A → A which is the identity outside of a finite subset of A, -constant symbols denoting isolated vertices, possibly with incident loops; the possible labels of vertices and loops are specified by these symbols.

The notion of a VR equation system S and the notations L(S, x), L Term (S, x), F (S), A(S) are similar to those relative to HR equation systems. They cover the case of labelled graphs as well. We will let val denote the evaluation mapping val GP (or val GP [K,Λ] ) from terms in T (F VR ) (or in T (F VR [K,Λ] )) to p-graphs (or to labelled p-graphs). The following proposition is similar to Proposition 4.2: Proposition 4.41 For every VR equation system S and every unknown x of S, we have L(S, x) = val (L Term (S, x)) and L Term (S, x) ⊆ T (F (S)).

The remarks about parsing and its algorithmic difficulty, derivation trees and the corresponding terms made in Definition 4.4 extend in an obvious way, and we do not repeat them. We only observe that if G is the value of a term

t in T (F VR [K,Λ] ), then |V G | = |Occ 0 (t)|, |E G | ≤ |Occ 0 (t)| 2 if G is unlabelled and |E G | = O(|Occ 0 (t)| 2 ) if G is labelled. (Occ 0 (t) is the set of occurrences of constant symbols in t different from ∅.)
The following proposition is similar to Proposition 4.5 and is proved in the same way.

Proposition 4.42 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] The membership problem for a VR-equational set is decidable.

(2) The emptiness of a VR-equational set (given by an equation system) is decidable.

(3) If a nonempty VR-equational set is defined by a uniform system with n unknowns, then it contains a p-graph with at most 2 n-1 vertices.

The technical observation made in Remark 4.6 about changing source labels extend to port labels in an obvious way.

We now give new examples and review some already given ones.

Examples 4.43

(1) Cographs. The set of cographs is defined by the equation (already considered in Sections 1.1.2 and 1.4.1):

x = (x ⊕ x) ∪ (x ⊗ x) ∪ 1
where the complete join ⊗ is the derived operation of GP u , the subalgebra of GP consisting of undirected p-graphs, defined by x ⊗ y := relab 2→1 (add 1,2 (x ⊕ relab 1→2 (y))). The constant symbol 1 denotes a graph with one vertex that is the 1-port (all vertices of a graph have port label 1). Without the monomial x ⊕ x, this equation defines the set of cliques K n , n ≥ 1. These sets are not HR-equational, by Proposition 4.7 (recall from Example 2.56(3) that K n has tree-width n -1).

(2) Directed cographs. The set of directed cographs is defined similarly by the equation:

y = (y ⊕ y) ∪ (y - → ⊗ y) ∪ (y ⊗ y) ∪ 1
where -→ ⊗ is the derived operation of GP defined by x -→ ⊗ y := relab 2→1 ( --→ add 1,2 (x ⊕ relab 1→2 (y))).

(3) Rooted trees. The sets of rooted trees (already considered in Example 4.3(2)) and of nonempty rooted forests are defined by the equation system S:

r = 1 ∪ relab 3→2 ( --→ add 1,3 (1 ⊕ relab 1→3 (f ))) f = r ∪ (f ⊕ f ).
An alternative system using the empty graph ∅ is S as follows:

r = relab 3→2 ( --→ add 1,3 (1 ⊕ relab 1→3 (f ))) f = ∅ ∪ (r ⊕ f ).
We have L(S, r) = L(S , r) and L(S , f ) = L(S, f ) ∪ {∅}.

(4) Trees. The set of trees (cf. Example 4.3(3)) is L(S , t) where S is the equation system:

     t = relab 2→1 (r) r = 1 ∪ relab 3→2 ( --→ add 1,3 (1 ⊕ relab 1→3 (f ))) f = r ∪ (f ⊕ f ).
The other sets considered in Examples 4.3 are also VR-equational sets because every HR-equational set of simple graphs is VR-equational as we will prove later (Theorem 4.49).

(5) Graphs of bounded clique-width. For each k, the set CWD(≤ k) of graphs of clique-width at most k is VR-equational: the proof is the same as for the sets TWD(≤ k -1) in Example 4.3(8). To be precise, Definition 2.89 yields, for k ≥ 1, the following equation that defines the set of undirected p-graphs G of clique-width at most k such that π(G) ⊆ [k]: Finally for generating graphs, we add the equation y = relab h (x) where h is such that h(i) := 1 for all i ∈ [k]. However we cannot claim, as in Remark 4.9(1) that the sets of graphs of clique-width exactly k are VRequational because these classes are not known to be monadic second-order logic definable, except for k ≤ 2.

x = (x ⊕ x) ∪ ( add a,b (x)) ∪ ( relab h (x)) ∪ 1 ∪ 1 ∪ ∅
Slightly more generally, the set CWD(≤ k, C) of p-graphs of clique-width at most k and of type included in C is VR-equational for every k ∈ N and every finite set C of port labels. So are the corresponding sets of labelled graphs. For each k ≥ 2, the set CWD(≤ k) is VR-equational but not HR-equational since it contains all cliques.

Linear clique-width can be handled in the same way as path-width in Example 4.3(9). In Section 2.5.6, we have defined variants of the signature F VR , obtained either by removing certain operations, by adding new operations or by replacing certain operations by (linear) derived ones. These new operations act on the same objects, the (labelled) p-graphs. Equation systems can be written over these alternative signatures, and they might define equational sets that are not exactly the VR-equational. However, they still define the VR-equational sets in all cases.

We first consider the case of

F κVR := C∈P f (A) F κVR C
. This signature is linear derived from F VR , but F VR is also linear derived from it: the operation ⊕ is in both signatures and for every unary operation f of F VR , we have f (G) = g(G, ∅) where g is the binary operation of F κVR defined by the term f (x 1 ⊕ x 2 ), cf. the proof of Proposition 2.121. It follows from Proposition 3.41 that the equational sets are the same for the two algebras.

A similar argument holds for the signature F VR , because every relabelling can be expressed as a composition of elementary relabellings (by using at most one auxiliary new port label, cf. Section 2.5.6, Proposition 2.118). For the signature F iVR it will be proved as a corollary of the Equationality Theorem for the VR algebra (Theorem 7.36) which gives a logical characterization of the class of VR-equational sets, although it would not be difficult to give a direct proof by a transformation of equation systems.

VR-equational sets and clique-width

For every VR equation system S, we define A(S) as the smallest subset C of A such that the signature F (S) is included in ] if labelled graphs are to be defined). (If S is written with derived operations like ⊗ and -→ ⊗ , we replace these operations by their definitions in order to determine the set A(S).) For the very same reasons as in Proposition 4.7 we have: Proposition 4.44 Every VR-equational set of (labelled) p-graphs has bounded clique-width. More precisely, for every VR equation system S and x ∈ Unk (S), we have cwd (L(S, x)) ≤ |A(S)|.

F VR C (or in F VR C,[K,Λ
A set of (labelled) graphs is not VR-equational if, either it has unbounded clique-width or has bounded clique-width but has an internal structure too complicated to be described exactly by an equation system. We made a similar observation about HR-equational sets in Remark 4.9(2), and the same examples illustrate the two cases: the set of planar graphs for the first case (because square grids have unbounded clique-width by Proposition 2.106(1)) and, for the second one, any set of paths whose lengths do not form a semi-linear set of integers (by Proposition 4.47(1) below).

Type analysis of VR equation systems

We recall that the type of a (labelled) p-graph G is the set π(G) of its port labels. If L is a set of (labelled) p-graphs, then π(L) := {π(G) | G ∈ L}. The proof of Proposition 4.10 can be adapted to the present case in a straightforward manner and we get: Proposition 4.45 For every VR-equational set L given by a VR equation system S, the finite set π(L) ⊆ P(A(S)) can be computed.

To compare the VR-equational sets with the equational sets of the manysorted VR algebra GP t of Section 2.6.3, typed VR equation systems can be defined as in Definition 4.12, together with all the related terminology in that definition.

Proposition 4.46 Every VR equation system can be effectively transformed into an equivalent typed VR equation system, and vice versa. A set of p-graphs is VR-equational if and only if it is GP t -equational.

The proofs are easily adapted from those of Proposition 4.13 (Section 4.1.3). A typed VR equation system can be exponentially larger than an untyped one defining the same set: Example 4.14 can be adapted to prove this fact.

For determining if a VR-equational set is finite, we can use the same method as in Section 4.1.4 for HR systems with the following adaptation: we need only count vertices, and we let |G| := |V G |. (A different size measure on graphs is used in Definitions 2.9 (Section 2.2) and 4.15 (Section 4.1.4).) We have for all G, H, a, b, λ and h of the relevant types

|G ⊕ H| = |G| + |H|, |add a,b (G)| = |add a,b,λ (G)| = | --→ add a,b (G)| = | --→ add a,b,λ (G)| = |relab h (G)| = |G|, |c| = 1 for every constant c that is not ∅ and |∅| = 0.
A set of simple (abstract) p-graphs L with vertex and edge labels in finite sets is finite if and only if the set {|G| | G ∈ L} is finite. Hence the methods used for Propositions 4. 16 and 4.19 give the following results.

Proposition 4.47

(1) For every VR-equational set L, the set {|G| | G ∈ L} is semi-linear. A description of it can be computed from a system that defines L.

(2) There is an algorithm that decides the finiteness of a VR-equational set L given by an equation system S; if L is finite, it can be computed from S.

(3) If L is finite and defined by a uniform and typable equation system S, then |G| ≤ 2 n-1 for every G in L, and the cardinality of L is at most

(|F (S)| • 2 a 2 • + 1) 2 n
, where a := |A(S)|, is the number of edge labels and n is the number of unknowns of S.

Proof: [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] The proof is analogous to the one of Proposition 4.16.

(2) The proof is analogous to the one of the first statement of Proposition 4.19.

(3) The proof is similar to the one of the last statement of Proposition 4.19, but in the Claim it uses Proposition 2.103 instead of Proposition 2.51. Moreover, the Claim is now the following: By this claim, the size of G is at most 2 n-1 by the same argument as in the proof of Proposition 4.42. The upper-bound for |L| is obtained in the same way as in the proof of Proposition 4.19, taking into account that, according to the proof of the claim, G can be obtained from t by adding an operation of the form ADD R at each node of t and then applying val . Note that R ⊆ A(S)×A(S)×Λ where Λ is the set of edge labels.

For a VR-equational set L, the set L (cf. Definition 4.15) need not be semi-linear: just consider for L the set of cliques.

Comparison with the HR-equational sets

VR-equational sets only contain simple (labelled) graphs (and p-graphs), whereas HR-equational sets may contain (labelled) graphs (and s-graphs) with multiple edges. We will compare the families of VR-equational sets and of HR-equational sets of simple (labelled) graphs. The following proposition shows that one can distinguish in an effective way the HR equation systems that define simple graphs.

Proposition 4.48 There exists an algorithm that, for every HR equation system S and every unknown x of S, decides if L(S, x) consists only of simple s-graphs, and, if this is not the case, that transforms S into an HR equation system S such that L(S , x) is the set of simple s-graphs in L(S, x).

Proof: It is not difficult to prove that the sets of simple, directed (or undirected), unlabelled (or (K, Λ)-labelled) s-graphs are effectively HR-recognizable, by constructing congruences as in Examples 4.30 (for the details, see the proof of Theorem 4.58). The existence of the desired algorithms follows then from Proposition 3.91(2) and the Filtering Theorem (Theorem 4.37).

Here is the main theorem of this section.

Theorem 4.49 Every HR-equational set L of simple (labelled) graphs is VRequational. A VR equation system defining L can be constructed from an HR equation system defining it.

For doing the proof, we introduce some technical notions that will also be useful for comparing HR-and VR-recognizable sets of simple (labelled) graphs.

Definition 4.50 (The border and the interior of an s-graph) We first give definitions for directed unlabelled s-graphs. The set of simple directed s-graphs is denoted by J S s . For an s-graph G and

X ⊆ V G , we denote by G[X] the s-graph G • [X], slab G X . In words, G[X] is the induced subgraph of G with vertex set X.
The border of an s-graph G ∈ J S s is the s-graph

β(G) := G[Src(G)] (it is also in J S s ). Clearly we have τ (β(G)) = τ (G). Note that β(G) is also a p-graph, with port G = slab G .
We define also the interior of G as the p-graph

Int(G) ∈ GP that consists of G • [Int G ] (we recall that Int G is V G -Src(G),
A := {a ∈ τ (G) | there is in G an edge u → src G (a)} A := {a ∈ τ (G) | there is in G an edge src G (a) → u}. Hence π(Int(G)) is a subset of P(τ (G)) × P(τ (G)). 21 If |τ (G)| ≤ N , then |τ (β(G)) ∪ π(Int(G))| ≤ N + 2 2N . Note that β(G) = G and Int(G) = ∅ if V G = Src(G). Moreover, if G is a graph, i.e., τ (G) = ∅, then β(G) = ∅ and Int(G) = G. 22
Note that an s-graph G can be reconstructed from β(G) and Int(G), because we have:

G = RELAB(ADD(β(G) ⊕ Int(G)))
where ADD and RELAB are derived operations (respectively compositions of edge additions and of relabellings) that are easy to define. The validity of the following facts, intended to show that β and Int are "almost" homomorphisms, is clear from the definitions.

Let G, H ∈ J S s . If G H is simple, then:

β(G H) = β(G) β(H) and Int(G H) = Int(G) ⊕ Int(H). (4.5)
If h is a finite permutation of A, then:

β(ren h (G)) = ren h (β(G)) and Int(ren h (G)) = RELAB h (Int(G)) (4.6)
where

RELAB h := relab g such that g( A, A ) = h(A), h(A ) for all A, A ⊆ τ (β(G)).
Next we consider the source forgetting operations:

β(fg B (G)) = β(G)[Src(G) -src G (B)] and
Int(fg B (G)) = RELAB B (ADD R(B) (Int(G) ⊕ β(G)[src G (B)])) ( 4
A b := {a ∈ τ (G) -B | src G (b) → src G (a) is an edge in β(G)} A b := {a ∈ τ (G) -B | src G (a) → src G (b) is an edge in β(G)}.
It should be noted that RELAB h , ADD R(B) and RELAB B depend on G, but actually, they only depend on β(G).

21 As in the proof of Proposition 2.103, we assume that the elements of this set are appropriately encoded as port labels in A that are not in τ (G). Formally this can be achieved by an injective computable mapping α : A ∪ (P f (A) × P f (A)) → A. Then port Int(G) (u) is formally defined as α( A, A ) with A, A as above. When β(G) is viewed as a p-graph, we can assume formally that its source names are encoded by α (and hence can be distinguished from the encoded port labels of Int(G)). Finally, we assume that α( ∅, ∅ ) = 1, the default port label. 22 We recall that ∅ is a constant symbol denoting the empty graph.

Finally, if G is defined by a constant symbol then:

β(G) = G and Int(G) = ∅. (4.8)
For dealing with undirected graphs, just one set A is needed instead of two sets A and A (since every undirected edge is a pair of opposite directed edges, the corresponding sets A and A are equal). The derived operation ADD R(B)

can use operations add A,b instead of --→ add A,A ,b and --→ add b, A,A . If |τ (G)| ≤ N , then |τ (β(G)) ∪ π(Int(G))| ≤ N + 2 N .
We will explain later the modifications to be done for handling labelled graphs.

We illustrate these definitions and facts with an example concerning undirected graphs. Figure 4.5 shows undirected s-graphs G, H. One can check on this example that β(G H) = β(G) β(H) and Int(G H) = Int(G) ⊕ Int(H) and that:

Int(fg 3 (G)) = relab 3→{2} (relab {2,3}→{2} (add {2,3},3 (Int(G) ⊕ 3))).
Proof of Theorem 4.49: Let L be an HR-equational set of simple directed graphs, given as L(S, X) where S is a uniform HR equation system (cf. Proposition 3.33) and X ⊆ Unk (S). By Proposition 3.37 we may also assume that S is trim with all unknowns useful for X. This implies that all s-graphs defined by S are simple: consider G in L(S, y) and a derivation sequence of G(S) from some x in X to a term t in T (F HR , {y}) where y has a unique occurrence; then t JS (G) ∈ L(S, x) ⊆ L. Since the operations of F HR preserve multiple edges and L consists only of simple graphs, G must be simple.

The mapping β behaves "homomorphically" (by (4.5), (4.6) and (4.7) of Definition 4.50) and there are only finitely many possible graphs β(G) (up to isomorphism) such that τ (G) = τ (β(G)) ⊆ A(S). Hence, we can assume that β(G) = β(G ) for every G, G ∈ L(S, y) and every y ∈ Unk (S) because, by using Corollary 3.89 of the Filtering Theorem, we can transform S into an equivalent system satisfying this property if this is not already the case. 23 We denote by β(y) the common value β(G) of the s-graphs G in L(S, y).

The next step is a transformation of S into a VR equation system S Int such that Unk (S Int ) := Unk (S) and L(S Int , y) = {Int(G) | G ∈ L(S, y)} for every y ∈ Unk (S). Since L is a set of graphs, Int(G) = G for every G ∈ L and so L equals L(S Int , X) and hence is VR-equational.

It remains to explain how S Int is obtained from S. The general equation of S is of the form

x = • • • ∪ m ∪ • • •
where each m is a monomial with only one function symbol because S is uniform. We define the corresponding equation of If N = |A(S)|, then this construction defines a system S Int with |A(S Int )| ≤ N + 2 2N . The same construction works for undirected graphs but uses at most N + 2 N port labels as noted above. We now consider the case of (K, Λ)-labelled graphs. The labels of vertices and loops are specified by the constant symbols that define graphs with a unique vertex. These richer constants are handled as in the unlabelled case, see (4.8). For each edge label, we need one pair of sets A, A where A and A are as in the case of directed unlabelled graphs. Hence, for a set Λ of edge labels, we need at most N + 2 2|Λ|•N port labels for directed graphs and at most N + 2 |Λ|•N for undirected ones. The above construction is easy to adapt.

S Int as x Int = • • • ∪ m Int ∪ • • • where m Int is as follows: if m = y z, then m Int := y ⊕ z, if m = ren h (y), then m Int := RELAB h (y), if m = fg B (y), then m Int := RELAB B (ADD R(B) (y ⊕ t B )),
As a consequence, we obtain a bound for the clique-width of a simple graph in terms of its tree-width (cf. Proposition 2.114). By taking N = k + 1, we get for G of tree-width at most k:

cwd (G) ≤ k + 1 + 4 k+1
if G is directed and unlabelled, and

cwd (G) ≤ k + 1 + 4 |Λ|•(k+1) if G is directed and (K, Λ)-labelled.
For undirected graphs, we get respectively the smaller upper-bounds k+1+2 k+1 and k + 1 + 2 |Λ|•(k+1) .

Sparse graphs

Although VR equation systems are strictly more powerful than HR equation systems (this is proved by Examples 4.43(1,2,5)), they are equally powerful for generating languages, sets of trees (through appropriate representations as labelled graphs) and sets of planar graphs. We now present a necessary and sufficient condition that subsumes these cases. Let

p ∈ N . A graph G is p-sparse if |E G | ≤ p • |V G |.
A set of graphs is p-sparse if all its graphs are p-sparse. It is uniformly p-sparse if all subgraphs of its graphs are p-sparse.

Recall from Proposition 2.115 that an unlabelled graph G is without K n,n if core(G) has no subgraph isomorphic to K n,n ; if G is labelled, we say that it is without K n,n if G λ (the subgraph of G consisting of its edges labelled by λ) is without K n,n for every edge label λ.

Theorem 4.51 Let L be a VR-equational set of (labelled) graphs. The following conditions are equivalent:

(1) L is HR-equational,

(2) L has bounded tree-width,

(3) L is uniformly p-sparse for some p ∈ N , (4) L is p-sparse for some p ∈ N , (5) there exists n ∈ N such that every graph in L is without K n,n .

Proof: We have the following implications:

(1) =⇒ (2) by Proposition 4.7.

(2) =⇒ (3): The set of subgraphs of graphs in L has bounded tree-width by Corollary 2.60 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. Every simple loop-free undirected graph G of tree-width at most k is k-sparse by Corollary 2.74(1) (for

|V G | ≥ k + 1; if |V G | ≤ k, then |E G | ≤ |V G | • (|V G | -1)/2 < k • |V G |).
Hence, a simple directed graph with edge labels from a set of at most labels (and possibly labelled loops), is (2k + 1) •sparse.

(3) =⇒ ( 1) follows from the Equationality Theorems for the VR and the HR algebra proved in Sections 7.2 and 7.4, and the Sparseness Theorem for graphs in Section 9.4.1. See Section 9.4.3 for the proof.

(3) =⇒ ( 4) is immediate.

(5) =⇒ (2) follows from Proposition 4.44, because for G with edge labels from a set of at most labels and without K n,n , we have twd (G) ≤ 3(n -1) • • cwd (G) -1 by Proposition 2.115.

(4) =⇒ ( 5): The proof is based on the following claim. Proof: Let L be a VR-equational set of graphs. We write the proof for unlabelled directed graphs, but it is essentially the same for labelled and/or undirected graphs. By Proposition 4.41, L = val (K) for some regular language K ⊆ T (F (S)) where S is a VR equation system and F (S) ⊆ F VR A(S) . We let A = A (B, C) be a complete deterministic finite F (S)-automaton recognizing K (cf. Definition 3.58 and Theorem 3.62).

For a context c ∈ Ctxt(F (S)) we define c ∅ to be the context obtained from c by changing all constant symbols in c into ∅. By Equalities (3), ( 6) and (11) of Proposition 2.101 and by (the last sentence of) Proposition 2.103, every derived operation (c ∅ ) GP is of the form G → relab h (ADD R (G)), and hence there are

k k • 2 k 2 -k such operations, where k = |A(S)| (cf. Lemma 2.120). We define two contexts c, c ∈ Ctxt(F (S)) to be equivalent if c B = c B and (c ∅ ) GP = (c ∅ ) GP .

This equivalence relation has at most

A A • k k • 2 k 2 -k classes.
For every context c, we let c be a context equivalent to c with a minimal number of leaves. Moreover, we let b be the maximal number of leaves of all contexts c. Finally, we define the required constant d as 2b + 1. Note that d depends on A(S) and A only.

Let G ∈ L. Without loss of generality, we assume that G = cval (t) for some t ∈ K. Its vertex set is thus Occ 0 (t) (see Section 2.5.2 for the definitions of cval (t) and Occ 0 (t)). Let H = G[X] where X ⊆ Occ 0 (t), and let n := |V H | = |X|. Our aim is to transform t into a term t ∈ K such that H is isomorphic to an induced subgraph of val ( t ) and t has at most d • n leaves.

Consider nodes u and v of t such that u is strictly below v, and such that for every x ∈ X, either x is below u (we may have x = u) or the least common ancestor of u and x is strictly above v. We will say that (u, v) is an X-free pair of nodes. Let c be the context such that t = (t ↑ v)[c[t/u]]. Informally, c is the part of the term t "between" u and v, and none of its leaves is in X. We denote c by c [u,v] if we need to indicate u and v.

Suppose that c is a context equivalent to c, and that t is obtained from t by changing c into c , i.e., t :

= (t ↑ v)[c [t/u]]. Since c B = c B ,
the term t is accepted by A .24 Hence t ∈ K and val (t ) ∈ L. By the proof of Proposition 2.105( 1), H = cval (t)[X] = cval (t X ) where the term t X is obtained from t by changing the label of every leaf of t that is not in X into ∅. Since, by assumption, the leaves of c are not in X and (c ∅ ) GP = (c ∅ ) GP , this implies that H is isomorphic to an induced subgraph of val (t ). (To be precise, we have that t

X = (t X ↑ v)[c ∅ [t X /u]] because the leaves of c are not in X. Let s := (t X ↑ v)[c ∅ [t X /u]]. Then val (t X ) = val (s) because (c ∅ ) GP = (c ∅ ) GP . Let X := Occ 0 (s). Then s = t X (
which is defined in the same way as t X ). Again by the proof of Proposition 2.105 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF], cval (t )[X ] = cval (t X ) and so cval (s) is an induced subgraph of cval (t ). Hence H = val (t X ) = val (s) is isomorphic to an induced subgraph of val (t ).)

In particular, if the number of leaves of c is larger than b, then we can change c into c which has at most b leaves. Since the resulting term has less leaves than t, repetition of this transformation (as long as possible) leads to a term t ∈ K such that H is isomorphic to a subgraph of val ( t ) ∈ L and the number of leaves of c [u,v] is at most b for every X-free pair (u, v) of nodes of t, where X is any subset of Occ 0 ( t ) such that H is isomorphic to cval ( t ) [X].

We let Y be the set of nodes of t consisting of X and the least common ancestors of any two leaves in X. Then, we consider the pairs (u, v) such that u ∈ Y and v is a maximal proper ancestor of u not in Y (thus, no node of Y is on the path from v to the father of u). There are at most |Y | = 2n -1 such pairs. Each of them is X-free and so the number of leaves of c [u,v] is at most b. Hence t has at most n + (2n -1)b < (2b + 1)n = dn leaves.

Thus, if G := cval ( t ), then G ∈ L, H is isomorphic to an induced subgraph of G, and

|V G | = |Occ 0 ( t )| ≤ d • |V H |. (We do not claim that G is isomorphic to an induced subgraph of G.) This claim implies that if a graph G of L has a subgraph isomorphic to K n,n , then there exists G ∈ L such that |V G | ≤ 2dn and |E G | ≥ n 2 .
Hence, if there is such a graph for every n, then L is not p-sparse for any p, and (4) implies (5).

The Semi-Linearity Theorem of Chapter 7 (Theorem 7.42) implies that Condition (5) is decidable. So one can decide if a VR-equational set of graphs is HR-equational.

The class of graphs of degree at most 2p is p-sparse. The class of simple graphs embeddable in the plane or in a fixed surface is p-sparse for some p (with p = 3 for loop-free planar graphs, see [*Die], Corollary 4.2.10). The same holds more generally for the class of graphs that do not contain a fixed graph as a minor. We will prove in Section 9.4.3 that if a set of graphs of bounded clique-width is uniformly p-sparse for some p, then it has bounded tree-width. In Theorem 4.51 we need only assume that L is p-sparse for some p in order to obtain, not only that it has bounded tree-width but, furthermore, that it is HR-equational.

VR-recognizable sets of graphs

The VR-recognizable sets of graphs are defined as the recognizable sets of the many-sorted algebra GP t . The following definition is similar to Definition 4.29 for HR-recognizable sets.

Definitions and examples

Definition 4.52 (VR-recognizable sets of p-graphs) A set of p-graphs is VR-recognizable if it is recognizable in the many-sorted algebra GP t , i.e., if it is a union of classes, possibly of different sorts, of a typepreserving and locally finite congruence on the one-sorted F VR -algebra GP. The sort of a p-graph G relative to GP t is its type π(G), defined as the set of its port labels.

For (K, Λ)-labelled p-graphs, the definitions are the same with

F VR [K,Λ] instead of F VR and GP t [K,Λ] instead of GP t . If L ⊆ GP[E]
for some finite set E of port labels, that is, such that all pgraphs in L have a type included in E, then its recognizability can be considered with respect to GP t or to GP t [E]. If L is VR-recognizable, then it is also recognizable in GP t [E] by Proposition 3.56 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. If furthermore L ⊆ GP gen [E], then it is also recognizable in GP t,gen [E] by the same proposition.

It is straightforward to show, as in Definition 4.29, that the algebras GP t,gen [E] and GP gen [E] have the same (effectively) recognizable sets.

The VR-recognizability index of a set of p-graphs L is the mapping γ L such that γ L (k), for k ∈ N , is the number of equivalence classes of type C of the syntactic congruence ≈ L of L with respect to GP t , where C is any set of port labels of cardinality k. By using bijective relabellings (like in Definition 4.33), we can prove that this number is well defined.

Many results are similar to the corresponding ones for HR-recognizable sets. In particular, the instantiation to the VR algebra of the algebraic version of the Filtering Theorem:

Theorem 4.53 The intersection L ∩ K of a VR-equational set L and a VRrecognizable set K is VR-equational. If K is semi-effectively VR-recognizable and L is given by a VR equation system, then an equation system defining L∩K can be constructed.

Its proof is fully similar to that of Theorem 4.37 relative to the HR algebra (using Proposition 4.46 instead of Proposition 4.13).

We now give some examples of VR-recognizable sets and we define congruences witnessing their recognizability. (2) Graphs with an even number of edges. We now prove that the set L e of simple graphs having an even number of directed edges is VR-recognizable. The construction of a type-preserving congruence that saturates L e is slightly more complicated than in the previous example. For distinct port labels a and b and a p-graph G, we let edg G (a, b) be the set of edges from an a-port to a b-port. (We recall that port G is the port mapping of G, from vertices to port labels). We define a type-preserving equivalence relation ≡ by: G ≡ H if and only if G and H have the same type and: This equivalence is locally finite and it saturates L e . The verification that it is a congruence uses observations similar to those used in Example 4.30 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. Here are some others, involving |edg G (a, b)| and |port -1

H (a)|. If H = --→ add a,b (G) then |edg H | = |edg G |+|port -1 G (a)|•|port -1 G (b)|-|edg G (
| = |port -1 G (a)| • |port -1 G (b)| and |edg H (c, d)| = |edg G (c, d)| for (c, d) = (a, b). If H = relab h (G), then |edg H (a, b)| is the sum of all |edg H (c, d)| such that h(c) = a and h(d) = b.
The set L e is thus VR-recognizable. This fact follows also from the Recognizability Theorem (Section 5.3.9, Theorem 5.68) because a graph has an even number of directed edges if and only if the number of its vertices having an odd indegree is even. This property is thus C 2 MS-expressible. (For a generalization of this observation, see [START_REF] Courcelle | On the model-checking of monadic second-order formulas with edge set quantifications[END_REF]).

(3) Planar graphs and other MS-definable sets. The sets of simple planar graphs, of cographs, of trees, of rooted trees are VR-recognizable: this follows from the Recognizability Theorem to be proved in the next chapter. In fact, for simple graphs, the sets ( 1)-( 8) of Proposition 4.31 are all (effectively) VR-recognizable.

(4) Connected graphs. It is not difficult to define a congruence that witnesses the VR-recognizability of the set of connected simple graphs and that has a bit less than 2 2 k classes of type C, where C is a set of k port labels. We will prove that no such congruence can have less than 2 2 k classes of type C if C has 2k + 1 elements. This gives a lower-bound to the VR-recognizability index of the set of connected graphs. Our proof only uses undirected graphs, but the lower-bound applies a fortiori to all (simple) graphs.

We let C := [0, 2k] for k > 0. For every nonempty subset A of C we define:

t A := ( a,b∈A,a =b add a,b )( a∈A a).
The p-graph val (t A ) is a clique of type A and each a in A is the port label of a unique vertex.

Let Z be a nonempty subset of P k ([2k]), defined as the set of subsets of [2k] of cardinality k. We let Z be the union of the sets in Z and we define:

s Z := t C-Z ⊕ A∈Z t A .
The p-graph H Z := val (s Z ) has type C and is not connected (0 belongs to no set in Z and Z is not empty).

We now define some contexts intended to show that distinct p-graphs H Z and H Z are not equivalent for any congruence ∼ that witnesses the VRrecognizability of the set of connected p-graphs. For every nonempty subset B of [2k], we define:

c B := ( b∈B add 0,b )(w)
where w is the special variable used to define contexts. It is clear that

val (c B [s Z ]) is connected if and only if B ∩ A = ∅ for every A ∈ Z.
We let Z be the set of all nonempty subsets of P k ([2k]). It is thus the set of all sets Z as defined above. We have

|P k ([2k])| > 2 k hence |Z| > 2 2 k , by routine computations.
Let us now consider two distinct elements Z and Z of Z. We first assume that some set A belongs to Z -Z and we let

B := [2k] -A. Then val (c B [s Z ]) is not connected because B ∩ A = ∅. On the other hand, val (c B [s Z ]) is connected because B ∩ A = ∅ for every A ∈ Z .
In fact, since all sets in Z and Z have cardinality k, each set A in Z must contain an element not in A (otherwise A ⊆ A so that A = A, but we have assumed that A / ∈ Z ). For a set A ∈ Z -Z we get a similar fact by exchanging the roles of Z and Z .

It follows that the p-graphs H Z for Z ∈ Z are all of type C and are pairwise inequivalent with respect to any congruence that witnesses the VRrecognizability of the set of connected p-graphs.

What about the set of connected graphs without ports, equivalently of type {0}? By replacing c B by ( b∈[2k] relab b→0 )(c B ), we get the same result for the VR-recognizability of connected graphs. Hence, in both cases we have γ L (2k + 1) > 2 2 k for every k > 0.

Hence, we have a double-exponential lower-bound for the VR-recognizability index of the set of connected graphs. In Example 4.30(2), we have given the much lower upper-bound k! + 1 for the HR-recognizability index of the same set (allowing multiple edges, but they do not matter).

(5) Sets that are not VR-recognizable. The set of graphs K n,n for all n > 0 is not VR-recognizable. The proof uses the same tools as those of Proposition 4.32: we let the constant symbols a and b denote 1, the unary operation g denote λx • (x ⊕ 1) and f denote the complete join ⊗. Note that this set is HR-recognizable (Proposition 4.36). Note also that this set is VRequational, with equation system

x = relab 2→1 (add 1,2 (y)) y = (1 ⊕ 2) ∪ (y ⊕ y),
but not HR-equational (Proposition 4.7).

By a proof similar to that of Example 4.30(3), one can prove that each singleton set consisting of a p-graph (and hence each finite set of p-graphs) is effectively VR-recognizable.

Remark 4.55 (On variants of the VR operations)

We observed at the end of Section 4.3.1 that the variants of the signature F VR defined in Section 2.5.6 yield the same classes of equational sets. They also yield the same classes of recognizable sets. For the signatures F κVR and F VR it is proved in the same way as at the end of Section 4.3.1, using Theorem 3.56(3). For the signature F iVR , this follows from a result of [CouWei] (Theorem 4.5) saying that if we add to the signature F tVR unary operations on p-graphs defined by quantifier-free formulas (we will define these operations in Section 5.3.2), then the class of recognizable sets of the obtained algebra is still the class of VRrecognizable sets. This result applies to F iVR , and to its many-sorted version.

A simpler VR-recognizability criterium

We will give a characterization of VR-recognizability analogous to that of HRrecognizability of Theorem 4.34 that extends the characterization of the regular languages due to Myhill and Nerode. We define an operation on p-graphs similar to the operation P k on s-graphs, but not commutative. This operation is derived from Proposition 2.103 that characterizes the operations on p-graphs defined by contexts.

Definition 4.56 (Some binary derived operations) Let (A 1 , A 1 ), (A 2 , A 2 ), . . . be an enumeration of the set P f (N ) × P f (N ) such that for every k ∈ N the sequence (A 1 , A 1 ), . . . , (A 2 2k , A 2 2k ) is an enumeration of P([k]) × P ([k]). If G and H are p-graphs of types respectively included in [k] and in [k + 1, k + 2 2k ], we define:

G k H := relab 1 (ADD R k (G ⊕ H))
where relab 1 is the relabelling that transforms every port label in [k + 2 2k ] into the default port label 1,

R k := {(k + j, i) | j ∈ [2 2k ], i ∈ A j } ∪ {(i, k + j} | j ∈ [2 2k ], i ∈ A j }
and ADD R is defined before Proposition 2.103. The asymmetric symbol k represents the fact that the right argument can have more port labels than the left one. Here is the reason. If a context takes a p-graph G such that π(G) ⊆ [k] as argument, then it may add new vertices to G, and edges between such a new vertex x and those of G. For each such x, these edges depend only on the port labels of the vertices of G. Hence, the edge additions defined by the considered context can be specified by a pair (A, A ) of subsets of [k] attached to each such vertex x (as shown in the proof of Proposition 2.103). Instead of using pairs of subsets of [k] as port labels, we use integers in [k + 1, k + 2 2k ]. Informally, in an expression G k H, the argument H represents a context taking G as argument. This explains the asymmetry of the operation k . (The symmetry of P k is thus a particular property of the HR algebra).

Our aim is to get a criterium for VR-recognizability similar to the one of Theorem 4.34 for HR-recognizability. We define, for a set L of simple graphs and k ∈ N , an equivalence relation on p-graphs of type [k] as follows:

G ∼ L,k G if and only if for every p-graph H of type included in [k + 1, k + 2 2k ], we have:

G k H ∈ L ⇐⇒ G k H ∈ L.
Theorem 4.57 A set L of simple graphs is VR-recognizable if and only if the equivalences ∼ L,k are finite for all k.

Proof: For convenience we write ∼ k instead of ∼ L,k . The equivalences ∼ k are defined as the syntactic congruence ≈ L , but in terms of particular contexts. Hence, for every two p-graphs G and

G of type [k], G ≈ L G implies G ∼ k G . Hence, if L is VR-recognizable, the equivalences ∼ k are all finite.
For proving the converse, we first define ∼ k as the equivalence relation on graphs of type [k] such that:

G ∼ k G if and only if ADD R1 (G) ∼ k ADD R1 (G ) for every R 1 ⊆ [k] × [k]. Then ∼ k is finite if ∼ k is finite. It has at most p • 2 k 2 classes if ∼ k has p classes.
Let L be a set of simple graphs such that the equivalences ∼ k , whence also the equivalences ∼ k are finite. Let B be a finite set of k port labels and c be a context in Ctxt(F VR

:= h B ∪ h C (i.e., R := {(h(a 1 ), h(a 2 )) | (a 1 , a 2 ) ∈ S}), and R 1 := R ∩ ([k] × [k]
). Then we have for every p-graph G of type B:

c(G) = (ADD R1 (relab h B (G))) k relab h C (H).
Let G and G be p-graphs of type B, with B of cardinality k, such that relab h B (G) ∼ k relab h B (G ), and c be a context expressed as above in terms of

R, R 1 , h B and h C . Then ADD R1 (relab h B (G)) ∼ k ADD R1 (relab h B (G )). It follows that c(G) ∈ L implies c(G ) ∈ L. This is true for all contexts, so we get G ≈ L G . Hence G ≈ L G if π(G) = π(G ) and relab h π(G) (G) ∼ k relab h π(G) (G ), where k = |π(G)|.
This implies that the number of equivalence classes of ≈ L of sort B is not larger than the number of equivalence classes of ∼ k , hence is finite. Hence, L is VR-recognizable.

The extension to labelled graphs is easy. It uses the expression of context of Proposition 2.103 with one relation R for each edge label.

Comparison with the HR-recognizable sets

We now compare the HR-recognizable sets of simple graphs and the VR-recognizable sets, as we did in Section 4.3.4 for the corresponding notions of equational sets. The proof of this theorem uses notions and notation introduced in Definition 4.50.

Theorem 4.58 Every VR-recognizable set L of (labelled) graphs is HR-recognizable. Moreover, if L is effectively VR-recognizable then it is effectively HRrecognizable, and similarly for semi-effective recognizability.

Proof: We first prove the first statement, using congruences. We let L be a VRrecognizable set of (unlabelled) graphs and ∼ be a type-preserving and locally finite congruence on the algebra GP that saturates L. We define as follows a binary relation ≈ on s-graphs: In this definition, β and Int are the border and the interior functions of Definition 4.50. It is clear that ≈ is a type-preserving and locally finite equivalence relation on JS. We first prove that it saturates L. Let G and H be such that

G ≈ H if and only if τ (G) = τ (H)
G ≈ H and G ∈ L. Since G is a graph, we get G = Int(G) ∼ Int(H) = H. Hence H ∈ L, because ∼ saturates L.
It remains to prove that ≈ is a congruence for the operations of F HR . Let G, G , H, H ∈ J S with G ≈ G and H ≈ H .

(1) If G is not simple, the same holds for G and for G H and G H .

Hence G H ≈ G H because τ (G H) = τ (G H ). The proof is similar if any of G , H or H is not simple.
(2) If G, G , H, H are all simple and G H is not simple, then β(G) β(H) is not simple. But the same holds for β(G ) β(H ), hence G H is not simple and G H ≈ G H .

(3) We now assume that G, G , H, H , G H, G H are all simple. We have, by using (4.5) of Definition 4.50:

β(G H) = β(G) β(H) = β(G ) β(H ) = β(G H ) since β(G) = β(G ) and β(H) = β(H ).
We also have:

Int(G H) = Int(G) ⊕ Int(H) ∼ Int(G ) ⊕ Int(H ) = Int(G H ) since Int(G) ∼ Int(G ), Int(H) ∼ Int(H ) and ∼ is a congruence. Hence G H ≈ G H .
The proofs that G ≈ G implies ren h (G) ≈ ren h (G ) and fg B (G) ≈ fg B (G ) are fully similar, by using (4.6) and (4.7) of Definition 4.50 respectively. Hence L is HR-recognizable.

To prove the second statement (including another proof of the first statement), let L = h -1 VR (C) where h VR is a homomorphism from GP t to a locally finite F tVR -algebra A and C ⊆ A. We have to define a locally finite F tHR -algebra B, a homomorphism h HR from JS t to B, and C ⊆ B, such that L = h -1 HR (C ). We define B := B 1 ∪ B 2 where B 1 := {⊥ D | D ∈ P f (A)} and B 2 is the set of all pairs (β, a) such that β is a simple s-graph with Int β = ∅ and a ∈ A has a sort included in P(τ (β)) × P(τ (β)). The sort of ⊥ D is D and the sort of (β, a) is τ (β). Furthermore, we define h

HR (G) = (β(G), h VR (Int(G))) if G is simple, and h HR (G) = ⊥ τ (G) otherwise. Finally, C := {(∅, a) | a ∈ C}. Since L consists of simple graphs, L = h -1 HR (C ).
It is straightforward to show, using (4.5), (4.6) and (4.7) of Definition 4.50 (together with the fact that h VR is a homomorphism), that B can be turned into a F tHR -algebra B such that h HR is a homomorphism from JS t to B. We leave the details to the reader 25 . By definition of B, the algebra B is locally finite. Assume now that A is (semi-)effectively given. Since B 2 is a decidable subset of J S × A, the set B can be encoded by a standard encoding such that B is (semi-)effectively given; again, we omit the details. If C is a decidable subset of A, then C is a decidable subset of B, and if h VR is computable, then so is h HR .

The extension of this proof to labelled graphs is straightforward (cf. the end of the proof of Theorem 4.49).

The following result, proved in [CouWei] (Theorem 6.2 and Proposition 6.4), is strikingly similar to Theorem 4.51.

Theorem 4.59 Let L be an HR-recognizable set of simple graphs. Each of the following conditions implies that L is VR-recognizable:

(1) L has bounded tree-width,

(2) L is uniformly p-sparse for some p ∈ N ,

(3) there exists n ∈ N such that every graph in L is without K n,n .

HR-and VR-, equational and recognizable sets

For sets of simple graphs, we have the implications of HR-equational sets of graphs is incomparable with that of HR-recognizable sets, and the same holds for VR-equational and VR-recognizable sets. To be precise, the set L 1 of Proposition 4.32 is HR-equational but not HR-recognizable, and the set of planar graphs is VR-recognizable but not VR-equational. However, for sets of simple graphs of bounded tree-width (these sets are without some K n,n ), we have the equivalences and the implication (without converse) shown in Table 4.2.26 It is similar to the proper inclusion of the family of regular languages (of words) in that of context-free languages.

Monadic second-order definable sets of graphs and monadic second-order transductions, to be studied in Chapters 5 and 7, will enrich the landscape.

The family of HR-equational sets of graphs has been first defined in terms of graph rewritings based on hyperedge replacement in [BauCou] and in [*Hab].

The analogous definition of VR-equational sets is more complicated because the context-freeness of a given vertex replacement rewriting system is not immediately visible from the syntax and has to be checked by an algorithm. We refer the reader to [*EngRoz]. The article [START_REF] Courcelle | An axiomatic definition of context-free rewriting and its application to NLC graph grammars[END_REF] defines an abstract (axiomatic) notion of context-free graph grammar, that is applied to certain grammars defined by vertex replacement.

The finiteness problem for HR-equational sets can be solved (see [*DreKH] or [*Hab]) by means of a pumping lemma that generalizes the pumping lemma for context-free languages (cf. Proposition 3.53). We use instead the Semi-Linearity Theorem (known as Parikh's Theorem) for context-free languages (Proposition 3.25), that we will further generalize in Chapter 7 (Theorem 7.42).

Theorem 4.49 is proved in essentially the same way in [*Eng94] (the proof is rather formulated in terms of transductions).

The implication (4) =⇒ (1) of Theorem 4.51 has first been proved in [START_REF] Courcelle | Structural properties of context-free sets of graphs generated by vertex replacement[END_REF] for directed edge-labelled graphs (in a more complicated way).

The notion of an HR-recognizable set of graphs is based on a particular algebra, the algebra JS and its many-sorted version. Similar or related algebraic structures on finite graphs can be defined. In many cases, they yield the same notion of a recognizable set of graphs (cf. Theorem 4. 34 and Remark 4.55). Other results of this kind are proved in [START_REF] Courcelle | Recognizable sets of graphs: equivalent definitions and closure properties[END_REF][START_REF] Courcelle | Equivalent definitions of recognizability for sets of graphs of bounded tree-width[END_REF][START_REF] Courcelle | Fusion in relational structures and the verification of monadic second-order properties[END_REF] and [CouWei]. The article [START_REF] Blumensath | Recognizability, hypergraph operations, and logical types[END_REF] defines as equivalent two signatures of graph operations that act on the same graphs and yield the same classes of equational and recognizable sets. It studies variants of F HR and F VR that are equivalent to them.

Certain HR equation systems have a unique solution in the algebra JS. Such systems are used in [CouSén] in order to establish that if an HR-equational set of graphs is minor-closed, then one can compute its finite set of excluded minors from an HR equation system defining this set. The opposite construction will be presented in Chapter 5 (Application 5.72). Both of them use monadic secondorder logic.

Directed cographs are investigated in [CrePau]. This article characterizes them by eight excluded induced subgraphs.

Chapter 5

Monadic second-order logic

This chapter defines monadic second-order logic, and shows how it can be used to formalize the expression of graph properties. Monadic second-order formulas can also be used to express properties of sets of vertices and/or edges in graphs. The Recognizability Theorem (Section 5.3.8) implies that a class of graphs characterized as the class of (finite) models of a monadic second-order sentence is VR-recognizable, and that it is HR-recognizable (but not necessarily VR-recognizable) if the sentence is written with edge set quantifications.

It follows that the monadic second-order satisfiability problem for the class of graphs of tree-width or of clique-width at most k is decidable for each k. Applications to the construction of fixed-parameter tractable algorithms and other algorithmic consequences will be developed in Chapter 6.

Although our first applications concern graphs, we will give the definitions and prove the main results for the general case of relational structures because proofs are not more difficult and the corresponding results apply in a uniform manner to labelled graphs represented, in several ways, by binary relational structures. However, relational structures with n-ary relations for n ≥ 2 are actually interesting by themselves. As we have shown in Section 1.9, they are useful to formalize betweenness and cyclic ordering (and for relational databases).

In Sections 5. 1 and 5.2, we review basic notions of logic, we define monadic second-order logic, and we give some results that delineate its expressive power. In Section 5.3, we establish the Recognizability Theorem and in Section 5.4 we develop its consequences regarding the decidability of monadic second-order satisfiability problems. In Section 5.5, we present logical characterizations of (certain) recognizable sets of trees. In Section 5.6, we give upper-bounds to the number of inequivalent formulas of bounded quantifier-height.

Relational structures and logical languages

We will not discuss in detail syntactic questions like renamings of bound variables. We will rather give examples and rest on the intended meanings of formulas. Our review of definitions will fix notation.

Relational structures

Definition 5.1 (Relational signatures and structures) We will use logical structures with relations of positive arity and constants, specified by relation symbols and nullary function symbols respectively. Constants will be useful for representing the sources of s-graphs. We will not use functions of positive arity.

A relational signature is a finite set R of symbols such that each symbol R ∈ R has an associated natural number called its arity, denoted by ρ(R). We let R 0 be the set of those of arity 0 and we call them constant symbols. We let R i be the set of symbols of arity i ≥ 1 and we call them relation symbols. We let A substructure of a concrete R-structure S = D S , (R S ) R∈R+ , (c S ) c∈R0 is a concrete R-structure of the form S[X] for some X ⊆ D S containing all constants of S and defined as follows:

R + := {R i | i ≥ 1} and ρ(R) be the maximal arity of a symbol in R. A relational signature R is binary if ρ(R) ≤ 2. A concrete R-structure is a tuple S = D S , (R S ) R∈R+ , (c S ) c∈R0 such that D S is
D S[X] = X, c S[X] = c S for all c ∈ R 0 , R S[X] = R S ∩ X ρ(R) for all R ∈ R + .
We say that S[X] is the substructure of S induced by X.

Let S, S be concrete R-structures. An isomorphism from S to S is a bijection h : D S → D S such that h(c S ) = c S for every c ∈ R 0 and, for every

R in R + and every d 1 , . . . , d ρ(R) in D S , we have (h(d 1 ), . . . , h(d ρ(R) )) ∈ R S if and only if (d 1 , . . . , d ρ(R) ) ∈ R S .
We denote by S S the existence of an isomorphism from S to S and we say that S and S are isomorphic. As for graphs (cf. Chapter 2) we define an abstract R-structure as the isomorphism class [S] iso of a concrete R-structure S. We denote by STR c (R) the set of concrete R-structures and by STR(R) the set of abstract ones. By a class of structures, we mean a set of concrete structures closed under isomorphism. It defines a set of abstract structures.

We will use relational structures to represent finite combinatorial objects like words, terms and graphs of various types. By a representation, we mean a mapping from a set of objects to a set of concrete or abstract structures. Isomorphic objects (in particular graphs) must be mapped to isomorphic structures. A representation is faithful if the converse also holds: two objects are isomorphic (hence, equal in the cases of terms and words) if and only if their representing structures are isomorphic.

We now define several representations to be used in all further chapters.

Examples 5.2 (Words, graphs and terms as relational structures)

(1) We first consider words over a finite alphabet A. We let W A := {suc} ∪ {lab a | a ∈ A} be the relational signature such that ρ(suc) = 2 and ρ(lab a ) = 1 for every a in A. For every word w over A, we let w be the concrete W Astructure2 such that:

D w := [n] if w has length n, suc w := {(1, 2), (2, 3), . . . , (n -1, n)}, i ∈ lab a w if and only if w[i] = a.
Hence the elements of D w are the positions of the word w and suc w (x, y) holds if and only if y is the successor of x in w. If u is the factor (also called subword) of a word w starting at position i and ending at position j, then u is isomorphic to the substructure of w induced by the interval [i, j], which is a subset of D w .

The empty word ε is thus represented by the empty structure. This may be inconvenient in certain situations. We can also let ε be the structure with a singleton domain and empty relations suc and lab a . We will specify in each case if a variant of the initially given definition is used. The same properties of words can be expressed by first-order or by monadic second-order sentences via both representations.

More generally, we say that two representations are equivalent if the same properties of the represented objects can be expressed by sentences of the logical language of interest3 , monadic second-order logic in most cases.

Yet another representation of words is possible. Let W A be obtained from W A by replacing suc by ≤, intended to denote the linear order of positions in a word w. We let w be the concrete W A -structure with domain [n] where n = |w| and such that lab a w := lab a w for each a ∈ A and ≤ w is the natural order on [n]. The two representations of words w and w are equivalent for monadic second-order logic, but not for first-order logic (a classical fact, see [*Tho97a]). Less properties of words can be expressed by first-order sentences through w than through w .

All representations we have defined above are faithful: different words are represented by non-isomorphic structures.

For L ⊆ A * , we denote by L the class of concrete structures that are isomorphic to w for some w ∈ L (and similarly for L ).

(2) We now explain how graphs can be represented by relational structures, in such a way that simple graphs are faithfully represented. We let R s := {edg} with edg binary. With a concrete directed graph G, we associate the concrete R s -structure G := V G , edg G where the domain4 of G is the vertex set V G of G, and (x, y) ∈ edg G if and only if there is an edge from x to y. We do the same if G is undirected and we let (x, y) ∈ edg G if and only if there is an edge linking x and y: it follows that edg G is in this case symmetric. Every concrete R s -structure represents a graph and every concrete R s -structure S with symmetric relation edg S represents an undirected graph. The structures representing isomorphic graphs are isomorphic. If a graph G is defined as an abstract graph, then we let G also denote the corresponding abstract structure. In the sequel, we will distinguish between concrete and abstract structures representing graphs only when necessary.

The structure G does not contain information concerning the multiplicity of edges. It is faithful for simple graphs5 , but it is not for all graphs. We will define in Section 5.2.5 a faithful representation of all graphs. However, for expressing logically graph properties like connectivity that do not depend on the multiplicity of edges, the structure G is sufficient (cf. Section 1.3.1).

For directed graphs, we will sometimes use suc instead of edg. We will call y a successor of x, and x a predecessor of y if (x, y) ∈ suc G . For rooted forests we will use son instead of edg, cf. Definition 2.13.

For representing a p-graph G of type6 π(G) ⊆ C, where C is a finite subset of A, we will use the signature R s,C := {edg} ∪ {lab a | a ∈ C}, with lab a unary for every a, and the concrete R s,C -structure

G C := V G , edg G , (
. If G = V G , edg G , src G , we let G be V G , edg G , (a G ) a∈C with a G := src G (a)
for each a in C. (These representations are equivalent for both first-order logic and monadic second-order logic.) For this variant, a structure S in STR(R ss,C ) is of the form G for some s-graph G of type C if and only if it is constant-separated. A substructure of the R ss,C -structure G representing an s-graph G is thus G[X] for a set of vertices X containing all sources; hence it represents an induced subgraph of G (cf. Definition 2.12) having the same sources as G. Note that R ss,C cannot be used for s-graphs of type properly included in C, because every constant symbol in C must have an interpretation.

These representations can be adapted so as to represent (K, Λ)-labelled graphs, p-graphs and s-graphs (faithfully if they are simple). We recall from Definition 2.11 that K is the set of vertex labels, Λ is the set of edge labels and that (K ∪Λ)∩A = ∅. We use unary relations lab κG for κ ∈ K in the obvious way to represent the vertex labels of a graph G. For each λ ∈ Λ, we use a binary relation edg λG consisting of all pairs (x, y) such that there is in G an edge labelled by λ from x to y (or between x and y if G is undirected). Hence, a labelled p-graph G of type C is faithfully represented by G := V G , (edg λG ) λ∈Λ , (lab aG ) a∈K∪C . The corresponding relational signatures are denoted by R s,[K,Λ] , R s,C,[K,Λ] and R ss,C, [K,Λ] . (This notation emphasizes the role of C in contrast to that of K.)

We recall from Definition 2.11 that binary R-structures without constants correspond bijectively to simple directed (R 1 , R 2 )-labelled graphs. 8 We will frequently identify such a graph G with the relational structure G that represents it faithfully.

The representation w of a word w ∈ A * , as initially defined in ( 1), can alternatively be described as

G(w) where G(w) is the directed (A, ∅)-labelled path with V G(w) = [|w|], edg G(w) = {(i, i + 1) | i ∈ [|w| -1]} and vertex i has label w[i].
If L is a set of (labelled) concrete or abstract graphs, we denote by L the set of concrete or abstract structures G for G ∈ L. If L is a set of (labelled) p-graphs or s-graphs of type included in C, for some finite C ⊆ A, we denote by L C the set of structures G C for G ∈ L. Moreover, if C is the smallest such set, i.e., if C is the union of all (finitely many) types of the elements of L, then we also denote L C by L . Note that L is not equal to { G | G ∈ L}, except when L is homogenous. Note also that L is defined only when L has bounded type, i.e., L ⊆ GP[C] or L ⊆ J S[C] for some finite C ⊆ A; this suffices for our purposes, because all VR-equational and HR-equational sets have bounded type (with C = A(S) for some VR or HR equation system S).

(3) We now define faithful representations of terms by relational structures. For every finite functional signature F , we let R F be the relational signature R s, [F,[ρ(F )]] (with edg changed into son), i.e.,

R F = {son i | 1 ≤ i ≤ k} ∪ {lab f | f ∈ F }
where k = ρ(F ), son i is binary and lab f is unary. Recall from Definition 2.14 that the syntactic tree Syn(t) of a term t over F is an (F, [ρ(F )])-labelled rooted tree. With t ∈ T (F ) we associate the concrete R F -structure t := Syn(t) . So,

t = N t , (son i t ) 1≤i≤k , (lab f t ) f ∈F
where the domain of t is the set N t of nodes of Syn(t) (which is the set Pos(t) of positions of t, cf. Definitions 2.3 and 2.14), (u, v) ∈ son i t if and only if v is the i-th son of u (we use the terminology of trees), and lab f t = Occ(t, f ). This is obviously a faithful representation: as discussed after Definition 2.14 the mapping t → [Syn(t)] iso is injective.

For some proofs it is important (or convenient) to add the constant symbol rt to R F which, in every structure t , is interpreted as the root of Syn(t), i.e., t = N t , (son i t ) 1≤i≤k , (lab f t ) f ∈F , rt t with rt t := root t (the first position of t). In this way we obtain an equivalent representation, because the root of t is the unique element v of N t that does not satisfy son i t (u, v) for any i ∈ [k] and u ∈ N t . This representation corresponds to viewing the syntactic tree of t as a labelled s-graph with one source (its root). As for s-graphs, rt can also be taken as a unary symbol such that rt t (u) holds if and only if u is the root of t.

Here is a variant, equivalent to the above defined representation (with or without rt): instead of k binary "son" relations, we use one binary relation son and k unary "brother" relations br i defined, for each i = 1, . . . , k, by br i t (v) :⇐⇒ ∃u. son i t (u, v).9 This obviously corresponds to a variant of Syn(t) with unlabelled edges and (F ∪ [ρ(F )])-labelled nodes, such that each node has one label from F and one label from [ρ(F )].

As for words (where ε can be chosen in different ways) we will use a single notation, here R F and t , for these slightly different relational signatures and structures. We will specify which is used if necessary.

In Definition 2.7, we have defined two bijections µ from A * (for a finite alphabet A) to T (U A ) where U A is a functional signature containing one constant symbol (corresponding to the empty word) and a unary function symbol for each a in A. We deduce from it two other faithful representations of words: w ∈ A * is represented by µ(w) . The empty word is represented by a nonempty structure. These representations are equivalent to the representation w defined in [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] for both first-order and monadic second-order logic.

As for words, if L is a set of terms over F , we denote by L the class of concrete structures that are isomorphic to t for some t ∈ L.

We now relate the representations of the subterms and the contexts of t with t , cf. Definition 2.6. If u is a position of a term t ∈ T (F ), we define t /u to be the R F -structure Syn(t)/u . As discussed after Definition 2.14, Syn(t/u) Syn(t)/u and hence the structure t/u is isomorphic to t /u (which is a substructure of t if we use the signature R F with binary relations son i ). For defining contexts as terms, we use w as special variable. We represent a context t ↑ u by the R F ∪{w} -structure t ↑ u := Syn(t) ↑ u . Since Syn(t ↑ u) Syn(t) ↑ u, the structure t ↑ u is isomorphic to t ↑ u (which is not a substructure of t because u has a different label). In the case where R F and R F ∪{w} contain the constant symbol rt, we define rt t /u := u (which implies that t /u is not any more a substructure of t ) and rt t ↑u := rt t .

(4) We now explain how to represent a graph G and one of its tree-decompositions by a single relational structure. This can be done in several ways.

If (T, f ) is a tree-decomposition of a graph G such that, without loss of generality, N T ∩ V G = ∅, we let S 0 (G, T, f ) be the relational structure V G ∪ N T , edg G , son T , box f that expands G by adding new domain elements (the nodes of T ) and the binary relations son T and box f ; the latter one is the set of pairs (u, x) such that u ∈ N T and x ∈ f (u). By using this relational structure, one can express by logical formulas properties of tree-decompositions, for example that every box is a clique (cf. Definition 2.71 about chordal graphs and their tree-decompositions).

It may be interesting to expand G in a more economical way, by adding only new relations. It easily follows from Proposition 2.67(2) that every nonempty graph has an optimal 1-downwards increasing tree-decomposition (T, f ) such that |f (root T )| = 1. In this case, the mapping x → max(f -1 (x)) is a bijection from V G to N T , cf. Remark 2.55(a). Hence, we can identify V G and N T and simplify S 0 (G, T, f

) into S 1 (G, T, f ) := V G , edg G , son T , box f .
Every normal tree-decomposition (cf. Example 2.56( 6)) satisfies the above properties (it can still be optimal by Corollary 2.73(3)). If (T, f ) is normal, then one can even omit box f and use S 2 (G, T, f ) := V G , edg G , son T because the mapping f can be determined from edg G and son T as follows:

f (u) := {u} ∪ {w | (w, u) ∈ son * T for some (v, w) ∈ edg G ∪ edg -1 G such that (u, v) ∈ son * T },
for every u ∈ N T = V G , hence box f can be expressed by a monadic second-order formula.

If G is k-chordal, one can even define son T for some normal tree T by a monadic second-order formula depending on k (there is one such formula for each k). This means that an optimal tree-decomposition (T, f ) of G represented by S 1 (G, T, f ) can be defined "inside" the structure G . We will prove this fact in Proposition 9.56(2). We will explain in Section 7.6 the consequences of results of this type.

Definition 5.3 (Sizes of structures)

We will only consider finite relational structures over finite signatures. Hence, just as (finite) graphs, structures can be inputs of algorithms. The time and space complexities of such algorithms will be analyzed in terms of the sizes of the input structures. We define first the size of a relational signature R as:

R := 1 + Σ R∈R (1 + ρ(R)).
Since the empty signature must be somehow described, its size is not 0. We now define the size of an R-structure S as:

S := R + |D S | + Σ R∈R+ ρ(R) • |R S |.
The size of the empty structure over the empty signature is also positive. These

G | + |edg G | + |C|) = O(|G| 2 ). For a simple s-graph G of type τ (G) = C represented by the R ss,C -structure G , we have G = Θ(1 + |V G | + |edg G | + |C|) = Θ( G ).
For a term t in T (F ) (where F is finite and ρ(F ) is the maximal arity of its symbols) represented by the R F -structure t , we have t = Θ(|t| + |F | + ρ(F )).

First-order logic

We let V 0 be a countable alphabet of lowercase letters called first-order variables.

Let R be a relational signature10 . A term is either a variable (from V 0 ) or a constant symbol (from R 0 ). The atomic formulas are s = t, R(t 1 , . . . , t ρ(R) ) for R ∈ R + and terms s, t, t 1 , . . . , t ρ(R) , and the Boolean constants True and False. The first-order formulas over R are formed from atomic formulas with the propositional connectives ∧, ∨, ¬, ⇒, ⇔, and quantifications ∃x and ∀x for x ∈ V 0 .

Let X ⊆ V 0 . We will denote by FO(R, X ) the set of first-order formulas over R with free variables in X . In order to specify the free variables that may occur in a formula ϕ, we will write it ϕ(x 1 , . . . , x n ) if ϕ ∈ FO(R, {x 1 , . . . , x n }). (Some variables in {x 1 , . . . , x n } may have no free occurrence in ϕ). If ϕ(x 1 , . . . , x n ) is a first-order formula over R, if S ∈ STR c (R), and if d 1 , . . . , d n ∈ D S , then we write S |= ϕ(d 1 , . . . , d n ) or (S, d 1 , . . . , d n ) |= ϕ to mean that ϕ is true in S if x i is given the value d i for i = 1, . . . , n. If ϕ has no free variables, it is said to be closed, equivalently to be a sentence. It describes a property of S and not of tuples of elements of S. We will denote by sat(S, ϕ, (x 1 , . . . ,

x n )) the set {(d 1 , . . . , d n ) ∈ D n S | S |= ϕ(d 1 , . . . , d n )}.
It is important to specify x 1 , . . . , x n as arguments of sat for two reasons: first to specify the order of the variables, second because the list of variables is not fixed in a unique way by ϕ. If ϕ is edg(x, y), we may need to consider sat( G , edg(x, y), (u, x, y)) or sat( G , edg(x, y), (x, y, z, u)) or sat( G , edg(x, y), (y, x)). If n = 0, then sat(S, ϕ, ()) = ∅ if S |= ¬ϕ, and sat(S, ϕ, ()) = {()} if S |= ϕ, where () denotes the empty tuple. If S |= ϕ, then S satisfies ϕ or is a model of ϕ. 11 We denote by MOD(ϕ) the class of models of ϕ. (It is a class by Lemma 5.4 below). But in many cases, we will also denote by MOD(ϕ) the corresponding set of abstract structures.

Sentences express properties of a structure S whereas formulas express properties of elements of S specified as values of the free variables. For example, the formula ϕ(x) over R s defined as:

∀y 1 , y 2 , y 3 [edg(x, y 1 ) ∧ edg(x, y 2 ) ∧ edg(x, y 3 ) ⇒ (y 1 = y 2 ∨ y 1 = y 3 ∨ y 2 = y 3 )]
expresses 12 that the vertex x of the considered directed graph G has outdegree at most 2. The sentence ∀x. ϕ(x) expresses that G has outdegree at most 2. We now give an example concerning words. We let A = {a, b, c}. A formula θ can be constructed in such a way that, for every word w ∈ A * :

w |= θ if and only if w ∈ ab * c.
Here is θ:

∃x[lab a (x) ∧ ∀y(¬suc(y, x))] ∧ ∀x[(lab a (x) ∨ lab b (x)) ⇒ ∃y(suc(x, y) ∧ (lab b (y) ∨ lab c (y)))] ∧ ∀x[lab c (x) ⇒ ∀y(¬suc(x, y))].
Note that θ has models that are not representations of words 13 . So, θ characterizes ab * c as a subset of A * ; it does not characterize the abstract structures representing the words of ab * c among those of STR(W A ).

11 We define S |= ϕ only if ϕ is a sentence. 12 As usual, ∀y 1 , y 2 , y 3 abbreviates ∀y 1 ∀y 2 ∀y 3 .

13 For example, S with D S = {1, 2, 3}, suc S = {(1, 2), (2, 3), (3, 2)}, lab aS = {1}, lab bS = {2, 3}, lab cS = ∅.

Second-order logic

Although we will only use its fragment called monadic second-order logic, we describe second-order logic for completeness. We will use a countable set of variables V ω consisting of first-order variables as in Section 5.1.2 and of relation variables, denoted by uppercase letters X, Y, X 1 , . . . , X m . Each relation variable has an arity which is a positive integer (ρ(X) is the arity of X), and there are countably many variables of each arity.

Let R be a relational signature. We now define the second-order formulas over R. The atomic formulas are: True, False, s = t, R(t 1 , . . . , t n ) and X(t 1 , . . . , t n ) where s, t, t 1 , . . . , t n are terms, R ∈ R, X ∈ V ω and n = ρ(R) = ρ(X) ≥ 1. The formulas are constructed from the atomic formulas with the propositional connectives and the quantifications ∃x, ∀x, ∃X, ∀X for first-order and relation variables. (Instead of a formal syntax we give examples below). For X ⊆ V ω , we will denote by SO(R, X ) the set of second-order formulas over R with free variables in X , and by FO(R, X ) the subset of those that have only first-order quantifications. The notation ϕ(X 1 , . . . , X m , x 1 , . . . , x n ) indicates that the free variables of ϕ belong to {X 1 , . . . , X m , x 1 , . . . , x n }.

The size |ϕ| and the quantifier-height qh(ϕ) of a formula ϕ are defined inductively as follows: It is clear that qh(ϕ) = 0 if ϕ is quantifier-free and that |ϕ| is the number of subformulas of ϕ. (A subformula is counted once for each of its occurrences.)

|ϕ| := 1, qh(ϕ) := 0 if ϕ is atomic, |¬ϕ| := |ϕ| + 1,
We now consider the semantics of a formula ϕ(X 1 , . . . , X m , x 1 , . . . , x n ). If S ∈ STR c (R), if E 1 , . . . , E m are relations on D S of respective arities ρ(X 1 ), . . . , ρ(X m ) and if d 1 , . . . , d n ∈ D S , then the notation S |= ϕ(E 1 , . . . , E m , d 1 , . . . , d n ) means that ϕ is true in S for the values E 1 , . . . , E m of X 1 , . . . , X m and d 1 , . . . , d n of x 1 , . . . , x n respectively. We let sat(S, ϕ, (X 1 , . . . , X m ), (x 1 , . . . , x n )) be the set of (m + n)-tuples (E 1 , . . . , E m , d 1 , . . . , d n ) of relations on D S and of elements of this set such that where γ(X i ) = E i and γ(x j ) = d j . Thus, sat(S, ϕ, (X 1 , . . . , X m ), (x 1 , . . . , x n )) can be viewed as the set of all X -assignments γ such that (S, γ) |= ϕ. The notions of sentence, of satisfaction and of model defined in Section 5.1.2 extend in the obvious way.

S |= ϕ(E 1 , . . . , E m , d 1 , . . . , d n ). Let X := {X 1 , . . . , X m , x 1 , . . . , x n }. An X -assignment in S is a mapping γ with domain X such that γ(X i ) is a ρ(X i )-
Here are some examples. We let β(X) be the formula in SO(∅, {X}):

∀x, y, z([X(x, y) ∧ X(x, z) ⇒ y = z] ∧ [X(x, z) ∧ X(y, z) ⇒ x = y]),
where X is binary. It expresses that X is a functional relation, and that the corresponding function is injective. The following formula α(X) expresses that X is an automorphism14 of a simple graph G represented by the structure G in STR(R s ). Here is α(X):

β(X) ∧ ∀x∃y. X(x, y) ∧ ∀x∃y. X(y, x) ∧ ∀x, y, x , y [edg(x, y) ∧ ((X(x, x ) ∧ X(y, y )) ∨ (X(x , x) ∧ X(y , y))) ⇒ edg(x , y )].
Hence, G has a nontrivial automorphism if and only if G satisfies the sentence15 ∃X[α(X) ∧ ∃x, y(x = y ∧ X(x, y))].

Consider now the formula γ(Y 1 , Y 2 ) in SO(∅, {Y 1 , Y 2 }): ∃X[β(X) ∧ ∀x{(Y 1 (x) ⇔ ∃y. X(x, y)) ∧ (Y 2 (x) ⇔ ∃y. X(y, x))}].
It expresses that there exists a bijection (the binary relation defined by X) between the sets Y 1 , Y 2 , handled as unary relations. Hence the following secondorder sentence characterizes the nonregular language {a n b n | n ≥ 1} as a subset of {a, b} * :

∃x[lab a (x) ∧ ∀y(¬suc(y, x))] ∧ ∀x[lab a (x) ⇒ ∃y(suc(x, y) ∧ (lab a (y) ∨ lab b (y)))] ∧ ∀x, y[lab b (x) ∧ suc(x, y) ⇒ lab b (y)] ∧ ∃Y 1 , Y 2 [γ(Y 1 , Y 2 ) ∧ ∀x[lab a (x) ⇔ Y 1 (x)] ∧ ∀x[lab b (x) ⇔ Y 2 (x)]].
This is an example of a language that cannot be characterized by a monadic second-order sentence (a particular type of second-order formula to be defined in the next section). Note that the sentences of the first three lines characterize the regular language a + b + .

Monadic second-order logic

The main logical language to be used in this book is monadic second-order logic which lies in between first-order and second-order logic. All formulas will be written with variables from a set V 1 consisting of the countable set V 0 of first-order variables and the countably many relation variables of arity one from V ω . Since a relation with one argument is nothing but a set, these relation variables will be called set variables.

Let R be a relational signature. A monadic second-order formula (MS formula in short) over R is a second-order formula written with R and the variables of V 1 : the quantified and free variables are first-order or set variables. In order to get more readable formulas, we will write x ∈ X and x / ∈ X instead of X(x) and ¬X(x) where X is a set variable. For X ⊆ V 1 , we will denote by MS(R, X ) the set of monadic second-order formulas over R, with free variables in X . Occasionally, monadic second-order formulas may have free relation variables of any arity, but their quantifications apply to first-order and set variables only.

In Section 1.3.1 we have constructed monadic second-order sentences expressing that a graph is connected and that it is 3-vertex colorable. We now give other examples. The sentence δ ∈ MS({suc}, ∅) given below expresses that a word in A * has odd length. Since this property does not depend on letters, δ does not use the unary relations lab a for a ∈ A. Here is δ:

∃X[δ (X) ∧ ∃x(x ∈ X ∧ ∀y(¬suc(x, y)))] where δ (X) is ∃x[x ∈ X ∧ ∀y(¬suc(y, x))] ∧ ∀x, y[suc(x, y) ⇒ (x ∈ X ⇔ y / ∈ X)].
For every nonempty word w ∈ A * , there is a unique set X ⊆ D w satisfying δ : the elements of X are the odd positions in w. The sentence δ expresses that the last position is odd, i.e., that the considered word has odd length. The next lemma is a basic fact of model theory. If h is a mapping :

D → D and E ⊆ D k , we define h(E) := {(h(d 1 ), . . . , h(d k )) | (d 1 , . . . , d k ) ∈ E}.
Lemma 5.4 Let h : S → T be an isomorphism of concrete R-structures. If ϕ ∈ SO(R, {X 1 , . . . , X m , x 1 , . . . , x n }), then: sat(T, ϕ, (X 1 , . . . , X m ), (x 1 , . . . , x n )) = h(sat(S, ϕ, (X 1 , . . . , X m ), (x 1 , . . . , x n ))), i.e., is the set of tuples (h(E 1 ), . . . , h(E m ), h(d 1 ), . . . , h(d n )) such that the tuple (E 1 , . . . , E m , d 1 , . . . , d n ) belongs to sat(S, ϕ, (X 1 , . . . , X m ), (x 1 , . . . , x n )).

If ϕ is a sentence, then S |= ϕ if and only if T |= ϕ.

Proof: By induction on the structure of ϕ.

From the last assertion, we get that if ϕ is a sentence (n = m = 0; () is the empty sequence of variables), then sat(S, ϕ, (), ()) is well defined if S is an abstract structure; it is then equal to {()} or to ∅.

Logical definitions of properties of relational structures

Let L be a logical language, typically first-order logic, second-order logic, or monadic second-order logic, designated respectively by FO, SO or MS, or one of the extensions of monadic second-order logic defined below. Let R be a relational signature. We denote by L(R, ∅) the corresponding set of sentences over R. If ϕ ∈ L(R, ∅), then the set of concrete R-structures S such that S |= ϕ, denoted by MOD(ϕ), is closed under isomorphism by Lemma 5.4, hence is a class of structures. We say that such a class is L-definable.

If C ⊆ STR c (R) is a class of R-structures, then the class {S ∈ C | S |= ϕ} = MOD(ϕ) ∩ C is said to be L-definable with respect to C. 16
We say that a property P of structures S in STR c (R) is L-expressible if, for some sentence ϕ of L(R, ∅), it is equivalent to S |= ϕ for all S in STR c (R). Thus, a class of structures

D ⊆ STR c (R) is L-definable if and only if the membership in D of a concrete R-structure is L-expressible. A property P of tuples (E 1 , . . . , E m , d 1 , . . . , d n ) in structures S of STR c (R) is L-expressible if there exists a formula ϕ in L(R, {X 1 , . . . , X m , x 1 , . . . , x n }) such that, for all S ∈ STR c (R) and all (E 1 , . . . , E m , d 1 , . . . , d n ) of appropriate types, P (S, E 1 , . . . , E m , d 1 , . . . , d n ) holds if and only if S |= ϕ(E 1 , . . . , E m , d 1 , . . . , d n ).
Similar definitions hold for L-expressibility with respect to a class C ⊆ STR c (R): in the above, just replace STR c (R) by C.

We adapt these definitions to finite combinatorial objects such as words, terms, partial orders, graphs, cyclic orders (cf. Section 1.9) represented by relational structures. Let C be a class of such objects and rep be a mapping : C → STR c (R) with the natural requirement that isomorphic objects are mapped to isomorphic structures. We say that rep is faithful if, conversely, for all

H, K ∈ C, H is equal or isomorphic to K if rep(H) is isomorphic to rep(K).
We say that a property P of the elements of C is L-expressible via rep if there exists a sentence ϕ in L(R, ∅) such that H has property P if and only if rep(H) |= ϕ, for every H ∈ C (and similarly for properties of tuples, when relevant). In the case where rep is faithful, and only in this case, we say that a set L ⊆ C is L-definable via rep if membership in L is L-expressible via rep.

To take an example, although the representation of a graph G by G is not faithful (it does not distinguish multiple edges), connectedness, a property that does not depend on the multiplicity of edges, is MS-expressible via this representation. (This example has been considered in Section 1.3.1). But we will not say that the set of connected graphs is MS-definable. However, we can say that the set of simple connected graphs is MS-definable: the representation

• is faithful on the class C of simple graphs. The expressibility of P and the definability of L are always with respect to some reference class C that we will sometimes leave implicit. We will usually omit the mention of the representation rep for words, terms and graphs, whenever it equals • as defined in Example 5.2. For a set L of p-graphs (or simple s-graphs) of bounded type, the default representation is • C where C is the union of all types of the elements of L.17 The hierarchy of logical languages FO ⊂ MS ⊂ SO yields a corresponding hierarchy of graph properties: every FO-expressible property is MS-expressible (implicitely, via • ) but not conversely. In Sections 5.2.5 and 5.2.6, we will introduce intermediate languages between MS and SO and compare their expressive power with that of MS.

Why considering relational structures with constants?

The root of the syntactic tree of a term and the sources of an s-graph have been defined in Example 5.2(2,3) as constants of representing structures, but we have observed that these constants can be replaced by unary relations denoting singleton sets. This observation can be extended to all relational structures with constants. For every relational signature R with R 0 = ∅, we let R * := R + ∪ Lab R where Lab R := {lab a | a ∈ R 0 } is a new19 set of unary relation symbols.

For every S ∈ STR c (R), we let S * be the structure in STR c (R * ) such that lab aS * := {a S } for every a ∈ R 0 and R S * = R S for every R ∈ R + . We denote by STR c * (R * ) the class of structures in STR c (R * ) such that the sets denoted by the relation symbols lab a in Lab R are singletons. The mapping S → S * is a bijection between (concrete or abstract) R-structures and R * -structures satisfying this condition. Every first-order, second-order or monadic secondorder formula over R can be rewritten into one over R * expressing in S * the same property as the given formula20 in S. However, this transformation may increase the quantifier-height: the atomic formula R(a, x) where a is a constant symbol and x is a variable is transformed into ∃y(lab a (y)∧R(y, x)). In the proof of the Recognizability Theorem, it will be important to express the operations on p-graphs and s-graphs in terms of the disjoint union of structures and of transformations specified by quantifier-free formulas. In order to express in this way the parallel-composition, a basic operation of the HR algebra, we cannot handle sources of graphs with unary relations, hence, we must use constants.

Decidability questions

Let R be a relational signature, let C ⊆ STR c (R) and let L be a logical language as in the previous section. The L-theory of C is the set of sentences:

Th L (C) := {ϕ ∈ L(R, ∅) | S |= ϕ for every S ∈ C}.
We say that the L-theory of C is decidable if some algorithm can test the membership in this set of any given sentence belonging to L(R, ∅). The L-satisfiability problem for C is the problem of deciding whether a given sentence of L(R, ∅) belongs to the following set:

Sat L (C) := {ϕ ∈ L(R, ∅) | S |= ϕ for some S ∈ C}.
We will always consider logical languages L such that L(R, ∅) is closed under negation. Hence, the L-theory of C is decidable if and only if its L-satisfiability problem is decidable, because Sat L (C) = {ϕ ∈ L(R, ∅) | ¬ϕ / ∈ Th L (C)}. Similar definitions hold for a class C of objects via a representation rep : C → STR c (R). We use the same default representations as in Section 5.1.5. As an example, for a finite functional signature F and a set of terms L ⊆ T (F ):

Th L (L) := {ϕ ∈ L(R F , ∅) | t |= ϕ for every t ∈ L} = Th L ( L ).
Theorem 5.5 The first-order theory of the class of graphs, of the class of graphs of degree at most 3, and of the class of planar graphs of degree at most 3 are undecidable. Thus, so are their monadic second-order and their second-order theories. 21The first assertion of this theorem is due to Trakhtenbrot. See Section 5.7 for references. We will exhibit in Section 5.4 some conditions on a set of graphs C ensuring that its MS-theory and its MS-satisfiability problem are decidable. It is thus desirable to separate the decidable cases from the undecidable ones. The following result about grids is a basic tool for obtaining undecidability results for monadic second-order theories.

We define a rectangular grid as a directed graph isomorphic, for some positive integers n and m, to the graph G n×m defined as follows (cf. Example 2.56(3)). We let its vertex set V Gn×m be [0, n -1] × [0, m -1] and its edges be the pairs ((i, j), (i , j )) such that 0 ≤ i ≤ i ≤ n -1, 0 ≤ j ≤ j ≤ m -1 and, either i = i+1 and j = j, or i = i and j = j +1. A square grid is a graph isomorphic to G n×n . We denote und (G n×m ) by G u n×m , cf. Proposition 2.106.

Theorem 5.6 The monadic second-order satisfiability problem for any set of graphs containing graphs isomorphic to G n×n or to G u n×n for infinitely many integers n is undecidable.

Proof: We first consider the case of directed graphs. One can construct a monadic second-order sentence γ that defines the square grids with respect to the class of simple directed graphs (see Proposition 5.14(1) in Section 5.2.3). Consider a Turing machine M with total alphabet A M = {a 1 , . . . , a m } (input letters, states, end markers, blank symbol) and an initial configuration w M ∈ A * M . If (U 1 , . . . , U m ) is a partition of the set of vertices of a square grid G n×n , then one can view it as defining a sequence of n words of length n in A * M . Each line of the grid encodes a word, where a line of G n×n is an induced subgraph with set of vertices [0, n-1]×{j} for some j and the (i+1)-th letter of this word is a k if and only if (i, j) ∈ U k . The property of being a line can be expressed by an MS formula by Proposition 5.14(2).

A partition (U 1 , . . . , U m ) of V Gn×n encodes a computation sequence of M if the first line encodes the initial configuration w M (with blank symbols to the right), and every two consecutive lines encode configurations that form a correct transition of M . If some line encodes a configuration with an accepting state, then we get from G n×n and the sequence of configurations encoded by (U 1 , . . . , U m ) a halting computation of M .

There is an algorithm that constructs, for every Turing machine M , an MS formula ψ M (X 1 , . . . , X m ) such that for every n, G n×n |= ψ M (U 1 , . . . , U m ) if and only if (U 1 , . . . , U m ) encodes on G n×n a halting computation of M . It follows that if the considered set of graphs C contains infinitely many square grids, then M halts if and only if some graph in C satisfies the sentence ϕ M : γ ∧ ∃X 1 , . . . , X m . ψ M if and only if ϕ M belongs to Sat MS (C). Hence, for each set C of directed graphs containing infinitely many square grids, the halting problem of Turing machines reduces to the MS-satisfiability problem for C. The latter problem is thus undecidable.

The proof is the same for a set of undirected graphs with the help of Proposition 5.14(3).

Remark 5.7 Let us assume that in this construction, the machine M is deterministic and that ψ M is defined in such a way that, when M halts, the square grid on which its unique halting computation is encoded is of minimal size. It follows that there exists at most one relational structure (up to isomorphism, it is then G n×n for some n) satisfying ϕ M . Hence, since the halting problem for deterministic Turing machines is undecidable, even if we know that a monadic second-order sentence ϕ has only finitely many models up to isomorphism, we cannot construct this set by an algorithm that takes all sentences ϕ as input.

We have just discussed the problem of verifying if a given sentence is true in some structure of a (fixed) set. We now introduce briefly the problem of verifying if a given sentence is true in a single given structure. This problem, called the model-checking problem, is trivially decidable since structures are by definition finite and the validity of a sentence is an effective notion. Its algorithmic complexity depends on the considered structures and on the logical language of the given sentence. This issue is the subject of Descriptive Complexity (see Section 5.7 for references). We only quote two results relevant to the algorithmic applications to be studied in Chapter 6:

(1) for each first-order sentence ϕ, one can check if

S |= ϕ in time O(|ϕ|• S w )
where w is the width of ϕ defined as the maximum number of free variables of a subformula of ϕ (Proposition 6.6 in [*Lib04] or Proposition 4.24 in [*FluGro]);

(2) each level of the polynomial hierarchy contains a model-checking problem for some monadic second-order sentence that is complete for polynomial reductions (Proposition 11 in [MakPnu]).

These results distinguish sharply first-order from monadic second-order logic with respect to the complexity of model-checking. Furthermore, the second one shows that monadic second-order logic is, by itself, of no help for obtaining efficient model-checking algorithms over all graphs. However by restricting the tree-width or the clique-width of input graphs or relational structures, we will obtain polynomial algorithms, as we will see in Chapters 6 and 9.

Graph properties expressible in monadic second-order logic

In the previous section and in Chapter 1, we have given several examples of graph properties expressed by logical formulas (via • ). We now review some tools that help to construct formulas. Since they work for second-order logic, we present them for this language. We will also review negative results showing that certain properties are not expressible in such or such language.

In order to shorten notation, we will use x to denote tuples of pairwise distinct first-order variables (typically x = (x 1 , . . . , x n )) and X to denote tuples of pairwise distinct relation variables (typically X = (X 1 , . . . , X m )). In such cases, we will denote by d an n-tuple (d 1 , . . . , d n ) of values in the domain D S of a concrete structure S where d i is taken as value of x i for each i. These values need not be pairwise distinct. We will denote similarly by E an m-tuple of relations on D S of respective arities ρ(X 1 ), . . . , ρ(X m ), that need not be pairwise distinct. We will also regard x and X as the corresponding sets of variables by using notation like y ∈

x or z ∈ X ∪ x. With this convention, SO(R, X ∪ x) denotes SO(R, {X 1 , . . . , X m , x 1 , . . . , x n }). If ϕ ∈ SO(R, X ∪ x)
, then the use of the notation S |= ϕ(E, d) implies that E is an m-tuple of relations on D S of appropriate arities and that d ∈ D n S . Two formulas ϕ and ϕ in SO(R, X ∪ x) are equivalent, denoted ϕ ≡ ϕ , if for all concrete R-structures S, for all relations E 1 , . . . , E m on D S of respective arities ρ(X 1 ), . . . , ρ(X m ) and all tuples d ∈ D n S , we have:

S |= ϕ(E, d) if and only if S |= ϕ (E, d).
Two equivalent formulas express the same property of the relevant tuples (E, d) in every structure S ∈ STR c (R). Equivalence can be relativized to a subset C of STR c (R): equivalent formulas express the same property of the relevant tuples in the structures of C.

Substitutions and relativization

If ϕ is a formula in SO(R, X ), x 1 , . . . , x n are pairwise distinct first-order variables in X and t 1 , . . . , t n are terms22 , then we denote by ϕ[t 1 /x 1 , . . . , t n /x n ] the result of the substitution of t 1 , . . . , t n for x 1 , . . . , x n . If some of the terms t 1 , . . . , t n are variables then, before substitution is done, some bound variables of ϕ may have to be renamed. For example, if ϕ(x 1 , x 2 , x 3 ) is:

∀y[edg(x 1 , y) ∨ edg(y, x 2 )] ∧ ∀u[edg(x 1 , u) ⇒ edg(u, x 3 )]
then ϕ[y/x 1 , u/x 2 , y/x 3 ] is (or can be, because bound variables can be renamed in several ways):

∀y [edg(y, y ) ∨ edg(y , u)] ∧ ∀u[edg(y, u) ⇒ edg(u, y)].
In many cases, we will simplify the notation

ϕ[t 1 /x 1 , . . . , t n /x n ] into ϕ(t 1 , . . . , t n ).
Clearly, if ϕ is monadic second-order or first-order, then so is ϕ[t 1 /x 1 , . . . , t n /x n ]. This transformation satisfies the following property which shows its semantic meaning:

Lemma 5.8 Let ϕ belong to SO(R, {X 1 , . . . , X m , x 1 , . . . , x n , u 1 , . . . , u q }), let t 1 , . . . , t n be terms and let y 1 , . . . , y p be the variables occurring in these terms.

Let ψ(X 1 , . . . , X m , y 1 , . . . , y p , u 1 , . . . , u q ) be the formula ϕ[t 1 /x 1 , . . . , t n /x n ]. For every concrete R-structure S, for all relations E 1 , . . . , E m on D S of respective arities ρ(X 1 ), . . . , ρ(X m ) and for all d ∈ D p S and f ∈ D q S , we have:

S |= ψ(E, d, f ) if and only if S |= ϕ(E, d 1 , . . . , d n , f )
where for all i = 1, . . . , n, we let d i := a S if t i = a and a belongs to R 0 , and

d i := d j if t i = y j .
We now define substitutions to relation symbols of formulas intended to define the corresponding relations. Let ϕ ∈ SO(R, X ∪ U ∪ x) where X = (X 1 , . . . , X p ), U = (U 1 , . . . , U q ) and x = (x 1 , . . . , x n ). For each i = 1, . . . , p, we let ψ i ∈ SO(R, U ∪ x ∪ w i ) where w i is a sequence of ρ(X i ) pairwise distinct first-order variables with x ∩ w i = ∅. We let ϕ[λw 1 • ψ 1 /X 1 , . . . , λw p • ψ p /X p ] be the formula in SO(R, U ∪ x) constructed as follows:

• by renaming some bound variables if necessary, one defines a formula ϕ equivalent to ϕ where no variable of X ∪ U ∪ x is bound;

• then, one replaces every atomic formula X i (u 1 , . . . , u ρ(Xi) ) of ϕ (where the terms u 1 , . . . , u ρ(Xi) need not be pairwise distinct) by the formula ψ i [u 1 /y 1 , . . . , u ρ(Xi) /y ρ(Xi) ] (which belongs to SO(R, U ∪ x)) where w i = (y 1 , . . . , y ρ(Xi) ).

It is clear that ϕ[λw 1 • ψ 1 /X 1 , . . . , λw p • ψ p /X p ] is first-order (resp. monadic second-order) if ϕ and the formulas ψ i are first-order (resp. monadic secondorder). With this notation, we have the following lemma.

Lemma 5.9 Let S ∈ STR c (R), let E be a q-tuple of relations on D S of appropriate arities and let d ∈ D n S . For each i = 1, . . . , p, let T i be the ρ(X i )-ary relation on D S defined by (a 1 , . . . , a ρ(Xi) ) ∈ T i if and only if S |= ψ i (E, d, a 1 , . . . , a ρ(Xi) ).

Then

S |= ϕ[λw 1 • ψ 1 /X 1 , . . . , λw p • ψ p /X p ](E, d) if and only if S |= ϕ(T 1 , . . . , T p , E, d).
Proof: Straightforward verification from the definition, by using an induction on the structure of ϕ.

We use the λ-notation λw i • ψ i because ψ i defines (for fixed values of U ∪ x) a mapping : D ρ(Xi) S → {True, False}. We will also simplify the notation ϕ[λw 1 • ψ 1 /X 1 , . . . , λw p • ψ p /X p ] into ϕ[Z 1 /X 1 , . . . , Z p /X p ] (or just ϕ(Z 1 , . . . , Z p )) in the case where, for each i, Z i is a relation variable such that ρ(Z i ) = ρ(X i ), ψ i is Z i (y 1 , . . . , y ρ(Xi) ) and w i = (y 1 , . . . , y ρ(Xi) ).

We now present the relativization of a formula to a substructure.

Lemma 5.10 Let ϕ ∈ SO(R, {Y 1 , . . . , Y m , x 1 , . . . , x n }) and let X be a set variable not in {Y 1 , . . . , Y m }. A formula ϕ in SO(R, {Y 1 , . . . , Y m , X, x 1 , . . . , x n }) can be constructed such that for every S ∈ STR c (R), every m-tuple of relations

E = (E 1 , . . . , E m ) on D S with E i ⊆ D ρ(Yi) S
, every subset A of D S that contains a S for each a ∈ R 0 , and every d ∈ A n :

S |= ϕ (E, A, d) if and only if S[A] |= ϕ(E , d)
where Yi) for each i. If ϕ is first-order or monadic second-order, then ϕ is first-order or monadic second-order respectively.

E i := E i ∩ A ρ(
Proof: We can assume that X does not occur in ϕ. (If X is bound in ϕ, then we rename its bound occurrences.) We let ϕ be associated with ϕ by the following inductive definition, where ϕ may have free variables of all types (relation variables as well as first-order variables): ψ = ψ for every atomic formula ψ, (ψ 1 op ψ 2 ) = ψ 1 op ψ 2 where op ∈ {∧, ∨, ⇒, ⇔},

(¬ψ) = ¬ψ , (∀x. ψ) = ∀x[x ∈ X ⇒ ψ ] and (∃x. ψ) = ∃x[x ∈ X ∧ ψ ],
(∀Y. ψ) = ∀Y. ψ and (∃Y. ψ) = ∃Y. ψ . 23In each case and by induction, we get that qh(ψ ) = qh(ψ).

The formula ϕ , called the relativization of ϕ to X, will be denoted by ϕ X. Semantically, it expresses the relativization to the substructure induced by X of the property expressed by ϕ. Its quantifier-height is the same as that of ϕ.

Transitive closure and path properties

We now consider the logical expression of the reflexive and transitive closure T * of a binary relation T . In Section 1.3.1, we have already defined the monadic second-order formula TC[R; x, y]:

∀X[x ∈ X ∧ ∀u, v(u ∈ X ∧ R(u, v) ⇒ v ∈ X) ⇒ y ∈ X].
In every structure S, this formula defines the binary relation R * S . One can also use it for defining the relation T * if T is not a relation of the considered structure but is defined by some formula, for example by α(u, v) equal to edg(u, v) ∨ edg(v, u). The relation T may be expressed by a formula with free variables besides u and v. Such a formula can be β(u, v, Y ) defined as edg(u, v) ∧ u ∈ Y ∧ v ∈ Y to take another example about graphs. Then, the formula (TC[R; x, y])[λu, v • α/R], more simply denoted by TC[(λu, v • α); x, y] and defined as the result of the substitution of the formula α for the relation symbol R in TC[R; x, y], expresses that the vertices x and y are the ends of a possibly empty undirected path (cf. Lemma 5.9). The formula x ∈ Y ∧ y ∈ Y ∧ TC[(λu, v • β); x, y] expresses that there is a directed Y -path from x to y, i.e., a directed path from x to y in the subgraph induced by Y .

Note that TC[(λu, v • γ); x, y] is a monadic second-order formula if γ is a monadic second-order formula. With these tools, we can express by monadic second-order formulas many properties of paths in graphs. In the next lemma, we write formulas over the signature R s , intended to express some basic graph properties. 24 Proposition 5.11 There exist monadic second-order formulas expressing in G the following properties of vertices x, y and of a set of vertices X of a directed graph G: P1: G is strongly connected, P2: x, y ∈ X and there is a directed X-path from x to y, P3: X is a connected component of G, P4: G, assumed to be simple, is a rooted tree,25 P5: for G assumed without circuit, X is the set of vertices of a directed path from x to y, P6: G is planar.

For every finite set C of source labels and every positive integer k, the following property of an s-graph G of type included in C is monadic second-order expressible in G C :

P7: G has tree-width at most k.26

Note that, except P4, these properties do not depend on the multiplicity of edges. They can be expressed logically for all graphs via the representation • .

Proof: We will denote by ϕ i , i = 1, . . . , 6, the formula expressing property Pi, in a concrete R s -structure S = G .

(1) ϕ 1 is the formula ∀x, y. TC[edg; x, y]. It is trivially true in the empty structure that represents the empty graph. An empty directed graph is strongly connected. (For the same reason, we defined an empty graph as connected, cf. Definition 2.9.)

(2

) ϕ 2 is x ∈ X ∧ TC[(λu, v • β); x, y] where β is: edg(u, v) ∧ u ∈ X ∧ v ∈ X. (3) ϕ 3 is ∃y[y ∈ X ∧∀x(x ∈ X ⇔ TC[(λu, v •α); x, y])]
where α is: edg(u, v)∨ edg(v, u).

(4) Let G be simple. That it has no circuits (and hence, no loops) can be expressed by the sentence γ: ∀x, y(TC[edg; x, y] ⇒ ¬edg(y, x)).

Then ϕ 4 is the sentence:

γ ∧ ∃x∀y. TC[edg; x, y] ∧ ∀x, y, z(edg(x, z) ∧ edg(y, z) ⇒ x = y)
expressing that G has no circuits, that every vertex is reachable from some vertex (the root) by a directed path and that every vertex is of indegree at most 1. (We recall that rooted trees have edges directed from the root towards the leaves.) Note that if we add to ϕ 4 the condition that every vertex has outdegree at most one, we obtain a sentence ϕ 4 expressing that G is a directed path.

(5) The formula ϕ 2 (x, y, X) expresses that x and y belong to X and there is a directed X-path from x to y. Hence the formula ϕ 2 (x, y, X) defined as:27

ϕ 2 (x, y, X) ∧ ∀Y [Y ⊆ X ∧ ϕ 2 (x, y, Y ) ⇒ X = Y ]
expresses that x and y belong to X and that X is the set of vertices {z

0 , z 1 , . . . , z k } of a directed path x = z 0 → z 1 → z 2 → • • • → z k-1 → z k = y that
is minimal in the sense that there is no edge z i → z j for i + 1 < j. Hence, this path cannot be shortened by a "shortcut"; there may exist several minimal paths of different lengths from x to y. If x = y, then X = {x}. This construction is valid even if G has circuits.

We now want to construct a formula ϕ 5 (x, y, X) describing all directed paths from x to y, not only the minimal ones. We assume that G has no circuits (otherwise the construction is not possible, see Proposition 5.13 below). In order to express that X is linearly ordered by the relation edg * G[X] , we let ϕ 5 (X) be:

∀x, y[x ∈ X ∧ y ∈ X ⇒ ϕ 2 (x, y, X) ∨ ϕ 2 (y, x, X)].
Let ϕ 5 (x, y, X) be the formula defined as

x ∈ X ∧ y ∈ X ∧ ϕ 5 (X) ∧ ∀z ∈ X[ϕ 2 (x, z, X) ∧ ϕ 2 (z, y, X)].
It says that X is linearly ordered by edg * G[X] with first element x and last element y. If x = y, then X = {x}. This is equivalent to the fact that X is the set of vertices of a directed path from x to y because the graph G is finite and without circuit.

(6) This has been proved in Corollary 1.15 by means of the characterization of planar graphs in terms of excluded minors and the formalization of minor inclusion by MS-formulas.

(7) For Property P7, we first consider graphs (without sources, i.e., C = ∅ and G C = G ). For each integer k, we know by Corollary 2.60(2) (Section 2.4.2) that there is a finite set of excluded minors characterizing the graphs of tree-width at most k. Corollary 1.14 gives the desired sentence ϕ 7,k .

We now consider an s-graph G of type C included in C, represented by the R s,C -structure G C . We have noted in Section 2.4.2 that it has tree-width at most k if and only the graph fg C (und (G) K C ) has tree-width at most k, hence, if and only if fg

C (und (G) K C ) |= ϕ 7,k . The latter condition is equivalent to G C |= ϕ 7,k,C where ϕ 7,k,C is the sentence ϕ 7,k [λu, v • θ/edg] and θ is: edg(u, v) ∨ a,b∈C,a =b (lab a (u) ∧ lab b (v)).
Thus, ϕ 7,k,C expresses property P7.

Note that sentence ϕ 7,k does not specify any tree-decomposition of width k. However, it follows from Example 5.2(4) that, for each k, one can construct a second-order sentence (not a monadic one) ψ k of the form ∃X. θ(X) where X is a binary relation variable and θ(X) is a monadic second-order formula, such that ψ k is true in G if and only if G has a normal tree-decomposition (T, f ) of width at most k. The binary relation that is the intended value of X is son T to be used in the structure S 2 (G, T, f ) = V G , edg G , son T (cf. Example 5.2(4)). The formula θ(X) is of the form θ 1 (X) ∧ θ 2 (X), where θ 1 (X) expresses that son T determines a rooted tree T that is normal for G, and θ 2 (X) expresses that |f (u)| ≤ k+1 for every u ∈ N T . The formula θ 2 (X) uses a monadic second-order formula µ(X, u, w) that defines in G , for every binary relation son T satisfying θ 1 (X), the binary relation box f = {(u, w) | w ∈ f (u)}, cf. Example 5.2(4). We will discuss in Section 7.6 the possibility of replacing ψ k by a monadic secondorder sentence that can specify at least one tree-decomposition of width k of any graph of tree-width at most k. 28 At the end of Section 5.1.2, we have shown that the regular language ab * c is MS-definable, i.e., that the class ab * c of W A -structures that represent the words of ab * c is MS-definable with respect to the class of structures representing words. We now consider the MS-definability of the latter class.

Corollary 5.12 For every alphabet A, the class of W A -structures A * is MSdefinable. Similarly, for every finite functional (possibly many-sorted) signature F , the class of R F -structures T (F ) is MS-definable.

Proof: Easy constructions using the sentences ϕ 4 and ϕ 4 of the proof of Proposition 5.11, respectively for words and terms. Such constructions can be done for the variants of w and t defined in Example 5.2. We omit the details.

It follows that for every language L ⊆ A * , the class of W A -structures L is MS-definable if and only if it is MS-definable with respect to the class A * . Hence, L is MS-definable if and only if L is MS-definable. A similar statement holds for terms.

We now review some graph properties that are not MS-expressible. 29 A directed (resp. undirected) graph is Hamiltonian if it has at least 2 vertices and a circuit (resp. a cycle) going through all vertices. A perfect matching is a set of undirected edges that link each vertex of X to a single vertex of Y and vice-versa, where {X, Y } is a bipartition of the vertex set of the graph.

Proposition 5.13 The following properties are not MS-expressible:

28 It is not known yet whether the class CWD(≤ k) of graphs of clique-width at most k is monadic second-order definable. Since it is not closed under taking minors, the proof for treewidth cannot extend. However, this class is closed under taking induced subgraphs, hence is characterized by a set of minimal excluded induced subgraphs. This set is {P 4 } for k = 2 and is infinite (and not yet characterized) for k ≥ 3. If this set would be monadic second-order definable, then so would be CWD(≤ k). The monadic second-order definability of the class of comparability graphs is provable in this way (see [START_REF] Courcelle | The monadic second-order logic of graphs XV: On a conjecture by D. Seese[END_REF], Lemma 5.1).

29 Recall from Section 5.1.5 that the default representation of a graph G is G .

(1) Two sets X and Y have equal cardinality.

(2) A simple graph is Hamiltonian, or has a perfect matching.

(3) In a simple directed graph, a set of vertices X is that of a directed path from x to y.

(4) A simple graph has a nontrivial automorphism.

Proof: We will use the result for words corresponding to Theorem 1.16 (see Section 1.10): if L ⊆ {a, b} * is the set of words w such that w |= ϕ where ϕ is an MS sentence, then L is a regular language.30 (1) Assume that we have a formula ψ ∈ MS(∅, {X, Y }) such that for every set S and every V, W ⊆ S:

S |= ψ(V, W ) if and only if Card (V ) = Card (W ).
Then the MS sentence ψ[λx•lab a (x)/X, λx•lab b (x)/Y ] belonging to MS(W {a,b} , ∅) characterizes (as a subset of {a, b} * ) the language E of words having as many occurrences of a and b. This language is not regular, so we get a contradiction with the above result.

(2) With every word w ∈ {a, b} + represented by the structure w = [n], suc w , lab a w , lab b w , we associate the graph K w with set of vertices [n] and an edge from i to j if and only if i ∈ lab a w and j ∈ lab b w or viceversa. Hence K w is a complete bipartite directed graph. It is Hamiltonian if and only if w belongs to the language E already used in [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF].

Let us now assume the existence of a sentence η in MS(R s , ∅) that defines the Hamiltonian graphs among the simple directed ones. The FO formula µ(x 1 , x 2 ) equal to (lab a (x 1 ) ∧ lab b (x 2 )) ∨ (lab b (x 1 ) ∧ lab a (x 2 )) defines in w the edges of K w (note that D w = V Kw ). It follows that for every word w ∈ {a, b} * of length at least 2, we have:

w ∈ E if and only if K w is Hamiltonian if and only if w |= η[λx 1 , x 2 • µ/edg].
This would imply that the words in E of length at least 2 form a regular language, which is not the case. This contradiction completes the proof.

The proof is the same for undirected graphs and for perfect matchings because a complete bipartite graph K n,m has a Hamiltonian cycle or a perfect matching if and only if n = m.

(3) Assume that we have a formula ϕ ∈ MS(R s , {x, y, X}) expressing that, in a simple directed graph, X is the set of vertices of a directed path from x to y. Then the MS sentence:

∃X[∀u(u ∈ X) ∧ ∃x, y(ϕ(x, y, X) ∧ x = y ∧ edg(y, x))]
expresses that the considered graph assumed to have at least 3 vertices is Hamiltonian. This is not possible by (2), hence no such formula ϕ exists.

(4) The proof is similar to that of (2). With every word of the form a n bcd m with n ≥ 2, m ≥ 2, we associate the graph H n,m with vertex set [-n, m + 1] and undirected edges between i and i + 1 for every i ∈ [-n, m -1] and between 0 and m + 1. (The vertices in [-n, -1] correspond to the occurrences of a, those in [1, m] to the occurrences of d, 0 is the occurrence of b and m + 1 is that of c.) This graph has a nontrivial automorphism if and only if n = m, if and only if the given word belongs to the nonregular language {a n bcd n | n ≥ 2}. Hence, no monadic second-order sentence can express that a graph has a nontrivial automorphism. We omit a detailed writing of the formula analogous to µ(x 1 , x 2 ) in (2).

In Remark 5.21 we will prove in a similar way that the property for a graph to have a spanning tree of degree at most 3 is not MS-expressible.

A worked example: the definition of square grids

The rectangular grid G n×m is defined in Section 5.1.6 as the graph with set of vertices V := [0, n -1] × [0, m -1] and set of directed edges consisting of the pairs ((i, j), (i , j )) such that (i, j), (i , j ) ∈ V and either i = i and j = j + 1 or i = i + 1 and j = j. If x → y in G n×m , we say that y is a successor of x and that x is a predecessor of y.

The north-, west-, south-, and east-borders of G n×m are the sets of vertices:

X n = [0, n -1] × {m -1}, X w = {0} × [0, m -1], X s = [0, n -1] × {0}, and X e = {n -1} × [0, m -1]. A set of the form [0, n -1] × {j} is called a line of G n×m .
The well-coloring of G n×m is the 4-tuple of sets of vertices Y 0 , Y 1 , Y 2 , Y 3 such that:

(i, j) ∈ Y 0 if and only if i ≡ 0 and j ≡ 0 (mod 2), (i, j) ∈ Y 1 if and only if i ≡ 0 and j ≡ 1 (mod 2), (i, j) ∈ Y 2 if and only if i ≡ 1 and j ≡ 0 (mod 2), (i, j) ∈ Y 3 if and only if i ≡ 1 and j ≡ 1 (mod 2).

Figure 5.1 shows the well-coloring of G 4×4 , where a vertex is colored by k if it belongs to Y k . All these notions will be used in the following proposition in order to prove that the class of square grids, i.e., of graphs isomorphic to G n×n for some n ≥ 2, is MS-definable, and to identify their lines. These constructions are used in the proof of Theorem 5.6.

We let W be the set of set variables {X n , X w , X s , X e , Y 0 , Y 1 , Y 2 , Y 3 }, and W be W ∪ {U a , U b , U c }.

Proposition 5.14 (1) There exists a formula θ in MS(R s , W) such that for every simple directed graph G and every mapping ν : W → P(V G ), we have:

( G , ν) |= θ if and only if G is isomorphic to the square grid G n×n for some n ≥ 2 by a bijection h : V G → V Gn×n such that h(ν(X n )), h(ν(X w )), h(ν(X s )) and h(ν(X e )) are the four borders of G n×n , and h(ν(Y 0 )), h(ν(Y 1 )), h(ν(Y 2 )) and h(ν(Y 3 )) form the well-coloring of G n×n .

There is a sentence γ in MS(R s , ∅) that defines the square grids with respect to the class of simple directed graphs.

(2) There exists a formula χ in MS(R s , W∪{Z}) such that for every (W∪{Z})assignment ν in G that satisfies θ, we have:

( G , ν) |= χ if and only if h(ν(Z)
) is a line of G n×n (where h is as in ( 1)).

(3) These results extend to simple undirected graphs and the undirected square grids G u n×n := und (G n×n ). One constructs formulas θ in MS(R s , W ), γ in MS(R s , ∅) and χ in MS(R s , W ∪ {Z}). A W -assignment ν in G that satisfies θ defines an isomorphism from G to G u n×n , the sentence γ defines the undirected square grids with respect to the class of simple undirected graphs and the formula χ satisfies the same property as in (2), for θ and G u n×n .

Proof: (1) We let θ 0 express the following conditions concerning a simple directed graph G given with sets of vertices X n , X w , X s , X e , Y 0 , Y 1 , Y 2 , Y 3 . These conditions are intended to characterize the grids G 2n×2n for n ≥ 1:

(1.1) G is connected and has no circuits;

(1.2) Y 0 , Y 1 , Y 2 , Y 3 form a partition of V G and G is bipartite with bipartition {Y 0 ∪ Y 3 , Y 1 ∪ Y 2 }
; assuming this we will call a vertex, a successor of y or a predecessor of y that belongs to Y i , an i-vertex, an i-successor of y, or an i-predecessor of y respectively;

(1.3) every vertex has at most one i-successor and at most one i-predecessor for each i;

(1.4) G[X n ] is a directed path of even length consisting alternatively of 1-and 3vertices ; its first vertex is a 1-vertex that is the unique element of X n ∩X w ; its last vertex is a 3-vertex that is the unique element of X n ∩ X e ; the condition that G[X n ] is a directed path is MS-expressible by Proposition 5.11 (see P4) and Lemma 5.10; the other conditions are easy to formalize;

(1.4 ) G[X e ] is a directed path of even length consisting alternatively of 2-and 3vertices; its first vertex is a 2-vertex which is the unique element of X s ∩X e ; its last vertex is a 3-vertex which is the unique element of X n ∩ X e ;

(1.4 ) and (1.4 ) state similar conditions on the sets X s and X w , see Figure 5.1;

(1.5) a 1-vertex in X n has a 3-successor and no 0-successor; a 3-vertex in X n -X e has a 1-successor and no 2-successor; the 3-vertex in X n ∩ X e has no successors;

(1.5 ), (1.5 ) and (1.5 ) state similar properties of X e , X s , X w , see Figure 5.1; in particular a 1-vertex in X w has a 0-predecessor and no 3-predecessor; a 0-vertex in X w -X s has a 1-predecessor and no 2-predecessor; the 0-vertex in X w ∩ X s has no predecessors;

(1.6) for each vertex x in V G -(X n ∪ X e ) there exist y, z, u such that y = z, x → y, x → z, y → u and z → u;

(1.7) the unique directed path from the vertex in X s ∩ X w with vertices having colors 0, 2, 3, 1, 0, 2, 3, 1, . . . in this order reaches the unique vertex in X n ∩ X e ; this condition can be expressed with the help of the transitive closure construction of Section 5.2.2.

Conditions (1.1) to (1.6) characterize the well-colored rectangular grids of the form G 2n×2m for n ≥ 1, m ≥ 1. In particular, Conditions (1.4) and (1.5) express how the borders must be. Conditions (1.3) and (1.6) express how the neighbourhood of a vertex not on any border must be. The alternation of colors in Condition (1.7) specifies an "ascending staircase" from left to right. This condition holds if and only if m = n. If n = m = 1 the path defined by this condition has only three vertices, with respective colors 0, 1, 3.

It is not hard to modify this construction in order to characterize the grids of the form G (2n+1)×(2n+1) for n ≥ 1 by a formula θ 1 . Hence, we take θ 0 ∨ θ 1 as formula θ. As sentence γ, we take ∃W. θ.

(2) A line of G given with X n , X w , . . . , Y 3 as above is a set

L ⊆ V G such that (2.1) G[L] is a directed path from a vertex in X w to a vertex in X e , (2.2) either L ⊆ Y 0 ∪ Y 2 or L ⊆ Y 1 ∪ Y 3 .
This gives the construction of χ.

(3) We now extend this construction to simple undirected graphs. Let G be so and let (U a , U b , U c ) ∈ P(V G ) 3 define a proper vertex 3-coloring of G. 31 We let G(U a , U b , U c ) be the simple directed graph G such that:

V G := V G , E G := {(u, v) | u -v is an edge of G and (u ∈ U a ∧ v ∈ U b ) ∨ (u ∈ U b ∧ v ∈ U c ) ∨ (u ∈ U c ∧ v ∈ U a )}.
It is clear that G = und (G ), and

G n×m = und (G n×m )(U a , U b , U c ) for some proper vertex 3-coloring (U a , U b , U c ). Such a coloring of und (G 4×4
) is shown in Figure 5.2. Thus, G is isomorphic to G u n×n for some n ≥ 2 if and only if there exists a proper vertex 3-coloring (U a , U b , U c ) such that G(U a , U b , U c ) is isomorphic to G n×n for some n ≥ 2.

Hence in order to extend the constructions of ( 1) and (2) to simple undirected graphs, we let θ be the formula

κ(U a , U b , U c ) ∧ θ[(λu, v • α)/edg]
where κ expresses that (U a , U b , U c ) defines a proper vertex 3-coloring of the given graph G (cf. Chapter 1, Section 1.3.1) and α is the following formula which directs the edges of G according to the coloring defined by (U a , U b , U c ):

edg(u, v) ∧ [(u ∈ U a ∧ v ∈ U b ) ∨ (u ∈ U b ∧ v ∈ U c ) ∧ (u ∈ U c ∧ v ∈ U a )]. Hence, θ[(λu, v • α)/edg] expresses that G(U a , U b , U c ) is isomorphic to G n×n for some n. The desired sentence γ is then ∃W . θ, and the formula χ is χ[(λu, v • α)/edg].
Directed, vertex-labelled rectangular grids, called pictures, can be considered as 2-dimensional words and studied with tools of logic and automata theory. See [*GiaRes] for a survey of such a study.

Monadic second-order definability of regular languages

We prove that every regular language (cf. Theorem 3.62) is monadic secondorder definable. The converse of this statement will be proved in the Recognizability Theorem (Theorem 5.64 and Corollary 5.67). Together, these results establish Theorem 1.16.

Theorem 5.15 Let F be a finite functional signature. For every finite F -automaton A , one can construct a monadic second-order sentence ϕ in MS(R F , ∅)

such that L(A ) = {t ∈ T (F ) | t |= ϕ}.
Proof: Let A = F, Q A , δ A , Acc A be a finite F -automaton as in Definition 3.46. Without loss of generality, we can assume that A is ε-free and that

Q A = [n]. A term t in T (F ) is represented by the R F -structure t := N t , (son i t ) i∈[k] , (lab f t ) f ∈F , rt t
where N t = Pos(t) and k = ρ(F ) (cf. Example 5.2(3); the variants of this representation can be used as well).

We must express the existence on t of an accepting run r : Pos(t) → Q A of A . Such a run will be represented by the n-tuple (U 1 , . . . , U n ) of subsets of N t = Pos(t) such that U i = r -1 (i). An arbitrary n-tuple (U 1 , . . . , U n ) ∈ P(N t ) n represents an accepting run if and only if the following conditions hold: (C1) {U 1 , . . . , U n } is a partition32 of N t ;

(C2) rt t belongs to U i for some i ∈ Acc A ;

(C3) for each occurrence u of a constant symbol f , if u belongs to U i , then f → A i;

(C4) for each occurrence u of f ∈ F p with p ≥ 1, if u belongs to U i and its sons u 1 , . . . , u p belong respectively to U j1 , . . . , U jp , then f [j 1 , . . . , j p ] → A i.

The conjunction of conditions (C1)-( C4) is expressible by a formula ψ in FO(R F , {X 1 , . . . , X n }) (where a set U i as above will be the value of the variable X i ). The desired sentence ϕ is thus ∃X 1 , . . . , X n . ψ.

Remarks 5.16

(1) The size of ϕ is bounded by O(( A ) 2 + A ), where A is the size of A , defined as its weighted number of transition rules (cf. Definition 3.46).

(2) Theorem 5.15 states that L(A ) is MS-definable with respect to T (F ) (implicitly via the faithful representation • ). If α F is the monadic second-order sentence that defines T (F ) (cf. Corollary 5.12), then MOD(ϕ∧α F ) = L(A ) where ϕ is constructed from A by Theorem 5.15. Hence the class of structures L(A ) is also MS-definable.

(3) Words are in bijection with terms over a unary functional signature, and automata on words can be seen as particular automata on terms as observed in Section 3.3.1, Remark 3.51(2). Moreover, as observed in Example 5.2(3), the representations w and µ(w) are equivalent (where w is a word and µ(w) the corresponding term). Hence, the construction of Theorem 5.15 can be adapted to finite automata on words in a straightforward manner33 .

Edge set quantifications

As already noted, the representation of a graph by a relational structure that we have used up to now, is faithful only for simple graphs. It allows neither to express graph properties that depend on the multiplicity of edges nor certain properties of simple graphs of the form "there exists a set of edges such that . . . " like the property of being Hamiltonian or of having a perfect matching, see Proposition 5.13. We now define another representation, where the edges are elements of the domain, that is faithful for all graphs and is appropriate for expressing logically certain properties of graphs that depend on the multiplicity of edges. Furthermore, it allows to express more properties of simple graphs by monadic second-order sentences. For a graph G, the corresponding structure is denoted G . Definition 5.17 (Representation by incidence graphs) Incidence graphs have been considered in Chapter 2, Example 2.56(5). We will distinguish the cases of directed and undirected graphs 34 .

If G is a concrete undirected graph, then its incidence graph Inc(G) is the simple directed bipartite graph with vertex set V G ∪ E G and edges e → v, for every e ∈ E G and v ∈ V G such that v is an end vertex of e. We let G := Inc(G) . It will be convenient to denote the adjacency relation of Inc(G) by the binary relation symbol in instead of edg, in order to distinguish it from the adjacency relation of G.

Hence G := V G ∪ E G , in G with in G := {(e, v) | v
:= Inc(G) := V G ∪ E G , in 1G , in 2G
where in 1G and in 2G define the edges labelled respectively by 1 and 2. 35 This is an R d m -structure, where

R d m := {in 1 , in 2 }. 36
Two graphs G and G are isomorphic if and only if the structures G and G are isomorphic, hence this representation is faithful for all graphs. In a structure S representing a graph G, the edges are the elements x of D S that satisfy the formula ∃y. in 1 (x, y) or the formula ∃y. in(x, y) depending on whether S belongs to STR c (R d m ) or to STR c (R u m ). In the former case, S = G for some directed graph G if and only if in 1S and in 2S are two functional relations with the same domain, call it E, and in 1S ∪ in 2S ⊆ E × (D S -E). In the latter case, S = G for some undirected graph G if and only if |{y ∈ D S | (x, y) ∈ in S }| ≤ 2 for every x ∈ D S and in S ⊆ E × (D S -E) where E = {x ∈ D S | (x, y) ∈ in S for some y}. In both cases, the conditions are first-order expressible. If they hold, then E G = E and V G = D S -E; in the directed case, vert G (x) = (y 1 , y 2 ) if and only if (x, y 1 ) ∈ in 1S and (x, y 2 ) ∈ in 2S , and in the undirected case, vert G (x) = {y ∈ D S | (x, y) ∈ in S }. Thus, the class of R d m -structures { G | G is a directed graph} is FO-definable, and similarly for the undirected case (cf. Corollary 5.12).

A variant of G will be useful. We let R m := {in, lab Edge }. For a directed 34 We do not consider here an undirected edge as a pair of opposite directed edges. This convention is natural and convenient if graphs are handled as binary relations on sets of vertices, but it is not if graphs are handled as sets of edges that share vertices, and this is what we are doing.

35 Inc(G) can be formalized as a ({κ}, {1, 2})-labelled graph, where κ is a default vertex label. Its representation Inc(G) is as in Example 5.2(2), without the useless unary relation lab κG (and with in i instead of edg i ). 36 The subscript "m" recalls that the considered representation is faithful for graphs with multiple edges. The superscripts "d" and "u" stand for "directed" and "undirected" respectively.

graph G, we define G ∈ STR c (R m ) such that:37

D G := V G ∪ E G , lab Edge G := E G , in G := {(v, e) | e ∈ E G , v is the tail of e} ∪ {(e, v) | e ∈ E G , v is the head of e}.
If G is undirected, we let D G and lab Edge G be as above and in G be {(e, v) | e ∈ E G and v is an end vertex of e}. In this case the relation lab Edge is redundant but keeping it allows us to use the same signature for directed and undirected graphs. With this variant, the relational structure representing a directed or undirected graph G is, up to the change of edg into in, of the form H for some vertex-labelled (rather than edge-labelled) directed graph H. For algorithmic applications (cf. Chapter 6) it is better to have few relation symbols of arity more than 1. In fact, H is an obvious variant of Inc(G).

We now extend these definitions to s-graphs. In order to represent s-graphs of type τ (G) ⊆ C (the type τ (G) of G is the set of names of its sources), where C is a finite subset of A, we expand the three above defined signatures by the set {lab a | a ∈ C} of unary symbols. Additionally, to represent s-graphs of type C we expand them by the set C of constant symbols, cf. -structure G , the interpretation of a is the a-source of G, for every a ∈ C; since no two source names designate the same vertex, this variant of G is constant-separated (cf. Section 5.1.1). The two representations G are equivalent for both first-order and monadic second-order logic. Similar definitions hold for R u m and R m . For an s-graph G, we define Inc(G) as the simple s-graph such that Inc(G) • := Inc(G • ) and slab Inc(G) := slab G . Thus, Inc(G) has the same sources as G, which are all in V G . From the above definitions and those in Example 5.2(2) for simple s-graphs, it is clear that G C = Inc(G) C and G = Inc(G) (provided we take "matching" variants).

Vertex and edge labels are represented in a natural way by additional unary relations. That is, if λ is an edge label, then e ∈ lab λ G if and only if e is an edge with label λ. The corresponding signatures are denoted by adding the subscript [K, Λ]. Technical details will be given when necessary.

If L is a set of (labelled) graphs, then L denotes the corresponding set of structures G for G ∈ L. If L is a set of (labelled) s-graphs of type included in C, for some finite C ⊆ A, then L C denotes the set of structures G C for G ∈ L. In particular, if C is the union of all (finitely many) types of the elements of L, then we also denote L C by L . Note that L is defined only when L has bounded type, i.e., L ⊆ J S[C] for some finite C ⊆ A. Note also that L = Inc(L) , where Inc(L)

:= {Inc(G) | G ∈ L}.
The properties of a graph G can be expressed logically, either via its representation by G with domain V G ∪E G , or via the initially defined representation G with domain V G . The representation G allows only quantification over vertices, sets of vertices, and relations on vertices (according to the logical language we consider), whereas the representation G also allows quantification over edges, sets of edges and relations on edges.

We define the MS 2 -expressible graph properties as those that are MS-expressible via the representation of G by G . They are expressed by formulas over the signatures R d m , R u m or R m , depending on the chosen variant of the representation G . The subscript 2 recalls that these formulas use quantifications over two types of objects. (This point is formalized below, cf. the discussion before Proposition 5.20). An MS 1 -expressible graph property is just an MS-expressible one, i.e., based on the standard representation • that we have considered up to now. The subscript 1 will be used to insist that formulas use only quantifications over vertices and sets of vertices. The notion of MS 2 -definability of a set of graphs is defined accordingly (which is possible because the representation • is faithful on the class of all graphs). For the MS 2 -definability of a set L of s-graphs of bounded type, the representation • C is used, where C is the union of all types of the elements of L. Since the class of structures J S[C] C is MSdefinable, L is MS 2 -definable if and only if L is MS-definable (analogously to the MS-definability of a set of p-graphs of bounded type).

Similarly, we have FO 2 -, FO 1 -, SO 2 -or SO 1 -expressible graph properties. We will also speak of FO 2 -or SO 2 -definable sets of graphs, and of FO 1 -, MS 1or SO 1 -definable sets of simple graphs. These definitions extend to s-graphs and p-graphs in obvious ways.

For every graph G, the relation edg G is definable in G by a first-order formula. It follows that for each L ∈ {FO, MS, SO}, a graph property is L 2expressible if it is L 1 -expressible. Trivially, this does not hold in the other direction, see Proposition 5.19(1) below. Proposition 5.20 compares these different types of expressibility for properties of simple graphs.

The notations MS 1 and MS 2 refer both to monadic second-order formulas, but written over different relational signatures. The corresponding relational structures represent graphs in different (and nonequivalent) ways. For an arbitrary R-structure S, the MS formulas over R generalize the MS 1 formulas for graphs (a simple graph is considered as a binary relation on its vertex set), and they form the "natural" monadic second-order language for expressing proper-ties of S (cf. Section 5.1). In Section 9.2, we will define the incidence graph Inc(S) of an R-structure S. The MS formulas over the relational signature of Inc(S) which is a faithful representation of S, will be called the MS 2 formulas. They generalize to relational structures the MS 2 formulas initially defined for graphs.

Example 5.18 (Chordal graphs) It follows from Proposition 2.72 that the chordal graphs are the graphs in the class C of nonempty, connected, simple, loop-free and undirected graphs that have no induced cycle with at least four vertices. They are also the graphs in C having a perfect spanning tree. By the first characterization, the class of chordal graphs is MS 1 -definable (with respect to the class of simple graphs). However, this characterization uses forbidden configurations and it says nothing of the perfect spanning trees of the graphs recognized as chordal. All efficient algorithms on chordal graphs (see Section 2.4.4) are based on perfect elimination orders, which can be obtained easily from perfect spanning trees.

A perfect spanning tree of a simple loop-free undirected graph G can be defined as a pair (E, r) such that:

(1) E is a set of edges of G forming a spanning tree U ;

(2) the pair T := (U, r) is a normal spanning tree of G (cf. Definition 2.13);

(3) T is a perfect spanning tree (cf. Definition 2.71).

These conditions can easily be expressed by an MS 2 formula ϕ(X, z), using some of the formulas of Proposition 5.11. To express Conditions (1) and (2), we need an MS 2 -expression of the edge relation son T of T (where son T (x, y) holds if and only if y is a son of x). It can be obtained in terms of the root r of T and the set of edges E of the tree U (which is und (T )). In fact, y is a son of x in T if and only if there exists an edge e ∈ E such that (i) x and y are the ends of e and (ii) x and r belong to the same connected component of U -e. It follows that the relation ≤ T can be expressed by an MS 2 formula in terms of E and r, and so can Conditions (1) and (2).

Hence a simple, loop-free and undirected graph G is chordal if and only if G |= ∃X, z. ϕ(X, z). From every pair (E, r) that satisfies ϕ(X, z) in G , we can specify by auxiliary monadic second-order formulas the perfect spanning tree T and the associated (optimal) normal tree-decomposition, cf. Corollary 2.73(3) and Example 5.2(4). Hence, there exists a monadic second-order transduction (cf. Sections 1.7 and 1.8) that associates with G , for any chordal graph G, an optimal tree-decomposition of this graph (Proposition 9.56( 1)). As already discussed in Example 5.2(4), a similar result holds for G when G is k-chordal, for each k (Proposition 9.56(2)) Proposition 5.19 The following graph properties are MS 2 -expressible but are not MS 1 -expressible.

(1) A graph is simple.

(2) In a directed graph, X is a set of edges (resp. W is a set of vertices) forming a directed path from x to y, where x = y.

(3) A graph is Hamiltonian.

Proof: (1) is clear from the definitions.

(2) We consider a directed graph G. For every U ⊆ E G , we let V (U ) denote the set of vertices incident with at least one edge in U . We let θ(x, y, Y ) be the first-order formula expressing the following conditions:

(2.1) x, y are vertices and x = y, (2.2) Y is a set of edges, (2.3) x is incident with exactly one edge in Y and is its tail; similarly, y is incident with exactly one edge in Y and is its head,

(2.4) each vertex in V (Y ) -{x, y} is incident with exactly two edges in Y , it is the tail of one and the head of the other.

Since G is finite, this formula says that Y is the union of the set X of edges of a path from x to y and of the sets of edges of some circuits disconnected from this path. Hence X is characterized as the least subset Z of Y such that θ(x, y, Z) holds. It follows that the desired MS 2 formula 39 is the following one ψ:

θ(x, y, X) ∨ ∀Z[Z ⊂ X ⇒ ¬θ(x, y, Z)].
There is, of course, no MS 1 formula equivalent to ψ because such a formula has no free variables denoting sets of edges.

For expressing that W is the set of vertices of a path from x to y, we use the formula ϕ(x, y, W ) defined as ∃X(ψ(x, y, X) ∧ "W = V (X)"). The quantification over sets of edges is thus crucial in ϕ since we have proved in Proposition 5.13(3) that no formula in MS(R s , {x, y, W }) equivalent to ϕ does exist.

(3) For directed graphs, this follows from (2) and the proof of Proposition 5.13(3), and from Proposition 5.13(2). The proof for undirected graphs is similar.

For writing and using MS 2 formulas it is often convenient to assume that the variables are typed in the following way: a first-order variable written x:e (instead of x) will always take values in the set of edges and a first-order variable x:v will always take values in the set of vertices. Similarly, a set variable of the form X:e will denote sets of edges and a set variable X:v will denote sets of vertices. The set of variables is thus V 1 × {e, v}). The atomic formulas must be "correctly typed", e.g., in(x:e, y:v) and x:e ∈ X:e. Obviously, every typed MS 2 sentence is equivalent (with respect to all structures of the form G ) to an ordinary (untyped) MS 2 sentence, that one can construct by an easy induction.

39 Z ⊂ X replaces ∀z[z ∈ Z ⇒ z ∈ X] ∧ ∃x[x ∈ X ∧ x / ∈ Z].
For example, a subformula ∃x:e. ψ is replaced by ∃x(∃y. in(x, y) ∧ ψ[x/x:e]), assuming without loss of generality that the variable x:v does not occur in ψ.

Conversely, every MS 2 sentence ϕ can be transformed into an equivalent typed one. The transformation is as follows (assuming without loss of generality that no variable occurs more than once in a quantifier of ϕ). First, every subformula ∃x. ψ of ϕ is replaced by ∃x:e. ψ[x:e/x] ∨ ∃x:v. ψ[x:v/x], and similarly for ∀x and ∧. Thus, both types are considered for each first-order variable. Second, incorrectly typed atomic subformulas such as in(x:e, y:e) are replaced by False. Finally, every subformula ∃X. ψ is replaced by ∃X:e, X:v. ψ (and similarly for ∀X), where ψ is obtained from ψ by replacing all atomic subformulas of the form x:e ∈ X and x:v ∈ X respectively by x:e ∈ X:e and x:v ∈ X:v. Thus, the variable X:e is interpreted as the set of edges in X and X:v as the set of vertices in X. The correctness of this transformation is clear. Similar transformations can be made for FO 2 and SO 2 sentences. In particular, the type of an n-ary relation variable is an element of {e, v} n ; thus, in the transformation of an untyped SO 2 sentence into a typed one, each n-ary relation variable is replaced by 2 n typed relation variables of arity n.

Proposition 5.20 Let P be a property of simple (labelled) graphs. 40(1) P is FO 2 -expressible if and only if P is FO 1 -expressible.

(2) P is SO 2 -expressible if and only if P is SO 1 -expressible.

(3) P is MS 2 -expressible if P is MS 1 -expressible; the converse does not hold.

Proof: As observed above, every L 1 -expressible graph property is L 2 -expressible, for each L ∈ {FO, SO, MS}. Then, obviously, this also holds for properties of simple graphs. That the converse does not hold for monadic second-order logic follows from Propositions 5.13(2) and 5.19(3). The converse holds for FO because a quantification of the form "there exists an edge e such that . . . " can be replaced by a quantification of the form "there exist vertices x and y that form an edge such that . . . ". The proof is similar for SO: quantification over n-ary relations on edges is replaced by quantification over 2n-ary relations on vertices. We omit the technical details.

Remark 5.21 Let P be the property that a simple undirected graph G has a spanning tree of degree at most 3. This property is MS 2 -expressible but not MS 1 -expressible. We prove this last fact by the following construction similar to those of Proposition 5.13. We let A and B be two disjoint sets and we let G(A, B) be the graph G such that: The next theorem describes classes of simple graphs on which MS 1 and MS 2 formulas are equally expressive. For these graphs, the representations G and G are thus equivalent with respect to the expression of their properties in MS logic. A graph G is uniformly p-sparse if |E G[X] | ≤ p • |X| for every X ⊆ V G (cf. Theorem 4.51). Every simple loop-free undirected planar graph is uniformly 3-sparse (Corollary 4.2.10 in [*Die]). Every undirected graph of degree at most k and every simple loop-free undirected graph of tree-width at most k is uniformly k-sparse (clear for the former case; by Corollary 2.74(1) for the latter case, cf. the proof of Theorem 4.51).

G[A] is a path, V G = A ∪ (B × {0, 1, 2}) and edg G = edg G[A] ∪ E ∪ E -1 where E = (A × (B × {0})) ∪ {((x, 0), (x, i)) | x ∈ B, i ∈ {1, 2}}.
Theorem 5.22 (Sparseness Theorem) Let C be a class of simple and uniformly p-sparse (labelled) graphs, for some p > 0. A property is MS 2 -expressible with respect to C if and only if it is MS 1 -expressible with respect to C. There are effective translations between the defining sentences of both types.

The translation of an MS 1 formula into an MS 2 formula that defines the same simple graphs or the same property of vertex sets of simple graphs is easy and does not depend on p. The proof of the opposite translation is quite long and will be given in Section 9.4.

To apply the above result to words and terms, we identify a word w over a finite alphabet A with the vertex-labelled graph G(w) defined in Example 5.2(2), and a term t over a finite signature F with the labelled graph Syn(t). Thus, we define w := G(w) and t := Syn(t) , and just as for graphs, we define MS 1 and MS 2 formulas for words w to be MS formulas interpreted in w and in w respectively, and similarly for terms. Since G(w) and Syn(t) are graphs of bounded degree, the following result is immediate from Theorem 5.22. However, as an example of the proof of Theorem 5.22, we also give a direct proof.

Corollary 5.23 The same properties of words, of terms and of labelled (rooted) trees can be expressed by MS 1 and by MS 2 formulas.

Proof: Let us consider words w over a finite alphabet A and typed MS 2 sentences ϕ over R d m,[K,Λ] with K = A and Λ = ∅. The idea is to replace each edge of G(w) by its head; thus, every edge is encoded by a vertex and every set of edges by a set of vertices. To transform ϕ into an equivalent MS 1 sentence, we change every atomic subformula in 1 (x:e, y:v) into suc(y, x), and every atomic subformula in 2 (x:e, y:v) into y = x; then we drop the types of variables (all variables will denote vertices).

For terms t over a finite signature F we use the same encoding of edges by their heads. Let ϕ be a typed MS 2 sentence over R d m,[K,Λ] with K = F and Λ = [ρ(F )]. To describe the transformation of ϕ it is convenient to use the representation t = N t , son t , (lab f t ) f ∈F , (br i t ) 1≤i≤ρ(F ) , see Example 5.2(3). The atomic subformulas in j (x:e, y:v) are changed as above, with son instead of suc, and every atomic subformula lab i (x:e) is changed into br i (x).

For rooted trees a similar transformation can be used as for terms, and for trees the transformed formula should start by choosing a root (thus turning the tree into a rooted one). We omit the details.

A table comparing the expressive power of MS 1 and MS 2 formulas, and their extensions with cardinality predicates will be given in Section 5.2.7.

Cardinality predicates

We now introduce an extension of monadic second-order logic called counting monadic second-order logic.

Definition 5.24 (Counting monadic second-order logic) For integers p, q with q > p ≥ 0 and q ≥ 2, and for a set variable X, we let Card p,q (X) be a new atomic formula expressing that |X| ≡ p (mod q). We denote by CMS(R, X ) the extension of MS(R, X ) that uses the atomic formulas Card p,q (X) in addition to those previously defined. The notation C r MS will be used (instead of CMS) to specify the sets of formulas written with the set predicates Card p,q such that q ≤ r. Hence C 0 MS, C 1 MS and MS designate the same formulas.

"Monadic second-order logic" (written in full) will refer in the sequel to counting monadic second-order logic as well as to the language defined in Section 5.1.4. The notations MS, C r MS and CMS will specify the absence or the possible use of set predicates Card p,q . For expressing graph properties, the notations C r MS 1 and C r MS 2 will be used in the obvious way. For every r, the same properties of words, of terms and of labelled trees can be expressed by C r MS 1 and by C r MS 2 -formulas, which generalizes41 Corollary 5.23.

It is easy to write, for each nonnegative integer p, a formula in FO(∅, {X}) expressing that a set X has cardinality p. It follows that each atomic formula Card p,q (X), for p = 0, is equivalent to

∃Y [Y ⊆ X ∧ "X -Y has cardinality p" ∧ Card 0,q (Y )].
Hence, without loss of expressive power, we could define CMS formulas by using only the atomic formulas Card 0,q (X) expressing that |X| is a multiple of q. However, having all formulas Card p,q (X) will be useful in some proofs like the one of Lemma 5.38. We now show an example of the use of CMS formulas. 42 Let L be a subset of N k and let Card L (U 1 , . . . , U k ) be the property of subsets U 1 , . . . , U k of a set D that (|U 1 |, . . . , |U k |) ∈ L. The following proposition will help to obtain a logical characterization of recognizable sets of rooted trees (Section 5.5).

Proposition 5.25 If a set L is recognizable in N k , then the property Card L of k-tuples of sets is CMS-expressible.

Proof: We have seen in Section 3.4.8 that Rec(N k ) is the set of finite unions of Cartesian products

L 1 × • • • × L k where L i = {a i + λ • b i | λ ∈ N } for some a i , b i ∈ N . 43 That |U i | belongs to L i means that |U i | = a i if b i = 0 and that |U i | ≥ a i if b i = 1. These properties are first-order expressible. If b i ≥ 2, then |U i | belongs to L i if and only if U i contains a set Y such that |Y | is a multiple of b i and |U i -Y | = a i :
this property is expressible by a C bi MS-formula. The result follows.

Remark 5.26 In the proof of Lemma 5.10 which constructs the relativization of a second-order formula ϕ to a set X, if the formula ϕ contains set predicates Card p,q , we must replace the transformation rules for set quantification by the following ones:

(∀Y. ψ) = ∀Y (∀u(u ∈ Y ⇒ u ∈ X) ⇒ ψ ) (∃Y. ψ) = ∃Y (∀u(u ∈ Y ⇒ u ∈ X) ∧ ψ ).
Hence, we have qh(ϕ ) ≤ qh(ϕ) + 1 (and not qh(ϕ ) = qh(ϕ) as in Lemma 5.10).

CMS formulas versus MS formulas

Every formula ϕ ∈ MS(∅, {X 1 , . . . , X m }) is equivalent to a finite disjunction of conjunctions of conditions of the form |Y 1 ∩ Y 2 ∩ • • • ∩ Y m | = n or |Y 1 ∩ Y 2 ∩ • • • ∩ Y m | > n with n ∈ N and, for each i = 1, . . . , m, the set Y i is either X i or D -X i
where D is the domain of the considered structure (this is proved in [START_REF] Courcelle | The monadic second-order logic of graphs I: Recognizable sets of finite graphs[END_REF] by quantifier elimination). In particular, the property that a set has an even cardinality is not MS-expressible. (Another proof is given in Proposition 7.12 of [*Lib04].) Hence the CMS formulas have strictly more expressive power than the MS formulas. However, they are equally expressive on linearly ordered (and linearly orderable) structures, as we will see next.

Lemma 5.27 For every q ≥ 2, one can construct a formula γ q (X) belonging to MS({≤}, {X}) to express, in every44 linearly ordered set (D, ≤ D ), that the cardinality of a subset of D denoted by X is a multiple of q.

Proof: One writes a formula γ q expressing that, if X is not empty, then there exist sets Y 0 , Y 1 , . . . , Y q-1 forming a partition of X and such that the first element of X is in Y 1 , the last element of X is in Y 0 and for every two elements x, y of X, if x ∈ Y p and y is the successor of x for the restriction to X of the order ≤ D , then y ∈ Y p where p ≡ p + 1 (mod q). Clearly, if

X = {x 1 , . . . , x n } with x k < D x k+1 for all k ∈ [n -1], then Y p = {x i | i ∈ [n], i ≡ p (mod q)} for every p ∈ [0, q -1].
Lemma 5.27 extends to any class C of structures on which a linear order is definable by MS formulas. We now define precisely this notion.

Definition 5.28 (MS-orderable classes of structures)

Let R be a relational signature, let θ 0 ∈ MS(R, {X 1 , . . . , X m }) and θ 1 ∈ MS(R, {X 1 , . . . , X m , x 1 , x 2 }). The pair (θ 0 , θ 1 ) orders (implicitly linearly) a structure S ∈ STR c (R) if the following conditions hold:

S |= (∃X 1 , . . . , X m . θ 0 ) ∧ ∀X 1 , . . . , X m (θ 0 ⇒ θ 1 )
where θ 1 is the formula in MS(R, {X 1 , . . . , X m }) defined as:

∀x. θ 1 (x, x) ∧ ∀x, y(θ 1 (x, y) ∧ θ 1 (y, x) ⇒ x = y) ∧ ∀x, y, z(θ 1 (x, y) ∧ θ 1 (y, z) ⇒ θ 1 (x, z)) ∧ ∀x, y(θ 1 (x, y) ∨ θ 1 (y, x)
). This means that, for every m-tuple (E 1 , . . . , E m ) satisfying θ 0 , the binary relation defined by θ 1 where X 1 , . . . , X m take respectively the values E 1 , . . . , E m is a linear order on D S , and that there is at least one such m-tuple in S.

A set C ⊆ STR c (R) is MS-orderable if there exists a pair (θ 0 , θ 1 ) that orders all its structures. A set of graphs C is MS 1 -orderable (resp. MS 2 -orderable) if the set C (resp. the set C ) is MS-orderable.

It is clear that if (θ 0 , θ 1 ) orders S, then the pair ( θ 1 , θ 1 ) orders the class MOD(∃X 1 , . . . , X m . θ 1 ) that contains S. Hence, θ 1 is enough for ordering a set of structures C because θ 1 can replace θ 0 . However, it is in general more clear to use the conditions on X 1 , . . . , X m defined by a formula θ 0 than by θ 1 .

Proposition 5.29 Let C be an MS-orderable class of concrete R-structures. The CMS-expressible properties of the structures in C are MS-expressible.

Proof: Let (θ 0 (X 1 , . . . , X m ), θ 1 (X 1 , . . . , X m , x 1 , x 2 )) be a pair of formulas that orders the structures of C. Let ϕ ∈ CMS(R, ∅) express some property of the structures of C. We can assume that the variables X 1 , . . . , X m have no occurrence in ϕ and that, for every atomic formula Card p,q (Y ), we have p = 0. For each q, we let γ q be γ q [λx 1 , x 2 • θ 1 / ≤] where γ q is constructed in Lemma 5.27. This formula belongs to MS(R, {X, X 1 , . . . , X m }). For every S ∈ C, for every E 1 , . . . , E m ⊆ D S satisfying θ 0 and for every E ⊆ D S , we have S |= γ q (E, E 1 , . . . , E m ) if and only if |E| is a multiple of q.

We obtain ϕ from ϕ by replacing every atomic formula Card 0,q (Y ) by γ q (Y, X 1 , . . . , X m ) (i.e., by γ q [Y /X], which is the result of the substitution of Y to X in γ q ). We let then ϕ be the formula of MS(R, ∅): Proof: Let T be a rooted tree given by the structure N T , son T where son T (x, y) holds if and only if y is a son of x. We denote by ≥ T the reflexive and transitive closure of son T , cf. Definition 2.13. A partition (N 1 , N 2 , . . . , N d ) of N T is good if no two sons of any node belong to the same set N i ; intuitively it defines a linear order on the sons of each node of T (through the natural order on [d]). If T has outdegree at most d (i.e., if each node has at most d sons) then N T has a good partition in d (possibly empty) sets. From a good partition (N 1 , . . . , N d ) of N T , we can define the following linear order:

∃X 1 , . . . , X m [θ 0 (X 1 , . . . , X m ) ∧ ϕ (X 1 , . . . , X m )]. If S |= ϕ , then S |= θ 0 (E 1 , . . . , E m ) and S |= ϕ (E 1 , . . . , E m ) for some E 1 , . . . , E m ,
x ≤ y if and only if either x ≥ T y or there exist z, x , y such that son T (z, x ), x ≥ T x, son T (z, y ), y ≥ T y, x ∈ N i , y ∈ N j and i < j.

It is not hard to see that ≤ is a linear order on N T ; in fact, it corresponds to the usual preorder tree traversal (for rooted trees for which a linear order is given on the sons of each node). An FO 1 formula θ 0 (X 1 , . . . , X d ) can express that a given d-tuple (N 1 , . . . , N d ) of subsets of N T is a good partition and an MS 1 formula θ 1 (X 1 , . . . , X d , x 1 , x 2 ) can express that x 1 ≤ x 2 holds where X i takes the value N i (for i = 1, . . . , d) and ≤ is defined from (N 1 , . . . , N d ). (One can write θ 1 with the help of the formula ϕ 2 of Proposition 5.11.)

Hence (θ 0 , θ 1 ) defines a linear order of N T (and even a topological order) for every rooted tree T of outdegree at most d. The proof for forests is similar except that in the definition of a good partition, we require that the roots of two trees of the forest do not belong to the same set N i . Then, we let x 1 < x 2 if x 1 and x 2 belong to trees T and T with roots respectively in N i and N j such that i < j. We omit the details.

Corollary 5.31 For each d ∈ N , the class of simple graphs that have a spanning tree of degree at most d is MS 2 -orderable.

Proof: Let G be a simple graph that has a spanning tree of degree at most d. We will define a linear order on V G by means of sets E, R, N 1 , . . . , N d such that:

(1) E is a set of edges forming a spanning tree U of G;

(2) R consists of a unique vertex r;

(3) (N 1 , . . . , N d ) is a good partition of V G where "good" is relative to the rooted tree T := (U, r).

These conditions can be expressed in G by an MS formula, and from (N 1 , . . . , N d ) one obtains a linear order of V G by using Proposition 5.30. For applying it, we need an MS formula for the relation son T in terms of E and r, which can be obtained as described in Example 5.18. From a linear order ≤ on V G , one defines a lexicographic order on V G × V G , whence on E G , since G is assumed to be simple. If G is undirected, we consider an edge {x, y} as a pair (x, y) with

x ≤ y and we use the lexicographic order on

V G × V G . CMS 2 - - CMS 1 MS 2 - - MS 1
Table 5.1: The four monadic second-order languages.

CMS 1 ≡ CMS 2 - MS 1 ≡ MS 2
Table 5.2: The case of simple uniformly k-sparse graphs.

Examples 5.32

(1) The class of simple 3-connected planar graphs is MS 1 -orderable: these graphs have spanning trees of degree at most 3 ( [Bar]), hence they are MS 2orderable. But for planar graphs, MS 2 formulas without free variables denoting edges and sets of edges (cf. the notion of a typed formula defined before Proposition 5.20) can be replaced by MS 1 formulas (cf. Remark 5.21 and Theorem 5.22).

(2) The set of cliques {K n | n ≥ 1} is MS 2 -orderable. It is not MS 1orderable because otherwise the class of finite sets (edgeless graphs) would be MS 1 -orderable and the set predicates Card 0,q (X) would be MS-expressible. We know that this is not the case.

Expressive power of monadic second-order languages

The expressive power of the monadic second-order languages MS 1 , MS 2 , CMS 1 and CMS 2 is compared in Table 5.1: the inclusions represented from bottomup, are proper. The expressive powers of CMS 1 and MS 2 are incomparable. These facts are proved by some examples listed below. They also hold for the expressibility of properties of simple graphs.

For expressing properties of words over a fixed finite alphabet, of terms over a fixed finite signature and of trees of bounded degree, all these four languages are equivalent by Corollaries 5.23 and 5.31. There are some intermediate cases, in particular that of simple uniformly k-sparse graphs (for each fixed k), shown in Table 5.2. The equivalences follow from Theorem 5.22. Tables 5.3 and5 Examples 5.33 The set of odd stars, i.e., of graphs K 1,2n+1 for n ≥ 0, realizes the proper inclusions of Table 5.2. It is uniformly 1-sparse and CMS 1 -definable, but it is not MS 1 -definable, otherwise the even cardinality set predicate would be monadic second-order expressible.

CMS 2 ≡ MS 2 - CMS 1 ≡ MS 1
Table 5.3: The case of joined paths.

CMS 2 ≡ MS 2 - CMS 1 - MS 1
Table 5.4: The case of labelled cliques.

The set of joined paths, i.e., of graphs P n ⊗P m for n, m ≥ 1 is MS 1 -orderable, hence, CMS 1 ≡ MS 1 and CMS 2 ≡ MS 2 for it (i.e., for expressing the properties of its graphs). Its subset {P n ⊗ P n | n ≥ 1} is MS 2 -definable but not MS 1definable (similar proof as for Proposition 5.13(2)).

We let LC be the set of ({a}, ∅)-labelled cliques (a vertex has label a or no label, an edge has no label). It is MS 2 -orderable, hence CMS 2 ≡ MS 2 for it. But its subset K consisting of the labelled cliques that have the same number of unlabelled vertices and of vertices labelled by a is MS 2 -definable but not CMS 1 -definable (by usual arguments).

These examples show that all inclusions of Table 5.1 are proper. The set of odd stars and the set K show that MS 2 and CMS 1 are incomparable (even for expressing properties of simple graphs only).

Monadic second-order logic and recognizability

This section is devoted to the proof of the Recognizability Theorem, a cornerstone of the theory developed in this book. Informally, every CMS-definable set of graphs or of relational structures is recognizable with respect to an appropriate algebra.

The most technical part of the proof (in the next section) is that of the Splitting Theorem for ⊕, the union of disjoint graphs or structures. This theorem says that, for every MS formula ϕ, the set of assignments that satisfy ϕ in the union of two disjoint structures S and T can be determined from the sets of those that satisfy auxiliary formulas of no larger quantifier-height in S and in T . Up to equivalence, there are finitely many formulas of bounded quantifier-height with a fixed set of free variables. If ϕ is a sentence, we obtain a finite set of auxiliary sentences, hence a finite set of properties that is inductive with respect to ⊕ (cf. Section 1.2.3). This theorem generalizes a result by Feferman and Vaught for first-order logic and is a (very) special case of the Composition Theorem by Shelah. (See [*Mak] and [START_REF] Thomas | Ehrenfeucht games, the composition method, and the monadic theory of ordinal words[END_REF] for detailed discussions and consequences of these results). An easy similar result for unary operations defined by quantifier-free formulas without constant symbols, called the Backwards Translation Theorem, yields the Recognizability Theorem for the VR algebra. The proof of that theorem for the HR algebra needs structures with constants (for representing the sources of s-graphs) and presents small technical difficulties. We will actually prove the Recognizability Theorem for a many-sorted algebra of relational structures with constants denoted by STR.

This long section is organized as follows. We first prove the Splitting Theorem for unions of disjoint relational structures, possibly with constants. Next, we define (unary) quantifier-free operations on structures. Initially we mainly consider restricted quantifier-free operations that can only delete constants from their input structures (they cannot delete "ordinary" elements). For them, we then prove the Backwards Translation Theorem. As a motivation for these definitions, we show that the operations of the VR and of the HR algebra are, or can be expressed in terms of, disjoint union and restricted quantifier-free operations. Then, we extend the Splitting Theorem to derived operations (on structures) built with disjoint union and restricted quantifier-free operations. We apply it to the computation of "bounded theories" (see Section 5.3.6 for definitions). Next we define the algebra STR of relational structures, with the operation of disjoint union and the quantifier-free operations, and we prove the Recognizability Theorem for the subalgebra with restricted quantifier-free operations. This restricted form of the theorem yields the cases of the algebras of words and terms, and of the VR and HR algebras of graphs. Finally, we extend the Recognizability Theorem to STR.

The Splitting Theorem for unions of disjoint concrete structures

Throughout this subsection, we assume that R, R , R are relational signatures such that

R 0 = R 0 ∪ R 0 , R 0 ∩ R 0 = ∅ and R + = R + = R + .
Definition 5.34 (Disjoint union of structures, a special case) Let S and T be concrete R -and R -structures respectively, that are disjoint, i.e., such that D S ∩ D T = ∅. Their union45 is the R-structure denoted by S ⊕ T (or by S ⊕ R ,R T if we need to specify R and R ) such that:

D S⊕T := D S ∪ D T , R S⊕T := R S ∪ R T for each R ∈ R + , a S⊕T := a S if a ∈ R 0 a T if a ∈ R 0 .
As for graphs (cf. Definition 2.23), we extend this definition to abstract structures: the disjoint union S ⊕ T of S ∈ STR(R ) and T ∈ STR(R ) is the isomorphism class of S ⊕ T where S and T are any two disjoint concrete structures respectively isomorphic to S and T .

We will consider C r MS formulas of bounded quantifier-height. If r, h ∈ N , S is a relational signature and X is a finite set of first-order and set variables, then we denote by C r MS h (S, X ) the set of formulas of counting monadic secondorder logic over S, with free variables in X , of quantifier-height at most h and written with the set predicates Card p,q (X) for 2 ≤ q ≤ r, 0 ≤ p < q. If r ≤ 1, there are no such predicates and we write MS h instead of C 0 MS h or C 1 MS h . Similarly we write FO h for first-order logic. If h = 0, we obtain quantifier-free formulas: they may have free set variables.

The sets C r MS h (S, X ) are infinite, but they are finite up to logical equivalence (this equivalence is defined at the beginning of Section 5.2), hence we will do as if they were finite. This important point will be discussed in detail in Section 5.6. Furthermore we will write formulas without universal quantifications. A formula of the form ∀ Y 1 , . . . , Y p . ϕ will be replaced by ¬∃ Y 1 , . . . , Y p . ¬ϕ. This transformation modifies neither the variables, nor their number of occurrences nor the quantifier-height. Similarly, we will not use ⇒, ⇔, False but only ∧, ∨, ¬, and True.

Let ϕ be a formula in C r MS h (R, X ) with X = {X 1 , . . . , X m , z 1 , . . . , z n }. For any two disjoint concrete structures S and T as above, we will express the set sat(S ⊕ T, ϕ, (X 1 , . . . , X m ), (z 1 , . . . , z n )) of X -assignments that satisfy ϕ in S ⊕ T (defined in Section 5.1.3; recall that this set is undefined for abstract structures unless m = n = 0) in terms of sets of the forms sat(S, ψ, (X 1 , . . . , X m ), (x 1 , . . . , x k )) and sat(T, θ, (X 1 , . . . , X m ), (y 1 , . . . , y )) for finitely many C r MS formulas ψ and θ of quantifier-height at most that of ϕ, where {x 1 , . . . , x k } and {y 1 , . . . , y } are subsets of {z 1 , . . . , z n }. We will call such an expression a splitting of the set sat(S ⊕T, ϕ, (X 1 , . . . , X m ), (z 1 , . . . , z n )). We will also refer to it as a splitting of ϕ because it is actually a transformation of formulas that does not depend on S and T . For making the proof easier to read, we first consider the case of first-order formulas which is actually of independent interest.

We need more notation. Sequences of pairwise distinct set and first-order variables are denoted respectively by X and z (see the beginning of Section 5.2). These sequences may be empty and are then denoted by ε instead of (). The use of the notation z = x y will assume that x and y have no variable in common (shortly denoted by x ∩ y = ∅, since we also view z as denoting the set of variables occurring in the sequence z).

Let X denote (X 1 , . . . , X m ) and z denote (z 1 , . . . , z n ). If m = 0 (i.e., ϕ has no free set variables), then we will write sat(S, ϕ, z) instead of sat(S, ϕ, ε, z). If n = 0, we will write sat(S, ϕ, X) instead of sat(S, ϕ, X, ε). If m = n = 0 (i.e., ϕ is a sentence), then we will write sat(S, ϕ) instead of sat(S, ϕ, ε, ε).

If z = (z 1 , z 2 , . . . , z n ) and π is a permutation of [n], we let π(z) denote the sequence (z π(1) , z π(2) , . . . , z π(n) ), and similarly for a ∈ D n (where D is any set). If A ⊆ D n , then we define

perm π (A) := {(a π(1) , . . . , a π(n) ) | (a 1 , . . . , a n ) ∈ A} = {π(a) | a ∈ A}.
It follows that if z = (z 1 , . . . , z n ), then:

sat(S, ϕ, π(z)) = perm π (sat(S, ϕ, z)).
If S ⊕ T is a (well-defined) concrete structure and ϕ has its free variables in x y (i.e., in x ∪ y with x ∩ y = ∅), we define

sat(S ⊕ T, ϕ, x; y) ⊆ D |x| S × D |y| T
as the subset of sat(S ⊕ T, ϕ, x y) consisting of its tuples with the first |x| components in D S and the last |y| components in D T . 46 If π is a permutation of [k + ] that applies to a sequence of first-order variables x y = (x 1 , . . . , x k )(y 1 , . . . , y ) = (x 1 , . . . , x k , y 1 , . . . , y ), then we say that it preserves the relative orders of variables in x and in y if π(i) < π(j) whenever, either 1 ≤ i < j ≤ k or k + 1 ≤ i < j ≤ k + . In other words, π interleaves the sequences x and y. Lemma 5.35 We have sat(S ⊕ T, ϕ, z) = perm π (sat(S ⊕ T, ϕ, x; y)) where the union 47 extends to all triples (π, x, y) such that z = π(x y) and π preserves the relative orders of variables in x and in y. 48 Proof: We first observe that if z = π(x y), then perm π (sat(S ⊕ T, ϕ, x; y)) ⊆ perm π (sat(S ⊕ T, ϕ, x y))

= sat(S ⊕ T, ϕ, π(x y))

= sat(S ⊕ T, ϕ, z).

This gives the inclusion from right to left. We now prove the other one.

We let z = (z 1 , . . . , z n ). For 49 a = (a 1 , . . . , a n ) ∈ sat(S ⊕ T, ϕ, z), we let the profile of a be {i ∈ [n] | a i ∈ D S }. For each subset I of [n] of cardinality k ≤ n there exists a unique permutation π I of [n] such that π I (z) = (z i1 , . . . , z i k , z j1 , . . . , z j ) where i 1 , . . . , i k is an increasing enumeration of I, and j 1 , . . . , j is an increasing enumeration of [n] -I (with = n -k). Hence 46 This notation is ambiguous because a structure can be expressed as S ⊕T in several ways. It stands for the precise notation sat(S, T, ϕ, x; y), which is less readable because it does not refer to ⊕. 47 The notation

X = Y 1 • • • Y k means that X = Y 1 ∪ • • • ∪ Y k and that Y 1 , . . . , Y k are pairwise disjoint.
48 In this lemma and the next, x and/or y may be ε. See also Footnote 46. 49 The notation a = (a 1 , . . . , an) for a i ∈ D S⊕T does not assume that a 1 , . . . , an are pairwise distinct.

π -1 I (x y) = z and the permutation π -1

I

preserves the relative orders of variables in x and in y, where x := (z i1 , . . . , z i k ) and y := (z j1 , . . . , z j ). 50Let a = (a 1 , . . . , a n ) belong to sat(S ⊕ T, ϕ, z), and let I be its profile. Then π I (a) = b c where b = (a i1 , . . . , a i k ) ∈ D k S and c = (a j1 , . . . , a j ) ∈ D T (because D S ∩ D T = ∅). It follows that b c ∈ sat(S ⊕ T, ϕ, x; y) where π I (z) = (z i1 , . . . , z i k , z j1 , . . . , z j ) and x := (z i1 , . . . , z i k ) and y := (z j1 , . . . , z j ). Hence a ∈ perm π -1 I (sat(S ⊕ T, ϕ, x; y)). This gives the inclusion from left to right. It remains to check that the union in the righthand side is disjoint.

Since D S ∩ D T = ∅, the profile of a tuple a in perm π (sat

(S ⊕ T, ϕ, x; y)) is {i ∈ [n] | z i ∈ x}.
Observe that the triple (π, x, y) is completely determined by the set x, hence different such triples have different sets x and thus correspond to different profiles of tuples in D n S⊕T . The sets perm π (sat(S ⊕ T, ϕ, x; y)) are therefore pairwise disjoint.

This lemma entails that we need only split the sets sat(S ⊕ T, ϕ, x; y). Lemma 5.36 For every ϕ ∈ FO h (R, x y), there exist p ∈ N and p pairs of formulas (θ i , ψ i ) with θ i ∈ FO h (R , x) and ψ i ∈ FO h (R , y) such that, for all disjoint concrete R -and R -structures, respectively S and T , we have:51 sat(S ⊕ T, ϕ, x; y) = 1≤i≤p sat(S, θ i , x) × sat(T, ψ i , y).

Proof: By induction on the structure of ϕ. We let k := |x| and := |y|, and we let sat denote sat(S ⊕ T, ϕ, x; y). We have the following cases: Case 1: ϕ is True. We take p = 1 and θ 1 , ψ 1 both equal to True.

Case 2: ϕ is s = t (s, t are terms, i.e., variables or constant symbols). We have three subcases:

sat =      sat(S, ϕ, x) × D T if s, t ∈ x ∪ R 0 , 52 D k S × sat(T, ϕ, y) if s, t ∈ y ∪ R 0 , ∅ otherwise,
which give respectively p = 1 and (θ 1 , ψ 1 ) = (ϕ, True) in the first case, p = 1 and (θ 1 , ψ 1 ) = (True, ϕ) in the second case and p = 0 in the last case.

Case 3: ϕ is R(t 1 , . . . , t n ). We have again three subcases:

sat =      sat(S, ϕ, x) × D T if t 1 , . . . , t n ∈ x ∪ R 0 , D k S × sat(T, ϕ, y) if t 1 , . . . , t n ∈ y ∪ R 0 , ∅ otherwise,
which give the same pairs (θ i , ψ i ) as in the previous case.

Case 4: ϕ is ϕ 1 ∨ ϕ 2 . We have sat = sat(S ⊕ T, ϕ 1 , x; y) ∪ sat(S ⊕ T, ϕ 2 , x; y).

The induction hypothesis yields the result.

Case 5: ϕ is ϕ 1 ∧ ϕ 2 . In this case53 : sat = sat(S ⊕ T, ϕ 1 , x; y) ∩ sat(S ⊕ T, ϕ 2 , x; y).

We note that if

A i , A j ⊆ D k S and B i , B j ⊆ D T , then 1≤i≤p A i × B i ∩ 1≤j≤p A j × B j = 1≤i≤p 1≤j≤p A i ∩ A j × B i ∩ B j .
Hence if (θ i , ψ i ) i∈[p] is associated by the induction hypothesis with ϕ 1 and (θ j , ψ j ) j∈[p ] with ϕ 2 , we get for ϕ the family

(θ i ∧ θ j , ψ i ∧ ψ j ) (i,j)∈[p]×[p ] .
Case 6: ϕ is ¬ϕ 1 . We have

sat = (D k S × D T ) -sat(S ⊕ T, ϕ 1 , x; y)
and, by using induction, sat(S ⊕ T, ϕ 1 , x; y) = 1≤i≤p sat(S, θ i , x) × sat(T, ψ i , y).

For subsets A i of D k S and B i of D T , where 1 ≤ i ≤ p, we have:

(D k S × D T ) - 1≤i≤p A i × B i = I⊆[p] ( i∈I (D k S -A i )) × ( j∈[p]-I (D T -B j )).
It follows that:

sat = I⊆[p] sat(S, i∈I ¬θ i , x) × sat(T, j∈[p]-I ¬ψ j , y)
where

i∈J α i is replaced by True if J = ∅.
In the particular case where ϕ is ¬True (which is equivalent to False) this computation yields p = 2, but we can also take p = 0.

Case 7: ϕ is ∃u. ϕ 1 . We have:

sat = pr 1 (sat(S ⊕ T, ϕ 1 , xu; y)) ∪ pr 2 (sat(S ⊕ T, ϕ 1 , x; yu))
where

pr 1 : (D k+1 S × D T ) → (D k S × D T )
is the projection that "eliminates" the (k + 1)-th component and pr 2 : (D k S × D +1 T ) → (D k S × D T ) similarly "eliminates" the last one.

We have by induction:

sat(S ⊕ T, ϕ 1 , xu; y) = 1≤i≤p sat(S, θ i , xu) × sat(T, ψ i , y).
Note that:

pr 1 (sat(S, θ i , xu) × sat(T, ψ i , y)) = sat(S, ∃u. θ i , x) × sat(T, ψ i , y).
We have also by induction:

sat(S ⊕ T, ϕ 1 , x; yu) = 1≤j≤p sat(S, θ j , x) × sat(T, ψ j , yu),
and we have:

pr 2 (sat(S, θ j , x) × sat(T, ψ j , yu)) = sat(S, θ j , x) × sat(T, ∃u. ψ j , y).
It follows that sat(S ⊕ T, ∃u. ϕ 1 , x; y) = 1≤i≤p sat(S, ∃u. θ i , x) × sat(T, ψ i , y) ∪ 1≤j≤p sat(S, θ j , x) × sat(T, ∃u. ψ j , y).

Using induction, we see that qh(θ i ), qh(ψ i ) ≤ qh(ϕ 1 ) and qh(θ j ), qh(ψ j ) ≤ qh(ϕ 1 ). Hence we have qh(ψ) ≤ 1 + qh(ϕ 1 ) = qh(ϕ) where ψ is any of ∃u. θ i , ψ i , θ j , or ∃u. ψ j . This completes the proof.

We can now state the Splitting Theorem for first-order formulas (with R, R and R as at the beginning of this subsection).

Proposition 5.37 For every ϕ ∈ FO h (R, z), there exists a finite family of 5-tuples (π i , θ i , ψ i , x i , y i ) 1≤i≤p such that, for all disjoint concrete R -and Rstructures, respectively S and T , we have:

sat(S ⊕ T, ϕ, z) = 1≤i≤p perm πi (sat(S, θ i , x i ) × sat(T, ψ i , y i ))
where, for each i, θ i ∈ FO h (R , x i ), ψ i ∈ FO h (R , y i ), z = π i (x i y i ) and π i is a permutation that preserves the relative orders of variables in x i and in y i .

Proof: We use Lemma 5.35, the observation that perm π (A ∪ B) = perm π (A) ∪ perm π (B), and a stronger version of Lemma 5.36 where the union is disjoint, that we establish as follows.

Assume we have an expression of sat(S ⊕ T, ϕ, x; y) as in Lemma 5.36 in terms of θ i and ψ i for p ≥ 2. For every nonempty subset I of [p] we let θ I be sat(S, θ I , x) × sat(T, ψ J , y).

Lemma 5.35 yields sat(S ⊕ T, ϕ, z) = perm π (sat(S ⊕ T, ϕ, x; y)) where the disjoint union extends to all triples (π, x, y) such that z = π(x y) and π preserves the relative orders of variables in x and in y. From the above equality we get: Our next objective is to extend this proposition to monadic second-order logic. Let ϕ belong to C r MS h (R, X ∪ x y) where X = (X 1 , . . . , X m ), x = (x 1 , . . . , x k ) and y = (y 1 , . . . , y ). If S, T are disjoint concrete R -and Rstructures respectively, we let sat(S ⊕ T, ϕ, X, x; y) be the set of tuples (A, a, b)

perm π (sat(S ⊕ T, ϕ, x; y)) = I∩J =∅, I∪J⊆[p]
such that A i ⊆ D S ∪ D T for i ∈ [m], a i ∈ D S for i ∈ [k], b i ∈ D T for i ∈ [ ]
A B := (A 1 ∪ B 1 , . . . , A m ∪ B m , a 1 , . . . , a k , b 1 , . . . , b ). If A ⊆ P(D) m × D k and B ⊆ P(D ) m × D , we let A B := { A B | A ∈ A, B ∈ B} ⊆ P(D ∪ D ) m × D k × D .
We will also need to permute first-order components of assignments. If A ⊆ P(D) m × D n and π is a permutation of [n], then we let:

perm π ( A) := {(A 1 , . . . , A m , a π(1) , . . . , a π(n) ) | (A 1 , . . . , A m , a 1 , . . . , a n ) ∈ A}.
Hence, if X = (X 1 , . . . , X m ) and z = (z 1 , . . . , z n ), we have: sat(S, ϕ, X, π(z)) = perm π (sat(S, ϕ, X, z)).

The following lemma extends Lemma 5.36.

Lemma 5.38 For every formula ϕ in C r MS h (R, X ∪ x y), there exists a family (θ i , ψ i ) 1≤i≤p of pairs of formulas such that θ i ∈ C r MS h (R , X ∪ x), ψ i ∈ C r MS h (R , X ∪ y) and for all disjoint concrete R -and R -structures, respectively S and T , we have: sat(S ⊕ T, ϕ, X, x; y) = 1≤i≤p sat(S, θ i , X, x) sat(T, ψ i , X, y).

Proof: We let as above m := |X|, k := |x| and := |y|. We first prove a weak version where is replaced by ∪, by induction on the structure of ϕ. Many steps will be as in the proof of Lemma 5.36. We let sat denote sat(S ⊕ T, ϕ, X, x; y).

Case 1: ϕ is True or s = t or R(t 1 , . . . , t n ). If ϕ is True, we have p = 1 and θ 1 , ψ 1 both equal to True as in the first case of Lemma 5.36. If ϕ is s = t, we have:

sat =      sat(S, ϕ, X, x) (P(D T ) m × D T ) if s, t ∈ x ∪ R 0 , (P(D S ) m × D k S ) sat(T, ϕ, X, y) if s, t ∈ y ∪ R 0 , ∅ otherwise,
and similarly if ϕ is R(t 1 , . . . , t n ), with t 1 , . . . , t n replacing s, t. This gives the same splittings of sat as in Cases 2 and 3 of Lemma 5.36.

Case 2: ϕ is t ∈ Y (and Y belongs to X). Then:

sat = sat(S, ϕ, X, x) (P(D T ) m × D k T ) if t ∈ x ∪ R 0 , (P(D S ) m × D S ) sat(T, ϕ, X, y) if t ∈ y ∪ R 0 ,
which gives the same first two forms of splitting of the case where ϕ is s = t (see Case 1).

Case 3: ϕ is Card n,q (Y ) (with Y in X).

We recall that Card n,q (C) means |C| ≡ n (mod q). For every set C = A B we have Card n,q (C) ⇐⇒ Card i,q (A) ∧ Card j,q (B) where the disjunction extends to all pairs (i, j) such that 0 ≤ i, j < l and i + j ≡ n (mod q). It follows that:

sat = sat(S, Card i,q (Y ), X, x) sat(T, Card j,q (Y ), X, y)
where the union extends to all pairs (i, j) as above.

Case 4: ϕ is ϕ 1 ∨ ϕ 2 . As in Case 4 of Lemma 5.36.

Case 5: ϕ is ϕ 1 ∧ ϕ 2 . We note that for A i , A j ⊆ P(D S ) m × D k S and B i , B j ⊆ P(D T ) m × D T we have:

( 1≤i≤p A i B i ) ∩ ( 1≤j≤p A j B j ) = 1≤i≤p 1≤j≤p ( A i ∩ A j ) ( B i ∩ B j )

MONADIC SECOND-ORDER LOGIC AND RECOGNIZABILITY 367

because for all i, j as above:

( A i B i ) ∩ ( A j B j ) = ( A i ∩ A j ) ( B i ∩ B j ).
Let us prove this (dropping the subscripts).

If (E, d) ∈ ( A B)∩( A B ), then (E, d) = A B = A B for some A ∈ A, A ∈ A , B ∈ B and B ∈ B . Since D S ∩ D T = ∅, this implies that, if E = (E 1 , . . . , E m ) and d = a b with a ∈ D k S and b ∈ D T , then A = A = (E 1 ∩D S , • • • , E m ∩D S , a) and similarly B = B . Hence (E, d) ∈ ( A ∩ A ) ( B ∩ B ),

and we have (

A B) ∩ ( A B ) ⊆ ( A ∩ A ) ( B ∩ B ).
The other inclusion is obvious.

Hence, we have the same splitting as in Case 5 of Lemma 5.36.

Case 6: ϕ is ¬ϕ 1 . As in Case 6 of Lemma 5.36 with the following fact:

(P(D S ) m × D k S ) (P(D T ) m × D T ) - 1≤i≤p A i B i = I⊆[p] i∈I ((P(D S ) m × D k S ) -A i ) j∈[p]-I ((P(D T ) m × D T ) -B j ) .
Case 7: ϕ is ∃u. ϕ 1 . As in Case 7 of Lemma 5.36.

Case 8: ϕ is ∃ U. ϕ 1 . Let (θ i , ψ i ) 1≤i≤p be associated with ϕ 1 , by induction. We This gives the desired result with the family (∃U. θ i , ∃U. ψ i ) 1≤i≤p .

We have constructed splittings in terms of unions. The stronger statement with disjoint union is obtained as in the proof of Proposition 5.37.

The final word is given by the following theorem which extends Proposition 5.37 to monadic second-order formulas.

Theorem 5.39 (Splitting Theorem, the basic case) Let R, R and R be relational signatures such that R

= R ∪ R , R 0 ∩ R 0 = ∅ and R + = R + = R + .
For every r and h in N and every formula ϕ in C r MS h (R, X ∪ z), there exists a finite family of 5-tuples (π i , θ i , ψ i , x i , y i ) 1≤i≤p such that, for all disjoint concrete R -and R -structures, respectively S and T , we have:

sat(S ⊕ T, ϕ, X, z) = 1≤i≤p perm πi (sat(S, θ i , X, x i ) sat(T, ψ i , X, y i ))
where, for each i,

θ i ∈ C r MS h (R , X∪x i ), ψ i ∈ C r MS h (R , X∪y i ), z = π i (x i y i )
and π i is a permutation that preserves the relative orders of variables in x i and in y i .

Proof: As in Lemma 5.35, and with the same proof, we have sat(S ⊕ T, ϕ, X, z) = perm π (sat(S ⊕ T, ϕ, X, x; y))

where the union extends to all triples (π, x, y) such that z = π(x y) and π preserves the ordering of variables in x and in y. Lemma 5.38 expresses each set sat(S⊕T, ϕ, X, x; y) as a disjoint union of sets sat(S, θ i , X, x) sat(T, ψ i , X, y). Since perm π ( A B) = perm π ( A) perm π ( B) for A, B ⊆ P(D) m × D n , we get the stated result.

The family (π i , θ i , ψ i , x i , y i ) 1≤i≤p will be called a splitting of ϕ relative to the operation of disjoint union.

Remarks 5.40

(1) The proof of Theorem 5.39 is effective. It gives an algorithm that constructs from ϕ, X and z a splitting of ϕ relative to ⊕. This construction depends on R, R 0 and R 0 . The integers r and h can be taken as the minimal ones such that ϕ ∈ C r MS h (R, X ∪ z).

(2) If z is empty, then we have a simpler formulation of Theorem 5.39 that avoids permutations of first-order variables:

sat(S ⊕ T, ϕ, X) = 1≤i≤p sat(S, θ i , X) sat(T, ψ i , X).
If ϕ is a sentence, we have an even simpler formulation which is also meaningful for abstract structures S and T :54 S ⊕ T |= ϕ if and only if there exists i such that S |= θ i and T |= ψ i , and furthermore, if it exists, this index is unique (which corresponds to the disjoint union used in the theorem). We now develop an example relative to cographs. These graphs are constructed from isolated vertices by disjoint union and complete join ⊗ (see Section 1.1.2). Case 3 (for ⊕): ϕ is edg(s, t); if sat = sat(G ⊕ H, ϕ, x; y) then:

sat =      sat(G, ϕ, x) × V |y| H if s, t ∈ x, V |x| G × sat(H, ϕ, y) if s, t ∈ y, ∅ otherwise (i.e., if s ∈ x and t ∈ y or if s ∈ y and t ∈ x).
For the operation ⊗, we need only modify Case 3 as follows:

Case 3 (for ⊗): ϕ is edg(s, t); if sat = sat(G ⊗ H, ϕ, x; y) then: sat(H, True, x) × sat(G, True, y). 55 (5.1)

sat =        sat(G, ϕ, x) × V |y| H if s, t ∈ x, V |x| G × sat(H, ϕ, y) if s, t ∈ y, V |x| G × V |y| H if s ∈ x
All other cases are as in Lemma 5.36. We now give a complete construction for the first-order formula ϕ(x, y) defined as edg(x, y) ∨ ϕ 1 (x, y) where ϕ 1 (x, y) is ∃z(edg(x, z) ∧ edg(y, z)). We have:

sat(G ⊕ H, ϕ, xy) = sat(G ⊕ H, edg(x, y), xy) ∪ sat(G ⊕ H, ϕ 1 , xy).
In order to compute sat(G ⊕ H, ϕ 1 , xy), we let ϕ 2 (x, y, z) denote edg(x, z) ∧ edg(y, z). For all disjoint sequences of variables u and v such that u v enumerates the free variables of ϕ 2 , we have:

sat(G ⊕ H, ϕ 2 , u; v) = sat(G ⊕ H, edg(x, z), u; v) ∩ sat(G ⊕ H, edg(y, z), u; v).
There are 8 (= 2 3 ) types of splitting for ϕ 2 since this formula has three free variables. We get in particular:

sat(G ⊕ H, ϕ 2 , xyz; ε) = sat(G ⊕ H, edg(x, z), xyz; ε) ∩ sat(G ⊕ H, edg(y, z), xyz; ε) = sat(G, edg(x, z), xyz) ∩ sat(G, edg(y, z), xyz). 55 Note that sat(G, True, x) is empty if G = ∅.
This set can be written as a disjoint union of sets like sat(G, edg(x, z)∧¬edg(y, z), xyz) but it is simpler to write it:

sat(G ⊕ H, ϕ 2 , xyz; ε) = sat(G, ϕ 2 , xyz).
By a similar computation, we get

sat(G ⊕ H, ϕ 2 , ε; xyz) = sat(H, ϕ 2 , xyz).
The six other cases are:

sat(G ⊕ H, ϕ 2 , xy; z), sat(G ⊕ H, ϕ 2 , xz; y), sat(G ⊕ H, ϕ 2 , x; yz), sat(G ⊕ H, ϕ 2 , yz; x), sat(G ⊕ H, ϕ 2 , y; xz) and sat(G ⊕ H, ϕ 2 , z; xy),
and each of them yields the empty set. It follows that: The unions in the first equality are not disjoint (are not ) because edg(x, y) and ϕ 1 (x, y) may hold simultaneously.

sat(G ⊕ H, ϕ 1 , xy) = sat(G, ϕ 1 , xy) sat(H, ϕ 1 , xy).
For the sake of comparison, we now consider the splitting of the same formula relative to ⊗. We have

sat(G ⊗ H, ϕ, xy) = sat(G ⊗ H, edg(x, y), xy) ∪ sat(G ⊗ H, ϕ 1 , xy). (5.2)
The splitting of sat(G⊗H, edg(x, y), xy) has been given above in Equality (5.1). The one for ϕ 2 yields again 8 cases. Similar to ⊕ we have:

sat(G ⊗ H, ϕ 2 , u; v) = sat(G ⊗ H, edg(x, z), u; v) ∩ sat(G ⊗ H, edg(y, z), u; v).

Quantifier-free transformations of structures

The transformation of a graph into its edge-complement defined in Chapter 1, Section 1.7.1, is an example of a quantifier-free transformation of relational structures. We now give the formal definition, for which we need some notation.

Let R and R be relational signatures and X be a set of first-order variables. Then QF(R, X ) denotes the set of quantifier-free formulas written with R and free variables in X . (It is equal to

C 0 MS 0 (R, X ) = FO 0 (R, X )).
Our objective is to specify functions : STR(R) → STR(R ) by formulas in QF(R, X ). A transduction is a subset of STR(R)×STR(R ) for some relational signatures R and R , that we consider also as a mapping from STR(R) to P(STR(R )). Monadic second-order transductions (defined in Section 1.7) will be studied in Chapter 7. In this chapter, we will consider particular monadic second-order transductions that are total functions : STR(R) → STR(R ) and that are specified by quantifier-free formulas. We will call them operations because they will mainly be used as unary operations of algebras of graphs and relational structures.

Definition 5.42 (Quantifier-free operations)

We first consider the particular but already useful case where R 0 = ∅. A quantifier-free operation definition scheme 57 (a QFO definition scheme in short) of type R → R is a tuple of quantifier-free formulas D = δ, (θ R ) R∈R such that δ ∈ QF(R, {x}) and θ R ∈ QF(R, {x 1 , . . . , x ρ(R) }) for every R ∈ R . We call δ the domain formula of D and the formulas θ R its relation formulas.

The associated mapping f : STR c (R) → STR c (R ), denoted by D, is defined as follows. If S is a concrete R-structure, then f (S) is the concrete R -structure such that:

D f (S) := sat(S, δ, x), R f (S) := sat(S, ϕ R , (x 1 , . . . , x ρ(R) )) where ϕ R is the formula θ R (x 1 , . . . , x ρ(R) ) ∧ δ(x 1 ) ∧ • • • ∧ δ(x ρ(R) ).
If S is isomorphic to S, then D(S ) and D(S) are isomorphic. Hence the mapping D is well defined : STR(R) → STR(R ), i.e., on abstract structures. We call it a quantifier-free operation, but this is only a special case, the general definition will be given shortly after some remarks and examples.

We have D(∅) = ∅ (where ∅ denotes the empty structure of any signature without constants) and we may have D(S) = ∅ for S nonempty.

The mapping G → G where G is the edge-complement of a simple undirected loop-free graph G (see Example 1.30) is clearly a quantifier-free operation. The same holds for the slightly different edge-complement considered in Proposition 2.105 and for the mapping w → w where w is the mirror image of a word w: δ(x) is True, θ suc (x 1 , x 2 ) is suc(x 2 , x 1 ), and θ laba (x 1 ) is lab a (x 1 ).

57 More powerful quantifier-free definition schemes, QF-definition schemes in short, will be defined in Chapter 7, Definition 7.2.

We now extend the notion of QFO definition scheme to the case where R has constants. A QFO definition scheme of type R → R is a tuple of formulas D = δ, (θ R ) R∈R + , (κ c,d ) c∈R0,d∈R 0 where the formulas δ, θ R are as in the above special case and the formulas κ c,d are quantifier-free sentences over R called the constant defining sentences, intended to express that d f (S) = c S whenever S |= κ c,d . Hence, R 0 must be empty if R 0 is empty.

In order to ensure that f (S) = D(S) is a well-defined structure in STR c (R ) for every S ∈ STR c (R), we require that the sentences e∈R0 κ e,d , κ c,d ⇒ δ(c) and κ c,d ⇒ ¬κ c ,d are true in every structure S in STR(R), for all d ∈ R 0 and all c, c in R 0 with c = c . The first of these sentences (or rather its validity in S) ensures that every constant d f (S) for d in R is defined as the value in S of some constant symbol e belonging to R 0 ; the sentences κ c,d ⇒ δ(c) ensure that the interpretation c S of c ∈ R 0 intended to be the interpretation of d in f (S) is actually in the domain of f (S); the last sentences ensure that d f (S) is defined as c S for at most one c. These sentences ensure collectively that each d in R 0 has a unique well-defined interpretation in D(S) for every S ∈ STR(R).

By a quantifier-free operation (a QF operation in short), we mean a function D : STR c (R) → STR c (R ) (hence also : STR(R) → STR(R )) defined by a QFO definition scheme D. The set of these operations is denoted by F QF 1 . It is the set of unary operations of a functional signature F QF to be defined below in Definition 5.62.

We say that a QFO definition scheme D and the corresponding operation D are domain preserving if the domain formula δ(x) is equivalent to True. This implies that D(S) has the same domain as S for every structure S. The following notion is slightly more general (this technicality will be useful to deal with operations like the parallel-composition of s-graphs represented by relational structures with constants). We say that D and D are quasi-domain preserving if the domain formula is equivalent to a formula of the form c∈R0 (α c ⇒ x = c), where α c is a quantifier-free sentence. This implies that D For qualifying operations, we will shorten "domain preserving quantifierfree" into DP-QF and "quasi-domain preserving quantifier-free" into QDP-QF. The corresponding definitions schemes will be called the DP-QFO and the QDP-QFO definition schemes.

Remarks 5.43

(1) The conditions to be verified by the constant defining sentences of a QFO definition scheme are decidable because they are expressed by quantifierfree sentences. Such a sentence is false in some R-structure if and only if it is false in some finite R-structure, if and only if it is false in an R-structure whose domain has cardinality at most |R 0 | (as the reader can check easily, and much quicker than by looking into [*BörGG] or Chapter 9 of [*BradMan]; this is true even if R 0 = ∅). It follows that the notion of a QFO definition scheme is effective, that is, one can decide if it satisfies the required semantical conditions. For a similar reason, one can decide if two quantifier-free formulas are equivalent. Hence, one can decide if two QFO definition schemes define the same function on all concrete structures (which necessarily implies that they define the same function on all abstract structures).

Furthermore, for each pair (R, R ) there are finitely many QF operations of type R → R . That is because every quantifier-free formula is a Boolean combination of atomic formulas. Since there are finitely many atomic formulas (with variables in a fixed finite set X ), and since every quantifier-free formula is equivalent to one in disjunctive normal form, there are finitely many pairwise inequivalent quantifier-free formulas (with variables in X ). This will be discussed in detail below in Section 5.6, Corollary 5.95.

A quantifier-free formula with one free variable x is false in some R-structure if and only if it is false in an R-structure whose domain has cardinality at most |R 0 | + 1 (immediate from the above similar remark for sentences). Hence the notion of a DP-QFO definition scheme is also effective. Since there are only finitely many pairwise inequivalent sentences α c , there are only finitely many pairwise inequivalent formulas of the form c∈R0 (α c ⇒ x = c), and for each of these formulas it can be decided whether it is equivalent to the domain formula δ(x). This shows the effectivity of the notion of a QDP-QFO definition scheme.

(2) In Definition 5.42, we do not require that the input structure S is constant-separated, i.e., that c S = c S for every two different constant symbols c and c . But even if S is constant-separated, a definition scheme may construct f (S) with d f (S) = d f (S) where d = d . In order to ensure that D transforms constant-separated structures into constant-separated ones (which will be useful for dealing with s-graphs), we need only require additionally that the sentences κ c,d ⇒ ¬κ c,d are true in every S ∈ STR(R), for all c ∈ R 0 and all d, d ∈ R 0 with d = d. This can be decided by the observations made in [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF].

(3) Let us comment about the role of constant symbols. Consider a constant symbol a and a binary relation R. Let f be the QF operation that transforms an {R, a}-structure S by adding to R S all pairs (d, d ) such that (d, a S ) and (a S , d ) are in R S . It is not a QF operation over {R, a} * -structures, i.e., over {R, a}-structures where a is replaced by a unary relation lab a (cf. Section 5.1.5) to be interpreted by a singleton set. We use constants in relational structures in order to handle such cases.

Example 5.44 The natural inclusion

ι R,R : STR c (R) → STR c (R ), where 58 R ⊆ R and R 0 = R 0 , is defined by D := True, (θ R ) R∈R + , (κ c,d ) c,d∈R0 such that: θ R is R(x 1 , . . . , x ρ(R) ) if R ∈ R + , False if R ∈ R + -R + ,
and, for all c, d ∈ R 0 :

κ c,d is True if d = c, False if d = c. Thus, R D(S) = R S for R ∈ R + and R D(S) = ∅ for R ∈ R + -R + ,

and D(S) has the same constants as S.

We recall that the union S ⊕ T of disjoint structures S in ST R c (R ) and T in ST R c (R ) has been defined under the condition that R and R have the same relation symbols (of positive arity) and no constant symbol in common. We now waive the former condition (we still assume that R 0 ∩ R 0 = ∅) and we define:

S ⊕ R ,R T := ι R ,R 1 (S) ⊕ ι R ,R 1 (T )
where

R 1 := R 0 ∪ R + ∪ R + and R 1 is defined similarly as R 0 ∪ R + ∪ R + .
We obtain thus a concrete (R ∪R )-structure S ⊕T . We will see that this extended union still satisfies the Splitting Theorem. This extension also applies to the disjoint union of abstract structures, that is then a derived operation expressed in terms of the disjoint union of Definition 5.34 and the QF operations of Definition 5.42.

We will frequently write ⊕ for ⊕ R ,R . The natural inclusion is actually an inverse of the following reduction operation 59 . If R ⊆ R, the operation fg R-R : STR c (R) → STR c (R ) deletes the relations and constants in R -R . Its definition scheme is easy to write. As for the natural inclusion, it is domain preserving. We will write fg R for fg {R} .

Here is an important example of a QDP-QF operation. Formally, for S ∈ STR c (R), we define fuse a,b (S) as the concrete structure S such that:

D S := if a S = b S then D S else D S -{b S }.
For every d ∈ R 0 :

d S := if d S = b S then a S else d S ,
or equivalently:

d S := if a S = b S ∨ d S = b S then d S else a S .
59 In Model Theory, fg R-R (S) is called a reduct of S. This operation generalizes the source forgetting operation on s-graphs (Definition 2.30, Section 2.3.1). This mapping can be defined by the QFO definition scheme δ,

(θ R ) R∈R+ , (κ c,d ) c,d∈R0 such that δ(x) is a = b ∨ (a = b ∧ x = b) and: κ a,d is True if d ∈ {a, b}, κ c,d is False if d ∈ {a, b} and c ∈ R 0 -{a}, κ a,d is d = b if d ∈ R 0 -{a, b}, κ d,d is d = b if d ∈ R 0 -{a, b}, κ c,d is False if d ∈ R 0 -{a, b} and c ∈ R 0 -{a, d}.
Note that κ b,b is False. It remains to define the formulas θ R (x 1 , . . . , x ρ(R) ) for R ∈ R + . We first define them with existential quantifications for the purpose of clarity. Then we will eliminate these quantifications. We let n

= ρ(R). The relation R fuse a,b (S) is defined in S by δ(x 1 ) ∧ • • • ∧ δ(x n ) ∧ ψ R (x 1 , . . . , x n ) where ψ R (x 1 , . . . , x n ) is: ∃ y 1 , . . . , y n [R(y 1 , . . . , y n ) ∧ 1≤i≤n (y i = b ∧ x i = a) ∨ (y i = b ∧ x i = y i )].
This formula is equivalent to:

I⊆[n] ∃ y 1 , . . . , y n [R(y 1 , . . . , y n ) ∧ ( i∈I y i = b ∧ x i = a) ∧ ( i / ∈I y i = b ∧ x i = y i )],
hence to:

I⊆[n] [R(x I 1 , . . . , x I n ) ∧ ( i∈I x i = a) ∧ ( i / ∈I x i = b)],
where x I i stands for b if i ∈ I and for x i if i / ∈ I. Hence we obtain a quantifier-free formula

θ R (x 1 , . . . , x n ) equivalent to ψ R (x 1 , . . . , x n ).
The operation fuse a,b is QDP-QF: an element is deleted only if it is the value of b and the domain formula of its definition scheme is equivalent to Note that the operations fuse a,b and fuse b,a are the same on abstract structures but not on concrete ones, because if a S = b S in the concrete input structure S, then b S is deleted by the former whereas a S is deleted by the latter.

Backwards translation with respect to QF operations

The main result of this section is the Backwards Translation Theorem (Theorem 5.47). We first prove a weak form of it that entails the Recognizability Theorem for the VR algebra.

Proposition 5.46 Let D be a DP-QFO definition scheme of type R → R where R 0 = ∅. For every formula ϕ in C r MS h (R , X ∪ y), there exists a formula µ in C r MS h (R, X ∪ y) such that, for every concrete R-structure S:60 sat( D(S), ϕ, X, y) = sat(S, µ, X, y).

Proof: We have D S = D D(S) . Hence, when constructing µ intended to define in S the assignments that satisfy ϕ in D(S), we need not put in µ the condition that the considered values assigned to variables are in the domain of D(S). This will be necessary in other cases to be considered later. The proof is by induction on the structure of ϕ.

Case 1: ϕ is True or u = v or u ∈ Y or Card p,q (Y ), with u, v in y and Y in X.

We take µ equal to ϕ.

Case 2: ϕ is R(u 1 , . . . , u n ) with R ∈ R + and u 1 , . . . , u n ∈ y.

The variables u 1 , . . . , u n need not be pairwise distinct. We have R D(S) = sat(S, θ R , ε, (x 1 , . . . , x n )) hence, by Lemma 5.8:

sat( D(S), ϕ, X, y) = sat(S, θ R [u 1 /x 1 , . . . , u n /x n ], X, y)

and we take µ equal to θ R [u 1 /x 1 , . . . , u n /x n ]. This formula is quantifierfree.

Case 3:

ϕ is ϕ 1 ∨ ϕ 2 or ϕ 1 ∧ ϕ 2 or ¬ϕ 1 .
Assuming µ 1 , µ 2 associated with ϕ 1 , ϕ 2 by induction, we take µ to be µ 1 ∨ µ 2 or µ 1 ∧ µ 2 or ¬µ 1 respectively.

Case 4: ϕ is ∃u. ϕ 1 or ∃U. ϕ 1 .

Assuming µ 1 associated with ϕ 1 we take µ to be respectively ∃u. µ 1 or ∃U. µ 1 . The correctness of this step follows from the fact that D is domain preserving.

We now consider a QDP-QFO definition scheme D. For every set variable X, we denote by δ(X) the quantifier-free formula c∈R0 (α c ⇒ c / ∈ X). It is clear that for every subset A of D S , we have S |= δ(A) if and only if A ⊆ D D(S) .

Theorem 5.47 (Backwards Translation Theorem)

(1) Let D be a QDP-QFO definition scheme of type R → R . For every r, h ∈ N and every formula ϕ in C r MS h (R , X ∪ y), there exists a formula ψ in C r MS h (R, X ∪ y) such that, for every concrete R-structure S, we have: sat( D(S), ϕ, X, y) = sat(S, ψ, X, y).

(2) If D is a QFO definition scheme, then this statement holds for ϕ in FO h (R , y) with ψ in FO h (R, y).

Proof: [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] The definition of ψ will use an auxiliary formula µ associated with ϕ by the same induction as in Proposition 5.46. It satisfies the following property: sat( D(S), ϕ, X, y) is the set of all elements of sat(S, µ, X, y) that are (X ∪ y)assignments in D(S), or in other words sat( D(S), ϕ, X, y) = sat(S, µ, X, y) ∩ sat( D(S), True, X, y). In all cases, µ is quantifier-free.

Case 1: ϕ is True or Card p,q (Y ) or s ∈ Y or s = t, with s, t ∈ y ∪ R 0 and Y ∈ X. If ϕ is True or Card p,q (Y ), then µ is ϕ. If ϕ is s ∈ X and s belongs y, then µ is ϕ; if ϕ is s ∈ X and s = d ∈ R 0 , then µ is c∈R0 (κ c,d ∧ c ∈ X).
Case 2: ϕ is R(t 1 , . . . , t n ) with R ∈ R + and t 1 , . . . , t n ∈ y ∪ R 0 .

For readability, we only consider the case where n = 2, and we let ϕ be R(s, t) with s and t in y ∪ R 0 .

If

s, t ∈ y, then µ is θ R [s/x 1 , t/x 2 ]. If s ∈ y and t = d ∈ R 0 , then µ is c∈R0 κ c,d ∧ θ R [s/x 1 , c/x 2 ] .
The case where t ∈ y and s

= d ∈ R 0 is similar. If s = d ∈ R 0 and t = d ∈ R 0 , then we define µ as c,c ∈R0 (κ c,d ∧ κ c ,d ∧ θ R [c/x 1 , c /x 2 ]
). The construction of µ in the general case is similar, but lengthy to write down. In all cases the formula µ is quantifier-free, because, in particular, the formulas θ R are quantifier-free.

Case 3: ϕ is ϕ 1 ∧ ϕ 2 or ϕ 1 ∨ ϕ 2 or ¬ϕ 1 .
As in Proposition 5.46.

Case 4: ϕ is ∃u. ϕ 1 or ∃U. ϕ 1 .

Assuming that µ 1 has been constructed from ϕ 1 by induction, we take µ to be respectively ∃u(δ(u) ∧ µ 1 ) or ∃U (δ(U ) ∧ µ 1 ). This definition is correct (using induction) and µ has quantifier-height 1 + qh(µ 1 ) which is at most 1 + qh(ϕ 1 ) = qh(ϕ), because the formulas δ(u) and δ(U ) are quantifier-free.

The desired formula ψ is the conjunction of µ, of the formulas δ(y i ) for every y i in y, and of the formulas δ(X i ) for every X i in X. This completes the proof of the first assertion.

(2) If ϕ ∈ FO h (R , y), then the formulas δ(X) are not needed in this construction. Hence it applies even if D is not quasi-domain preserving.

We will denote by ϕ D the formula ψ constructed by backwards translation applied to ϕ and D.

Remarks 5.48

(1) As for Theorem 5.39, the proof of Theorem 5.47 is effective. It gives an algorithm that constructs ψ from ϕ and D.

(2) If ϕ is a sentence, then ϕ D is also a sentence and we have:

D(S) |= ϕ if and only if S |= ϕ D ,
and this is meaningful for an abstract structure S.

(3) It is important for proving the Recognizability Theorem that Backwards Translation does not increase the quantifier-height. This concern motivates the technicality about QDP-QF operations and the particular treatment of constants (cf. Remark 5.43(3)).

(4) We consider the QDP-QF operation fuse a,b applied to a concrete structure S such that a S = b S . The structure T := fuse a,b (S) is constructed from S by deleting b S whereas it can also be seen as a quotient of S. That is, we have a surjective mapping h : D S → D T that identifies a S and b S and is the identity otherwise. The relation R T consists of all tuples (h(a 1 ), . . . , h(a n )) such that the tuple (a 1 , . . . , a n ) is in R S , and for every constant symbol c, we have h(c S ) = c T . To simplify the discussion, let us consider in Theorem 5.47 a formula ϕ with a single free variable y. Letting D define fuse a,b , we do not have sat(S, ϕ D , ε, y) = h -1 (sat(fuse a,b (S), ϕ, ε, y)) as one might think, but we have:

sat(S, ϕ D , ε, y) = {d ∈ D S -{b S } | fuse a,b (S) |= ϕ(d)}.
The following proposition deals with compositions of QF operations.

Proposition 5.49 If f : STR c (R) → STR c (R ) and g : STR c (R ) → STR c (R ) are QF operations, then so is g • f : STR c (R) → STR c (R ).
If f and g are domain preserving or are quasi-domain preserving, then g • f has the same property.

Proof: Let f be defined by D = δ, (θ R ) R∈R + , (κ c,d ) c∈R0,d∈R 0 and g be defined by D = δ , (θ R ) R∈R + , (κ d,e ) d∈R 0 ,e∈R 0 . We define:

D := δ , (θ R ) R∈R + , (κ c,e ) c∈R0,e∈R 0 .
We need a formula δ such that sat( D(S), δ , x) = sat(S, δ , x). It is given by the second assertion of Theorem 5.47 with h = 0, so we can take δ equal to δ D . This theorem gives us also, for each We now examine the case where f and g are quasi-domain preserving. It is clear that for every structure S in STR c (R), the elements in D g•f (S) -D S are constants of S, because if such an element is deleted by g, then it is a constant of f (S), hence a constant of S, and if it is deleted by f it is also a constant of S. However, the notion of a QDP-QF operation is defined by a particular syntactic form of the domain formula. We now check that δ has the required form. Let δ(x) be c∈R0 (α c ⇒ x = c) and δ (x) be d∈R 0 (

R ∈ R n , n ≥ 1, a formula θ R defined as θ D R such that sat( D(S), θ R , x) = sat(S, θ R , x) where x = (x 1 , . . . , x n ).
β d ⇒ x = d). We can take δ (x) to be c∈R0 (γ c ⇒ x = c) where γ c is α c ∨ d∈R 0 (κ c,d ∧ β D d ).
The case of DP-QF operations is clear.

The VR and HR graph operations

We apply the above defined notions to describe the operations of the VR and the HR graph algebras. In particular, the unary operations are all QF operations.

Application 5.50 (The operations of the VR algebra GP t ) The many-sorted algebra GP t has been defined in Section 2.6.3. Our aim is to express its operations in terms of operations on relational structures. A p-graph G of type C (with C ∈ P f (A)) is faithfully represented by the R s,C -structure G = V G , edg G , (lab cG ) c∈C (see Example 5.2(2)) and we have:

G ⊕ C,D H = G ⊕ R s,C ,R s,D H ,
where C = π(G) and D = π(H). Here we use the extended disjoint union of structures defined in Example 5.44; note that R s,C ∪ R s,D = R s,C∪D . We now formalize the unary VR operations as quantifier-free operations.

If C is a finite set of port labels, π(G) = C and a, b ∈ C, then:

--→ add a,b,C (G) = D a,b,C ( G )
where D a,b,C is the DP-QFO definition scheme True, θ edg , (θ labc ) c∈C of type R s,C → R s,C such that:

θ edg (x 1 , x 2 ) is edg(x 1 , x 2 ) ∨ (lab a (x 1 ) ∧ lab b (x 2 )), θ labc (x 1 ) is lab c (x 1 ), for each c ∈ C.
If h : C → A and D = h(C) we have:

relab h,C (G) = D h,C ( G ) for every p-graph G of type π(G) = C, where D h,C is the DP-QFO definition scheme True, θ edg , (θ lab d ) d∈D of type R s,C → R s,D such that θ edg (x 1 , x 2 ) is edg(x 1 , x 2 ) and θ lab d (x 1 ) is c∈h -1 (d) lab c (x 1 ) for each d ∈ D.
The structures corresponding to the constant graphs of GP t have domains with at most one element. The extension to operations on labelled graphs (cf. Definition 2.90) is straightforward.

Application 5.51 (The unary operations of the HR algebra JS t ) We now consider in a similar way the operations of the many-sorted algebra JS t defined in Section 2.6.2. An s-graph G of type C is faithfully represented here by the constant-separated R ms,C -structure G = V G ∪ E G , in G , lab EdgeG , (a G ) a∈C (see Section 5.2.5), where a G is the a-source of G.

If B ⊆ C, the operation fg B,C takes as argument an s-graph of type C and produces an s-graph of type C -B. We have: The reader may recall that we have defined in Definition 4.50 a kind of simulation of the operations of the HR algebra by derived operations of the VR algebra. Why not resting on it instead of defining particular operations for the HR algebra? There are several reasons. First, this simulation is quite complicated and it describes graphs of tree-width at most k by VR operations using a number of port labels that is exponential in k (and we know by Proposition 2.114(2) that this blow-up is unavoidable). Second, it is defined for simple graphs and would have to be adapted to graphs with multiple edges. Third, graph classes of bounded tree-width are frequently considered for algorithmic purposes and it is thus useful to consider them more directly than via cumbersome encodings. And finally, the encoding of Definition 4.50 works for graphs but not for relational structures of bounded tree-width, a case that we will consider in Chapter 9.

fg B,C (G) = D B,C ( G ) where D B,C := True, θ in , θ lab Edge , (κ a,b ) a∈C,b∈C-B of type R ms,C → R ms,C-B and θ in (x 1 , x 2 ) is in(x 1 , x 2 ), θ lab Edge (x 1 ) is lab Edge (x 1 ), κ a,b is True if a = b, False if a = b.

The Splitting Theorem for derived operations

We will show that the Splitting Theorem (Theorem 5.39) extends to all linear and strict derived operations, built with disjoint union and QDP-QF operations (as defined in Example 5.44 and Definition 5.42 respectively). For sentences, it extends to all derived operations. Definition 5.52 (n-ary QDP-QF operations) We first define binary operations. Let R (1) , . . . , R (4) , R be relational signatures such that R

(3) 0 ∩ R (4) 0 = ∅ (and according to the convention of Footnote 58 in Example 5.44, a symbol belonging to two of them has the same arity with respect to both). Let f : STR(R (1) ) × STR(R (2) ) → STR(R) be defined by:

f (S, T ) := h(g(S) ⊕ R (3) ,R (4) g (T ))
where g, g and h are QDP-QF operations such that g : STR(R (1) ) → STR(R (3) ), g : STR(R (2) ) → STR(R (4) ) and h : STR(R (3) ∪ R (4) ) → STR(R).

We call such a mapping f a binary QDP-QF operation 61 and a binary DP-QF operation if g, g and h are DP-QF operations. Its definition uses only the finitely many symbols of R (1) ∪ • • • ∪ R (4) ∪ R. Note that every binary linear and strict derived operation f that is built with disjoint union and QDP-QF operations, can be written as above because the family of QDP-QF operations is closed under composition (Proposition 5.49) and contains the identity on every STR(R) (it is ι R,R , see Example 5.44).

In general, for n ≥ 1, an n-ary mapping f : STR(R (1)

) × • • • × STR(R (n) ) → STR(R)
is called an n-ary QDP-QF operation if it is a linear and strict derived operation that is built with disjoint unions ⊕ R ,R and QDP-QF operations. Clearly, by Proposition 5.49, the unary QDP-QF operations are the same as the QDP-QF operations. Every n-ary QDP-QF operation f with n > 2 can be expressed as a composition of binary QDP-QF operations. To be precise, it can be defined (recursively) as f (S 1 , . . . , S n ) := h(g 1 (S 1 , . . . , S m ), g 2 (S m+1 , . . . , S n )), where h is a binary QDP-QF operation, g 1 is an m-ary QDP-QF operation, with 1 ≤ m ≤ n -1, and g 2 is an (n -m)-ary QDP-QF operation. Similar definitions hold for n-ary DP-QF operations.

These operations act as well on concrete structures, provided the argument structures are pairwise disjoint (the Splitting Theorem to be stated concerns concrete structures).

Before proving that the Splitting Theorem extends to these operations, we give some examples.

Example 5.53 (Series-composition) Series-composition has been defined as a binary mapping • on directed s-graphs of type {1, 2}. Via the faithful representation of an s-graph G by G in STR(R ms,{1,2} ) = STR({in, lab Edge , 1, 2}), (1 and 2 are constant symbols), we have:

G • H = G • s H where • s : STR(R ms,{1,2} ) × STR(R ms,{1,2} ) → STR(R ms,{1,2} )
is the binary operation such that:

S • s T := fg {3,4} (fuse 3,4 (ren 2↔3 (S) ⊕ ren 1↔4 (T ))).
It is a binary QDP-QF operation since by Example 5.45, Application 5.51 and Proposition 5.49 the unary operations ren 2↔3 , ren 1↔4 and fg {3,4} • fuse 3,4 (= fg 3 • ffuse 3,4 ) are QDP-QF operations that preserve constant-separation. (This is necessary for them to represent operations on s-graphs). We now review the types of the operations used in this definition: The definition would be the same with {in 1 , in 2 } instead of {in, lab Edge }, that is, if G is defined alternatively as an {in 1 , in 2 , 1, 2}-structure.

⊕ : R ms,{1,3} × R ms,{2,4} → R ms,{1,2,3,4} ,
Example 5.54 (The complete join) The complete join of simple undirected graphs can be expressed by:

G ⊗ H = create(nat( G ) ⊕ mark ( H )).
In this writing, G , H ∈ STR({edg}), the operation nat is ι {edg},{edg,m} that expands the structure G with the new empty unary relation m (cf. Example 5.44), the operation mark expands H with the new unary relation m equal to the domain of the argument structure, and the operation create adds undirected edges between any two vertices x and y such that ¬m(x) ∧ m(y) holds, and then deletes m. The types of these DP-QF operations are: mark , nat : STR({edg}) → STR({edg, m}) create : STR({edg, m}) → STR({edg}).

Hence the complete join is a binary DP-QF operation.

Example 5.55 (Parallel-composition of structures) Let R, R be two relational signatures. We denote by R,R , or simply by , the operation : STR(R) × STR(R ) → STR(R ∪ R ) described informally as follows: S T is obtained from the union of disjoint concrete structures S and T by fusing the constants a S and a T for every a in R 0 ∩ R 0 . We call S T the parallelcomposition of S and T .

Let A := R 0 ∩ R 0 and let A := {a | a ∈ A} be a set of auxiliary constant symbols disjoint from R 0 ∪ R 0 (we assume of course that a = b if a = b). For structures S ∈ STR(R) and T ∈ STR(R ) the parallel-composition operation can be expressed by:

S R,R T = ffuse(S ⊕ R,R ren(T ))
where the DP-QF operation ren changes each a ∈ A into a (its definition scheme is similar to the one of ren h in Application 5.51), R is the relational signature (R -A) ∪ A and ffuse is the operation fg A • fuse where fuse is the composition in any order of the QDP-QF operations fuse a,a for all a ∈ A.62 Hence, this operation is a binary QDP-QF operation. This operation is also defined on disjoint concrete structures. It is not commutative on concrete structures whereas it is on abstract ones. We recall from Example 5.2(1) that w is the representation of a word w ∈ A * that uses the order of occurrences of letters. We have v • w = v -→ ⊕ w . We will use this observation in the proof of Corollary 5.66.

If we construct R-structures by using the ordered disjoint union -→ ⊕ , basic structures with a single element * satisfying * ≤ * , and quantifier-free operations that do not modify the relation defined by ≤, then all structures constructed by these operations are linearly ordered by ≤.

We now state the extension of Theorem 5.39 to binary QDP-QF operations. Its statement is exactly the same as the one of Theorem 5.39, with ⊕ replaced by an arbitrary binary QDP-QF operation f (and with R, R replaced by R (1) , R (2) which is of course irrelevant).

Theorem 5.57 (Splitting Theorem, for binary QDP-QF operations) Let f be a binary QDP-QF operation : STR(R (1) ) × STR(R (2) ) → STR(R). For every r and h in N and every formula ϕ in C r MS h (R, X ∪ z), there exists a finite family of 5-tuples (π i , θ i , ψ i , x i , y i ) 1≤i≤p such that, for all disjoint concrete R (1) -and R (2) -structures, respectively S and T , we have:

sat(f (S, T ), ϕ, X, z) = 1≤i≤p perm πi (sat(S, θ i , X, x i ) sat(T, ψ i , X, y i ))
where, for each i, θ i ∈ C r MS h (R (1) , X ∪ x i ), ψ i ∈ C r MS h (R (2) , X ∪ y i ), z = π i (x i y i ) and π i is a permutation that preserves the relative orders of variables in x i and in y i .

Proof: We let f be defined by f (S, T ) := h(g(S) ⊕ R (3) ,R (4) g (T )). By Example 5.44 and Proposition 5.49 we may assume that R

(3) + = R (4) + . By Theorems 5.39 and 5.47, we have:

sat(f (S, T ), ϕ, X, z) = sat(g(S) ⊕ g (T ), ϕ , X, z) = 1≤i≤p perm πi (sat(g(S), θ i , X, x i ) sat(g (T ), ψ i , X, y i )) = 1≤i≤p perm πi (sat(S, θ i , X, x i ) sat(T, ψ i , X, y i )),
where ϕ is constructed from ϕ by backwards translation relative to the unary operation h (Theorem 5.47). The sequences of variables, the formulas and the permutations in the second equality are constructed by the Splitting Theorem (Theorem 5.39) applied to ϕ . The formulas θ i and ψ i in the last equality are constructed by backwards translation applied to the formulas θ i and the unary operation g, and to the formulas ψ i and the unary operation g , respectively.

This theorem extends to n-ary QDP-QF operations of all arities in a straightforward way. We will however not need that extension. Instead, we will use Corollary 5.60 below.

Remarks 5.58

(1) By Remarks 5.40(1) and 5.48 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF], the proof of Theorem 5.57 is effective. It gives an algorithm that constructs from ϕ, X, z and f a splitting of ϕ relative to f . If f is defined by f (S, T ) := h(g(S) ⊕ R (3) ,R (4) g (T )), then the definition schemes of g, g and h are given as input to the algorithm.

(2) If z = ε, then the statement of Theorem 5.57 is simpler. No permutations are needed and we have:

sat(f (S, T ), ϕ, X) = 1≤i≤p sat(S, θ i , X) sat(T, ψ i , X).
(3) If ϕ is a sentence, then we obtain the following statement:

f (S, T ) |= ϕ if and only if S |= θ i and T |= ψ i for some i ∈ [p],
and furthermore, the index i is unique when it exists. This statement holds for abstract structures S and T .

If furthermore R (1) = R (2) , we can define g(S) := f (S, S) for an abstract R (1) -structure S. Then we have:

g(S) |= ϕ if and only if S |= i∈[p] θ i ∧ ψ i .
More generally, the Splitting Theorem extends to sentences and to derived operations on abstract structures built with disjoint union and QDP-QF operations that are not linear. However, we will not need this extension for proving recognizability results because, by Proposition 3.56(3), if a set is recognizable in an F -algebra, then it is recognizable in any derived algebra of it, defined with derived operations that need not be linear.

(4) If ϕ is a sentence and T is a fixed structure, then the unary mapping defined by k(S) := f (S, T ) satisfies the following:

k(S) |= ϕ if and only if S |= θ
where θ is the disjunction of the sentences θ i such that T |= ψ i .

Computing bounded theories

According to the definition given in Section 5.1.6, the L-theory Th L ({S}) of a structure S (where L denotes a logical language) is the set of sentences of this language that are valid in S. This is usually an infinite set. Our objective is to compute theories of structures in certain cases where they are finite because of syntactic restrictions, typically on the quantifier-height.

Definition 5.59 (Bounded theories) In Section 5.6, we will give an algorithm that transforms an arbitrary formula ϕ in C r MS h (R, X ) into an equivalent formula ϕ that is a kind of normal form of ϕ.

(We have ψ = ψ if ψ = ϕ.) This formula also belongs to C r MS h (R, X ). If X is finite, then the set C r MS h (R, X ) := { ϕ | ϕ ∈ C r MS h (R, X )}
is finite and can be computed from r, h, R and X (Proposition 5.94). We define the (h, r)-bounded (CMS) theory of a concrete or abstract R-structure S as the set Th(S, R, h, r) of sentences in C r MS h (R, ∅) that are valid in S, i.e.,

Th(S, R, h, r) := {ϕ ∈ C r MS h (R, ∅) | S |= ϕ} = { ϕ | ϕ ∈ C r MS h (R, ∅), S |= ϕ}.
The set Th(S, R, h, r) is finite and computable from S, R, h and r, although not in a tractable way. This is a specialization of the notion of theory introduced in Section 5.1.6.

More generally, if X k = {x 1 , . . . , x k } is the standard set of first-order variables, with the standard order (x 1 , . . . , x k ), and a = (a 1 , . . . , a k ) is a k-tuple of elements of the domain of a concrete structure S, we let

Th(S, R, h, r, a) := {ϕ ∈ C r MS h (R, X k ) | S |= ϕ(a)} = { ϕ | ϕ ∈ C r MS h (R, X k ), a ∈ sat(S, ϕ, (x 1 , . . . , x k ))}.
An easy consequence of Theorems 5.47 and 5.57 is the following:

Corollary 5.60 Let f : STR(R (1) ) × • • • × STR(R (n) ) → STR(R) be an n-ary QDP-QF operation. For every h, r, k 1 , . . . , k n , k ∈ N with k = k 1 + • • • + k n ,
there exists a computable mapping Z f :

P( C r MS h (R (1) , X k1 )) × • • • × P( C r MS h (R (n) , X kn )) → P( C r MS h (R, X k ))
such that, for all pairwise disjoint concrete R (1) -, . . . , R (n) -structures, respectively S 1 , . . . , S n , and every k-tuple a 1 • • • a n of elements of D f (S1,...,Sn) such that a 1 ∈ (D S1 ) k1 , . . . , a n ∈ (D Sn ) kn , we have: (1) , h, r, a 1 ), . . . , Th(S n , R (n) , h, r, a n )).

Th(f (S 1 , . . . , S n ), R, h, r, a 1 • • • a n ) = Z f (Th(S 1 , R
When necessary, we will use the more precise notation Z f,h,r,(k1,...,kn) for Z f .

A similar statement holds for abstract structures S 1 , . . . , S n and empty tuples a 1 , . . . , a n .

Proof: We first consider the case n = 1. Let D be the definition scheme of the QDP-QF operation f . Let S be a concrete R (1) -structure and let a be a k-tuple of elements of D f (S) . It has to be shown that Th(f (S), R, h, r, a) can be computed from Th(S, R (1) , h, r, a). We have: (1) , h, r, a)}, where ϕ D is the backwards translation of ϕ relative to D (cf. Theorem 5.47). In order to prove the inclusion ⊇, we consider ϕ in the set to the right. If a ∈ sat(S, ϕ D , (x 1 , . . . , x k )) = sat(S, ϕ D , (x 1 , . . . , x k )), then Theorem 5.47 implies that a ∈ sat(f (S), ϕ, (x 1 , . . . , x k )) and ϕ ∈ Th(f (S), R, h, r, a). The proof is similar for the other inclusion. Hence, we can define:

Th(f (S), R, h, r, a) = {ϕ ∈ C r MS h (R, X k ) | ϕ D ∈ Th(S, R
Z f (Θ) := {ϕ ∈ C r MS h (R, X k ) | ϕ D ∈ Θ},
for every Θ ⊆ C r MS h (R (1) , X k ), and Z f is the desired function. Note that Z f (Θ) is defined for every subset Θ of C r MS h (R (1) , X k ), even if Θ is not a theory: Θ may be empty or contain contradictory formulas.

The proof for n = 2 is similar to the one for n = 1. Let f be a binary QDP-QF operation, let S 1 , S 2 be concrete structures, and let a 1 ∈ (D S1 ) k1 and a 2 ∈ (D S2 ) k2 . We consider a formula ϕ ∈ C r MS h (R, X k1+k2 ). By Theorem 5.57 (considering only identity permutations), a finite family (θ i , ψ i ) ≤i≤p can be computed, with θ i ∈ C r MS h (R (1) , X k1 ) and ψ i ∈ C r MS h (R (2) , {x k1+1 , . . . , x k1+k2 }), such that a 1 a 2 ∈ sat(f (S 1 , S 2 ), ϕ, (x 1 , . . . , x k1+k2 )) if and only if there exists i ∈ [p] with a 1 ∈ sat(S 1 , θ i , (x 1 , . . . , x k1 )) and a 2 ∈ sat(S 2 , ψ i , (x k1+1 , . . . , x k1+k2 )).

Hence, for Θ ⊆ C r MS h (R (1) , X k1 ) and Ψ ⊆ C r MS h (R (2) , X k2 ), we can define

Z f (Θ, Ψ) such that ϕ is in Z f (Θ, Ψ) if and only if θ i ∈ Θ and ψ i ∈ Ψ for some i ∈ [p]
, where ψ i is defined as

ψ i [x 1 /x k1+1 , . . . , x k2 /x k1+k2 ].
Finally, we consider an n-ary QDP-QF operation with n > 2. Let f be defined by f (S 1 , . . . , S n ) := h(g 1 (S 1 , . . . , S m ), g 2 (S m+1 , . . . , S n )). Then we can define Z f (Θ 1 , . . . , Θ n ) := Z h (Z g1 (Θ 1 , . . . , Θ m ), Z g2 (Θ m+1 , . . . , Θ n )). We omit the details.

The computability of Z f follows from Remarks 5.48(1) and 5.58 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. The result for abstract structures and empty sequences is an immediate consequence of the result for concrete structures.

It should be noted that, in fact, the mappings Z f are uniformly computable: there is an algorithm that on input (f, Θ 1 , . . . , Θ n ) computes Z f (Θ 1 , . . . , Θ n ) as output (cf. the definition of an effectively given algebra in Definition 2.8). The n-ary QDP-QF operation f is specified by a definition scheme (in the unary case), by three definition schemes (in the binary case), or by the way it is built from binary QDP-QF operations (together with their specifications).

The following application will be useful in Section 7.2 for proving the Equationality Theorem, and in Section 8.5 to prove that monadic second-order transductions of terms can be simulated by tree-walking transducers.

Application 5.61 (Operations on terms) Let F be a fixed finite functional signature. The concrete R F -structure t = N t , (son i t ) 1≤i≤k , (lab f t ) f ∈F , rt t that represents faithfully a term t ∈ T (F ) is defined in Example 5.2(3). Without rt t , it equals Syn(t) . Thus, its domain is the set of positions of t, hence the set of nodes of the syntactic tree Syn(t) of t (see Definition 2.14), denoted by N t . The constant rt t is the root of t (denoted by root t ); it will be needed in what follows, but can as well be represented by a unary relation symbol rt such that rt t (u) holds if and only if u = root t .

Our objective is to express the theory Th( f (t, t ) , R F , h, r, a b) in terms of Th( t , R F , h, r, a) and Th( t , R F , h, r, b) where a and b are sequences of positions in t and t respectively. For this purpose we will express f (t, t ) as f * ( t , t ) for some appropriate binary operation f * . A technical problem comes from the fact that the concrete structures t and t are not disjoint, whereas Corollary 5.60 is stated for disjoint structures. To overcome it, we can use for t ∈ T (F ) and u ∈ N t , the structure t /u defined in Example 5.2(3). Without rt, it equals Syn(t)/u . It is the concrete R F -structure isomorphic to t/u whose domain is N t /u = {v ∈ N t | v ≤ t u}; the relations of t /u are the restrictions to its domain of those of t , and rt t /u = u.

For t ∈ T (F ) and u ∈ N t , if a is a k-tuple of elements of D t /u , we will use the shorter (hopefully more clear) notation Th(t, ↓u, h, r, a) instead of Th( t /u, R F , h, r, a). In particular, we will use Th(t, ↓root t , h, r, a) to denote Th( t , R F , h, r, a).

Let f ∈ F 2 . We consider the mapping that associates the term t = f (t 1 , t 2 ) with t 1 , t 2 ∈ T (F ). It can be expressed by

t = f * ( t /u 1 , t /u 2 )
where u 1 and u 2 are the left and right sons of the root of t and f * is the binary operation on disjoint concrete relational structures S, T defined by

f * (S, T ) := f 1 (rt, p(S, T ))
where f 1 and p are the following binary DP-QF operations:

f 1 (U, W ) := f 1 (U ⊕ W ) and
p(S, T ) := ren rt→s (S) ⊕ ren rt→s (T ).

(5.4)

These operations are defined with the help of the auxiliary constant symbols s and s , and the concrete {rt}-structure rt having the unique domain element 1: in the use of f * to define t , this element is taken as the root of t. The unary DP-QF operation ren rt→s renames rt into s, with κ rt,s taken equal to True in its definition scheme. The unary DP-QF operation f 1 (depending on f ) is defined by the following formulas:

θ son1 (x 1 , x 2 ) is son 1 (x 1 , x 2 ) ∨ (x 1 = rt ∧ x 2 = s), θ son2 (x 1 , x 2 ) is son 2 (x 1 , x 2 ) ∨ (x 1 = rt ∧ x 2 = s ), θ soni (x 1 , x 2 ) is son i (x 1 , x 2 ) if i ≥ 3, θ lab f (x 1 ) is lab f (x 1 ) ∨ x 1 = rt, θ labg (x 1 ) is lab g (x 1 ) if g ∈ F -{f }, κ rt,rt is True, κ s,rt , κ s ,rt
are False.

Since the structure f * (S, T ) is intended to belong to STR c (R F ) but s, s / ∈ R F , there are no formulas κ c,s and κ c,s in the definition scheme of f 1 . Note also that if rt is a unary relation symbol, then x 1 = rt should be replaced by rt(x 1 ), and the constant defining sentences should be replaced by the definition of θ rt (x 1 ) as rt(x 1 ).

For h, r, , k, k ∈ N , we will construct a mapping Z f * such that, for every term t in T (F ) with leading symbol f , every d ∈ (D rt ) , every a ∈ (D t /u1 ) k and every b ∈ (D t /u2 ) k , we have: 64

Th(t, ↓root t , h, r, d a b) = Z f * (Th(t, ↓u 1 , h, r, a), Th(t, ↓u 2 , h, r, b)).
64 There is a unique tuple d in D rt , hence d need not occur in the righthand side.

If t = f (t 1 , t 2 ) and = 0 (so that d = ε), this equality implies that

Th( t , R F , h, r, a b) = Z f * (Th( t 1 , R F , h, r, a ), Th( t 2 , R F , h, r, b ))
where a corresponds 65 to a sequence of positions a of t 1 , and b to a sequence of positions b of t 2 .

For defining Z f * we use the fact that, by the Equalities (5.4), the mapping f 2 defined by f 2 (U, S, T ) := f 1 (U, p(S, T )) is a ternary DP-QF operation, such that f * (S, T ) = f 2 (rt, S, T ). Thus, by Corollary 5.60, we have:

Th(t, ↓root t , h, r, d a b) = Z f2,h,r,( ,k,k ) (Th(rt, {rt}, h, r, d), Th(t, ↓u 1 , h, r, a), Th(t, ↓u 2 , h, r, b)).
Hence, we obtain Z f * from Z f2,h,r,( ,k,k ) by using the fixed set Th(rt, {rt}, h, r, d).

To be precise, we define:

Z f * (Θ, Θ ) := Z f2,h,r,( ,k,k ) (Th(rt, {rt}, h, r, d), Θ, Θ ) for all Θ ⊆ C r MS h (R F , X k ) and Θ ⊆ C r MS h (R F , X k ).
If we need to be more precise, we denote this function by Z f * ,h,r, ( ,k,k ) .

This result extends to function symbols f of arbitrary arities. Here we have used a ternary DP-QF operation f 2 with one fixed argument. For a symbol f of arity n, we need an (n + 1)-ary operation f 2 with one fixed argument. That operation can be expressed as a composition of binary DP-QF operations, and hence is an (n + 1)-ary DP-QF operation, to which Corollary 5.60 can be applied.

We now consider in a similar way the insertion of a term f (t 1 , t 2 ) in a context. We recall that a context c ∈ Ctxt(F ) is defined as a term in T (F ∪{w}) where w is a (special) variable that has a unique occurrence in c. A context is represented by an R F ∪{w} -structure. For t ∈ T (F ) and u ∈ N t , the structure t ↑ u is defined as Syn(t) ↑ u with, additionally, rt t ↑u = rt t . It is the concrete R F ∪{w} -structure isomorphic to t ↑ u whose domain is N t ↑ u = N t -{v ∈ N t | v < t u}; the relations of t ↑ u are the restrictions to its domain of those of t , except that the label of u is changed into w. See Definition 2.6, Definition 2.14 and Example 5.2(3) for the details. If d is an -tuple of elements of D t ↑u , we will abbreviate Th( t ↑ u, R F ∪{w} , h, r, d) by Th(t, ↑u, h, r, d).

Let

f ∈ F 2 , c ∈ Ctxt(F ) and t, t 1 , t 2 ∈ T (F ) be such that t = c[f (t 1 , t 2 )].
Let u be the occurrence of f in t such that c = t ↑ u, and let u 1 and u 2 be its left and right sons. Hence, t/u 1 = t 1 and t/u 2 = t 2 . We have D t ↑u = N t ↑ u, D t /u1 = N t /u 1 and D t /u2 = N t /u 2 . It follows that D t = N t is the disjoint union of the sets D t ↑u , D t /u1 and D t /u2 . Furthermore, we have:

t = f † ( t ↑ u, t /u 1 , t /u 2 )
65 via the unique isomorphism of Syn(t) /u 1 and Syn(t/u 1 ) described after Definition 2.14, which is also the unique isomorphism of t /u 1 and t/u 1 = t 1 , and similarly for b where f † is the ternary DP-QF operation defined by f † (U, S, T ) := f † 1 (U ⊕ ren rt→s (S) ⊕ ren rt→s (T )), s, s are new constant symbols and f † 1 is the unary DP-QF operation of type R F ∪{w} ∪{s, s } → R F that has exactly the same definition scheme as the unary DP-QF operation f 1 discussed before, except that the atomic formula x 1 = rt is replaced by lab w (x 1 ). 66 We use here a ternary DP-QF operation, as in the case of t = f (t 1 , t 2 ) but not with a fixed argument.

Application of Corollary 5.60 to f † shows that, for h, r, , k, k ∈ N , we can construct a ternary function Z f † on sets of formulas such that, for all d ∈ (D t ↑u ) , a ∈ (D t /u1 ) k and b ∈ (D t /u2 ) k , we have:

Th(t, ↓root t , h, r, d a b) = Z f † (Th(t, ↑u, h, r, d), Th(t, ↓u 1 , h, r, a), Th(t, ↓u 2 , h, r, b)).
(5.5)

It implies that:

Th( t , R F , h, r, d a b) = Z f † (Th( c , R F ∪{w} , h, r, d ), Th( t 1 , R F , h, r, a ), Th( t 2 , R F , h, r, b ))
where d corresponds to a sequence d of positions of the context c and a to a sequence a of positions of t 1 , and similarly for b, cf. Footnote 65. If necessary, we use the more precise notation Z f † ,h,r,( ,k,k ) for Z f † .

In the same situation, we also have that:

t /u = f * ( t /u 1 , t /u 2 )
with f * defined as before, except that D rt = {u}. Since D rt is a singleton, the fixed theory Th(rt, {rt}, h, r, d) does not depend on D rt , and so the same mapping Z f * is obtained. So, we have that:

Th(t, ↓u, h, r, d a b) = Z f * (Th(t, ↓u 1 , h, r, a), Th(t, ↓u 2 , h, r, b)) (5.6)
where Z f * is Z f * ,h,r,( ,k,k ) . There are also mappings Z f (1) and Z f (2) such that

Th(t, ↑u 1 , h, r, d a b) = Z f (1) (Th(t, ↑u, h, r, d), Th(t, ↓u 2 , h, r, b)) and Th(t, ↑u 2 , h, r, d a b) = Z f (2) (Th(t, ↑u, h, r, d), Th(t, ↓u 1 , h, r, a)). (5.7)
To obtain Z f (1) we define the binary operation f (1) such that

t ↑ u 1 = f (1) ( t ↑ u, t ↓ u 2 ) = f (1) 1 ( t ↑ u ⊕ s ⊕ ren rt→s ( t ↓ u 2 ))
where s is the concrete {s}-structure with domain {u 1 } and f

(1)

1 is the unary DP-QF operation of type R F ∪{w} ∪ {s, s } → R F ∪{w} that has the same definition scheme as f † 1 with additionally θ labw (x 1 ) taken equal to x 1 = s. The mapping Z f (2) is obtained in a similar way.

As before, these results easily extend to function symbols of arbitrary arity.

The many-sorted algebra of relational structures

The Recognizability Theorem to be stated in the next section (Theorem 5.75) says that every CMS-definable class of relational structures is recognizable. We first define the relevant algebra.

Definition 5.62 (The algebra STR of relational structures)

We let S be the set of relational signatures. It is countable because we assume that each relational signature is a finite subset of a countable (effectively given) set of symbols containing countably many symbols of each arity. We define STR as the S-sorted algebra with domain STR(R) for each R ∈ S. The (functional) signature F QF of this algebra consists of the following symbols; we also define the operations they denote: We will frequently omit the subscripts R and R in the symbols ⊕ R,R , ∅ R and ♦ B,R . Instead of the symbol qf D,R,R we will use the operation D, in accordance with our custom not to distinguish an operation from the symbol denoting it.

(a) for every R, R ∈ S such that R 0 ∩ R 0 = ∅, the binary symbol ⊕ R,R of type R × R → R ∪ R ; it
The notation F QF emphasizes the important role of quantifier-free operations. The signature F QF contains unary operations that are not quasi-domain preserving.

We now define several subalgebras of STR. If we restrict the unary operations to those that are quasi-domain preserving, we obtain a subsignature F QF pres of F QF and a subalgebra STR pres of STR. Both algebras have the same sorts and the same domains. Every n-ary QDP-QF operation is a (linear and strict) derived operation of the F QF -algebra STR pres .

We let STR sep be the subalgebra of STR obtained by taking as domain of sort R the set STR sep (R) of constant-separated structures in STR(R) and by restricting the unary operations to those that preserve constant-separation. The corresponding signature is denoted by F QF sep . One can combine these two restrictions, and this gives the F QF sep,pres -algebra STR sep,pres . We let S nc be the subset of S consisting of relational signatures without constant symbols. The associated structures are constant-separated in a trivial way. We obtain thus a subalgebra STR nc of STR sep with set of sorts S nc and functional signature F QF nc that is a subsignature of F QF sep . Its domain of sort R is STR(R). If we now restrict F QF nc to F QF nc,pres by keeping only the unary DP-QF operations, we obtain the S nc -sorted algebra STR nc,pres .

All these algebras are effectively given (see Definitions 2.8 and 2.127). The discussion in Definition 2.32 of the fact that the HR algebra JS is effectively given extends to STR and its subalgebras: it is clear that its set of sorts is effectively given; so are the definition schemes of its operations and of those of its subalgebras by Remarks 5.43 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]2). That two definition schemes can define the same operation is no problem, cf. Remark 5.58 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] and the paragraph after Corollary 5.60.

Lemma 5.63 The algebra STR is generated by F QF pres , the algebra STR sep is generated by F QF pres,sep and the algebra STR nc is generated by F QF nc,pres .

Hence, by Lemma 3.75( 1), a set is effectively recognizable in these algebras if and only if it is effectively term-recognizable (just as for the HR and VR algebras).

The proof of Lemma 5.63 is similar to those of Proposition 2.33 showing that the HR algebra is generated by its signature, and of Proposition 2.104( 1) doing the same for the VR algebra. Every term t in T (F QF ) evaluates into a concrete structure denoted by cval (t) whose domain is a subset of Occ 0 (t) defined as the set of occurrences in t of constant symbols other than ∅ R (they are leaves of the syntactic tree of t). The corresponding abstract structure is denoted by val (t). The formal definition of cval (t) is a straightforward generalization of the corresponding one given in Section 2.5.2 for terms in T (F VR ).

In Section 9.3, we will define complexity measures on relational structures that can be considered as generalizations of clique-width. They are related with the generation of relational structures by particular subsignatures of F QF pres . If we identify a p-graph G of type π(G) = C with the R s,C -structure G = V G , edg G , (lab aG ) a∈C (and C with R s,C ), then, since we have observed in Application 5.50 that the unary operations of F tVR are DP-QF operations, we obtain that the many-sorted algebra GP t is a subalgebra of STR nc,pres .67 Recall from Example 5.2(2) that a structure S in STR(R s,C ) is G for some graph G such that π(G) = C if and only if the sets lab aS for a ∈ C form a partition of D S that consists of nonempty sets. This condition is first-order expressible.

The Recognizability Theorem for STR pres

We first prove the Recognizability Theorem for the algebra STR pres , and then we will extend it to STR.

Theorem 5.64 Let R be a relational signature. For every sentence ϕ in CMS(R, ∅), the set MOD(ϕ) ⊆ STR(R) of models of ϕ is effectively recognizable in the algebra STR pres .

Proof: We let r and h be such that ϕ ∈ C r MS h (R, ∅). For each relational signature R ∈ S, we let ∼ R be the equivalence relation on STR(R ) defined by S ∼ R T if and only if Th(S, R , h, r) = Th(T, R , h, r). This condition means that S |= ψ if and only if T |= ψ, for every sentence

ψ in C r MS h (R , ∅).
Since all the operations of STR pres are binary or unary QDP-QF operations, it follows from Corollary 5.60 that the equivalence relations ∼ R (which are well defined on abstract structures) form a congruence ∼ on STR pres . This congruence is locally finite because the set P( C r MS h (R , ∅)) is finite for every R ∈ S (by Proposition 5.94 in Section 5.6 below), it is decidable because the mapping S → Th(S, R , h, r) is computable, and it saturates MOD(ϕ). The membership in MOD(ϕ) of any given R-structure S is decidable. This proves the semi-effective recognizability of MOD(ϕ) by Proposition 3.78(1) in Section 3.4.4.

We now establish the effective recognizability by a different proof, because we cannot use Proposition 3.78 to get the effectivity from the semi-effectivity. Following Definition 3.74, we construct a locally finite F QF pres -algebra A and a homomorphism κ from STR pres to A. The set of sorts is S. For each R ∈ S, we let A R be the powerset of C r MS h (R , ∅) and κ be the mapping that associates with each S ∈ STR(R ) its theory κ(S) := Th(S, R , h, r). 68 We use Corollary 5.60 to define the operations of A in such a way that κ is a homomorphism. If f is a QDP-QF operation of type R → R , then we let f A be the mapping Z f,h,r,0 . It follows from Corollary 5.60 that, for every R -structure S, we have Th(f (S), R , h, r) = f A (Th(S, R , h, r)), hence κ(f (S)) = f A (κ(S)). The proof is similar for disjoint union, which is a binary DP-QF operation: if f = ⊕ R ,R , then we let f A be the mapping Z f,h,r,(0,0) .

Hence, we have a locally finite algebra A, and κ is a homomorphism into it. If we define C ⊆ A by C := {Θ ∈ A R | ϕ ∈ Θ}, then it is easy to see that MOD(ϕ) = κ -1 (C). Since κ is computable and C is a decidable subset of A, it remains to show that A is effectively given. Using the encoding of the effectively given countable set of relation symbols (see Definition 5.62) it is straighforward to encode the set of all CMS sentences, and hence the set of its finite subsets, of which A is a decidable subset: as observed in Definition 5.59, the set C r MS h (R , ∅) can be computed from r, h and R . From this we obtain an encoding of A, with a computable sort mapping. The previous observation also shows that the mapping R → |A R | is computable (and obviously, |A| = ω). The operations of A are uniformly computable (cf. Definition 2.8) because the mappings Z f are uniformly computable (as observed after Corollary 5.60). This shows that A is effectively given.

In Theorem 5.96 of Section 5.6 we will compute an upper-bound to the recognizability index of MOD(ϕ).

Example 5.65 We give an example showing that the Recognizability Theorem fails to hold if we add to the signature of STR pres a single unary operation that is defined by a definition scheme involving a single formula with a single first-order quantifier.

We let R be the relational signature R s,[2] = {edg, lab 1 , lab 2 }. Every p-graph G of type [2] is represented by the R-structure G . Since the many-sorted VR algebra GP t is a subalgebra of STR pres (as discussed at the end of Section 5.3.7), we will use the operations of GP t , without showing their types.

We define f : STR(R) → STR(R) as the operation that transforms a structure S into f (S) by modifying only the relation edg S ; the relation edg f (S) is defined in S by the formula:

edg(x 1 , x 2 ) ∨ (x 1 = x 2 ∧ ∃x 3 [edg(x 1 , x 3 ) ∧ edg(x 3 , x 3 )]).
It transforms a p-graph G by adding loops to some vertices: in f (G), a vertex has a loop if and only if it has a loop in G or it is the tail of a directed edge whose head has a loop.

We let STR f pres be the algebra STR pres with the additional unary operation f , and we let ϕ be the first-order sentence ∀x. edg(x, x). We claim that the set MOD(ϕ) ⊆ STR(R) is not recognizable in STR f pres . To prove this claim, we define, for i = 1, 2, the unary derived VR operation g i of type [i] → [2] such that for every p-graph G of type [i]:

g i (G) := relab 3→1 (relab 1→2 ( --→ add 3,1 (3 ⊕ G))).
We let STR f,g pres be the algebra STR f pres to which the operations g 1 and g 2 are added; it is a derived algebra of STR f pres . Then, we define t n,m as the term Before generalizing Theorem 5.64 to the algebra STR, we present some of its consequences.

f n g m 2 g 1 1 . It is clear that the term g m 2 g 1 1 defines the p-graph 1 → 2 → 2 → • • • 2 → 2 of

Recognizable languages and recognizable sets of graphs

We first consider sets of words. A word w ∈ A * is faithfully represented by the structure w defined in Example 5.2 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF], that uses the order of occurrences of letters. 69Corollary 5.66 Let A be a finite alphabet. If a language L ⊆ A * is MSdefinable, then it is effectively recognizable in W(A), hence regular.

Proof: Let α A be the MS sentence over W A := {≤} ∪ {lab a | a ∈ A} (where each relation lab a is unary) that defines the class A * . (Corollary 5.12 holds for • ). Let L ⊆ A * be MS-definable. It is the set of words w such that w satisfies an MS sentence ϕ over W A , hence also the set of those such that w satisfies an MS sentence ϕ over W A . It follows that L = MOD(ϕ ∧ α A ).

For words v, w ∈ A * , we have v • w = v -→ ⊕ w , where -→ ⊕ is the derived operation of STR pres defined in Example 5.56. Hence, if we identify every word w in A * with the W A -structure w (or more precisely, with the corresponding abstract structure), then the monoid of words W(A) is a subalgebra H of a derived algebra of STR pres . Since L is effectively recognizable in STR pres by Theorem 5.64, we get by Proposition 3.76 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]3) that it is effectively recognizable in H. Hence L is effectively recognizable in W(A) and thus regular (cf. Example 3.57( 2)).

We now consider terms and give a proof in our setting of the well-known result stated as Theorem 1.16 (cf. Theorem 5.15).

Corollary 5.67 Let F be a finite functional signature. If a language L ⊆ T (F ) is MS-definable, then it is effectively recognizable in T(F ), hence regular.

Proof: We first assume that F is one-sorted. We have shown in Section 5.3.6 (Equalities (5.4) in Application 5.61) that the operations on terms, (t 1 , . . . , t k ) → f (t 1 , . . . , t k ), for f ∈ F k , are derived operations of STR pres , via the representation of a term t by the R F -structure t . Hence, identifying t and t , we have that T(F ) is a subalgebra of a derived algebra of STR pres . If L ⊆ T (F ) is MS-definable, then L is MS-definable by Corollary 5.12, hence effectively recognizable in STR pres by Theorem 5.64. By a proof similar to that of the previous corollary, we obtain that L is effectively recognizable in T(F ) and thus regular by Theorem 3.62. Now let F be many-sorted, and let F -be the one-sorted signature obtained from F by making all sorts identical. From the above, we get that L is effectively recognizable in T(F -). Then it is effectively recognizable in T(F ) by Theorem 3.62 and Remark 3.38(4) (which are both effective), hence regular over F .

The classical proof of this result, based on the construction of a finite automaton recognizing L ⊆ T (F ) from a monadic second-order formula that defines it, will be given in Section 6.3.3.

properties of words are MS-expressible via these two faithful representations, i.e., they are MS-equivalent.

The case of graph algebras

We now apply the Recognizability Theorem to the typed algebras GP t and JS t which are also subalgebras of derived algebras of STR pres .

We recall that a p-graph of type π(G) ⊆ C is faithfully represented by the R s,C -structure G C , and that an s-graph G of type τ (G) ⊆ C (it can have multiple edges) is faithfully represented by the R m,C -structure G C (we also recall that R m,C = {in, lab Edge } ∪ {lab a | a ∈ C} where in is binary and the other symbols are unary, cf. Section 5.2.5). In order to represent vertex and edge labels, we use additional unary relation symbols in G C and additional unary and binary relation symbols in G C . For each finite set C, the class of structures of the form G C (resp. G C ) for some s-graph (resp. p-graph) G of type included in C is FO-definable. It follows (cf. the proof of Corollary 5.66 for a similar fact) that a set L of (labelled) p-graphs of bounded type is CMSdefinable if and only if the set of structures

L = L C = { G C | G ∈ L} is CMS-definable,
where C is the union of all types of the elements of L. A similar statement holds for the CMS 2 -definability of a set of (labelled) s-graphs of bounded type.

Theorem 5.68 (Recognizability Theorem for graph algebras)

(1) Every CMS-definable set of (labelled) p-graphs is effectively VR-recognizable.

(2) Every CMS 2 -definable set of (labelled) s-graphs is effectively HR-recognizable.

Proof: The proofs are essentially the same for labelled and unlabelled graphs.

(1) Let L be a CMS-definable set of p-graphs of bounded type. By the above remarks, we have L = L C = MOD(ϕ) for some sentence ϕ in CMS(R s,C , ∅).

We first show that for every D ⊆ C, the set {G ∈ L | π(G) = D} is CMS-definable. Let ϕ D in CMS(R s,D , ∅) be obtained from ϕ by changing every atomic subformula lab a (x), a ∈ C -D, into False. Then:

MOD(ϕ D ) = { G D | G ∈ L, π(G) ⊆ D} and so MOD(ϕ D ∧ a∈D ∃x.lab a (x)) = { G D | G ∈ L, π(G) = D}. Hence {G ∈ L | π(G) = D} is CMS-definable.
Since L is a finite union of such sets, this implies, by Corollary 3.86, that we may assume from now on that L is homogenous, and so

L = { G | G ∈ L} = MOD(ϕ).
As observed in Section 5.3.7, if G is identified with G , then the manysorted VR algebra GP t is a subalgebra of STR nc,pres , hence of STR pres . So, L is effectively recognizable in STR pres by Theorem 5.64, hence, by Proposition 3.76 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF], it is effectively recognizable in that subalgebra, and thus L is effectively recognizable in GP t . Proposition 3.76( 1) is applied to M = GP t and M = STR pres , in S ,S is the mapping C → R s,C , in F ,F is the mapping that maps each VR operation to the corresponding operation of STR pres as defined in Application 5.50, and in M ,M is the mapping G → G . These mappings are computable, and {R s,C | C ∈ P f (A)} is a decidable subset of the set of sorts of STR pres . Note that, although G is identified with G , they are encoded by different elements of N in GP t and STR pres .

(2) By the same proof as above (replacing • by • ), we may assume that L is a homogenous set of s-graphs, and so L = { G | G ∈ L}. And then, we may also assume that G is an R ms,C -structure rather than an R m,C -structure, i.e., the sources of G are represented by constants rather than by unary relations (we recall that R ms,C = {in, lab Edge } ∪ C where each element of C is a constant symbol, cf. Section 5.2.5).

Identifying G with G , the many-sorted HR algebra JS t is a subalgebra of a derived algebra of STR pres . This follows from Application 5.51 and Example 5.55, where it is shown that, with this identification, the operations of JS t are binary QDP-QF and unary DP-QF operations, respectively, and hence (linear) derived operations of STR pres . Moreover, the definition schemes of the binary and unary QDP-QF operations can be computed from the HR operations, and hence the involved derived signature is effectively given. Theorem 5.64 and Proposition 3.76 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]3) can thus be used.

We now consider CMS-definable sets of p-graphs of bounded clique-width, and similarly, CMS 2 -definable sets of s-graphs of bounded tree-width. A set L of p-graphs is of bounded clique-width and of bounded type if and only if L ⊆ val (T VR C ) for some C ∈ P f (A), and a similar statement holds for s-graphs (see Definition 2.89 and Theorem 2.83(1), respectively). (2) Every CMS 2 -definable set L of (labelled) s-graphs of bounded tree-width is effectively recognizable in the algebra JS gen [C], where C is any finite subset of A such that L ⊆ J S gen [C] = val (T HR C ) (i.e., such that twd (L) ≤ |C| -1 and τ (G) ⊆ C for every G ∈ L).

Proof: We first prove (2). As observed after Proposition 2.132, val (T HR C ) = val (T tHR C ), and hence L ⊆ J S t,gen [C]. Since L is effectively recognizable in JS t by Theorem 5.68, it is also effectively recognizable in the subalgebra JS t,gen [C] by Proposition 3.76 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. Since JS t,gen [C] has finitely many sorts, the set L is also effectively recognizable in JS gen [C] as noted in Chapter 4, Definition 4.29.

The proof of ( 1) is the same. The remark about effective recognizability in the one-sorted algebra GP gen [C] is in Definition 4.52.

Filtering theorems: logical versions

An "algebraic" Filtering Theorem has been proved in Section 3.4.7. Here, we state "logical" Filtering Theorems for graph algebras, together with the related proof technique of fixed-point induction (as formulated at the end of Section 1.2.2).

Corollary 5.70 (Filtering Theorem for the VR algebra) For every VRequational set L and every CMS-definable set K of (labelled) p-graphs, we have:

(1) The set L ∩ K is VR-equational, and an equation system for it can be constructed from an equation system defining L and a sentence defining K.

(2) The emptiness and the finiteness of L ∩ K can be decided. If L ∩ K is finite, it can be computed70 .

(3) Let L be defined by (S, X µ ) for some typed VR equation system S with Unk (S) = X n and some µ ∈ [n]. Then L ⊆ K if and only if there exists an n-tuple (K 1 , . . . , K n ) of CMS-definable sets of (labelled) p-graphs that is an oversolution of S and is such that K ⊆ K for every ∈ [µ]. If L ⊆ K (which can be decided by ( 1) and ( 2)), then one can construct CMS sentences that define K 1 , . . . , K n .

Proof: (1) is immediate from Theorems 5. 68 and 4.53, and (2) from Propositions 4.42(2) and 4.47(2).

The if direction of ( 3) is immediate from Theorem 5.68 and Proposition 3.91( 1), for M := GP t . Let K = MOD(ϕ) for a sentence ϕ in C r MS h (R s,D , ∅) with D ∈ P f (A). For deciding L ⊆ K, we first use Proposition 4.45 to decide if L ⊆ GP[D], and then we use ( 1) and ( 2

) to decide if L ∩ (GP[D] -K) is empty (note that GP[D] -K is defined by ¬ϕ).
To prove the only-if direction of (3), let (L 1 , . . . , L n ) be the least solution of S in P(GP t ) and suppose that L = L 1 ∪ • • • ∪ L µ ⊆ K. Let D j be the type of the elements of L j , for every j ∈ [n]. We first prove that we may assume that L = L i and that all elements of K have type D i , for some i ∈

[n]. Obviously, L ⊆ {G ∈ K | π(G) = D } for every ∈ [µ]. As shown in the proof of Theorem 5.68, {G ∈ K | π(G) = D } is CMS-definable. For every ∈ [µ], let (K 1 , . . . , K n ) be an n-tuple of CMS-definable sets that is an oversolution of S such that K ⊆ {G ∈ K | π(G) = D }. Then it is straightforward to verify that the n-tuple (K 1 , . . . , K n ) := ( ∈[µ] K 1 , . . . , ∈[µ] K n ) satisfies the requirements.
So, let L = L 1 and let all elements of K be of type D 1 = D. It follows from Proposition 3.9 that every L i is equational in STR pres . By Theorem 5.64, K is effectively recognizable in STR pres . In what follows we identify L i with L i and K with K; note that since K is homogenous, K = { G | G ∈ K}, and similarly for L i . It is shown in the proof of Theorem 5.64 that K = κ -1 (C) for a homomorphism κ : STR pres → A and C ⊆ A. Moreover, C = {Θ ∈ A R s,D | ϕ ∈ Θ} and, for every R -structure S, A R is the powerset of C r MS h (R , ∅) and κ(S) = Th(S, R , h, r). We now apply Proposition 3.91 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] for M := STR pres . According to its proof, the n-tuple (K 1 , . . . , K n ) can be taken such that K i is the union of all sets κ -1 (q) such that L i ∩κ -1 (q) = ∅ for q ∈ A. Obviously, it suffices to take q ∈ A R s,D i and hence the union is finite.

For every q ⊆ C r MS h (R , ∅), the set κ -1 (q) consists of all R -structures S such that Th(S, R , h, r) = q, and hence it is CMS-definable by the conjunction of all sentences in q. So, K i is CMS-definable by a finite disjunction ϕ i of such sentences, and ϕ i can be constructed because the nonemptiness of L i ∩ κ -1 (q) can be decided by ( 2): L i is VR-equational and κ -1 (q) is CMS-definable. Note that K i consists of p-graphs: if G ∈ L i ∩ κ -1 (q) then q = Th( G , R s,Di , h, r) contains a sentence expressing that G is the representation of a p-graph.

The results and their proofs are fully similar for the HR algebra and CMS 2definability. We state them for easy reference.

Corollary 5.71 (Filtering Theorem for the HR algebra) For every HRequational set L and every CMS 2 -definable set K of (labelled) s-graphs, we have:

(1) The set L ∩ K is HR-equational, and an equation system for it can be constructed from an equation system defining L and a sentence defining K.

(2) The emptiness and the finiteness of L ∩ K can be decided. If L ∩ K is finite, then it can be computed.

(3) Let L be defined by (S, X µ ) for some typed HR equation system S with Unk (S) = X n and some µ ∈ [n]. Then L ⊆ K if and only if there exists an n-tuple (K 1 , . . . , K n ) of CMS 2 -definable sets of (labelled) s-graphs that is an oversolution of S and is such that K ⊆ K for every ∈ [µ]. If L ⊆ K (which can be decided by ( 1) and ( 2)), then one can construct CMS 2 sentences that define K 1 , . . . , K n .

Proof: (1) follows from Theorems 5. 68 and 4.37, and (2) from Propositions 4.5(2) and 4.19. In the proof of the if direction of (3), Proposition 4.10 is used instead of Proposition 4.45. For the only-if direction, we observe that L i is equational in STR pres by Proposition 3.9 and Proposition 3.41: the operations of JS t are linear derived operations of STR pres , as mentioned in the proof of Theorem 5.68(2).

We now present an application to the construction of an HR equation system that defines a set of graphs characterized by excluded minors.

Application 5.72 (From excluded minors to HR equation systems) Let be given a finite set Ω of simple, loop-free undirected graphs, and let L := Forb(Ω) be the set of graphs that do not contain any of them as a minor. We know from the proof of Proposition 2.61 that L has bounded tree-width if and only if some planar graph belongs to Ω. Since we want to find an HR equation system for defining L, we assume that Ω contains some planar graph P (otherwise the construction is impossible by Proposition 4.7).

We also know from the proof of Proposition 2.61 that twd (Forb({P })) ≤ f (P ) where f is a computable function. It follows that:

L = TWD(≤ f (P )) ∩ Forb(Ω).
The set Forb(Ω) is MS-definable by Corollary 1.14: it is defined by the conjunction of the sentences ¬MINOR H for all H ∈ Ω (cf. Proposition 4.31( 8)). Hence, by Corollary 5.71( 1) and Example 4.3(8) (that constructs an HR equation system for TWD (≤ k) where k is a given integer), the set L is HR-equational and a system defining it can be constructed.

Noncomputability results for congruences

By Theorems 5. 64 and 5.68, several locally finite congruences on the VR and the HR algebras are associated with monadic second-order sentences:

(1) the congruence ∼ h that defines two p-graphs or two s-graphs as equivalent if they have the same type and satisfy the same MS sentences of quantifier-height at most h (we take r = 0 in the proof of Theorem 5.64), and

(2) the syntactic congruence ≈ MOD(ϕ) of the set of p-graphs or s-graphs of the same type that satisfy an MS sentence ϕ.

Clearly, ∼ h refines ≈ MOD(ϕ) if the quantifier-height of ϕ is at most h. In the following proposition, we only consider congruences relative to the VR algebra (and for unlabelled graphs), but the same negative results hold for the HR algebra, and the proofs are essentially the same.

Proposition 5.73

(1) For each integer h the equivalence relation ∼ h on p-graphs is decidable, but there is no algorithm that computes, for any given h ∈ N and any given finite set C of port labels, the number of equivalence classes of ∼ h on p-graphs of type C.

(2) It is not decidable whether G ≈ MOD(ϕ) H for any given p-graphs G and H and any given sentence ϕ.

Proof:

(1) The equivalence relation ∼ h is decidable (and even uniformly decidable, for varying h) by the observations in Definition 5.59.

We now prove that if, for each h, we can compute the number of equivalence classes of ∼ h of type {1} (the type of nonempty graphs without ports, we let 1 be a default port label), then we can decide the monadic second-order satisfiability problem. Let ϕ be an MS sentence, h be its quantifier-height and let N h be the number of equivalence classes of ∼ h of type {1}. Let G 1 , G 2 , . . . , G i , . . . be an effective enumeration of all simple nonempty graphs. Since ∼ h is decidable, one can compute the increasing sequence

n 1 < n 2 < • • • < n i < • • • such that n 1 = 1 and, for each i > 1, n i is the smallest integer j > n i-1 such that G j is not ∼ h -equivalent to any graph G k for k < j.
This sequence has exactly N h elements. Since we know this value, we can determine when its computation is terminated. It follows that ϕ is satisfied in some simple graph if and only if it is in some of the graphs G n1 , G n2 , . . . , G m where m := n N h or in the empty graph. This can be decided and we get a contradiction with Theorem 5.5.

(2) We will use the proof of Theorem 5.6 and Remark 5.7. Let L := MOD(ϕ M ) where M is a deterministic Turing machine and L is empty if M does not halt or consists of one directed square grid (up to isomorphism) if M halts. Let H be any nonempty simple directed graph. If L = ∅, then for every simple directed graph G, we have G ⊕ H ∈ L if and only if G ⊕ ∅ ∈ L. If L = {K}, then this equivalence does not hold (take G = K). More generally, we get that H ≈ L ∅ if and only if M does not halt, which is not decidable. This reduction establishes the result.

Remark 5.74 The situation is different if we consider congruences relative to finitely generated graph algebras, like those of graphs of tree-width or cliquewidth at most some fixed k. In these cases, the decidable congruence ∼ h is effectively given by Proposition 3.78(3.1) of Section 3.4.4, which means (cf. Definition 3.77) that an algorithm can compute the cardinality of each congruence class. The index of ∼ h is thus computable. It is an upper-bound to that of ≈ MOD(ϕ) (where h is the quantifier-height of ϕ). By Claim 3.80.2, this congruence is decidable and its index is computable, as for ∼ h , by Proposition 3.78(3.1).

Handling general quantifier-free operations

We will prove the Recognizability Theorem for the algebra STR. Its unary operations are all QF operations, even those that are not quasi-domain preserving.

Theorem 5.75 (Recognizability Theorem for STR) For every relational signature R and every sentence ϕ in CMS(R, ∅), the set MOD(ϕ) ⊆ STR(R) is effectively recognizable in STR.

This theorem is a consequence of Theorem 5.64 and the following one: Theorem 5.76 Every set of relational structures that is recognizable, semieffectively recognizable or effectively recognizable in STR pres has the same property in STR.

To prove this, we need some definitions and lemmas. We recall that, if all constants of a structure S are in a subset E of its domain, then S[E] denotes the substructure of S with domain E. (Its signature is the same as that of S.) Definition 5.77 (Domain restricting operations) A QF operation f : STR c (R) → STR c (R) is domain restricting if, for some formula δ in QF(R, {x}), we have f (S) = S[sat(S, δ, x)] for every S ∈ STR c (R). This implies that S |= δ(c) for every c ∈ R 0 and every S ∈ STR c (R). These operations are those defined by definition schemes whose domain formula δ is equivalent to a formula of the form δ (x) ∨ c∈R0 x = c for some δ ∈ QF (R, {x}).

: STR c (R) → STR c (R ) can be expressed as g • h where h is a domain restricting QF operation : STR c (R) → STR c (R) and g is a QDP-QF operation : STR c (R) → STR c (R ). Proof: Let f have definition scheme δ, (θ R ) R∈R + , (κ c,d ) c∈R0,d∈R 0 . Let S ∈ STR c (R) and S := f (S) ∈ STR c (R ). Let E be such that {c S | c ∈ R 0 } ∪ sat(S, δ, x) ⊆ E ⊆ D S .
We have D f (S) ⊆ E because, by definition, D f (S) = sat(S, δ, x). Since c S ∈ E for each c ∈ R 0 , the structure S[E] belongs to STR c (R). We have:

f (S[E]) = f (S).
(5.8)

We check this equality. This proves Equality (5.8). It follows that f = g(h(S)) for every S ∈ STR c (R), where h is the domain restricting QF operation with domain formula δ(x) ∨ c∈R0 x = c and g is the QDP-QF operation defined by the definition scheme δ ,

(θ R ) R∈R + , (κ c,d ) c∈R0,d∈R 0 where δ is c∈R0 (¬δ(c) ⇒ x = c). The struc- ture h(S) is S[E] where E := D f (S) ∪ {c S | c ∈ R 0 }
so that by Equality (5.8), f (h(S)) = f (S). But f and g have the same effect on h(S) because the same elements of E satisfy δ and δ .

Lemma 5.79 Let R and R be relational signatures such that R 0 ∩ R 0 = ∅. Let f : STR c (R ∪R ) → STR c (R ∪R ) be a domain restricting QF operation. There exist two families of pairs (χ i , g i ) 1≤i≤p and (χ j , g j ) 1≤j≤p such that for every i and j, χ j ∈ QF(R , ∅), χ i ∈ QF(R , ∅), g i and g j are domain restricting operations of respective types R → R and R → R , and for every two disjoint concrete R-and R -structures, respectively S and T :

(1) there exist a unique i ∈ [p ] such that T |= χ i and a unique j ∈ [p ] such that S |= χ j ,

(2) we have f (S ⊕ T ) = g i (S) ⊕ g j (T ) where i, j are as in [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF].

Proof: One might think that, for every f , S and T as in the statement we have

f (S ⊕ T ) = f (S) ⊕ f (T )
. This is actually true if R 0 = R 0 = ∅, but not in general. Consider for example the operation f with domain formula δ(x) equal to

R(x) ∧ R (a) ∧ R (b) ∨ R(x) ∧ ¬R (a) ∧ ¬R (b) ∨ ¬R(x) ∧ R (a) ∧ ¬R (b) .
There is no pair of domain restricting QF operations (g, h) such that, for every concrete disjoint {R, R , a}-structure S and {R, R , b}-structure T , we have f (S ⊕ T ) = g(S) ⊕ h(T ), because the set D f (S⊕T ) ∩ D S depends on whether R (b) holds or not in T , and is not a function of S alone. The formulas χ j , χ i and the domain formulas of the operations g i and g j will be constructed by Proposition 5.37 (the Splitting Theorem for first-order formulas) applied to the quantifier-free formula δ(x) of the definition scheme of f . (Since we want g i and g j to be domain restricting, the other formulas of their definition schemes are fixed, cf. Definition 5.77.) Proposition 5.37 also holds for the general disjoint union defined in Example 5.44, by a proof fully similar to the one of Theorem 5.57. By Proposition 5.37, one can find n, m ∈ N and construct quantifier-free formulas θ 1 (x), . . . , θ n (x), θ n+1 , . . . , θ n+m and ψ 1 , . . . , ψ n , ψ n+1 (x), . . . , ψ n+m (x) of the following forms:

θ i ∈ QF(R , {x}) and ψ i ∈ QF(R , ∅) for each i ∈ [n], θ n+j ∈ QF(R , ∅) and ψ n+j ∈ QF(R , {x}) for each j ∈ [m],
such that for every two disjoint concrete structures S and T of the appropriate types:

{d ∈ D S | S ⊕ T |= δ(d)} = i∈[n] {d ∈ D S | S |= θ i (d) and T |= ψ i } and {d ∈ D T | S ⊕ T |= δ(d)} = j∈[m] {d ∈ D T | S |= θ n+j and T |= ψ n+j (d)}.
For every I ⊆ [n], we define the sentence χ I to be i∈I ψ i ∧ i∈[n]-I ¬ψ i and the domain restricting QF operation g I of type R → R to have domain formula i∈I θ i (x). Similarly, for every J ⊆ [m], we let χ J be the sentence j∈J θ n+j ∧ j∈[m]-J ¬θ n+j , and the domain restricting operation g J of type R → R to have domain formula j∈J ψ n+j (x). Clearly, for all S and T as in the statement:

previous results, but since it is less transparent, we have kept the above proof with congruences. Assume that L is effectively STR pres -recognizable, and let L = β -1 (C) where β is a homomorphism from STR pres to a locally finite, effectively given F QF presalgebra B and C ⊆ B R . Let κ and A be as in the proof of Theorem 5.64 (with h = r = 0).

We define the locally finite

F QF -algebra D such that D R is the set of map- pings from DRQF R to B R × A R ,
⊕ D such that (d ⊕ D d )(f ) := d (g i ) ⊕ B×A d (g j ) for all d ∈ D R and d ∈ D R , provided χ i ∈ d 2 (id R ) and χ j ∈ d 2 (id R )
, where id R is the identity on STR(R). If i and j are not unique, then (d ⊕ D d )(f ) can be defined arbitrarily. Since both B and A are effectively given and DRQF R can be computed, the algebra D is effectively given.

We define the mapping δ from STR to D such that δ(S)(h) := β(h(S)), κ(h(S))

for every R-structure S and every h ∈ DRQF R . Then

L = δ -1 (E) for E := {d ∈ D R | d 1 (id R ) ∈ C}.
It is immediate from the definitions that δ is a homomorphism.

Decidable monadic second-order theories

We have presented undecidability results in Section 5.1.6. Here we present decidability results for sets of graphs of bounded tree-width or clique-width. They extend some "classical" results: the monadic second-order theory of a regular language (of words or of terms) is decidable, by reduction to emptiness problems for languages defined by finite automata. The links between monadic second-order logic and finite automata have been discovered in the 60's with the motivation of finding classes of finite and infinite structures having decidable monadic second-order theories.

Theorem 5.80

(1) Every VR-equational set of (labelled) p-graphs has a decidable CMStheory, equivalently a decidable CMS-satisfiability problem.

(2) Every HR-equational set of (labelled) s-graphs has a decidable CMS 2theory, equivalently a decidable CMS 2 -satisfiability problem.

Proof: (1) Let L be a VR-equational set given by an equation system, with L = L C , and let ϕ be a CMS sentence in CMS(R s,C ). The set of p-graphs (2) The proofs are similar for HR-equational sets and CMS 2 sentences by using Corollary 5.71.

K := {G ∈ GP[C] | G C |=
Corollary 5.81

(1) For each k, the CMS-theory of the set of simple (labelled) graphs of cliquewidth at most k and its CMS-satisfiability problem are decidable.

(2) For each k, the CMS 2 -theory of the set of (labelled) graphs of tree-width at most k and its CMS 2 -satisfiability problem are decidable.

Proof: Immediate consequence of the previous theorem and the results of Chapter 4 (Examples 4.3(8) and 4.43( 5)) showing that the sets CWD(≤ k) and TWD(≤ k) and the corresponding sets of (K, Λ)-labelled graphs (for fixed pairs (K, Λ) of sets of labels) are respectively VR-and HR-equational.

In Section 7.5 we will state converse results establishing that only sets of graphs of bounded tree-width and clique-width can have decidable MS 2 -and C 2 MS-theories respectively.

Logical characterization of recognizability

We have proved in Theorem 5.15 and in Corollaries 5.66 and 5.67 the result stated in Theorem 1.16 that a language (of terms, and of words as a special case) is regular if and only if it is MS-definable. It can be restated and generalized in terms of CMS-definability and recognizability in STR.

We will identify a term t ∈ T (F ) and the structure t that represents it (faithfully). Similarly, we will identify L and L in the following statement and its proof.

Theorem 5.82 Let F be a finite functional signature. The following properties of a language L ⊆ T (F ) are equivalent:

(1) L is recognizable in STR, (2) L is recognizable in T(F ), (3) L is regular over F , (4) L is MS-definable, (5) L is CMS-definable.
The same equivalences hold if L ⊆ A * for some finite alphabet A, with T(F ) replaced by W(A), W left (A) or W right (A).

The translations between sentences and automata are effective.

Proof: Since the representation • is faithful and by Corollary 5.12, a set L ⊆ T (F ) is MS-definable (or CMS-definable) if and only if the class L is.

(1) =⇒ ( 2) follows (for one-sorted F ) from Proposition 3.56 because T(F ) is a subalgebra of a derived algebra of STR (by Application 5.61), cf. the proof of Corollary 5.67.

(2) =⇒ (3): the regularity of L ⊆ T (F ) is equivalent to its recognizability in T(F ) (cf. Theorem 3.62).

(3) =⇒ ( 4) is proved by a translation of a finite automaton A into an MS sentence that defines L(A ) (cf. Theorem 5.15). ( 4) =⇒ ( 5) is trivial; (5) =⇒ ( 4) is proved in Proposition 5.29, using the fact that the structures representing terms are MS-orderable.

(5) =⇒ ( 1) by the Recognizability Theorem (Theorem 5.75).

Since A * is isomorphic to T (U A ) where U A is the unary signature of Definition 2.7, these results specialize to subsets of A * . The algebras W(A), W left (A) and W right (A) have the same recognizable sets.

A natural question is whether there exists a similar characterization for sets of graphs. One could hope that a set of graphs is HR-recognizable if and only if it CMS 2 -definable, but we have proved in Proposition 4.36 that there are uncountably many HR-recognizable sets of graphs. This result forbids any such characterization, as well as any characterization in terms of "finite graph automata" (because different HR-recognizable sets would necessarily correspond to different formulas or automata, and logical languages as well as families of finite automata are countable). Logical characterizations can only exist if recognizability is relativized to particular graph classes. (However, this cardinality argument does not exclude a logical characterization of the effectively HR-recognizable sets of graphs). The following theorem concerns trees and is one motivation among others for introducing counting monadic second-order logic. The more general case of sets of graphs of bounded tree-width will be discussed in Section 7.6.

We consider rooted trees. We view a rooted tree t as an s-graph with one source: the root of t. It can be identified with the {son, rt}-structure t . Thus, t = N t , son t , rt t where ρ(son) = 2, ρ(rt) = 0 and rt t is the root of t. The set of sons of a node is not ordered. We turn the set of rooted trees into an { , ext, * }-algebra R where (the parallel-composition) glues two trees at their roots, and ext is the unary operation that extends a tree by attaching an edge at the root and making the resulting new vertex into the new root. The constant * denotes the tree reduced to a root. We let F rt be the functional signature { , ext, * } (the subscript "rt" means "rooted trees").

Clearly, R is a subalgebra of a derived algebra of JS t , cf. Example 4.3(3): the derived operation ext is defined by the term fg 2 (12 ren 1↔2 (x 1 )), where 1 stands for rt. It is also a subalgebra of a derived algebra of STR, because for simple s-graphs G, Application 5.51 and Example 5.55 also work for R ss,Cstructures G instead of R ms,C -structures G .

If t is a rooted tree, we denote by Unr (t) the unrooted and undirected tree obtained from t by forgetting the root and the directions of edges. Thus, Unr (t) = und (fg rt (t)).

Theorem 5.83 For every set L of rooted trees, the following properties are equivalent:

(

1) L is recognizable in STR, (2) L is recognizable in JS t , (3) L is recognizable in R, (4) L is CMS-definable.
If L is a set of (undirected) trees, then we have the equivalences of ( 1), ( 2), ( 4) and the following property:

(3 ) The set Unr -1 (L) is recognizable in R.

Proof:

The implications (1) =⇒ (3) and ( 2) =⇒ (3) follow from Proposition 3.56 and previous remarks. Implications (4) =⇒ ( 1) and ( 4) =⇒ (2) follow from the Recognizability Theorem (Theorems 5. 75 and 5.68(2), respectively).

We prove implication (3) =⇒ (4). Let L be recognizable in R. There exists a surjective homomorphism h : R → Q where Q is a finite F rt -algebra such that L = h -1 (Q 0 ) for some subset Q 0 of Q (the domain of the algebra Q). The surjectivity of h implies that Q is associative and commutative with unit element * Q because the same properties hold in R.

Let Q be enumerated as {q 1 , . . . , q k }. Let t ∈ R and u 1 , . . . , u n be the sons of the root of t. Let m(t) ∈ N k be the k-tuple (m 1 , . . . , m k ) such that, for each

j ∈ [k], m j is the cardinality of {i ∈ [n] | h(t/u i ) = q j }.
Then h can be factorized as • m for some function :

N k → Q because: h(t) = h(ext(t/u 1 ) • • • ext(t/u n )) = ext Q (h(t/u 1 )) Q • • • Q ext Q (h(t/u n )) = (m 1 ext Q (q 1 )) Q • • • Q (m k ext Q (q k ))
where, for r ∈ N and q ∈ Q, we let r q := q Q • • • Q q with r times q if r ≥ 1 and 0 q = * Q . Hence h(t) can be expressed as a fixed function of m(t). Furthermore, ( 0

) = * Q and (m + m ) = (m) Q (m ) for all m, m ∈ N k as
We now generalize this result. For convenience we only consider one-sorted functional signatures.

Definition 5.85 (Terms over associative and commutative operations) An AC-signature is a pair (F, H) where F is a finite one-sorted functional signature and H ⊆ F is a set of symbols of arity 2. An F -algebra M is an (F, H)-AC-algebra if the operations f M are associative and commutative for all f ∈ H. For example, the algebra R of rooted trees defined above is an (F rt , { })-AC-algebra.

We let T AC (F, H) denote the quotient F -algebra T(F )/≡ AC(H) where ≡ AC(H) is the congruence on T(F ) generated by the associativity and commutativity laws for the operations of H. For every (F, H)-AC-algebra M, there exists a unique homomorphism h : (F, H). This follows from Lemma 3.68, in the same way as Proposition 3.69.

T AC (F, H) → M (see [*BaaNip], [*DersJou] or [*Wec] for these classical facts). It follows that if M is an (F, H)-AC-algebra generated by its signature F , then a set L ⊆ M is recognizable in M if and only if h -1 (L) ⊆ T (F )/≡ AC(H) is recognizable in T AC
Our objective is to obtain a logical characterization of the recognizable sets of the algebra T AC (F, H) similar to those of Theorems 5. 82 and 5.83. We first define a faithful representation of the elements of T (F )/ ≡ AC(H) . For each term t ∈ T (F ), we let t be the term obtained by flattening t as follows. For every symbol f ∈ H we introduce new symbols f m of arity m, for every m ≥ 2. For flattening t, we first replace every occurrence of f ∈ H in t by f 2 , and then we iterate as many times as possible the replacement of a subterm of the form f n (s 1 , . . . , s i-1 , f k (t 1 , . . . , t k ), s i+1 , . . . , s n ) by f n-1+k (s 1 , . . . , s i-1 , t 1 , . . . , t k , s i+1 , . . . , s n ).

For example if F = {g, ⊕, ⊗, a, b, c}, H = {⊕, ⊗} and

t 0 = ⊕(a, ⊗(⊕(g(a, b), ⊕(b, c)), ⊗(g(b, a), ⊗(a, c)))) then t 0 = ⊕ 2 (a, ⊗ 4 (⊕ 3 (g(a, b), b, c), g(b, a), a, c)).
The term t is uniquely defined and any two terms t and t such that t = t are ≡ AC(H) -equivalent, but the converse does not hold because this construction does not take into account the commutativity of the operations of H. We have t ≡ AC(H) t if and only if t and t are equivalent by the congruence that permutes the arguments of the operations of H. In the above example, t 0 is ≡ AC(H) -equivalent to any term t 1 such that

t 1 = ⊕ 2 (⊗ 4 (a, c, g(b, a), ⊕ 3 (b, c, g(a, b))), a).
For t ∈ T (F ), we will represent the equivalence class [t] ≡ AC(H) by a relational structure S(t) obtained as follows from t , where t is the flattened term corresponding to t. We let k := ρ(F ), we let F be the set of all symbols that have an occurrence in t, and k := ρ(F ). (Both F and k depend on t). The term t can be represented, according to Example 5.2(3), by the relational structure t = N t , son t , (lab f t ) f ∈F , (br i t ) 1≤i≤k , rt t , that we transform into:

S(t) := N t , son t , (lab * f t ) f ∈F , (br * i t ) 1≤i≤k , rt t ,
by letting:

lab * f t := lab f t if f ∈ F -H fm∈F lab fm t if f ∈ H br * i t := {u ∈ br i t | the label of the father of u in t is in F -H}.
It is clear that S(t) ∈ STR(R F ) because the unary relations br i for i > k have been eliminated and the subscripts of the symbols in H have been dropped.

Example 5.86 We let F = {g, ⊕, ⊗, a, b, c} and H = {⊕, ⊗}, as before. The two flattened terms

t = g(⊕ 3 (a, g(b, c), a), ⊗ 3 (⊕ 2 (c, a), a, b)) and t = g(⊕ 3 (a, a, g(b, c)), ⊗ 3 (a, b, ⊕ 2 (a, c)))
represent the same element s of T (F )/≡ AC(H) . The structure s = S(t) = S(t ) is shown in Figure 5.4.

Lemma 5.87 For any two terms t, t ∈ T (F ), we have t ≡ AC(H) t if and only if S(t) and S(t ) are isomorphic.

Proof sketch: The effect of the transformation of t into S(t) is to forget the order of arguments of the function symbols that belong to H. The result follows by routine arguments.

For s = [t] ≡ AC(H) belonging to T (F )/≡ AC(H) , we define s as S(t). This structure is well defined by the previous lemma. It makes now sense to say that a subset of T (F )/≡ AC(H) is CMS-definable, or recognizable with respect to an algebra of relational structures, because we can identify an element s of T (F )/≡ AC(H) and its representing structure s .

Theorem 5.88 Let (F, H) be an AC-signature. The following properties of a subset of T (F )/≡ AC(H) are equivalent:

(1) it is recognizable in STR,

(2) it is recognizable in T AC (F, H),

(3) it is CMS-definable.

Proof: (1) =⇒ ( 2). Each operation of T := T AC (F, H) is, via the identification of s ∈ T (= T (F )/≡ AC(H) ) and s ∈ STR(R F ), a derived operation of STR. For f ∈ F -H, we have that f T is f * , as defined in Application 5.61 (with some obvious changes, because we use a variant representation of terms by structures). For f ∈ H and s, s ∈ T , we have that f T (s, s ) = ext f ( s ) ext f ( s ) where is parallel-composition of structures (cf. Example 5.55) and ext f is the QF operation such that ext f (S) = S if S |= lab f (rt) and ext f (S) = ren f1→f (f * 1 (S)) otherwise. This gives the result, as in the proof of Corollaries 5.66 and 5.67 concerning words and terms.

The implication (3) =⇒ ( 1) follows from the Recognizability Theorem. It remains to prove (2) =⇒ (3). We extend the proof of (3) =⇒ (4) of Theorem 5.83. Let L ⊆ T be T-recognizable and h : T → Q be a surjective homomorphism to a finite F -algebra Q such that L = h -1 (Q 0 ) for some Q 0 ⊆ Q. Since f T is associative and commutative for every f ∈ H, the surjectivity of h ensures that f Q is so. Hence Q is an (F, H)-AC-algebra. We enumerate Q as {q 1 , . . . , q k } and, for every f ∈ H and q i1 , q i2 , . . . , q in ∈ Q, n ≥ 3, we extend f Q by defining recursively

f Q (q i1 , q i2 , . . . , q in ) := f Q (q i1 , f Q (q i2 , . . . , q in )). We denote by N k ≥2 the set of k-tuples (m 1 , . . . , m k ) in N k such that m 1 + • • • + m k ≥ 2,
and for each f ∈ H, we define the mapping f : N k ≥2 → Q by: f (m 1 , . . . , m k ) := f Q (q 1 , . . . , q 1 , q 2 , . . . , q 2 , . . . , q k , . . . , q k ) where, for each i ∈ [k], the sequence of arguments of f Q has m i occurrences of q i . For t ∈ T (F ), we let [t] denote [t] ≡ AC(H) . If s = [t] ∈ T and t = f n ( t 1 , . . . , t n ) with f ∈ H (which implies that f is the leading symbol of t but not of any of t 1 , . . . , t n ), we define m(s) := (m 1 , . . . , m k ) where

m j := |{i ∈ [n] | h([t i ]) = q j }|
for each j = 1, . . . , k. Then we have h(s) = f (m(s)), by the definitions and by the associativity and commutativity of f Q .

Our objective is to prove that each set -1 f (q i ) is recognizable in N k . We let ∼ be the equivalence relation on N k defined as follows: m ∼ m if and only if either m, m ∈ N k ≥2 and f (m) = f (m ), or m and m are both not in N k

≥2

and they are equal. This equivalence relation has at most 2k + 1 classes and saturates each set -1 f (q i ). We now prove that it is a congruence on N k . If m, m , r, r ∈ N k and m ∼ m and r ∼ r , we must prove that m + r ∼ m + r . Assume first that m, m , r, r belong to N k ≥2 . Then so do m + r and m + r . Since f Q is associative and commutative, we have

f (m + r) = f Q ( f (m), f (r))
and similarly for m and r . But

f (m) = f (m ) and f (r) = f (r ), hence we get f Q ( f (m), f (r)) = f Q ( f (m ), f (r ))
and m + r ∼ m + r . For the other cases, the verifications are similar. Each set L i := -1 f (q i ) is thus recognizable in N k , hence each property Card Li is CMS-expressible by Proposition 5.25.

As in the proof of Theorem 5.83, we construct a CMS sentence ϕ that defines L = {s ∈ T | h(s) ∈ Q 0 }. The construction combines those of Theorems 5.15 and 5.83. Let s = [t] be represented by the R F -structure S(t) whose domain is the set N t of nodes of the flattened term t. The sentence ϕ is constructed as ∃X 1 , . . . , X k . θ where θ expresses that (X 1 , . . . , X k ) is a partition of N t , that the root belongs to some X i such that q i ∈ Q 0 and that for every

u ∈ N t , u ∈ X i if and only if h([t/u ]) = q i , where u ∈ N t is such that t/u = t/u.
The latter condition is expressed by the following equivalent one:

for every u, if u is an occurrence of f with sons u 1 , . . . , u n and if u j ∈ X ij for each j, then u ∈ X i where i is such that q i = f Q (q i1 , . . . , q in ).

For the expression of the last equality, there are two cases: (a) either f ∈ F -H, n = ρ(f ), and the condition is written in a straightforward way, as in Theorem 5.15, (b) or f ∈ H, and in this case, letting (m 1 , . . . , m k ) count the numbers of states of the set {q i1 , . . . , q in } equal to q 1 , . . . , q k respectively, we need only check that (m 1 , . . . , m k ) ∈ -1 f (q i ), and we do this with the help of Proposition 5.25 as in the proof that (3) implies (4) in Theorem 5.83.

Note that in Case (a), u has an ordered sequence of sons, and a son is the i-th element of this sequence if it belongs to br * i t . In Case (b), it has a set (not a sequence) of at least two sons, of unbounded size.

Remarks 5.89

(1) The proof of ( 2) =⇒ (3) can be seen as the construction of a finite deterministic automaton that runs bottom-up on the syntactic trees of flattened terms. Some nodes of these trees (the occurrences of the symbols in F -H) have a sequence of sons of bounded length and the others have a set of sons of unbounded (finite) cardinality (cf. Remark 5.84(1)).

(2) As in Theorem 5.83, we have the additional equivalent condition of recognizability in JS t : It is implied by (3). However, it is not straightforward to prove that for a subset of T (F )/≡ AC(H) (viewed as a set of labelled s-graphs such as the one in Figure 5.4), its recognizability in JS t implies its recognizability in T, because T is not a subalgebra of a derived algebra of JS t : if f ∈ H, the operation (s, s) → f T (s, s ) has four cases, depending on whether the roots of s and s are labelled f , so that it is not a derived operation. However, more complex derived operations involving conditional statements are defined in [START_REF] Blumensath | Recognizability, hypergraph operations, and logical types[END_REF] (they are called finite state derived operations) that can handle these types of situations. They "preserve recognizability" as do our derived operations (cf. Proposition 3.56(3)) and one can prove by using them that if L ⊆ T (F )/≡ AC(H) , then L ∈ Rec(JS t ) implies L ∈ Rec(T).

Equivalences of logical formulas

In this section, we present some equivalences and transformations of logical formulas from which we can make precise in which sense the sets of first-order and of monadic second-order formulas over a finite signature, of quantifier-height at most some given integer and having free variables in a finite set, can be considered as finite. From these notions, we will bound the indices of the congruences constructed for proving the Recognizability Theorem. However, we will obtain better upper-bounds in the next chapter.

Boolean formulas

We let p 1 , . . . , p n be (standard) Boolean variables and B n be the set of terms T ({∧, ∨, ¬, ⇒, ⇔, True, False}, {p 1 , . . . , p n }), called Boolean terms. We write b ≡ b if b and b in B n are equivalent, i.e., if they define the same Boolean function.

It is well known that b and b are equivalent if and only if b can be transformed into b by the laws of Boolean calculus like ¬¬p ≡ p, p ∨ p ≡ p, p ⇒ q ≡ ¬p ∨ q, p ∧ (q ∨ r) ≡ (p ∧ q) ∨ (p ∧ r) and p ∨ ¬p ≡ True, to take a few examples. We assume that a strict linear order < on n≥0 B n is fixed. (It can be defined as a lexicographic ordering on formulas considered as words; we need not specify it precisely.)

For each n and each b ∈ B n , there is a unique formula b in B n that is equivalent to b and is in disjunctive normal form in such a way that:

-disjuncts are ordered by increasing order with respect to <, -in each disjunct, each variable from {p 1 , . . . , p n } occurs exactly once and variables occur in increasing order of indices.

Let us take examples.

If b = ¬¬p 1 and n = 1, then b = p 1 , but if n = 2, we have b = (p 1 ∧ p 2 ) ∨ (p 1 ∧ ¬p 2 ). If n = 3 and b = p 1 ∧ (p 2 ∨ ¬p 3 ), then b = (p 1 ∧ p 2 ∧ p 3 ) ∨ (p 1 ∧ p 2 ∧ ¬p 3 ) ∨ (p 1 ∧ ¬p 2 ∧ ¬p 3 ).
Let us now assume that L ⊆ CMS(R, X ) is a set of formulas whose outermost symbol is not in {∧, ∨, ¬, ⇒, ⇔, True, False}. We denote by B n [L] the set of formulas of the form b(ϕ 1 , . . . , ϕ n ) (which abbreviates b[ϕ 1 /p 1 , . . . , ϕ n /p n ]) where b ∈ B n , ϕ 1 , . . . , ϕ n ∈ L and for each i, ϕ i is substituted for p

i in b. It is clear that B n [L] ⊆ C r MS h (R, X ) if L ⊆ C r MS h (R, X ).
We also assume that CMS(R, X ) is linearly ordered by some strict ordering <.

Definition 5.90 (Boolean normalization)

If ϕ = b(ϕ 1 , . . . , ϕ n ) ∈ B n [L]
, then we denote by ϕ the formula in B k [L] constructed as follows, for some appropriate k ≤ n:

-we enumerate {ϕ 1 , . . . , ϕ n } as {ϕ i1 , . . . , ϕ i k } with ϕ i1 < • • • < ϕ i k and
k ≤ n (we have k < n if ϕ i = ϕ j for some i and j = i);

-we write accordingly ϕ as b (ϕ i1 , . . . , ϕ i k ) for some b ∈ B k ;

-we let ϕ be b (ϕ i1 , . . . , ϕ i k ).

Note that ϕ = ϕ if ϕ = ψ for some ψ. We call ϕ a normalized Boolean combination of formulas.

We let

B[L] := n≥0 B n [L] and B[L] := { ϕ | ϕ ∈ B[L]}. We let β(m) be the number Σ 0≤p≤m 2 2 p • m p . It will be enough to note that 2 2 m < β(m) < 2 2 m+1 .
With these hypotheses and notation we have Proof: (1) Clear from the definition and the classical results of Boolean calculus. Note that the same formulas of L appear as subformulas of ϕ and of ϕ.

(2) For each finite set {ϕ 1 , . . . , ϕ p } of pairwise distinct formulas, one can build 2 2 p formulas in B[{ϕ 1 , . . . , ϕ p }] containing each formula ϕ i as a subformula; they are the formulas b(ϕ 1 , . . . , ϕ p ) for all b in B p . Hence:

| B[L]| = Σ K⊆L 2 2 |K| = β(|L|)
by the definition of β. It is clear that one can (in principle, not practically) compute the finite set B[L] if the finite set L is given.

Monadic second-order formulas

In this section, X will always denote a finite subset of the countable set V 1 of first-order and set variables (cf. Section 5.1.4). Furthermore, r and h denote elements of N , and R is a fixed relational signature.

The semantic equivalence ≡ on formulas of CMS(R, X ) (defined at the beginning of Section 5.2) is undecidable 71 . Our objective is to define a syntactic equivalence ≈ that refines ≡ (i.e., such that ϕ ≈ ψ implies ϕ ≡ ψ), is decidable and is finite over each set C r MS h (R, X ).

We let ∼ be the equivalence relation on CMS(R, X ) generated by the following elementary transformation rules and their inverses (where u denotes a first-order or a set variable):

(1) application of a law of Boolean calculus like the replacement of ϕ ∨ ϕ by

ϕ or of ϕ ∧ (ψ ∨ ψ ) by (ϕ ∧ ψ) ∨ (ϕ ∧ ψ ),
(2) replacement of ∀u. ϕ by ¬∃u. ¬ϕ,

(3) renaming of bound variables, e.g., replacement of ∃u. ϕ by ∃w. ϕ[w/u] if w has no free occurrence in ϕ.

If ψ is obtained from ϕ by rule (3) only, we write ϕ ≡ α ψ and say that ϕ and ψ are α-equivalent.

It is clear that ϕ ∼ ψ implies ϕ ≡ ψ. Moreover, if ϕ ∼ ψ and ϕ ∈ C r MS h (R, X ) then ψ ∈ C r MS h (R, X ).
For example, let ϕ be the sentence:

∀X¬∃y(y ∈ X ∧ (∃z. R(y, z) ∨ ∃z . R(y, z )))
and ψ be the sentence:

¬∃X, y(y ∈ X ∧ ∃z. R(y, z)).
We have ϕ ∼ ψ. On the other hand, ∃y(y = y ∨ R(x, y)) is not ∼-equivalent to ∃y. R(x, y) because, although y = y ∨ R(x, y) is ≡-equivalent to R(x, y), these formulas are not equivalent with respect to ∼.

We now define a transformation of formulas, such that if ϕ is transformed into ϕ, then ϕ ∼ ϕ and thus ϕ ≡ ϕ. We assume that a linear order is fixed on the set V 1 of first-order and set variables.

Definition 5.92 (Normalization of formulas)

With each ϕ ∈ CMS(R, X ), we associate a formula ϕ ∈ CMS(R, X ) by the following algorithm:

Step 1: We transform ϕ into ϕ written without universal quantifiers by using rule (2) of the definition of ∼. Hence, we obtain ϕ in CMS(R, X ) that is ∼-equivalent to ϕ. In what follows we still denote ϕ by ϕ for more readability.

Step 2: For every finite subset Y of V 1 that is disjoint with X and contains at least qh(ϕ) first-order variables and at least qh(ϕ) set variables, we transform ϕ into ϕ Y , by induction on |ϕ| (the size of ϕ, see Section 5.1.3): Case 1: If ϕ is atomic, we let ϕ Y be ϕ.

71 A consequence of Theorem 5.5 and the other classical undecidability results. The equivalences of formulas with respect to finite and infinite, and to finite and countable structures instead of with respect to finite ones (which is our definition of equivalence), are also undecidable.

∈ C r MS h-1 (R, X ∪ {u}), we define ϕ Y as ∃y 1 . ψ[y 1 /u] Y-{y1}
where y 1 is the first first-order variable in Y (with respect to the order on V 1 ).

Case 4: If ϕ is ∃U. ψ, where U is a set variable and

ψ ∈ C r MS h-1 (R, X ∪ {U }), we define similarly ϕ Y as ∃Y 1 . ψ[Y 1 /U ] Y-{Y1}
where Y 1 is the first set variable in Y.

It can easily be shown, simultaneously with the above definition, that if ϕ ≡ α ϕ , then ϕ Y = ϕ Y . 72 That implies that ϕ Y is well defined in Cases 3 and 4 (note that the substitutions ψ[y 1 /u] and ψ[Y 1 /U ] are only defined modulo αequivalence).

Step 3: We define ϕ as ϕ Y where Y consists of the first qh(ϕ) first-order variables that are not in X and the first qh(ϕ) set variables that are not in X . Let us take an example. Let ϕ be the sentence of quantifier-height 3 expressing that an undirected graph is not connected:

∃X ∃x. x ∈ X ∧ ∃y. y / ∈ X ∧ ∀u, v(u ∈ X ∧ edg(u, v) ⇒ v ∈ X) .
After eliminating ∀ and ⇒ and using Boolean laws, we obtain the equivalent sentence:

∃X ∃x. x ∈ X ∧ ∃y. y / ∈ X ∧ ¬∃u, v(u ∈ X ∧ edg(u, v) ∧ v / ∈ X) ,
and after renaming its bound variables, we get the sentence ϕ:

∃Y 1 ∃y 1 . y 1 ∈ Y 1 ∧ ∃y 1 . y 1 / ∈ Y 1 ∧ ¬∃y 1 , y 2 (y 1 ∈ Y 1 ∧ edg(y 1 , y 2 ) ∧ y 2 / ∈ Y 1 )
where y 1 , y 2 are the first two first-order variables of V 1 and Y 1 is its first set variable.

Proposition 5.93 For every ϕ ∈ C r MS h (R, X ), we have:

(1) ϕ ∈ C r MS h (R, X ) and the set of bound variables of ϕ is {y i | 1 ≤ i ≤ h 1 } ∪ {Y i | 1 ≤ i ≤ h 2 } for some integers h 1 , h 2 ∈ [0, qh(ϕ)]
, where y i is the i-th first-order variable of V 1 -X and Y i its i-th set variable;

(2) ϕ ∼ ϕ and thus, ϕ ≡ ϕ;

(3) the mapping ϕ → ϕ is idempotent, i.e., if ϕ = ψ for some ψ, then ϕ = ϕ. Proof: We prove the same assertions for each ϕ Y (where, in Assertion ( 1), V 1 -X is replaced by Y), by induction on |ϕ|. We can assume that ϕ is written without universal quantifiers by the first step of the algorithm of Definition 5.92.

In Case 1, ϕ is quantifier-free and the result is obvious. In Case 2, the result follows by induction and Proposition 5.91 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. In Case 3, For each r, h, R, X , we define:

ψ[y 1 /u] Y-{y1} ∼ ψ[y 1 /u]
C r MS h (R, X ) := { ϕ | ϕ ∈ C r MS h (R, X )}.
We let f (r, R, n) be a computable upper-bound to the number of atomic formulas in C r MS(R, X ) for any X with at most n variables. Without loss of generality, we can assume that f is monotone in n, i.e., that f (r, R, n) ≤ f (r, R, n + 1). We define g(h, r, R, n) ∈ N by the following induction:

g(0, r, R, n) = β(f (r, R, n)), g(h + 1, r, R, n) = β(3 • g(h, r, R, n + 1)),
where β is the function of Definition 5.90; the function g is thus monotone in n. We recall that 2 2 m < β(m) < 2 2 m+1 . An easy calculation (by using an induction on h) yields:

73 exp(2h + 2, f (r, R, n + h)) < g(h, r, R, n) < exp(2h + 2, f (r, R, n + h) + h + 1).
Proposition 5.94 For each r, h, R, X , we have:

| C r MS h (R, X )| ≤ g(h, r, R, |X |),
and the finite set C r MS h (R, X ) can be computed from r, h, R, X .

Proof: We prove this by induction on h for every set C

r MS h Y (R, X ) := { ϕ Y | ϕ ∈ C r MS h (R, X )}. If h = 0, then the formulas of C r MS 0 (R, X ) are Boolean combinations of atomic formulas. Hence C r MS 0 Y (R, X ) = B[L]
where L is the set of atomic formulas in C r MS(R, X ). By Proposition 5.91(2), this set can be computed and has cardinality at most β(f (r, R, |X |)) = g(0, r, R, |X |) by the definitions of f and g.

If h ≥ 0, then a formula ϕ of C r MS h+1 (R, X ) is a Boolean combination of (atomic or existential) formulas in C r MS h (R, X ) and of formulas of the form ∃u. ψ where ψ ∈ C r MS h (R, X ∪ {u}) and u is a first-order or a set variable. Hence, ϕ Y is a normalized Boolean combination θ of (atomic or existential) formulas in C r MS h Y (R, X ) and of formulas of the form ∃y 1 . ψ or ∃Y 1 . ψ , where ψ

(resp. ψ ) is in C r MS h Y-{y1} (R, X ∪ {y 1 }) (resp. C r MS h Y-{Y1} (R, X ∪ {Y 1 })).
Vice versa, every such formula θ equals ϕ Y for some ϕ in C r MS h+1 (R, X ) (if θ is ∃y 1 . ψ as above, then θ Y = ∃y 1 . ψ Y-{y1} = ∃y 1 . ψ by idempotency, see Proposition 5.93(3), and so θ = θ Y ). By Proposition 5.91(2), this set of formulas θ can be computed and has cardinality at most g(h, r, We now evaluate f (r, R, n) in some concrete cases. The atomic formulas written with a finite set X of first-order and set variables, a relational signature R and cardinality predicates Card p,q (X) for p < q ≤ r are of the following forms:

R, |X |) + 2 • g(h, r, R, |X | + 1) ≤ 3 • g(h, r, R, |X | + 1) (because g is monotone in its last argument) which gives | C r MS h+1 Y (R, X )| ≤ g(h + 1, r, R, |X |).
True, False, s = t, t ∈ X, Card p,q (X) and R(t 1 , . . . , t ρ(R) ) for s, t, t 1 , . . . , t ρ(R) ∈ X ∪ R 0 , R ∈ R + and X ∈ X .

Hence we can take as bounding function:

f (r, R, n) = 2 + (n + c) 2 + n(n + c) + nr 2 + R∈R+ (n + c) ρ(R) ,
where n = |X | and c = |R 0 |. (A more precise estimate could be obtained by counting separately first-order and set variables, by considering s = t as identical to t = s, etc., but would not be very useful because of the predominant influence of the quantifier-height in Proposition 5.94).

For handling directed s-graphs G of type C and represented by G , we can use the relational signature R = R d ms,C consisting of the two binary relation symbols in 1 and in 2 and k := |C| constant symbols. We get f (r, R, n) = 3(n + k) 2 + n(n + k) + nr 2 + 2. If we use the alternative signature {in, lab Edge } where we replace one binary relation by a unary one, we obtain the slightly smaller function

f (r, R, n) = 2(n + k) 2 + n(n + k) + nr 2 + n + k + 2.
For handling p-graphs with k port labels we use a signature R consisting of one binary relation symbol and k unary ones. Thus, f (r, R, n) = 3n 2 +nr 2 +nk+ 2. From this observation and the computation in the proof of Corollary 5.95, we get that there are at most β(2k + 14) m+1 QF operations transforming p-graphs of type C of cardinality k into p-graphs of type D of cardinality m.

Numbers of formulas and recognizability indices

Theorem 5.64 has established that for every sentence ϕ in CMS(R, ∅) the class of structures MOD(ϕ) ⊆ STR(R) is recognizable in STR pres . The following theorem bounds its recognizability index (Section 3.4.3). We will use the function f that bounds the number of atomic formulas (cf. Proposition 5.94).

Theorem 5.96 Let R be a relational signature and ϕ ∈ C r MS(R, ∅) for some r ∈ N . The recognizability index of MOD(ϕ) with respect to the algebra STR pres is bounded by the function that maps each sort R to exp(2h + 3, f (r, R , h) + h + 1), where h := qh(ϕ). Let us make this more concrete by bounding the recognizability indices relative to the HR and the VR algebras that have been defined in Chapter 4 (cf. Definitions 4. 33 and 4.52). Since the many-sorted VR and HR algebras are subalgebras of derived algebras of STR, the recognizability index of a homogenous set of p-graphs or s-graphs is at most that of the corresponding set of structures, for all sorts of those subalgebras (cf. the proofs of Propositions 3. 56 and 3.64). The upper-bound on the recognizability index of a class MOD(ϕ) we have given depends on the quantifier-height of ϕ by an iterated exponentiation. Similar lower bounds are known, see [StoMey] and [Wey]. However, the recognizability index γ of a homogenous CMS-or CMS 2 -definable set of p-graphs or s-graphs, is a finitely iterated exponential function 74 , because the nesting of exponentiations depends only on the quantifier-height of the defining sentence, and the number of atomic formulas is bounded by a polynomial in the number of port or source labels.

In the following corollary, the size of a p-graph is its number of vertices, and the size of an s-graph is its number of vertices and edges.

Corollary 5.97 For every CMS-definable set of p-graphs L there exists a finitely iterated exponential function f L : N → N such that, for every k ∈ N , if L k is the set of p-graphs in L of clique-width at most k then:

(1) if L k = ∅, then it contains a p-graph of size at most f L (k), (2) if L k is finite, then every p-graph in L k has size at most f L (k).
Similar results holds for CMS 2 -definable sets of s-graphs and tree-width.

Proof: We first prove this for HR. Since every CMS 2 -definable set of s-graphs is a finite union of homogenous CMS 2 -definable sets of s-graphs, as shown in the proof of Theorem 5.68, we may assume that L is homogenous. Let E be the type of its elements, and let TWD(≤ k -1, = E) be the set of all s-graphs of type E and tree-width at most k -1. By Example 4.3( 8 The numbers of formulas are more than "cosmological" ( [StoMey]), and practical implementations are not directly possible. Better upper bounds will be given in Chapter 6. They are based on an alternative proof of the Weak Recognizability Theorem.

The sentence expressing connectivity has quantifier-height 3. This gives, for graphs of tree-width ≤ k an HR-recognizability index of the form exp(9, p(k)) for some polynomial p whereas, by a direct analysis, we found in Example 4.30(2) an upper-bound of O(k!).

Remark 5.98 The reader may ask why we do not use prenex formulas, that is, formulas of the form ∀ w 1 ∃ w 2 ∀ w 3 • • • θ where w 1 , w 2 , . . . are possibly empty sequences of first-order and set variables and θ is quantifier-free. There would be no loss of generality in doing so because every formula ϕ can be transformed into an equivalent prenex formula ϕ. For doing this, one uses iteratively rules like the one transforming ∃x. θ ∧ ∃y. θ into ∃x, y(θ ∧ θ ) where x and y are distinct variables respectively not free in θ and in θ, together with renamings of bound variables. 75 The size of ϕ is at most one more than that of ϕ but its quantifier-height may increase in a non-linear way. There exist formulas ϕ n in FO({edg}, {x, y}) of size O(n 2 ) and quantifier-height n such that ϕ n has quantifier-height O(n 2 ). One takes ϕ n (x, y) expressing that for every m, 1 ≤ m ≤ n, there is a directed walk of length m + 1 in the considered graph from vertex x to vertex y.

About descriptive complexity we refer the reader to the books by Libkin [*Lib04], Ebbinghaus and Flum [*EbbFlu] and Immermann [*Imm].

Theorem 5.5 stating the undecidability of the first-order satisfiability problem for finite graphs is due to Trakhtenbrot. See [*Lib04] or [*EbbFlu] for the proof. Stronger versions result from restrictions to particular classes of graphs. The case of graphs of degree at most 3 is proved in [Wil], that of planar graphs of degree at most 4 is proved in [Her] and that of planar graphs of degree at most 3 is stated with a handwaving proof in [GarSha]. Theorem 5.6 is due to Seese ([See91]).

That MS 2 -formulas are no more expressive than MS 1 -formulas for expressing the properties of graphs in certain classes of graphs is proved in [START_REF] Courcelle | The monadic second-order logic of graphs VI: On several representations of graphs by relational structures[END_REF] and [START_REF] Courcelle | The monadic second-order logic of graphs XIV: Uniformly sparse graphs and edge set quantifications[END_REF]. Guarded second-order formulas defined in [GräHO] are equivalent to our MS 2 -formulas. (The equivalence is valid for all structures; see Section 7 of [GräHO]).

The definability by monadic second-order formulas of linear orderings of the vertex sets of graphs from particular classes is studied in [START_REF] Courcelle | The monadic second-order logic of graphs X: Linear orderings[END_REF]. (Such a definition for all graphs by a unique monadic second-order transduction is impossible.) Some of these results yield logical characterizations of recognizability for subsets of certain graph classes and for traces: Traces are partially ordered 75 Since we allow empty structures, some usual transformations of formulas fail to preserve equivalence. For example the sentence ∃x(x = x) ∨ ∀y(y = y) is not equivalent to the sentence ∃x(x = x ∨ ∀y(y = y)) because it is true in the empty structure whereas the latter sentence is not. Nevertheless, every monadic second-order formula ϕ has an equivalent monadic secondorder formula ϕ in prenex form that we construct as follows. We let ϕ be the "usual" prenex form of ϕ, equivalent to ϕ in all nonempty structures. The formulas ϕ and ϕ have the same free variables. If ϕ has free first-order variables, we let ϕ be ϕ. Otherwise, if ∅ |= ϕ(∅, . . . , ∅), we let ϕ be ∀x. ϕ where x is a first-order variable; if ∅ |= ¬ϕ(∅, . . . , ∅), we let ϕ be ∃x. ϕ. In the first case, ϕ and ϕ cannot be satisfied in the empty structure because their free first-order variables cannot have any value. Hence ϕ is equivalent to ϕ also in the empty structure. In the second case, it is not hard to check that ϕ and ϕ are equivalent in all structures including the empty one.

sets with labelled elements that represent equivalence classes of words with respect to congruences generated by commutativity rules of the form ab ≡ ba, where a, b are letters; the theory of traces is developed in the book [*DiekRoz]. Lemma 5.27 entails that every CMS formula can be translated into an orderinvariant MS formula written with an additional binary relation ≤ intended to be interpreted by linear orderings. But some order-invariant MS sentences are not equivalent to CMS sentences ( [GanRub]).

The Splitting Theorem for disjoint unions of structures follows the paradigm of a result by Feferman and Vaught. This theorem, its history and its numerous variants and consequences are presented by Makowsky in [*Mak]. The proof of the Splitting Theorem given in this chapter is both more general and (hopefully) more clear than the original versions published in [START_REF] Courcelle | An axiomatic definition of context-free rewriting and its application to NLC graph grammars[END_REF][START_REF] Courcelle | The monadic second-order logic of graphs I: Recognizable sets of finite graphs[END_REF][START_REF] Courcelle | Monadic second-order evaluations on tree-decomposable graphs[END_REF]. The name "Splitting Theorem" refers to a polynomial-time algorithm that computes the Tutte polynomial of the graphs of tree-width bounded by a given integer. The relevance to the present situation is explained in [*Mak].

Other proofs of the Weak Recognizability Theorem and its algorithmic applications will be presented in Chapter 6.

Apart from finite automata on terms, finite automata on labelled rooted trees (called unordered, unranked trees) and on labelled rooted unranked, ordered trees have been defined and compared with monadic second-order logic and related languages. We refer the reader to [*Cou96b, *Lib06, BonTal, Cou89a] and to Chapter 8 of the book [*Com+].

The results of Section 5.6 improve some results from [CouWei].

Chapter 6

Algorithmic Applications

This chapter is devoted to the algorithmic applications of the Recognizability Theorem (Theorem 5.75, Section 5.3.10), one of the main results of this book. We will prove the existence of fixed-parameter tractable algorithms with tree-width and clique-width as parameters that solve the model-checking problem for monadic second-order sentences, or that count or list the answers to queries expressed by monadic second-order formulas with first-order free variables. These algorithms are based on graph decompositions of different types, that are formalized as terms over the signatures F HR and F VR . They use two main constructions. The first one is the parsing of the input graph, that is, the computation of a term in T (F HR [k] ) or in T (F VR [k] ), for given values of k, that evaluates to this graph. The second one is a kind of "compilation" of the given monadic second-order formula into a finite automaton over the signature F HR

[k] or F VR [k] . 1
Both constructions raise difficult algorithmic problems. Concerning the second one, the existence of a finite automaton follows from the Weak Recognizability Theorem (Corollary 5.69), but the proof gives no usable algorithm for constructing automata. We give an alternative construction in Section 6.3 that is essentially the one done by Büchi in the early 60's and implemented by Klarlund and his team ([BasKla, Hen+, Kla]) in the software MONA. We will present some improvements tending to lower the sizes of the automata constructed from monadic second-order formulas. Even if automata cannot be constructed in practice from logical descriptions and by general algorithms, it is useful to know that they exist. This existence motivates the research of alternative constructions based on combinatorial properties rather than on logical formulas.

Section 6.1 reviews terminology and states the results that follow from the Recognizability Theorem. Section 6.2 reviews the main parsing algorithms. Sections 6.3 and 6.4 are devoted to the constructions of automata and their uses for model-checking and other algorithmic problems. We will also compare several proofs of the Recognizability Theorem.

Fixed-parameter tractable algorithms for model-checking

We first recall from Chapter 1 the definition of a fixed-parameter tractable algorithm. We generalize it slightly by allowing the parameters to have other values than integers. Definition 6.1 (Fixed-parameter tractable algorithms) A decision problem is defined as a pair (C, P ) consisting of an effectively given set C and a computable mapping P : C → {True, False}, i.e., P is a decidable property of the elements of C. We assume that each element d of C has a computable size |d| in N . We also assume that C is parametrized, i.e., that it is equipped with a computable function p : C → N such that p(d) ≤ |d| for every d ∈ C.

An algorithm that decides whether P (d) = True for every element d of C is fixed-parameter tractable (FPT) with respect to p if its computation time is bounded, for every input d, by an expression of the form f (p(d)) • |d| c for some fixed computable function f : N → N and some fixed positive integer c.2 A decision problem is fixed-parameter tractable with respect to some parameter p if it has an algorithm that is fixed-parameter tractable with respect to p. If c = 1, 2 or 3, we say that the algorithm (hence also the decision problem it solves) is fixed-parameter linear, fixed-parameter quadratic or fixed-parameter cubic respectively, with respect to p.

If C is a set of graphs, the size of an input graph G is usually its number of vertices and edges, denoted by G , or, in many cases, its number of vertices, denoted by |G|. The parameter can be the degree of G, its tree-width or its clique-width3 . Other examples can be found in the books [*DowFel] and [*FluGro] which present in detail the theory of fixed-parameter tractability.

In model-checking problems (see the next definition), the input is, typically, a pair consisting of a sentence ϕ and a relational structure. In most applications, such a structure represents a graph G, but we have seen other cases in Section 1.9. The parameter is frequently, for a model-checking problem on (labelled) graphs, the integer twd (G) + |ϕ|.

However, we will extend the initial definition so as to allow the parameter function p to take its values in any effectively given set D, and not only in N . We still require that p : C → D and f : D → N are computable functions (which is meaningful on effectively given sets). In the above case we will use the parameter (twd (G), ϕ) that is more natural than twd (G) + |ϕ|. Since, for (labelled) graphs, there are only finitely many sentences of size bounded by a given integer (up to renamings of bound variables, and of vertex and edge labels), it is equivalent to say that the time taken by an algorithm is g(twd (G), ϕ) • G c for some computable function g or f (twd (G) + |ϕ|) • G c for some computable function f , because if we know g, we can obtain f as follows:

4 f (p) := max{g(k, ϕ) | k ≤ p, |ϕ| ≤ p -k},
and the parameters (twd (G), ϕ) and twd (G) + |ϕ| are both computable from the input (ϕ, G). So, we get equivalent definitions for fixed-parameter tractability because there is no condition on the time necessary to compute the function f . A similar argument holds for all parameters considered in this chapter.

It is important to specify the parameter when saying that a problem is FPT. For example, the problem of deciding whether a graph G satisfies an MS sentence ϕ is FPT with respect to (ϕ, twd (G)), but neither with respect to ϕ nor to (ϕ, Deg(G)), where Deg(G) is the degree of G (unless P = NP, since 3colorability is MS-expressible and NP-complete on graphs of degree at most 4: see [*GarJoh], problem GT4).

Our definitions differ from those of [*DowFel] and [*FluGro] on some minor points: Downey and Fellows put the value of the parameter as an explicit part of the input. In other words, the input of an algorithm parametrized by p is the pair (d, p(d)) instead of d. Our definition corresponds in this case to their strongly uniform fixed-parameter tractability (cf. Definition 2.4 in [*DowFel]). Flum and Grohe require that the parameter function p be computable in polynomial time. This is not the case of tree-width (as a mapping from graphs to integers) and they waive the polynomial-time constraint in Section 11.4 of [*FluGro]. Our objective is not to develop, or even to discuss, the theory of fixed-parameter tractability, but to have simple definitions that cover the cases we will present (see Theorems 6. 3 and 6.4). We refer the reader to the above cited books for detailed discussions of the definitions. Definition 6.2 (Model-checking) Let L be a logical language, typically first-order logic or monadic second-order logic, and let C be a set of relational structures. The model-checking problem for (C, L), denoted by MC(C, L) is defined as follows:

Input: An R-structure S in C and a sentence ϕ in L(R, ∅).

Question: Is it true that S |= ϕ?

We will analyze model-checking algorithms in terms of the sizes of the input structures: the size of S, denoted by S , is defined in Definition 5.3 and compared there to the size of the word, the term or the graph it may represent. The parameters will consist of the sentence and of the tree-width or the clique-width of S. The tree-width and the clique-width of a binary structure can be taken as those of the corresponding labelled graphs. General definitions will be given in Chapter 9. In the present chapter, we will only consider binary relational structures that represent words, terms and graphs (via the representation • for the model-checking of CMS sentences, and via • for CMS 2 ones). Theorem 6.3

(1) For every finite functional signature F , the problem MC(T (F ), CMS) is fixed-parameter linear with respect to (F, ϕ) where ϕ is the input sentence.

(2) For every triple of finite, pairwise disjoint sets of labels (C, K, Λ), the problem of checking whether val (t

) C |= ϕ for t ∈ T (F HR C,[K,Λ] ) and ϕ ∈ CMS 2 (R m,C,[K,Λ] , ∅) is fixed-parameter linear with respect to (C, K, Λ, ϕ).
(3) For every triple of finite, pairwise disjoint sets of labels (C, K, Λ), the problem of checking whether val (t

) C |= ϕ for t ∈ T (F VR C,[K,Λ] ) and ϕ ∈ CMS(R s,C,[K,Λ] , ∅) is fixed-parameter linear with respect to (C, K, Λ, ϕ).
In these statements, we use parameters that are tuples of finite objects rather than integers. We do not consider F, C, K, Λ and ϕ as fixed, but as parts of the input and of the parameter. 5Proof: (1) Let F be a finite functional signature and ϕ belong to CMS(R F , ∅). By Corollary 5.67, one can construct a finite deterministic automaton A that recognizes the set of terms t in T (F ) such that t |= ϕ. This being done, say in time f 1 (F, ϕ), then for any given t ∈ T (F ), one need only run A on t to get the answer. This answer is obtained in time a • |t| where a is an upperbound to the time necessary to perform a transition. This time depends on A , hence on F and ϕ. The global time for getting the result is thus of the form

f 1 (F, ϕ) + f 2 (F, ϕ) • |t|.
(2) For every C, K, Λ and ϕ as in the statement, one can construct by the Weak Recognizability Theorem for the HR algebra (Corollary 5.69), and by Proposition 3.76(2) and Theorem 3.62, a finite deterministic automaton A that recognizes the set of terms val

-1 (L) ⊆ T (F HR C,[K,Λ] ), where L is the set of s-graphs {G ∈ J S gen [K,Λ] [C] | G C |= ϕ}.
Then, for any given term t ∈ T (F HR C,[K,Λ] ), one need only run A on t to find out whether val (t) C |= ϕ. As above, the computation time is of the form

f 1 (C, K, Λ, ϕ) + f 2 (C, K, Λ, ϕ) • |t|.
(3) Similar to Case (2) with the VR algebra.

The algorithms that prove Assertions (2) and (3) of this theorem take terms as inputs and not graphs. If we want to check if G |= ϕ for a given graph G, we need to parse it first, that is, to find a term t ∈ T (F HR C, [K,Λ] ) such that G = val (t)

with n vertices, computes in time g(cwd (G), K, Λ)

• n 3 a term in F VR [hΛ(G)],[K,Λ]
that evaluates to G, where h Λ (G) is a positive integer that can be computed from G (this integer is bounded in terms of cwd (G) and Λ, but is independent of K; see the proof of Proposition 6.8). This will complete the proof with the help of Theorem 6.3(3).

The proof for parameter (cwd (G), ϕ) is also similar to the one in [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. In this case, G is obtained from G by removing all vertex labels in K -K ϕ and all edges that have labels in Λ -Λ ϕ . Since cwd (G ) ≤ cwd (G), the function f can now be defined from

f by f (k, ϕ) := max{f (m, K ϕ , Λ ϕ , ϕ) | 0 ≤ m ≤ k}.
It is straightforward to generalize Theorem 6.4 to s-graphs in J S [K,Λ] [C] and p-graphs in GP [K,Λ] [C], via the representations • C and • C respectively (where C belongs to the input but not to the parameter). In fact, the source and port labels of C can just be viewed as additional vertex labels, and Theorem 6.4 can be applied to the resulting graphs in J S [C∪K,Λ] [∅] and GP [C∪K,Λ] [∅]. Definition 6.5 (Property-checking; counting and optimizing) Theorems 6.3 and 6.4 provide algorithms for model-checking, that is, for verifying that a given relational structure (in particular, one representing a graph) satisfies a property expressed by a given sentence in some fixed logical language.

Property-checking is the problem of verifying that a given assignment in a given relational structure satisfies a given formula, hence that the elements specified by the assignment satisfy a certain property. We will see in Section 6.4 that the algorithms of Theorems 6.3 and 6.4 extend to the property-checking problem.

We now define monadic second-order counting functions. For convenience we only consider formulas of which all free variables are set variables. Let be given a relational signature R and a monadic second-order formula ϕ with set of free variables X := {X 1 , . . . , X n , Y 1 , . . . , Y p }. Let S be a concrete R-structure and γ be an {Y 1 , . . . , Y p }-assignment in it. We let sat(S, ϕ, (X 1 , . . . , X n ), γ) be the number of n-tuples (U 1 , . . . , U n ) in P(D S ) n such that (S, γ ) |= ϕ, where γ is the X -assignment in S that extends γ and is such that γ (X j ) := U j for each j ∈ [n]. If p = 0, we drop γ from the notation; in this case sat(S, ϕ, (X 1 , . . . , X n )) is the cardinality of sat(S, ϕ, (X 1 , . . . , X n )). We call the function that maps γ to sat(S, ϕ, (X 1 , . . . , X n ), γ) for fixed ϕ and S a monadic second-order counting function; its computation is a monadic second-order counting problem.

Finally, we define optimizing functions in a similar way. We let R, ϕ, X , S and γ be as above, with n = 1, so X := {X, Y 1 , . . . , Y p }. We define Maxsat(S, ϕ, X, γ) as the maximum cardinality of a subset U of D S such that (S, γ ) |= ϕ, where γ is the X -assignment in S that extends γ and is such that γ (X) := U . As before, we drop γ from the notation if p = 0; in that case Maxsat(S, ϕ, X) is the maximal cardinality of the sets in sat(S, ϕ, X). We call the function that maps γ to Maxsat(S, ϕ, X, γ) for fixed ϕ and S, or the one defined similarly with minimum instead of maximum, a monadic secondorder optimizing function; its computation is a monadic second-order optimizing problem.

In Section 6.4.3 we will extend Theorems 6.3 and 6.4 to the computation of monadic second-order counting and optimizing functions by FPT algorithms.

Decomposition and parsing algorithms

The algorithms of Theorem 6.4 need to parse the input graphs, i.e., to compute appropriate terms evaluating to them. We will review three types of algorithms: those that construct tree-decompositions, easily convertible into terms over F HR or F HR [K,Λ] , those that construct such terms from derivation trees for graphs defined by HR equation systems and those that construct terms over

F VR or F VR [K,Λ] .

Constructing tree-decompositions

Since the tree-width of a graph depends neither on the directions and multiplicities of its edges, nor on the existence of loops nor on its possible vertex and edge labels, we will only consider simple, loop-free, undirected graphs. As discussed in the proof of Theorem 6.4( 1), if G is a (K, Λ)-labelled graph, every tree-decomposition of core(G) (cf. Remark 2.55(d)) is a tree-decomposition of G and can be converted in linear time into a term in T (F HR [K,Λ] ) evaluating to G (by Theorem 2.83 and Proposition 2.47).

The problem of deciding if twd (G) ≤ k for a given pair (G, k) is NP-complete and can be solved in time O(n k+2 ) where n = |V G | ( [ArnCP]), and the corresponding algorithm constructs a tree-decomposition of width at most k if twd (G) ≤ k. In the sequel we will only quote decomposition algorithms for this problem, that construct tree-decompositions of width at most k, as opposed to recognition algorithms that only decide whether twd (G) ≤ k, say, by checking the absence of finitely many minors (Corollary 2.60) or by other means like performing sequences of reductions as in [ArnCPS].

Bodlaender has given in [START_REF] Bodlaender | A linear-time algorithm for finding treedecompositions of small treewidth[END_REF] a decomposition algorithm that takes time 2 32k 3 • n. It is actually not implementable but it entails Theorems 1.25(2) and 6.4 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. Efficient linear algorithms exist for k ≤ 3. The article [BodFKKT] contains two decomposition algorithms that are more likely to be usable, even if they are not linear. The first one takes time f (n, k) • 2 n and space g(n, k) • 2 n for some polynomials f and g. It has been tested with success for nonrandom graphs with at most 50 vertices and tree-width at most 35 arising from concrete problems. Another algorithm is given that takes time f (n, k) • 3 n and polynomial space for some polynomial f (but no implementation is reported). Yet other algorithms that have been implemented and tested are presented in [START_REF] Bachoore | A branch and bound algorithm for exact, upper, and lower bounds on treewidth[END_REF][START_REF] Bachoore | Weighted treewidth: algorithmic techniques and results[END_REF][START_REF] Van Den Eijkhof | Safe reduction rules for weighted treewidth[END_REF]. A survey can be found in [*Bod06].

Approximation algorithms have also been developed. Flum and Grohe give in [*FluGro] (Proposition 11.14) an algorithm that constructs for every graph G a tree-decomposition of width at most 4

• twd (G) + 1 in time O(3 3•twd(G) • twd (G) • n 2
). This algorithm is based on work by Reed who has given in [Ree] a similar algorithm taking time O(n • log(n)) for producing a tree-decomposition of width at most 3 • twd (G) + 2. Even if the constructed tree-decomposition is not optimal (i.e., has a width that is not minimal), the algorithm is usable for solving the model-checking problem of Theorem 6.4(1) for graphs of treewidth bounded by a fixed value. The article [BouKMT] gives a polynomial-time algorithm that constructs for every graph G a tree-decomposition of width at most twd (G)(560 + 80 • log(twd (G))). However, due to the large constants, this algorithm is not practically usable. Another polynomial-time approximation algorithm that is not usable either, is given in [FeiHL]: it produces a treedecomposition of width O(twd (G) • log(twd (G)) )

For each k, there is an algorithm that decides in time O(n) if a simple graph G with n vertices has path-width at most k, and if this is the case, it outputs a path-decomposition of width at most k. The article [BodKlo] (Theorem 6.1) constructs, for any two integers k and m, an algorithm doing that from a treedecomposition of G of width at most m. Hence, if G only is given, one first computes by using the algorithm of [START_REF] Bodlaender | A linear-time algorithm for finding treedecompositions of small treewidth[END_REF] a tree-decomposition of this graph of width at most k, to which the algorithm of [BodKlo] is applied in order to obtain if possible a path-decomposition of width at most k. If no such decomposition exists, the path-width of G is more than k.

Parsing with respect to HR equation systems

The second method for defining a term in T (F HR ) that evaluates to a given graph G consists in using an HR equation system S that defines a set L to which G belongs. If we know how G is generated by S, that is, if we know a derivation tree of G relative to S, then (cf. Definition 4.4) we can transform this tree in linear time into a term in T (F HR A(S) ) that evaluates to G, where A(S) is a set of source labels that depends only on S (with |A(S)| possibly larger than twd (G) + 1, see Proposition 4.7). Using Theorem 6.3, this gives what we want for model-checking8 . Otherwise, we have to rest on a parsing algorithm for the system S. The situation is here not very encouraging. First, by the NP-completeness result of [ArnCP], we know that there is no general parsing algorithm running in time f (S) • n c for fixed c (unless P = NP). But even worse, certain HR-equational sets of graphs have an NP-complete membership problem. An example is the set of graphs of cyclic bandwidth at most 2 (by [LeuVW], see Example 4.3(11)). This is also the case of string grammars with disconnection ( [LanWel]), and these grammars can be seen as defining HRequational sets of disconnected graphs of degree at most 2. However, imposing connectedness is not enough to modify the situation ([*DreKH], Theorems 2.7. 1 and 2.7.2). Lautemann has proved in [Lau] (also [*DreKH], Theorem 2.7.7) that an HR-equational9 set of graphs L has a polynomial-time parsing algorithm if it satisfies the following condition:

L is defined by an HR equation system S such that, if k = |A(S)| (hence k is the number of source labels used to write S), then there exists a constant a such that for every G ∈ L: 8) and (the proof of) Corollary 5.71 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF], this result gives a polynomial-time parsing algorithm for connected graphs of tree-width at most k -1 and degree at most d. This algorithm extends to the nonconnected such graphs by Proposition 2.62.

Sep(G, k) ≤ a • log(|V G |) where, for k ∈ N , Sep(G, k) is the maximum number of connected com- ponents of G[V G -X] for any X ⊆ V G such that |X| ≤ k.
Other polynomial-time parsing algorithms for HR grammars are presented in [*DreKH].

Graphs of bounded clique-width

The parsing problem relative to the signature F VR is even more difficult than that relative to the signature F HR . First, the problem of deciding whether cwd (G) ≤ k for given (G, k) (with G simple and undirected) is NP-complete ( [FelRRS]). For k = 2, this verification can be done in time

O(|V G | + |E G |)
because a simple, loop-free undirected graph has clique-width at most 2 if and only if it is a cograph (cf. Proposition 2.106( 2)) so that one can use the algorithm of [CorPS]. It can be done in cubic time for k = 3 ( [CorHLRR]). For other fixed values of k, it is not known if the problem is polynomial or NP-complete. Furthermore, there is presumably no polynomial-time approximation algorithm since the article [FelRRS] establishes the following:

If for some real number ε such that 0 ≤ ε < 1 there exists a polynomialtime algorithm that computes, for every simple undirected graph G of minimum degree 3, an integer

f (G) such that |f (G) -cwd (G)| ≤ |V G | ε , then P = NP.
In order to overcome this difficulty, Oum and Seymour have introduced in [OumSey] the notion of rank-width. Definition 6.6 (Rank-width) A cubic tree is a tree T whose nodes are all of degree 3 or 1. The latter ones are called the leaves; the set of leaves is denoted by Leaves(T ). Let G be a simple loop-free undirected graph, described by a symmetric V G × V G adjacency matrix A G with coefficients in {0, 1} such that A G [v, w] = 1 if and only if v and w are the ends of an edge of G. A layout10 of G is a pair (T, f ) where T is a cubic tree and f is a bijection : V G → Leaves(T ). For each edge e of T , the two connected components of T -e (the forest obtained from T by removing e) induce a bipartition (X e , Y e ) of Leaves(T ), hence a bipartition (X e , Y e ) = (f -1 (X e ), f -1 (Y e )) of V G . We let rk (e, T, f ) be the rank over GF (2) (the field with the two elements 0 and 1) of A G [X e , Y e ], the rectangular X e × Y e submatrix of A G (it describes the edges of G that link the vertices of X e and Y e ). Then we define the rank of (T, f ) as rk (T, f ) := max{rk (e, T, f

) | e ∈ E T } and the rank-width of G as rwd (G) := min{rk (T, f ) | (T, f ) is a layout of G}.
For every simple loop-free undirected graph G, we have, by [OumSey]:

rwd (G) ≤ cwd (G) ≤ 2 rwd(G)+1 -1.
More precisely, this article establishes that from every term t in F VR

[k] defining a graph G, one can construct in linear time a layout (T, f ) of G such that rk (T, f ) ≤ k. One defines T from the syntactic tree of t by contracting some edges so as to make it cubic. Conversely, from every such layout one can construct in quadratic time a term in T (F VR [2 k+1 -1] ) that evaluates to G, together with a corresponding witness. Hence clique-width and rank-width are equivalent complexity measures on simple loop-free undirected graphs: the same sets of such graphs have bounded clique-width and bounded rank-width. The problem of deciding whether rwd (G) ≤ k for given (G, k) is NP-hard, as for clique-width (see the survey [*GotHOS]). However, Hliněný and Oum have constructed in [HliOum] a parsing algorithm11 running in time g 0 (k) • n 3 (for some fixed function g 0 ) that decides if a graph G with n vertices has rank-width at most k. The algorithm produces a layout of rank at most k if there exists one. Hence, one can obtain from it a term in T (F VR [2 k+1 -1] ) that evaluates to G (with a witness); since every layout of G has size O(n), this takes time O(n 2 ). Thus, by the proof of Theorem 1. 25 and using Theorem 6.3(3), this algorithm gives the proof of Theorem 6.4(2) for simple loop-free undirected unlabelled graphs.

We now extend this result to larger classes of graphs. First, we recall that clique-width does not depend on vertex labels and loops: by Proposition 2.100, if one adds or modifies vertex labels, or if one adds or deletes loops in a graph G that is the value of a term t, then one can transform t in linear time into a term t that evaluates to the modified graph G , just by modifying some constant symbols of t. It is important to note that one need not parse G . The situation is different for edge labels and edge directions. Definition 6.7 (Encodings of directed and labelled graphs) We will encode simple directed graphs, and more generally, simple edge-labelled directed and undirected graphs by simple vertex-labelled undirected graphs.

We first consider the case of simple directed graphs. For such a graph G, we define B(G) as the simple vertex-labelled undirected graph12 such that:

V B(G) := V G × [3], E B(G) := {(v, i) -(v, i + 1) | v ∈ V G , i ∈ [2]} ∪ {(v, 3) -(w, 1) | v → w in G}, γ B(G) ((v, i)) := i for every (v, i) ∈ V B(G) .
Here is the decoding transformation. If H is a vertex-labelled undirected graph of the form B(G) for some G, with labelling function γ H : V H → {1, 2, 3}, then G can be recovered from H as follows:

(a) one directs every edge linking a vertex v with label 3 and a vertex w with label 1 from v to w;

(b) one contracts the other edges (they link a vertex with label 2 and one with label 1 or 3). We now generalize this construction into an encoding of simple, directed edge-labelled graphs. We let the set Λ of edge labels be {λ 1 , . . . , λ m } and not contain 1 and 2. We define a mapping B Λ (it is an FO-transduction) that associates with every directed (∅, Λ)-labelled graph G an ([m + 2], ∅)-labelled undirected graph B Λ (G) as follows:

V BΛ(G) := V G × [m + 2], E BΛ(G) := {(v, 1) -(v, 2) | v ∈ V G } ∪ {(v, 2) -(v, i)) | v ∈ V G , i ∈ {3, . . . , m + 2}} ∪ {(v, 2 + i) -(w, 1) | v → w is an edge of G with label λ i }, γ BΛ(G) ((v, i)) := i for every vertex (v, i) of B Λ (G). Figure 6.1 shows a directed (∅, [2])-labelled graph G and its encoding B [2] (G) by a ([4], ∅)-labelled graph. A vertex (v, i) of B [2] (G) is represented by v i .
As in the case of the mapping B (which is B Λ for m = 1), we have:

cwd (B Λ (G)) ≤ p Λ (cwd (G)) and cwd (G) ≤ p Λ (cwd (B Λ (G))),
for some computable functions p Λ and p Λ . Furthermore, focusing on B -1 Λ and the second inequality, it follows from Corollary 7.38(3) that there is an algorithm that transforms a term t in ,Λ] ) that evaluates to G, in time g 1 (k, Λ) • |t| for some computable function g 1 . Thus, the algorithm is fixed-parameter linear with respect to (k, Λ).

T (F VR [k],[[m+2],∅] ) that evaluates to B Λ (G) into one in T (F VR [p Λ (k)],[∅
The following proposition will yield the parsing step of the proof of Theorem 6.4(2). Proposition 6.8 There exists an algorithm that, for every simple (K, Λ)-labelled graph G with n vertices, computes in time at most g(cwd (G), K, Λ) • n 3 a term over F VR [hΛ(G)], [K,Λ] evaluating to G, where g is a computable function and h Λ (G) is a positive integer that can be computed from G.

Proof: We first consider directed unlabelled graphs. Let be given a simple directed graph G with n vertices, and an integer k. We construct the vertexlabelled undirected graph B(G). We run A, the algorithm of [HliOum], on input (B(G), k). It takes time at most g 0 (k) • n 3 . There are two possible outputs:

(i) The answer that rwd (B(G)) > k. (ii) A layout of B(G) of rank at most k. In Case (ii), another algorithm can construct in time O(n 2 ) a term t in T (F VR [2 k+1 -1],[[3],∅]
) that evaluates to B(G), and in time

g 1 (∅, k) • |t| a term in T (F VR [p(2 k+1 -1)]
) that evaluates to G. Altogether this takes time at most g 2 (k)•n 3 for some computable function g

2 . Case (i) cannot occur if p(cwd (G)) ≤ k because rwd (B(G)) ≤ cwd (B(G)) ≤ p(cwd (G)).
Hence, if we run A with input (B(G), k) for k = 1, 2, 3, . . . , we must find a value k for which the output is a layout of B(G) of rank at most k. Let m(G) be the first such k. Then m(G) ≤ p(cwd (G)) by the above observation. Hence, we obtain a term in T (F VR [h(G)] ) that evaluates to G, where h(G) := p(2 m(G)+1 -1). This term is obtained in time at most (

p(cwd(G)) k=1 g 2 (k)) • n 3 . Note that the integer h(G) is bounded by f (cwd (G)) for a computable function f .
For (∅, Λ)-labelled graphs, the proof is the same with the encoding B Λ in place of B. In time bounded by (

pΛ(cwd(G)) k=1 g 2 (Λ, k)) • n 3 , we obtain a term in T (F VR [hΛ(G)],[∅,Λ]
) that evaluates to G, where h Λ (G) := p Λ (2 m(G)+1 -1). Finally this proof extends easily to simple (K, Λ)-labelled graphs because we know that clique-width does not depend on vertex labels, and (by Proposition 2.100), that a term in T (F VR [∅,Λ] ) that defines an edge-labelled directed graph can be easily transformed into one in T (F VR [K,Λ] ) that also specifies the vertex labels. Note that an upper-bound to h Λ (G) can be computed from cwd (G) and Λ.

The reader may ask about the parsing problem for VR equation systems. By Theorem 4.49 establishing that every HR-equational set is VR-equational, all difficulties met with HR equation systems also occur with VR ones. However, polynomial recognition algorithms exist for certain classes of graphs of bounded clique-width defined by forbidden induced subgraphs. All these algorithms construct terms in T (F VR [k] ) for the recognized graphs (see [BraDLM, BraELL, MakRot]) but they only work for undirected graphs without edge labels.

Monadic second-order formulas compiled into finite automata

Theorems 6.3 and 6.4 entail the existence of FPT algorithms for monadic secondorder model-checking problems on terms and on graphs of bounded tree-width or clique-width. They are consequences of the Weak Recognizability Theorem (Corollary 5.69). However, although its proof is effective, the states of the finite automata resulting from it are (or encode) huge sets of formulas. Hence, they do not give tractable implementations. The purpose of this section is to give another translation of monadic secondorder sentences into finite automata that is hopefully usable for not too complex sentences and for "small" bounds on tree-width or clique-width, or for "small" signatures in the case of terms.13 However, the difficulty is unavoidable as soon as one wishes a model-checking algorithm that works for every CMS sentence, as proved by Frick and Grohe in [FriGro04]. They establish the following theorem 14 . Theorem 6.9 If there exist c, d ∈ N such that, for every MS sentence ϕ and every word w ∈ {0, 1} * , one can decide if w |= ϕ in time exp(d, |ϕ|) • |w| c , then P = NP.

We will nevertheless try to get applicable cases of Theorem 6.3. We first review (from Section 3.3) some definitions concerning finite automata and we also present some new constructions.

In this section, we will only consider finite, one-sorted functional signatures and finite, ε-free automata over such signatures. We will call them simply functional signatures and automata.

Automata

We recall (from Section 3.3) that an F -automaton is defined as a four-tuple A = F, Q A , δ A , Acc A (signature, states, transition rules, accepting states). It accepts (or recognizes) the language L(A ) ⊆ T (F ). Without Acc A , we have an F -semi-automaton. The language L(A , q) is the set of terms recognized by A with q as unique accepting state. The number of states of A is denoted by A . A transition rule in δ A is of the form f [q 1 , . . . , q ρ(f ) ] → q with f ∈ F and q, q 1 , . . . , q ρ(f ) ∈ Q A .

We will denote by det(A ) the trim, complete and deterministic automaton constructed from an automaton A (cf. Proposition 3.50). Its set of states is (or is in bijection with) a subset of P(Q A ).

For every complete and deterministic automaton A , the automaton A defined from A by taking Q A -Acc A as set of accepting states recognizes the language T (F ) -L(A ).

Products of automata and Boolean operations

If A and B are two F -semi-automata, their product is the F -semi-automaton

A × B := F, Q A × Q B , δ A ×B where δ A ×B is defined as the set of rules f [(p 1 , q 1 ), . . . , (p k , q k )] → (p, q) with f [p 1 , . . . , p k ] → A p and f [q 1 , . . . , q k ] → B q.
If A and B are automata, then we define the F -automaton A ∩B as A ×B equipped with set of accepting states

Acc A × Acc B . Clearly, L(A ∩ B) = L(A ) ∩ L(B). We define similarly A ∪ B as A × B with set of accepting states (Acc A × Q B ) ∪ (Q A × Acc B ). If A and B are complete, then L(A ∪ B) = L(A ) ∪ L(B).
We now generalize this construction so as to build an automaton that accepts a Boolean combination of the languages accepted by given automata A 1 , . . . , A m .

Let L 1 , . . . , L m ⊆ T (F ) be accepted by complete and deterministic Fautomata, respectively A 1 , . . . , A m . Let L := b(L 1 , . . . , L m ) ⊆ T (F ) be defined from L 1 , . . . , L m by a term b ∈ T ({∩, ∪, }, {x 1 , . . . , x m }) (where M denotes T (F )-M ). We define C as the F -semi-automaton

A 1 ×(• • •×(A m-1 ×A m ) • • • ).
For convenience, we identify its set of states with

Q A1 × • • • × Q Am-1 × Q Am and we denote C by A 1 × • • • × A m-1 × A m . It is complete and deterministic.
(1) If L ⊆ T (H) is recognized by an H-automaton with n states, then h(L) is recognized by an F -automaton with n states.

(2) If K ⊆ T (F ) is recognized by an F -automaton A with n states, then h -1 (K) is recognized by an H-automaton B with n states. If A is complete and deterministic, then so is B.

Counting and optimization based on automata

The following constructions will be used in Section 6.4 for computing monadic second-order counting and optimizing functions (see Definition 6.5).

Let H, F be functional signatures and h : H → F be arity preserving. Let A be a complete and deterministic H-semi-automaton. For t ∈ T (F ) and q ∈ Q A we define: q). If, furthermore, A is an automaton, then, for every t ∈ T (F ), we have:

A ,h -1 (t, q) := |h -1 (t) ∩ L(A , q)| and A ,h -1 (t) as the function λq ∈ Q A • A ,h -1 (t,
|h -1 (t) ∩ L(A )| = q∈Acc A A ,h -1 (t, q).
For J ⊆ H and s ∈ T (H), we denote by |s| J the number of occurrences in s of symbols belonging to J. For t ∈ T (F ) and q ∈ Q A , we define:

Max A ,h -1 ,J (t, q) := max{|s| J | s ∈ h -1 (t) ∩ L(A , q)}
and Max A ,h -1 ,J (t) as the function λq ∈ Q A • Max A ,h -1 ,J (t, q). (The maximum of an empty set of integers is -∞.) It follows that for every t, we have:

max{|s| J | s ∈ h -1 (t) ∩ L(A )} = max{Max A ,h -1 ,J (t, q) | q ∈ Acc A }.
With these hypotheses and notations, we have the following result. Proposition 6.12 Let h : H → F be an arity preserving mapping between functional signatures, let J ⊆ H and A be a complete and deterministic Hautomaton. The functions A ,h -1 and Max A ,h -1 ,J are computable in linear time by an induction on the structure of the input term.

Proof: We describe the inductive computation, assuming that all function symbols f have arity 0 or 2. The extension to other arities is straightforward. We fix h and A , and we replace A ,h -1 (t, q) by (t, q) to simplify the notation.

For f ∈ F 0 , (f, q) is the number of symbols f in h -1 (f ) such that f → A q. We can rewrite this into:

(f ) = D f
where D f is a function (with finite domain Q A ) that can be determined from h and A in time O( A ), hence in time that does not depend on the input term.

For f ∈ F 2 and t 1 , t 2 ∈ T (F ) we have:

(f (t 1 , t 2 ), q) = (q1,q2,f )∈R (t 1 , q 1 ) • (t 2 , q 2 )
where R is the set of triples (q 1 , q 2 , f ) in

Q A ×Q A ×H 2 such that f [q 1 , q 2 ] → A q and f ∈ h -1 (f ).
This equality is true because:

h -1 (f (t 1 , t 2 ))∩L(A , q) = (q1,q2,f )∈R f h -1 (t 1 )∩L(A , q 1 ), h -1 (t 2 )∩L(A , q 2 ) ,
and the union is disjoint because A is deterministic15 . Hence we have

(f (t 1 , t 2 )) = D f ( (t 1 ), (t 2 ))
for all f ∈ F 2 and t 1 , t 2 ∈ T (F ), where D f is a fixed function :

[Q A → N ] × [Q A → N ] → [Q A → N ].
This function can be computed from h and A in time O(( A ) 2 ) if each arithmetic operation is considered as evaluable in constant time. This gives the computation time O(|t|) for fixed automaton A and fixed h : H → F . A similar construction can be done for computing Max A ,h -1 ,J . We fix A , h and J, and we write Max (t, q) instead of Max A ,h -1 ,J (t, q).

If f ∈ F 0 , and H 0 (f, q) is the set of symbols f in h -1 (f ) such that f → A q, then:

Max (f, q) =      1 if H 0 (f, q) ∩ J = ∅ 0 if H 0 (f, q) ∩ J = ∅ and H 0 (f, q) = ∅ -∞ if H 0 (f, q) = ∅. If f ∈ F 2 and t 1 , t 2 ∈ T (F ), then: Max (f (t 1 , t 2 ), q) = max{ε J,f + Max (t 1 , q 1 ) + Max (t 2 , q 2 ) | (q 1 , q 2 , f ) ∈ R}
where ε J,f := if f ∈ J then 1 else 0, and R is as above for the computation of (t, q). The union need not be disjoint here because we take a maximum and not a sum, hence the definition is the same if A is not deterministic. Remarks 6.13

(1) In the previous proposition, we have assumed that the arithmetic operations are done in constant time. For handling large integers, it is more accurate to assume that they take time proportional to the logarithms of their arguments. In the computation of A ,h -1 (t), we have A ,h -1 (s, q) ≤ d n if s is any subterm of t, n is the size of t and d is the maximal cardinality of h -1 (f ) for f ∈ F . Hence, the computation time is multiplied by n • log(d) and becomes quadratic instead of linear, if the logarithmic cost of arithmetical operations is used. For optimizing functions, the results and the intermediate values are bounded by n. Hence, the computation time is multiplied by log(n).

(2) The proof of Proposition 6.12 can be seen as a construction of complete and deterministic automata with infinite sets of states (the sets of functions from Q A to N or to N ∪ {-∞}). Each state is a function having a finite domain, hence is a finitely encodable object. This automaton is thus effectively given, i.e., all its components are effectively given. The transition functions are computable in constant time if arithmetic operations have unit cost. They are computable in linear time (for A ,h -1 ) or in logarithmic time (for Max A ,h -1 ,J ) if arithmetic operations have logarithmic cost.

Runs of nondeterministic automata

Let A be an F -semi-automaton. For t ∈ T (F ), we denote by run * A (t) the set of states of the form r(root t ) for some run r of A on t. This set is nonempty if A is complete and it has a single element if A is complete and deterministic (cf. Definition 3.49). If d is a positive integer we say that A is d-nondeterministic if, for all f ∈ F and q 1 , . . . , q ρ(f ) ∈ Q A , there are at most d states q such that f [q 1 , . . . , q ρ(f ) ] → A q. The integer d measures the degree of nondeterminism of A . A 1-nondeterministic semi-automaton is deterministic.

In the next proposition, A is d-nondeterministic and a is an upper-bound to the time necessary to determine the i-th state q such that f [q 1 , . . . , q ρ(f ) ] → A q for i ∈ [d] or to find that the number of such states q is less than i, so that there is no i-th state (we can assume that Q A is linearly ordered). We will say that A has transition time bounded by a. Proposition 6.14 Let A be a d-nondeterministic F -semi-automaton and let a bound its transition time. For every term t ∈ T (F ), one can determine the set run * A (t) in time bounded by a

• d • ( A ) ρ(F ) • |t|.
Proof: We use a bottom-up computation to compute the set run * A (t/u) (of cardinality at most A ) for each node u of the syntactic tree of t. At a node u that is an occurrence of a symbol of arity k ≥ 0, there are at most d • ( A ) k transitions, and for each of them, it takes time a to find the resulting state q. This gives the result. Remark 6.15 In the particular case where ρ(F ) = 2 and the nondeterminism of transitions is limited to constant symbols, we get in the previous proposition the better bound a • (d + ( A ) 2 ) • |t| on the computation time.

Normalizing monadic second-order formulas

We will need some normalization lemmas for monadic second-order formulas. As in Section 5.3 the formal constructions will use formulas without universal quantifications. The expression ∀X. ϕ will be used as a shorthand for ¬∃ X. ¬ϕ.

(2) Conversely, every formula ψ in C r MS (R, X n ) is equivalent to a formula in C r MS(R, X n ) of quantifier-height at most qh(ψ) + max{2, ρ(R)}.

Proof: (1) Without loss of generality, we can assume that there is no index i > 1 such that the variables X i and x i both occur in ϕ. (Otherwise, we rename some bound variables to ensure this condition.) Then we take ψ equal to

Sgl (X p+1 ) ∧ • • • ∧ Sgl (X n ) ∧ ϕ
where ϕ is obtained as follows from ϕ by induction on its structure:

(i) we replace the atomic formulas x i ∈ X j and x i = x j by X i ⊆ X j , and those of the form R(x i1 , . . . , x i k ) by R(X i1 , . . . , X i k );

(ii) we replace

∃ x i . θ by ∃ X i (Sgl (X i ) ∧ θ).
The quantifier-height of ψ is that of ϕ. We have |ψ| ≤ 3 • |ϕ| + 2(n -p). The correctness of the construction is clear. By the initial condition, no conflict of variable can occur from the replacement of x i by X i .

(2) The converse construction is straightforward. The quantifier-height may increase because the atomic formula

X i ⊆ X j is replaced by ¬∃ x(x ∈ X i ∧ x / ∈ X j ), the atomic formula Sgl (X i ) is replaced by σ(X i ) defined as ∃ x(x ∈ X i ∧ ∀y(y ∈ X i ⇒ x = y)), and R(X i1 , . . . , X i k ) is replaced by σ(X i1 )∧• • •∧σ(X i k )∧ ∃ x 1 , . . . , x k (x 1 ∈ X i1 ∧ • • • ∧ x k ∈ X i k ∧ R(x 1 , . . . , x k )).
An example will be given below (Example 6.23).

Remark 6.18 In the last clause of Definition 6.16, we can extend relations to have sets as arguments in other ways. Instead of R(X i1 , . . . , X i k ), we can use: R ∀ (X i1 , . . . , X i k ) to mean:

(d 1 , . . . , d k ) ∈ R S for every d 1 ∈ X i1 , . . . , d k ∈ X i k , and R ∃ (X i1 , . . . , X i k ) to mean: (d 1 , . . . , d k ) ∈ R S for some d 1 ∈ X i1 , . . . , d k ∈ X i k .
We can also combine both types of extensions and, for R binary, define R ∀∃ (X, Y ) to mean: for every d in X there exists d in Y such that (d, d ) ∈ R S . Lemma 6.17 remains valid with these variants. For example, the formula R ∀ (X i ) is replaced by ¬∃ x(x ∈ X i ∧ ¬R(x)). These variants may simplify the constructions of automata to be developed below.

The following notions will help to bound the sizes of automata constructed from formulas. Let R be fixed (it will not appear in the notation). We let L denote the set of all CMS (or CMS) formulas over R, and we define subsets of L as follows:

A is the set of atomic formulas; B 0 is the set of formulas b(α 1 , . . . , α m ) such that m ∈ N + , b ∈ Bool m and α 1 , . . . , α m are formulas in A;

B i , for i ≥ 1, is the set of formulas b(ϕ 1 , . . . , ϕ m ) such that m ∈ N + , b ∈ Bool m and ϕ 1 , . . . , ϕ m are formulas in E i ∪ • • • ∪ E 1 ∪ A such that at least one of them is in E i ; E i , for i ≥ 1
, is the set of formulas ∃X. ϕ where X is a nonempty sequence of set variables, ϕ belongs to B i-1 and ϕ does not begin with a quantification. 16It is clear that each formula of L belongs to one and only one of the sets B i . Since the term p 1 is in Bool 1 , we have A ⊆ B 0 and

E i ⊆ B i for i ≥ 1.
The block quantifier-height of a formula ϕ is the integer i such that ϕ ∈ B i . We denote it by bqh(ϕ). Its Boolean arity is the maximal arity m of a Boolean term b such that b(ϕ 1 , . . . , ϕ m ) is a subformula of ϕ for some pairwise distinct formulas ϕ 1 , . . . , ϕ m . We denote it by ba(ϕ). For example, bqh(ϕ) = 3 and ba(ϕ) = 2 for ϕ defined as:

∀X 1 ∃X 3 , X 4 (edg(X 1 , X 2 ) ∧ ∃X 5 (edg(X 3 , X 5 ) ∧ ¬edg(X 4 , X 1 ))).
We will need another normalization lemma. It is a simple variant of the normalization in Proposition 5.93 (Section 5.6), involving renaming of bound variables only.

Definition 6.20 (n-normal formulas)

For each n ∈ N , we define certain formulas of CMS (R, X ω ) as n-normal by structural induction:

(1) an atomic formula ϕ is n-normal if its variables are all in X n ;

(2) a Boolean combination of formulas θ 1 , . . . , θ k is n-normal if each formula θ i is n-normal;

(3) a formula of the form ∃X i . θ is n-normal if i = n + 1 and θ is (n + 1)normal.

If a formula has at least one quantifier, it is n-normal for at most one integer n determined by the leftmost quantified variable that must be X n+1 . Lemma 6.21 If a formula ϕ is n-normal, then its set of quantified variables is {X n+1 , . . . , X n+qh(ϕ) } and its free variables are all in X n .

Proof: Straightforward by induction on the structure of ϕ. Lemma 6.22 Every formula ϕ in C r MS (R, X n ) can be transformed into an equivalent n-normal formula ϕ in C r MS (R, X n ) by a renaming of bound variables.

Proof: It is clear that ϕ can be obtained from ϕ by an appropriate renaming of its bound variables into the variables X n+1 , . . . , X n+qh(ϕ) . Formally, the construction of ϕ is by induction on the size of ϕ.

(1) If ϕ is atomic, we let ϕ be ϕ.

(

) If ϕ is ¬ϕ 1 or ϕ 1 ∨ ϕ 2 or ϕ 1 ∧ ϕ 2 , then we let ϕ be respectively ¬ ϕ 1 or ϕ 1 ∨ ϕ 2 or ϕ 1 ∧ ϕ 2 . 2
(3) If ϕ is ∃X n+1 . θ, then we let ϕ be ∃X n+1 . θ, where θ is the (n + 1)-normal formula obtained from θ by the induction hypothesis.

(

) If ϕ is ∃X k . θ with k = n + 1, then we let θ be θ[X n+1 /X k ]. 4
Note that X n+1 is not free in θ. The substitution of X n+1 to X k may necessitate some renaming of bound variables in θ, but θ has the same size as θ and its free variables are in X n+1 . We let then ϕ be ∃X n+1 . θ where θ is (n + 1)-normal and obtained by the induction hypothesis.

Hence, ϕ has the same quantifier-height, block quantifier-height and Boolean arity as ϕ, and the same free variables.

Example 6.23 For expressing that X is the vertex set of a connected component of an undirected graph, we let ϕ(X) be the following CMS formula written with first-order variables, universal quantifications and implications (and with some atomic CMS formulas):

X = ∅ ∧ ∀u, v(edg(u, v) ∧ u ∈ X ⇒ v ∈ X) ∧ ¬∃Y [Y ⊆ X ∧ ¬(X ⊆ Y ) ∧ Y = ∅ ∧ ∀u, v(edg(u, v) ∧ u ∈ Y ⇒ v ∈ Y )].
Here is an equivalent formula θ in CMS (R s , {X}):

X = ∅ ∧ ¬∃U, V (Sgl (U ) ∧ Sgl (V ) ∧ edg(U, V ) ∧ U ⊆ X ∧ ¬(V ⊆ X)) ∧ ¬∃Y [Y ⊆ X ∧ ¬(X ⊆ Y ) ∧ Y = ∅ ∧ ¬∃U, V (Sgl (U ) ∧ Sgl (V ) ∧ edg(U, V ) ∧ U ⊆ Y ∧ ¬(V ⊆ Y ))].
By replacing X by X 1 and by renaming the bound variables, we obtain the following 1-normal formula θ:

X 1 = ∅ ∧ ¬∃X 2 , X 3 (Sgl (X 2 ) ∧ Sgl (X 3 ) ∧ edg(X 2 , X 3 ) ∧ X 2 ⊆ X 1 ∧ ¬(X 3 ⊆ X 1 )) ∧ ¬∃X 2 [X 2 ⊆ X 1 ∧ ¬(X 1 ⊆ X 2 ) ∧ X 2 = ∅ ∧ ¬∃X 3 , X 4 (Sgl (X 3 ) ∧ Sgl (X 4 ) ∧ edg(X 3 , X 4 ) ∧ X 3 ⊆ X 1 ∧ ¬(X 4 ⊆ X 1 ))].
These formulas have quantifier-height 3 and block quantifier-height 2 (they belong to B 2 ). The first one has Boolean arity 4 and the last two have Boolean arity 5. The last one can be simplified by deleting Sgl (X 2 )∧Sgl (X 3 ) and Sgl (X 3 )∧ Sgl (X 4 ) which are implied respectively by edg(X 2 , X 3 ) and edg(X 3 , X 4 ). The resulting formula has Boolean arity only 4.

Monadic second-order formulas on terms

For every (finite) functional signature F , we will use the relational signature

R F := {son i | 1 ≤ i ≤ k} ∪ {lab f | f ∈ F } where k is ρ(F ), defined as max{ρ(f ) | f ∈ F }. A term t in T (F )
L ϕ := {t ∈ T (F ) | t |= ϕ}.
We will prove that L ϕ is regular (this is one implication of Theorem 1.16 also proved in Corollary 5.67, Section 5.3) by constructing an F -automaton A ϕ that recognizes L ϕ . This construction will use an induction on the structure of ϕ, and thus, we will need to define sets L ϕ associated with formulas ϕ and not only with sentences. We recall from Definition 6.16 that X n denotes {X 1 , . . . , X n } and that X ω denotes the union of the sets X n . Definition 6.24 (a) Let D be a set and γ be a mapping : X n → P(D). The characteristic vector relative to γ of an element u of D is the n-tuple w γ (u) = (w 1 , . . . , w n ) ∈ {0, 1} n such that, for each i, we have w i = 1 if and only if u ∈ γ(X i ).

(b) If σ is a mapping X n → X m , called a substitution, and γ is an assignment : X m → P(D), then w γ•σ (u) = h σ (w γ (u)) where h σ is the mapping : {0, 1} m → {0, 1} n such that h σ (w 1 , . . . , w m ) = (w σ (1) , . . . , w σ (n) ) and σ(X i ) = X σ (i) for each i = 1, . . . , n. The verification is straightforward from the definitions. For example, if n = 4, m = 6 and σ maps X 1 to X 2 , X 2 to X 6 and, finally, X 3 and X 4 to X 3 , then h σ (w 1 , . . . , w 6 ) = (w 2 , w 6 , w 3 , w 3 ). Hence, if γ is an assignment :

X 6 → P(D), if U i = γ(X i ) for i = 1, . . . , 6 and W i = γ(σ(X i )) for i = 1, . . . , 4, then we have u ∈ W 1 ∩ W 2 ∩ W 3 ∩ W 4 if and only if w γ•σ (u) = (1, 0, 1, 1) if and only if w γ (u) = ( * , 1, 1, * , * , 0) where * means 0 or 1, if and only if u ∈ U 2 ∩ U 3 ∩ U 6 .
(c) For every n ∈ N , we let F (n) be the signature F × {0, 1} n where, for every w ∈ {0, 1} n , the symbol (f, w) has arity ρ(f ). Let t ∈ T (F ). For every assignment γ : X n → P(N t ), we let t * γ be the term in T (F (n) ) such that N t * γ = N t , its relations son i for i = 1, . . . , ρ(F ) are the same as those of t, and u ∈ Occ(t * γ, (f, w)) if and only if u ∈ Occ(t, f ) and w = w γ (u). The function symbol that occurs at an occurrence u of a symbol f in t is thus (f, w γ (u)) in t * γ. Obviously, every term in T (F (n) ) is of the form t * γ for some t and γ.

(d) If P (X 1 , . . . , X n ) is a property of sets of positions of terms in T (F ), we define L P (X1,...,Xn) as the language: {t * γ | t ∈ T (F ), γ : X n → P(N t ) and P (γ(X 1 ), . . . , γ(X n )) is true for t}.

(e) If ϕ ∈ CMS (R F , X n ), we define L ϕ,n := {t * γ | t ∈ T (F ), γ : X n → P(N t ) and ( t , γ) |= ϕ}.
Hence, L ϕ,n is defined if and only if n ≥ mfv (ϕ), where mfv (ϕ) denotes the maximal index of a free variable in ϕ. We let L ϕ denote L ϕ,mfv (ϕ) . If ϕ and ϕ are formulas with free variables in X n , then they are equivalent with respect to T (F ) if and only if L ϕ,n = L ϕ ,n .

We will prove that the language L P (X1,...,Xn) is regular if and only if P is monadic second-order expressible. The only-if direction follows from Theorem 5.15. 18 In the other direction, we will construct for every formula ϕ in CMS (R F , X ω ) an automaton A ϕ that recognizes the language L ϕ . We will use an induction on the structure of ϕ, and for some subformulas ψ of ϕ we will have to construct automata A ψ,m that recognize L ψ,m for m > mfv (ψ): consider for example ϕ = ψ ∧ θ with ψ and θ such that mfv (ψ) = 3 and mfv (θ) = 5. Then L ψ ∩ L θ is always empty because F (3) ∩ F (5) = ∅, hence it is not equal to L ϕ in general. Clearly, L ϕ = L ψ,5 ∩ L θ . The same happens when ϕ expresses P and mfv (ϕ) < n (which means that P does not depend on X mfv (ϕ)+1 , . . . , X n ): then an automaton A ϕ,n must be constructed that recognizes L ϕ,n .

This fact motivates the next lemma for which we define some notation. For every substitution σ : X n → X m and every formula ϕ in CMS (R F , X n ), we let ϕ σ be the formula ϕ[σ(X 1 )/X 1 , . . . , σ(X n )/X n ] in CMS (R F , X m ). We extend h σ into an arity preserving mapping :

F (m) → F (n) by letting h σ (f, w) = (f, h σ (w)).
Lemma 6.25 For every formula ϕ in CMS (R F , X n ) and every substitution σ :

X n → X m , we have L ϕ σ ,m = h -1 σ (L ϕ,n ).
Proof: Let t be a term in T (F ) and γ be an assignment :

X m → P(N t ). Since ϕ σ is ϕ[σ(X 1 )/X 1 , . . . , σ(X n )/X n ], we obtain from Lemma 5.9 that ( t , γ) |= ϕ σ if and only if ( t , γ • σ) |= ϕ. Thus, t * γ ∈ L ϕ σ ,m if and only if t * (γ • σ) ∈ L ϕ,n .
From the observation made in Definition 6.24(b) that h σ (w γ (u)) = w γ•σ (u) for every u in the relevant set, here N t , we get that

h σ (t * γ) = t * (γ • σ). Hence, t * γ ∈ L ϕ σ ,m if and only if t * γ ∈ h -1 σ (L ϕ,n ). Since every term in T (F (m) ) is of the form t * γ, this shows that L ϕ σ ,m = h -1 σ (L ϕ,n ).
We continue with the example in Definition 6.24(b) of the substitution σ such that h σ (w 1 , . . . , w 6 ) = (w 2 , w 6 , w 3 , w 3 ): from the language L ϕ where ϕ is

X 1 ⊆ X 2 ∧edg(X 3 , X 4 ), we get L ψ = h -1 σ (L ϕ ) where ψ is X 2 ⊆ X 6 ∧edg(X 3 , X 3 ). As another example, if ϕ ∈ CMS (R F , X n ) and m > n, then L ϕ,m = h -1 σ (L ϕ,n
) where h σ is the mapping that removes the last m -n Booleans of each symbol of F (m) (i.e., σ(X i ) = X i for i = 1, . . . , n and h σ (w 1 , . . . , w m ) = (w 1 , . . . , w n )). Hence, from an automaton recognizing L ϕ,n one can construct an automaton recognizing L ϕ,m by the inverse image construction (Proposition 6.11( 2)).

The inductive construction of automata Theorem 6.26 For every functional signature F and every formula ϕ in the set CMS (R F , X ω ), one can construct a complete and deterministic automaton A ϕ that recognizes the language L ϕ ⊆ T (F (mfv (ϕ)) ).

We will later bound the size of A ϕ in terms of ϕ and F . We now give the proof of the theorem.

Let ϕ be as in the statement of the theorem. We have L ϕ = L ϕ,mfv (ϕ) where ϕ is the mfv (ϕ)-normal formula constructed from ϕ by Lemma 6.22. Hence, it suffices to restrict attention to normal formulas and to construct, for every n ∈ N and every n-normal formula ψ in CMS (R F , X n ), an automaton A ψ,n that recognizes the language L ψ,n . Then A ϕ is the automaton det(A ϕ,mfv (ϕ) ). To construct A ψ,n we will use an induction on the structure of ψ.

Construction 6.27 (Automata for atomic formulas)

The atomic formulas are of the following forms:

(0) True, (1) Card p,q (X i ), X i = ∅, Sgl (X i ), lab f (X i ), (2) X i ⊆ X j , son s (X i , X j ), with f ∈ F and 1 ≤ s ≤ ρ(F ).
For the constant True of type (0) (without free variables), we have L True,n = T (F (n) ), hence the automaton is trivial to build (and actually not needed because True can easily be eliminated from formulas).

We need only construct automata recognizing the sets L ψ,1 where ψ is of type ( 1) with i = 1, and the sets L ψ,2 where ψ is of type (2) with i = 1, j = 2. For the other cases, we can use an appropriate substitution σ by Lemma 6.25 and the inverse image construction for automata (Proposition 6.11(2)).

All automata will be complete and deterministic. We will only detail two cases, the other ones being very similar.

Case 1:

The automaton A Sgl(X1) .

We let Q := {0, 1, Error } be the set of states. The automaton must check, for every term over F (1) , that one and only one occurrence of a symbol in that term belongs to F × {1}. This is of course straightforward, but we take advantage of this very simple case to explain how we will specify automata. The transition rules are in Table 6.1. The automaton is complete and deterministic,

Transition rules

Conditions

(c, 0) → 0 ρ(c) = 0 (c, 1) → 1 ρ(c) = 0 (f, α)[q 1 , . . . , q ρ(f ) ] → 0 α = q 1 = • • • = q ρ(f ) = 0 (f, α)[q 1 , . . . , q ρ(f ) ] → 1 exactly one of α, q 1 , . . . , q ρ(f ) is 1,
the others being 0 (f, α)[q 1 , . . . , q ρ(f ) ] → Error all other cases Table 6.1: Transition rules of A Sgl(X1) .

and 1 is its unique accepting state. By the last line of Table 6.1, we have (f, α)[. . . , Error , . . . ] → Error .

Convention: A state named Error is never accepting (but some other states may not be accepting). For every transition (f, α)[. . . , Error , . . . ] → q we have q = Error , hence, a recognized "error" propagates bottom-up. All transitions not listed yield Error . By using such states, we can make automata complete.

Reducing them would eliminate the states Error and make them incomplete, but we have seen in Proposition 6.10 that complete automata are necessary for defining Boolean combinations of languages. Of course, when we apply the complementation operation to a complete deterministic automaton having a state Error , since this state becomes accepting in the new automaton, we rename it in order to satisfy this convention.

In order to make the construction of A Sgl(X1) clear and its correctness proof easy (but we will not do that proof), we specify in Table 6.2 the meanings of the different states of the constructed automaton A := A Sgl(X1) . That is, for every term t * γ ∈ T (F (1) ):

t * γ ∈ L(A , q) if and only if ( t , γ(X 1 )) satisfies P q .

(6.1)

In Table 6.2, we write X 1 instead of γ(X 1 ) for the purpose of clarity. We will do the same below in all similar tables. Here is an equivalent formulation of Equivalence (6.1). If r is the unique run of A on a term t * γ and u ∈ N t , then r(u) = q if and only if ( t /u, γ(X 1 ) ∩ (N t /u)) satisfies P q . (We recall from Example 5.2(3) that t /u is the R F -structure Syn(t)/u , with domain N t /u: the set of descendants of u in t, including u.) Property P q is thus the meaning of the state q. It describes its role with respect to the property of t to be checked. The three properties listed in this table are mutually exclusive and cover all cases: this means that they specify the behaviour of a complete and deterministic automaton. All tables shown below (Tables 6.3,6.5,6.8 etc.) will also specify complete and deterministic automata.

State q

Property P q 0 X 1 = ∅ 1 Sgl (X 1 )
Error Card (X 1 ) ≥ 2 Table 6.2: Meanings of the states of A Sgl(X1) .

It is now quite easy, by using an induction on the structure of t, to prove Equivalence (6.1). In fact, technically it is more convenient to prove the equivalent formulation of Equivalence (6.1), by bottom-up induction on the node u.

Case 2: The automaton A son2(X1,X2) .

It has four states: 0, 2, Ok , Error , whose meanings are shown in Table 6.3. In this table, r denotes the root of the syntactic tree of the considered term t (or of Syn(t)/u in the equivalent formulation of Equivalence (6.1)). The accepting state is Ok . The transition rules are shown in Table 6.4. In this table (and in the similar ones below), we shorten (0,0) into 00, (0,1) into 01, etc. The automaton is complete and deterministic.

State q

Property P q

0 X 1 = X 2 = ∅ 2 X 1 = ∅, X 2 = {r} Ok son 2 (X 1 , X 2 )
Error all other cases Table 6.3: Meanings of the states of A son2(X1,X2) .

Construction 6.28 (Automata for Boolean compositions)

We will consider formulas in the sets B i . Recall that we restrict attention to normal formulas. We let ψ be an n-normal formula of the form b(θ 1 , . . . , θ m ) for some Boolean term b. The formulas θ i are thus also n-normal. We assume that, for each i, we have constructed the automaton A θi,n recognizing L θi,n . We have L ψ,n = b(L θ1,n , . . . , L θm,n ) where the Boolean operations ∨, ∧ and ¬ are interpreted as union, intersection and complementation with respect to T (F (n) ).

The language L ψ,n is thus recognized by an automaton A ψ,n obtained from Rules Conditions (f, 00)[q 1 , . . . , q ρ(f

) ] → 0 ρ(f ) ≥ 0, q 1 = q 2 = • • • = q ρ(f ) = 0 (f, 01)[q 1 , . . . , q ρ(f ) ] → 2 (f, 10)[q 1 , . . . , q ρ(f ) ] → Ok ρ(f ) ≥ 2, q 2 = 2, q 1 = q 3 = • • • = q ρ(f ) = 0 (f, 00)[q 1 , . . . , q ρ(f ) ] → Ok ρ(f ) ≥ 1
and for some i, q i = Ok and q j = 0 for all j = i Table 6.4: Transition rules of A son2(X1,X2) .

det(A θ1,n ), . . . , det(A θm,n ) by Proposition 6.10. If b is positive, i.e., without negation, we need not determinize the automata A θ1,n , . . . , A θm,n . We need only assume they are complete.

Construction 6.29 (Automata for quantified formulas)

We now consider formulas in the sets E i . We let ψ be n-normal and of the form ∃ X n+1 , X n+2 , . . . , X m . θ where θ is m-normal and does not begin with a quantification. (Hence, θ is atomic or is a Boolean combination of formulas). We assume that an automaton A θ,m has already been constructed. We let h : F (m) → F (n) be the arity preserving mapping that associates (f, (w 1 , . . . , w n )) in F (n) with (f, (w 1 , . . . , w m )) in F (m) by erasing the last m-n Booleans. It is clear from the definitions that L ψ,n = h(L θ,m ). Hence, L ψ,n = L(h(A θ,m )) by the direct image construction for automata (Proposition 6.11(1)). We can take A ψ,n equal to h(A θ,m ) or to det(h(A θ,m )) in order to have a complete and deterministic automaton.

Proof of Theorem 6.26: The theorem follows immediately from Constructions 6.27 to 6.29.

Bounding the sizes of the constructed automata

Our aim is to derive from these constructions an upper-bound to A ϕ , the number of states of the complete and deterministic automaton A ϕ . This will give a bound on its size A ϕ (cf. Definition 3.46 in Section 3.3) since it is at most 2

mfv (ϕ) • |F | • (ρ(F ) + 1) • ( A ϕ ) ρ(F )+1
where ρ(F ) is the maximal arity of F (and of F (mfv (ϕ)) ).

In the following evaluation, we will assume that complete and deterministic automata are constructed at each step. Minimizing them reduces their sets of states, but we cannot evaluate how much. Constructions 6.27 to 6.29 distinguish three types of formulas: the atomic formulas in A, those in the sets B i and those in the sets E i . We will bound A ϕ in terms of (i) the maximum of A ψ for the atomic subformulas ψ of ϕ, (ii) the Boolean arity of ϕ and (iii) its block quantifier-height, by considering in turn each of these constructions.

Atomic formulas, cf. Construction 6.27 : By Lemma 6.25 and Proposition 6.11(2) (about substitutions and the inverse image construction), we need only construct complete and deterministic automata for atomic formulas with variables either X 1 or X 1 and X 2 , because by these results we can transform these automata into complete and deterministic ones with the same sets of states, over the larger signatures F (n) . The automata for True have one state, those for X i = ∅ and X i ⊆ X j have 2 states, those for Sgl (X i ) and lab f (X i ) (for f ∈ F ) have 3 states, those for son s (X i , X j ) (for 1 ≤ s ≤ ρ(F )) have 4 states, and finally, the automata A Cardp,q(X1) have q states. Thus, for a formula ϕ in C r MS (R F , X ω ), we have A ψ ≤ max{r, 4} for every atomic subformula ψ of ϕ.

Boolean combinations, cf. Construction 6.28 : We use the product of complete and deterministic automata A θ1,n , . . . , A θm,n for constructing an automaton A ψ,n for ψ of the form b(θ 1 , . . . , θ m ). Since we may assume that θ 1 , . . . , θ m are pairwise distinct, we obtain by Proposition 6.10 a complete and deterministic automaton such that

A ψ,n ≤ A θ1,n × • • • × A θm,n ≤ N ba(ψ) if A θi,n ≤ N for each i.
Existential quantifications, cf. Construction 6.29 : If ϕ is ∃X. θ, then A ψ,n is obtained from A θ,m by the direct image construction (with m := n + |X|). By Proposition 6.11 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF], this construction produces a nondeterministic automaton with the same number of states. It has degree of nondeterminism 2 m-n (cf. Section 6.3.1). Since we determinize automata at each step, we get

A ψ,n ≤ 2 A θ,m .
Corollary 6.30 Let ϕ be a formula of block quantifier-height h and Boolean arity m. Let a be the maximal number of states of a complete and deterministic automaton constructed for an atomic subformula of ϕ. The number of states of the automaton A ϕ , and of the automata constructed during the construction of A ϕ , is bounded by exp(h, m(a m + h)).

Proof: By Lemma 6.22 and the proof of Theorem 6.26, it suffices to prove this for every n-normal formula ψ and the automaton A ψ,n .

We let E : N ×N + ×N + → N + be the total function such that E(0, x, m) = x and E(h ,x,m) for all h ∈ N and x, m ∈ N + . It is easy to see that E is monotonic in each of its arguments. By elementary calculations 19 , we can see that E(h, x, m) ≤ exp(h, m(x + h)) for all h, x, m. Hence it suffices to prove the following claim. Claim 6.30.1 If ψ belongs to B h , if m = ba(ψ) and a is as in the statement of the corollary (for ψ), then we have

+ 1, x, m) = 2 m•E(h
A ψ,n ≤ E(h, a m , m). Proof: If h = 0, then ψ ∈ B 0 and A ψ,n ≤ a m = E(0, a m , m). If ψ belongs to E h+1 and is ∃X. θ with θ ∈ B h , then A ψ,n ≤ 2 E(h,a m ,m) , since A θ,n+|X| ≤ E(h, a m , m). If ψ ∈ B h+1 , then ψ = b(θ 1 , . . . , θ m ), m ≤ m, with θ 1 , . . . , θ m ∈ E h+1 ∪ • • • ∪ E 1 ∪ A, hence: A ψ,n ≤ (max{ A θ1,n , . . . , A θ m ,n }) m ≤ (2 E(h,a m ,m) ) m = E(h + 1, a m , m). We have A θi,n ≤ 2 E(h,a m ,m) because E is monotonic in each of its arguments.
This completes the proof of the claim and thus, of the corollary.

Remarks 6.31

(1) The bound exp(h, m(a m + h)) is also an upper-bound to the number of states of the minimal automaton of the language L ϕ , hence of its recognizability index (cf. Proposition 3.73( 2)). This upper-bound is better than the one obtained from Theorem 5.96 in Section 5.6 (for sentences ϕ), because it has less levels of exponentiation. However, the implementation of the algorithm of Theorem 6.26 remains problematic due to the lack of memory that occurs during the computation.

(2) For n ≥ mfv (ϕ), the language L ϕ,n is equal to L P (X1,...,Xn) where P (X 1 , . . . , X n ) is the property expressed by ϕ (cf. Definition 6.24). By Proposition 3.73 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF], minimization of the automaton A ϕ,n leads to the (unique) minimal automaton M (P ) := M (L P (X1,...,Xn) ) that recognizes the language L P (X1,...,Xn) . However, A ϕ,n may be of much larger size than M (P ). Hence, even if M (P ) is of reasonable size, its computation may fail due to the too large size of A ϕ,n . Corollary 6.30 gives upper-bounds to the sizes of the automata constructed by the algorithm used to prove Theorem 6.26. We will present two notions intended to facilitate effective constructions of automata: the direct computation of automata for frequently used properties and the use of Boolean set terms in the writing of formulas.

Precomputed automata

Remark 6.31(2) motivates the following idea. For expressing properties of terms (handled as syntactic trees) certain MS-expressible notions are frequently used and can be "precompiled" into "small" automata. This will reduce the nesting level of determinizations in the construction of the automaton for a formula using these properties. We only give one example.

Least common ancestor

For t ∈ T (F ), we let Lca(X 1 , X 2 ) be the property of sets X 1 , X 2 ⊆ N t defined by: X 1 = ∅ and X 2 = {u} where u is the least common ancestor of the nodes in X 1 , which we denote by u = lca(X 1 ). It can be expressed by a monadic second-order formula ϕ(X 1 , X 2 ) (we will give it below) but this formula is not needed for the following construction. We define directly (without using ϕ) a complete and deterministic automaton A that recognizes the language L Lca(X1,X2) .

Its states are 0, 1, Ok and Error with meanings defined by Table 6.5. The accepting state is Ok .

State q

Property P q

0 X 1 = X 2 = ∅ 1 X 1 = ∅ ∧ X 2 = ∅ Ok X 1 = ∅ ∧ X 2 = {lca(X 1 )}
Error all other cases Table 6.5: Meanings of the states of the automaton A .

The corresponding transition rules are in Table 6.6, with k = ρ(f ).

Transition rules Conditions

(f, 00)[q 1 , . . . , q k ] → 0 k ≥ 0, q 1 = q 2 = • • • = q k = 0
(f, 00)[q 1 , . . . , q k ] → Ok k ≥ 1 and for some i, q i = Ok and q j = 0 for j = i (f, 00)[q 1 , . . . , q k ] → 1 k ≥ 1 and for some i, q i = 1 and q j ∈ {0, 1} for j = i (f, 01)[q 1 , . . . , q k ] → Ok k ≥ 2, at least two of q 1 , . . . , q k are 1, the others being 0 (f, 11)[q 1 , . . . , q k ] → Ok k ≥ 0, q i ∈ {0, 1} for all i (f, 10)[q 1 , . . . , q k ] → 1 Table 6.6: Transition rules of the automaton A .

The property Lca(X 1 , X 2 ) is expressed by ϕ(X 1 , X 2 ) defined as:

X 1 = ∅ ∧ Ub(X 2 , X 1 ) ∧ ∀X 3 (Ub(X 3 , X 1 ) ⇒ Ub(X 3 , X 2 )),
where Ub(X, Y ) means that X = {u} and u is an ancestor of each element of Y (possibly u ∈ Y ). The latter property can be expressed by the formula:

Sgl (X) ∧ ∀Z(X ⊆ Z ∧ ∀V, W [V ⊆ Z ∧ son(V, W ) ⇒ W ⊆ Z] ⇒ Y ⊆ Z),
where son(V, W ) stands for the disjunction of the atomic formulas son i (V, W ) for i = 1, . . . , ρ(F ).

The constructed automaton is actually minimal (because for any two states q and q , there exist terms t ∈ L(A , q), t ∈ L(A , q ) and a context c ∈ Ctxt(F (2) ) such that c[t] ∈ L Lca(X1,X2) and c[t ] / ∈ L Lca(X1,X2) or vice-versa; cf. Section 3.4.3, Proposition 3.73( 1)). However, the application to ϕ of the general constructions of Theorem 6.26 involves lengthy and space-consuming computations. Hence, for applying them, as done for example in the software MONA ( [Hen+, Kla]), it seems preferable to use monadic second-order formulas constructed with more atomic formulas than those listed in Construction 6.27. In this way, we extend the syntax of monadic second-order formulas without extending their expressive power.

Boolean set terms

Another method for lowering the block quantifier-heights of formulas consists in writing them with Boolean set terms. We first give examples. Assume that we need to express the set property 20 X 1 -X 2 ⊆ X 3 . It is equivalent to

X 1 ⊆ X 2 ∪ X 3 , hence can be expressed by the formula ϕ(X 1 , X 2 , X 3 ) defined as: ∀U (X 2 ⊆ U ∧ X 3 ⊆ U ⇒ X 1 ⊆ U )
but it cannot be expressed by a quantifier-free formula in CMS (∅, {X 1 , X 2 , X 3 }).

However, L ϕ = h -1 (L X1⊆X2
) where h is the mapping : {0, 1} 3 → {0, 1} 2 such that, for every i, j, k ∈ {0, 1} we have h((i, j, k)) := (i, max{j, k}).

Similarly, if ϕ is intended to express that the set X 1 ∩X 2 has even cardinality, then we have L ϕ = h -1 (L Card0,2(X1) ) where h : {0, 1}

2 → {0, 1} is such that h((i, j)) := min{i, j}.

The following definition applies to other relational signatures than R F .

Definition 6.32

Let R be a relational signature without constant symbols.

A Boolean set term is a term in T (B, X n ) where B := {∪, ∩, } and is the unary operation of complementation. We extend the language CMS (R, X n ) by allowing atomic formulas of the forms Card p,q (t 1 ), t 1 ⊆ t 2 , t 1 = ∅, Sgl (t 1 ) and R(t 1 , . . . , t ρ(R) ) where t 1 , t 2 , . . . , t ρ(R) are Boolean set terms. Examples of Boolean set terms are X 2 , X 3 ∩ X 1 and (X 3 ∩ X 1 ) ∪ (X 3 ∩ X 4 ). Their interpretations and those of the atomic formulas built with them is clear from the syntax. We denote by CMS Bool (R, X n ) the corresponding set of formulas. It contains CMS (R, X n ).

A Boolean substitution is a mapping σ :

X n → T (B, X m ). For every formula ϕ ∈ CMS Bool (R, X n ), we let ϕ σ be the formula ϕ[σ(X 1 )/X 1 , . . . , σ(X n )/X n ] in CMS Bool (R, X m ). 20 For a more complicated example, consider X ⊆ Y ∪ (Z -V ). It is expressed by ∀U [Y ⊆ U ∧Z -V ⊆ U ⇒ X ⊆ U ]. Since Z -V ⊆ U is expressed by ∀W (U ⊆ W ∧V ⊆ W ⇒ Z ⊆ W ), the property X ⊆ Y ∪ (Z -V ) is expressed by the formula ∀U [Y ⊆ U ∧ ∀W (U ⊆ W ∧ V ⊆ W ⇒ Z ⊆ W ) ⇒ X ⊆ U ] of (block) quantifier-height 2.
We now apply this definition to the formulas that express properties of terms. Let t ∈ T (F ) and γ : X m → P(N t ). It is clear (from similar results in Section 5.2.1) that ( t , γ) |= ϕ σ if and only if ( t , δ) |= ϕ, where δ is the assignment : X n → P(N t ) defined by δ(X i ) := σ(X i ) P(Nt) (γ(X 1 ), . . . , γ(X m )) and P(N t ) is the Boolean algebra of subsets of N t . On the other hand, it is easy to check that w δ (u) = h σ (w γ (u)) for every u ∈ N t , where h σ is the mapping : {0, 1} m → {0, 1} n such that, for every w ∈ {0, 1} m , we have h σ (w) := (σ(X 1 ) B (w), . . . , σ(X n ) B (w)) and B is the Boolean algebra {0, 1}. As before, we extend h σ into an arity preserving mapping :

F (m) → F (n) by letting h σ (f, w) = (f, h σ (w)).
The following lemma generalizes Lemma 6.25 and its proof is the same. Lemma 6.33 For every formula ϕ in CMS Bool (R F , X n ) and every Boolean substitution σ :

X n → T (B, X m ), we have L ϕ σ ,m = h -1 σ (L ϕ,n ).
By applying this lemma to the atomic formulas ϕ of Construction 6.27, we can extend Theorem 6.26 to formulas in CMS Bool (R F , X n ). Formulas in this set are of lower block quantifier-height than the equivalent formulas in CMS (R F , X n ). Since the inverse image construction (cf. Proposition 6.11(2)) does not increase the number of states, using them will necessitate less determinizations of intermediate automata than if we start from the equivalent formulas that do not use Boolean set terms. The expression of Corollary 6.30 that bounds the number of states of the constructed automata is the same but it will be applied to formulas of smaller block quantifier-height (the value h in Corollary 6.30).

Monadic second-order properties of graphs of bounded clique-width

We will construct automata for checking the monadic second-order properties of simple (unlabelled) p-graphs of bounded clique-width. Extending the constructions to simple (K, Λ)-labelled p-graphs of bounded clique-width will be straightforward.

In the next subsection, we will do the same for graphs of bounded tree-width defined by terms over the signature F HR C . We first present the construction for pgraphs of bounded clique-width defined by terms over F VR C because it is simpler. (However, the parsing problem for the VR algebra is more difficult, as we have seen in Section 6.2).

Let C := {a, b, . . . } be a finite set of port labels. A simple p-graph G of type π(G) ⊆ C is represented faithfully by the R s,C -structure G C = V G , edg G , (lab aG ) a∈C , where some of the sets lab aG may be empty.

We will denote these p-graphs by terms over the finite functional signature F VR C . We recall that it consists of the function symbols ⊕, --→ add a,b , add a,b and relab h such that a, b ∈ C, a = b and h ∈ [C → C], and of the constant symbols ∅, a and a for a ∈ C. We let C := {a, a | a ∈ C}. Although the constant symbol ∅ that denotes the empty graph can be eliminated from the terms that denote nonempty graphs, it will be useful in certain constructions.

Every term t in T (F VR C ) evaluates to a concrete p-graph G = cval (t) = cval (t Id ) of clique-width at most |C|, with vertex set V G equal to Occ 0 (t), the set of occurrences in t of the constant symbols different from ∅ (cf. Section 2.5.2). Hence, in order to encode an assignment γ : X n → P(V G ) in a term t evaluating to G, we need only attach Booleans to the constant symbols in C. We will denote by

F VR(n) C the signature F VR C where C is replaced by the set of constant symbols C (n) defined as {(c, w) | c ∈ C, w ∈ {0, 1} n }.
Hence, we use a slight modification of the notation of Definition 6.24(c). For t ∈ T (F VR C ) and γ : X n → P(Occ 0 (t)) we define t * γ to be the term in T (F

VR(n) C ) obtained from t by replacing c by (c, w γ (u)) at each occurrence u of c ∈ C. Every term in T (F VR(n) C ) is of the form t * γ. For ϕ ∈ CMS (R s,C , X n ), we define L VR C,ϕ,n as the set of terms t * γ in T (F VR(n) C
) such that ( cval (t) C , γ) |= ϕ and we denote the set L VR C,ϕ,mfv (ϕ) by L VR C,ϕ . We will also use the notation L VR C,P (X1,...,Xn) for L VR C,ϕ,n if the n-ary property P is expressed by ϕ and mfv (ϕ) ≤ n. In most cases, the set C will be fixed by the context and we will omit the subscript C in the notation L VR C,ϕ,n and the related ones. The exponent VR is intended to distinguish these languages from the languages L ϕ,n of the previous section.

There is an obvious variant of Lemma 6.25:

L VR C,ϕ σ ,m = h -1 σ (L VR C,ϕ,n
) for every formula ϕ in CMS (R s,C , X n ) and every substitution σ : X n → X m , where h σ is extended into an arity preserving mapping : m) . The proof is similar to the one of Lemma 6.25.

F VR(m) C → F VR(n) C by letting h σ (c, w) = (c, h σ (w)) for c ∈ C and h σ (f ) = f for f / ∈ C (
By an inductive construction similar to that of Section 6.3.3, we can construct, for each formula ϕ (assumed without loss of generality to be mfv (ϕ)normal), an automaton B C,ϕ (denoted by B ϕ if C is specified by the context) that recognizes the language L VR C,ϕ . For formulas that are not atomic, obvious variants of Constructions 6.28 and 6.29 can be used 21 . We will only construct complete and deterministic automata for atomic formulas. Furthermore, we will only do that for formulas with variables X 1 and X 2 because substitutions and inverse images give the general case by (the variant of) Lemma 6.25 and Proposition 6.11(2). Construction 6.34 (Automata for atomic formulas over R s,C ) For constructing B Sgl(X1) , we only modify Table 6.1 appropriately, which gives Table 6.7. The accepting state is 1. By our convention on missing transitions, we also have the transition ⊕[1, 1] → Error , which is not listed in the table.

Similarly, the automata for Card p,q (X 1 ) (with q states), X 1 ⊆ X 2 and X 1 = ∅ (both with 2 states) are straightforward to build. We can also take as basic the automaton for X 1 = X 2 (also with 2 states).

21 In Construction 6.29, the arity preserving mapping h :

F VR(m) C → F VR(n) C
erases the last m -n Booleans associated to every c ∈ C and is the identity on

F VR(m) C -C (m) .

Transition rules

Conditions

∅ → 0 (c, 0) → 0 c ∈ C (c, 1) → 1 f [0] → 0, f [1] → 1 f is --→ add a,b or add a,b or relab h ⊕[0, 0] → 0 ⊕[0, 1] → 1 ⊕[1, 0] → 1 Table 6.7: Transition rules of B Sgl(X1) .
We now construct the automaton B := B edg(X1,X2) . Its set of states is:

Q := {0, Ok , Error } ∪ {a(1), a(2), ab | a, b ∈ C, a = b}
with accepting state Ok . The meanings of these states are described in Table 6.8, where, similarly to Equivalence (6.1), we have, for every term t * γ ∈ T (F

VR(2) C ): t * γ ∈ L(B, q) if and only if ( cval (t) C , γ(X 1 ), γ(X 2 )) satisfies P q (6.2)
and we recall that γ(X 1 ) and γ(X 2 ) are written X 1 and X 2 in the table for better readability.

State q

Property P q 0 X 1 = X 2 = ∅ Ok X 1 = {v 1 }, X 2 = {v 2 }, edg cval(t) (v 1 , v 2 ) for some v 1 , v 2 in V cval(t) a(1) X 2 = ∅, X 1 = {v 1 }, port cval(t) (v 1 ) = a a(2) X 1 = ∅, X 2 = {v 2 }, port cval(t) (v 2 ) = a ab X 1 = {v 1 }, X 2 = {v 2 }, port cval(t) (v 1 ) = a, port cval(t) (v 2 ) = b, v 1 = v 2 , ¬edg cval(t) (v 1 , v 2 )
Error all other cases Table 6.8: Meanings of the states of B edg(X1,X2) .

The number of states is k 2 + k + 3 where k = |C|. The transition rules are in Table 6.9. Among the missing transitions, note the following ones:

⊕[Ok , Ok ] → Error , (a, 11) → Error if a ∈ C and relab h [ab] → Error if h(a) = h(b). The table specifies O(k 4
) transitions, with (or without) counting the transitions to Error .

Equivalence (6.2) can be proved by induction on the structure of t, using Lemmas 2.95 and 2.96. Technically it is more convenient to prove its equivalent formulation by bottom-up induction on u: if r is the unique run of B on a term t * γ and u ∈ N t , then r(u) = q if and only if ( cval (t)/u C , γ(X 1 )∩(N t /u), γ(X 2 )∩ (N t /u)) satisfies P q .22 Then cval (t) must be replaced by cval (t)/u in Table 6.8 (and port cval(t)/u (v i ) can be replaced by port t (u, v i ), see Definition 2.94).

Transition rules

Conditions

∅ → 0 (c, 00) → 0 (c, 10) → a(1) c is a or a (c, 01) → a(2) (a , 11) → Ok relab h [q] → q q ∈ {0, Ok } relab h [a(1)] → b(1) b = h(a) relab h [a(2)] → b(2) relab h [ab] → cd c = h(a), d = h(b), c = d --→ add a,b [q] → q q ∈ Q -{ab} --→ add a,b [ab] → Ok add a,b [q] → q q ∈ Q -{ab, ba} add a,b [ab] → Ok add b,a [ab] → Ok ⊕[a(1), b(2)] → ab a = b ⊕[b(2), a(1)] → ab ⊕[a(2), b(1)] → ba ⊕[b(1), a(2)] → ba ⊕[q, 0] → q q ∈ Q ⊕[0, q] → q Table 6
.9: The transition rules of B edg(X1,X2) .

Table 6.9 contains also transitions for the operations add a,b that add pairs of opposite directed edges, that we also consider as undirected edges. If we restrict this automaton to the signature F VRu C that generates only undirected graphs (by deleting the transitions relative to the operations --→ add a,b ), then any two states ab and ba can be identified as the reader will check easily. Hence, the number of states is (slightly) reduced to k(k -1)/2 + 2k + 3.

The automaton for lab a (X 1 ) can be constructed in a similar, but easier way, with k + 2 states. We can also take as basic the automaton for lab ∀ a (X 1 ) (cf. Remark 6.18), with 2 k states.

The constructions of automata are done for generic sets C. That is, if we replace C by another set in bijection with it by h, then the corresponding automata are obtained by replacing everywhere in the states, in the transitions and the accepting states of the original ones, each a ∈ C by h(a). In particular, the numbers of states and transitions depend only on the cardinality of the considered set C.

We obtain the following theorem:

Theorem 6.35 For every finite set C of port names and every formula ϕ in CMS (R s,C , X ω ), one can construct a complete and deterministic automaton B C,ϕ that recognizes the language L VR C,ϕ ⊆ T (F

VR(mfv (ϕ)) C

). This automaton has at most exp(h, m(a m + h)) states where h = bqh(ϕ), m = ba(ϕ), and a is the maximal number of states of a complete and deterministic automaton (over F VR(1) C and F

VR(2) C

) constructed for an atomic subformula of ϕ.

For sentences ϕ, this theorem provides an alternative proof of Theorem 6.3(3). By Proposition 3.69, it entails the Weak Recognizability Theorem for the VR algebra (Corollary 5.69 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]) that also follows from the (full) Recognizability Theorem for the VR algebra (Theorem 5.68( 1)). However the (full) Recognizability Theorem for the VR algebra does not follow from it (see Section 6.4.6 below).

Remark 6.36 We can also prove the first statement of Theorem 6.35 without constructing the automaton B edg(X1,X2) and by using instead Theorem 6.26.

It suffices to show that the edge relation of

G = cval (t) for t ∈ T (F VR(n) C
) is definable in the relational structure t by an MS formula η(x, y). It follows that every formula

ϕ in CMS (R s,C , X n ), with n := mfv (ϕ), can be translated into a formula ψ in CMS (R F VR C , X n ) with mfv (ψ) = n such that, for every term t ∈ T (F VR(n) C
) and every mapping γ : X n → P(N t ), we have:

( t , γ) |= ψ(X 1 , . . . , X n ) if and only if γ(X 1 ), . . . , γ(X n ) are subsets of Occ 0 (t) and ( cval (t) C , γ) |= ϕ(X 1 , . . . , X n ).

Hence L VR

C,ϕ = L ψ and the automata B C,ϕ and A ψ are equivalent. This (short) proof is not satisfactory because the formula η(x, y) is fairly complicated. It must express that x, y are occurrences of constant symbols, for example a and b, and that they have a common ancestor u that is an occurrence of an edge creating operation --→ add c,d , and that the port labels a and b are transformed into c and d by the port relabelling operations that occur on the paths in t between x and u, and between y and u (cf. the function port t used in Definition 2.94 and Lemma 2.95; these relabellings are actually handled by the rules in Table 6.9 relative to the operations relab h .) The construction of η will be done in the proof that the evaluation mapping t → cval (t) C from terms to p-graphs is a monadic second-order transduction (Proposition 7.30, Section 7.2), so that the transformation of ϕ into ψ is a special case of the Backwards Translation Theorem (Theorem 7.10). It follows that ψ has a larger quantifier-height than ϕ. Using this proof would yield a longer computation, although the minimal automata of B C,ϕ and A ψ are the same (up to renaming of states). The construction of B C,edg(X1,X2) can be seen as that of a precomputed automaton (cf. Section 6.3.3) for η.

More tools for constructing automata

At the end of Section 6.3.3, we have presented two notions intended to facilitate the construction of automata: the direct construction of automata for frequently used properties and the use of Boolean set terms in the writing of formulas. These two notions are applicable to the present case. Our next objective is to enrich the tool box with a construction of automata for relativized formulas. We will also detail the direct construction of an automaton for paths, analogous to what we did above for the least common ancestor function. Construction 6.37 (Automata for relativized formulas) We recall from Section 5.2.1 that if ϕ is a sentence, then ϕ X 1 is a formula expressing that the substructure induced by the set denoted by X 1 satisfies the property expressed by ϕ, and we fix a set C. We will prove that the inverse image construction applied to B ϕ yields an automaton equivalent to B ϕ X1 . Slightly more generally, we consider a property of vertex sets P (X 1 , . . . , X n ). We let Q(X 1 , . . . , X n+1 ) be the property such that, for all sets of vertices X 1 , . . . , X n+1 of a graph G, the property

Q(X 1 , . . . , X n+1 ) is true if and only if P (X 1 ∩ X n+1 , . . . , X n ∩ X n+1 ) is true in the induced subgraph G[X n+1
]. Then we will construct an automaton recognizing L VR Q(X1,...,Xn+1) from one recognizing L VR P (X1,...,Xn) . This construction will be used in the case where P is a monadic second-order property. We present it in terms of properties rather than in terms of formulas to stress that it does not depend on the structure of formulas.

We define h as the arity preserving mapping :

F VR(n+1) C → F VR(n) C
such that, for every c ∈ C and w ∈ {0, 1} n , we have h((c, w0)) := ∅ and h((c, w1)) := (c, w), and h(f n) . With these hypotheses and notation we obtain the following lemma: Lemma 6.38 We have L VR Q(X1,...,Xn+1) = h -1 (L VR P (X1,...,Xn) ). Thus, if an automaton B P (X1,...,Xn) recognizes the language L VR P (X1,...,Xn) , then the automaton h -1 (B P (X1,...,Xn) ) recognizes the language L VR Q(X1,...,Xn+1) .

) := f for f / ∈ C (
Proof: Let t * γ belong to T (F VR(n+1) C

) and G = cval (t). Then h(t * γ) = t * γ , where, by the definitions, t evaluates to G := G[γ(X n+1 )] (cf. the proof of Proposition 2.105( 1)) and γ is the assignment :

X n → P(V G ) such that γ (X i ) = γ(X i ) ∩ γ(X n+1 ) for each i. It follows that t * γ ∈ L VR Q(X1,...,Xn+1) if and only if t * γ ∈ L VR P (X1,...,Xn) .
This result shows the usefulness of the symbol ∅ to denote the empty graph, for which we have defined transitions in Tables 6.7 and 6.9. Construction 6.39 (Precomputed automata for path properties)

The following construction concerns undirected graphs (it can easily be extended to directed paths in directed graphs). For an undirected graph G, we let Path(X 1 , X 2 ) mean that X 1 ⊆ X 2 , |X 1 | = 2 and there is a path in G[X 2 ] that links the two vertices of X 1 . It is monadic second-order expressible.

We will construct an automaton B C,Path(X1,X2) that recognizes the language L VR C,Path(X1,X2) , without using the logical expression of Path(X 1 , X 2 ). We take C of cardinality at least 2 because otherwise, the graphs generated by F VR C have no edges apart from loops (cf. Remark 2.107( 1)) and Path(X 1 , X 2 ) is always false. We need some auxiliary notions.

Let G be an undirected p-graph of type π

(G) = {port G (x) | x ∈ V G } ⊆ C. For x ∈ V G , we let 23 : α(G, x) := {port G (y) | y ∈ V G and x - * G y} ⊆ C, and
β(G) := {(port G (x), port G (y)) | x, y ∈ V G and x - * G y} ⊆ C × C. Hence β(G)
is a symmetric and reflexive relation on the set π(G). In particular, β(G) determines π(G). The relation β(G) is not necessarily transitive.

We will prove that the functions α and β can be computed inductively on the structure of a term over Claim 6.39.1

F VR C that evaluates to G. If h : C → C and B ⊆ C × C, then h(B) := {(h(a), h(b)) | (a, b) ∈ B}.
(1) α(G ⊕ H, x) = α(G, x) if x ∈ V G , α(H, x) if x ∈ V H . (2) β(G ⊕ H) = β(G) ∪ β(H). (3) α(add a,b (G), x) = if a, b ∈ π(G) then α(G, x) ∪ α(G, x) (a b) • β(G) else α(G, x). (4) β(add a,b (G)) = if a, b ∈ π(G) then β(G) ∪ β(G) • (a b) • β(G) else β(G). (5) α(relab h (G), x) = h(α(G, x)). (6) β(relab h (G)) = h(β(G)). (7) α(a, x) = α(a , x) = {a}. (8) β(a) = β(a ) = {(a, a)}. (9) β(∅) = ∅.
Proof: The verifications are easy from the definitions. We only sketch the proof of the inclusion ⊆ in (3).

If c is in α(add a,b (G), x), then either it is in α(G, x) or there exists a path from x to a c-port z that uses one or more edges added to G by add a,b . If this path contains only one such edge and goes through an a-port u and immediately after through a b-port w, we have a ∈ α(G, x) and (b, c) ∈ β(G) and thus c ∈ α(G, x) (a b) • β(G) because (a, b) ∈ a b. If this path contains several such edges, the first one being u -w and the last one being u -w , where u and u are a-ports and w and w are b-ports, then there is also an edge between u and w and the previous case gives the result. If u-w and u -w are as above except that w is an a-port and u is a b-port, then there is also an edge between w and w . Then a ∈ α(G, x) and (a, c) ∈ β(G) and thus

c ∈ α(G, x) (a b) • β(G) because (a, a) ∈ a b.
We now construct the automaton B C,Path(X1,X2) with its set of states Q defined as:

{Ok , Error } ∪ {(0, B) | B ⊆ C × C} ∪ {(1, A, B) | ∅ = A ⊆ C, B ⊆ C × C} ∪ {(2, {A, A }, B) | A, A ⊆ C, A = ∅, A = ∅, B ⊆ C × C}
with accepting state Ok . The meanings of these states are described in Table 6.10. In this table, we denote by G(t) the graph cval (t), and by G(t, X 2 ) the graph cval (t)[γ(X 2 )] where γ is the assignment encoded by the considered term (cf. Equivalences (6.1) and (6.2)). Equivalently, we could write G(u) to denote cval (t)/u, and

G(u, X 2 ) to denote cval (t)/u[γ(X 2 ) ∩ (N t /u)].
The transition rules are shown in Table 6.11, where we use the following height. The given construction of B C,Path(X1,X2) avoids thus lengthy computations. As already noted in Remark 6.31(2), the minimal automaton equivalent to B C,Path(X1,X2) depends only on the property Path(X 1 , X 2 ). It is thus the same as the one that could be obtained from any monadic second-order expression of this property, provided the computations do not abort by lack of memory.

Remark 6.40 (Some computing experiments)

The automaton of Table 6.11 has been implemented and minimized successfully24 for |C| = 2, 3, 4. (All automata discussed in this remark are complete and deterministic). For |C| = 3, the initial trim automaton has 214 states. The corresponding minimal automaton has 125 states and more than 16500 transition rules that do not yield the state Error . For |C| = 4, the minimal automaton has 2197 states.

For C := {a, b}, the initial trim automaton A := B C,Path(X1,X2) has 25 states and 372 transition rules; its minimal automaton has 12 states and 137 rules. The minimization algorithm has determined the following 12 equivalence classes of states of A . We first list the 9 singleton classes: By Proposition 2.106(2), the simple loop-free undirected graphs of cliquewidth at most 2 are the cographs that we have already discussed in Sections 1. 1.2 and 1.4.1,and in Example 4.43(1). These graphs are the p-graphs of type {a} generated by a, ⊕ and the complete join ⊗, a derived operation of GP u . Only six of the states of the minimal automaton of A are needed for the minimal {⊕, ⊗, a}-automaton. These states are Ok , Error , (0, ∅), (0, {(a, a)}), It would be interesting to simplify in a similar way the functional signature that generates graphs of clique-width 3 and more. This might yield workable automata for graphs of larger clique-width than 2.

Ok , Error , (0, ∅), (0, {(a, a)}), (0, {(b, b)}), (1, {a}, {(a, a)}), (1, {b}, {(b, b)}), (2, {{a}, {a}}, {(a, a)

Hopefully tractable monadic second-order properties

Our aim is here to identify classes of monadic second-order graph properties for which the associated automata have manageable sizes. These properties are expressible without quantifier alternation in terms of some "basic" monadic second-order properties. Definition 6.41 Let P be a set of pairwise inequivalent formulas in CMS (R s , X ω ) such that the set of free variables of any ϕ ∈ P is X mfv (ϕ) . The integer mfv (ϕ) is called the arity of the property P defined by ϕ and is denoted by ρ(P ).

We let P Bool be the set of formulas in CMS Bool (R s , X ω ) obtained from those of P by substitutions of Boolean set terms (cf. Definition 6.32). We let EB(P Bool ) be the set of sentences of the form ∃X. θ such that θ is a Boolean combination of formulas in P Bool and X is a sequence of set variables.

We assume that, for each ϕ in P and k in N + , we have constructed (or some algorithm can construct) a complete and deterministic

F VR(mfv (ϕ)) [k] -automaton B [k],ϕ recognizing L VR [k],ϕ , with N (k, ϕ)
states. This number is also denoted by N (k, P ) if P is the property corresponding to ϕ. If a formula α is obtained from ϕ ∈ P by a substitution X mfv (ϕ) → T (B, X n ) of Boolean set terms, then an automaton recognizing L VR

[k],α,n , with N (k, α) = N (k, ϕ) states, can be constructed for it by (the obvious variant of) Lemma 6. 33 and Proposition 6.11(2).

Since the formulas of P are over R s , the properties that they express do not depend on port labels (they are properties of graphs, not of p-graphs). Hence, the graphs to be checked can be constructed with sets of port labels [k] instead of sets C of cardinality k without loss of generality or efficiency. The F VR(mfv (ϕ)) C automata associated with such sets C are all "isomorphic" to B [k],ϕ . We use here the remark before Theorem 6.35. Proposition 6.42 Let P ⊆ CMS (R s , X ) be as in Definition 6.41. Let ϕ in EB(P Bool ) be a sentence of the form ∃X 1 , . . . , X n . θ where θ is a Boolean combination of formulas α 1 , . . . , α m in P Bool . For each k, there exists a nondeter-

ministic F VR [k] -automaton B [k],ϕ with at most N := N (k, α 1 ) × • • • × N (k, α m ) states that recognizes the language L VR [k],ϕ . Membership in L(B [k],ϕ ) of any term t ∈ T (F VR [k] ) can be checked in time m•a•(2 n +N 2 )•|t|
, where a is an upper-bound to the transition time of the automata for α 1 , . . . , α m .

Proof: For each i, the formula α i is obtained from some ϕ i ∈ P by a substitution of Boolean set terms. From the complete deterministic automaton B [k],ϕi for ϕ i with N (k, ϕ i ) states, we obtain, by the inverse image construction, a complete deterministic automaton for α i with the same number of states, recognizing L VR

[k],αi,n . From the automata for α 1 , . . . , α m a complete and deterministic automaton for θ can be obtained by the product construction of Proposition 6.10. It recognizes L VR

[k],θ,n and has N states (but after trimming, it can have less states). A nondeterministic automaton B [k],ϕ for ϕ with the same number of states is then obtained from it by a direct image construction (as in Construction 6.29, by Proposition 6.11( 1)). That automaton has degree of nondeterminism 2 n and is only nondeterministic on constant symbols. The evaluation of the computation time uses Proposition 6.14 and Remark 6.15.

Examples 6.43 (Automata for some basic graph properties) In the following, we define a set of basic monadic second-order graph properties that we denote by P (like the corresponding set of formulas).

In Definition 6.41, we have given no syntactic constraints on the formulas of P. In order to get applicable instances of Proposition 6.42, we will only (or mainly) consider formulas ϕ such that N (k, ϕ) = 2 O(k 2 ) . Imposing on the numbers N (k, ϕ) a polynomial bound, or even the bound 2 O(k) , would eliminate too many basic and useful graph properties. Furthermore, the automata for the important property of connectivity have 2 2 Θ(k) states. A similar situation holds for the property of being a forest.

Example 6.43(1): A set P of basic graph properties

We let P consist of the properties defined by the atomic formulas, the property Path(X 1 , X 2 ) that has been defined in Construction 6.39, together with the following properties.

Disj (X 1 , . . . , X p ) expresses that the vertex sets X 1 , . . . , X p are pairwise disjoint, Part(X 1 , . . . , X p ) expresses that X 1 , . . . , X p form a partition of the vertex set of the considered graph (where some of the sets X 1 , . . . , X p may be empty),

Card ≤p (X 1 ) expresses that the set X 1 has cardinality at most p, St expresses that the considered graph is stable, i.e. that its only edges are loops,

Clique expresses that any two distinct vertices of the considered graph are linked by an undirected edge (equivalently, by two opposite directed edges), Link (X 1 , X 2 ) expresses that there exists an edge linking a vertex of X 1 to one of X 2 (hence, Link is edg ∃∃ , cf. Remark 6.18), Dom(X 1 , X 2 ) expresses that X 2 dominates X 1 , i.e., that X 1 and X 2 are disjoint and every vertex of X 1 is the head of an edge with tail in X 2 , InDeg p (X 1 , X 2 ) expresses that every vertex in X 1 is the head of exactly p edges with tail in X 2 (X 1 and X 2 need not be disjoint and a loop incident with

x ∈ X 1 counts if x ∈ X 2 ),
Conn expresses that the considered graph is connected, and NoCycle expresses that the considered undirected graph is a forest (has no cycle, in particular, no loop).

We let ConnIfDeg d express connectedness for a graph assumed to have degree at most d, and similarly, NoCycleDeg d express that a graph of degree at most d is a forest.

From St, which is a property of the considered graph, one gets by relativization (Construction 6.37) the corresponding property St(X 1 ) of the subgraph induced by a set of vertices X 1 . Similarly we obtain the relativized properties Clique(X 1 ), Conn(X 1 ), NoCycle(X 1 ), ConnIfDeg d (X 1 ) and NoCycleDeg d (X 1 ). We also add these properties to P. By Lemma 6.38 and Proposition 6.11(2), an F VR [k] -automaton for property P can easily be transformed into an

F VR (1) [k]
automaton for the property P (X 1 ), with the same number of states. Table 6.12 shows upper-bounds to the numbers of states N (k, P ) for these properties. 25 The values come from constructions of complete and deterministic automata that are not necessarily minimal. We will not give detailed descriptions of these automata. We will only define their sets of states and describe their meanings, as we did previously (cf. Table 6.10). The transitions will be easy to construct from these descriptions. We will use the notation of Table 6.10: G(t) denotes cval (t) and G(t, X i ) denotes cval (t)[γ(X i )]. We order the automata by increasing number of states.

The properties Disj (X 1 , . . . , X p ) and Part(X 1 , . . . , X p ): The F

VR(p) [k]

-automata for these properties are straightforward to construct; they have 2 states but their sizes depend of course on p and k. The property Card ≤p (X 1 ): The states are 0, 1, . . . , p and Error . The accepting states are 0, 1, . . . , p. The meanings of the states are described by the following conditions:

P i : G(t) has i vertices. P Error : G(t) has more than p vertices.

Stability:

The states are Error and A for each A ⊆ [k]. All states are accepting except Error . Their meanings are described by the following conditions:

P A : A = π(G(t)) and G(t) is stable. P Error : G(t) is not stable.
Since we use the constant symbol ∅ (it is useful for the relativization construction), we may have G(t) = ∅ and A = ∅.

Property P N (k, P ) X 1 = ∅ 2 X 1 ⊆ X 2 2 Disj (X 1 , . . . , X p ) 2 Part(X 1 , . . . , X p ) 2 Sgl (X 1 ) 3 Card p,q (X 1 ) q Card ≤p (X 1 ) p + 2 edg(X 1 , X 2 ) k 2 + k + 3 St 2 k + 1 Link (X 1 , X 2 ) 2 2k + 1 Dom(X 1 , X 2 ) 2 2k + 1 InDeg p (X 1 , X 2 ) (p + 2) 2k Path(X 1 , X 2 ) 2 k 2 +2 Clique 2 Θ(k 2 ) ConnIfDeg d 2 d•k 2 NoCycleIfDeg d 2 d 2 •k 2 Conn 2 2 Θ(k) NoCycle 2 2 O(k)
Table 6.12: Some graph properties.

) can be transformed into an equivalent irredundant term s in T (F

VR(n) [k]
) as follows: if --→ add a,b or add a,b has an occurrence u in t such that (a, b) ∈ Edg(t ↑ u) (this set is defined in the proof of Proposition 2.105(4), at the end of Section 2.5.6), then this edge addition operation can be removed at u (or replaced by the identity operation relab Id ). Since the sets Edg(t ↑ u) can be computed in linear time, the term s can also be constructed in linear time.

It follows that it suffices to construct automata that work as desired on irredundant terms. For InDeg p (X 1 , X 2 ) and for the property NoCycle considered below, such automata are simpler to construct (and smaller) than those intended to accept arbitrary terms. The property Clique: The states are the pairs (A, R) for all A ⊆ [k] and binary relations R on A. The accepting states are the pairs (A, ∅) (we consider ∅ as a clique). Their meanings are as follows:

P (A,R) : A = π(G(t)) and R is the set of pairs (a, b) ∈ A × A
such that there exist in G(t) a vertex x with port label a and a vertex y with port label b such that (x, y) / ∈ edg G .

The number of states is less than 2 k 2 +k . The minimal automaton has 2 Θ(k 2 ) states as one can check easily.

Connectivity: An automaton for this property must have many states: we know from Example 4.54(4) that there exists no automaton with 2 2 m states or less that checks the connectivity of graphs of clique-width at most k = 2m + 1. Our construction will be similar to the proof of HR-recognizability in Example 4.30(2). We will use the following notions and notation relative to a p-graph G of type included in [k]: We are ready to define the set of states Q of the automaton for connectivity. We let E be the set of nonempty subsets of [k] and Q be the set of multisets of the form Set † (M ) where M is a multiset of elements of E. The meanings of these multisets are described by the equality:

CC (G)
P M : M = Set † (π(CC (G(t)))).
The accepting states are the singletons. Examples of states are {{1, 2}, {1, 2}} and {{1}, {1, 2}, {2, 3, 4, 6}}. They may correspond to a p-graph G(t) having three connected components, all of type {1, 2} in the first case, and four connected components of types {1}, {1}, {1, 2} and {2, 3, 4, 6} in the second one. The state {{1, 2}} is accepting and corresponds to a connected p-graph of type {1, 2}.

The number of states is thus 2 |D| + |D| = 2 2 k -1 + 2 k -1. However, if we want only to verify the connectivity of graphs of degree at most d, we can use a smaller automaton: we replace Q by the set Q d of states M ∈ Q such that each element of [k] belongs to at most d sets of M , to which we add a state Error . Hence, each state M in Q d is a set of at most dk elements from E. It follows that its cardinality is less than 2 d•k 2 . The corresponding automaton may reject a term that defines a connected graph of degree larger than d.

Detailed constructions and correctness proofs can be found in [START_REF] Courcelle | Automata for the verification of monadic second-order graph properties[END_REF].

Forests: The construction of an automaton with 2 2 O(k) states for the property NoCycle saying that an undirected graph has no cycles, i.e., that it is a forest, is also quite complicated. As for connectivity, if we want to verify the absence of cycles in graphs of degree at most d, we can use a smaller automaton, with 2 d 2 •k 2 states. The reader will find these constructions in [START_REF] Courcelle | Automata for the verification of monadic second-order graph properties[END_REF]. They work for irredundant terms.

Letting P be the above set of basic properties, we now give a few examples of graph properties in EB(P Bool ).

Example 6.43(2): Monadic second-order vertex partitioning problems

We first consider colorability problems for undirected graphs; vertex p-colorability can be expressed as follows:

∃X 1 , . . . , X p (Part(X 1 , . . . , X p ) ∧ St(X 1 ) ∧ • • • ∧ St(X p )).
A vertex p-coloring defined by X 1 , . . . , X p is achromatic ([Bod89]) if there is an edge between any two distinct sets X i and X j . The existence of such a coloring is thus expressed, for an undirected graph, by:

∃X 1 , . . . , X p (Part(X 1 , . . . , X p ) ∧ • • • St(X i ) • • • ∧ • • • Link (X i , X j ) • • • ),
where the conjunctions extend to all 1 ≤ i < j ≤ p.

A vertex p-coloring of an undirected graph G, defined by X 1 , . . . , X p , is

acyclic (cf. [*JenTof]) if each induced graph G[X i ∪ X j ] is acyclic, i.e.
, is a forest. The existence of an acyclic p-coloring is thus expressed by:

∃X 1 , . . . , X p (Part(X 1 , . . . , X p ) ∧ • • • St(X i ) • • • ∧ • • • NoCycle(X i ∪ X j ) • • • ),
where the conjunctions extend to all 1 ≤ i < j ≤ p.

These three properties are in EB(P Bool ) where P is as in Example 6.43 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. For p-coloring, achromatic p-coloring and acyclic p-coloring, we obtain nondeterministic automata with respectively 2 O(p•k) , 2 O(p 2 •k) and 2 p 2 •2 O(k) states, by Proposition 6.42.

We now consider domination problems constrained by particular monadic second-order properties. The sentence

∃X(θ(X) ∧ Dom( X, X)),
where X denotes the complement of X, expresses that there exists a set X that dominates all other vertices (cf. Example 6.43(1)) while satisfying a property specified by θ. This sentence is thus in EB((P ∪ {θ}) Bool ).

A graph has domatic number at most p if its vertex set can be partitioned into p sets such that each of these sets dominates all other vertices. That is:

∃X 1 , . . . , X p (Part(X 1 , . . . , X p ) ∧ Dom( X 1 , X 1 ) ∧ • • • ∧ Dom( X p , X p )).
Minor inclusion can also be considered as a vertex partitioning problem. We recall from Lemma 1.13 and Corollary 1.14 that an undirected graph G contains a fixed simple loop-free undirected graph H as a minor if and only if it satisfies the following sentence MINOR H :

∃X 1 , . . . , X p (Disj (X 1 , . . . , X p ) ∧ Conn(X 1 ) ∧ • • • ∧ Conn(X p ) ∧ X 1 = ∅ ∧ • • • ∧ X p = ∅ ∧ • • • Link (X i , X j ) ∧ • • • ),
where {v 1 , . . . , v p } = V H and there is in MINOR H one formula Link (X i , X j ) for each edge {v i , v j } of H. We obtain a nondeterministic automaton with k) states for checking that H is a minor of the given graph; we can use a nondeterministic automaton with 2 O(d•p•k 2 +p 2 •k) states if the input graph has degree at most d.

2 p•2 O(k) +p 2 •O(
fixed-parameter cubic algorithm for testing perfectness, with clique-width as parameter.

Tests conducted by Durand are reported in [START_REF] Courcelle | Automata for the verification of monadic second-order graph properties[END_REF].

6.3.5 Monadic second-order properties of graphs of bounded tree-width

In the previous section, we have constructed automata from monadic secondorder formulas for graphs of bounded clique-width. We have given in this way an alternative proof of the Weak Recognizability Theorem for the VR algebra and a fixed-parameter tractable algorithm for the model-checking problem of CMS sentences, the parameter being the clique-width of the given graph (if the sentence to be checked is fixed). Our objective is here to do the same for the HR algebra and the model-checking problem for CMS 2 sentences with respect to tree-width. Before embarking on constructions of automata, let us look at what can be obtained from the results and constructions of the previous section. First, we sketch a proof that the model-checking problem MC(J S [K,Λ] [∅], CMS) is fixed-parameter linear with respect to (twd (G), ϕ), where G is the input graph and ϕ is the input sentence (this is a weakening of Theorem 6.4(1) where the richer language CMS 2 is used). We can derive this result from Theorem 6.35 (or Theorem 6.3(3)) relative to the VR algebra as follows. Let G be a labelled graph given as val (t) for a term t over F HR [K,Λ] . By the proof of Theorem 4.49, one can transform this term in linear time into a term t over F VR [K,Λ] that evaluates to the same graph. Theorem 6.35 gives the result, with the help of the parsing step described in the proof of Theorem 6.4 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. This proof has two drawbacks: first, it does not apply to sentences with edge set quantifications and second, it transforms a term in T (F HR

[k],[K,Λ] ) into a term in T (F VR [m],[K,Λ]
) where m is exponential in k (cf. the discussion in Section 5.3.4).

Another possibility consists in observing that if G is a (K, Λ)-labelled graph of tree-width k, then its incidence graph Inc(G) is a (K ∪ Λ, ∅)-labelled simple directed graph of tree-width at most max{2, k} (cf. Example 2.56(5)). Hence, the previous reduction is applicable, which answers the first objection but not the second one. However, the incidence graph of such a graph of path-width k has path-width at most k + 1 (easy) and clique-width at most k + 3 (by Proposition 2.114(1.3)). Hence the two drawbacks we are discussing disappear for graphs G of bounded path-width given by slim terms over

F HR [k+1],[K,Λ] .
We have observed at the end of Section 6.2.1 that path-decompositions of width at most any fixed k can be computed in linear time (for graphs of path-width at most k). From such a decomposition, we can compute one for Inc(G). Proposition 2.85 shows that it can be converted in linear time into a slim term over F HR

[k+2],[K∪Λ,∅] , and Proposition 2.114 (1.3) shows that this term can be turned into one over F VR [k+3],[K∪Λ,∅] that defines Inc(G). The necessary terms can thus be constructed in linear time. The constructions of automata of Section 6.3.4 can be adapted (without the exponential increase of their sizes due to Proposition 2.114(2)) and applied to the model-checking of CMS 2 sentences. This observation is developed in [START_REF] Courcelle | On the model-checking of monadic second-order formulas with edge set quantifications[END_REF].

Since graphs of bounded tree-width are frequently considered, and since the above reductions use very large sets of port labels, it is useful to have a direct inductive construction of automata, along the lines of Section 6.3.4. As for graphs of bounded clique-width, the main task will be to specify the relevant signature (analogous to F VR(n) ) and to construct automata for the atomic formulas. The other steps will use products, direct and inverse images of automata (cf. Section 6.3. 1 and Constructions 6.28 and 6.29).

We will only construct automata that check properties of directed unlabelled graphs (without sources). The constructions will extend easily to undirected and/or labelled graphs with sources. In particular, the source names of an sgraph can be specified as vertex labels. (See the remark after Theorem 6.4, the remarks in Section 5.1.5 about replacing constant symbols by unary relations, and Remark 6.51 below). Definition 6.44 (A variant of the signature F HR ) Let C be a finite set of source labels. We let F HRd C be the derived signature of F HRd C consisting of the following constant and operation symbols:

-the constant symbols ∅, a and -→ ab for a, b ∈ C such that a = b, -the parallel composition , -the source renaming operations ren h such that h is a permutation of C, -the unary (derived) operations miv a , for a ∈ C, defined by: miv a (G) := fg a (a G).

The operation miv a makes an internal vertex by using source label a: if a ∈ τ (G), then miv a (G) = fg a (G); otherwise miv a (G) is G ⊕ fg a (a), i.e., is G augmented with a new isolated internal vertex. In both cases, the number of internal vertices is increased by one. Note that τ (miv a (G)) = τ (G) -{a}. The other symbols have the same interpretation as in JS d . For a term t in T (F HRd

C

), the s-graph val (t) is well defined since F HRd C is a derived signature of F HRd C . Note that the isolated vertices of val (t) cannot be sources. Apart from that, F HRd C and F HRd C generate the same s-graphs. The type τ (t) of t is defined to be τ (val (t)) and τ (u) := τ (t/u) for u ∈ N t . We denote by T (F HRd C ) ∅ the set of terms t in T (F HRd

C

) such that τ (t) = ∅, i.e., such that val (t) has no sources.

If G is a concrete s-graph such that G val (t) for a term t in T (F HRd

C

), then there are bijections between E G and the set Occ 0 (t) of occurrences in t of constant symbols different from ∅, and between Int G , the set of internal vertices of G, and the set Occ 1 (t) of occurrences in t of the unary symbols miv a . This fact is made more precise in the following proposition that uses definitions from Section 2.3.2 and some new definitions.

We define for every term t in T (F HRd

C

) a canonical (concrete) s-graph c val (t), to be distinguished from the canonical s-graph cval(t) associated with every t in T (F HRd ). Let t be a term in T (F HRd

C

). Without loss of generality, we assume that C ∩ N t = ∅. For every u ∈ N t , we denote Occ i (t) ∩ N t /u by Occ i (t)/u and we define a concrete s-graph G(u) with edge set Occ 0 (t)/u, vertex set (Occ 1 (t)/u) ∪ τ (u) and a-source a for every a ∈ τ (u), by the following bottom-up induction:

If u is an occurrence of ∅, then G(u) := ∅. If u is an occurrence of a , then G(u) has vertex a (that belongs to τ (u)) with the incident loop u.

If u is an occurrence of -→ ab, then G(u) has vertices a and b and u is an edge from a to b.

If u is an occurrence of with sons u 1 and u 2 , then G(u) is the concrete graph G(u 1 ) G(u 2 ) (it is easy to check that G(u) is well defined).

If u is an occurrence of ren h with son u 1 , then G(u) is the concrete graph ren h (G(u 1 )) with every vertex a ∈ τ (u 1 ) renamed into h(a). 26If u is an occurrence of miv a with son u 1 , there are two cases. If a ∈ τ (u 1 ), then G(u) is the concrete graph fg a (G(u 1 )) with vertex a renamed into u. If a / ∈ τ (u 1 ), then G(u) is G(u 1 ) augmented with u as new internal and isolated vertex.

We will denote G(root t ) by c val (t). It is a concrete s-graph isomorphic to val (t). It has edge set Occ 0 (t) and vertex set Occ

1 (t) ∪ τ (t). If t ∈ T (F HRd C ) ∅ (which means that val (t) is a graph), then V c val(t) = Occ 1 (t).
If G is a concrete graph isomorphic to c val (t) by an isomorphism w : G → c val (t), then w can be viewed as a bijection : V G ∪ E G → Occ 1 (t) ∪ Occ 0 (t). We call such a bijection a simple witness of the isomorphism of G and val (t). ("Simple" because it is simpler than the witnesses defined in Section 2.3.2, and to distinguish it from them.) Proposition 6.45 (2) Let s be a term in T (F HRd

C

) ∅ that defines a concrete graph G, and w be a canonical witness of G val (s). One can compute in linear time (for fixed C) an equivalent term t in T (F HRd C ) ∅ and a simple witness w of G val (t).

(3) Let L be a set of graphs and A be an automaton with N states such that, for every term t in T (F HRd

C

) ∅ , we have t ∈ L(A ) if and only if val (t) ∈ L. From A , an automaton B with 2 |C| • N states can be constructed that recognizes the set of terms t in T (F HRd

C

) ∅ such that val (t) ∈ L. If A is complete and deterministic, then so is B.

Proof: (1) Since F HRd C is a derived signature of F HRd C , the s-graphs it defines are also defined by terms over F HRd

C

. The opposite implication, for graphs (without sources), follows from (2) that we now prove.

(2) Let s ∈ T (F HRd

C

) ∅ and w be a canonical witness of G val (s). In two steps, we will transform s into t, and w into w .

Step 1 : At each occurrence u in s of an operation fg B , we replace this operation by the composition of the operations fg a for all a in B ∩ τ (u 1 ), where u 1 is the son of u (in particular, fg B is removed if B ∩ τ (u 1 ) = ∅). We obtain in this way an equivalent term s 1 , and easily, a corresponding canonical witness w 1 .

Step 2 : We obtain the desired term t by replacing in s 1 every constant symbol a by ∅ and every operation symbol fg a by miv a .27 Since t is obtained from s 1 by replacements of unary operations, N t = N s1 . It is straightforward to show, by bottom-up induction on u ∈ N s1 , that val (t/u) is obtained from val (s 1 /u) by removing all isolated sources. In particular, if s 1 /u = fg a (s 1 /u 1 ) and the a-source of val (s 1 /u 1 ) is isolated, then a / ∈ τ (t/u 1 ) and so the operation miv a adds an isolated vertex to val (t/u 1 ). Hence val (t) = val (s 1 ) and G val (t). It remains to define a simple witness w of this fact. Recall that N t = N s1 . We define w (e) := w 1 (e) if e ∈ E G .

By the definitions of Section 2.3.2, if x ∈ V G , then w 1 (x) = (u, a) where a ∈ τ (s 1 /u) and (u, a) ∈ X max , i.e., u is the unique maximal node of s 1 in the set {u ∈ N s1 | (u , a ) ≈ s1 (u, a) for some a ∈ C}. The node u cannot be the root of s 1 because τ (s 1 ) = τ (s) = ∅. The father v of u is necessarily an occurrence of fg a in s 1 , hence of miv a in t. We take it as w (x).

A formal proof of the correctness of w can be based on a proof that cval (s 1 ) is isomorphic to c val (t). By bottom-up induction on u ∈ N t it can be shown that the concrete graph that is obtained from ((Exp(s 1 ) u)/≈ s1,u ) Xmax (see the proof of Proposition 2.41) by removing its isolated sources, is isomorphic to G(u). For edges, the isomorphism is the identity on Occ 0 (t)/u. For vertices, it maps (u, a) ∈ X max to a if u is the root, and to the father of u otherwise.

To optimize the construction one can, by using Equalities (3), ( 5) and ( 9) of Proposition 2.48, eliminate from s all occurrences of ∅ (cf. Proposition 2.49). Using Equalities (3) and ( 9), the occurrences of ∅ in t can be removed except those that are directly below some miv a .

All these computations can be done in time O(|s|).

(3) Let A be an F HRd

C

-automaton with the stated property. We construct an F HRd C -automaton B that, for each input term s of type ∅, simulates the automaton A on input t, where t is defined from s as in the proof of (2). The states of B are of the form (A, q) where A ⊆ C and q is a state of A . The final states are all (∅, q) with q ∈ Acc A . In the first component of its state, B computes the type of s. For an input symbol ∅, a , -→ ab, or ren h , the automaton B just simulates A (and updates the type). For an input symbol a, the automaton B simulates A for the input symbol ∅ (and computes the type {a}). If B arrives in state (A, q) at an input symbol fg B , then it simulates A (in state q) on the consecutive input symbols miv a1 , . . . , miv am , where {a 1 , . . . , a m } = B ∩ A (and it updates the type to A -B). In the particular case where m = 0, the state q is unchanged. The detailed construction of B is omitted.

Example 6.46 We let C := {a, b, c, d} and:

s := fg a,b,d 1 ( -→ ab 3 2 fg c 4 (c 6 5 ( -→ cb 8 7 fg a,d 9 (a 11 10 d 12 )))).
The indices 1 to 12 indicate the positions of the term s (in Polish prefix notation). The concrete graph G val (s), with vertices u, v, x, y, z, is:

• u -→ • v ←-• x • y • z .
Its canonical witness w maps vertices as follows:

w(u) = (5, c), w(v) = (2, b), w(x) = (2, a), w(y) = (10, a), w(z) = (10, d),
and maps the edges (u, v) (defined by the symbol -→ cb) and (x, v) (defined by the symbol -→ ab) to 8 and 3 respectively. We apply to s the transformation of Step 1 in the proof of Proposition 6.45(2) and obtain the term

s 1 := fg a 1 (fg b 2 ( -→ ab 4 3 fg c 5 (c 7 6 ( -→ cb 9 8 fg a 10 (fg d 11 (a 13 12 d 14 ))))))
and the canonical witness w 1 that maps vertices as follows:

w 1 (u) = (6, c), w 1 (v) = (3, b), w 1 (x) = (2, a), w 1 (y) = (11, a), w 1 (z) = (12, d),
and maps the edges (u, v) and (x, v) to 9 and 4 respectively. This term is in the left part of Figure 6.2. Note for example that w 1 (u) = (6, c): vertex u is defined by c at position 7 and by -→ cb at position 9; it is made internal by fg c at position 5 and is thus represented by w 1 (u) = (6, c) where 6 is the son of 5 and so, the highest position where u is still a source. We now transform s 1 according to Step 2 in the proof of Proposition 6.45(2). Then, we get:

t := miv a 1 (miv b 2 ( -→ ab 4 3 miv c 5 (∅ 7 6 ( -→ cb 9 8 miv a 10 (miv d 11 (∅ 13 12 ∅ 14 ))))))
with the simple witness w that maps vertices as follows:

w (u) = 5, w (v) = 2, w (x) = 1, w (y) = 10, w (z) = 11.
and, as w 1 , maps the edges (u, v) and (x, v) to 9 and 4 respectively. This term is in the right part of Figure 6.2. Vertex u is now represented by w (u) = 5. Note that u is not a source at position 5. Since c is replaced at position 7 by We can remove two occurrences of ∅ from t, and we obtain the term t := miv a 1 (miv b 2 ( -→ ab 4 3 miv c 5 ( -→ cb 9 8 miv a 10 (miv d 11 (∅ 12 )))))

with the same witness w (but, to obtain the correct positions, one must subtract 2 from the numbers 8 to 12). Note that the positions marked 1,2,5,10,11 in t correspond (by the simple witness) to vertices, and the positions marked 4 and 9 to edges. The positions marked 3, 8 and 12, which are occurrences of and ∅, describe no vertex or edge of G.

One more remark: If in term s we replace the constant symbol -→ ab by ∅, then, clearly, the corresponding edge disappears, but also its end vertex x, which may be undesired. This is so because x and its incident edge are specified by the same symbol -→ ab. If we do this replacement in the term t (or in t ), then vertex x remains because it is specified by the first occurrence of miv a .

More generally, the terms t in T (F HRd

C

) specify the vertices of the graphs they define by unary operations and the edges by constant symbols: if, in such a term, we replace by ∅ some constant symbols, we delete the corresponding edges, but we delete no vertices. This remark will be useful for Proposition 6.50.

The CMS properties of directed graphs G are expressed by sentences of CMS ({edg}, ∅) interpreted in the structures G . Their CMS 2 properties are expressed by sentences of CMS ({in 1 , in 2 }, ∅) interpreted in the structures G = Inc(G) , cf. Section 5.2.5. We recall that edg G (x 1 , x 2 ) holds if and only if in 1 G (x 3 , x 1 ) and in 2 G (x 3 , x 2 ) hold for some element x 3 (that is necessarily an edge of G).

Let t be a term in T (F HR C ). For building automata associated with the CMS 2 formulas expressing properties of the concrete graph G := c val (t) (cf. Definition 6.44), we need to encode in t the assignments γ :

X n → P(V G ∪ E G ). We let F HRd(n) C
be the signature obtained from F HRd C by replacing the symbols miv a , -→ ab and a respectively by (miv a , w), ( -→ ab, w) and (a , w), for all w ∈ {0, 1} n , of the same arity. For t in T (F HRd C ) and γ : X n → P(Occ 0 (t) ∪ Occ 1 (t)) we define t * γ to be the term in T (F

HRd(n) C ) obtained from t by replacing f by (f, w γ (u)) at each occurrence u of f = miv a , f = -→ ab or f = a . Every term in T (F HRd(n) C
) is of the form t * γ. Note that, in general, γ is an assignment :

X n → P(Int G ∪ E G ) where G is the concrete s-graph c val (t). If ϕ ∈ CMS ({in 1 , in 2 }, X n ), we let L HR C,ϕ,n be the set of terms t * γ in T (F HRd(n) C
) ∅ such that ( c val (t) , γ) |= ϕ. Our objective is to construct an automaton C C,ϕ,n recognizing this set in the following sense:

L HR C,ϕ,n = L(C C,ϕ,n ) ∩ T (F HRd(n) C ) ∅ .
Note that C C,ϕ,n is not determined in a unique way by this equality. This condition is sufficient because we can assume that only terms in T (F

HRd(n) C
) ∅ will be given as input to C C,ϕ,n . However, the language T (F

HRd(n) C
) ∅ is recognized by an automaton with 2 k states, where k = |C|. Hence, any automaton C C,ϕ,n as above with N states can be replaced by an automaton with 2 k • N states that recognizes L HR C,ϕ,n . Moreover, in the special case where ϕ is a sentence, it follows from Proposition 6.45(3) that C C,ϕ,0 can be transformed into an automaton with 2 k • N states that recognizes the set of terms t in T (F HRd

C

) ∅ such that val (t) |= ϕ.

We now present the inductive construction of the automata

C C,ϕ,n . It is not hard to check that if L HR C,ϕ,n = L(C C,ϕ,n ) ∩ T (F HRd(n) C ) ∅ and L HR C,ψ,n = L(C C,ψ,n ) ∩ T (F HRd(n) C
) ∅ , then:

L HR C,ϕ∨ψ,n = (L(C C,ϕ,n ) ∪ L(C C,ψ,n )) ∩ T (F HRd(n) C ) ∅ , L HR C,ϕ∧ψ,n = L(C C,ϕ,n ) ∩ L(C C,ψ,n ) ∩ T (F HRd(n) C
) ∅ and

L HR C,¬ϕ,n = (T (F HRd(n) C ) -L(C C,ϕ,n )) ∩ T (F HRd(n) C ) ∅ .
If θ is ϕ σ where σ is a substitution of variables or of Boolean set terms (cf. Lemmas 6. 25 and 6.33), that transforms

ϕ ∈ CMS ({in 1 , in 2 }, X n ) into ϕ σ ∈ CMS ({in 1 , in 2 }, X m ), then L HR C,θ,m = h -1 σ (L(C C,ϕ,n )) ∩ T (F HRd(m) C ) ∅
where h σ is defined in these lemmas, extended to an arity preserving mapping :

F HRd(m) C → F HRd(n) C
in the obvious way (cf. Section 6.3.4). If θ is ∃X n+1 , . . . , X m . ϕ, then

L HR C,θ,n = h(L(C C,ϕ,m )) ∩ T (F HRd(n) C ) ∅
where h : F

HRd(m) C → F HRd(n) C
deletes the last m-n Booleans from each symbol that encodes an assignment. The last two equalities hold because τ (h σ (t)) = τ (t) for every term t ∈ T (F

HRd(m) C
) and similarly for h. Hence, we need only construct automata for the atomic formulas. The other constructions, that use products and direct or inverse images of automata, are similar or identical to those of Sections 6.3.3 and 6.3.4. Construction 6.47 (Incidence relations) Our aim is to construct, for each finite set C of source labels, a complete and deterministic F HRd(2) C -automaton C C,in1(X1,X2) that recognizes (in the above particular sense) the language L HR C,in1(X1,X2) . 28 As set of states, we take Q := C ∪ {0, Ok , Error } of cardinality k + 3 and Ok as accepting state. The meanings of the states are described in Table 6.13. Although the automaton to be constructed will have to operate on terms t ∈ T (F

HRd(2) C
) of type τ (t) = ∅, the meanings of its states must be specified with respect to terms of all types. We will use the same convention as before regarding X 1 and X 2 . The vertices and edges of the concrete graph c val (t) (for τ (t) = ∅) are nodes of t (cf. Definition 6.44). An edge e of c val (t) is a leaf and its ends x and y are both on the path between the root and the leaf e. Hence, the ends of an edge of c val (t) are above this edge in t; for τ (t) = ∅, x and y can be in τ (t): the set of sources of c val (t). When the properties P q are formulated (equivalently) for a node u of t, c val (t) must be replaced in Table 6.13 by G(u), as defined in Definition 6.44, i.e., P q should be satisfied in ( G(u) C , γ(X 1 ) ∩ (N t /u), γ(X 2 ) ∩ (N t /u)).

State q

Property P q

0 X 1 = X 2 = ∅ Ok X 1 = {e}, X 2 = {v} for some e ∈ E c val(t) , where v ∈ Int c val(t) and v is the tail of e a X 2 = ∅, X 1 = {e} for some e ∈ E c val(t)
such that the tail of e is the a-source of c val (t)

Error all other cases Table 6.13: Meanings of the states of C C,in1(X1,X2) .

28 We write L HR C,ϕ instead of L HR C,ϕ,mfv (ϕ) and similarily for C C,ϕ .

Table 6.14 shows its transition rules. The construction of C C,in2(X1,X2) is of course similar.

Transition rules

Conditions

∅ → 0 ( -→ ab, 00) → 0 ( -→ ab, 10) → a (a , 00) → 0 (a , 10) → a (miv a , 00)[q] → q q ∈ Q (miv a , 01)[a] → Ok a ∈ C ren h [0] → 0 ren h [Ok] → Ok ren h [a] → h(a) a ∈ C [0, q] → q [q, 0] → q q ∈ Q Table 6.14: Transition rules of C C,in1(X1,X2) .
The automata for the other atomic formulas are similar to this one or to those of Section 6.3.4. As for terms and graphs in Sections 6.3.3 and 6.3.4, it may be useful to precompile automata for frequently used properties. We now give some examples. Construction 6.48 (Precompiled automata)

(1) Let Vertices(X) and Edges(X) mean respectively that X is a set of vertices and that X is a set of edges. These first-order set predicates can be useful for shortening the writing of CMS 2 formulas. Complete and deterministic automata for them, that have 2 states, are straightforward to construct.

(2) We now consider the construction of C C,edg(X1,X2) . We have:

edg(X 1 , X 2 ) :⇐⇒ ∃X 3 (in 1 (X 3 , X 1 ) ∧ in 2 (X 3 , X 2 )).
It follows that by using inverse images, product and direct image, we can get a nondeterministic automaton with (k + 3) 2 states, hence a deterministic one having 2 (k+3) 2 states (before trimming). We could construct a deterministic automaton with less states. Rather than doing it, we show that every deterministic automaton must have at least 2 k(k-1) states. Hence, a specific construction would not be very useful. ) defined as the composition (in any order) of the unary operations (miv a , 10), (miv b , 01) and (miv d , 00) for every d ∈ C -{a, b}. We have c a,b [ R] ∈ L HR C,edg(X1,X2) if and only if (a, b) ∈ R. This shows that every complete and deterministic automaton recognizing L HR C,edg(X1,X2) must "know" R exactly after having traversed from bottom-up a term R. Hence, it must have at least 2 k(k-1) different states.

(3) Next we consider subgraphs and induced subgraphs. Let G be an s-graph and X be a subset of V G ∪ E G . The property Sub(X) is defined by: every edge in X has its (possibly equal) ends in X, i.e., it means that G has a subgraph H such that V H = V G ∩ X and E H = E G ∩ X (cf. Definitions 2.12 and 2.25; its sources are those of G that are in X). Furthermore, we denote by Src G (X) the set of sources of G that are end vertices of edges in X. We define an F HRd( 1) C -automaton C C,Sub(X1) having the states Error and A for all subsets A of C. Their meanings for a term t are as follows (with the same notation as in Table 6.13):

P A : Sub(X 1 ∪ Src c val(t) (X 1 )
) is true and A = Src c val(t) (X 1 ), P Error : Sub(X 1 ∪ Src c val(t) (X 1 )) is false, i.e., some edge in X 1 has an end that is an internal vertex of c val (t) not in X 1 .

The condition on A is meaningful because each element a of τ (t) is the a-source of the concrete s-graph c val (t) (cf. Definition 6.44). The accepting state is ∅. Table 6.15 shows the transition rules.

We now construct the more complicated automaton for the property Ind (X) defined as follows, for an s-graph G and a subset X of V G ∪ E G :

X is the set of edges and vertices of an induced subgraph of G (cf. Definition 2.12), i.e., Sub(X) holds and every edge of G having its ends in X is in X.

The latter requirement is equivalent to

NoEdge((V G ∩ X) ∪ (E G -X))
, where, for an s-graph G and a subset X of V G ∪ E G , the property NoEdge(X) means: no edge in X has its ends in X.

We first construct the automaton C C,NoEdge(X1) . Its states are Error and the triples (A, B, R) such that A, B ⊆ C and R is a set consisting of subsets of C of cardinality 2. This automaton has 2 2k+k(k-1)/2 + 1 states whose meanings are as follows:

P Error : some edge in X 1 has its two (possibly equal) ends in X 1 .

P (A,B,R) is the conjunction of four conditions : Transition rules Conditions ∅ → ∅ ( -→ ab, 0) → ∅ ( -→ ab, 1) → {a, b} (a , 0) → ∅ (a , 1) → {a} (miv a , 0)[A] → A a / ∈ A (miv a , 1)[A] → A -{a} ren h [A] → h(A) [A, B] → A ∪ B
Table 6.15: Transition rules of C C,Sub(X1) .

(1) P Error does not hold,

(2) The accepting state is (∅, ∅, ∅). Table 6.16 shows the transitions.

A = {a ∈ τ (t) | a is the vertex incident with a loop of c val (t) that belongs to X 1 }, (3)
For obtaining C C,Ind(X1) , we let h be the mapping F

HRd(1) C → F HRd(1) C
such that, for every a, b ∈ C and i ∈ {0, 1}: h(( -→ ab, i)) := ( -→ ab, 1 -i) and h((a , i)) := (a , 1 -i), and that does not modify the other symbols. It is clear (cf. Lemma 6.33 on substitutions of Boolean set terms) that:

L HR C,Ind(X1) = L HR C,Sub(X1) ∩ h -1 (L HR C,NoEdge(X1) ),
so that we obtain easily C C,Ind(X1) as a product of C C,Sub(X1) and an inverse image of C C,NoEdge(X1) . It has 2 3k+k(k-1)/2 + 1 states.

Construction 6.49 (Relativizations)

We now show that relativizations can be obtained along the lines of Construction 6.37, with some more technical details. We consider a property P (X 1 , . . . , X n ) of sets of edges and vertices. We let Q(X 1 , . . . , X n+1 ) be the property such that, for all sets of edges and vertices X 1 , . . . , X n+1 of a graph G (without sources), the set X n+1 satisfies Sub(X n+1 ), hence defines a subgraph H of G, and P (X 1 ∩X n+1 , . . . , X n ∩X n+1 ) is true in H. We will construct an automaton

Transition rules Conditions

∅ → (∅, ∅, ∅)

( -→ ab, 0) → (∅, ∅, ∅) ( -→ ab, 1) → (∅, ∅, {{a, b}}) (a , 0) → (∅, ∅, ∅) (a , 1) → ({a}, ∅, ∅) (miv a , 0)[(A, B, R)] → (A , B , R ) A = A -{a}, B = B -{a}, R is R without the pairs containing a (miv a , 1)[(A, B, R)] → (A, B , R ) a / ∈ A ∪ B, B = B ∪ {b | {a, b} ∈ R}, R is R without the pairs containing a ren h [(A, B, R)] → (h(A), h(B), h(R)) [(A, B, R), (A , B , R )] → (A , B , R ) A = A ∪ A , B = B ∪ B , R = R ∪ R Table 6.16: Transition rules of C C,NoEdge(X1) .
C C,Q(X1,...,Xn+1) from C C,P (X1,...,Xn) with the help of the automaton C C,Sub(X1) of Construction 6.48(3). We let h be the mapping :

F HRd(n+1) C → F HR(n) C
such that, for every a, b ∈ C with a = b and every w ∈ {0, 1} n :

h(( -→ ab, w0)) := ∅, h(( -→ ab, w1)) := ( -→ ab, w), h((a , w0)) := ∅, h((a , w1))
:= (a , w), h((miv a , w0)) := ren Id (where Id is the identity : C → C) and h((miv a , w1)) := (miv a , w).

The other symbols are not modified by h. We use the "neutral" constant symbol ∅ in order to replace the constant symbols that specify the deleted edges, and the "neutral" unary symbol ren Id (denoting the identity operation) in order to replace the unary symbols (miv a , w0) that specify the deleted vertices. We let also h : F

HRd(n+1) C → F HR(1) C
delete the first n Booleans of each sequence. With these definitions and notation we have:

Proposition 6.50 L HR C,Q(X1,...,Xn+1) = L HR C,Sub(Xn+1) ∩ h -1 (L HR C,P (X1,...,Xn) ) and thus C C,Q(X1,...,Xn+1) can be defined as h -1 (C C,Sub(X1) ) ∩ h -1 (C C,P (X1,...,Xn) ).
Similar facts hold for induced subgraphs, with Ind (X n+1 ) instead of Sub(X n+1 ).

Proof: The proof is similar to that of Lemma 6.38 except that we must take into account that X n+1 defines a subgraph. Claim 6.50.1 Let t ∈ T (F HRd

C

) ∅ , G := c val (t) and H be a subgraph of G. Let U := V H ∪ E H , so that Sub(U ) holds in G. Then H = c val (h(t * γ)), where γ is the X 1 -assignment such that γ(X 1 ) = U . Proof: Let t := h(t * γ) and H := c val (t ). Note that G, H and H are concrete graphs with vertices and edges belonging to N t = N t by the definitions. It is clear that H and H have the same edges (i.e., E H = E H , but we will verify that the incidences are the same) and the same internal vertices.

Let us check that the incidences in H and H are the same. Let e be an edge of H brought in by an occurrence u (in U ) of a constant symbol -→ ab or a . Its tail x in H (introduced as the a-source in the corresponding basic graphs) is made internal by some operation miv c , precisely at occurrence x. Some renamings on the path in t between u and x have transformed a into c. These renamings are not modified by h. Let y be the tail of e in H. If y = x, then y is an occurrence (below x) of some operation miv d that has been changed into ren Id by h. But this implies that y is not in U whereas it is the tail of the edge e ∈ U . This contradicts the fact that H is a subgraph of G. Hence y = x. The same argument works for the heads of the edges of H .

Since the incidences in H and H are the same, all edges of H are incident with internal vertices of H . Thus, H has no sources (because sources of any c val (t ) cannot be isolated). Hence H has the same vertices as H, and so H = H. This proves the claim.

We now prove the proposition. Let t * γ belong to T (F

HRd(n+1) C
) ∅ and G := c val(t). Moreover, let γ(X n+1 ) be the set of vertices and edges of a subgraph H of G, i.e., let t * γ belong to L HR C,Sub(Xn+1) . Then h(t * γ) = t * γ , where c val (t ) = H (by the claim) and γ is the assignment :

X n → P(E H ∪ V H ) such that γ (X i ) = γ(X i )∩γ(X n+1 ) for each i. It follows that t * γ ∈ L HR C,Q(X1,...,Xn+1) if and only if t * γ ∈ L VR C,P (X1,...,Xn) . Hence L HR C,Q(X1,...,Xn+1) = L HR C,Sub(Xn+1) ∩ h -1 (L HR
C,P (X1,...,Xn) ). The assertion about automata follows immediately. The proof is the same for induced subgraphs. Remark 6.51 (Labelled graphs with sources) We adapt the above definitions to (K, Λ)-labelled graphs. We will use the constant symbols -→ ab λ and a λ for defining directed edges and loops labelled by λ ∈ Λ, and, for a ∈ C and α = {κ 1 , . . . , κ p } ⊆ K, the derived operations miv a,α defined by:

miv a,α (G) := fg a (a κ1 • • • a κp G). We get a signature F HRd C,[K,Λ] . Note that for a term t in T (F HRd C,[K,Λ]
) the sources of val (t) do not have labels in K.

Proposition 6.45 can be extended to labelled graphs. In the proof of Statement (2), the desired term t is obtained by replacing in s 1 every occurrence of a constant symbol a by ∅, and every occurrence u of an operation symbol fg a by miv a,α where α is the set of labels of the a-source of val (s 1 /u 1 ) and u 1 is the son of u. In the proof of Statement (3), the automaton B has states (A, α, q) where α is a mapping : A → P(K). For input term s, it computes the set of labels α(a) ⊆ K of each a-source of val (s). Thus, B has (2 |K| + 1) |C| • N states. Constructions 6.47, 6.48 and 6.49 extend in a straightforward manner to the construction of automata for checking CMS 2 properties of (K, Λ)-labelled graphs of bounded tree-width. They yield fixed-parameter linear model-checking algorithms with respect to tree-width because the parsing problem is not more difficult for labelled graphs than for unlabelled ones, as we have observed in the proof of Theorem 6.4(1), cf. Proposition 2.47(2).

For checking properties of (K, Λ)-labelled s-graphs, we convert source names into vertex labels. If C is a finite set of source names, we let C := {a | a ∈ C} be a set of vertex labels disjoint from K ∪ Λ and from the set A of source names.

Every (K, Λ)-labelled s-graph G of type A = {a 1 , . . . , a s } ⊆ C, defined by a term t ∈ T (F HRd C,[K,Λ] ), is converted into the (C ∪ K, Λ)-labelled graph G defined by the term miv a1,{a1}∪α1 (• • • (miv as,{as}∪αs (t) • • • )),
where α i is the set of vertex labels of the a i -source of G. It is then routine work to transform a CMS 2 sentence expressing a property of G, to be interpreted in G C , into one that expresses the same property of G, to be interpreted in G . Hence, all constructions done in this section and the associated algorithms extend to (K, Λ)-labelled s-graphs of bounded tree-width.

We conclude this section by observing that the constructions of automata for checking properties of graphs of bounded tree-width are more complicated than those for graphs of bounded clique-width (developed in Section 6.3.4). For graphs of bounded path-width (and also for larger classes as shown in [START_REF] Courcelle | On the model-checking of monadic second-order formulas with edge set quantifications[END_REF]), the constructions of Section 6.3.4 can be adapted to the model-checking of CMS 2 properties as explained in the introduction of this section.

Other monadic second-order problems solved with automata

In the previous section, we have constructed automata for solving model-checking problems. We will show how these constructions can be used or adapted for solving related algorithmic problems. Whereas model-checking problems concern properties specified by monadic second-order sentences, the problems considered in this section will be specified by monadic second-order formulas with free variables.

Property-checking problems

Let R be a relational signature without constant symbols and ϕ be a formula in CMS(R, X, z), where X = (X 1 , . . . , X n ) and z = (z 1 , . . . , z m ). We define new unary relations P 1 , . . . , P n and Q 1 , . . . , Q m intended to represent γ(X 1 ), . . . , γ(X n ) and {γ(z 1 )}, . . . , {γ(z m )} respectively for some (X ∪z)-assignment γ in an R-structure. We let P := {P 1 , . . . , P n , Q 1 , . . . , Q m } and we transform the formula ϕ into a sentence ϕ ∈ CMS(R ∪ P, ∅) as follows. Without loss of generality, we assume that X 1 , . . . , X n , z 1 , . . . , z m have no bound occurrence in ϕ.

Step 1, concerning X 1 , . . . , X n . We replace every atomic formula of the form x ∈ X i by P i (x) (where x is some z j or some bound first-order variable) and every atomic formula Card p,q (X i ) by ∃ X(Card p,q (X) ∧ ∀x(P i (x) ⇔ x ∈ X)).

Step 2, concerning z 1 , . . . , z m . We replace every atomic formula θ having among its free variables z i1 , . . . , z is , listed in such a way that 1

≤ i 1 < i 2 < • • • < i s ≤ m, by the formula ∃ z i1 , . . . , z is (Q i1 (z i1 ) ∧ • • • ∧ Q is (z is ) ∧ θ).
The first-order variables not in z are not modified by this transformation.

We obtain a sentence ϕ (the variables X 1 , . . . , X n , z 1 , . . . , z m are no longer free). We let then ϕ be

ϕ ∧ 1≤i≤m ∃ x(Q i (x) ∧ ∀y(Q i (y) ⇒ y = x)).
The quantifier-height of ϕ is larger than that of ϕ by a constant at most max{2, ρ(R)}. It has first-order variables that can be eliminated by Lemma 6.17 (Section 6.3.2). With these definitions and notation, we have: Lemma 6.52 For every concrete R-structure S and every (X ∪ z)-assignment γ in S we have:

(S, γ) |= ϕ if and only if S + γ |= ϕ
where S + γ is the (R ∪ P)-structure that expands S by γ(X i ) as interpretation of P i and {γ(z j )} as interpretation of Q j for i = 1, . . . , n and j = 1, . . . , m.

The validity of this lemma is clear from the construction. We now apply the lemma to terms and graphs.

If S = t for a term t, then γ specifies nodes and sets of nodes of its syntactic tree and S + γ is equivalent to t * γ (this technical point will be discussed in Chapter 7, Definition 7.20). Sentences over S + γ are translatable into equivalent sentences over t * γ (and vice-versa).

For the application to graphs, there are two cases. If S = G , then γ specifies vertices and sets of vertices. Then, S + γ = G where G is obtained from G by attaching new labels to its vertices. The corresponding transformation of terms in T (F VR ) is easy (cf. Proposition 2.100): we need only modify certain constant symbols. If S = G , then γ specifies vertices, edges and sets thereof. Then, S + γ = G where G is obtained from G by attaching new labels to its vertices and to its edges29 . The corresponding transformation of terms in T (F HR ) is also easy (cf. Proposition 2.47(2)). In both cases, we need not perform another parsing of the given graph G and the corresponding transformations of terms can be done in linear time.

Hence, Theorems 6.3 and 6.4 extend to the corresponding property-checking problems. The sizes of the data include those of the input assignment γ, defined by γ := m + n + Σ j∈[n] |γ(X j )|, and the verification that γ satisfies a given monadic second-order formula can be done within the same time bounds. The size of γ is at most m + n • |D S |, hence it is at most linear in the number of elements of the considered structure S.

The above proof of the extension of Theorems 6.3 and 6.4 to propertychecking is based on Lemma 6.52 and Theorems 6.3 and 6.4. Alternatively, we can use the automata constructed in the previous sections. Let ϕ be a formula in CMS

(R F , X n ). Then ( t , γ) |= ϕ if and only if t * γ ∈ L ϕ,n . Now let ϕ be a formula in CMS (R s,C , X n ), let t be a term in T (F VR C ) such that G val (t) and let w be a witness of that. Then ( G C , γ) |= ϕ if and only if t * γ ∈ L VR C,ϕ,n , where γ (X i ) := w(γ(X i )) for i ∈ [n]. Similarly, if ϕ is a formula in CMS (R m , X n ) and t is a term in T (F HRd C ) ∅ such that G val (t) with simple witness w, then ( G , γ) |= ϕ if and only if t * γ ∈ L HR C,ϕ,n
, with the same definition of γ .

Listing and selection problems for monadic secondorder queries

Definition 6.53 (Listing and selection problems)

The listing problem consists in computing the set sat(S, ϕ, (X 1 , . . . , X n )) ⊆ P(D S ) n for a given concrete R-structure S and a given formula ϕ in CMS (R, X n ).

In this context, the formula ϕ is also called a query.

The size of the output A = sat(S, ϕ, (X 1 , . . . , X n )) is defined as

A := (U1,...,Un)∈A (n + |U 1 | + • • • + |U n |)
and must be distinguished from its cardinality |A|. It can be exponential in

|D S |. However, we have ||A|| ≤ n • |A| • (1 + |D S |
). An algorithm for a listing problem will be said to operate in linear time if its computation time is linear in the size of the input plus the size of the output.

The selection problem consists in computing one n-tuple belonging to the set sat(S, ϕ, (X 1 , . . . , X n )) for a given concrete R-structure S and a given formula ϕ in CMS (R, X n ), or in reporting that this set is empty. The size of the output is at most n • (1 + |D S |), hence, the evaluation of the time taken by an algorithm for this problem will be done in terms of the size of the input, as usual.

We first present algorithms for these problems in the case of monadic secondorder queries on terms. These algorithms operate in linear time. We let F be a finite functional signature, ϕ be a formula in CMS (R F , X n ) and A be the associated complete and deterministic F (n) -automaton A ϕ,n that recognizes L ϕ,n . We let h : F (n) → F be the arity preserving mapping that deletes the Booleans of the symbols in F (n) . Note that N h(s) = N s for every s ∈ T (F (n) ). Let t ∈ T (F ). By the definitions of Section 6.3.3, an n-tuple (U 1 , . . . , U n ) of subsets of N t belongs to sat( t , ϕ, (X 1 , . . . , X n )) if and only if there is a term s in L(A , q) ⊆ T (F (n) ) such that h(s) = t, q is an accepting state and, for each i ∈ [n], U i is the set of occurrences in s of a symbol (f, w) such that w[i] = 1.

The following definitions generalize this fact. Instead of F (n) , we take an arbitrary finite functional signature H and an arity preserving mapping h : H → F . We let A be a complete and deterministic H-automaton. We let J be an n-tuple (J 1 , . . . , J n ) of subsets of H. For every s ∈ T (H), we let

N J (s) denote the n-tuple (U 1 , . . . , U n ) of subsets of N s such that U i := {v ∈ N s | lab s (v) ∈ J i } (in other words, U i is the set of occurrences v of symbols in J i ). More generally, if u ∈ N s , we let N J (s)/u denote the n-tuple (U 1 , . . . , U n ) of subsets of N s /u such that U i := {v ∈ N s | v ≤ s u and lab s (v) ∈ J i } (it is the set of occurrences v of symbols in J i that are below u).
For t ∈ T (F ), u ∈ N t and q ∈ Q A , we let:

sat J (u, q) := {N J (s)/u | s ∈ h -1 (t) ∩ L(A , q)}
and for P ⊆ Q A , we let:

sat J (u, P ) := λq ∈ P • sat J (u, q).
Finally, we let:

sat J (t) := {sat J (root t , q) | q ∈ Acc A },
and we have:

sat J (t) = {N J (s) | s ∈ h -1 (t) ∩ L(A )}.
For q = q , the sets sat J (u, q) and sat J (u, q ) are disjoint, because the automaton A is deterministic, hence the union in the definition of sat J (t) is a disjoint union. Since N h(s) = N s for every s ∈ T (H), the set sat J (u, q) consists of tuples (U 1 , . . . , U n ) with U i ⊆ N t /u, and so sat J (t) ⊆ P(N t ) n . With these definitions and notations, we have the following proposition from [FluFG].

Proposition 6.54

(1) There is an algorithm that computes, for every term t in T (F ), the set

sat J (t) in time O(|t| + sat J (t) ).
(2) There is an algorithm that computes, for every term t in T (F ), some element of sat J (t), or reports that this set is empty, in time O(|t|).

Proof: For simplicity we assume that F and H only contain symbols of arity 0 and 2. The proofs extend easily to the general case.

(1) We first show that the mappings sat J (u, Q A ) can be computed by bottom-up induction on the node u. To do that, we recall the definition of the operation from Section 5.3.1 (after Proposition 5.37). Let D and D be disjoint sets.

If U = (U 1 , . . . , U n ) ∈ P(D) n and V = (V 1 , . . . , V n ) ∈ P(D ) n , then U V is the n-tuple (U 1 ∪ V 1 , . . . , U n ∪ V n ). (In this case,
is nothing but componentwise disjoint union.) For A ⊆ P(D) n and B ⊆ P(D ) n , we have defined

A B as {U V | U ∈ A, V ∈ B}. Note that A B = ∅ if and only if A = ∅ or B = ∅.
For a node u of t that is an occurrence of f ∈ F 2 , with sons u 1 and u 2 , we have:

sat J (u, q) = {U J,f sat J (u 1 , q 1 ) sat J (u 2 , q 2 ) | h(f ) = f, f [q 1 , q 2 ] → A q} (6.3) where U J,f is the singleton {(U 1 , . . . , U n )} such that U i = {u} if f ∈ J i and U i = ∅ if f / ∈ J i .
For a node u that is an occurrence of f ∈ F 0 (hence is a leaf), we have:

sat J (u, q) = {U J,f | h(f ) = f, f → A q}.
(6.4)

These equalities show that the mappings sat J (u, Q A ) (for all u ∈ N t ) can be computed bottom-up. It remains to prove that the set sat J (t) can be computed in linear time. Since sat J (t) is the union of the sets sat J (root t , q) for q ∈ Acc A , it suffices to prove that the mapping sat J (root t , Acc A ) can be computed in linear time. We will use two ideas:

(a) to compute only those (nonempty) sets sat J (u, q) that are needed for the computation of some (nonempty) set sat J (root t , p) for some p ∈ Acc A , and

(b) to compute A B in an efficient way.

First we discuss (a). For t ∈ T (F ) and u ∈ N t , we define call (u) ⊆ Q A by the following top-down induction on the syntactic tree of t:

(i) for the root of t, we define call (root t ) as the set of all accepting states q of A such that sat J (root t , q) = ∅;

(ii) for a node u of t that is an occurrence of some f ∈ F 2 , with sons u 1 and u 2 , we define call (u 1 ) as the set of states p of A for which there exist states q 1 and q 2 , a symbol f in h -1 (f ) and a state q ∈ call (u) such that p = q 1 , f [q 1 , q 2 ] → A q and sat J (u i , q i ) = ∅ for i = 1 and i = 2; we define similarly call (u 2 ) with the condition p = q 2 instead of p = q 1 . Equalities (6.3) and (6.4) form a recursive definition of the sets sat J (u, q). We can see that call (u) consists of all states q such that the nonempty set sat J (u, q) is called during the recursive computation of some nonempty set sat J (root t , p) with p ∈ Acc A . Thus, in order to compute the set sat J (t), it suffices to compute the mappings sat J (u, call (u)) for all nodes u. Let us abbreviate sat J (u, call (u)) into sat(u). Thus,

sat(u) = λq ∈ call (u) • sat J (u, q).
Note that, for an occurrence u of f ∈ F 2 with sons u 1 and u 2 , the mapping sat(u) can be computed from the mappings sat(u 1 ) and sat(u 2 ) by using Equality (6.3); moreover, each set sat J (u i , q i ) with q i ∈ call (u i ) is needed in the computation of some set sat J (u, q) with q ∈ call (u).

Since sat J (u, q) = ∅ if and only if A ,h -1 (t/u, q) = 0, we can use Proposition 6.12 to determine, for all u and q, which of the sets sat J (u, q) are nonempty. We use for that a bottom-up computation30 on t that takes linear time. From this preliminary computation and the definition of call (u), we can compute all sets call (u) in linear time by a top-down computation on t. Finally, the mappings sat(u) = sat J (u, call (u)) can be computed by a bottom-up computation on t. It remains to prove that this computation can be done in linear time too.

Second we discuss (b). 31We first note that the union of two disjoint sets can be computed in constant time: just add the sets 32 . Now we consider the computation of A B, for nonempty sets A ⊆ P(D) n and B ⊆ P(D ) n such that D ∩ D = ∅. When computing U V , for U ∈ A and V ∈ B, we make a copy of both U and V (in time U + V = U V + n) and compute their componentwise union (in constant time). However, when U is used for the last time we do not copy U but we use U itself, and similarly for V . In this way A B is computed in time A similar argument holds for arbitrary expressions that are written with the operations and . As an example, we can compute

O(1 + 2n • |A B| + A B 0 -A 0 -B 0 ), where A 0 := Σ (U1,...,Un)∈A (|U 1 | + • • • + |U n |), i.e., A = A 0 + n • |A|. It is straightforward to show that this is O(1 + A B 0 -A 0 -B 0 ), provided A 0 = 0 and B 0 = 0. 33 If A 0 = 0, i.e., A is the singleton {(∅, . . . , ∅)}, then A B = B (and similarly, if B 0 = 0 then A B = A). Hence, A B can be computed in time O(1 + A B 0 -A 0 -B 0 ),
E = (A B) (A C) in time O(1 + E 0 -A 0 -B 0 -C 0 )
: first we make a copy A of A (in time A ), and then we compute A B and A C as indicated above. From this fact it is clear that, for every node u with sons u 1 and u 2 , we can compute sat(u) from sat(u 1 ) and sat(u 2 ) in time O(1 + sat(u) 0 -sat(u 1 ) 0 -sat(u 2 ) 0 ), where sat(u) 0 is defined as q∈call(u) sat J (u, q) 0 . Since sat(u) can be computed in constant time for a leaf u, this shows that the set sat(root t ) can be computed in time O(|t| + sat(root t ) 0 ), and hence that the set sat J (t) can be computed in time

O(|t| + sat J (t) 0 ), which is O(|t| + sat J (t) ).
(2) We use an easy variant of the proof of [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. Instead of computing all tuples of sat J (u, q), q ∈ call (u), we compute only one of them. For each u this computation takes constant time, because for tuples U and V the tuple U V can be computed in constant time.

The method of [FluFG] used in the above proof is based on the direct translation of CMS formulas into automata described in Sections 6.3.3-6.3.5. An important ingredient is the efficient use of the operation . This operation arises in the statement of the Splitting Theorem and also when, as above, we compute the sets sat( t , ϕ, (X 1 , . . . , X n )) with automata.

In Definition 6.1, fixed-parameter tractable algorithms are for decision problems, hence, they output only True or False. For the next theorem, we extend the definition by requiring that the computation time is bounded, for every input d with corresponding output e, by an expression of the form f (p(d))

• (|d| c + |e|)
where f is a fixed computable function, c is a fixed positive integer and |e| is an appropriate notion of size for e. Note that this size may be exponentially larger than |d| for the listing problem. This is not the case for the selection problem, and the computation time can be bounded by f (p(d)) • |d| c as in Definition 6.1. If c is 1 (or 3), we say that the algorithm is fixed-parameter linear (or cubic respectively).

Theorem 6.55

(1) There exist fixed-parameter linear algorithms for solving the monadic second-order listing and selection problems on terms. The parameter is (F, ϕ) where the given term is in T (F ) and the given formula is ϕ.

(2) There exist fixed-parameter cubic algorithms for solving the listing and selection problems for simple (K, Λ)-labelled graphs and CMS queries.

The parameter is (cwd (G), ϕ) where the given (K, Λ)-labelled graph is G and the given formula is ϕ. The size of the input graph is its number of vertices.

(3) There exist fixed-parameter linear algorithms for solving the listing and selection problems for (K, Λ)-labelled graphs and CMS 2 queries. The parameter is (twd (G), ϕ) where the given (K, Λ)-labelled graph is G and the given formula is ϕ. The size of the input graph G is G .

Proof: (1) Let ϕ be a formula in CMS (R F , X n ). We apply Proposition 6.54 by letting H := F (n) , h be the arity preserving mapping :

F (n) → F that deletes the Booleans, J := (J 1 , . . . , J n ) with J i := {(f, (w 1 , . . . , w n )) ∈ H | w i = 1}
, and A be the complete and deterministic

F (n) -automaton A ϕ,n that recognizes L ϕ,n (as constructed in Section 6.3.3). Then sat( t , ϕ, (X 1 , . . . , X n )) = {N J (s) | s ∈ h -1 (t) ∩ L(A )} = sat J (t).
(2) and ( 3): the proofs are similar, with the constructions in Sections 6.3.4 and 6.3.5 of automata recognizing L VR C,ϕ,n and L HR C,ϕ,n (cf. the last paragraph of Section 6.4.1). As shown in the proof of Theorem 6.4, C = [h Λ (G)] and C = [twd (G) + 1] respectively.

Monadic second-order counting and optimizing functions

Monadic second-order counting and optimizing functions have been defined in Definition 6.5. By using the counting and optimizing automata defined in Section 6.3.1, we can prove the following theorem. Detailed formulations are as for Theorem 6.55.

Theorem 6.56 Monadic second-order counting and optimization functions defined by CMS formulas can be computed by fixed-parameter linear algorithms on terms and by fixed-parameter cubic algorithms on graphs for clique-width as parameter. Such functions defined by CMS 2 formulas can be computed by fixed-parameter linear algorithms on graphs for tree-width as parameter.

Proof: We first consider the evaluation of counting functions on syntactic trees of terms in T (F ). Let ϕ be a formula in CMS (R F , X n ∪ {Y 1 , . . . , Y p }). We first assume that p = 0. We let H, h, J and A be as in the proof of Theorem 6.55 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF].

Then the integer sat( t , ϕ, (X 1 , . . . , X n )) to be computed is the cardinality of the set {N J (s) | s ∈ h -1 (t)∩L(A )}. Since N J (s) = N J (s ) for distinct elements s and s of h -1 (t), we obtain that:

sat( t , ϕ, (X 1 , . . . , X n )) = |h -1 (t) ∩ L(A )| = q∈Acc A A ,h -1 (t, q).
We can then apply Proposition 6.12. For the case of sat( t , ϕ, (X 1 , . . . , X n ), γ) where p > 0 and γ is an {Y 1 , . . . , Y p }-assignment in S := t , we apply this algorithm to S + γ, as we have done in Section 6.4.1.

For computing optimizing functions for terms, we also use Proposition 6.12. We use the same notation as above, with n = 1, and we write X for X 1 and J for J 1 = {(f, 1) | f ∈ F }. For p = 0 we obtain that:

Maxsat( t , ϕ, X) = max{|s| J | s ∈ h -1 (t) ∩ L(A )} = max{Max A ,h -1 ,J (t, q) | q ∈ Acc A }.
These proofs extend to graphs, as in the proof of Theorem 6.55(2,3).

The results of Theorems 6.55 and 6.56 for terms and graphs of bounded tree-width are proved in [CouMos] as consequences of the Splitting Theorem for n-ary QDP-QF operations (Theorem 5.57). This version of the theorem is needed for the graphs defined by the operations of the HR algebra because the parallel-composition fuses constants of its argument structures. Since the corresponding splitting is expressed in terms of disjoint unions, the cardinalities of the considered sets can be obtained by additions. More general evaluations are described in [CouMos]. They can also be implemented on top of deterministic automata, as in the proofs of Theorems 6.55 and 6.56.

Other algorithmic applications (1) Enumeration problems

An enumeration algorithm of a set A of the form sat(S, ϕ, (X 1 , . . . , X n )) outputs one by one and without repetition the elements of A. The listing algorithms of Theorem 6.55 are actually enumeration algorithms, but here, we are interested in the delay, that is, in the computation time between two outputs. An enumeration algorithm has linear delay if this time is linear in the size of the next output. Linear delay enumeration algorithms of sets sat( G , ϕ, (X 1 , . . . , X n )) for CMS formulas ϕ and graphs G of bounded clique-width are constructed in [Bag] and [START_REF] Courcelle | Linear delay enumeration and monadic second-order logic[END_REF]. Both algorithms are based on the automata constructed in Sections 6.3.3-6.3.5, but they need an additional step: the terms t that define the considered graphs G must be a-balanced, i.e., have height at most a•log(|V G |) for fixed a. We refer to [CouVan], [CouTwi] and [CouKan] for the transformations of terms in T (F HR C ) or in T (F VR C ) into a-balanced equivalent ones, for fixed values of a, but at the cost of using more source or port labels. These results give an alternative proof of Theorem 6.55.

(2) Reduction Every CMS-definable set of graphs of tree-width at most k (where k is known) can be recognized by reduction. This means that there exists a finite set of Noetherian graph rewriting rules and a finite set of accepting irreducible graphs. The input graph G is rewritten until an irreducible graph H is obtained. The graph G is recognized if and only if H is accepting. The graph G need not be of tree-width at most k, and need not be parsed. If its tree-width is more than k, some irreducible graph that is not accepting will be reached. A positive answer does not yield a tree-decomposition of the input graph.

This result gives different fixed-parameter linear graph algorithms for the problem considered in Theorem 6.4 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. The general theorem is proved in the article [ArnCPS] and the algorithm is improved in [BodvAnt].

(3) Labelling schemes A labelling scheme for checking a property P (X 1 , . . . , X n ) of sets of vertices X 1 , . . . , X n of the graphs of a fixed class consists of two algorithms A and B. Algorithm A attaches labels to the vertices of a given graph G of the class in such a way that the validity of P (X 1 , . . . , X n ) can be checked by algorithm B that takes as input the labels of the vertices of the elements of X 1 , . . . , X n (and nothing else from G). The objective is to use labels of size O(log(|V G |)).

The article [CouVan] gives a meta-theorem for constructing labelling schemes for checking monadic second-order properties P (X 1 , . . . , X n ) for graphs of bounded clique-width. It is based on the translation of monadic second-order formulas into automata described in Sections 6.3.3 and 6.3.4. The general construction involves huge constants. A direct and more efficient construction for a particular problem is done in [CouTwi]. The result of [CouVan] is also useful as an intermediate step of the construction of labelling schemes for graphs of unbounded clique-width: in particular, for the MS property Sep(u, v, X) that two vertices u and v of a planar graph are separated by a set of vertices X [CouGKT] and for first-order properties of certain graphs, that are locally of bounded clique-width [CouGK].

Optimality results

Let us look again at Theorem 6.4 that we restate in a simpler form as follows:34

Result 1: One can check in time f (ϕ, k) • n the validity of a CMS 2 sentence ϕ on a simple graph G with n vertices that belongs to any class C of tree-width at most k (for some fixed function f ).

Result 2: One can check in time g(ϕ, k) • n 3 the validity of a CMS sentence ϕ on a simple graph G with n vertices that belongs to any class C of clique-width at most k (for some fixed function g).

A natural question is whether and how one can improve these results. We will review three types of improvement.

(1) Alternative algorithms A significant improvement of Result 2 could come from the discovery of a better parsing algorithm for graphs of bounded clique-width (or rank-width), see Section 6.2.3. For fixed ϕ and k, Result 1 can be achieved in logarithmic space instead of linear time ( [ElbJT]; the proof does not extend to Result 2).

(2) More model-checking problems?

That is, can one treat more problems, by writing them in more powerful logical languages? The answer is yes: Results 1 and 2 can be extended to sentences of the form ∃X(α ∧ ϕ) where ϕ is a monadic second-order formula and α is a Boolean combination of arithmetical conditions like

|Y | < a • |Z| + b • |Z |
where a and b are real numbers and Y , Z and Z are variables from X. This extension follows from Theorem 6.55 (or rather from a modification of its proof) and has already been considered in [ArnLS], [CouMos] and [ElbJT] for graphs of bounded tree-width. The methods of [CouMos] and [ElbJT] work for graphs of bounded clique-width (see [Rao].

Some MS 2 problems that are not CMS-expressible can nevertheless be solved in time O(n f (k) ) for graphs of clique-width at most k ([Wan]), however, there is little hope to solve all MS 2 problems in polynomial time for graphs of cliquewidth 2: if NEXPTIME = NEXPTIME, then there exists an MS 2 problem that is not solvable in polynomial time on cliques ( [CouMakR]).

(3) Covering larger graph classes Several results limit the possibilities of expanding the classes covered by Result 1. The following is proved in [MakMar], under the assumption that P = NP: if every problem expressible by an existential MS sentence (i.e., a sentence written as a sequence of existential quantifications followed by a first-order formula) is solvable in polynomial time on a class of graphs C closed under taking minors, or even, under taking topological minors, then C has bounded tree-width.

For each positive number a, we denote by T W a the class of graphs G of tree-width at most log a (|V G |). Then, the following is proved in [KreTaz] under the Exponential Time Hypothesis: if a ≥ 29, then some MS 2 problems have no polynomial time algorithm on T W a .

The Exponential Time Hypothesis states that problem SAT cannot be solved in subexponential time, i.e. in time 2 o (n) .

Since there are also (unnatural) classes of graphs of unbounded clique-width (hence also of unbounded tree-width, that are even closed under taking subgraphs) for which every MS problem is solvable in polynomial time ( [MakMar]), results like these two ones cannot be proved for arbitrary graph classes. This fact can be contrasted with the result of [See91] saying that every class of graphs having a decidable MS 2 theory has bounded tree-width (see Theorem 7.55 for its proof).

Comparing some proofs of the Recognizability Theorem

Motivated by the practical construction of automata, we have given in Theorem 6.35 an alternative proof of the Weak Recognizability Theorem (Corollary 5.69) for the VR algebra (and similarly for the HR algebra in Section 6.3.5).

Let us raise a natural question: Does Theorem 6.35 give another proof of the Recognizability Theorem for the VR algebra (Theorem 5.68)?

The answer is no. Theorem 6.35 establishes that, for every CMS sentence ϕ, for each k the set of graphs {G | cwd (G) ≤ k and G |= ϕ} is recognizable in the subalgebra of GP consisting of the p-graphs that are the values of terms over VR [k] . This does not imply that L ϕ := {G | G |= ϕ} is VR-recognizable, as observed in Proposition 4.40 for the HR case (of which the proof is also valid for the VR case).

F
However, in [START_REF] Engelfriet | A regular characterization of graph languages definable in monadic second-order logic[END_REF] a description is given of MS-and MS 2 -definable sets of labelled graphs (of unbounded clique-width and tree-width) by certain regular expressions. These expressions use basic sets of graphs (corresponding to the atomic formulas of the considered sentences) that somehow generalize the local regular languages. They also use the Boolean operations on sets of graphs, corresponding to the Boolean connectives in formulas, relabellings (corresponding to existential quantifications, cf. Construction 6.29) and inverse relabellings (for handling substitutions of variables, cf. Lemma 6.25). The basic sets of graphs are recognizable (appropriate congruences are easy to define for proving that) and the operations on sets used in these regular expressions preserve recognizability. The case of relabellings needs some more work but can be proved with the technique used in [START_REF] Blumensath | Recognizability, hypergraph operations, and logical types[END_REF] (Proposition 58). One obtains in this way an alternative proof of the Recognizability Theorem. After working out the details, the reader will decide if it is simpler or not than the one in Chapter 5, based on the Splitting Theorem and on several technical lemmas. Furthermore it is not clear how to obtain from this proof the extensions to counting and optimization functions considered in Section 6.4.3. It seems also to require more work for handling the QDP-QF operations used in the algebra STR.

There are numerous articles that give polynomial-time recognition algorithms for classes of structured graphs, that are, in most cases, classes of bounded treewidth or clique-width. Hedetniemi lists 238 titles in his bibliography [*Hed] published in 1994.

The theory of fixed-parameter tractability is exposed in the books by Downey and Fellows [*DowFel] and by Flum and Grohe [*FluGro], but these books do not present algorithms for classes of graphs of bounded clique-width. This notion is surveyed in [*CouMR]. The surveys by Grohe [*Gro] and Kreutzer [*Kre] give algorithmic meta-theorems for first-order logic on graph classes of unbounded tree-width and clique-width that satisfy some structural constraints (relative to bounded tree-width).

Makowsky surveys in [*Mak] the meta-algorithmic uses of the Splitting Theorem for graph classes of bounded tree-width or clique-width, with applications to the computation of graph polynomials.

Bodlaender has published several articles about implemented and tested algorithms for computing tree-width: [START_REF] Bachoore | A branch and bound algorithm for exact, upper, and lower bounds on treewidth[END_REF][START_REF] Bachoore | Weighted treewidth: algorithmic techniques and results[END_REF][START_REF] Bodlaender | Treewidth: characterizations, applications, and computations[END_REF][START_REF] Bodlaender | Treewidth computations I. Upper bounds[END_REF][START_REF] Bodlaender | Treewidth computations II. Lower bounds, Information and Computation[END_REF][START_REF] Van Den Eijkhof | Safe reduction rules for weighted treewidth[END_REF].

For computing or approximating rank-width the known algorithms are in [START_REF] Oum | Approximating clique-width and branch-width[END_REF][START_REF] Oum | Approximating rank-width and clique-width quickly[END_REF][START_REF] Hliněný | Finding branch-decompositions and rank-decompositions[END_REF] (an exact exponential algorithm is also given in [START_REF] Oum | Computing rank-width exactly[END_REF]). No implementations have been reported. There exists an algorithm that is fixed-parameter linear with respect to tree-width for computing the clique-width of a graph. However, it is not useful for model-checking, because if we have a tree-decomposition of width at most k, we can use it directly, without going through a term over F VR to define the given graph.

Since we have presented rank-width in this chapter, we mention here that for each k, the graphs of rank-width at most k are characterized by finitely many excluded vertex-minors, whence by a C 2 MS sentence ( [START_REF] Courcelle | Vertex-minors, monadic second-order logic and a conjecture by Seese[END_REF][START_REF] Oum | Rank-width and vertex-minors[END_REF]). These results are extended to directed graphs in [KanRao].

The recognition problems for HR and VR equation systems are discussed respectively in the book chapters [*DreKH] and [*EngRoz] where numerous references can be found.

Constructions of linear-time algorithms from logical descriptions and for graphs of bounded tree-width can be found in [Bor, BorPT]. Monadic secondorder logic on finite and infinite words and terms is implemented in the software MONA, that has been developed by Klarlund and others and is described in many articles, in particular [BasKla], [Hen+] and [Kla]. Using it for checking MS graph properties is not successful because the automata of Section 6.3.4 are too large to be computable in practice as soon as the parameter k that bounds clique-width is more than 3 (see [Sog]). Other practically oriented approaches aiming at handling large fragments of monadic second-order logic are proposed in [START_REF] Courcelle | On the model-checking of monadic second-order formulas with edge set quantifications[END_REF][START_REF] Courcelle | Verifying monadic second-order graph properties with tree automata[END_REF][START_REF] Courcelle | Automata for the verification of monadic second-order graph properties[END_REF] and, with a different approach using games, in [KneLan]. Another research direction consists in developing algorithms for particular monadic second-order problems: see, e.g., [BuiTV, GotPWa, GotPWb] and [GanHli].

The ideas and tools of this section seem to be useful in applied computer science. They are quoted in works on computational linguistics [Kep], database querying [BeeEKM], logistics [MooSpie], compilation [Thop], telecommunications [McDRee], quantum computing [VNMDB], and perhaps yet in other fields.

Chapter 7

Monadic second-order transductions

Monadic second-order transductions are transformations of relational structures specified by monadic second-order formulas. They can be used to represent transformations of graphs and related combinatorial structures via appropriate representations of these objects by relational structures, as have shown the examples discussed in Section 1.7.1.

These transductions are important for several reasons. First because they are useful tools for constructing monadic second-order formulas with the help of the Backwards Translation Theorem (Theorem 7.10). Second because by means of the Equationality Theorems (Theorems 7.36 and 7.51), they yield logical characterizations of the HR-and VR-equational sets of graphs, that are independent of the signatures F HR and F VR . From these characterizations, we get short proofs that certain sets of graphs have bounded, or unbounded, tree-width or clique-width.

They also play the role of transducers in formal language theory: the image of a VR-equational set of graphs under a monadic second-order transduction is VR-equational, and a similar result holds for HR-equational sets and monadic second-order transductions that transform incidence graphs. Finally, the decidability of the monadic second-order satisfiability problem for a set of structures C implies the decidability of the same problem for its image τ (C) under a monadic second-order transduction τ . Hence monadic second-order transductions make it possible to relate decidability and undecidability results concerning monadic second-order satisfiability problems for graphs and relational structures.

Section 7.1 presents the definitions and the fundamental properties. Section 7.2 is devoted to the Equationality Theorem for the VR algebra, one of the main results of this book. Section 7.3 presents the monadic second-order transductions of graphs represented by their incidence graphs. Section 7.4 establishes the Equationality Theorem for the HR algebra. Sections 7.5 and 7.6 present some applications, respectively to the decidability of monadic second-order sat-503 isfiability problems and to the logical characterization of recognizability.

In this chapter (and the next) all functional signatures are assumed to be one-sorted. Let R and R be relational signatures. A concrete transduction τ of type R → R is a binary relation on concrete structures. More precisely, it is a set of pairs (S, S ) where S and S are concrete R-and R -structures respectively, hence it is a subset of STR c (R) × STR c (R ). The associated transduction of abstract structures is the set of pairs ([S] iso , [S ] iso ) for (S, S ) in τ , hence a subset of STR(R) × STR(R ), also denoted by τ . If we wish to be precise, it will be denoted by [τ ] iso . We say that two concrete transductions τ and τ are isomorphic if [τ ] iso = [τ ] iso . In proofs, transductions will be defined between concrete structures, but the equality of two transductions and their properties will be understood in terms of the associated relations on abstract structures, except otherwise specified.

The image of a (concrete) R-structure S under τ is the set of (concrete) R -structures τ (S) := {T | (S, T ) ∈ τ }. In this way, τ can also be viewed as a mapping : STR c (R) → P(STR c (R )) or : STR(R) → P(STR(R )). The image τ (C) of a set C of (concrete) R-structures is the union of the sets τ (S) for S in C. The domain Dom(τ ) of a (concrete) transduction τ is the set of (concrete) R-structures S such that τ (S) is not empty 1 .

If τ and τ are transductions (or concrete transductions) of respective types R → R and R → R , then their composition is the transduction (or the concrete transduction):

τ • τ := {(S, T ) | (S, U ) ∈ τ and (U, T ) ∈ τ for some U }. It is of type R → R . Note that (τ • τ )(S) = τ (τ (S)) for every R-structure S.
The inverse of τ is the transduction (or the concrete transduction) of type R → R defined by: τ

-1 := {(T, S) | (S, T ) ∈ τ }.
We will view a concrete transduction τ of type R → R that is functional also as a partial function : STR c (R) → STR c (R ), and similarly for transductions. For this reason, if τ and τ are functional (and only in this case), we will sometimes denote by τ • τ the composition τ • τ . Note that the transduction associated with a concrete transduction that is not functional may be functional (see Example 7.3(1) below). If a transduction (or concrete transduction) τ is functional, we will often write τ (S) = T instead of τ (S) = {T }.

For describing a concrete transduction τ of type R → R , we will frequently declare its type as STR c (R) → STR c (R ), or even as C → C in the case where τ ⊆ C × C ⊆ STR c (R) × STR c (R ). A similar notation will be used for transductions.

Definition 7.2 (Monadic second-order definition schemes and transductions) Let R and R be two relational signatures such that R 0 = ∅. (This restriction will be lifted later). Let also W be a finite set of set variables called parameters. A definition scheme of type R → R with set of parameters W is a tuple of formulas of the form

D = χ, (δ i ) i∈[k] , (θ w ) w∈R [k] for some k > 0 such that: χ ∈ CMS(R, W);
this formula is called the precondition;

δ i ∈ CMS(R, W ∪ {x}) for each i ∈ [k];
these formulas are called the domain formulas; R) };2 these formulas are called the relation formulas.

θ w ∈ CMS(R, W ∪ {x 1 , . . . , x ρ(R) }) for each w ∈ R [k], where R [k] is defined as {(R, i) | R ∈ R , i ∈ [k] ρ(
We write these formulas χ D , δ iD , θ wD if we need to specify D. The quantifierheight qh(D) of D is defined as the maximal quantifier-height of its formulas.

We now define the transduction of type R → R associated with D. Let S be a concrete R-structure and let γ be a W-assignment in S. We say that D defines the concrete R -structure T from (S, γ) if:

(i) (S, γ) |= χ, (ii) D T := {(a, i) ∈ D S × [k] | (S, γ) |= δ i (a)}, (iii) for each n > 0 and R ∈ R n : R T := {((a 1 , i 1 ), . . . , (a n , i n )) ∈ D n T | (S, γ) |= θ R,i1,...,in (a 1 , . . . , a n )}.
By (S, γ) |= θ w (a 1 , . . . , a n ), we mean (S, γ ) |= θ w where γ is the assignment extending γ such that γ(x i ) = a i for each i = 1, . . . , n (and similarly for (S, γ) |= δ i (a)). The structure T is uniquely determined by D, S and γ whenever it is defined, i.e., whenever (S, γ) |= χ. Therefore, we can use a functional notation and we will denote T by D(S, γ). The associated relation between concrete structures, defined by:

D := {(S, D(S, γ)) | γ is a W-assignment in S such that (S, γ) |= χ},
is the concrete transduction defined by D. It is called a concrete monadic secondorder transduction. Thus D(S) denotes { D(S, γ) | (S, γ) |= χ for some γ}. A monadic second-order transduction is the transduction [ D] iso of abstract structures associated with a concrete monadic second-order transduction D. It will also be denoted by D. Note that if τ is a concrete transduction, then we can say that it is a monadic second-order transduction (as opposed to being a concrete one), meaning that the associated transduction [τ ] iso of abstract structures is a monadic second-order transduction. That is in accordance with the fact that we also use τ to denote [τ ] iso .

If τ ⊆ STR(R) × STR(R ) and C ⊆ Dom(τ ), we will say that τ is a monadic second-order transduction on C if there exists a monadic second-order transduction τ of type R → R such that τ (S) = τ (S) for every S in C. Note that we do not require that the domain of τ is C. By Theorem 7.16 established below, we can require this if C is CMS-definable.

We recall that QF, FO, MS, CMS, C r MS h , MS 2 , etc., refer to fragments, extensions or variants of first-order and (counting) monadic second-order logic. If L is one of them, we call D an L-definition scheme if all its formulas are in the corresponding fragment, and then we call D an L-transduction. 3 The term "monadic second-order transduction" does not distinguish MS, CMS, MS 2 , etc. An FO-or a QF-definition scheme may use set variables as parameters: a parameter Y can be used in the atomic formulas x ∈ Y and Card p,q (Y ), but no set variable is quantified in an FO-or a QF-definition scheme.

If S is ∅ R , the empty structure in STR c (R), then the only possible assignment is γ ∅ such that γ ∅ (Y ) = ∅ for every Y ∈ W, and, either

D(∅ R , γ ∅ ) is undefined or it is ∅ R .
By Lemma 5.4, if S, S ∈ STR c (R) and h is an isomorphism : S → S , then the structures in D(S) are isomorphic to those in D(S ). More precisely, if γ is a W-assignment in S and γ is defined by γ (Y ) = h(γ(Y )) for every Y ∈ W, then D(S , γ ) is defined if and only if D(S, γ) is defined, and these structures are isomorphic by the mapping h such that h ((a, i)) = (h(a), i) for every (a, i) in the domain of D(S, γ).

It follows that D([S] iso ) is {[T ] iso | T ∈ D(S )} where S is any concrete structure isomorphic to S. (Definition 7.1 defines D([S] iso ) as {[T ] iso | T ∈ D(S ) for some S ∈ [S] iso }.)
If a definition scheme D has parameters (i.e., W = ∅), but if for every S in STR c (R), any two structures in D(S) are isomorphic, then we say that D and D are parameter-invariant. In this case D defines a partial function on abstract structures. Parameter-invariance is undecidable: it can be guaranteed by a particular construction of D but cannot be checked on arbitrary definition schemes.

If W = ∅, we say that D and D are parameterless. Parameterless transductions are functional, already on concrete structures.

We will refer to the integer k by saying that D and D are k-copying. If k = 1, we say that D and D are noncopying. A noncopying definition scheme has the simpler form χ, δ, (θ R ) R∈R where we let δ denote δ 1 and θ R denote θ R,1,...,1 . The domain of T := D(S, γ) is defined as a subset of D S and not of D S × [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. If D is noncopying and the domain formula δ is equivalent to True, then we say that D and D are domain-preserving. It implies that D T = D S . We say that D and D are domain-extending if k > 1 and some domain formula δ i is equivalent to True. Then the domain of any T := D(S, γ) contains D S × {i}, hence, a copy of D S . In most cases, we will have this for i = 1.

In some statements of Section 9.4, we will consider concrete functional transductions f : STR c (R) → STR c (R ) such that, for every S in some set C ⊆ Dom(f ) ⊆ STR c (R), we have D S ⊆ D f (S) ; moreover, if h is an isomorphism from S 1 to S 2 , then there is an isomorphism from f (S 1 ) to f (S 2 ) that extends h. We will say that such f is a domain-extending monadic second-order transduction on C if there exists a concrete domain-extending monadic secondorder transduction τ of type R → R such that C ⊆ Dom(τ ) and, for some i, the domain formula δ i is equivalent to True and, for every S ∈ C and T ∈ τ (S), there is an isomorphism from T to f (S) that maps (a, i) to a for every a in D S . For an example see Example 7.8 below.

If D is k-copying, the domain of D(S, γ) is defined above as a subset of

D S × [k].
In some constructions, it will be convenient to define it as a subset of D S × I for a fixed index set I of cardinality k. Then [k] can be replaced by I in the above definitions.

Every monadic second-order transduction τ is of linear size increase. We mean by this that there exists an integer k such that T ∈ τ (S) implies |D T | ≤ k • |D S |. This observation has been stated in Chapter 1 as Fact 1.37. It entails that certain graph transductions4 are not monadic second-order transductions. For example, the line graph transduction5 is not a monadic second-order transduction because the number of vertices of Line(K n ) is n(n -1)/2, whereas that of K n is n (cf. Example 1.45).

If τ is a monadic second-order transduction defined as D, its domain is characterized by the formula ∃Y 1 , . . . , Y q . χ D where Y 1 , . . . , Y q are the parameters, hence is C r MS-definable if τ is a C r MS-transduction. (A more general fact will be proved in Corollary 7.12.) The image of τ defined as the set τ (STR(R)) of abstract structures, is not always CMS-definable. For a counter-example, just consider the transduction that transforms a simple graph G into G ⊕ G. It is a 2-copying monadic second-order transduction. We know that the set of graphs G⊕G is not VR-recognizable (by Proposition 4.32, since VR-recognizability implies HR-recognizability by Theorem 4.49), hence it is not monadic second-order definable by the Recognizability Theorem for the VR algebra (Theorem 5.68). Other counterexamples will be given below (Remark 7.23). As a consequence of Theorem 7.10 (the Backwards Translation Theorem, cf. Remark 7.13(3)) this fact proves that the inverse of a CMS-transduction is not always a CMS-variable has more than one occurrence in t g . We say that θ H is strict if each term t g is strict, that is, if each variable x i has at least one occurrence in t g for i = 1, . . . , ρ(g), and we say that it is nonerasing if no term t g is a variable.

If θ H is linear, then it is an MS-transduction. More precisely, the set of pairs ( t , θ H (t) ) such that t ∈ T (H) is an MS-transduction6 . Terms are represented here by relational structures without constants. It is a straightforward exercise to construct a definition scheme for θ H that is parameterless and k-copying, where k is the maximal number of occurrences of symbols from F in a term t g . The hypothesis that the terms t g are linear cannot be removed. If g is unary with t g = f (x 1 , x 1 ) and a is a constant symbol with t a = a, then the size of θ H (g n (a)) is 2 n+1 -1, hence the corresponding transduction is not of linear size increase, so that it cannot be a monadic second-order transduction.

If θ H is linear, strict and nonerasing, then it is an invertible FO-transduction. Again, it is a straightforward exercise to construct a noncopying definition scheme for θ -1 H , with |H| parameters (see also Examples 8.3 and 8.5).

Remark 7.4 (Effectivity of definitions)

Certain conditions on a definition scheme D of type R → R are not decidable.

Typical examples are whether it is domain-preserving, parameter-invariant or produces only structures of the form S * for S ∈ STR(R ) in the case where R 0 = ∅ (cf. Section 5.1.5 and below Section 7.1.2). Another undecidable property is whether Dom( D) = ∅. These facts are due to the undecidability of the satisfiability problem for FO and MS sentences (Theorem 5.5). To the opposite, all particular properties of QF operations defined in Definition 5.42 are decidable from their definition schemes, because the absence of quantifiers makes the satisfiability problem decidable.

Monadic second-order transductions producing structures with constants

In Definition 7.2, we have defined monadic second-order transductions of type R → R where R has no constant symbols. We now waive this restriction. The definition scheme of a transduction producing structures T with constants must have some way to specify them as pairs (u, i) where i is an integer and u is in the domain of the input structure. Rather than rewriting all definitions, we will rest on the particular case of Definition 7.2 by replacing each constant symbol by a new unary relation. This method has been discussed in Section 5.1.5. Formally, for every relational signature R we let

R * := R + ∪ Lab R where Lab R := {lab a | a ∈ R 0 } is
a new set of unary relations. (Unless otherwise specified, when we discuss several signatures R, R , . . . we will always assume that

(R ∪ R ∪ • • • ) ∩ (Lab R ∪ Lab R ∪ • • • ) = ∅).
For every S ∈ STR c (R), we let S * be the structure in STR c (R * ) such that lab aS * = {a S } for every a ∈ R 0 and R S * = R S for every R ∈ R + . We denote by

STR c

* (R * ) the class of concrete R * -structures such that the relations lab a are interpreted as singletons, and by STR * (R * ) the corresponding set of abstract structures. The first-order sentence α defined as the conjunction of the sentences

∃x. lab a (x) ∧ ∀x, y(lab a (x) ∧ lab a (y) ⇒ x = y) for all a in R 0 characterizes STR c * (R * ). The mapping S → S * is a bijection : STR c (R) → STR c * (R * )
and also a parameterless and domain-preserving QFtransduction. (It is even a QF operation since it is total, but we will not use it as an operation of a functional signature.) Its inverse associates with

T ∈ STR c * (R * ) a structure in STR c (R) denoted by T † . If R 0 = ∅, we have R * = R and S = S * for every S ∈ STR c (R) and thus, STR c * (R * ) = STR c (R)
. Similar statements hold for abstract structures.

The following lemma says that the same first-order and monadic secondorder properties of an R-structure S can be expressed in S * or, directly, in S. We let r be a nonnegative integer and X be a finite set of first-order and set variables.

Lemma 7.5 For every formula ϕ in C r MS(R, X ) there exists a formula ψ in C r MS(R * , X ) such that, for every S ∈ STR c (R) and every X -assignment γ in S, we have (S, γ) |= ϕ if and only if (S * , γ) |= ψ. Conversely, for every formula ψ in C r MS(R * , X ) there exists a formula ϕ in C r MS(R, X ) satisfying the above equivalence. The same properties hold for FO instead of C r MS.

Proof: For proving the first assertion, we construct ψ from ϕ by the following steps.

Step 1: We replace every atomic formula R(t 1 , . . . , t n ) where each t i is a constant symbol or a variable by the formula:

∃x 1 , . . . , x n (R(x 1 , . . . , x n ) ∧ i∈[n] x i = t i ).
Step 2: For every a, b ∈ R 0 , every first-order variable x and every set variable X, we replace certain atomic formulas as follows:

x = a and a = x by lab a (x),

a = b by ∃x(lab a (x) ∧ lab b (x)), a ∈ X by ∃x(lab a (x) ∧ x ∈ X).
The verification that ψ satisfies the requested property is straightforward by induction on the structure of ϕ.

For the opposite direction, we construct ϕ from ψ by replacing lab a (x) by x = a for every first-order variable x and every a ∈ R 0 .

The first transformation may increase the quantifier-height, the second one preserves it. Both of them transform first-order formulas into first-order formulas.

We will denote by ϕ * the formula ψ constructed from ϕ, and by ψ † the formula ϕ constructed from ψ. The second transformation of this proof is actually an application of the Backwards Translation Theorem for QF operations (Proposition 5.46). Definition 7.6 (Transductions relating structures with constants) Let R and R be two relational signatures, possibly with constant symbols.

A definition scheme D of type R → R is a definition scheme D * of type R → R * such that D * ⊆ STR c (R) × STR c * (R * ). If S ∈ STR c (R)
and γ is a W-assignment in S where W is the set of parameters of D * , then we define D(S, γ) as D * (S, γ) † . The concrete transduction of type R → R defined by D is defined as D := {(S, T † ) | (S, T ) ∈ D * }, and it is called a concrete monadic second-order transduction. The corresponding transduction of abstract structures is [ D] iso , and it is called a monadic second-order transduction. Properties of a definition scheme D (and of the associated transduction) like to be parameterless, k-copying, parameter-invariant, etc. are defined as the corresponding properties of D * .

Note that the property that

D * ⊆ STR c (R) × STR c * (R * )
is not decidable for an arbitrary definition scheme D * . However, it can be guaranteed syntactically as we will see in Remark 7.13(2) after proving the fundamental Backwards Translation Theorem.

We now extend the remark of Example 7.3(2). Every QF operation of type R → R is a parameterless noncopying QF-transduction with precondition True, although a QFO definition scheme (cf. Definition 5.42) is not necessarily a QF-definition scheme since it may contain constant defining sentences κ c,d for c ∈ R 0 and d ∈ R 0 . However, a QFO definition scheme can be translated into a QF-definition scheme D * by taking as formula θ lab d (for d ∈ R 0 ) the formula c∈R0 (κ c,d ∧ x 1 = c). The conditions on the constant defining sentences in Definition 5.42 ensure that lab d is interpreted as a singleton.

If τ is a transduction of type R → R , then we let τ * := {(S, T * ) | (S, T ) ∈ τ } and, for having a symmetric notion, we define also τ * * := {(S * , T * ) | (S, T ) ∈ τ }. These three transductions are equivalent in the following sense. A definition scheme for τ * is obtained from one for τ * * by replacing each of its formulas ψ by the formula ψ † constructed in Lemma 7.5.

The first equivalence also holds for QF-transductions, by definition, but the second equivalence does not. If τ * is a QF-transduction, then the corresponding transduction τ * * is not necessarily one. If the domain formula of τ * is R(x) ∨ R(c) where c ∈ R 0 , then the domain formula of τ * * must be equivalent to R(x) ∨ ∃y(lab c (y) ∧ R(y)), hence is not equivalent to a quantifier-free formula (cf. Section 5.1.5).

As can be verified from the proof of Lemma 7.7, all the usual properties of definition schemes (except being a QF-definition scheme) carry over. Thus, an alternative to Definition 7.6 is to define a definition scheme D of type R → R to be a definition scheme

D * * of type R * → R * such that D * * ⊆ STR c * (R * ) × STR c * (R * ). Then D(S,

Transductions of words, terms and graphs

We have defined transductions that transform relational structures. Via relational structures that represent faithfully words, terms and labelled p-graphs or s-graphs (cf. Section 5.1.1, faithfully means that isomorphic structures represent identical or isomorphic objects), we can specify transformations of such objects by monadic second-order transductions that transform their representing structures. These transformations of objects will also be called monadic second-order transductions.

Specifically, we have defined in Section 5.1.1 structures w , t , G and G C that represent faithfully, respectively, a word w in A * , a term t in T (F ), a simple labelled graph G and a p-graph or a simple s-graph G of type included in C. To take a representative example, a relation τ ⊆ T (F ) × A * is said to be an MS-transduction if the relation τ := {( t , w ) | (t, w) ∈ τ } is an MS-transduction of type R F → W A .7 Properties of τ like being k-copying, parameterless, parameter-invariant, etc. are transferred from τ to τ in the obvious way. We omit a formal definition of an L-transduction of objects, which would be similar to the definition of L-definability of a set of objects in Section 5. 1.5.

A graph transduction is a set of pairs (G, H) such that G and H are, possibly labelled, graphs. Similarly we define p-graph and s-graph transductions. If τ is, e.g., a monadic second-order p-graph transduction, then both the domain Dom(τ ) and the image Dom(τ -1 ) of τ are sets of p-graphs of bounded type, because the p-graphs G in Dom(τ ) must be represented as G C for a fixed C, and similarly for Dom(τ -1 ). If necessary, we will make precise the relational signatures used for representing the considered graphs, p-graphs, or s-graphs. Such a precision may be necessary since we have defined variants of the basic representations. The quantifier-free operations on graphs, p-graphs or s-graphs, in particular the edge-complement, the edge addition operation --→ add a,b,C and the source fusion fuse a,b (cf. Sections 5.3. 2 and 5.3.4), are examples of monadic second-order graph (p-graph or s-graph) transductions. We now consider an example concerning forests. Its definition scheme uses a parameter Y ; its precondition χ expresses that G is a forest and that Y denotes a set of vertices A that has one and only one element in each connected component of G: this means that A can be chosen as a set of roots. We let (G, A) denote the corresponding rooted, and thus directed, forest.

The domain formulas δ 1 and δ 2 are respectively True and x / ∈ Y . A vertex u of G in D Inc(G) will correspond to the pair (u, 1), and an edge e will correspond to the pair (u, 2) where u is the head of e in (G, A). Every vertex not in A is thus the head of a unique edge, which justifies the definition of δ 2 . We now complete the construction by defining the relation formulas: θ in,2,1 is x 2 = x 1 ∨ "x 2 → (G,A) x 1 " and θ in,1,1 , θ in,1,2 , θ in,2,2 are False. This transduction is parameter-invariant. Since the composition of two monadic second-order transductions is a monadic second-order transduction, as we will prove below (Theorem 7.14), we get that τ is a monadic second-order transduction if and only if τ is a monadic secondorder transduction. Hence, the replacement of w by w to represent a word w does not modify the notion of monadic second-order transduction between words and terms, or between words and words, words and graphs etc. The same argument holds in the general case.

It can be verified that all variants of representations discussed in Example 5.2 are strongly MS-equivalent, with one exception: representing the empty word by the empty structure is MS-equivalent but not strongly MS-equivalent to representing it by a nonempty structure (we considered these two possibilities in Example 5.2( 1)) because the image of the empty structure ∅ R under an MStransduction of type R → R is necessarily the empty structure ∅ R . If this point is important, we will specify in statements concerning transductions of words which type of representation is used. This problem does not occur for terms and graphs, because no term is represented by the empty structure and the empty graph is always represented by the empty structure.

In addition to the standard representation of a graph G by the relational structure G with domain V G (cf. Example 5.2(2)), we have also defined a faithful representation by the structure G = Inc(G) with domain V G ∪ E G (cf. Section 5.2.5). The representations G and G are not strongly equivalent for all graphs (but they are for forests by Example 7.8) hence, we get several types of graph transductions, depending on the choice of G or G . This point has been discussed in detail in Section 1.8, and we will go back to it in Section 7.3 and in Chapter 9. In this section and the next one (i.e., Sections 7. 1 and 7.2), we will only consider simple graphs, and a graph G will always be represented by (and even identified with) G .

The fundamental property of monadic second-order transductions

A definition scheme D defines a transduction between structures but it also yields a translation of formulas. The following theorem says that if T = D(S, γ), then each monadic second-order property of T can be expressed by a monadic second-order formula over S. (The particular case of QF operations, more precisely of QDP-QF operations, has been proved in Theorem 5.47). The usefulness of monadic second-order transductions is largely based on this fact.

Let D be a k-copying definition scheme of type R → R with set of parameters W. Given a set X of set variables disjoint from W, we introduce new set variables X (i) for X ∈ X and i ∈ [k], and we let

X (k) := {X (i) | X ∈ X , i ∈ [k]}.
Let S ∈ STR c (R). For every mapping η : X (k) → P(D S ), we define η [k] :

X → P(D S × [k]) by η [k] (X) := (η(X (1) ) × {1}) ∪ • • • ∪ (η(X (k) ) × {k}).
Let Y = {y 1 , . . . , y n } be a set of first-order variables, linearly ordered as indicated. For a mapping µ : Y → D S and an n-tuple i = (i 1 , . . . , i n ) ∈ [k] n , we denote by µ i : Y → D S × [k] the mapping such that µ i (y j ) := (µ(y j ), i j ). If k = 1, then we identify D S × [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] with D S and µ (1,...,1) with µ.

Note that, even if T = D(S, γ) is well defined (for a W-assignment γ), the mapping η [k] is not necessarily an X -assignment in T because η [k] (X) may not be a subset of the domain of T . A similar observation holds for µ i .

Theorem 7.10 (Backwards Translation Theorem) Let D be a k-copying C r MS-definition scheme of type R → R with set of parameters W. Let X be a finite set of set variables and Y = {y 1 , . . . , y n } be a set of first-order variables. For every

β ∈ C r MS(R , X ∪ Y) and i ∈ [k] n , one can construct a formula β D i ∈ C r MS(R, W ∪ X (k) ∪ Y)
such that for every S ∈ STR c (R), every W-assignment γ, every X (k) -assignment η, and every Yassignment µ, all of them in S, we have:

(S, γ ∪ η ∪ µ) |= β D i if and only if D(S, γ) is defined, η [k] ∪ µ i is an (X ∪ Y)-assignment in D(S, γ), and ( D(S, γ), η [k] ∪ µ i ) |= β.
The quantifier-height of

β D i is at most k • qh(β) + qh(D) + 1.
Before giving the proof, we present the construction of β D i and a lemma, for the case where R has no constant symbols. The extension to the general case will be straightforward.

We first define a formula β D i , by an inductive construction on the structure of β. As in the constructions of Chapters 5 and 6 and without loss of generality, we will assume that β contains neither universal quantifications, nor the Boolean connectives ⇒ and ⇔, nor the atomic formula False. Let R 0 = ∅. We let D be χ, (δ i ) i∈[k] , (θ w ) w∈R [k] with set of parameters W. For every i ∈ [k] and every set variable X, we denote by δ i (X) the formula ∀x(x ∈ X ⇒ δ i ).

For every m and n, every β in C r MS(R , {X 1 , . . . , X m , y 1 , . . . , y n }), and every i ∈ [k] n , we define as follows a formula

β D i in C r MS(R, {X 1 , . . . , X m } (k) ∪ {y 1 , . . . , y n }): • True D i is True, • (y j = y j ) D i is y j = y j if i[j] = i[j ] and is False otherwise (where i[j] is the j-th component of the tuple i), • (y j ∈ X ) D i is y j ∈ X (i[j]) , • (R(y j1 , . . . , y j ρ(R) )) D i is θ w [y j1 /x 1 , . . . , y j ρ(R) /x ρ(R) ] where w := (R, i[j 1 ], . . . , i[j ρ(R) ]), • (Card p,q (X )) D i is i∈[k] Card pi,q (X (i) )
, where the disjunction extends to all k-tuples (p 1 , . . . , p k ) ∈ [0, q -1] k such that p 1 +• • •+p k ≡ p (mod q), so that:

(T, η [k] ∪ µ i ) |= β if and only if (S, γ ∪ η ∪ µ) |= β D i .
The other cases are easy to establish.

Proof of Theorem 7.10:

We first assume that R has no constant symbols and we let D be as in the previous lemma. As said above, the formula β D i is the following:

χ ∧ i∈[k], ∈[m] δ i (X (i) ) ∧ j∈[n] δ i[j] [y j /x] ∧ β D i .
Its conjuncts express respectively that T := D(S, γ) is defined, that η [k] is an {X 1 , . . . , X m }-assignment in T , that µ i is a {y 1 , . . . , y n }-assignment in T and, by Lemma 7.11, that (T, η [k] ∪ µ i ) |= β. Hence, β D i satisfies the required property. We now consider the case where R may have constant symbols. We apply the above construction to the definition scheme D * and the formula β * constructed from β in Lemma 7.5. We obtain that: We recall that C 0 MS designates the same formulas as MS, hence the following corollary also concerns MS-transductions.

(S, γ ∪ η ∪ µ) |= (β * ) D * i if and only if D * (S, γ) is defined, η [k] ∪ µ i is an (X ∪ Y)-assignment in D * (S,
Corollary 7.12 Let τ be a C r MS-transduction of type R → R . For every C r MS-definable subclass C of STR c (R ), the subclass τ -1 (C) of STR c (R) is C r MS-definable. A similar property holds for certain transductions that are not monadic secondorder transductions, in particular, for the unfolding of a graph into a possibly infinite tree (see Section 7.7). However, for monadic second-order transductions, we have more than the above equivalence. To simplify the discussion, we assume that D is k-copying, parameterless and that n = 0 (the considered formula β has no first-order variables). By Theorem 7.10, we have a bijection between the set sat( D(S), β, X ) and the set sat(S, β D , X (k) ), where X is a tuple that enumerates X and similarly for X (k) . Such a bijection is impossible for the unfolding, by a simple cardinality argument.

(2) Let D be a definition scheme of type R → R * . Let α be the firstorder sentence that characterizes the class STR c * (R * ) and α D be its backwards translation. Then, if we replace the precondition of D by α D , we obtain a definition scheme D such that D = D ∩ (STR c (R) × STR c * (R * )), hence a definition scheme of type R → R . It is equivalent to D for producing structures that encode R -structures correctly.

(3) By Corollary 7.12, the image of a C r MS-definable set of structures under an invertible C r MS-transduction is C r MS-definable. This is not true in general, even for an injective transduction (cf. Remark 7.23).

Constructions of monadic second-order transductions

The following theorem10 is, with Corollary 7.12, the second main consequence of the Backwards Translation Theorem.

Theorem 7.14 (Composition of transductions)

(1) The composition τ • τ of two C r MS-transductions τ : R → R and τ : R → R is a C r MS-transduction. If τ and τ are both parameterless and/or both noncopying, then so is τ • τ . If τ is k-copying and is defined with q parameters, and if τ is k -copying and is defined with q parameters, then τ • τ is (kk )-copying and is defined with q + kq parameters.

(2) If τ and τ as above are concrete transductions and at least one of them is noncopying, then τ • τ is also a concrete C r MS-transduction.

(3) If τ and τ as above are both domain-preserving or both domain-extending, then so is τ • τ . If one of them is domain-preserving and the other is domain-extending, then τ • τ is domain-extending.

Proof: We first consider the special case where R and R have no constant symbols. Since the proof is a bit technical, we consider four cases.

Case 1: τ and τ are both noncopying.

We let τ and τ be the concrete transductions defined respectively by the definition schemes D = χ, δ, (θ R ) R∈R with set of parameters W := {Y 1 , . . . , Y q } and D = χ , δ , (θ R ) R∈R with set of parameters W := {Z 1 , . . . , Z q } disjoint with W. We build as follows a definition scheme D = χ , δ , (θ R ) R∈R . (iv) It remains to define the relation formulas θ R for R ∈ R . Each relation R U for R ∈ R is defined by θ R in T , hence by (θ R ) D in S (using an argument similar to the one in (iii)). Hence we need only take θ R to be

(θ R ) D for R ∈ R . We have θ R in C r MS(R , W ∪ {x 1 , . . . , x ρ(R) }) and θ R in C r MS(R, W ∪ W ∪ {x 1 , . . . , x ρ(R) }).
It is clear from the construction of D that it defines the concrete transduction τ • τ . This proves Assertions (1) and (2) for this case. To prove Assertion (3), we observe that instead of defining δ as (δ ) D , we can as well define it as the weaker formula δ ∧(δ ) D and use Lemma 7.11 instead of Theorem 7.10. Thus, if both δ and δ are True, then δ is (equivalent to) True. We note that, similarly, θ R can as well be defined as (θ R ) D .

Case 2: τ is noncopying and τ is k -copying (k > 1). The construction is similar, again for concrete transductions: for

D = χ , (δ i ) i∈[k ] , (θ w ) w∈R [k ] , we let D := χ , (δ i ) i∈[k ] , (θ w ) w∈R [k ] ,
where

χ is (χ ) D , δ i is (δ i ) D for each i (or it is δ i ∧ (δ i ) D ), and θ w is (θ w ) D for each w ∈ R [k ]. As in Case 1, D defines the concrete transduction τ • τ .
Case 3: τ is k-copying and τ is k -copying with k, k > 1.

We only prove Assertion [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. If T := D(S, γ) and U := D (T, γ ), we have

D T ⊆ D S × [k] and D U ⊆ D T × [k ] ⊆ (D S × [k]) × [k ].
We will prove that τ • τ is a monadic second-order transduction. It is not a concrete one because D U is not a subset of any D S × [m]. However, since we only want to construct structures isomorphic to those of (τ • τ )(S), we will consider (D

S × [k]) × [k ] as equal to D S × ([k] × [k ]).
The set of parameters for D will be W

:= W ∪W (k) = {Y 1 , . . . , Y q }∪{Z (i) j | 1 ≤ j ≤ q , 1 ≤ i ≤ k}.
For each W-assignment γ in S, a W -assignment γ in T := D(S, γ) is described in terms of a W (k) -assignment η in S with γ = η [k] . We let the precondition χ be (χ ) D . Its free variables are in W . Then, by Theorem 7.10, (S, γ ∪ η) |= χ if and only if U := D (T, γ ) is defined.

The definition scheme D will construct from S a structure with domain included in We define δ i,j as (δ j ) D (i) (or as δ i ∧ (δ j ) D (i) for the domain-extending case). Assuming that γ ∪η satisfies χ , we have (again by Theorem 7.10, or Lemma 7.11), for a ∈ D S , (S, γ ∪ η) |= (δ j ) D (i) (a) if and only if (a, i) ∈ D T and (T, γ ) |= δ j (a, i),

D S × ([k] × [k ]),
i.e., if and only if ((a, i), j) = (a, (i, j)) ∈ D U . Finally for each w = (R, (i 1 , j 1 ), . . . , (i p , j p )) where R ∈ R and p = ρ(R), we define the relation formula θ w as (θ R,j1,...,jp ) D (i1,...,ip) . For a 1 , . . . , a p ∈ D S :

(S, γ ∪ η) |= (θ R,j1,...,jp ) D (i1,...,ip) (a 1 , . . . , a p ) if and only if (a q , i q ) ∈ D T for each q ∈ [p] and (T, γ ) |= θ R,j1,...,jp ((a 1 , i 1 ), . . . , (a p , i p )), i.e., if and only if ((a 1 , (i 1 , j 1 )), . . . , (a p , (i p , j p )) ∈ R U .

It is clear from the construction of D that it defines the abstract transduction τ • τ . We observe, however, that it "almost" defines the concrete transduction τ • τ , in the following sense. For fixed integers k, k > 1 let θ be the binary relation {( ((d, i) Remarks 7.15 (QF operations and QF-transductions)

, j), (d, k(i -1) + j)) | i ∈ [k], j ∈ [k ]}
(1) We have observed in Example 7.3(2) and after Definition 7.6 that the quantifier-free operations (cf. Section 5.3.2) are total functions and, actually, QF-transductions of a particular form: they are parameterless, noncopying and with a precondition equal (or equivalent) to True. Proposition 5.49 (Section 5.3.2) has shown that the composition of two quantifier-free operations is a quantifier-free operation. It can be considered as a special case of Theorem 7.14.

(2) More generally than QF operations, we have defined QF-and FOtransductions as MS-transductions with definition schemes that use only QF and FO formulas respectively. Results like Theorems 7.10 and 7.14 and their corollaries have particular special cases for FO-transductions and FO-definable sets of structures. However, we will not detail the corresponding statements because, for the questions studied in this book, knowing that a class of structures is FO-definable rather than MS-definable brings no additional results. The fact that a transduction is an FO-transduction rather than a CMS-transduction indicates that it is "not too complicated", and we will make such observations only by passing. However, QF-transductions (or rather QF operations) have particularly important properties that we have used to prove the Recognizability Theorem in Chapter 5, and that MS-transductions do not share. Example 5.65 has shown that this theorem can fail to hold if only one unary operation that is an FO-transduction is added to the signature F VR . We continue by presenting other techniques to construct monadic secondorder transductions. In the case where R has constant symbols, we observe that

(τ ∩ (MOD(α) × MOD(β))) * = τ * ∩ (MOD(α) × MOD(β * ))
hence the result follows from the first case.

We denote by ♦ the structure in STR c (∅) consisting of the single element * .

Proposition 7.17 Let S be an R-structure having k elements. There exists a parameterless k-copying QF-transduction τ of type ∅ → R such that τ (♦) consists of a single structure isomorphic to S.

Proof:

The construction of a definition scheme for τ is easy. The domain of τ (♦) will be { * } × [k] and all formulas of the definition scheme will be True or False.

We now consider the union of two transductions of the same type.

Proposition 7.18 If τ and τ are (concrete) C r MS-transductions of type R → R , then τ ∪ τ is a (concrete) C r MS-transduction.

Proof: Since (τ ∪ τ ) * = τ * ∪ τ * , it suffices to consider the case where R has no constant symbols. Let D and D be definition schemes for the concrete transductions τ and τ that are respectively k-and k -copying. We first assume that k < k . We define from D = χ, δ 1 , . . . , δ k , (θ w ) w∈R [k] the k -copying definition scheme

E := χ, δ 1 , . . . , δ k , False, . . . , False, (θ Ew ) w∈R [k ] . Its domain formula δ j is False if k < j ≤ k . The relation formula θ Ew is θ w if w ∈ R [k] and False if w ∈ R [k ] -R
[k] (but it can be any formula by Definition 7.2, since the formulas δ j are equal to False for j > k). It is clear that the concrete transductions defined by E and D are equal.

Hence we assume that D and D are both k-copying, with sets of parameters W and W respectively. (The sets W and W need not be disjoint). We construct a k-copying definition scheme D by taking W ∪ W ∪ {Z}, where Z / ∈ W ∪ W , as set of parameters and by defining χ D as (Z = ∅ ∧ χ D ) ∨ (Z = ∅ ∧ χ D ) and similarly for the domain and relation formulas of D , so that for every W -assignment γ in a nonempty structure S ∈ STR c (R), we have:

D (S, γ) = D(S, γ W) if γ(Z) = ∅, D (S, γ W ) if γ(Z) = ∅.
There is however a difficulty if S = ∅ R because the condition γ(Z) = ∅ cannot be satisfied. It follows that the above definition is incorrect in the only case where D(∅ R ) = ∅ and D (∅ R ) = {∅ R }. In this case, we just exchange the conditions Z = ∅ and Z = ∅ in the definition of the formulas of D . With this modification, D defines the concrete transduction τ ∪ τ as wanted.

The statement for transductions follows immediately.

These two propositions entail that every finite set of R-structures is the image of ♦ under a monadic second-order transduction.

Some particular monadic second-order transductions

We will consider "labelling" transductions and "copying" transductions.

Labelling transductions

We know from Example 5.2(2) that vertex labels of a graph (including source and port labels) can be handled as unary relations in the structure that represents the graph. In general, we can view unary relations of a structure as labels attached to the elements of the structure. We will consider monadic secondorder transductions that manipulate such labels. Since unary relations are sets, there is also a close relationship between labels and set variables, in particular parameters.

Definition 7.19 (Expansions by unary relations)

Let R be a relational signature and U be a set of unary relation symbols in R. For every S ∈ STR c (R), we let fg U (S) be the corresponding reduct (cf. Example 5.44) in STR c (R -U): it is the structure obtained by deleting (or "forgetting") from S the relations that interpret the symbols in U. The mapping fg U is a parameterless, noncopying and domain-preserving QF-transduction.

We let exp U be its inverse, the transduction of type (R -U) → R that associates with S the set of structures S such that fg U (S ) = S. These structures S are called the expansions of S by the set U of unary relations. The transduction exp U is a noncopying and domain-preserving QF-transduction with U as set of parameters: each U ∈ U is made into a parameter and the interpretation U T of U in the output structure T is defined as γ(U ), where γ is the U-assignment in the input structure from which T is defined, i.e., the relation formula θ U is x 1 ∈ U . We will denote by U par the set U considered as a set of parameters to distinguish it from the initial set of unary relation symbols included in R.

Definition 7.20 (Monadic second-order relabellings) Let R and R be relational signatures such that R i = R i for i = 1, i.e., that may differ only by their unary relation symbols. A concrete monadic second-order transduction τ of type R → R is called a monadic second-order relabelling if it is domain-preserving and, for every T in τ (S), we have a T = a S if a ∈ R 0 = R 0 and R T = R S if R has arity at least 2 (which implies R ∈ R ∩ R ). Such a transduction can only modify, add and/or delete unary relations.

A transduction τ of type R → R is a monadic second-order relabelling if and only if τ * * has a domain-preserving definition scheme whose relation formula

θ R is R(x 1 , . . . , x ρ(R) ) if R ∈ R * -R 1 .
In such a definition scheme, there is no constraint on the precondition and on the relation formulas θ R if R is unary and not of the form lab a for any a ∈ R 0 .

It is clear from the definitions that the composition of two monadic secondorder relabellings is a monadic second-order relabelling. It is also clear that the composition of definition schemes used in the proof of Theorem 7.14 (Case 1) preserves the above syntactic property (provided θ R is defined as (θ R ) D rather than (θ R ) D ).

The transductions fg U and exp U of Definition 7.19 are monadic second-order relabellings.

We now consider two particular monadic second-order relabellings of terms. Let F and F be two finite functional signatures. In the following definition, the associated relational signatures R F and R F use the binary relations son i (as opposed to the binary relation son and the unary relations br i ). Their only unary relations are thus the relations lab f for f in F or in F . A relation τ ⊆ T (F ) × T (F ) is a monadic second-order relabelling if the corresponding relation {( t , t ) | (t, t ) ∈ τ } is a monadic second-order relabelling of type R F → R F . Hence, if (t, t ) ∈ τ , the term t is obtained from t by the replacement of function symbols from F by function symbols from F of the same arity, in a way that is not uniform as in an alphabetic relabelling (cf. the paragraph before Proposition 2.126, and cf. Section 6.3.1), but is specified by monadic second-order formulas.

Here is our second particular monadic second-order relabelling of terms. Again, F is a finite functional signature. Let U := {U 1 , . . . , U n } be a set of unary relation symbols disjoint from R F , ordered as indicated. If t ∈ T (F ) and (A 1 , . . . , A n ) is an n-tuple of subsets of N t , we denote by t + (A 1 , . . . , A n ) the expansion of t into the (R F ∪ U)-structure such that A 1 , . . . , A n are the interpretations of U 1 , . . . , U n respectively (cf. Lemma 6.52 in Section 6.4.1 for the notation S + γ). We recall from Definition 6.24(c) in Section 6.3.3 that the pair of a term t and an n-tuple (A 1 , . . . , A n ) as above is encoded by a term t * (A 1 , . . . , A n ) in T (F (n) ) where u is an occurrence of (f, w) belonging to F (n) (w is a sequence of n Booleans) if and only if it is an occurrence of f in t and, for each i = 1, . . . , n, w[i] = 1 if and only if u ∈ A i . Then, the mapping : T (F (n) ) → ST R c (R F ∪ U) that maps t * (A 1 , . . . , A n ) to t + (A 1 , . . . , A n ) is a monadic second-order relabelling. It defines a bijection between T (F (n) ) and exp U ( T (F ) ) that we denote by µ F,n . Its inverse is also a monadic secondorder relabelling, which holds for all monadic second-order relabellings as will be shown in Proposition 7.22 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF].

We will also use the monadic second-order relabelling π F,n := µ F,n • fg U . It represents, in terms of relational structures, the alphabetic relabelling of terms : T (F (n) ) → T (F ) that deletes the Booleans from the symbols (f, w) of F (n) . Definition 7.21 (Labellings by bounded theories) A bounded theory (Definition 5.59 in Section 5.3.6) is a subset Φ of a fixed finite set L of formulas. We will make each such set into a unique symbol, to be used as a label.

Let r, h ∈ N and let R be a relational signature. We recall from Proposition 5.93 (Section 5.6) that every formula in C r MS h (R, {x}) is equivalent to a formula belonging to the finite set L := C r MS h (R, {x}) of formulas that are in a certain "normal form". For S ∈ STR c (R) and a ∈ D S , we define Φ(a) := {ϕ ∈ L | S |= ϕ(a)}, i.e., Φ(a) = Th(S, R, h, r, a) as defined in Definition 5.59. The set P(L) in which Φ(a) takes its values is finite and depends only on r, h and R. For each subset Φ of L, we let U Φ be a new unary relation symbol. These symbols form a finite set U. For each S ∈ STR c (R), we let S be the unique expansion of S into an (R ∪ U)-structure satisfying the following sentence Ψ:

Φ⊆L ∀x U Φ (x) ⇔ ϕ∈Φ ϕ ∧ ϕ∈L-Φ ¬ϕ .
It expresses that U Φ S consists of all elements a of D S such that Φ(a) = Φ. The mapping S → S is a C r MS h -transduction : STR(R) → STR(R ∪ U) where each unary relation U Φ of U is defined by a formula of quantifier-height at most h. It is a parameterless (hence functional) monadic second-order relabelling.

We now prove that the class of monadic second-order relabellings is closed under inverse, which is not true of all monadic second-order transductions. In the following statement, F and F denote as usual finite functional signatures.

Proposition 7.22

(1) Every monadic second-order relabelling is invertible; its inverse is a monadic second-order relabelling.

(2) The image of a CMS-definable class of structures under a monadic secondorder relabelling is CMS-definable.

(3) The image of a regular language over F under a monadic second-order relabelling from T (F ) to T (F ) is regular over F .

Proof: [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] We first give the idea. If a transduction deletes or modifies unary relations, its inverse can be expressed as a monadic second-order transduction using parameters that describe the (possible) initial values of these relations.

Let τ be a monadic second-order relabelling of type R → R and let τ * * be defined by D := χ, True, (θ R ) R∈R * where θ R is R(x 1 , . . . , x ρ(R) ) for every R in R * -R 1 . Let W be the set of parameters of D. For defining the inverse of τ * * (this will suffice because (τ * * ) -1 = (τ -1 ) * * ), we take W := W ∪ (R 1 ) par as set of parameters, where (R 1 ) par is the set R 1 considered as a set of parameters (cf. Definition 7.19).

The definition scheme for (τ * * ) -1 is then D := χ , True, (θ R ) R∈R * where θ R is R(x 1 , . . . , x ρ(R) ) for each R in R * and the precondition χ is defined as:

χ ∧ R∈R 1 ∀x 1 (R(x 1 ) ⇔ θ R ).
Note that in the formulas of D , every atomic formula U (x) with U ∈ R 1 can be replaced by x ∈ U by our syntactical convention for set variables (which does not hold for unary relation symbols). In particular, θ U then becomes x 1 ∈ U for each U ∈ R 1 , which means that the unary relation symbol U is interpreted as the value of the parameter U . The precondition χ ensures that, in a given R * -structure T , if the values of the parameters are taken as the relations U S for U ∈ R 1 in an R * -structure S where the other relations are as in T , then (S, T ) ∈ D. The other formulas of D ensure that S and T have the same domain and the same relations defined by the symbols not in R 1 or R 1 .

(2) Follows from ( 1) and the Backwards Translation Theorem (Corollary 7.12).

(3) Follows from (2) and the equivalence between regularity and monadic second-order definability for languages over a finite functional signature (Theorem 5.82).

Remark 7.23 We have already noted in Definition 7.2 and Remark 7.13(3) that the image of a CMS-definable class under a monadic second-order transduction is not always CMS-definable, hence that the inverse of a monadic secondorder transduction is not always a monadic second-order transduction. We give three examples of such cases for monadic second-order transductions that only modify a single relation of arity 2.

First, we consider the mapping on p-graphs of type {a, b} that deletes the edge relation. It transforms the structure (ab) n for n ≥ 1 that represents the word (ab) n into the structure representing the edgeless p-graph a ⊕ • • • ⊕ a ⊕ b ⊕ • • •⊕b with an equal number of occurrences of a and b. These structures do not form an MS-definable set by Proposition 5.13 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. The same proof shows that they do not form a CMS-definable set. However, the language (ab) + is regular, hence MS-definable by Theorem 5.15.

As another example, we consider the mapping und on graphs that forgets edge directions. Hence it redefines edg(x 1 , x 2 ) by edg(x 1 , x 2 ) ∨ edg(x 2 , x 1 ). We let L := {G n | n ≥ 1} where G n is the graph with vertices u 1 , . . . , u n , v 1 , . . . , v n and edges u i → v i and v j → u i for all i, j ∈ [n] with j = i. The set of graphs L is FO-definable, but und (L) is the set {K n,n | n ≥ 1} which is not MSdefinable by the proof of Proposition 5.13(2) and also not CMS-definable by an easy extension of that proof.

As last example, we take the monadic second-order transduction from words to words that transforms a word a 1 a 2 a 3 • • • a 2n (where a 1 , a 2 , . . . , a 2n are letters) into the word a 1 a 3 • • • a 2n-1 a 2 a 4 • • • a 2n . It is a parameterless domain-preserving transduction that transforms the regular, hence MS-definable language (ab) + into the nonregular language {a n b n | n ≥ 1} which is not CMS-definable. This example shows that adding conditions of connectivity and bounded degree does not change the situation.

The next two propositions show that monadic second-order transductions can be factorized as compositions of transductions of particular types. We first show that every CMS-transduction can be decomposed into a (very simple) monadic second-order relabelling and a parameterless CMS-transduction.

If W is a set of set variables, we will denote by W rel the same set viewed as a set of unary relation symbols. The monadic second-order relabelling π F,n : T (F (n) ) → T (F ) associated with a finite functional signature F has been defined at the end of Definition 7.20.

Proposition 7.24

(1) Every concrete C r MS-transduction τ of type R → R with set of parameters W can be expressed as exp W rel •τ where τ is a concrete parameterless C r MS-transduction of type R ∪ W rel → R .

(2) Every concrete C r MS-transduction τ : T (F ) → STR c (R ) with n parameters can be expressed as (π F,n ) -1 •τ where τ is the concrete parameterless C r MS-transduction :

T (F (n) ) → STR c (R ) defined by τ ( t * (A 1 , . . . , A n ) ) := τ ( t , (A 1 , . . . , A n )).
Proof: [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] We let τ be defined by τ (S + γ) := τ (S, γ) for every concrete R-structure S and every W-assignment γ in S, where S + γ is the expansion of S into the concrete (R ∪ W rel )-structure such that γ(Y ) is the interpretation of Y ∈ W rel (see Lemma 6.52). The formulas of a parameterless definition scheme for τ are obtained from those of one for τ by replacing, for every Y ∈ W, each atomic formula Card p,q (Y ) by ∃Z(∀x(x ∈ Z ⇔ Y i (x)) ∧ Card p,q (Z)) (and replacing each atomic formula s ∈ Y by Y (s), where s is a first-order variable or a constant symbol).

(2) We let τ be defined by τ ( t * γ ) := τ ( t , γ) for every t ∈ T (F ) and γ : X n → P(N t ), where X n = {X 1 , . . . , X n } is the set of parameters (cf. Definition 6.24(c)). Let τ be defined as in [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF], with R := R F and W := X n . Then τ = µ F,n • τ , where µ F,n is defined at the end of Definition 7.20, and this equality holds for the concrete transductions. By Theorem 7.14(2) (about the compositions of concrete monadic second-order transductions), we get the desired result. Theorem 7.14(2) is applicable because µ F,n is noncopying, so that we have an equality of concrete transductions.

Copying transductions

We now show that every parameterless CMS-transduction can be decomposed into a very simple copying transduction and a parameterless noncopying CMStransduction. To this aim we define, for each k > 1, a particular parameterless k-copying monadic second-order transduction that transforms a structure S ∈ STR c (R) by adding to it k -1 copies of each element of its domain. The i-th copy of an element is related to it by a new binary relation B i . Finally, a new unary relation P i collects all i-th copies of the elements of D S .

Definition 7.25 (The copy k -transduction)

For k > 1, we let C k := {P i | 1 ≤ i ≤ k} ∪ {B i | 1 < i ≤
k} be a set of relation symbols such that each P i is unary and each B i is binary. We assume that this set is disjoint with the other relational signatures R, R , . . . that we will consider. For each relational signature R, we define as follows the mapping copy and relations and constants defined by: R T := {((a 1 , 1), . . . , (a ρ(R) , 1))

k : STR c (R) → STR c (R ∪ C k ).
| (a 1 , . . . , a ρ(R) ) ∈ R S } for R ∈ R + , c T := (c S , 1) for c ∈ R 0 , P iT := D S × {i} for 1 ≤ i ≤ k, B iT := {((a, 1), (a, i)) | a ∈ D S } for 1 < i ≤ k.
It is clear that copy k is a parameterless k-copying QF-transduction. The sets P iT are FO-definable from the relations B iT . Hence, we could omit them, and the next proposition would remain valid, but having them will make formulas more clear.

Proposition 7.26 For every concrete parameterless k-copying C r MS-transduction τ of type R → R , there exists a concrete parameterless noncopying C r MStransduction µ of type R ∪ C k → R such that τ = copy k • µ and every structure in Dom(µ) is isomorphic to one in copy k (STR c (R)).

Proof: A structure U in STR(R∪C k ) of the form copy k (S) satisfies the following conditions:

(1) the sets P 1U , . . . , P kU form a partition of the domain;

(2) every constant belongs to P 1U and for every R ∈ R + and every tuple a in R U , we have a ⊆ P 1U , i.e., all components of a are in P 1U ;

(3) each relation B iU defines a bijection between P 1U and P iU .

We let β be the first-order formula expressing the conjunction of Conditions ( 1)-(3). Each structure U ∈ STR(R ∪ C k ) satisfying β is isomorphic to copy k (S) where S is fg C k (U [P 1U ]).

We denote by ϕ P 1 the relativization of a formula ϕ to the set that is the interpretation of P 1 , i.e., ϕ P 1 is the formula ϕ X in which every atomic formula x ∈ X is replaced by P 1 (x) (and X is a set variable that is not free in ϕ, cf. Lemma 5.10 in Section 5.2.1).

Suppose that τ is defined by

D = χ, (δ i ) i∈[k] , (θ w ) w∈R * [k]
. We construct a definition scheme E = χ , δ , (θ R ) R∈R * for the transduction µ. Its precondition χ has to express in the considered (R ∪ C k )-structure U that there is some structure S such that U is isomorphic to copy k (S) and S |= χ. We define χ to be β ∧ (χ P 1 ).

The domain formula δ must define the set of all elements (a, i) in D U such that S |= δ i (a). This can be done by defining δ (x) as:

P 1 (x) ⇒ (δ 1 P 1 )(x) ∧ 2≤i≤k P i (x) ⇒ ∃y(B i (y, x) ∧ (δ i P 1 )(y)) .
Finally, we must construct relation formulas θ R for R ∈ R * . We use the relations B i to obtain a copy of a given tuple that lies in D S × {1}. Letting n := ρ(R), we have: ((a 1 , i 1 ), . . . , (a n , i n )) ∈ R D(S) if and only if S |= θ R,i1,...,in (a 1 , . . . , a n ).

For fixed i 1 , . . . , i n , we can express this by the formula γ i1,...,in (x 1 , . . . , x n ) defined as: ∃y 1 , . . . , y n 1≤j≤n B ij (y j , x j ) ∧ (θ R,i1,...,in P 1 )(y 1 , . . . , y n ) , where B ij (y j , x j ) is the formula y j = x j ∧ P 1 (x j ) if i j = 1. Therefore, we can define θ R (x 1 , . . . , x n ) as: 1≤i1,...,in≤k

( 1≤j≤n P ij (x j ) ∧ γ i1,...,in (x 1 , . . . , x n )).
Together with Proposition 7.24, we have a factorization of an arbitrary monadic second-order k-copying transduction τ as τ = exp U • copy k • µ where µ is parameterless and noncopying. If k = 1, the factor copy k disappears. If τ is parameterless, the factor exp U disappears. This factorization is useful to prove that inverse monadic second-order transductions preserve recognizability (cf. [START_REF] Blumensath | Recognizability, hypergraph operations, and logical types[END_REF], Theorem 51).

In Section 7.2 we will consider monadic second-order transductions from terms and trees to p-graphs, and we will obtain a logical characterization of the VR-equational sets of p-graphs. Chapter 8 will be devoted to the study of monadic second-order transductions that transform terms and words. Automatabased transducers will be defined, and proved to be equivalent to parameterless monadic second-order transductions. These equivalences generalize the equivalence of finite automata and monadic second-order sentences for the definition of languages (sets of terms or words) stated in Theorem 1.16 and proved in Chapter 5.

We continue with some technical (but useful) notions.

7. If C and C are equivalent, then C = τ (C) and C = τ (C ) for MS-transductions τ and τ . This is implied by the stronger condition that τ and τ are MStransductions such that τ is an injection and τ is its inverse. We have met such a condition when defining strongly equivalent representations of combinatorial objects by relational structures in Definition 7.9.

A finite functional signature F is weak if T (F ) is finite. For not to be weak, F must contain at least one constant symbol and at least one symbol of arity at least 1. It is fat if it contains at least one constant symbol and at least one symbol of arity at least 2. A term t is slim if, for any of its subterms of the form f (t 1 , . . . , t k ), at most one of t 1 , . . . , t k is not a constant symbol (or is not a variable if we consider terms with variables). We denote by Slim(F ) the set of slim terms in T (F ), cf. Proposition 2.85.

Proposition 7.27 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] The following sets of structures11 are pairwise equivalent: paths, directed paths, A * for every nonempty finite alphabet A and Slim(F ) for every finite signature F that is not weak.

(2) The same holds for the following sets: trees, rooted trees, binary rooted trees and T (F ) for every finite fat signature F .

Proof: (1) For transforming a path into a directed path, if suffices to select one of its ends (the MS-definition scheme uses a parameter for doing that). A monadic second-order formula can express the corresponding directions of edges. The inverse transformation is straightforward.

For transforming a directed path into a nonempty word over A, one uses a monadic second-order relabelling that chooses one letter for each position. The empty word can easily be obtained from, e.g., P 1 by an MS-transduction. Then Proposition 7.18 can be used. Again, the inverse transformation is straightforward.

For a finite signature F , let H be the unary finite signature such that H 0 = F 0 and H 1 consists of (or is in bijection with) the tuples of the form f, i, a 1 , . . . , a k-1 for k ≥ 1, f ∈ F k , i ∈ [k] and a 1 , . . . , a k-1 ∈ F 0 . Note that H is weak if and only if F is weak. There is a surjective mapping α from T (H) to Slim(F ), defined as follows: α(c) := c for c ∈ H 0 , and α( f, i, a 1 , . . . , a k-1 (t)) := f (a 1 , . . . , a i-1 , α(t), a i , . . . , a k-1 ). Since α is a linear, strict and nonerasing second-order substitution, it is an invertible FO-transduction by Example 7.3(4). Hence, Slim(F ) and T (H) = Slim(H) are equivalent. Note that α is not injective, e.g., f (a 1 , a 2 ) = α( f, 1, a 2 (a 1 )) = α( f, 2, a 1 (a 2 )).

For a unary finite signature F , there is an obvious bijection between T (F ) and the words in the set (F + ) * F 0 ⊆ F * where F is viewed as a finite alphabet. This bijection and its inverse are MS-transductions. Thus, there is an MStransduction that transforms F * into T (F ), and one that transforms T (F ) into (F + ) * .

(2) For transforming a tree into a rooted tree, it suffices to choose a root and, from this choice, to determine the corresponding direction of the edges. Every rooted tree T can be obtained from a large enough binary rooted tree B by choosing a set U of nodes containing the root (to be the nodes of T ) and by contracting all edges of B with their head not in U (cf. Definition 2.15 in Section 2.2 about edge contractions). This can be formalized by means of an MS-transduction with one parameter intended to specify U (cf. Example 7.3( 1)). Additional parameters can specify node labels that determine the symbol from F attached to each node, and, except for the root, its rank in the sequence of brothers. Using Theorem 7.16, it can be checked that the resulting labelled tree is in T (F ). Hence, one can obtain T (F ) for each finite signature F by contracting edges in some way and by choosing new node labels. Conversely, if F is fat, then the rooted trees can be obtained from T (F ) in the same way as they were obtained from the binary rooted trees.

The detailed constructions of definition schemes are omitted because they are straightforward.

Note that the transductions that relate paths and directed paths define inverse bijections on the corresponding abstract structures, but not on the concrete ones because a concrete path can be directed in two ways.

The set of paths is not equivalent to the set of trees because, by Corollary 7.49 below, the set of trees would have bounded path-width, which is not the case (see Definition 2.57).

The following proposition12 implies that sets are not equivalent to paths. By sets we mean ∅-structures, i.e., graphs without edges. The nodes of a (rooted) tree that are not leaves are its nonleaf nodes (not to be confused with the internal nodes of a rooted tree whose root is defined as a source).

Proposition 7.28 Let τ be a CMS-transduction of type ∅ → {son} that produces rooted (and thus directed) trees. The output trees have a bounded number of nonleaf nodes.

Proof: Let τ be k-copying with p parameters. Let m := k •2 p . Let us assume by contradiction that there is a rooted tree in τ (D) for some set D ∈ STR(∅), that is defined from values D 1 , . . . , D p of the parameters (with D i ⊆ D) and that has more than m nonleaf nodes. There exist two such nodes equal to (a, i) and to (b, i) for some i ∈ [k] and some elements a and b = a of D that belong to the same sets in {D 1 , . . . , D p }. The node (a, i) has a son, say (c, j). But the tuples (D 1 , . . . , D p , a, c) and (D 1 , . . . , D p , b, c) satisfy the same monadic second-order formulas by the choice of (a, b). This implies that (c, j) is also a son of (b, i), hence that a = b. This contradiction completes the proof. This proposition concerns for example the FO-transduction that makes a set of n elements (with n > 2) into the rooted tree (K 1,n-1 , r), where the root r is the unique vertex of degree n -1. A parameter selects a vertex r to be the root and the relation son is defined by son(x, y) :⇐⇒ x = r ∧ y = x.

Since directed paths are particular directed trees, Proposition 7.28 shows that a fixed monadic second-order transduction can define from all sets only paths of bounded length. our two representations of graphs by relational structures with our two graph algebras. They show the robustness of all these notions.

Let us discuss this in some more detail. Instead of trees we consider terms, cf. Proposition 7.27(2). Graphs can be denoted by terms in two ways, either by terms over the signature F VR of the algebra GP or over the signature F HR of the algebra JS. Hence, we have two mappings from terms to graphs, and we will prove that they are both monadic second-order transductions. It follows that every equational set of graphs is the image of a regular set of terms under a monadic second-order transduction. For an HR-equational set L, this is true in a strong sense: the set of incidence graphs of the graphs in L is the image of a regular set of terms under a monadic second-order transduction. Since the regular set is MS-definable, it can be incorporated into the monadic second-order transduction.

Two converse results will be proved: if the image of a set of terms T (F ) under a monadic second-order transduction is a set of graphs, then that set is VR-equational, and similarly, if it is the set of incidence graphs of a set of graphs L, then L is HR-equational. This provides us with characterizations of the VRand HR-equational sets in terms of monadic second-order transductions, that are independent of the signatures F VR and F HR . These characterizations show the robustness of the whole theory. In particular, they yield easy proofs that for some variants of the signature F VR the equational sets of the corresponding algebras are the same (and similarly for F HR ). They also yield, easily, that the classes of VR-and of HR-equational sets of graphs are closed under monadic second-order graph transductions of the relevant types: direct constructions from given equation systems and definition schemes would be impossible to write down in a readable way; all difficulties are concentrated in the Equationality Theorems.

Let us now start the proof of the Equationality Theorem for the VR algebra (the theorem relative to the HR algebra will be proved in Section 7.4). We first show that, for each finite set C of port labels, the mapping val (defined in Section 2.5, Definition 2.87) that associates a p-graph with every term in T (F VR C ), is an MS-transduction.14 Since the domain of a monadic second-order transduction must be a class of structures over a finite relational signature, and since F VR is infinite, we cannot hope to have such a transduction with domain T (F VR ). Hence, we consider the finite subsignatures F VR Proof: We will show that the mapping t → cval (t) C is a concrete parameterless noncopying MS-transduction. This result follows from Lemmas 2.95 and 2.96 (Section 2.5.2) and we will use the notation of these lemmas. Let be given t in T (F VR C ) and G := cval (t) be the associated concrete graph. The vertex set of G is the set Occ 0 (t) of occurrences in t of constant symbols different from ∅. That can be expressed by a quantifier-free domain formula. The edges and ports of G are defined by relation formulas as follows:

(a) If x ∈ V G , there is a loop incident with x if and only if x is an occurrence of c for some c ∈ C. This condition is expressible by a quantifier-free formula interpreted in t .

(b) If x, y ∈ V G with x = y, then (x, y) ∈ edg G if and only if there exist a, b ∈ C and an occurrence u above x and y of one of the symbols --→ add a,b , add a,b or add b,a such that port t (u, x) = a and port t (u, y) = b. This condition is expressible by an MS formula with the help of the following auxiliary formulas: for every port label a there exists an MS formula ϕ a (x 1 , x 2 ) such that, for all x, u in N t , if x ∈ Occ 0 (t) and x ≤ t u, then t |= ϕ a (u, x) if and only if port t (u, x) = a.

We will describe later its construction.

(c) The port mapping of G satisfies port G (x) = port t (root t , x) for every x ∈ V G . Thus, port G (x) = a if and only if t |= ∃y(ϕ a (y, x) ∧ "y is the root").

Hence, to complete the proof that the edges and port labels of G can be determined by MS formulas interpreted in t , we need only describe the formulas ϕ a (x 1 , x 2 ). That is similar to the proof of Theorem 5.15. By Lemma 2.95, the condition port t (u, x) = a (for x ∈ Occ 0 (t) and x ≤ t u) is equivalent to the existence of a family of sets of nodes (X c ) c∈C such that:

(1) it is a partition of the set [x, u] := {w | x ≤ t w ≤ t u},

(2) if x is an occurrence of c or of c , then it belongs to X c , (3) for every w ∈ [x, u] and every c ∈ C, if w ∈ X c is an occurrence of relab h , then its son belongs to X d for some d such that h(d) = c, (4) for every w ∈ [x, u] and every c ∈ C, if w ∈ X c is an occurrence of ⊕ or of an edge addition operation, then its son that belongs to [x, u] is in X c ,

(5) u ∈ X a .

Since these conditions are expressible by a monadic second-order formula, the proof of the first statement is complete.

Let τ be the mapping t → val (t) C with domain T (F VR C ). Let β be a formula over R s,C expressing that a p-graph has type included in D (or has type D). Then the required mapping is (τ ∩ (MOD(True) × MOD(β))) • fg U where U := {lab a | a ∈ C -D}. The second statement now follows from Theorems 7. 16 and 7.14.

The extension to (K, Λ)-labelled graphs is straightforward.

Remarks 7.31

(1) From this proposition, we obtain a short proof of the Weak Recognizability Theorem (Corollary 5.69( 1)), which, by Proposition 3.69, states that the set of terms in T (F VR C ) that evaluate to a p-graph satisfying a CMS sentence ϕ is regular: by Proposition 7. 30 and Backwards Translation (Corollary 7.12), this set of terms is CMS-definable. Hence it is regular by Theorem 6.26. For the algorithmic applications described in Chapter 6 this proof is not satisfactory because it produces a sentence of quantifier-height qh(ϕ) + O(|C|). For this reason, we have given in Chapter 6 direct constructions of automata over F VR C rather than constructions based on Backwards Translation, cf. Remark 6.36.

(2) We also obtain a generalization of the model-checking result of Theorem 6.4(2) to the evaluation of parameter-invariant monadic second-order graph transductions:

There exists a fixed-parameter cubic algorithm that computes τ (G), for a given parameter-invariant monadic second-order graph transduction τ and a given labelled graph G. 15 The parameter of the algorithm is (cwd (G), D), where D is the definition scheme for τ .

The proof is as follows. As shown in Proposition 6.8, a term t over F VR [hΛ(G)], [K,Λ] can be computed in cubic time such that val (t) = G. By Theorem 7.14 and Proposition 7.30 (for D = ∅), val • τ is a parameter-invariant monadic secondorder transduction from terms to graphs. Thus, by Theorem 7.29, the graph τ (G) = (val • τ )(t) can be computed in time O(|t| + τ (G) ).

As discussed after Theorem 6.4, this result also holds for p-graphs.

Corollary 7.32 For every VR-equational set of labelled p-graphs L, there exist a fat finite functional signature F , consisting of binary and nullary symbols, and a parameterless noncopying MS-transduction τ such that L = τ (T (F )).16

Proof: Let L be a VR-equational set of (K, Λ)-labelled p-graphs and let D be the smallest set that includes the types of all p-graphs in L. ) is equivalent to the set of paths. With Proposition 7.30, the result follows.

Our objective is now to establish the converses of these two corollaries. For proving the next theorem we will need a technical lemma.

Theorem 7.34 Let F be a finite functional signature, let K and Λ be finite sets of vertex and edge labels and let D be a finite set of port labels. Let τ : T (F ) → GP [K,Λ] [D] be a monadic second-order transduction, given by a definition scheme of type R F → R s,D, [K,Λ] .

(1) One can construct a finite set C of port labels that includes D and an invertible MS-transduction µ :

T (F ) → T (F VR C,[K,Λ] ) such that τ = µ • val . If τ is parameterless, then so is µ. (2) One can construct a regular language M ⊆ T (F VR C,[K,Λ] -{∅}) ∪ {∅} such that τ (T (F )) = val (M ). The set τ (T (F )) is VR-equational. Furthermore, if Dom(τ ) ⊆ Slim(F ), then µ(T (F )) ⊆ Slim(F VR C,[K,Λ]
) and M is a set of slim terms.

The elements of τ (T (F )) are (K, Λ)-labelled p-graphs G of type included in D, represented by the structures G D in STR(R s,D, [K,Λ] ). The (auxiliary) port labels in C -D will be useful to build the output graphs, but they do not occur in the definition scheme of τ .

We denote by Leaves(t) the set of leaves of the syntactic tree of a term t, i.e., the set of occurrences of constant symbols in t.

Lemma 7.35 Let F be a finite functional signature and τ : T (F ) → STR(R) be a monadic second-order transduction. One can construct a finite functional signature F , a monadic second-order transduction τ : T (F ) → STR(R) and an invertible MS-transduction π : T (F ) → T (F ) such that τ = π • τ and τ (T (F )) = τ (T (F )), and the following conditions hold:

(1) F contains only nullary and binary symbols,

(2) τ is parameterless and noncopying, and

(3) for every t ∈ Dom(τ ), the domain of the concrete R-structure τ (t) is a subset of Leaves(t).

Moreover, if τ is parameterless, then so is π. Furthermore, if Dom(τ ) ⊆ Slim(F ), then F and τ can be constructed in such a way that Dom(τ ) ⊆ Slim(F ).

Proof: We may assume that R 0 = ∅. In three steps we transform (F, τ ) into (F , τ ) that satisfies the required properties (except for the assertion about slim terms).

Step 1: Eliminating parameters If τ is parameterless, there is nothing to do. Otherwise, we let τ be specified by a definition scheme with n parameters forming the set X n . By Proposition 7.24(2), we can write τ as (π F,n ) -1 •τ 1 for the parameterless monadic secondorder transduction τ 1 : T (F (n) ) → STR(R) such that τ 1 ( t * γ ) := τ ( t , γ) for every t ∈ T (F ) and γ : X n → P(N t ). The definition of τ 1 implies that τ 1 (T (F (n) )) = τ (T (F )). The MS-transduction π F,n is invertible since it is a monadic second-order relabelling.

Step 2: Making the transduction noncopying and satisfy Condition (3)

Let (F (n) , τ 1 ) be obtained by the first step. Since the composition of two invertible MS-transductions is invertible (by Theorem 7.14), it suffices to continue the proof with (F (n) , τ 1 ) instead of (F, τ ). If τ 1 is noncopying and Condition (3) holds, there is nothing to do. Otherwise, to simplify the notation, we denote (F (n) , τ 1 ) by (F, τ ). Let τ be k-copying. (We may have k = 1 if Condition (3) is not satisfied). We define F as the functional signature F ∪ { * } with arity mapping ρ such that ρ( * ) := 0 and ρ(f ) := k + ρ(f ) for each f ∈ F . We let λ : T (F ) → T (F ) be defined inductively as follows:

λ(f (t 1 , . . . , t n )) = f ( * , . . . , * , λ(t 1 ), . . . , λ(t n )),
with k occurrences of * . We let also λ be the mapping : N → N defined by λ(u) := u + k(u -1). It maps each position u of t to its corresponding position in λ(t). (Positions are defined as positive integers.) In particular, if u is an occurrence in t of some symbol, then λ(u) is an occurrence of the same symbol in λ(t). We give an example. Let t = f (a, g(b), a) and k = 2. Then λ(t) = f ( * , * , a( * , * ), g( * , * , b( * , * )), a( * , * )). The positions of t are 1,2,3,4,5 and their corresponding positions in λ(t) are respectively 1,4,7,10,13. The mapping λ is injective. Since it is a linear, strict and nonerasing second-order substitution, it is an invertible parameterless (k + 1)-copying MStransduction,cf. Example 7.3(4). Its inverse λ -1 has a definition scheme with particular properties described in the following claim; the construction is easy.

Claim 7.35.1 The partial function λ -1 has a parameterless noncopying MSdefinition scheme E of type R F → R F such that for every t ∈ T (F ), if S is the concrete structure λ(t) , then the domain of the structure E(S) is the subset λ(N t ) of D S and λ is the unique isomorphism between t and E(S).

We let τ := λ -1 • τ . This implies that τ (T (F )) = τ (T (F )) and, since λ is injective, that τ = λ • τ . We now construct a definition scheme for τ that satisfies Conditions (2) and (3). Let τ be given by a definition scheme

D := χ, (δ i ) i∈[k] , (θ w ) w∈ R [k] .
Claim 7.35.2 The partial function τ has a parameterless noncopying definition scheme of type R F → R that satisfies Condition (3).

Proof: By Theorem 7.14 the concrete monadic second-order transduction E • D is parameterless. It transforms a concrete R F -structure S = λ(t) into a concrete R-structure U as follows:

(i) First, by Claim 7.35.1, E transforms S into T isomorphic to t such that D T is the subset λ(N t ) of D S .

(ii) Then τ transforms

T into U such that D U ⊆ D T × [k] = λ(N t ) × [k].
We will construct a parameterless noncopying definition scheme H for τ such that the concrete transduction H transforms S into U isomorphic to U , in such a way that an element (u, i) of D U is replaced in D U by u i , the i-th son of u: this is possible because every node u of λ(t) of the form λ(w) has at least k sons. Furthermore, the first k ones are occurrences of the constant symbol * , hence, Condition (3) will be satisfied.

We construct H = χ , δ , (θ R ) R∈R . Its precondition χ is defined as χ E (cf. Theorem 7.10), which guarantees that H and E • D have the same domain.

For i ∈ [k] and u, v in N λ(t) , the condition λ(t) |= son i (u, v) means that v will replace in D U the pair (λ -1 (u), i) of D U . The domain formula δ is thus defined as:

i∈[k] ∃y(son i (y, x) ∧ (δ i ) E [y/x]).
(In every structure λ(t) , every x satisfying this formula is an occurrence of * , hence corresponds to a leaf of λ(t)).

For each R ∈ R n , the relation formula θ R is:

i∈[k] n ∃y 1 , . . . , y n ( j∈[n] son i[j] (y j , x j )) ∧ (θ R,i ) E [y 1 /x 1 , . . . , y n /x n ] .
It is clear that H( λ(t) ) τ (t) for every t ∈ T (F ). The precondition of H ensures that H(S) is defined only if S λ(t) , and we have noted that H satisfies Condition (3). This completes the proof of the claim.

Hence, the pair (τ , F ) satisfies all requirements of the lemma, except possibly Condition [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF].

Step 3: Making function symbols nullary or binary If (τ , F ) constructed by the previous step satisfies Condition [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF], i.e., if F consists of nullary and binary symbols, there is nothing to do. Otherwise, to simplify the notation, we denote (τ , F ) by (τ, F ). We define F as the signature F ∪ {@, ⊥} with arity mapping ρ such that ρ (f ) := 0 if ρ(f ) = 0 or f = ⊥, and ρ (f ) := 2 if ρ(f ) = 0 or f = @. We let β : T (F ) → T (F ) be defined inductively as follows:

β(f ) = f if ρ(f ) = 0, β(f (t 1 )) = f (β(t 1 ), ⊥) if ρ(f ) = 1, β(f (t 1 , . . . , t n )) = f (β(t 1 ), @(β(t 2 ), . . . @(β(t n-1 ), @(β(t n ), ⊥)) • • • )) with n -1 occurrences of @, if ρ(f ) = n ≥ 2.
The mapping β is injective. Just as λ in Step 2, it is a linear, strict and nonerasing second-order substitution and hence, an invertible parameterless MStransduction. For its inverse β -1 , we can construct a definition scheme with particular properties.

Claim 7.35.3 The partial function β -1 has a parameterless noncopying MSdefinition scheme B of type R F → R F such that, for every t ∈ T (F ), if S is the concrete structure B( β(t) ) and h is the (unique) isomorphism : S → t , then h -1 (Leaves(t)) ⊆ Leaves(β(t)).

Proof: We sketch the construction of the required definition scheme B. It has a precondition expressing that the input structure is isomorphic to β(t) for some t ∈ T (F ). For an input structure β(t) , we let S be the intended output structure. Its domain D S is defined as the set of occurrences of the symbols of F (which excludes the occurrences of @ and ⊥). The set lab f S for f ∈ F is the set of occurrences of f in β(t). Finally, if u, v ∈ D S , we define (u, v) to belong to son iS if and only if:

v ≤ β(t) u and the directed path in Syn(β(t)) from u to v consists of i + 1 nodes, i -1 of which are occurrences of @.

It is clear from this construction of B that, by the isomorphism h -1 , the leaves of t correspond to leaves of β(t) (to be precise, to the occurrences of the symbols of F 0 in β(t)).

To complete the construction of Step 3, we let τ be the concrete transduction β -1 •τ , where β -1 is defined by the scheme B of the previous claim. As in Step 2, this implies that τ (T (F )) = τ (T (F )) and, since β is injective, that τ = β • τ . For the transduction τ , the conditions achieved by the previous two steps are preserved. Condition (2) follows from Theorem 7.14 because both β -1 and τ are parameterless and noncopying. For Condition (3), we observe that B transforms the structure β(t) for every t ∈ T (F ) into a structure S isomorphic to t , by an isomorphism h : S → t . By the observations made in Definition 7.2, τ (S) is isomorphic to τ ( t ) by h := h D τ (S) . We have:

D τ (S) = h -1 (D τ ( t ) ) ⊆ h -1 (Leaves(t)) ⊆ Leaves(β(t)).
Hence, τ transforms a term t of the form β(t) into a concrete structure with domain (the set D τ (S) in the above proof) included in Leaves(t ).

Since F satisfies Condition [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF], this completes the proof of Step 3 and of the first assertion of the lemma. It remains to consider the assertion about slim terms.

If the signature F is unary, then the signature constructed in Step 1 is also unary. The function symbols constructed in Step 2 have arity at most k + 1, and Step 3 constructs a binary signature. It is clear that if t ∈ T (F ), then the term β(λ(t)) is slim. Hence, the domain of the transduction τ consists of slim terms.

In the more general case where Dom(τ ) ⊆ Slim(F ) we precede Step 1 by a preliminary Step 0 in which we replace (F, τ ) by (H, τ 0 ) where H is unary, as follows. Let H and α be defined as in the third paragraph of the proof of Proposition 7.27. Hence, the surjective mapping α : T (H) → Slim(F ) is an invertible MS-transduction of type R H → R F . Now let τ 0 := α • τ . Then τ 0 (T (H)) = τ (T (F )), and τ = α -1 • τ 0 because α is a mapping (and so α -1 • α is the identity on Slim(F )). Note that α is not injective. If τ is parameterless, then we can make α injective by restricting it to the MS-definable set of terms t ∈ T (H) such that if f, i, a 1 , . . . , a k-1 (a) is a subterm of t with a ∈ H 0 , then i = 1. Then the resulting α -1 is a parameterless MS-transduction with the same properties as above.

Proof of Theorem 7.34: We will first prove Assertion (1) and then, we will use it to prove Assertion (2). Assertion [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] We now prove Assertion (1). We will assume that F and τ satisfy the three conditions of Lemma 7.35 (without the primes). This is not a loss of generality because this lemma shows how to replace, if necessary, a pair (F, τ ) by one that satisfies these conditions. So, we assume that F has only symbols of arity 0 and 2, that τ is parameterless and noncopying, and that for every t ∈ Dom(τ ), the vertex set of the concrete p-graph τ (t) is a subset of Leaves(t).

We will first give the proof for unlabelled p-graphs, and later extend it to the labelled case. Moreover, we will first prove Assertion ( 1 ) such that Dom(µ) = Dom(τ ) ⊆ T (F ) and, for every t ∈ Dom(τ ), the concrete p-graph τ (t) is equal to cval (µ(t)). 17 The port labels in C -D will be bounded theories (cf. Definitions 5. 59 and 7.21). The pairs of port labels (a, b) ∈ R such that ⊗ R,h occurs at u in µ(t) will trigger the creation of the edges between the vertices of τ (t) below u 1 and those below u 2 , where u 1 and u 2 are the two sons of u. The precise definitions of R and h that form the operation ⊗ R,h occurring at a node u will be based on Application 5.61 where bounded theories are computed. These R and h will be denoted by R u and h u . The constant symbol occurring at a leaf x in µ(t) will be denoted by c x .

The transductions τ and µ take terms as inputs. We know from Section 5.2.6 (Propositions 5. 29 and 5.30) that cardinality predicates bring no expressive power to MS formulas on terms. Hence, without loss of generality, we will only consider MS formulas, i.e., monadic second-order formulas without cardinality predicates.

We will denote the concrete p-graph τ (t), of type included in D, by G(t). Thus, we will define µ such that G(t) = cval (µ(t)). Letting D be fixed, we will identify G(t) with the concrete R s,D -structure D( t ) = G(t) D , where D = χ, δ, θ edg , (θ lab d ) d∈D is the given definition scheme D of τ . The precondition χ of D will also be the precondition of the definition scheme of µ. We will define the label c x of a leaf x of t in µ(t) to be ∅ if and only if t |= δ(x), thus guaranteeing that V G(t) = Occ 0 (µ(t)).

In order to simplify the exposition of the main part of the proof, we will additionally assume that every p-graph G(t) is without loops. This restriction will be lifted at the end of the proof.

The (technical) proof will consist of 5 steps and some final steps. We need some notation in addition to that of Definition 5.59 and Application 5.61 (Section 5.3.6) which the reader is assumed to have in mind. As in Application 5.61, the relational signature R F has a constant symbol for the root of the represented terms. We let q be the maximum quantifier-height of the relation formulas of D. We define the following finite sets of formulas:

L 2 := MS q (R F , {x 1 , x 2 }), L 1 := MS q (R F , {x 1 }), L 0 := MS q (R F , ∅), L 0 := MS q (R F ∪{w} , ∅),
where w is the special variable used to define contexts. For a term t in T (F ) and a node u ∈ N t , we let First(u) := 1 if u is the left son of its father or u is the root, and First(u) := 2 otherwise.

We now describe the main construction for an input term t in T (F ) such that G(t) is defined (i.e., t ∈ Dom(τ )).

Step 1: With every nonleaf node u in N t with sons u 1 and u 2 , we associate:

Θ(u) := (Θ 0 (u), Θ 1 (u), Θ 2 (u))
where Θ 0 (u) := Th(t, ↑u, q, 0, ε) ⊆ L 0 and Θ i (u) := Th(t, ↓u i , q, 0, ε) ⊆ L 0 for i = 1, 2. (See Application 5.61 for notation.) This information is MS-expressible: for each Θ in P(L 0 ) × P(L 0 ) × P(L 0 ), there is an MS formula Ψ Θ (x) such that, for every nonleaf node u of t, we have t |= Ψ Θ (u) if and only if Θ(u) = Θ.

We only give the construction of the formula Ψ Φ (x) such that, if u is a nonleaf node, then t |= Ψ Φ (u) if and only if Θ 0 (u) = Φ. For every subset Φ of L 0 , we define Ψ Φ (x) as:

∃X(∀y(y ∈ X ⇔ ¬(y < x)) ∧ ϕ∈Φ ϕ(X, x) ∧ ϕ∈L 0 -Φ ¬ ϕ(X, x) ),
where y < x is a formula expressing that y is strictly below x, and where, for each ϕ, the formula ϕ(X, x) is obtained from ϕ X, the relativization of ϕ to X (cf. Section 5.2.1), by the replacement of each atomic formula lab w (z) by z = x and each atomic formula lab f (z) (where f ∈ F ) by z = x ∧ lab f (z). It is clear that t |= Ψ Φ (u) if and only if t ↑ u |= ϕ for every ϕ in Φ and t ↑ u |= ¬ϕ for every ϕ in L 0 -Φ.

A similar construction can be done for the MS-expression of Θ 1 (u) and Θ 2 (u).

Step 2: We define the set of port labels C as C ∪D where C := P(L 1 )×{1, 2}, where we assume that C ∩ D = ∅. We define a partial function p : N t × N t → C as follows. For u ∈ N t and x ∈ V G(t) such that x ≤ t u:

p(root t , x) := port G(t) (x) ∈ D p(u, x) := (Th(t, ↓u, q, 0, x), First(u)) ∈ C if u = root t .
Note that p(u, x) ∈ D if and only if u is the root (and then p(u, x) is defined for every x ∈ V G(t) ). We have defined an element of C as a pair (Θ, i) where Θ is any subset of L 1 , but only those such that Θ = Th(t, ↓u, q, 0, x) for some t, u and x will occur in the operation symbols of the terms in µ(T (F )). For instance, the subsets of L 1 that contain a formula and its negation cannot be of the form Th(t, ↓u, q, 0, x).

Step 3: The objective is now to define µ(t) in such a way that the partial function port µ(t) (defined in Definition 2.94) is the function p of Step 2, i.e., such that port cval(µ(t))/u (x) = p(u, x) for every u ∈ N t and x ∈ V u := {x ∈ V G(t) | x ≤ t u}. For this purpose, we will define a family of mappings h u : C → C, associated with the nonleaf nodes u of t such that, for each such node and each leaf x in V u , we have:

p(u, x) = (h u • h v1 • • • • • h vn )(p(x, x)),
where (u, v 1 , . . . , v n , x) is the path in Syn(t) from u to x. (We have n = 0 if u is the father of x). The values h u (d) for d ∈ D will not be needed, so we define (arbitrarily) h u (d) := d. The values h u (c ) for c ∈ C are defined with the use of Application 5.61. We let f be the binary function symbol at u in N t , and u 1 and u 2 be the sons of u.

Case 1: u is not the root. By Equation (5.6) in Application 5.61, if x ≤ t u 1 , we have: Th(t, ↓u, q, 0, x) = Z f * ,q,0,(0,1,0) (Th(t, ↓u 1 , q, 0, x), Th(t, ↓u 2 , q, 0, ε)), and, if x ≤ t u 2 : Th(t, ↓u, q, 0, x) = Z f * ,q,0,(0,0,1) (Th(t, ↓u 1 , q, 0, ε), Th(t, ↓u 2 , q, 0, x)).

We have Th(t, ↓u i , q, 0, ε) = Θ i (u) for i = 1, 2 by Step 1. We define h u such that h u (C ) ⊆ C as follows:

h u ((Θ, 1)) := (Z f * ,q,0,(0,1,0) (Θ, Θ 2 (u)), First(u)) and h u ((Θ, 2)) := (Z f * ,q,0,(0,0,1) (Θ 1 (u), Θ)), First(u)).

The function h u is defined for all pairs (Θ, i) in C , even for those such that Θ is empty or contains contradictory formulas.

Case 2: u = root t . We let h u : C → C be the function h u defined as in Case 1. If (u, v 1 , . . . , v n , x) is the directed path in Syn(t) from u to x, then:

(Th(t, ↓u, q, 0, x), 1) = (h u • h v1 • • • • • h vn )(p(x, x)).
We can obtain port G(t) (x) from Th(t, ↓u, q, 0, x) (that is Th(t, ↓root t , q, 0, x)) because port G(t) (x) = d if and only if t |= θ lab d (x) if and only if θ lab d ∈ Th(t, ↓root t , q, 0, x). Note that by the assumption that τ (t) is a p-graph, there is a unique d ∈ D with these properties for each vertex x of G(t). Hence we can define h u such that h u (C ) ⊆ D as follows:

h u ((Θ, i)) := d ∈ D such that θ lab d ∈ Θ where (Θ , 1) = h u ((Θ, i)).
If there are several such d, or none, we take for h u ((Θ, i)) an arbitrary, but fixed, element of D. For the pairs (Θ, i) arising from a term t, there is a unique such d. The definition of h u handles the other cases to ensure that h u is a total function. It follows that:

port G(t) (x) = (h u • h v1 • • • • • h vn )(p(x, x)).
This ends Case 2 and the definition of h u .

Since the sets Θ i (u) (defined in Step 1) are MS-expressible, the same holds for the functions h u attached to the nonleaf nodes u of t. We mean by this that for each mapping h : C → C, there is an MS formula Ψ h (x) such that t |= Ψ h (u) if and only if h u = h.

We now define the labels c x in µ(t) for every leaf x of t. If x ∈ V G(t) is not the root, we let c x be the constant symbol c where c = (Th(t, ↓x, q, 0, x), First(x)) = p(x, x). If x ∈ V G(t) is the unique node of t, we let c x be d, such that port G(t) (x) = d. If x is a leaf of t that is not in V G(t) , we let c x be ∅.

These constant symbols are MS-expressible: the set Th(t, ↓x, q, 0, x) only depends on the label of x in t, x is in V G(t) if and only if t |= δ(x), and port G(t) (x) = d if and only if t |= θ lab d (x).

Hence, we have defined the constant symbol c x to be attached by µ at each leaf x of t and the mapping h u of the new label to be attached at each nonleaf node u. This achieves the goal of representing p as the partial function port µ(t) . We have thus port G(t) (x) = p(root t , x) = port µ(t) (root t , x) = port cval(µ(t)) (x) for each vertex x of G(t). It remains to complete the definition in such a way that µ(t) evaluates to G(t), i.e., that G(t) • = cval (µ(t)) • .

Step 4: We will define for each nonleaf node u of t a relation R u ⊆ C × C such that the operation ⊗ Ru,hu attached to this node in µ(t) has the effect of creating the edges between the vertices of G(t) below u 1 and those below u 2 and only these edges. This implies that (cval (µ(t))/u) • = (G(t)[V u ]) • where, as above, V u := {x ∈ V G(t) | x ≤ t u}; note that this equation also holds if u is a leaf x, by the definition of c x .

If x, y ∈ V u1 ∪V u2 ⊆ V G(t) , then (x, y) ∈ edg G(t) if and only if t |= θ edg (x, y). Let x ∈ V u1 and y ∈ V u2 . We know from Equation (5.5) in Application 5.61 that Th(t, ↓root t , q, 0, xy) ⊆ L 2 is equal to: Z f † ,q,0,(0,1,1) (Th(t, ↑u, q, 0, ε), Th(t, ↓u 1 , q, 0, x), Th(t, ↓u 2 , q, 0, y)).

We have Th(t, ↑u, q, 0, ε) = Θ 0 (u) by the definition in Step 1. Hence we can define R u := R 1u ∪ R 2u where R 1u is the set of pairs ((Θ, 1), (Θ , 2)) such that θ edg ∈ Z f † ,q,0,(0,1,1) (Θ 0 (u), Θ, Θ ) and R 2u is the set of pairs ((Θ , 2), (Θ, 1)) such that θ ∈ Z f † ,q,0,(0,1,1) (Θ 0 (u), Θ, Θ ) where θ is

θ edg [x 2 /x 1 , x 1 /x 2 ].
Again, as above for the h u 's and the c x 's, the relations R u can be expressed by MS formulas.

Step 5: Here is the final definition of µ(t): at a nonleaf node u, we attach the operation ⊗ Ru,hu (where R u and h u are defined respectively in Steps 4 and 3); at a leaf x, we attach the constant symbol c x (cf.

Step 3).

From previous observations made in Steps 3 and 4, we get that µ(t) is a monadic second-order relabelling. Its domain formula is the one of D.

It is clear from the construction that the port labels and the edges of G(t) are defined correctly by µ(t). Hence G(t) = cval (µ(t)) for every t ∈ Dom(τ ) = Dom(µ).

Final steps: A few things remain to be done for completing the proof of Assertion [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF].

(a) First, we waive a restriction made initially to simplify the proof. Let us consider the case where G(t) may have loops: a vertex x has a loop if and only if t |= θ edg (x, x). In this case, we let c x be c or d where c and d are defined as in Step 3.

(b) Then, we consider the case of (K, Λ)-labelled graphs. We handle vertex labels as we did for loops: we modify in the appropriate way the constant symbols c x . Since vertex labels are MS-expressible in t , the new c x 's are still determined by MS formulas. For defining Λ-labelled edges, we replace in the operations ⊗ R,h the binary relation R on port labels by a ternary relation R ⊆ C × C × Λ (cf. the paragraph before Proposition 2.103). The extension is then straightforward. Labelled loops at a vertex x are defined as its labels, in the constant symbols c x .

(c) We can replace

F κVR C,[K,Λ] by F VR C,[K,Λ]
: By the definition of the operations ⊗ R,h , there is a linear, strict and nonerasing second-order substitution θ :

T (F κVR C,[K,Λ] ) → T (F VR C,[K,Λ]
) such that t and θ(t) are equivalent terms for every t in T (F κVR C ) (cf. Proposition 2.121). Then θ is a parameterless invertible MS-transduction by Example 7.3(4). Clearly, θ preserves the slimness of terms. Hence, if µ :

T (F ) → T (F κVR C,[K,Λ]
) is the monadic second-order relabelling constructed above, then the MS-transduction µ := µ • θ :

T (F ) → T (F VR C,[K,Λ]
) is the required one, i.e., we have τ = µ • val .

This completes the proof of Assertion [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF].

Let us now prove Assertion (2). In the first paragraph of this proof, we have shown that τ (T (F )) = val (N ) for the regular language N = µ(T (F )) ⊆ T (F VR C, [K,Λ] ). Since we have defined c Proof: For convenience, we abbreviate F VR C,[K,Λ] by F . We will construct a finite functional signature H, a parameterless monadic second-order relabelling α : T (F ) → T (H) and a linear second-order substitution β : T (H) → T (F -{∅}) ∪ {∅} such that t and β(α(t)) are equivalent terms for every t in T (F ).

x := ∅ if x ∈ Leaves(t) -V G(t) in
Then we define M := β(α(N )). Clearly, val (M ) = val (N ). Moreover, M is regular by Proposition 7.22(3) (for α) and by Corollary 3. 19 and Proposition 3.41 (for β).

We define H such that H 0 := F 0 , H 1 := F 1 × {0, 1} and H 2 := {⊕} × {0, 1} 2 . Let t be a term in T (F ). For every node u in N t we define em(u) := 0 if val (t/u) = ∅ and em(u) := 1 otherwise. Since val (t/u) = ∅ if and only if all leaves of t below u are occurrences of ∅, the property em(u) = 0 is MSexpressible. Thus, α can be constructed such that if u is an occurrence of f ∈ F , then α relabels u with f, em(u) if f ∈ F 1 and with f, em(u 1 ), em(u 2 ) if f = ⊕ where u 1 and u 2 are the sons of u (the labels of the leaves stay the same).

We define β : T (H) → T (F ) by interpreting the symbols of H as derived operations of F , defined by the following terms with variables: each constant is defined by itself; for f ∈ F 1 , the symbol f, 1 is defined by f (x 1 ) and the symbol f, 0 by ∅; finally, ⊕, 1, 1 is defined by ⊕(x 1 , x 2 ), ⊕, 1, 0 by x 1 , ⊕, 0, 1 by x 2 , and ⊕, 0, 0 by ∅. Note that β is linear, but neither strict nor nonerasing.

Using the relevant equations in Proposition 2.101, it can easily be shown by induction on the structure of t ∈ T (F ) that t and β(α(t)) are equivalent terms, and that β(α(t)) is in T (F -{∅}) ∪ {∅}. ) are binary, and they create edges between their two disjoint argument p-graphs, but not inside these p-graphs. This implies that an edge linking two vertices is necessarily created by such an operation occurring at the least common ancestor in t of the two leaves corresponding to these vertices.

We denote by trees the set of (undirected, unrooted) trees.

Theorem 7.36 (Equationality Theorem for the VR algebra) Let L be a set of possibly labelled p-graphs of bounded type. The following conditions are equivalent:

(1) L is VR-equational,

(2) L is the image of trees under an MS-transduction. 18 (3) L is the image of trees under a CMS-transduction.

Proof: (1) =⇒ ( 2) is immediate from Corollary 7. 32 and Proposition 7.27(2).

(3) =⇒ [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. Let L = τ ( trees ) where τ is a CMS-transduction. Hence L = τ ( T (F ) ) where F is some finite fat signature (because then T (F ) is 18 More precisely, this means (in the case where the p-graphs in L are (K, Λ)-labelled) that there is an MS-transduction τ of type Rs → R s,D, [K,Λ] such that L = τ ( trees ), where D is the smallest set of port labels such that π(G) ⊆ D for every G ∈ L.

equivalent to trees by Proposition 7.27(2)) and τ is a CMS-transduction. (For any such F , some transduction τ can be constructed). By Theorem 7.34, the set L is VR-equational.

In statements (2) and (3) one can replace trees by T (F ) for any finite fat signature F or by any other equivalent set like that of binary rooted trees, by Proposition 7.27(2). Theorem 7.36 yields a characterization of the VRequational sets of p-graphs that is based on logic, in contrast with their algebraic (or, grammatical) definition based on least solutions of equation systems. This characterization makes no a priori use of the signature F VR , but establishes that it (or a variant of it) is the right one.

As a first corollary of Theorem 7.36 we obtain that the alternative signature F iVR , introduced before Proposition 2.119, leads to the same equational sets as F VR . The signature F iVR is obtained from F VR by allowing a = b for the edge addition operations add a,b . Thus, every VR-equational set is also iVRequational (i.e., equational for the F iVR -algebra). It is clear that Section 2.5.2 also holds for F iVR , and hence so do Proposition 7.30 and Corollary 7.32. From the resulting Corollary 7.32 we obtain that for every set iVR-equational set L, the set of structures L is the image of T (F ) under an MS-transduction, for some fat signature F . It now follows that L is VR-equational from Proposition 7.27.

As a second corollary of Theorem 7.36 we obtain that the class of VRequational sets of p-graphs is (effectively) closed under monadic second-order p-graph transductions. This generalizes the logical version of the Filtering Theorem for the VR algebra (Corollary 5.70 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]): the identity Id K on a CMS-definable set of p-graphs K is clearly a CMS-transduction (with a precondition defining K) and Id K (L) = L ∩ K for every set of p-graphs L.

Corollary 7.37 The image of a VR-equational set of labelled p-graphs under a monadic second-order p-graph transduction is VR-equational.

Proof: Let L be VR-equational and let L = L D . Then L D = τ (trees) for some MS-transduction τ , by Theorem 7.36 (for convenience, we write trees instead of trees ). Let θ be a monadic second-order p-graph transduction, represented by a CMS-transduction θ of type R s,D → R s,E (as usual we first consider unlabelled graphs). Then:

θ(L) E = θ ( L D ) = θ (τ (trees)) = (τ • θ )(trees).
Since, for every E ⊆ E, the representations • E and • E are strongly MSequivalent (Definition 7.9), there is an MS-transduction α such that θ(L) = (τ • θ • α)(trees). Hence θ(L) is VR-equational by Theorems 7.14 and 7.36. The proof is the same for labelled graphs.

As a third corollary we obtain a logical characterization of the sets of pgraphs of bounded clique-width.

A graph G in C is a split graph if V G = A ∪ B, A ∩ B = ∅, A is stable (G[A]
has no edges) and B is a clique in G. (If A and B are both nonempty, there are edges between A and B). Split graphs are chordal (cf. Definition 2.71). For every graph G and k > 1, we let und (G) k be the simple undirected graph with vertex set V G and edges between any two distinct vertices at distance exactly k in und (G).

Proposition 7.39

(1) The classes of split graphs, of chordal graphs and of tournaments have unbounded clique-width.

(2) There exists a computable function f : N × N → N such that, for every graph G and k > 1, we have cwd (und (G) k ) ≤ f (k, cwd (G)).

Proof: (1) Let S be the class of split graphs. Let τ be the MS-transduction that takes a simple undirected graph G, finds sets A and B witnessing that it is a split graph and removes A and all edges u -v of G[B] such that u -x -v for some vertex x in A of degree 2. If G is not a split graph, then there is no output. Then τ (S) is the class of all simple loop-free undirected graphs, and this class has unbounded clique-width. (This follows from Corollary 2.122 and also from Proposition 2.106(1)). So does S by Corollary 7.38(2). The same also holds for chordal graphs. Hence, although they can be constructed as trees of cliques (cf. Section 2.4.4), and cliques have clique-width at most 2, chordal graphs have unbounded clique-width. We now describe an FO-transduction τ that transforms the class of tournaments into the class of simple loop-free undirected graphs. Let G be a tournament (i.e., an orientation of a clique) and X be a set of vertices such that, for every x ∈ X, there are exactly two edges with tail x and head in V G -X. Then, we define τ (G, X) as the graph H such that V H = V G -X and y -H z if and only if x → G y and x → G z for some x ∈ X. Every simple loop-free undirected graph H is τ (G, X) for some tournament G such that V G ⊇ V H and |X| = |E H |. Hence, we obtain that tournaments have unbounded clique-width. We have already proved this fact in a different way by a counting argument (Proposition 2.114(3)).

(2) It suffices to note that, for each k > 1, the mapping G → und (G) k is an FO-transduction and to apply Corollary 7.38(2).

The following proposition shows that the unbounded clique-width of tournaments can be viewed as a consequence of the unbounded tree-width of cliques. It was already stated in Proposition 2.117.

Proposition 7.40 There exists a computable function g : N → N such that, for every simple undirected graph G, we have twd (G) ≤ g(max{cwd (H) | H ∈ und -1 (G)}). If a class of simple directed graphs is closed under arbitrary changes of edge directions and has bounded clique-width, then it has also bounded tree-width.

Proof: We will use the following claim whose proof is easy to extract from that of Lemma 2.3 of [START_REF] Courcelle | The monadic second-order logic of graphs VIII: Orientations[END_REF].

Claim 7.40.1 One can construct a monadic second-order graph transduction τ such that, for every undirected graph G and every odd integer n ≥ 3, if the undirected rectangular grid G u (2n-1)×( n+1) is a minor of G, then G has an orientation H such that G u n×(n+1) ∈ τ (H). Let k be an integer and G be a simple undirected graph, every orientation of which has clique-width at most k. Let m be the smallest odd integer larger than 3 and the integers f τ (i) for all i ∈ [k], where τ is constructed by Claim 7.40.1 and f τ is the computable function of Corollary 7.38(2).

Then G does not contain G u (2m-1)×(m+1) as a minor because otherwise, by the claim, it would have an orientation H such that G u m×(m+1) ∈ τ (H); then cwd (H) ≤ k, so that, by Corollary 7.38(2), we have cwd (G u m×(m+1) ) ≤ m, but we know from Proposition 2.106(1) that cwd (G u m×(m+1) ) ≥ m + 1. Hence, G does not contain G u (2m-1)×(m+1) as a minor and thus, by Proposition 2.61, its tree-width is at most g(k) := f (G u (2m-1)×(m+1) ), where f is a fixed computable function. Hence g is the required computable function.

The second assertion follows immediately.

Linear equation systems and linear clique-width

A context-free grammar is linear if the righthand side of each rule contains at most one occurrence of a nonterminal ([*Har, *Ber]). Similarly, we say that a (polynomial) equation system S is linear if each monomial in the righthand side of each equation of S contains at most one occurrence of an unknown. A linear equational set of an algebra is a set defined in that algebra by a linear equational system. A set of p-graphs is linear VR-equational if it is linear equational in the algebra GP, and a linear HR-equational set of s-graphs is defined similarly.

For k ≥ 1, we say that a term t is k-slim if, for each of its subterms of the form f (t 1 , . . . , t k ), at most one of t 1 , . . . , t k has size |t i | > k. We denote by Slim k (F ) the set of all k-slim terms over a signature F ; note that Slim 1 (F ) = Slim(F ). It is straightforward to prove that for every linear equation system S over F and every y ∈ Unk (S), we have µx • S P(T(F )) (x) y ⊆ Slim k (F ) where k is the maximal size of a monomial in the righthand side of an equation of S; the proof is by fixed-point induction (Proposition 3.91 with

K = K i = Slim k (F )).
The linear clique-width lcwd (G) of a graph G has been defined in Definition 2.89 with respect to slim terms, whereas clique-width is defined with respect to arbitrary terms over F VR . It is to clique-width what path-width is to tree-width. We let paths denote the set of paths.

Theorem 7.41

(1) A set of labelled p-graphs of bounded type is linear VR-equational if and only if it is the image of paths under an MS-transduction (or, a CMStransduction).

(2) A set of labelled p-graphs of bounded type has bounded linear cliquewidth if and only if it is included in the image of paths under a monadic second-order p-graph transduction (MS or CMS).

(3) For every monadic second-order p-graph transduction τ , there exists a computable function f lin τ : N → N such that for every (possibly labelled) p-graph G and every (possibly labelled) p-graph H in τ (G), we have lcwd (H) ≤ f lin τ (lcwd (G)).

Proof: (1) Let L be a linear VR-equational set of (K, Λ)-labelled p-graphs. As in the proof of Corollary 7.32, we obtain that L = val (R) where R is a regular set of terms over F := F VR C,[K,Λ] and, by the above observation, R ⊆ Slim k (F ) for some k ≥ 1. Then L = τ ( Slim k (F ) ) for an MS-transduction τ . Generalizing the proof of Proposition 7.27(1) (taking a i ∈ T (F ) such that |a i | ≤ k), it is clear that Slim k (F ) is equivalent to paths.

Now let L = µ( paths ) for a CMS-transduction µ. Then, by Proposition 7.27 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF], L = τ (Slim(F )) for some finite functional signature F and some monadic second-order transduction τ : T (F ) → GP [K,Λ] [D]. Since it is clear that Slim(F ) is MS-definable, we may assume that Dom(τ ) ⊆ Slim(F ) by Theorem 7.16, and hence L = τ (T (F )). By Theorem 7.34, L = val (M ) for a regular set M ⊆ Slim(F ) with F := F VR C, [K,Λ] . Let S be an equation system over F and let Y ⊆ Unk (S) such that (S, Y ) defines M in T(F ) and L in GP. By Propositions 3.39 and 3.37, we may assume that each unknown of S defines an infinite set of terms and is useful for Y . Then we can show that S is a linear equation system, and hence L is linear VR-equational. In fact, assume that S is not linear. Then the regular grammar G(S), defined in Definition 3.17, has a rule x → t such that t has at least two occurrences of an unknown. Since x is useful for Y and S is trim, there exist y ∈ Y , c ∈ Ctxt(F ) and s ∈ T (F , Unk (S)) such that y ⇒ * G(S) c[s], s has exactly two occurrences of an unknown: u 1 of x 1 and u 2 of x 2 (possibly x 1 = x 2 ), and root s is the least common ancestor of u 1 and u 2 in s, cf. Remarks 3.38 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]2). Since x i defines an infinite set of terms, there exist terms t 1 and t 2 (possibly equal) in T (F ) such that x i ⇒ * G(S) t i and

|t i | > 1. Then y ⇒ * G(S) s := c[s[t 1 /x 1 , t 2 /x 2
]] and so s ∈ M . However, s is not slim because the root of its subterm s[t 1 /x 1 , t 2 /x 2 ] has two sons that are not constant symbols. This contradicts the fact that M consists of slim terms.

(2) The only-if direction was proved in Corollary 7.33. In order to prove the converse, we let L be a subset of µ(paths) for some monadic second-order p-graph transduction µ. This implies, as shown in the second part of [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF], that L ⊆ val (M ) for a regular set M ⊆ Slim(F VR C, [K,Λ] ). It follows that L has linear clique-width at most |C|.

(3) Let τ be a monadic second-order p-graph transduction that transforms (K, Λ)-labelled graphs into (K , Λ )-labelled ones. Let L be the set of (K, Λ)labelled graphs of linear clique-width at most k and of type included in a finite set D. It is the image of Slim(F VR C ) under the MS-transduction val (by Proposition 7.30) for some C of cardinality k that includes D. Hence, τ (L) is the image of Slim(F VR C ,[K,Λ] ) under the MS-transduction val • τ . Hence, as in (2), its linear clique-width is bounded by a value computable from k and a definition scheme of τ .

Note that the first statement of this theorem implies that Corollary 7.37 also holds for linear VR-equational sets.

The Semi-Linearity Theorem for VR-equational sets

We fix n ≥ 1 and we let X denote the n-tuple of set variables (X 1 , . . . , X n ). If γ is an X-assignment in a structure S, we let:

- → #γ := (|γ(X 1 )|, . . . , |γ(X n )|) ∈ N n .
If S ∈ STR c (R) and ϕ ∈ CMS(R, X), we let:

- → #sat(S, ϕ, X) := { - → #γ | (γ(X 1 ), . . . , γ(X n )) ∈ sat(S, ϕ, X)}
and if L ⊆ STR c (R), we let:

- → #sat(L, ϕ, X) := { - → #sat(S, ϕ, X) | S ∈ L} ⊆ N n .
For the notion of a semi-linear subset of N n see Section 3.1.6.

Theorem 7.42 If L is a regular set of terms, a VR-equational set of graphs or, more generally, the image of trees under a CMS-transduction from trees to R-structures, then the set -→ #sat(L, ϕ, X) associated with a CMS formula ϕ in CMS(R, X) is semi-linear.

Proof: We first consider the case of a regular set of terms L ⊆ T (F ). It suffices to prove the result for L = T (F ): since L is MS-definable, there is a sentence ψ such that L = {t ∈ T (F ) | t |= ψ}, and hence

- → #sat(L, ϕ, X) = - → #sat(T (F ), ψ ∧ ϕ, X).
notations are used for transductions that transform p-graphs, s-graphs, terms or words.

A C r MS i,j -transduction is a transformation of objects, defined by a C r MStransduction of the appropriate type, transforming structures that faithfully represent the objects. For i = 1 and j = 1 we assume that the objects are labelled p-graphs (including simple graphs, terms and words) and for i = 2 and j = 2 that they are labelled s-graphs (including graphs, terms and words). 20 For example, if we say that τ is a C r MS 1,2 -transduction, this will mean that it is a set of pairs (G, H) such that G is a p-graph represented by G C (for some finite C) and H is an s-graph represented by H D (for some finite D), defined by a C r MS-definition scheme. Note that a CMS 1,1 -transduction is a monadic second-order p-graph transduction. If necessary, we will make precise the relational signatures used for representing the considered objects.

Let us give more details about the relational structure Inclusions between the four classes of monadic second-order graph transductions, and examples showing proper inclusions and incomparability results have been discussed in Section 1.8.2. For the reader's convenience, we reproduce Table 1.1 of Section 1.8.2. Some of these inclusions follow from Theorem 7.14 and the obvious fact that the transformation of G into G is an MS-transduction (and even an 20 We identify a word w over a finite alphabet A with the vertex-labelled simple graph G(w) defined in Example 5.2(2), and a term t over a finite signature F with the labelled simple graph Syn(t) defined in Definition 2.14, cf. the paragraph before Corollary 5.23.

21 G := Inc(G) , for a graph G. If G is directed, then Inc(G) := V G ∪ E G , in 1G , in 2G ,
21 All variants defined in Section 5.2.5 are strongly FO-equivalent (Definition 7.9). Hence the results to be stated below also hold for them. We refer the reader to Definition 5.17 for the extension of these definitions to the representation of labelled graphs.

22 Note that in the undirected (unlabelled) case, the signature

R u m,C of G C is the signature R s,C in which edg is changed into in. Similarly in the directed (unlabelled) case, R d m,C is R s,C,[∅,{1,2}] with the same change. CMS 2,1 - CMS 1,1 ∪ CMS 2,2 - - CMS 1,1 CMS 2,2 - - CMS 1,1 ∩ CMS 2,2 - CMS 1,2
Table 7.1: The different classes of monadic second-order graph transductions.

FO-transduction), in other words that the identity on simple graphs is an MS 2,1transduction. On certain classes C of simple graphs the identity : C → C is also an MS 1,2 -transduction. This means that the transformation of G into G for G ∈ C is an MS-transduction, and it follows that certain of the proper inclusions of Table 7.1 become equalities. Let C be such a class, and i be 1 or 2. Then:

(1) every C r MS 2,i -transduction with domain included in C is (effectively) a C r MS 1,i -transduction;

(2) every C r MS i,1 -transduction with image included in C is (effectively) a C r MS i,2 -transduction.

We have seen in Example 7.8 that the class C of forests is such a class, and hence so is the class trees. A similar proof shows that, for any finite functional signature F and any finite alphabet A, the sets of terms T (F ) and the sets of words A * are such classes, cf. Corollary 5.23. Thus, the four types of transductions of terms (or words) are all the same. There are only two types of transductions from trees (or terms, or words) to graphs, because in this case and for each i = 1 or 2, the C r MS 1,i -and the C r MS 2,i -transductions are the same, with effective translations between the definition schemes of different types. In Section 9.4.1 (Theorem 9.44) we will prove that for every class C of simple and uniformly sparse (labelled) graphs, the identity : C → C is an MS 1,2 -transduction, cf. Theorem 5.22. Implications ( 1) and ( 2) are false if C is the class of simple graphs.

Example 7.44 (Edge subdivision)

If G is a simple directed graph, we let Sub(G) be the simple directed graph such that:

V Sub(G) := V G ∪ E G , E Sub(G) := {(u, e), (e, v) | (e, u) ∈ in 1G and (e, v) ∈ in 2G }.
This transformation consists in replacing every directed edge by a directed path of length 2. It is an MS 2,2 -transduction because the transformation of G into Sub(G) is a (3-copying and domain-extending) MS-transduction: a vertex v of G is made into a vertex (v, 1) of Sub(G), and an edge e of G linking u to v is made into a vertex (e, 1) and also into edges (e, 2) and (e, 3) linking respectively (u, 1) to (e, 1) and (e, 1) to (v, 1). Its definition scheme is D := χ, (δ i ) i∈[3] , (θ w ) w∈R [3] of type R → R where R = {in 1 , in 2 }, with formulas as follows:

χ expresses that G is simple, δ 1 (x 1 ) is True, δ 2 (x 1 ) and δ 3 (x 1 ) express that x 1 is an edge, θ in1,2,1 (x 1 , x 2 ) expresses that x 1 is an edge with tail x 2 , θ in1,3,1 (x 1 , x 2 ) expresses that x 1 is an edge and x 2 = x 1 , θ in2,2,1 (x 1 , x 2 ) expresses that x 1 is an edge and x 2 = x 1 , θ in2,3,1 (x 1 , x 2 ) expresses that x 1 is an edge with head x 2 , and all other formulas θ ini,j,k are False.

This transduction has been used in Example 1.47 as an example of an MS 2,2transduction that transforms simple graphs into simple graphs and is not an MS 1,1 -transduction.

Example 7.45 (Graph minors)

We will prove that the graph transduction ¢ -1 that transforms a graph into its minors is an MS 2,2 -transduction. We recall from Definition 2.15 that a minor of a concrete graph G is a graph of the form The set Z specifies the vertices and edges to be deleted, Y is the set of edges to be contracted and X is a set of vertices of G chosen to be the vertex set of H. (Vertices of G get fused to become vertices of H; the set X selects, from a set of fused vertices, the one that is kept as a vertex of H). Hence, we have proved that the transduction ¢ -1 from (abstract) graphs to their (abstract) minors is an MS 2,2 -transduction. It follows that for every graph H there exists an MS 2 sentence MINOR H such that a graph G has a minor isomorphic to H if and only if G |= MINOR H . This sentence is ∃X, Y, Z. β D where β has for models the structures isomorphic to H and β D is constructed by Backwards Translation (Theorem 7.10). In Corollary 1.14 we have defined a similar sentence MINOR H not using edge set quantifications, for H simple and loop-free.

H = ((G -(Z ∪ Y ))/≈ Y ) X where X ⊆ V G , Y ⊆ E G , Z ⊆ V G ∪ E G
Example 7.46 (Definition of orientations) Proposition 9.46 will show that the mapping und -1 that associates with an undirected graph all its orientations is an MS 2,2 -transduction. It is not a CMS 1,1 -transduction, because otherwise, by Corollary 7.38(2) and since cliques have clique-width 2, tournaments would have bounded clique-width, and we know that this is not the case by Propositions 2.114(3) and 7.39 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF].

The Equationality Theorem for the HR algebra

Our objective is now to establish a characterization of the HR-equational sets similar to that of the VR-equational sets given by the Equationality Theorem in Section 7.2. This characterization will use monadic second-order transductions that construct incidence graphs. However, we first state some direct consequences of the Equationality Theorem for the VR algebra and of some results of Chapter 2.

Theorem 7.47 Let τ be a graph transduction.

(1) If τ is a CMS 2,2 -transduction, then there exists a computable function g τ : N → N such that, for every graph G and every graph H in τ (G), we have twd (H) ≤ g τ (twd (G)).

(2) If τ is a CMS 1,2 -transduction, then there exists a computable function g τ such that twd (H) ≤ g τ (cwd (G)) for every simple graph G and every graph H in τ (G).

(3) If τ is a CMS 2,1 -transduction, then there exists a computable function g τ such that cwd (H) ≤ g τ (twd (G)) for every graph G and every simple graph H in τ (G).

(4) These three results extend to labelled graphs and to path-width and linear clique-width instead of, respectively, tree-width and clique-width.

Proof: (1) Let τ be a CMS 2,2 -transduction that transforms graphs. Then the graph transduction τ The extension to labelled graphs, and especially to edge labels (because vertex labels do not modify tree-width and clique-width) is similar. We get twd (H) ≤ f τ (k) for some computable function f τ depending on the (fixed) sets of vertex and edge labels. (The definition scheme of the transduction τ takes into account all relations of the input and output relational structures.)

:= {(Inc(G), Inc(H)) | (G, H) ∈ τ } is a CMS
(2) The proof is similar with a CMS 1,1 -transduction τ that transforms G into Inc(H). We have twd (H) ≤ 12 • f τ (cwd (G)) -1.

(3) Here τ transforms Inc(G) into H and we have cwd (H) ≤ f τ (2 4k+4 + k + 1), where k = twd (G).

(4) The proofs of ( 2) and ( 3) extend to labelled graphs as that of [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. All these proofs extend to path-width and linear clique-width for labelled graphs. That is, to take an example, if τ is as in (2), then, for some fixed function h τ , we have pwd (H) ≤ h τ (lcwd (G)) for every simple graph G and every H in τ (G). The proofs use Theorems 2.114 (1.3) and 7.41(2),and Proposition 2.115(3).

These facts are useful for showing quickly that certain sets of graphs have bounded or unbounded clique-width or tree-width, but they do not give precise upper or lower bounds. Furthermore, they do not yield a characterization of the HR-equational sets of graphs similar to that of Theorem 7.36 for the VRequational ones.

The next proposition is similar to Proposition 7.30. It shows that, for each finite set C of source labels, the mapping val (defined in Section 2.3.1, Definition 2.32) that associates an s-graph with every term in T (F HR C ), is an MS 1,2transduction (and hence also an MS 2,2 -transduction, cf. Section 7.3). It is actually not needed for the proof of the Equationality Theorem for the HR algebra but it is interesting anyway. It gives a short proof of the Weak Recognizability Theorem for the HR algebra, cf. Remark 7.31 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. It also gives a fixed-parameter linear algorithm that computes τ (G), for a given parameterinvariant CMS 2,2 -transduction τ and a given labelled graph G, with parameter (twd (G), D) where D is the definition scheme for τ , cf. Remark 7.31(2). Proof: Most of the work has been done in Section 2.3.2: Definition 2.40 and Proposition 2.41. This proposition constructs val (t) as the quotient of a concrete s-graph Exp(t), called the expansion of t, by an equivalence relation on its vertices denoted by ≈ t that is defined as the equivalence generated by a binary relation R t on V Exp(t) . We will denote by Exp(t) C +R t the relational structure obtained by adding the binary relation R t to Exp(t) C . We recall that the vertices of Exp(t) are the pairs (u, a) where u is a node of t and a belongs to the type of u (i.e., the type of val (t/u)), and hence to the finite set C. Its edges are the nodes of t labelled by the constant symbols that specify edges. It is clear from Definition 2.40 that the mapping t → Exp(t) C + R t , for t ∈ T (F HR C ), is a parameterless (|C| + 1)-copying MS-transduction, let us denote it by µ 1 . For writing the domain formulas of its definition scheme, we need, for each a in C, an MS formula that expresses that the type of a node u of t (cf. Definition 2.35) contains a. Such a formula is easy to write; it is similar to the one used in the proof of Proposition 7.30 for expressing logically the mapping port t .

We will denote by µ 2 the parameter-invariant transduction (cf. Example 7.3( 1)) that transforms Exp(t) C + R t into the structure Exp(t)/ ≈ t C representing the quotient of Exp(t) by the equivalence relation generated by R t . By Proposition 2.41, val (t) is isomorphic to Exp(t)/≈ t . Hence, the mapping t → val (t) C is equal to µ 1 • µ 2 , hence is a parameter-invariant MStransduction.

In Section 2.3.2, we have also defined concrete quotient graphs Exp(t)/≈ t denoted by cval (t) and gval (t). It is easy to check that their representations can also be defined from t by MS-transductions: the only difference with the above construction concerns µ 2 that must be modified so as to select particular cross-sections of ≈ t . Since these cross-sections are MS-expressible without the use of parameters, µ 2 and µ 1 • µ 2 are parameterless MS-transductions. We omit the easy technical details.

The second statement is proved as in the proof of Proposition 7.30.

Corollary 7.49 A set of graphs has bounded tree-width (resp. bounded pathwidth) if and only if it is included in the image of trees (resp. of paths) under a CMS 1,2 -transduction.

Proof: For tree-width, the equivalence follows from Proposition 7.48, Theorem 7.47(2), Proposition 7.27(2) and the characterization of graphs of tree-width at most k as the values of terms over finite subsignatures of T (F HR ) (Theorem 2.83). For path-width it follows from Proposition 7.48, Theorem 7.47(4), Proposition 7.27(1) and the characterization of graphs of path-width at most k as the values of slim terms over finite subsignatures of T (F HR ) (Proposition 2.85).

This result has several variants: one can replace CMS 1,2 -transductions by MS 1,2 -transductions and the sets trees and paths by equivalent sets by using Proposition 7.27.

The Equationality Theorem for the algebra JS

We start with a result that is similar to Theorem 7.34. In its proof we will actually use Theorem 7.34, coding s-graphs as vertex-labelled incidence graphs (without sources or ports).

If G is a (K, Λ)-labelled s-graph of type included in C, we let G C be the (C∪K, Λ)-labelled graph (without sources) obtained by attaching a as additional label to the a-source of G, for each a ∈ τ (G). 23 It is clear that ) such that τ = µ 1 • val . We will construct an invertible and parameterless MS-transduction µ 2 that transforms every term t ∈ T (F VR C,[K∪Λ,[2]] ) such that cval (t) = Inc(G) into a term t in T (F HR C , [K,Λ] ) that evaluates to G, for some finite C . Then the required invertible MS-transduction is µ := µ 1 • µ 2 . To guarantee that µ 2 is invertible, we will construct it as the composition of a monadic second-order relabelling and a linear, strict and nonerasing second-order substitution (Proposition 7.22(1), Example 7.3(4)).

Inc(G C ) = Inc(G) C . Moreover, G C = G C and if G is simple, G C = G C . If L is a set of (K, Λ)-
Let t and G be as above. Since Inc(G) is without K 3,3 (cf. the proof of Theorem 7.47), we can use the construction of Proposition 2.115, that defines a tree-decomposition of Inc(G) of width at most 12 • |C| -1 whose tree is the syntactic tree Syn(t) of t. (We recall that V Inc(G) = Occ 0 (t) is a set of leaves of t, hence a subset of N t = N Syn(t) which is the domain of the relational structure t ). This construction defines a mapping f : N t → P(V G ∪ E G ) such that: 2). It follows that, if we delete from the boxes f (u) the edges of G, then we have a tree-decomposition of G. In order to have a rich tree-decomposition of G, we must ensure that each e ∈ E G belongs to a unique box. To obtain this, we restrict f into f as follows:

f (u) := (f (u) ∩ V G ) ∪ {e ∈ E G | u is the father of e}.
It is clear that (Syn(t), f ) is a rich tree-decomposition of G.

The construction of Proposition 2.115 (that we do not reproduce here) is based on subsets Pt(u, a) and Ext(u, a) of V Inc(G) , with u ∈ N t and a ∈ C. It follows from the proof of Proposition 7.30 that, for x ∈ V Inc(G) , the properties x ∈ Pt(u, a) and x ∈ Ext(u, a) are MS-expressible in t . Together with the definition of f , this shows that there exists an MS formula ϕ(u, x) such that:

t |= ϕ(u, x) if and only if u ∈ N t , x ∈ V G ∪ E G and x ∈ f (u).
Hence, roughly speaking, we have a rich tree-decomposition of G of bounded width, with underlying tree Syn(t), and that is specified in t by MS formulas (cf. Example 5.2(4)).

Definition 2.80 shows how to transform such a decomposition into a term t over F HR C , [K,Λ] for some set C of bounded size (in fact, C is any set of cardinality 12 • |C|). By combining this transformation with the previous one, we will actually define G by a term t over a finite derived signature H of F HR C , [K,Λ] such that the transformation of t into t is a monadic second-order relabelling. Then t := θ H (t ) evaluates to G, where θ H is the second-order substitution corresponding to H (by Proposition 2.126). This will give the desired result.

The construction of Definition 2.80 uses a vertex coloring γ : V G → C of the considered graph, here G, such that two vertices of the same box have different colors (Lemma 2.78). Since the membership of two vertices in a same box is MS-expressible in t , one can use |C | set variables to specify such a coloring. In order to do that in a unique way, we take the first such coloring for an appropriate linear order defined as follows. Since V G ⊆ N t , the elements of V G are linearly ordered by the natural order on N t = [|t|] ⊆ N (which is MSexpressible in t because it corresponds to the usual preorder tree traversal of Syn(t), cf. the proof of Proposition 5.30). We also fix a linear order on C so that the vertex colorings are ordered lexicographically and this is also MS-expressible. 25 Then, Definition 2.80 builds from γ and (Syn(t), f ) a term t over a derived signature H of F HR C , [K,Λ] having the same syntactic tree as t (by neglecting node labels) and that evaluates to G. These derived operations form a finite set, depending only on C, because they have arity at most 2 and because the graphs H(u) that occur in Equation (2.3) of Definition 2.80, have at most two edges by Property (b) above and the definition of f (cf. Remark 2.84(2)). 26 Since the decomposition f of G is MS-expressible in t , it follows that t can be transformed into t by a parameterless monadic second-order relabelling. It is clear from Equation (2.3) that the second-order substitution θ H is linear, strict and nonerasing.

If Dom(σ) ⊆ Slim(F ), then µ 1 (T (F )) is a set of slim terms by Theorem 7.34. It is clear that µ 2 transforms slim terms into 2m-slim terms, where m is the maximal size of a term with variables that defines a derived operation in the set H.

We now consider the case where D is nonempty, but we treat each s-graph G of type included in D as a graph G D without sources. Clearly, the relation τ :

= {(t, Inc(G D )) | (t, G) ∈ σ} is a CMS 1,1 -transduction : T (F ) → GP [D∪K∪Λ,[2]] [∅]. The transduction µ 2 should now transform every term t ∈ T (F VR C,[D∪K∪Λ,[2]] ) such that cval (t) = Inc(G D ) into a term t in T (F HR C ,[K,Λ]
) that evaluates to G, where C includes D. The proof is as in the case of graphs without sources: the rich tree-decomposition (Syn(t), f ) of G has to be defined so that the sources of G are all in the root box. This can be realized by adding the sources of G to each box of f . Then each box of the resulting rich tree-decomposition has at most 12 • |C| + |D| elements. Since the sources are identified in G D by vertex labels, the monadic second-order formula ϕ(u, x) intended to specify f can ensure this additional condition. As in the first case, the transformation of t into t is a parameterless monadic second-order relabelling and the transformation from t to t is a linear, strict and nonerasing second-order substitution.

Theorem 7.51 (Equationality Theorem for the HR algebra) Let L be a set of possibly labelled s-graphs of bounded type. The following conditions are equivalent:

(1) L is HR-equational,

(2) Inc(L) * is VR-equational,

(3) L is the image of trees under an MS 1,2 -transduction. 27 ν : T (F ) → STR(R) (for some finite functional signature F and some relational signature R) there exists a parameterless MS-transduction ν : T (F ) → STR(R) such that Dom(ν ) = Dom(ν) and ν ⊆ ν (i.e., ν computes one element of ν(t), for every t ∈ Dom(ν)). A linear order on parameter assignments can be defined, and ν uses the first such assignment that satisfies the precondition. 26 In the notation H(u), the letter H does not refer to the derived signature.

27 More precisely, this means (in the case where the s-graphs in L are (K, Λ)-labelled) that there is an MS-transduction τ of type Rm → R m,D, [K,Λ] such that L = τ ( trees ), where D is the smallest set of source labels such that τ (G) ⊆ D for every G ∈ L.

(4) L is the image of trees under a CMS 1,2 -transduction. Moreover, L is linear HR-equational if and only if it is the image of paths under an MS 1,2 -transduction (or, a CMS 1,2 -transduction) if and only if Inc(L) * is linear VR-equational.

Proof: (2) ⇐⇒ (3) ⇐⇒ (4) by the Equationality Theorem for the VR algebra (Theorem 7.36), because Inc(L) * = Inc(L) = L . The "linear case" (i.e., the corresponding part of the last statement of the theorem) follows from Theorem 7.41 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF].

(1) =⇒ ( 3) is immediate from Proposition 7. 48 and Proposition 7.27(2). The linear case can be shown similar to the first part of the proof of Theorem 7.41 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. Instead, (the nonlinear case of) ( 1) =⇒ ( 2) can be shown without the use of Proposition 7.48, as follows.

Let L be an HR-equational set of directed (K, Λ)-labelled graphs (without sources). Then Inc(L) is also HR-equational: if in an equation system that defines L, we replace everywhere -→ ab λ by fg c ( -→ ca 1 -→ cb 2 c λ ) and a λ by fg c ( -→ ca 1 -→ ca 2 c λ ), then we obtain an equation system that defines Inc(L). The subscripts 1 and 2 in -→ ca 1 and -→ cb 2 represent the edge labels 1 and 2 that distinguish the two types of edges (cf. in 1 and in 2 ) of Inc(G) when G is directed. Since Inc(L) is a set of simple graphs, it is also VR-equational by Theorem 4.49. The proof is similar for undirected graphs.

We now consider graphs with sources. Let D be the smallest set of source labels such that τ (G) ⊆ D for every s-graph G ∈ L. If G is such an s-graph, then G D = fg D (G a a • • • ) where is applied to all constant symbols a a for a ∈ τ (G). Each a-source of G is made into an internal vertex of the graph G D labelled by a. It follows that if L is a homogenous HR-equational set of type D, then L * = fg D (L a a • • • ), hence is an HR-equational set of graphs (without sources). The same holds for every HR-equational set because such a set is a finite union of homogenous HR-equational sets (cf. the paragraph before Definition 4.12). Thus, if L is HR-equational, then so are L * and Inc(L) * since this last set is equal to Inc(L * ). Hence Inc(L) * is VR-equational, which proves that (1) implies (2).

(4) =⇒ ( 1) is immediate from Proposition 7.27(2) and Theorem 7.50. In the linear case, the proof is similar to the second part of the proof of Theorem 7.41 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] (in particular, that proof also holds if

M ⊆ Slim k (F ), taking |t i | > k).
The following corollary is similar to Corollary 7.37.

Corollary 7.52 The image of an HR-equational set of s-graphs under a CMS 2,2transduction is HR-equational. Furthermore, the image of an HR-equational set of s-graphs under a CMS 2,1 -transduction is VR-equational and the image of a VR-equational set of p-graphs under a CMS 1,2 -transduction is HR-equational. Similar statements hold for labelled s-and p-graphs, and for the linear equational sets.

Proof: The proof is similar to the one of Corollary 7.37. The first statement is a consequence of the equivalence of ( 1) and ( 4) of Theorem 7.51, and the fact that, by Theorem 7.14 and the definitions, τ • θ is a CMS 1,2 -transduction if τ is a CMS 1,2 -transduction and θ is a CMS 2,2 -transduction. For the remaining statements one additionally uses the equivalence of ( 1) and (3) of Theorem 7.36 (and Theorem 7.41(1) for the linear case), together with the more general fact that if τ is a CMS 1,i -transduction and θ is a CMS i,j -transduction, then τ • θ is a CMS 1,j -transduction.

Since the identity is a CMS 2,1 -transduction on simple graphs, we obtain from this corollary that every linear HR-equational set of simple graphs is linear VRequational: the linear version of Theorem 4.49.

As observed in Section 7.3, it is proved in the main theorem of Section 9.4.1 (Theorem 9.44) that the identity on a set of simple and uniformly sparse labelled graphs is an MS 1,2 -transduction. Using this, we get from Corollary 7.52 that a set of simple labelled graphs is HR-equational if and only if it is VR-equational and has bounded tree-width (see the proof of Theorem 4.51 and Section 9.4.3). Furthermore, it is decidable whether a VR-equational set is HR-equational (see the discussion after Theorem 7.42).

Here is another example of the use of Corollary 7.52. We recall that the line graph Line(G) of a graph G has vertex set E G and an (undirected) edge between e and e in E G = V Line(G) if and only if e and e have an end vertex in common.

Corollary 7.53 The set of line graphs of an HR-equational set of graphs is VR-equational.

Proof: The transduction that transforms G into Line(G) is an FO-transduction, and so the graph transduction Line is an MS 2,1 -transduction (see Example 1.45). Hence, if L is an HR-equational set of graphs, then Line(L) is VR-equational by Corollary 7.52. From Theorem 7.51 and Corollary 7.52 one can prove that Theorem 7.47 and Corollary 7.49 actually hold for s-graphs and p-graphs, rather than just graphs. These results correspond to Corollary 7.38(1,2) and Theorem 7.41(2,3).

Theorem 7.42, the Semi-Linearity Theorem for images of the set trees under CMS-transductions (and in particular for VR-equational sets), has an obvious counter-part for HR-equational sets, where one can count edges and not only vertices.

Decidability of monadic second-order satisfiability problems

One of the consequences of the Recognizability Theorem is that the equational sets of graphs have decidable monadic second-order satisfiability problems (Sec-tion 5.4, Theorem 5.80). In this section we use monadic second-order transductions to reduce monadic second-order satisfiability problems for sets of graphs or relational structures to similar problems for related sets. We obtain in particular (by using difficult results of graph theory) that bounded tree-width and bounded clique-width are necessary conditions for the decidability of certain monadic second-order satisfiability problems.

We first recall a definition already given in Section 5.1.6. Let L be a logical language, and C be a set of structures. The L-satisfiability problem for C consists in deciding whether a given sentence in L is true for some structure in C. (For sets L closed under negation, there is an equivalent formulation in terms of L-theories). For having an easy comparison with what follows, we restate the results of Section 5.4.

The CMS-satisfiability problems of the set of simple labelled graphs of cliquewidth at most k, for each fixed k, and, more generally, of every VR-equational set of labelled graphs are decidable. So are the CMS 2 -satisfiability problems of the set of labelled graphs of tree-width at most k, for each fixed k, and, more generally, of every HR-equational set of labelled graphs.

We will give alternative proofs of these results by using the following theorem. Proof: Let C be a subset of STR(R) and A be an algorithm that decides its C r MS-satisfiability problem. Let τ be a C r MS-transduction with parameters Y 1 , . . . , Y q and ϕ be a sentence in C r MS(R , ∅). Then S |= ϕ for some S ∈ τ (S) such that S ∈ C if and only if S |= ∃Y 1 , . . . , Y q . τ # (ϕ) for some S in C. We use here the Backwards Translation Theorem (Theorem 7.10). Its proof gives an algorithm that constructs τ # (ϕ) from ϕ and a definition scheme of τ . Algorithm A can decide if ∃Y 1 , . . . , Y q . τ # (ϕ) is satisfiable in C. Hence, the set τ (C) has a decidable C r MS-satisfiability problem.

In the particular case where r = 0, we obtain a statement relative to MSsatisfiability problems and MS-transductions. By using this theorem, Proposition 7.30 and the classical result that the monadic second-order satisfiability problem for regular languages is decidable (cf. Theorem 1.16), we get immediately that the CMS-satisfiability problem of a VR-equational set of (K, Λ)labelled graphs, and in particular of the set of (K, Λ)-labelled graphs of cliquewidth bounded by any fixed k, is decidable. The proof is similar for the CMS 2satisfiability problem of an HR-equational set of (K, Λ)-labelled graphs, and in particular, for the set of those of tree-width bounded by any fixed k. The following theorem gives some kind of converse statements.

Theorem 7.55

(1) If a set of labelled graphs has a decidable MS 2 -satisfiability problem, then it has bounded tree-width.

(2) If a set of simple labelled graphs has a decidable C 2 MS-satisfiability problem, then it has bounded clique-width.

Proof: [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] We have shown in Example 7.45 that the transduction ¢ -1 that associates with a graph the set of its minors is an MS 2,2 -transduction. If C has a decidable MS 2 -satisfiability problem, then so has the set ¢ -1 (C) of all minors of the graphs in C by the Reduction Theorem (Theorem 7.54). Hence, by Theorem 5.6, the square grids in ¢ -1 (C) have bounded size. So, there exists n ∈ N such that the graphs of C do not contain G n×n as a minor. Since G n×n is planar, this implies that C has bounded tree-width by the second assertion of Proposition 2.61.

(2) The proof is in [CouOum]. It follows the same scheme but is more complicated. It is based on the notion of vertex-minor inclusion instead of that of minor inclusion. The mapping that transforms a simple undirected graph into the set of its vertex-minors is shown to be a C 2 MS-transduction, and the proof uses in a crucial way the even cardinality set predicate. For this reason, the hypothesis that the considered set has a decidable C 2 MS-satisfiability problem cannot be replaced by the decidability of its MS-satisfiability problem.

The result of [CouOum] is first proved for bipartite and undirected graphs. (This special case concentrates all the difficulties). It is extended first to simple (K, ∅)-labelled, bipartite and undirected graphs, and then to simple (K, Λ)labelled graphs by a slight modification of the encoding B Λ used in Section 6.2.3. This extension is based on the Reduction Theorem and Corollary 7.38(2).

This theorem leaves open several questions.

Can one weaken the hypotheses of Theorem 7.55? Question 7.56 Is it true that if a set of simple labelled graphs has a decidable MS-satisfiability problem, then it has bounded clique-width? This condition is strictly weaker than the decidability of the C 2 MS-satisfiability problem by the following proposition.

Proposition 7.57 Let A be a unary relation symbol. There exists a subset of STR({A}) that has a decidable MS-satisfiability problem and an undecidable C 2 MS-satisfiability problem.

Proof: An element of STR({A}) is a pair S = D S , A S where A S ⊆ D S . For i, j ∈ N , we let S i,j be the structure S in STR({A}) such that |D S | = i + j and |A S | = i. For each i ≥ 1, we let ϕ i be the C 2 MS sentence such that MOD(ϕ i ) = {S i,j | j is odd}.

Let M 1 , M 2 , . . . , M i , . . . be an effective enumeration of all deterministic Turing machines, where each machine is given with an initial configuration. We let C be the set of structures S i,j such that i ≥ 1 and, either j = 2k ≥ 2i and after k steps the computation of M i is not terminated, or j = 2k + 1 ≥ 2i + 1 and the computation of M i terminates in k steps for some k ≤ k. Membership in the set C is decidable. Since the computation of M i terminates if and only if MOD(ϕ i ) ∩ C = ∅, the C 2 MS-satisfiability problem of C is undecidable.

We now prove that the MS-satisfiability problem for C is decidable. The result of [START_REF] Courcelle | The monadic second-order logic of graphs I: Recognizable sets of finite graphs[END_REF] recalled in Section 5.2.6 (above Lemma 5.27) entails that every sentence ϕ in MS({A}, ∅) is equivalent (in every {A}-structure S) to a fixed finite disjunction of conditions of the four possible forms, for p, q in N :

C 1,p,q : |A S | = p ∧ |D S -A S | = q, C 2,p,q : |A S | > p ∧ |D S -A S | = q, C 3,p,q : |A S | = p ∧ |D S -A S | > q, C 4,p,q : |A S | > p ∧ |D S -A S | > q.
We prove that, for each (i, p, q), one can decide if C i,p,q is satisfied by some S in C.

Case of C 1,p,q : The structure S p,q is the only one that satisfies this condition. Hence C 1,p,q is satisfied by some structure in C if and only if S p,q belongs to C. We have noted that membership in C is decidable, hence this fact is decidable.

Case of C 2,p,q : A structure S i,j satisfies this condition if and only if i > p and j = q ≥ 2i. Hence C 2,p,q is satisfied by some structure in C if and only if S i,q belongs to C for some i such that p < i ≤ q/2. This is decidable since membership in C is decidable.

Case of C 3,p,q : If p = 0, this condition cannot hold for any structure in C. If p > 0, q ≥ p and 2q > q, then one of the two structures S p,2q and S p,2q +1 belongs to C and satisfies C 3,p,q . Hence C 3,p,q is satisfied by some structure in C if and only if p = 0. (But for given p, we cannot decide if this is by a structure of the form S p,2q or of the form S p,2q +1 .)

Case of C 4,p,q : As in the previous case, such a condition is always satisfied by S p+1,r for some large enough r.

This proves that the satisfiability in C of any given MS sentence is decidable, which concludes the proof.

A related open question concerns extensions of Theorem 7.55 to sets of graphs that have decidable L-satisfiability problems for fragments L of CMS or of CMS 2 that are defined by limitations on quantifications. To make one precise question out of this remark, we ask: Question 7.58 Is it true that if a set of labelled graphs has a decidable Lsatisfiability problem, where L is the set of existential MS 2 -sentences, i.e., of MS 2 -sentences written with a sequence of existential set quantifications followed by a first-order formula, then it has bounded tree-width? Can one extend Theorem 7.55 to relational structures?

The answer is positive for its first assertion by Theorem 9.19. The corresponding extension of the second one is open (cf. Question 9.20).

Question 7.59 Is it true that if a set C ⊆ STR(R) has a decidable CMSsatisfiability problem, then C ⊆ τ (trees) for some MS-transduction τ from trees to STR(R)?

Could we have a necessary and sufficient condition in Theorem 7.55?

Having bounded tree-width or clique-width is only a necessary condition for sets of graphs to have a decidable monadic second-order satisfiability problem of a certain type. Strong structural conditions like to be a set of paths (equivalently a set of words), do not imply that a set of graphs satisfying such conditions has a decidable MS-satisfiability problem. From the equivalence of monadic secondorder logic and finite automata on words, we get that a language L ⊆ {0, 1} * has a decidable MS-satisfiability problem if and only if the following problem is decidable:

Given a finite automaton A , decide if L ∩ L(A ) = ∅.
The class of languages for which this problem is decidable contains in particular all languages of the form τ (trees) where τ is a monadic second-order transduction, because these languages are those that are HR-equational (equivalently VR-equational) by Theorem 7.51. They will be studied in Section 8.9.

Can one still get decidable satisfiability problems for extensions of monadic second-order logic?

We can ask for "small extensions" of monadic second-order logic such that the corresponding satisfiability problem remains decidable, say at least on trees. We will present three negative results in this direction.

We let CMS+Eq be the extension of CMS logic with the binary set predicate EqCard (X, Y ) meaning that X and Y have the same cardinality. If P ⊆ N is a decidable set of integers, we let CMS+P be the extension of CMS logic with the set predicate Card P (X) meaning that the cardinality of X belongs to the set of integers P . In the following proposition, we will consider

P = P 23 := {n ∈ N | n = 2 k or n = 3 k for some k ≥ 1}.
For n > 0, we let D n be the structure [n], ≤ (it is nothing but a n without the relation lab a , cf. For x, y, z ∈ [n] the condition z = x + y is equivalent to:

∃Y ("[z] = Y ∪ [x]" ∧ EqCard (Y, [y])),
and the condition z = x • y is equivalent to:

∃X("z = max(X)" ∧ EqCard (X, [x]) ∧ ∀Z("Z ∈ I(X)" ⇒ EqCard (Z, [y]))),
where "[z] = Y ∪ [x]", "z = max(X)" and "Z ∈ I(X)" are easily expressible in terms of x, z, X, Y and Z by monadic second-order formulas.

In each structure D n such that n ≥ 4, an MS+Eq formula can determine the maximal element a > 1 such that a 2 ≤ n, because, by the above observation, an MS+Eq formula can express that there exists z in the domain of D n such that z = a • a. Then one can define A n and B n to be [a] and C n to be [a 2 ], and one can construct the formulas θ A , θ B and θ C that characterize them.

The relation R n defined by R n (x, y, z) if and only if z = x + (y -1) • a for x, y ∈ [a] and z ∈ [a 2 ] defines a pairing function : A n × B n → C n . It is definable by an MS+Eq formula θ R since the sum and the product are definable by such formulas. We omit the details. We have α(S n ) = √ n for each n, hence the integers α(S n ) are unbounded. This completes the proof.

The construction for CMS+P 23 .

We will now build pairing functions in D n by making use of the set predicate Card P23 (X). For each pair of integers (p, q) with p ≥ 2 and q ≥ 1, we define:

A (p) := {2 k | 2 ≤ k ≤ p}, B (q) := {3 k | 1 ≤ k ≤ q}, C (p, q) := {2 k 3 m | 2 ≤ k ≤ p, 1 ≤ m ≤ q}.
When we say that "x is a power of 2 or 3", we exclude the case x = 1. We first observe that for x ∈ D n :

x is a power of 2 if and only if Card P23 ([x]) ∧ Even([x]) and 29

x is a power of 3 if and only if

x > 1 ∧ Card P23 ([x]) ∧ ¬Even([x]).
Our objective is to define in D n by a formula of CMS+P 23 the pairing function z = x • y for x ∈ A (p) and y ∈ B (q), where 2 p 3 q ≤ n. We will use the following observations. If k, k , k ≥ 1, then:

(a) 2 k + 2 k is a power of 2 if and only if k = k , (b) 3 k + 3 k + 3 k is a power of 3 if and only if k = k = k .
Let us consider the following conditions on Y ⊆ N and z ∈ N :

As final similar case, we define MS+Auto as the extension of MS logic with the set predicate Auto(X) meaning that the structure induced by X has a nontrivial automorphism. We get that the set of structures T n := [n], suc (where suc is the successor relation) has an undecidable (MS+Auto)-satisfiability problem. The basic observation is that if X is the union of two intervals [p, q] and [r, s] with r ≥ q + 2, then T n [X] has a nontrivial automorphism if and only if q -p = s -r. By using it, one can build an MS+Auto formula ϕ(x, y, z) to express that x and y are different prime numbers and that z = x • y. It is then easy to build pairing functions as in the previous two constructions.

Questions about logical characterizations of recognizability

Recognizability is equivalent to MS-definability for languages over a finite alphabet or a finite functional signature. It is equivalent to CMS-definability for sets of rooted trees and for sets of terms over an associative and commutative signature. We have proved these results in Chapter 5 (see Section 5.5). On the other hand, we have proved that there are uncountably many HR-and VR-recognizable sets (cf. Section 4.2.3), so that there is no hope to have such characterizations for them. The following conjecture has been made in [START_REF] Courcelle | The monadic second-order logic of graphs V: On closing the gap between definability and recognizability[END_REF]:

Conjecture 7.62 Every HR-recognizable set of graphs of bounded tree-width is CMS 2 -definable.

Together with the Recognizability Theorem for the HR algebra (Theorem 5.68), it would imply that a set of graphs of bounded tree-width is HR-recognizable if and only if it is CMS 2 -definable. For simple graphs of bounded tree-width, CMS 2 -definability is equivalent to CMS-definability as we will prove in Section 9.4 (cf. Theorem 5.22); we proved that for forests in Example 7.8. Hence, the conjecture implies that a set of simple graphs of bounded tree-width is HR-recognizable if and only if it is CMS-definable. Concerning the algorithmic applications, if the conjecture is true, then no logical language strictly more expressive than counting monadic second-order logic can have fixed-parameter model-checking algorithms based on automata, like those obtained in Chapter 6, with respect to tree-width as parameter.

Since it is hard to prove or disprove this conjecture, relativized versions have been considered. Let us say that the conjecture holds for a set of graphs C if all its HR-recognizable subsets of bounded tree-width are CMS-definable. The following relativizations have been established: to graphs of tree-width at most 2 ([Cou91]), of tree-width at most 3 and, for each k, to k-connected graphs of tree-width at most k ( [Kal]). The cases of graphs of path-width at most k and of all graphs (of tree-width at most k) have been announced in [Kab] and [Lap] respectively, but the full proofs have not been published. The conjecture is still open.

Our second observation is that the transduction τ k cannot be val -1 AC , i.e., it cannot associate with a graph G all the terms in T AC (F HR [f (k)] ) that evaluate to it. There is a trivial reason: the set val -1 AC (G) is infinite, because of Equalities (3), ( 5), ( 6), ( 7), ( 9) and ( 12)-( 17) of Proposition 2.48 (Equality (3) alone implies that). For a less trivial counter-example, we consider again the series-parallel graphs, generated by e and the operations and •: the set of different terms modulo the associativity and commutativity of that denote the simple seriesparallel graphs with n vertices is finite but not of cardinality O(n). Hence, no monadic second-order transduction τ k can construct all such (equivalence classes of) terms from a given series-parallel graph G. Thus, a transduction τ k satisfying Conditions ( 1) and (2) must select particular terms that evaluate to the input graph. Such transductions are constructed in [START_REF] Courcelle | The monadic second-order logic of graphs V: On closing the gap between definability and recognizability[END_REF] and in [Kal].

Instead of a transduction τ k that constructs terms, one could think of a transduction that constructs for every graph in C k a structure, as described in Example 5.2(4), that represents a tree-decomposition of G of width at most f (k). (We will do that in Proposition 9.56 for k-chordal graphs.) Such a construction is equivalent to the first one because the transformations between quotient-terms (in T AC (F HR [f (k)] )) and the corresponding tree-decompositions are monadic second-order transductions, see Definitions 2.75 and 2.80 and the proof of Theorem 7.50.

Here is an auxiliary question, where the associative and commutative operation of F VR [m] is ⊕:

Question 7.64 Is it true that for each k there is an integer m and a CMS 2,1transduction that associates with every simple graph of clique-width at most k a term in T AC (F VR [m] ) that evaluates to it?

A positive answer would not solve Question 7.63 but would perhaps lead to a solution.

The Equationality Theorems for the VR and HR algebras have been proved first (in a different way) in [START_REF] Engelfriet | Logical description of contextfree graph languages[END_REF] and in [CouEng]. Proofs similar to the one given for the case of the VR algebra and that extend to the algebra of relational structures are in [START_REF] Courcelle | The monadic second order logic of graphs VII: Graphs as relational structures[END_REF] and [START_REF] Blumensath | Recognizability, hypergraph operations, and logical types[END_REF].

The linear HR-equational and VR-equational sets are those that are generated by linear context-free Hyperedge Replacement and Vertex Replacement graph grammars respectively, where such a grammar is called linear if, as usual, the righthand side of each of its rewriting rules has at most one occurrence of a nonterminal symbol (see [*Eng97] for a survey). For an example of a linear HR grammar, see Example 4.28.

Monadic second-order transductions from terms to terms are characterized in [START_REF] Bloem | A comparison of tree transductions defined by monadic second order logic and by attribute grammars[END_REF] and in [START_REF] Engelfriet | Macro tree transducers, attribute grammars, and MSO definable tree translations[END_REF], respectively in terms of attribute grammars and of macro tree transducers. The same sets of words and terms are HR-equational and VR-equational, and have equivalent characterizations respectively, in terms of deterministic tree-walking transducers ( [START_REF] Engelfriet | The string generating power of context-free hypergraph grammars[END_REF]) and in terms of attribute grammars ( [START_REF] Bloem | A comparison of tree transductions defined by monadic second order logic and by attribute grammars[END_REF]) or of macro tree transducers [START_REF] Engelfriet | Tree languages generated by contextfree graph grammars[END_REF]). These results will be presented in Chapter 8.

Theorem 7.55( 1) is proved in a different way in [See91]. In this article, Seese asks whether a set of graphs that has a decidable MS-theory is the image of a set of trees under an MS-transduction. This question is solved affirmatively (but partially) in [CouOum], see Theorem 7.55(2).

The Reduction Theorem (Theorem 7.54) is a classical tool introduced by Rabin in [START_REF] Rabin | A simple method for undecidability proofs[END_REF] and [START_REF] Rabin | Decidable theories[END_REF] under the name of "interpretation of theories" for proving that certain first-order theories are decidable or undecidable by reduction to known cases.

Certain graph transformations that are not monadic second-order transductions satisfy a weak Backwards Translation Theorem. One example is the unfolding of rooted, directed and acyclic (i.e., without circuits) graphs that transforms a graph G into the finite tree of its finite directed paths originating from a specified vertex r designated by some label (a unary relation in G denoting a singleton set). This tree, denoted by Unf (G, r), is called the unfolding of G from r. Since the unfolding is not of linear size increase, it is not a monadic second-order transduction. However, there exists a mapping ϕ → ϕ from CMS sentences to CMS sentences such that, for every (G, r):

Unf (G, r) |= ϕ if and only if G |= ϕ.
This result is proved in [CouWal] for all finite and countable directed graphs: their unfoldings are finite or countably infinite trees. However, it holds only for sentences, and not for arbitrary formulas. To see this point, consider a finite graph G with circuits: the bijection described in Remark 7.13(1) between the assignments that satisfy a formula in a structure T obtained from S by a monadic second-order transduction and those that satisfy an associated formula in S cannot exist by an obvious comparison of cardinalities (just take ϕ(X) equal to True). But even if G is acyclic, no such bijection can exist.

The definitions by monadic second-order transductions of orientations of graphs (Example 7.46) and of linear orders of their vertex sets (Example 7.3(3)) will be studied in Chapter 9 (Propositions 9.42(1), 9. 43 and 9.46; more results can be found in [START_REF] Courcelle | The monadic second-order logic of graphs VIII: Orientations[END_REF] and [START_REF] Courcelle | The monadic second-order logic of graphs X: Linear orderings[END_REF]).

Theorem 8.1 of [HliSee] states for infinite trees a result similar to Proposition 7.57. The proof of this proposition is based on the proof sketch given in that article.

The comparison of sets of structures via monadic second-order transductions (cf. Section 7.1.7) has been initiated in [START_REF] Blumensath | On the monadic second-order transduction hierarchy[END_REF] where the relation between sets of incidence graphs is characterized.

Chapter 8

Transductions of terms and words

As explained in the introduction of Section 1.7, there do not exist appropriate finite-state automata or finite-state transducers that work "directly" on graphs. Thus, for graphs, the role of automata and transducers is taken over by monadic second-order logic: instead of being accepted by an automaton, a set of graphs is defined by a monadic second-order sentence; and instead of being computed by a transducer, a graph transduction is defined by a definition scheme consisting of monadic second-order formulas. With respect to automata, the original motivation for this approach was Theorem 1.16 (cf. Theorem 5.82): for terms and words monadic second-order logic and finite-state automata have the same expressive power.

The aim of this chapter is to show that, in a certain sense, the automatatheoretic characterization of monadic-second order logic for sets of terms and words (Theorem 1.16) can be generalized to transductions. This means of course, that the automata should produce output, i.e., that they are transducers. We will concentrate on transductions that are partial functions, and in particular on deterministic devices, i.e., parameterless definition schemes and deterministic transducers. For these, we will show that monadic second-order transductions of words correspond to two-way finite-state transducers, and that monadic second-order transductions of terms correspond to (compositions of) tree-walking transducers. These transducers are well known from Formal Language Theory.

A two-way finite-state transducer is a finite-state automaton with a two-way read-only input tape and a one-way output tape. The input word is placed on the input tape between endmarkers, and the transducer has a reading head that is positioned over a cell of the input tape, at each moment of time. In one computation step, it reads the symbol in that cell, moves its head by one cell to the left or to the right (or keeps it at the same cell), writes some symbols on the output tape, and goes into another state. Such a transducer is said to be a one-way finite-state transducer if it never moves to the left.

A tree-walking transducer is very similar to a two-way finite-state transducer, but more complicated as both its input and output are trees (or more precisely, syntactic trees of terms). It is a finite-state device, of which the reading head is positioned over a node of the input tree, at each moment of time; this node will be called the "current node". In one computation step, it reads the label of that node and either does not produce output, or produces one labelled node of the output tree. In the first case, it moves its head up to the father or down to one of the sons of the current node (or lets it stay at the same node), and goes into another state. In the second case, the computation of the transducer branches into k parallel computations, where k is the number of sons of the produced output node. Each of these computations then moves its head to the father or one of the sons of the current node (or lets it stay where it is), and goes into another state. Different computations can move to different input nodes and go into different states; in other words, the parallel computations behave independently (and will continue to behave independently in the following steps). The task of the i-th computation is to output the tree rooted at the i-th son of the produced output node. Thus, the output tree is generated in a top-down fashion, with several configurations of the transducer at some of the leaves of the output generated sofar. Each of these configurations represents a parallel branch of computation, which ends when an output node is produced that has no sons (i.e., k = 0). It should be noted that a tree-walking transducer can detect whether or not the current node has a father (i.e., whether it is the root), which son it is of its father, and how many sons it has itself. We also note, for readers familiar with alternation, that the branching behaviour of a nondeterministic tree-walking transducer is similar to that of an alternating automaton.

We will identify words with terms over a signature consisting of unary function symbols and the constant symbol . A word a 1 a 2 • • • a n is identified with (the syntactic tree of) the term a 1 (a 2 (• • • a n ( ) • • • )). A tree-walking transducer that translates such unary terms (trees) into unary terms (trees) is, apart from notational matters, the same as a two-way finite-state transducer. The symbol acts as a right endmarker; there is no left endmarker, but the transducer can detect the left end of the word because it is the root of the tree. Walking up and down on the input tree corresponds to the two-way (left and right) motion on the input tape. Since the output tree is unary, the transducer never branches, and so the output is produced as on a one-way output tape.

One might expect or hope that MS-transductions of words correspond to the more usual ones, called rational transductions, that are defined by oneway finite-state transducers (see, e.g., [*Ber]). However, these two classes of transductions have different properties. As observed in the introduction of Section 1.7, the class of rational transductions is closed under composition and inverse, and rational transductions preserve regularity and context-freeness of languages. On the other hand, the class of MS-transductions of words is closed under composition (by Theorem 7.14) but not under inverse. Moreover, inverse MS-transductions of words preserve regularity of languages (by Corol-lary 7.12) but MS-transductions do not (see Remark 7.23). MS-transductions do not preserve context-freeness either, but (by Corollary 7.37) they do preserve VR-equationality (of which context-freeness is a, proper, special case). These statements will be made more precise in Examples 8.2 and 8.3 and in Section 8.9.

Through the Weak Recognizability Theorem (Section 5.3.9, Corollary 5.69), a finite-state automaton on terms can be viewed as the implementation of a specification of a set of graphs by an MS sentence (i.e., of an MS-definable set of graphs). For describing terms, the implementation formalism corresponds exactly to the specification formalism, in the sense that they have the same expressive power.

This chapter shows how to implement MS-transductions of terms and words by finite-state transducers. In the case of words, the two-way finite-state transducers correspond exactly to the MS-transductions, in the above sense (Theorem 8.10). For terms, MS-transductions can be implemented by the compositions of two tree-walking transducers, the first of which never moves up (Theorem 8.16). These composed transducers correspond exactly to the MStransductions when restricted to transductions of linear size increase (Theorem 8.17). For terms we will discuss other implementation devices: the treewalking pushdown tree transducer (Theorem 8.13), the multi bottom-up tree-toword transducer (Theorem 8.21) and the macro tree transducer (Theorem 8.22). After the automata-theoretic characterization of MS-transductions of terms, we obtain from Theorems 7.34 and 7.50 that each of the above tree transducers can be viewed as the implementation of a specification of a graph transduction by a monadic second-order definition scheme (Theorem 8.18). Moreover, we obtain from Theorem 7.36 (the Equationality Theorem) automata-theoretic characterizations of the VR-equational, equivalently HR-equational, sets of terms and words (Theorems 8.27 and 8.28).

Terminology

We review some definitions and notation, and we introduce some new terminology, to be used in this chapter.

For transductions τ and τ , their composition is τ • τ = {(S, T ) | (S, U ) ∈ τ and (U, T ) ∈ τ for some U } (see Definition 7.1). For classes X and X of transductions, X

• X = {τ • τ | τ ∈ X, τ ∈ X }.

Terms and words

In this chapter, all alphabets are finite. Moreover, all functional signatures are finite and one-sorted, and all relational signatures are without constant symbols. A term will also be called a tree; that should not lead to confusion, because in this chapter we will not consider trees other than syntactic trees of terms. Finally, all unary functional signatures have exactly one constant symbol, which is denoted . A term over a unary functional signature will be called a unary term (or unary tree). then, for every i ∈ [k], td -run A ,s (u i ) is the state q i such that f [q 1 , . . . , q k ] → q is the unique rule in δ with q = td -run A ,s (u). Note that A need not have a run on s, but if it has one, then td -run A ,s is the unique run of A on s.

Logic

Let F be a functional signature. A tree-walking transducer implementing an MS-transduction of terms will need to know at each node u of a tree s ∈ T (F ) which MS formulas ϕ(x 1 ) are true at u, and in some cases even which formulas ϕ(x 1 , x 2 ) are true at u and some other node. To handle this formally, we define the following theories, similar to, but different from those in the proof of the Equationality Theorem for the VR algebra (more precisely, the proof of Theorem 7.34). For the notation used see Application 5.61.

Let F and q ∈ N be fixed. The integer q will be specified later. For n ∈ N , let L n := MS q (R F , {x 1 , . . . , x n }) and L n := MS q (R F ∪{w} , {x 1 , . . . , x n }), where w is the special variable used for contexts. Recall from Definition 5.59 and Section 5.6 that L n and L n are finite. For s ∈ T (F ) and u ∈ N s , we define

Th ↓ s (u) := {ϕ ∈ L 1 | s /u |= ϕ(u)} = Th(s, ↓u, q, 0, u), Th ↑ s (u) := {ϕ ∈ L 1 | s ↑ u |= ϕ(u)} = Th(s, ↑u, q, 0, u), and Th s (u) := {ϕ ∈ L 1 | s |= ϕ(u)} = Th(s, ↓root s , q, 0, u).
and for s ∈ T (F ) and x, u ∈ N s , we define

Th ↓ s (x, u) := {ϕ ∈ L 2 | s /u |= ϕ(x, u)} provided x ∈ N s /u, Th ↑ s (x, u) := {ϕ ∈ L 2 | s ↑ u |= ϕ(x, u)} provided x ∈ N s ↑ u, and
Th s (x, u) := {ϕ ∈ L 2 | s |= ϕ(x, u)},
and so Th ↓ s (x, u) = Th(s, ↓u, q, 0, (x, u)), and similarly for the other two. Note that if m ≤ n then the set of formulas MS q (R F , {x 1 , . . . , x m }) is included in MS q (R F , {x 1 , . . . , x n }), and similarly for R F ∪{w} . Hence, e.g., Th ↓ s (u) contains all sentences ϕ such that ϕ ∈ MS q (R F , ∅) and s /u |= ϕ.

The theory Th ↑ s (root s ) is independent of s because the R F ∪{w} -structure S := s ↑ root s is the same for all s: it has the singleton domain D S = {1} with lab w S = rt S = D S , the other relations being empty. We will denote this theory by Th ↑ rt and call it the root theory. We now use the Splitting Theorem for derived operations (Theorem 5.57 and Corollary 5.60), and in particular Application 5.61, to obtain relationships between the above theories.

Let u be a node of s ∈ T (F ) with label f ∈ F k and sons u 1 , . . . , u k . By Equation (5.6) in Application 5.61, there is a mapping δ f : P(L 1 ) k → P(L 1 ) (independent from s and u), such that

Th ↓ s (u) = δ f (Th ↓ s (u 1 ), . . . , Th ↓ s (u k )). 2
Let us express this by saying that Th ↓ s (u) can be determined from f and Th ↓ s (u 1 ), . . . , Th ↓ s (u k ) (implicitly by a fixed mapping, δ f in this case). Similarly, now using Z f † of Equation (5.5) in Application 5.61, there is a mapping Z f : P(L 1 ) × P(L 1 ) k → P(L 1 ), such that

Th s (u) = Z f (Th ↑ s (u), Th ↓ s (u 1 ), . . . , Th ↓ s (u k ))
, in other words, Th s (u) can be determined from f , Th ↑ s (u), and all theories Th ↓ s (u j ), j ∈ [k]. Moreover, by a similar argument (cf. Equation (5.7) in Application 5.61), for every i ∈ [k] there is a mapping Z f,i : P(L 1 )×P(L 1 ) k-1 → P(L 1 ), such that

Th ↑ s (u i ) = Z f,i (Th ↑ s (u), Th ↓ s (u 1 ), . . . , Th ↓ s (u i-1 ), Th ↓ s (u i+1 ), . . . , Th ↓ s (u k )), i.e., Th ↑
s (u i ) can be determined from f , Th ↑ s (u), and all theories Th ↓ s (u j ) with j ∈ [k], j = i.

Similar statements are valid when two nodes x and u are considered. For instance, if x ∈ N s ↑ u, then Th s (x, u) can be determined from f , Th ↑ s (x, u), and Th ↓ s (u 1 ), . . . , Th ↓ s (u k ). As another example, if x ∈ N s /u i , then Th ↓ s (x, u) can be determined from f , Th ↓ s (x, u i ), and all theories Th ↓ s (u j ) with j = i; moreover, for every j = i, Th ↑ s (x, u j ) can be determined from f , Th ↑ s (u), Th ↓ s (x, u i ), and all theories Th ↓ s (u m ) with m = i, j. We note here that the mappings δ f considered above can be viewed as the transition rules of a complete and deterministic finite semi-automaton A = F, Q, δ with Q = P(L 1 ). Obviously, run A ,s (u) = Th ↓ s (u) for every s ∈ T (F ) and u ∈ N s . Hence, if ϕ ∈ L 0 has quantifier-height ≤ q and Acc consists of all subsets of L 1 that contain ϕ, then q∈Acc L(A , q) = {s ∈ T (F ) | s |= ϕ} (see Corollary 5.67).

We observe, as in Step 1 of the proof of Theorem 7.34, that for every Φ ⊆ L 1 there exists an MS formula η ↓ Φ (x 1 ) such that s |= η ↓ Φ (u) if and only if Th ↓ s (u) = Φ, and a similar formula η ↑ Φ (x 1 ) exists expressing that Th

↑ s (u) = Φ. The formula η ↓ Φ (x 1 ) is ∃X[∀y(y ∈ X ⇔ y ≤ x 1 ) ∧ ϕ∈Φ ϕ (X, x 1 ) ∧ ϕ∈L1-Φ ¬ϕ (X, x 1 )]
where y ≤ x 1 is a formula expressing that y is a descendant of x 1 and ϕ (X, x 1 ) is obtained from ϕ(x 1 ) X, the relativization of ϕ(x 1 ) to X (cf. Section 5.2.1), by the replacement of each atomic formula rt(z) by z = x 1 . Similarly, the formula η

↑ Φ (x 1 ) is ∃X[∀y(y ∈ X ⇔ ¬(y < x 1 )) ∧ ϕ∈Φ ϕ (X, x 1 ) ∧ ϕ∈L 1 -Φ ¬ϕ (X, x 1 )]
where ϕ (X, x 1 ) is obtained from ϕ(x 1 ) X by the replacement of each atomic formula lab w (z) by z = x 1 and each atomic formula lab f (z) (where f ∈ F ) by z = x 1 ∧ lab f (z).

Tree-walking transducers

To facilitate the proof of the implementation of MS-transductions of terms by tree-walking transducers, we will consider a hybrid device: a tree-walking transducer that uses MS tests and MS jumps.3 More precisely, it uses monadic second-order logic for two purposes: for a given input term s, (1) it can use a formula ϕ(x 1 ) to test a global property4 of the current node x 1 of s, and (2) it can use a formula ψ(x 1 , x 2 ) to describe conditions implying a jump5 in s from the current node x 1 to the next current node x 2 . This hybrid transducer will allow us to present the implementation in several steps. To stress the role of determinism, we also consider nondeterministic tree-walking transducers, and prove some of the results on transducers also for the nondeterministic case.

An MS tree-walking transducer (abbreviated ms-twt) is a 5-tuple M = (F, H, Q, q in , R), where F and H are functional signatures of input and output symbols, respectively, Q is a finite set of states, q in ∈ Q is the initial state, and R is a finite set of rules. A rule is of the form q, ϕ → ζ such that q ∈ Q, ϕ ∈ MS(R F , {x 1 }), and ζ equals 1. q , ψ , or 2. h( q 1 , ψ 1 , . . . , q k , ψ k ), where [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]

q ∈ Q and ψ ∈ MS(R F , {x 1 , x 2 }) such that s |= ∀x 1 [ϕ(x 1 ) ⇒ ∃! x 2 . ψ(x 1 , x 2 )] for every s ∈ T (F ), or (2) k ≥ 0, h ∈ H k , q 1 , . . . , q k ∈ Q and ψ 1 , . . . , ψ k ∈ MS(R F , {x 1 , x 2 }) such that s |= ∀x 1 [ϕ(x 1 ) ⇒ ∃! x 2 . ψ i (x 1 , x 2 )] for every s ∈ T (F ), i ∈ [k].
As usual the quantifier ∃! stands for "there exists exacly one". Rules of type 1 will be called epsilon-output rules.

The above conditions on ϕ, ψ, ψ 1 , . . . , ψ k are decidable by the Recognizability Theorem for terms (Corollary 5.67) and the decidability of the emptiness of a regular language (cf. Corollary 3.24). Thus, the definition of MS tree-walking transducer is effective.

The ms-twt M is deterministic if for every two distinct rules q 1 , ϕ 1 → ζ 1 and q 2 , ϕ 2 → ζ 2 in R, if q 1 = q 2 then ϕ 1 and ϕ 2 are mutually exclusive on T (F ), i.e., s |= ¬∃x 1 [ϕ 1 (x 1 ) ∧ ϕ 2 (x 1 )] for every s ∈ T (F ). Again, this is a decidable condition.

An MS tree-walking transducer is jumping rather than walking; moreover, it can do global rather than local tests (cf. the introduction of this section). We say that M is nonjumping if the only formulas ψ(x 1 , x 2 ) that are used in the righthand sides of rules are x 1 = x 2 (stay where you are), son(x 2 , x 1 ) (move to the father)6 , and son i (x 1 , x 2 ) for i ∈ [ρ(F )] (move to the i-th son). These formulas will also be denoted stay, up, and down i , respectively. We say that M is local if it is nonjumping and the only formulas ϕ that are used in the lefthand sides of rules are boolean combinations of lab f (x 1 ) for f ∈ F (is the label of the current node f ?), ∃y. son i (y, x 1 ) for i ∈ [ρ(F )] (is it the i-th son of its father?) and rt(x 1 ) (is it the root?) which can be viewed as an abbreviation of ¬ i∈[ρ(F )] ∃y. son i (y, x 1 ). In our terminology and notation, locality will be indicated by dropping 'MS'. Thus, a local MS tree-walking transducer is also called a tree-walking transducer (for short twt), and the class of transductions computed by the deterministic ones is denoted DTWT (and DTWT su for singleuse ones). The class of transductions computed by deterministic tree-walking tree-to-word transducers is denoted DTWTW, and the class of transductions (of words) computed by deterministic two-way finite-state transducers is denoted 2DGSM (where '2gsm' stands for 'two-way generalized sequential machine', a well-known name for the two-way finite-state transducer).

In the remainder of this section we consider examples of MS-transductions of words and terms that can be computed by tree-walking transducers.

Example 8.1 The yield of a term t ∈ T (F ) is the (nonempty) word yd (t) ∈ F * 0 defined recursively as follows: yd (f ) = f for f ∈ F 0 , and yd (f (t 1 , . . . , t k )) = yd (t 1 ) • • • yd (t k ) for f ∈ F k with k > 0 and t 1 , . . . , t k ∈ T (F ). The mapping yd is a 2-copying parameterless MS-transduction in DMSOTW: the positions of the output word yd (t) are the leaves of the input tree t, plus one extra position (e.g., the second copy of the last leaf). Each (first copy of a) leaf is linked to (the first copy of) the next leaf, in the left-to-right order of the nodes of t, and the first copy of the last leaf is linked to its second copy (which gets label ).

The mapping yd can also be computed by a (local) deterministic tree-walking tree-to-word transducer M = (F, H, Q, q in , R). The transducer walks depthfirst left-to-right through the input tree and outputs the labels of the leaves; it outputs when it returns to the root. Thus, yd is in the class DTWTW. To consider a concrete example, let A be a finite set. We take F := {f } ∪ A with ρ(f ) := 2 and ρ(a) := 0 for a ∈ A, and H := A ∪ { } with ρ(a) := 1 for a ∈ A and ρ( ) := 0. The set of states of M is Q := {↓, ↑ 1 , ↑ 2 } and q in := ↓. The rules in R are the following, for a ∈ A and i ∈ {1, 2} (and br i (x 1 ) abbreviates ∃y. son i (y, x 1 )):

↓, lab f (x 1 ) → ↓, down 1 ↓, lab a (x 1 ) ∧ br i (x 1 ) → a( ↑ i , up ) ↑ 1 , True → ↓, down 2 ↑ 2 , br i (x 1 ) → ↑ i , up ↑ 2 , rt(x 1 ) → ↓, lab a (x 1 ) ∧ rt(x 1 )
→ a( ↑ 2 , stay ).

Let us also consider a slightly more complicated example: let H := A ∪ { } with ρ(a) := 2 for a ∈ A and ρ( ) := 0, and define τ : T (F ) → T (H ) as follows. For every tree t ∈ T (F ), τ (t) is the unique tree in T (H ) such that the sequence of labels of the nodes of any path from the root to a leaf equals yd (t) (hence, all leaves are at the same depth in τ (t)). For instance, if t := f (f (a, b), c), then τ (t) = a(b(c( , ), c( , )), b(c( , ), c( , ))). The mapping τ is computed by the deterministic tree-walking transducer M that is obtained from M by changing the righthand side of the second rule into a( ↑ i , up , ↑ i , up ), and similarly the one of the last rule into a( ↑ 2 , stay , ↑ 2 , stay ). It is clear that M is not singleuse. The mapping τ is not in DMSOT, because it is not of linear size increase (cf. Section 8.1.1): if |yd (t)| = n (and hence |t| = 2n -1) then |τ (t)| = 2 n+1 -1.

As an additional example, let H := F ∪ {σ, c, d} where σ is binary and c, d are unary. Consider the mapping t → σ(c n (t), d n (t)) from T (F ) to T (H ) where n = |yd (t)|. It can be computed by a single-use deterministic treewalking transducer M that starts its computation with the rule q in , True → σ( ↓ c , stay , ↓ d , stay ), thus branching into two computations. In each branch, M walks depth-first left-to-right through t and outputs the symbol c (or d) at each leaf. After returning to the root, it outputs the input tree t (by the rules q id , lab f (x 1 ) → f ( q id , down 1 , q id , down 2 ) and q id , lab a (x 1 ) → a for a ∈ A).

Example 8.2 In Remark 7.23 an MS-transduction of words is discussed that does not preserve regularity of languages. It transforms the word

a 1 a 2 a 3 • • • a 2n into the word a 1 a 3 • • • a 2n-1 a 2 a 4 • • • a 2n .
It is clear that this transduction can be computed by a deterministic two-way finite-state transducer: the transducer walks to the right and outputs all letters at odd positions; then it returns to the beginning of the input (without producing output) and walks again to the right, this time writing the letters at even positions to the output tape.

As a similar, slightly more complicated example, consider the mapping τ on words that associates with w ∈ {a, b, c, d} * the word τ (w) := a k b l c m d n where k = |w| a (the number of occurrences of a in w), l = |w| b , m = |w| c , and n = |w| d . It is not difficult to see that τ is a parameterless domain-preserving MS-transduction, i.e., that there is a parameterless domain-preserving definition scheme D = χ, δ, (θ R ) R∈R U A such that D( µ A (w) ) is (isomorphic to) µ A (τ (w)) for every w ∈ A * , where A := {a, b, c, d}. In fact, both χ and δ are True, and for every f ∈ U A = A ∪ { } we have θ lab f = lab f (x 1 ) (which means that every node keeps its label). The details of the formula θ son1 (x 1 , x 2 ) are left to the reader: it should link each occurrence of a in w to the next occurrence of a, unless it is the last occurrence of a, in which case it should be linked to the first occurrence of b; and similarly for b and c, for c and d, and for d and .

It should also be clear that τ can be computed by a deterministic two-way finite-state transducer. The transducer scans the input word four times (for instance from left to right and from right to left, and then again). At the first scan it outputs all occurrences of a, and at the next scans all occurrences of b, c, and d; finally it outputs .

Thus, τ is in both DMSOW and 2DGSM. Let L be the regular language (abcd) * . Obviously, τ (L) = {a n b n c n d n | n ≥ 0}. Hence, τ does not preserve regularity or context-freeness of languages (see the discussion in the introduction of this chapter). We know from Corollary 7.12 that τ -1 preserves regularity. Now consider the context-free language

L = {a k b k c m d m | k, m ≥ 0}. Then τ -1 (L )
is not context-free; in fact, if it would be context-free then its intersection with the regular language R = (ac) * b * d * would also be context-free, but it is clear that τ

-1 (L ) ∩ R = {(ac) n b n d n | n ≥ 0}, a classical noncontext-free language.
Thus, inverse MS-transductions of words do not preserve context-freeness of languages.

Example 8.3 A transduction of words τ : A * → B * is a rational transduction if it can be expressed as follows7 : τ (w) = h (h -1 (w) ∩ L) for every w ∈ A * , where L ⊆ C * is a regular language over some alphabet C, and h : C * → A * and h : C * → B * are homomorphisms (for equivalent characterizations see the book by Sakarovitch [*Sak]). In other words, τ = h -1 • Id L • h , where Id L is the identity on L. It is well known (and the proof is straightforward) that all rational transductions can be computed by two-way, even one-way, finite-state transducers. In fact, the rational transductions are exactly those computed by one-way finite-state transducers (see Chapter 4 of [*Sak]).

It is clear that all homomorphisms are parameterless MS-transductions (the definition scheme for h is k-copying, where k is the maximal length of a word h (c) with c ∈ C, cf. Example 7.3(4)). Hence, since L is MS-definable by Theorem 5.15, the partial function Id L • h is a parameterless MS-transduction by the Restriction Theorem (Theorem 7.16). However, inverse homomorphisms are not MS-transductions, because, in general, they do not have finite images (whereas MS-transductions do, see Section 8.1.1). Thus, the class of MS-transductions of words is not closed under inverse, cf. the discussion in the introduction of this chapter. If the homomorphism h is nonerasing (i.e., h(c) = ε for all c ∈ C), then h -1 is a noncopying MS-transduction (cf. Example 7.3(4)): its definition scheme uses a parameter X intended to denote the set {u 1 , . . . , u n } ⊆ Pos(µ A (w)) where u i is the first position of a subword h(c i ) of the input word w, such that w = h(c 1 ) • • • h(c n ) for c 1 , . . . , c n ∈ C; additionally, it uses parameters X c for c ∈ C, that form the partition of {u 1 , . . . , u n } such that X c denotes {u i | c i = c}; in other words, the parameters represent a guess of a word

v = c 1 • • • c n ∈ C *
such that h(v) = w; the output word v is constructed from the positions in the set denoted by X, and such a position is given the label c if it belongs to the set denoted by X c . Thus, in this case the rational transduction τ is an MStransduction, by Theorem 7.14. Every rational transduction τ that has finite images, can be expressed as above with h nonerasing (see the book by Berstel [*Ber, Exercise 7.2, page 87], or the one by Autebert and Boasson [*AutBoa,Chapter 1]). Consequently, a rational transduction is an MS-transduction if and only if it has finite images.

Example 8.4 Let w be the mirror image of the word w. The mapping τ (w) := w w is in 2DGSM: the transducer first walks from left to right over the input word, and then back from right to left; it outputs each letter that it meets on its way. If it does not produce output during the walk from left to right, it computes the mapping τ (w) := w. Both τ and τ are deterministic MStransductions (2-copying and noncopying, respectively). Note that neither τ nor τ is a rational transduction; τ preserves regularity and context-freeness, but τ does not. For every k ≥ 2, the mapping τ k (w) := w k is in 2DGSM: the transducer walks k times from left to right over the input word, writing it to the output tape (each time walking back from right to left without producing output). Moreover, τ k is a k-copying parameterless MS-transduction (in DMSOW); it can be expressed as copy k • µ, where µ is a noncopying parameterless MStransduction, cf. Proposition 7.26. As a more complicated example, consider the alphabet B := {a 1 , a 2 , b} and the mapping σ : B * → B * defined by

σ(w 0 bw 1 bw 2 • • • bw n ) := w 0 w 0 bw 1 w 1 bw 2 w 2 • • • bw n w n ,
where w i ∈ {a 1 , a 2 } * . The mapping σ is a 2-copying parameterless MS-transduction in DMSOW. It is also in 2DGSM: the transducer scans each subword w i three times and outputs that word when walking to the right. Now let F be the functional signature {f } ∪ B where f has arity 2 and the elements of B have arity 0. Then the mapping σ := yd • σ : T (F ) → B * is in DMSOTW (cf. Example 8.1). It is also in DTWTW: a tree-walking tree-to-word transducer can walk from one b-labelled leaf to the next one, or to the previous one.

Example 8.5 The second-order substitutions, defined in Section 2.6.1 (just before Proposition 2.126), and discussed in Example 7.3(4), are often called tree homomorphisms. Every second-order substitution can be computed by a (local) deterministic tree-walking transducer of which the rules do not use up; for instance, if the derived operation h of arity 3 is defined by the term f (x 3 , g(x 1 )), then the transducer has rules q in , lab h (x 1 ) → f ( q in , down 3 , q, stay ) and q, True → g( q in , down 1 ), where q is a "new" state. Moreover, if the secondorder substitution is linear (as in the above instance), then the transducer is single-use. Thus, every linear second-order substitution is in DTWT su . It is also a parameterless MS-transduction in DMSOT, cf. Example 7.3(4). As discussed in Example 7.3(4), not all second-order substitutions are MS-transductions.

This shows again that tree-walking transducers have more expressive power than MS-transductions of terms.

The basic characterization

We start by characterizing the MS-transductions of terms by MS tree-walking transducers that are single-use. Intuitively, the single-use restriction means that the tree-walking transducer can output at most k copies of each input node, where k is its number of states: due to determinism, if the transducer visits an input node twice in the same state, then it repeats its computation and hence does not halt and produces no output. This integer k corresponds to the copying number of a definition scheme.

Theorem 8.6 The classes DMSOT and DTWT MS su are equal.

Proof: We first prove the inclusion DMSOT ⊆ DTWT MS su . Let τ : T (F ) → T (H) be a deterministic MS-transduction of terms, i.e., {( s , t

) | (s, t) ∈ τ } is a parameterless MS-transduction from STR(R F ) to STR(R H ). Let D = χ, (δ i ) i∈[k] , (θ w ) w∈R H [k] be a parameterless definition scheme of type R F → R H defining τ , hence D( s ) = τ (s)
for every s ∈ T (F ). We define an MS tree-walking transducer M := (F, H, Q, q in , R) that computes τ , as follows. First, its set of states is Q := {q in , q 1 , . . . , q k }. Intuitively, for i ∈ [k], the state q i represents the i-th copy of the input structure. More precisely, if M is in configuration q i , u on the input structure s , then it will output the node (u, i) of the output structure τ (s) , cf. Definition 7.2. It remains to define the set R. We first define the rules for q in . Intuitively, M starts its computation by jumping to the node of the input tree that will represent the root of the output tree. For every i ∈ [k], M has the rule:

q in , χ ∧ ∃x[δ i (x) ∧ θ rt,i (x)] → q i , δ i (x 2 ) ∧ θ rt,i (x 2 ) .
Now suppose that M is in configuration q i , u . Then it outputs the node (u, i) of the output tree and jumps to the nodes of the input tree that will represent the sons of (u, i). To do this, it has to determine the label of the node (u, i), and the input nodes for its sons. For every h ∈ H m and every j 1 , . . . , j m ∈ [k], M has the rule q i , ϕ → h( q j1 , ψ 1 , . . . , q jm , ψ m ) where ϕ is

χ ∧ δ i (x 1 ) ∧ θ lab h ,i (x 1 ) ∧ n∈[m] ∃y[δ jn (y) ∧ θ sonn,i,jn (x 1 , y)] and ψ n is δ jn (x 2 ) ∧ θ sonn,i,jn (x 1 , x 2 ).
It should be clear that M computes τ , and that M is deterministic. Moreover M is single-use, because the configurations of its computation (except the first one) are in bijection with the nodes of the output tree.

For the inclusion DTWT MS su ⊆ DMSOT, let M = (F, H, Q, q in , R) be a singleuse deterministic MS tree-walking transducer. We first consider the special case where M has no epsilon-output rules. Without loss of generality, we assume that Q = [k] for some k ≥ 1.

Since M is deterministic and single-use, each node of the output tree (for a given input tree s) is produced by a unique configuration q, u of M , with q ∈ [k] and u ∈ N s . Hence a k-copying definition scheme for τ M can be constructed that uses (u, q) for that node. To simplify the construction we will actually show that τ M is the composition τ 1 • τ 2 of two parameterless MS-transductions, of which the first is k-copying and the second is noncopying. This gives the desired result by Theorem 7.14.

The first MS-transduction τ 1 transforms the input tree s into the "computation space" of M on s, which is a structure S in STR c (R H ) that encodes the regular grammar G M,s = H, X M,s , R M,s and the initial configuration q in , root s . The structure S has the domain {(u, q) | q, u ∈ X M,s }, and it has the unary relation rt S = {(root s , q in )}. Let q, u → h( q 1 , v 1 , . . . , q m , v m ) be a rule in R M,s . Then (u, q) is in lab hS , and ((u, q), (v i , q i )) is in son iS , for every i ∈ [m]. Note that S represents an (H, [ρ(H)])-labelled directed graph with a designated node (the "root").

This MS-transduction τ 1 is defined by the k-copying parameterless definition scheme D

1 := χ, (δ i ) i∈[k] , (θ w ) w∈R H [k] of type R F → R H .
The precondition χ expresses that the input structure represents a term in T (F ), see Corollary 5.12. For every q, q ∈ [k], δ q is True, θ rt,q is rt(x 1 ) if q = q in and False otherwise, θ lab h ,q is the disjunction of all formulas ϕ such that q, ϕ → h( q 1 , ψ 1 , . . . , q m , ψ m ) is a rule of M , and θ soni,q,q is the disjunction of all formulas ϕ ∧ ψ i such that q, ϕ → h( q 1 , ψ 1 , . . . , q m , ψ m ) is a rule of M with i ∈ [m] and q i = q .

The second MS-transduction τ 2 will be obtained by the Restriction Theorem from the mapping τ 2 that transforms the computation space into the subgraph induced by all vertices that are reachable from the "root" of the graph. Thus, τ 2 is defined by the noncopying parameterless definition scheme

D 2 := True, δ, (θ R ) R∈R H of type R H → R H such that δ is the formula ∃y(rt(y) ∧ TC[(λu, v • son(u, v)); y, x 1 ]), θ lab h is lab h (x 1 ), θ soni is son i (x 1 , x 2 ),
and θ rt is rt(x 1 ).8

It remains to check that the resulting graph is a tree (i.e., that s is in the domain of τ M ). Since M is single-use, it suffices to check that (1) there is no circuit (otherwise the computation of M on s does not halt), and (2) every vertex has a label in H (otherwise the computation of M on s aborts). This is expressed by the sentence β := ∀x, y(TC [(λu, v •son(u, v)); x, y] ⇒ ¬son(y, x))∧ ∀x h∈H lab h (x). Thus, τ 2 := τ 2 ∩ (MOD(True) × MOD(β)) is a noncopying parameterless MS-transduction by Theorem 7.16.

Finally, we consider a single-use deterministic MS tree-walking transducer M = (F, H, Q, q in , R) with epsilon-output rules. Let the deterministic ms-twt M := (F, H ∪ { }, Q, q in , R ) be obtained from M by changing every epsilonoutput rule q, ϕ → q , ψ of M into the output producing rule q, ϕ → ( q , ψ ) of M , where is a new output symbol of arity 1. Obviously M is still single-use, and thus we know that τ M is in DMSOT. It is also obvious that τ M = τ M • τ , where τ : T (H ∪ { }) → T (H) is the linear second-order substitution that replaces (x 1 ) by x 1 . By Example 7.3(4), τ is a parameterless MS-transduction, and hence so is τ M by Theorem 7.14.

The subscript 'su' cannot be dropped from Theorem 8.6, because DTWT contains transductions that are not of linear size increase, cf. Example 8.1. If the output signature is unary, then it can be dropped, because every mstwt with a unary output signature is single-use. Thus: DMSOTW = DTWTW MS .

We observe that the construction of a parameterless definition scheme for an MS tree-walking transducer M , as described in the above proof, can also be carried out in the case where M is not single-use. Then, instead of a tree, the output structure is a directed graph G without circuit (i.e., a tree with shared subtrees). Unfolding G produces the output tree of M . This also shows that it is decidable whether or not M is single-use: M is single-use if and only if the indegree of every vertex of G is at most 1, for every output G. Since this is an MS-expressible property, the set of all input terms such that G does not satisfy this property is regular by Corollaries 7.12 and 5.67, and can be checked for emptiness.

From jumping to walking

Our aim will now be to "get rid of" the MS tests and MS jumps of our hybrid tree-walking transducer. It turns out that MS jumps can be simulated by treewalking transducers, provided these transducers are still allowed to use MS tests. However, MS tests cannot be handled by tree-walking transducers; thus, for the simulation of tests other means have to be found. We therefore start with the "removal" of jumps.

Theorem 8.7 For every MS tree-walking transducer an equivalent nonjumping MS tree-walking transducer can be constructed. Determinism and the single-use restriction are preserved.

Proof: Let M be an ms-twt with input signature F . The problem is to simulate by a walk a jump of M defined by a formula ψ ∈ MS(R F , {x 1 , x 2 }) in the righthand side of a rule of M . We may assume that s |= ∀x 1 ∃! x 2 . ψ(x 1 , x 2 ) for every s ∈ T (F ). If this is not the case, we replace ψ by (ϕ ∧ ψ) ∨ (¬ϕ ∧ x 1 = x 2 ), where ϕ ∈ MS(R F , {x 1 }) is the formula in the lefthand side of the rule.

We will prove that for every such formula ψ a nonjumping deterministic ms-twt M ψ = (F, ∅, Q, q in , R) can be constructed that has only epsilon-output rules, and that has a state q f such that for every s ∈ T (F ) and y, z ∈ N s , s |= ψ(y, z) if and only if q in , y ⇒ * G q f , z , where G is the regular grammar G M ψ ,s (cf. Section 8.2). It is easy to see that, using these transducers M ψ as "subroutines", M can be turned into an equivalent nonjumping ms-twt. Since every M ψ is deterministic, determinism and the single-use restriction will be preserved. Note that since M ψ has epsilon-output rules only, it is essentially a tree-walking automaton rather than a tree-walking transducer.

So, let ψ ∈ MS(R F , {x 1 , x 2 }) such that s |= ∀x 1 ∃! x 2 . ψ(x 1 , x 2 ) for every s ∈ T (F ). Let q := max{qh(ψ), m} + 2 where m is the quantifier-height of the formula expressing that x 1 is a descendant of x 2 . For this q (and F ), we will use the definitions in Section 8. 1.3.

The transducer M ψ := (F, ∅, Q, q in , R) to be constructed, should walk from node y to node z if and only if s |= ψ(y, z). It will do this in a special way: it walks along the shortest (undirected) path in s from y to z, and, roughly speaking, at each node u on this path it keeps track, in its state at that node, of the (finite) theory Th ↓ s (y, u) or Th ↑ s (y, u) depending on whether or not y is a descendant of u.

More precisely, M ψ first walks from y up to the least common ancestor lca(y, z) of y and z, and at each node u on that path (except y) it is in state ↑ i,Φ such that y is a descendant of the i-th son u i of u and Φ = Th ↓ s (y, u i ). Then, M ψ walks from lca(y, z) down to z, and at each node u on that path (except lca(y, z)) it is in state ↓ Φ such that Φ = Th ↑ s (y, u). Thus, the set Q of states of M ψ consists of q in , q f , ↑ i,Φ , and ↓ Φ , for all i ∈ [ρ(F )] and Φ ⊆ L 2 ∪ L 2 . The righthand sides of the rules in R are of one of the three forms ↑ i,Φ , up , ↓ Φ , down j , or q f , stay . Recall that up, down j , and stay denote the formulas son(x 2 , x 1 ), son j (x 1 , x 2 ), and x 1 = x 2 , respectively.

For every node u that M ψ visits, it uses a test of the form

η ↑ Φ (x 1 ) ∧ ∃y 1 [son 1 (x 1 , y 1 ) ∧ η ↓ Φ1 (y 1 )] ∧ • • • ∧ ∃y k [son k (x 1 , y k ) ∧ η ↓ Φ k (y k )]
to obtain the sets Th ↑ s (u) and Th ↓ s (u 1 ), . . . , Th ↓ s (u k ), where u 1 , . . . , u k are the sons of u (see the end of Section 8. 1.3). It should now be clear from Section 8.1.3 that from these sets, and the state ↑ i,Φ or ↓ Φ at u, and the label of u (which can of course be obtained by a test lab f (x 1 )), M ψ can determine the set Th s (y, u). If ψ is in that set (or more precisely, if ψ ∈ Th s (y, u)), then u = z and M ψ halts in state q f . Now assume that it is not. Then M ψ should decide, deterministically, where to go next. Suppose first that M ψ is in state ↑ i,Φ . If for some j = i the formula ψ j (x 1 , x 2 ), defined as ∃v, w[son j (x 2 , v) ∧ w ≤ v ∧ ψ(x 1 , w)], is in Th s (y, u), then u = lca(y, z) and M ψ moves down to the j-th son of u; otherwise, M ψ moves up to the father of u. In the former case the new state is ↓ Φ where Φ can be determined (according to Section 8.1.3) from Φ, Th ↑ s (u), and all Th ↓ s (u m ) with m = i, j. In the latter case the new state is ↑ i ,Φ where i can be obtained by a test ∃v. son i (v, x 1 ), and Φ can be determined from Φ and all Th ↓ s (u j ) with j = i. Suppose now that M ψ is in state ↓ Φ . This case is similar to, but easier than the previous one: if the formula ψ j (x 1 , x 2 ) is in Th s (y, u) (and that must be so for exactly one j ∈ [k]), then M ψ moves down to the j-th son of u in the state ↓ Φ , where Φ can now be determined from Φ and all Th ↓ s (u i ) with i = j.

It remains to explain how M ψ starts its walk, in state q in . It first tests whether y = z, by checking if the rule q in , ψ(x 1 , x 1 ) → q f , stay is applica-ble. If that is not the case, then M ψ uses the test formulas ψ j (x 1 , x 1 ), i.e., ∃v, w[son j (x 1 , v) ∧ w ≤ v ∧ ψ(x 1 , w)]. If such a formula is true, then M ψ moves down to the j-th son of y in state ↓ Φ , where Φ can be determined from Th ↑ s (y, y) and all Th ↓ s (y i ) with i = j (where y i is the i-th son of y). Otherwise, M ψ moves up to the father of y in state ↑ i,Φ where y is the i-th son of its father and Φ := Th ↓ s (y, y). Note that Th ↑ s (y, y)

= {ϕ(x 1 , x 2 ) | ϕ(x 1 , x 1 ) ∈ Th ↑ s (y)} and Th ↓ s (y, y) = {ϕ(x 1 , x 2 ) | ϕ(x 1 , x 1 ) ∈ Th ↓ s (
y)}, and that Th ↑ s (y) and Th ↓ s (y) can be obtained by a test.

This ends the description of the nonjumping ms-twt M ψ . Due to the condition on ψ, which says that for every y there is a unique z such that s |= ψ(y, z), the transducer M ψ is deterministic.

From global to local tests

We first show that MS tests can be simulated by tree-walking transducers in the special case where the input signature is unary. For this we need the fact that a two-way automaton can keep track of the state of a deterministic one-way automaton. This is expressed in the next lemma, in an informal, but hopefully clear way. We use the terminology and notation from Section 8.1.2. Lemma 8.8 Let M be an MS tree-walking transducer with a unary input signature F , and let A be a complete and deterministic finite F -semi-automaton. Then an MS tree-walking transducer M can be constructed that stepwise simulates9 M and keeps track of the state of A ; in its non-local rules, M uses the same MS formulas as M . The same holds if A is a top-down complete and deterministic finite F -automaton. Determinism and the single-use restriction are preserved in the construction of M from M .

Proof: Let A = F, Q, δ be a complete and deterministic finite semi-automaton. The ms-twt M should stepwise simulate M and, for every input tree s ∈ T (F ) and current node u ∈ N s , keep track (in its finite state at u) of p := run A ,s (u). In fact, M will behave in exactly the same way as M , except that after each "simulation step" it uses local epsilon-output rules to compute the new value of p, deterministically.

We will view p as a programming variable, to which assignments can be made. To initialize the variable p, M first walks down to the unique leaf of s (its -labelled node), and then walks back to the root, simulating A ; note that it can recognize the root by the local test rt(x 1 ). Then M sets p := run A ,s (root s ), and starts the simulation of M . Suppose that, simulating a step of M , M moves up to the father of the current node. To update p it simply tests the label of the father, say f , and sets p := δ f (p).

Suppose now that M moves down to the son of the current node u. This is the difficult case. Let f be the label of u. If the label of the son u 1 is , then M simply sets p := δ . If it is not, then the new p must be in the set C := {q ∈ Q | δ f (q) = p} (where C stands for "candidates"). If C is a singleton, the problem is solved. Now suppose it is not a singleton. Then M walks down from u 1 and computes for each descendant u of u 1 , and each q ∈ C, the set C(q, u ) of all states q ∈ Q such that, when started at u in state q , A reaches u 1 in state q. Note that, for fixed u , the sets C(q, u ) are pairwise disjoint. It is easy to see that M can compute these sets, just by testing the labels of the nodes and using δ. In fact, C(q, u 1 ) := {q} and if u is the son of u , then C(q, u ) := {q ∈ Q | δ f (q ) ∈ C(q, u )}, where f is the label of u . Now there are two cases: either M arrives at a descendant u such that exactly one of the sets C(q, u ), say C(q, u ), is nonempty, whereas all the others are empty, or M arrives at the leaf u of s, in which case there is a unique q such that δ ∈ C(q, u ). In both cases, q = run A ,s (u 1 ) and M sets p := q. But now M should return to u 1 . To this purpose, M moves up to the father u of u and picks two states q 1 , q 2 ∈ Q that are in two distinct sets C(q, u ) (obviously, when walking down, M can also store in its state the candidate sets of the father of the current node). Now M starts the simulation of two incarnations A 1 and A 2 of the automaton A , one in state q 1 and the other in state q 2 at u . Then M walks up, simulating both A 1 and A 2 . At the very moment where A 1 and A 2 are in the same state (which is the previous value of p), M is back on node u, and moves down to u 1 . This ends the description of M .10

Finally, let A be a top-down complete and deterministic finite automaton, with Acc := {q 0 }. This time, M should keep track of p := td -run A ,s (u). The proof is basically the same as the one above, interchanging the up and down moves, and interchanging the roles of the root and the leaf of s. Initially, M just sets p := q 0 . When M moves down from u, M sets p := q where f [q] → p is the unique rule in δ with righthand side p and f is the label of u. Now the difficult case is when M moves up to u from its son u 1 . The computation of the new p is similar to the one above, with M first walking up and computing the candidate sets for the ancestors of u, possibly reaching the root, then walking down to u 1 and finally moving up to u. Theorem 8.9 For every MS tree-walking transducer with a unary input signature an equivalent (local) tree-walking transducer can be constructed. Determinism and the single-use restriction are preserved.

Proof: Let M be an ms-twt with unary input signature F . By Theorem 8.7 we may assume that M is nonjumping. The remaining problem is how to simulate a global test of M , defined by a formula ϕ ∈ MS(R F , {x 1 }) in the lefthand side of a rule of M , by an ordinary walk that uses local tests only.

So, let ϕ ∈ MS(R F , {x 1 }) and let q be the quantifier-height of ϕ. It suffices to prove that M can be changed into a transducer M that stepwise simulates M and, moreover, for input tree s ∈ T (F ) and current node u ∈ N s , additionally keeps track (in its finite state at u) of the theories p 1 := Th ↓ s (u 1 ) (if u has a son u 1 ) and P := Th ↑ s (u). Recall from Section 8.1.3 that there is a mapping Z f such that Th s (u) = Z f (Th ↑ s (u), Th ↓ s (u 1 ), . . . , Th ↓ s (u k )), where u has sons u 1 , . . . , u k (with k = 1 or k = 0) and label f . Hence, in M , the global test ϕ can be replaced by the local test consisting of the disjunction of all formulas lab f (x 1 ) such that ρ(f ) = 1 and ϕ ∈ Z f (P, p 1 ), and the formula lab (x 1 ) if ϕ ∈ Z (P ).

The construction of M is possible by Lemma 8.8. Recall from Section 8.1.3 that there is a complete and deterministic finite F -semi-automaton A such that for every s ∈ T (F ) and u ∈ N s , run A ,s (u) = Th ↓ s (u). It is easy to construct from A a complete and deterministic finite F -semi-automaton A 1 such that run A1,s (u) = lab s (u), Th ↓ s (u 1 ) if u has a son u 1 (where lab s (u) is the label of u). Thus, by Lemma 8.8, there is an ms-twt M 1 that stepwise simulates M and keeps track of Th ↓ s (u 1 ). It should also be clear from Section 8.1.3, and from the fact that F is unary, that there is a top-down complete and deterministic finite F -automaton A 2 such that td -run A2,s (u) = Th ↑ s (u) for every s ∈ T (F ) and u ∈ N s . In fact, A 2 has the set of states P(L 1 ) and the unique initial state Th ↑ rt (the root theory, defined in Section 8.1.3); the transition rules of A 2 are obtained from the mappings Z f,1 : P(L 1 ) → P(L 1 ) discussed in Section 8.1.3. Again by Lemma 8.8, applied to M 1 and A 2 , there is an mstwt M that stepwise simulates M and keeps track of both Th ↓ s (u 1 ) and Th ↑ s (u).

The next theorem (which is the main result of [START_REF] Engelfriet | MSO definable string transductions and two-way finite state transducers[END_REF]) is now immediate from Theorems 8.6 and 8.9. It shows that the monadic second-order transductions of words are exactly those computed by two-way finite-state transducers (see Examples 8.2 and 8.4). This generalizes the monadic case of Theorem 1.16 to transductions.

Theorem 8.10 The classes of transductions of words DMSOW and 2DGSM are equal.

In general, it is not possible to "remove" the MS tests from an MS treewalking transducer, not even when it is an MS tree-walking automaton. This result is proved by Bojańczyk and Colcombet in [BojCol].

Theorem 8.11 The class DTWTW MS contains a transduction that is not in the class DTWTW. 11 Proof: Every regular tree language L can be recognized by a deterministic MS tree-walking automaton. In fact, the automaton need not walk at all: if the MS sentence ϕ expresses L (by Theorem 5.15), then the rule q in , ϕ → suffices. However, not every regular tree language can be recognized by a treewalking automaton [BojCol]. Thus, to "remove" MS tests in general, a more powerful type of transducer is needed. One such transducer can be obtained by equipping the nonjumping MS tree-walking transducer with a restricted pushdown. This extended transducer can only push a symbol on the pushdown when it moves down to a son, and it has to pop the top symbol off the pushdown when it moves to the father. In other words, the movements of the pushdown are synchronized with the movements of the reading head. Initially (at the root) the pushdown contains one symbol, and hence, at each moment, the number of symbols on the pushdown equals the depth of the current node u, i.e., its number of ancestors (including itself).12 Each cell of the pushdown corresponds to an ancestor of u, and the content of the cell provides information about that ancestor; in particular, the top of the pushdown corresponds to u itself, and the bottom to the root.

Formally, an MS tree-walking pushdown transducer (abbreviated p-ms-twt) is a tuple M = (F, H, Q, q in , Γ, γ in , R), where F , H, Q, and q in are the same as for an ms-twt, Γ is an alphabet of pushdown symbols, γ in is the initial pushdown symbol, and R is a finite set of rules. A rule is of the form q, ϕ, γ The transducer M is deterministic if for every two distinct rules q, ϕ 1 , γ → ζ 1 and q, ϕ 2 , γ → ζ 2 in R, ϕ 1 and ϕ 2 are mutually exclusive on T (F ). Just as we did for an ms-twt, we define for every input term s ∈ T (F ) a regular grammar G M,s := H, X M,s , R M,s . The set X M,s of configurations of M on s now consists of all triples q, u, π with q ∈ Q, u ∈ N s , and π ∈ Γ * such that the length of π equals the depth of u. If q, ϕ, γ → ζ is a rule in R, then R M,s contains all rules q, u, πγ → ζ for every u ∈ N s such that s |= ϕ(u) and every π ∈ Γ * such that |πγ| equals the depth of u, where ζ is defined as follows:

→ ζ with q ∈ Q, ϕ ∈ MS(R F , {x 1 }), γ ∈ Γ, and either ζ ∈ I or ζ = h(ζ 1 , . . . , ζ k ) with h ∈ H k and ζ 1 , . . . , ζ k ∈ I, where I is the set of all triples q , ψ, β with q ∈ Q, ψ ∈ MS(R F , {x 1 , x 2 }),
1. if ζ = q , ψ, β , then ζ := q , v, πβ and v is the unique node such that s |= ψ(u, v), ρ(f ) = k, b ∈ {0, 1}, and q 1 , . . . , q n ∈ Q with n ≤ k (using the states ↓ and ↑ b,q for every b ∈ {0, 1} and q ∈ Q):

(

1) if n < k, then ↓, lab f (x 1 ), (b, q 1 • • • q n ) → ↓, down n+1 , (b, q 1 • • • q n )(0, ε) , (2) if n = k and δ f (q 1 , . . . , q n ) = q, then ↓, lab f (x 1 ), (b, q 1 • • • q n ) → ↑ b,q , up, ε , (3) if n < k, then ↑ 0,q , lab f (x 1 ), (b, q 1 • • • q n ) → ↓, stay, (b, q 1 • • • q n q) .
Thus, the subroutine returns to u in some state ↑ 1,q , and then M stores p i := q in its state. It remains to show how M keeps track of P = Th ↑ s (u). The value of P is stored on the pushdown. Thus, if M has pushdown alphabet Γ and initial pushdown symbol γ in , then M uses the pushdown symbols (γ, S) with γ ∈ Γ and S ⊆ L 1 , and has initial pushdown symbol (γ in , Th ↑ rt ) where Th ↑ rt is the root theory. Clearly, it suffices to show how P can be computed when M moves down from node u to the i-th son u i , simulating a step of M . That is easy: at u, M has computed p 1 = Th ↓ s (u 1 ), . . . , p k = Th ↓ s (u k ) (as indicated above), and it has stored P = Th ↑ s (u) in the top of the pushdown. From this it can determine Th ↑ s (u i ) = Z f,i (P, p 1 , . . . , p i-1 , p i+1 , . . . , p k ) as observed in Section 8.1.3, and push Th ↑ s (u i ) as second component of the new top symbol when moving down to u i . Theorems 8.6, 8.7, and 8.12 together show that the monadic second-order transductions of terms can be computed by tree-walking pushdown tree transducers.

Theorem 8.13 The following inclusions hold: DMSOT ⊂ P-DTWT and DMSOTW ⊂ P-DTWTW.

The inclusions are proper because the word transduction a n → a 2 n is in P-DTWTW: the pushdown can be used to count to 2 n , in binary. This also shows that DTWT MS is properly included in P-DTWT: a deterministic MS tree-walking transducer with set of states Q can visit each node of a n ( ) at most |Q| times (otherwise it is in a loop) and hence the height of the output tree is at most |Q| • (n + 1).

It follows from Theorem 7.29 (based on Proposition 6.54) that every parameterless MS-transduction of terms can be computed in linear time (but usually with a large constant). We present here an alternative, but similar, proof using the construction in the proof of Theorem 8.12. As in the case of Theorem 7.29, the corresponding linear-time algorithm is not directly applicable, due to the large constant.

Theorem 8.14 Every MS-transduction τ in DMSOT can be computed in linear time, that is, for a given input term s the value of τ (s) can be computed in time O(|s|).

Proof: Let τ be an MS-transduction in DMSOT. By Theorems 8.6 and 8.7, the transduction τ is computed by a single-use deterministic nonjumping MS treewalking transducer M = (F, H, Q, q in , R). We first observe that M computes in linear time, assuming that each computation step takes one time unit. More precisely, for every s ∈ T (F ) and

t ∈ T (H), if q 0 , root s = ξ 0 ⇒ G M,s ξ 1 ⇒ G M,s ξ 2 ⇒ G M,s • • • ⇒ G M,s ξ n = t, then n ≤ |Q| • |s|.
To see this, we show that each configuration q, u of M is rewritten at most once during this computation. Suppose it is rewritten both in ξ i and in ξ j , with i < j. Let ξ i be of the form ξ i = w 0 q 1 , u 1 w 1 • • • q k , u k w k , where each q l , u l is a configuration and w 0 , w 1 , . . . , w k do not contain configurations. Then ξ j is of the form

ξ j = w 0 ζ 1 w 1 • • • ζ k w k with q l , u l ⇒ * G M,s ζ l for every l ∈ [k]
. Let q, u = q m , u m . Since q, u is rewritten in ξ i , q, u does not occur in ζ m , because otherwise the deterministic transducer M would loop and the computation would be infinite. Thus, q, u occurs in one of

ζ 1 , . . . , ζ m-1 , ζ m+1 , . . . , ζ k . Now consider the computation ξ 0 ⇒ * G M,s ξ i ⇒ * G M,s ξ ⇒ * G M,s ξ j ⇒ * G M,s t with ξ = w 0 ζ 1 w 1 • • • ζ m-1 w m-1 q m , u m w m ζ m+1 w m+1 • • • ζ k w k . It contradicts the fact that M is single-use, because q, u occurs at least twice in ξ.
Thus, assuming that each computation step takes constant time, τ (s) can be computed in linear time: on input s, at most |Q|•|s| computation steps of M are executed. However, in each computation step, global tests must be simulated. For each such test (with quantifier-height q), as in the proof of Theorem 8.12, it now suffices to show that M can be stepwise simulated in such a way that, for input tree s ∈ T (F ) and current node u ∈ N s , the information p 1 := run A ,s (u 1 ), . . . , p k := run A ,s (u k ) (if u has k sons u 1 , . . . , u k ) and P := Th ↑ s (u) is available, where A is the complete and deterministic F -semi-automaton such that run A ,s (u i ) = Th ↓ s (u i ) (see Section 8.1.3). Rather than computing the states p 1 , . . . , p k each time M visits u (as in the proof of Theorem 8.12), we can preprocess the input tree s by first computing the (unique) run run A ,s : Pos(s) → Q A of A on s, where Q A is the set of states of A . Now p 1 , . . . , p k are available to M in constant time whenever it visits u. The run of A on s can be computed in time O(|s|) and so, since M has only finitely many global tests, the total preprocessing time is linear.

The set of formulas P can be computed using the pushdown of a p-ms-twt. As described at the end of the proof of Theorem 8.12, this pushdown can be updated in constant time in each computation step of M (using p 1 , . . . , p k ). Thus, P is available whenever M visits u.

Next we use Theorem 8.13 to prove that every MS tree-walking transducer can be simulated by a composition of two tree-walking transducers, the first of which only walks down in the input tree. A deterministic tree-walking transducer is called a deterministic top-down tree transducer if it does not use the formula up in the righthand sides of its rules (cf. Example 8.5). The class of transductions computed by deterministic top-down tree transducers is denoted by DTWT ↓ .

Theorem 8.15 For every tree-walking pushdown transducer M two tree-walking transducers M 1 and M 2 can be constructed such that τ M = τ M1 • τ M2 . Moreover, M 1 is a deterministic top-down tree transducer, and if M is deterministic then so is M 2 .

Proof: Let M = (F, H, Q, q in , Γ, γ in , R) be a (local) p-twt and enumerate Γ as {γ 1 , . . . , γ n }. Without loss of generality we assume that during the computations of M , the bottom symbol of the pushdown is always equal to γ in (M can store the actual value of the bottom symbol in its state). We also assume without loss of generality that in case (c) of the definition of a p-ms-twt, β = γγ for some γ ∈ Γ, i.e., the symbol γ is pushed on top of the pushdown, without changing the previous top symbol γ (if γ has to be changed, one first uses a stay-rule). Finally, we assume that β = γ in case (b) of the definition of a p-ms-twt, i.e., the pushdown is unchanged (if it has to be changed, one first moves up and then moves down again).

The transducer M 1 preprocesses the input tree s in such a way that M 2 can stepwise simulate M on τ M1 (s), using the structure of τ M1 (s) to implement the pushdown of M . More precisely, for each node u ∈ N s and each pushdown π ∈ Γ m , where m is the depth of u, τ M1 (s) has a node [u, π] with label [f, γ], such that f is the label of u in s and γ is the top symbol of π. Thus, π will correspond to the second components of the labels of the ancestors of [u, π].

We define M 1 := (F, F × Γ, Γ, γ in , R 1 ). Note that M 1 uses the pushdown symbols of M as states. For every γ ∈ Γ and f ∈ F of arity k, the arity of [f, γ] is nk, and R 1 contains the rule γ, lab f (x 1 ) → ζ γ,f where ζ γ,f is:

[f, γ]( γ 1 , down 1 , . . . , γ n , down 1 , . . . , γ 1 , down k , . . . , γ n , down k ).
This rule changes each son u i of the current node u into n sons that will receive the additional labels γ 1 , . . . , γ n respectively. Note that after application of the rule, the j-th copy of u i is the m-th son of the output node with m = n(i-1)+j.

Finally we define M 2 := (F × Γ, H, Q, q in , R 2 ) as follows. Let q, ϕ, γ → ζ be a rule of M . It is simulated by the rule

q, ϕ ∧ f ∈F lab [f,γ] (x 1 ) → ζ in R 2 , where
ϕ is obtained from ϕ by changing every subformula lab f (x 1 ) into the formula γ∈Γ lab [f,γ] (x 1 ), and every subformula ∃y. son i (y, x 1 ) into the formula j∈[n] ∃y. son n(i-1)+j (y, x 1 ), and ζ is obtained from ζ by changing every triple q , up, ε into q , up , every triple q , stay, γ into q , stay , and every triple q , down i , γγ j into q , down n(i-1)+j .

It is clear that τ M (s) = τ M2 (τ M1 (s)) for every s ∈ T (F ). Thus, P-DTWT ⊆ DTWT ↓ • DTWT. It is straightforward to show that this is, in fact, an equality (see also Theorem 8.22).

From Theorems 8.13 and 8.15 we obtain the next result.

Theorem 8.16 The class DMSOT is included in the class DTWT ↓ •DTWT.

This theorem can be strengthened to a characterization of DMSOT in terms of tree-walking transducers, which can be viewed as a generalization of Theorem 1.16 to transductions. We omit the complicated proof (see [START_REF] Engelfriet | Macro tree translations of linear size increase are MSO definable[END_REF], as explained in Section 8.10). Recall from Section 8.1.1 that, trivially, every MS-transduction is of linear size increase. The class DTWT ↓ • DTWT contains transductions that are not of linear size increase, because even DTWT ↓ does, cf. Examples 8. 5 and 7.3(4). The characterization is that DMSOT and DTWT ↓ • DTWT have the same expressive power with respect to transductions of linear size increase. In other words, the monadic second-order transductions of terms are exactly the transductions of linear size increase that are computed by the composition of two tree-walking tree transducers, the first of which is a top-down tree transducer.

Theorem 8.17 A transduction τ of terms is in the class DMSOT if and only if [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] τ is in the class DTWT ↓ • DTWT and (2) τ is of linear size increase.

Of course, as a special case, this result also holds for term-to-word transductions, i.e., DMSOTW equals the class of transductions of linear size increase in DTWT ↓ • DTWTW.

It is also shown in [START_REF] Engelfriet | Macro tree translations of linear size increase are MSO definable[END_REF], by the same complicated proof, that it is decidable for τ ∈ DTWT ↓ • DTWT (given as a composition of two tree-walking transducers) whether or not τ is of linear size increase, i.e., whether or not it is in DMSOT; and if so, a definition scheme for τ can be constructed.

We now show that every monadic second-order transduction of graphs of bounded clique-width can be computed, on the level of terms over F VR , by a tree-walking pushdown transducer (or by the composition of two tree-walking transducers, the first of which is a top-down tree transducer). This can be viewed as a generalization of the Weak Recognizability Theorem to transductions. (1) This result also holds for parameter-invariant monadic second-order transduction of p-graphs (rather than parameterless ones). In that case the term transduction µ is not parameterless (and in general not even parameterinvariant), but can be replaced by a parameterless MS-transduction µ ⊆ µ such that Dom(µ ) = Dom(µ), see Footnote 25 in the proof of Theorem 7.50.

(2) The result also holds for CMS i,j -transductions (Section 7.3), for each i and j, additionally using Proposition 7.48 and Theorem 7.50. For instance, if τ : GP[D 1 ] → J S[D 2 ] is a parameterless CMS 1,2 -transduction, then the transducer M has input signature F VR C1 and output signature F HR C2 .

(3) Theorem 8.18 can also be used as an alternative way of evaluating a parameterless (and even parameter-invariant) monadic second-order graph transduction τ , using Theorem 8.14 instead of Theorem 7.29, see Remark 7.31(2). The input graph is parsed, the resulting term t 1 is translated into a term t 2 for the output graph using Theorem 8.14, and the value of t 2 is computed (cf. Proposition 2.45). The advantage of this method is that further transformations of the output graph need not parse that graph, because t 2 is still available.

Multi bottom-up tree-to-word transducers

In this section we present an alternative tree transducer model for DMSOTW. It can be viewed as an automaton on terms with infinitely many states and transition rules. Thus, it operates in a bottom-up fashion. Instead of computing one word translation of the input tree, it computes a finite number of translations simultaneously (which is indicated by 'multi'). At each node u of the input tree s, the finitely many translations of the subtree s/u form, together with the finite state of the transducer, the state of the infinite automaton. The translations at u are concatenations of letters of the output alphabet and the translations at the sons u 1 , . . . , u k of u. The words computed by the transducer are not viewed as unary trees.

Formally, a (complete and deterministic) multi bottom-up tree-to-word transducer (abbreviated mbott) is a tuple M = (F, B, Q, X , x out , δ, Acc) where F is a functional signature of input symbols, B is an alphabet of output symbols, Q is a finite set of states, Acc ⊆ Q is the set of accepting states, X is a finite set of variables, x out ∈ X is the output variable, and δ is a finite set of transition rules. A transition rule is of the form f [q 1 , . . . , q k ] → [q, α] where k ≥ 0, f ∈ F k , q 1 , . . . , q k , q ∈ Q and α is a mapping : X → ((X ×[k])∪B) * . For every q 1 , . . . , q k and every f ∈ F k there is exactly one pair [q, α] such that f [q 1 , . . . , q k ] → [q, α] is in δ (which means that M is complete and deterministic). We will denote [q, α] by δ f (q 1 , . . . , q k ).

It is clear that the transduction computed by a single-use mbott M is of linear size increase. By DMBOT lsi we will denote the class of transductions of linear size increase that are computed by mbotts, by DMBOT su the class of transductions computed by single-use mbotts, and by DMBOT lin the class of transductions : T (F ) → B * of the form {(s, w) | (#(s), w) ∈ τ M } where M is a linear mbott with input signature F ∪ {#} and # is a special unary function symbol not in F (which, intuitively, allows M to recognize "the end of the input"). For the one-way multi word transducers the corresponding classes are denoted 1DMWT lsi , 1DMWT su and 1DMWT lin .

Example 8.20 We construct a single-use mbott M = (F, B, Q, X , x out , δ, Acc) that computes the transduction σ : T (F ) → B * from Example 8.4, where B = {a 1 , a 2 , b} and

F = {f } ∪ B with f ∈ F 2 and a 1 , a 2 , b ∈ F 0 . For every s ∈ T (F ), if yd (s) = w 0 bw 1 bw 2 • • • bw n , with w i ∈ {a 1 , a 2 } * , then σ (s) := w 0 w 0 bw 1 w 1 bw 2 w 2 • • • bw n w n .
The mbott M has states b and a, both accepting; when M reaches node u of s, it is in state b if u has a descendant with label b, and in state a otherwise. It has six variables: l 1 , l 2 , m, r 1 , r 2 and x out . If yd (s/u) = w 0 bw 1 bw 2 • • • bw n , then the value of both l 1 and l 2 is w 0 , the value of m is bw 1 w 1 bw 2 w 2 • • • b, the value of both r 1 and r 2 is w n , and the value of x out is σ (s/u). The transition rules of M are:

b → [b, α b ], a i → [a, α ai ] for i = 1, 2, f [a, a] → [a, α a,a ], f [a, b] → [b, α a,b ], f [b, a] → [b, α b,a ] and f [b, b] → [b, α b,b ].
The set of assignments α b is l 1 := ε, l 2 := ε, m := b, r 1 := ε, r 2 := ε and x out := b, and the set of assignments α a1 is l 1 := a 1 , l 2 := a 1 , m := ε, r 1 := a 1 , r 2 := a 1 and x out := a 1 a 1 . The set of assignments α b,b is

l 1 := l 1 , 1 , l 2 := l 2 , 1 , m := m, 1 r 1 , 1 l 1 , 2 r 2 , 1 l 2 , 2 m, 2 , r 1 := r 1 , 2 , r 2 := r 2 , 2 and
x out := l 1 , 1 l 2 , 1 α b,b (m) r 1 , 2 r 2 , 2 .
The other sets of assignments are similar.

If the assignments to x out would not be there, M would be linear. Since x out is not used in the righthand sides of assignments, this implies that M is single-use. We note that this way of handling x out can be used to show that DMBOT lin ⊆ DMBOT su : a linear mbott realizing the same transduction as M has assignments x out := ε, except in the additional transition rules #

[a] → [a, α #,a ] and #[b] → [b, α #,b ]: in the first rule x out := l 1 , 1 l 2 , 1 , and in the second rule x out := l 1 , 1 l 2 , 1 m, 1 r 1 , 1 r 2 , 1 .
In the next theorem we present the characterization of MS tree-to-word transductions by single-use mbotts. By restricting to unary input signatures, the MS transductions of words are characterized by single-use one-way multi word transducers (as an alternative to Theorem 8.10).

Theorem 8.21 The classes DMSOTW and DMBOT su are equal, and so are the classes DMSOW and 1DMWT su .

Proof: We first show the inclusion DTWTW MS ⊆ DMBOT su , cf. Theorem 8.6. Let M = (F, H, Q, q in , R) be a nonjumping deterministic MS tree-walking treeto-word transducer (cf. Theorem 8.7), and let B := H -{ }. Let q be the maximal quantifier-height of the tests ϕ in the lefthand sides of the rules of M , and let A = F, Q A , δ A be the complete and deterministic finite F -semiautomaton A such that for every s ∈ T (F ) and u ∈ N s , run A ,s (u) = Th ↓ s (u) (cf. the proofs of Theorems 8.9 and 8.12). Note that Q A = P(L 1 ).

We will construct a single-use mbott M = (F, B, Q , X , x out , δ, Acc) that computes the same tree-to-word transduction as M . To ensure that M is single-use, it computes the linking relation γ(u) in its state. The set of states Q of M is defined to consist of all triples p, σ, γ such that p ∈ Q A , σ is a mapping : Q × P(L 1 ) → Q ∪ {@, ⊥} (called a transition table of M ) and γ ⊆ X × X . Intuitively, when M reaches node u ∈ N s , the transition table σ means the following: if σ(q, Th ↑ s (u)) = q ∈ Q then the transducer M , when started in state q at node u, has a computation on s/u that ends by moving up to the father of u in state q ; moreover, if σ(q, Th ↑ s (u)) = @ then the computation of M does not leave s/u and is successful, and if σ(q, Th ↑ s (u)) = ⊥ then the computation of M does not leave s/u and is unsuccessful (i.e., aborts or is infinite). The set Acc of accepting states is defined to consist of all triples p, σ, γ such that σ(q in , Th ↑ rt ) = @, where Th ↑ rt is the root theory. The set of variables X of M is defined to be Q × P(L 1 ). Intuitively, when M reaches node u ∈ N s , the value of the variable q, Th ↑ s (u) is the output word in B * that is produced by M during the above-mentioned computation (if σ(q, Th ↑ s (u)) = ⊥; otherwise the value is ε). The output variable x out is defined to be q in , Th ↑ rt . It remains to define the transition rules of M . Consider a lefthand side f [ p 1 , σ 1 , γ 1 , . . . , p k , σ k , γ k ] of a rule of M . Intuitively, M has reached (simultaneously) the sons u 1 , . . . , u k of a node u ∈ N s (for some input tree s), it knows p 1 := Th ↓ s (u 1 ), . . . , p k := Th ↓ s (u k ) and it knows the transition tables σ 1 , . . . , σ k of u 1 , . . . , u k . It additionally knows the linking relations γ 1 = γ(u 1 ), . . . , γ k = γ(u k ) and it knows the following: for P := Th ↑ s (u i ), if the variables q 1 , P and q 2 , P are linked at u i , i.e., ( q 1 , P , q 2 , P ) ∈ γ i , then the corresponding computations of M on s/u i both contain the same subcomputation corresponding to a variable q , P at a proper descendant of u. These facts can be formally proved by bottom-up induction on u; we omit the details. Note that M does not know Th ↑ s (u), but is prepared for every possible Th ↑ s (u). We will construct the righthand side [ p, σ, γ , α] of the rule. First of all, we define p to be δ A (p 1 , . . . , p k ), i.e., M computes Th ↓ s (u) in the first com-ponent of its state. Let us now define σ(q, P ) and α( q, P ) for given q ∈ Q and P ⊆ L 1 . We let Th := Z f (P, p 1 , . . . , p k ) and, for i ∈ [k], Th i := Z f,i (P, p 1 , . . . , p i-1 , p i+1 , . . . , p k ), cf. Section 8.1.3; thus, if P = Th ↑ s (u), then Th = Th s (u) and Th i = Th ↑ s (u i ). We now start a simulation of the transducer M , starting in state q. During this simulation, we keep track of the current state of M (initialized to q) and of the current prefix of α( q, P ) constructed sofar (initialized to the empty word ε). Moreover, we keep track of the current position of M : the father or the i-th son (initialized to the father). If M is at the father and the current state is q , then the applicable rules of M are of one of the three forms q , ϕ → q , ψ , or q , ϕ → b( q , ψ ), or q , ϕ → , such that ϕ is in Th (where ψ is stay, up, or down i ). If there is no such rule, or there are two or more, then we abort the simulation, i.e., we end the simulation and define σ(q, P ) to be ⊥ and α( q, P ) to be ε. Now assume that there is exactly one such rule. If it is of the third form, we end the simulation and define σ(q, P ) to be @ and α( q, P ) to be the current prefix. If the rule is of the first or second form, then we change the current state to q , and we add b to the current prefix in the second case. Moreover, if ψ is down i , we change the current position to the i-th son; if ψ is up, we end the simulation and define σ(q, P ) to be the current state and α( q, P ) to be the current prefix. Now let (our simulation of) M be at the i-th son in state q . If the current prefix has an occurrence of a variable q, Th i , i of the i-th son such that ( q, Th i , q , Th i ) ∈ γ i , then we abort the simulation, as above, because the computation of M on s/u contains a certain subcomputation on s/u i twice, and hence is infinite. Otherwise, let q := σ i (q , Th i ). If q = ⊥, then we abort the simulation, as above. If q = @, then the simulation ends and we define σ(q, P ) to be @ and α( q, P ) to be the current prefix to which q , Th i , i is added: the variable q , Th i at the i-th son. If q ∈ Q, then we change the current state to q and the current position to the father, and we add q , Th i , i to the current prefix. The only remaining problem is that the simulation can be infinite. Since M is deterministic, this can only happen when there is a repetition of the pair consisting of the current state and the current position. In that case we abort the simulation, as above.

Finally, we define γ in the same way as we defined γ(u): γ is the set of all (x, y) ∈ X × X such that α(x) has an occurrence x , i and α(y) has an occurrence y , i (with the same i ∈ [k]) and either x = y or (x , y ) ∈ γ i . It ensures that M computes γ(u) in the third component of its state.

This ends the construction of M . It should be clear from this construction, and the given intuitive comments, that M "simulates" M and thus computes the same transduction as M . To show that M is single-use, we first check Condition [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] in the definition of single-use. If, in the above construction of α( q, P ), the variable q , Th i , i of the i-th son would be added for the second time to the current prefix, then the pair consisting of the current state (q ) and the current position (the i-th son) repeats, and thus α( q, P ) = ε. Condition (2) holds by the construction of M .

For the proof of the inclusion DMBOT su ⊆ DTWTW MS , consider a singleuse mbott M = (F, B, Q, X , x out , δ, Acc). For s ∈ T (F ) and u ∈ N s , we de-fine the set of variables var (u) ⊆ X by top-down induction on u, as follows: var (root s ) is {x out } and if u has sons u 1 , . . . , u k , then var (u i ) consists of all y ∈ X such that y, i has an occurrence in α u (x) for some x ∈ var (u). Intuitively, var (u) is the set of variables of which the value at u is used to compute the output word. It follows from the definitions (with a proof by top-down induction on u) that (x, y) / ∈ γ(u) for distinct variables x, y ∈ var (u). Hence, again by the definitions, for each y ∈ var (u i ) there is a unique x ∈ var (u) such that y, i occurs in α u (x). We construct a nonjumping deterministic MS treewalking tree-to-word transducer M := (F, H, Q , q in , R) that uses its MS tests to compute α u and var (u) at each node u. It can do this because for each q ∈ Q an MS formula expressing that run M,s (u) = q can be constructed as in the proof of Theorem 5.15 (since M has a unique run on s). Then, for each set of assignments α, an MS formula can be constructed expressing that α u = α, and from that one can construct, for each Y ⊆ X , an MS formula expressing that var (u) = Y, in a way similar to the proof of Theorem 5.15 (but top-down instead of bottom-up).

The unary output signature H of M is B ∪ { }. In the construction of M we will assume, without loss of generality, that it has rules of the form q, ϕ → w( q , ψ ) for arbitrary w ∈ B * , meaning that w is written to the output; using auxiliary states such a rule can easily be changed into a finite number of official rules, each of them writing one letter to the output. The set of states

Q of M is X × ({↓} ∪ {↑ i | i ∈ ρ(F )}) with q in := x out , ↓ . Intuitively, if M
is at node u in state x, ↓ , then it starts writing the value of the variable x at u to the output; if it is in state x, ↑ i at node u, then it has just finished writing the value of x at the i-th son of u to the output. It is always the case that x ∈ var (u); in particular, if u is the root, then x = x out . We now describe the rules of M , in an informal way.

Let M be at node u in state x, ↓ and let α u (x) = w 0 x 1 , i 1 w 1 • • • x n , i n w n . If n > 0, then M outputs w 0 and moves down to the i 1 -th son in state x 1 , ↓ . If n = 0 and u is not the root, then M outputs w 0 and moves up in state x, ↑ i to its father (of which it is the i-th son). If n = 0 and u is the root, then M outputs w 0 and halts (using a rule x, ↓ , ϕ → ).

Let M be at node u in state y, ↑ i . Then M determines the unique x ∈ var (u) such that y, i occurs in α u (x). Let α u (x) = w 0 x 1 , i 1 w 1 • • • x n , i n w n and let y, i = x j , i j . If j < n, then M outputs w j and moves down to the i j+1 -th son in state x j+1 , ↓ . If j = n and u is not the root, then M outputs w n and moves up in state x, ↑ b to its father (of which it is the b-th son). If j = n and u is the root, then M outputs w n and halts.

This ends the description of M . It should be clear that it computes the same transduction as M .

The one-way multi word transducer walks from right to left on its input tape. However, we may as well assume that it walks from left to right, as usual, because if τ is a deterministic MS-transduction of words, then so is

{( v, w) | (v, w) ∈ τ }, cf. Example 8.4.
As observed in Section 8.1.1, DMSOT is contained in DMSOTW. Hence we obtain from Theorem 8.21 that DMSOT ⊂ DMBOT su . Thus, all deterministic MS-transductions of terms can be implemented on the single-use mbott, as an alternative to the tree-walking pushdown transducer (Theorem 8.13) or the composition of two tree-walking transducers (Theorem 8.17). In particular, by (the proof of) Theorem 8.18, every monadic second-order transduction of graphs of bounded clique-width can be computed, on the level of terms, by a single-use mbott. It should be noted that the values of the variables of an mbott that computes a tree transduction, need not be subtrees of the output tree (but they are subwords of the output term). A characterization of DMSOT as a subset of DMBOT su is not known. The multi bottom-up tree transducer was introduced in [START_REF] Fülöp | A bottom-up characterization of deterministic top-down tree transducers with regular look-ahead[END_REF]. It is the mbott with an output signature (rather than alphabet), such that for every assignment x := α(x) the righthand side α(x) is a term, where each variable x, i of a son has arity 0. The linear version of the multi bottom-up tree transducer is studied in [START_REF] Fülöp | Linear deterministic multi bottom-up tree transducers[END_REF] and [EngLM].

This section was inspired by [Alu Čer] and [AluDan]. In [Alu Čer] the linear one-way multi word transducer is introduced (called streaming string transducer ), as a model for the computation of deterministic MS-transductions of words, and it is shown that DMSOW = 1DMWT lin . In [AluDan] a variant of the linear mbott (called streaming tree transducer ) is presented, as a model for the computation of deterministic MS-transductions of terms. It is proved, for that variant, that DMSOTW = DMBOT lin . The proofs in both papers are based on the sharing of subwords of the values of linked variables. Since the inclusions 1DMWT su ⊆ DMSOW and DMBOT su ⊆ DMSOTW are relatively straightforward, these results are stronger than Theorem 8.21. Thus, Theorem 8.21 even holds with subscript 'lin' instead of 'su'. On the other hand, Theorem 8.21 also holds with subscript 'lsi' instead of 'su', as can be concluded from the main result of [START_REF] Fülöp | A bottom-up characterization of deterministic top-down tree transducers with regular look-ahead[END_REF], Theorems 7. 1 and 7.4 of [EngMan03a], and Theorem 7.7 of [START_REF] Engelfriet | Macro tree transducers, attribute grammars, and MSO definable tree translations[END_REF] (recall from the paragraph before Example 8.20 that 'lsi' stands for linear size increase).

Attribute grammars and macro tree transducers

The formalisms used in the litterature to prove the results on MS-transductions of terms in Sections 8.3, 8.4, and 8.5 (as opposed to those on MS-transductions of words), differ from the tree-walking transducer and the tree-walking pushdown transducer: instead, they are the attribute grammar and the macro tree transducer. Here we have proved those results using the tree-walking transducer as a formal model for two reasons: (1) to have uniform proofs for words and terms, and (2) to avoid the rather complicated definitions of attribute grammar and macro tree transducer. In this section we discuss these formalisms, without going into details.

The attribute grammar is a compiler construction tool (see, e.g., [*AhoLSU, *DeraJL, *WilMau]) introduced in [Knu]. It is essentially a deterministic treewalking transducer M of which the states are called attributes. The value of an attribute q at a node u of the input tree is the term computed by M when started at node u in state q, interpreted in some semantic domain (i.e., in an H-algebra, where H is the output signature). The transduction computed by the attribute grammar consists of all pairs (s, v) such that v is the value of the attribute q in at the root of the input tree s. The input tree is restricted to be a parse tree of a given context-free grammar, and the attributes are divided into synthesized and inherited attributes: states in which the transducer M , roughly speaking, walks down and up the tree, respectively. This division of states is not essential, but allows a specification of the rules of M that is local to the rules of the context-free grammar. The attributed tree transducer (see [*FülVog, Fül]) allows arbitrary trees over some input signature, and does not interpret the output term, but it still has synthesized and inherited attributes. The current version of the treewalking transducer, without the distinction between synthesized and inherited states, is introduced in [MilSV] as a model of XML transformations. In that paper, it is in addition equipped with a finite number of pebbles that it can drop on the nodes of the input tree (which is why it is called the pebble tree transducer ). We stress here that the attribute grammar, the attributed tree transducer, and the tree-walking transducer are essentially notational variations of the same formalism. The precise formal relationship between the latter two transducers is explained in Section 3.2 of [START_REF] Engelfriet | A comparison of pebble tree transducers with macro tree transducers[END_REF]. The deterministic treewalking transducer is slightly more powerful than the deterministic attributed tree transducer, because the latter is assumed to be "noncircular", which means that every attribute has a value at every node, i.e., that the transducer always halts when started at any node in any state.

The tree-walking tree-to-word transducer was introduced in [AhoUll71], as a model of syntax-directed translation. It can be viewed as an attribute grammar of which the values of the attributes are words in the algebra W left (A) for some alphabet A. The main result of [START_REF] Aho | Translations on a context-free grammar[END_REF] is in essence the equality DTWTW MS = DMBOT lsi (cf. the end of the previous section). The multi bottom-up tree-to-word transducer can be viewed as a two-phase process: phase 1 computes the state components of the run of the transducer on the input tree, and phase 2 is an attribute grammar with synthesized attributes only, of which the values are words in the algebra W(A) (also called a "generalized syntax-directed translation scheme").

To appreciate the relationship of Theorems 8.13, 8.16, and 8.17 to the litterature, it is necessary to discuss the macro tree transducer [*Eng80, CouFra, EngVog85], which was introduced as a formal model of denotational semantics. The macro tree transducer is obtained from the top-down tree transducer by letting its states (which can be viewed as recursive function procedures) have parameters of type 'output tree'; for a formal definition that is close to the treewalking transducer, see [START_REF] Engelfriet | A comparison of pebble tree transducers with macro tree transducers[END_REF]. Here we can explain the deterministic macro tree transducer in a different way, as a generalization of the multi bottomup tree-to-word transducer: we allow the variables of the mbott to have terms as values, instead of words. To give more details, and to avoid confusion, we second-order transduction of graphs of bounded clique-width can be computed, on the level of terms, by a deterministic macro tree transducer.

Nondeterminism

We will denote the classes of transductions computed by nondeterministic devices (in particular, by definition schemes with parameters) by dropping the D from the notation for the corresponding deterministic devices.

We first note that the nondeterminism of MS-definition schemes is different in nature from that of tree-walking transducers. This is so because (the semantics of) a definition scheme uses a global guess of the values assigned to the parameters, whereas a transducer makes a local guess whenever it visits an input node. It can make different guesses at different visits to the same node. Since, for a given input term s, each parameter has 2 |s| possible values, every transduction τ in MSOT has finite images, i.e., τ (s) is finite for every input s. This follows also from the fact that τ is of linear size increase, cf. Section 8.1.1.

Proposition 8.23 The classes MSOW and 2GSM are incomparable. Hence the classes MSOT and TWT MS su are incomparable. Proof: Obviously, two-way finite-state transducers can compute transductions that do not have finite images, for instance, the one that translates the word a (consisting of one symbol a) into the words a n for all n ∈ N . In fact, even oneway finite-state transducers can do that, see also Example 8.3. Hence, 2GSM is not included in MSOW.

To show that MSOW is not included in 2GSM, consider the transduction τ of words from A * := {a} * to B * := {b, c, #} * such that for every n ∈ N , we have τ (a n ) := {w#w | w ∈ {b, c} * , |w| = n}. It is clear that τ ∈ MSOT: the definition scheme is 2-copying and has one parameter, which indicates for each input position whether it will be relabelled with b or c. This transduction cannot be computed by a two-way finite-state transducer. Intuitively that is because the transducer would have to visit each input position twice, but, in general, cannot make the same choice (b or c) during the two visits. Formally, assume that τ is computed by such a transducer M with k states. Choose n such that 2 n > k(n + 1). Consider the behavior of M on input µ A (a n ), i.e., the unary term a(a(• • • a( ) • • • )). Clearly, M has k(n + 1) configurations on this input tree. Now consider the configuration of M when it has just produced the output node with label #. As there are 2 n possible output words w#w for a n , there exist two words w 1 and w 2 for which this configuration is the same. This means that, on input µ A (a n ), M can switch its computation of w 1 #w 1 halfway to the computation of w 2 #w 2 , thus producing output w 1 #w 2 , a contradiction.

Since the nondeterminism of an MS-transduction just consists of choosing the values of the parameters, it can easily be expressed as a (nondeterministic) relabelling of terms, cf. Proposition 7.24(2). Let REL be the class of all relabellings π -1 F,n where F is a functional signature and n ∈ N (cf. the end of Definition 7.20). In view of this proposition, the nondeterministic case is not as interesting as the deterministic case. The results for DMSOT can be turned into results for MSOT by composition with REL. In particular, MSOT = REL • DTWT MS su by Theorem 8.6, MSOT ⊂ REL•P-DTWT by Theorem 8.13, and MSOT is the class of transductions in REL•DTWT ↓ •DTWT of linear size increase by Theorem 8.17 (because π -1 F,n is size preserving, and π -1 F,n (t) = ∅ for every t ∈ T (F )). For MSOW a similar, but slightly more complicated version of Proposition 8.24 holds (see Theorem 19 of [START_REF] Engelfriet | MSO definable string transductions and two-way finite state transducers[END_REF]). Identifying (f, (0, . . . , 0)) ∈ F (n) with f ∈ F , we obtain that τ (ε) is a singleton for every word transduction τ in REL • DMSOW, because the constant symbol in the unary input tree can only be relabelled by ( , (0, . . . , 0)), and so REL • DMSOW is a proper subset of MSOW. Thus, for words, a class slightly larger than REL is needed.

VR-equational sets of terms and words

Having characterized the MS-transductions of terms, we can apply the Equationality Theorem (Theorem 7.36) to obtain an automata-theoretic characterization of the VR-equational sets of terms. A set of terms L ⊆ T (F ) is defined to be VR-equational if the set of (F, [ρ(F )])-labelled graphs {Syn(t) | t ∈ L} is VRequational. A similar definition holds for sets of words, viewed as unary trees. Since t = Syn(t) for every term in T (F ), we obtain from the Equationality Theorem that L is VR-equational if and only if it is the image of trees under an MS-transduction from graphs to terms. From Corollary 7.37 it then follows that the class of VR-equational sets of terms is preserved under MS-transductions of terms. In particular, the class of VR-equational sets of words is preserved under MS-transductions of words (see the discussion in the introduction of this chapter).

The HR-equational sets of terms (and words) can be defined in the same way. From the Equationality Theorem for the HR algebra (Theorem 7.51) one then obtains that L is HR-equational if and only if it is the image of trees under an MS 1,2 -transduction from graphs to terms. Since for terms and words the MS 1,2 -transductions and MS-transductions are the same (see Section 7.3), the HR-equational sets of terms or words are the same as the VR-equational ones (as also shown in [START_REF] Engelfriet | Hypergraph languages of bounded degree[END_REF], for Hyperedge Replacement and Vertex Replacement context-free graph grammars).

To characterize the VR-equational sets of terms and words, we first prove an additional characterization of the MS-transductions of terms. Let MSOT-REL functional signature F and an MS-transduction τ , such that L = τ (T (F )). By Theorem 8.26 there is a monadic second-order relabelling ρ and a transduction µ ∈ DTWT su such that L = µ(ρ(T (F ))). Since T (F ) is regular, ρ(T (F )) is regular by Proposition 7.22(3). This shows that L ∈ DTWT su (REGT). Now let L = µ(R) with µ ∈ DTWT su and R ∈ REGT, such that L ⊆ T (H) and R ⊆ T (F ). By Theorem 8.6, µ is in MSOT. Since R is MS-definable, we obtain from µ by the Restriction Theorem (Theorem 7.16) an MS-transduction τ such that L = τ (T (F )). Clearly, we may assume that F is a fat signature. By the Equationality Theorem and Theorem 7.27(2), L is VR-equational.

In a similar way, using Theorems 7.41(1) and 7.27 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF], it can be shown that a set of terms is linear VR-equational if and only if it is the image of a regular set of words under a deterministic single-use tree-walking transducer with a unary input signature (i.e., a word-to-tree transducer). 14As an example, the set of terms {σ(c n (t),

d n (t)) | t ∈ T (F ), n = |yd (t)|} is VR-equational, see Example 8.1. Similarly, an example of a linear VR- equational set of terms is {σ(c n (µ A (w))), d n (µ A (w))) | w ∈ A * , n = |w|}, where A is any alphabet.
Since deterministic tree-walking transducers with a unary output signature are single-use, Theorem 8.27 immediately gives the next result. We denote by REGW the class of regular word languages.

Theorem 8.28 Let L be a set of words. The language L is VR-equational if and only if it is in DTWTW(REGT), and it is linear VR-equational if and only if it is in 2DGSM(REGW). By Theorems 8.21 and 8.6 these classes are the same as DMBOT su (REGT) and 1DMWT su (REGW), respectively. 15 The equality of DTWTW(REGT) and DMBOT su (REGT) is essentially stated in Corollary 4.11(i) of [EngRS] and due to [START_REF] Aho | Translations on a context-free grammar[END_REF] (cf. Section 8.7). Other characterizations of DTWTW(REGT) can be found in Section 6 of [*Eng97]. A characterization of TWTW(REGT) as path languages of VR-equational sets of graphs is proved in Theorem 28 of [START_REF] Engelfriet | Regular description of contextfree graph languages[END_REF].

Examples of linear VR-equational languages are (1) In Theorems 8.27 and 8.28 one can replace REGT by the class of tree languages T (F ) where F is a functional signature (and similarly for REGW). Thus, a set of terms is VR-equational if and only if it is the image (range) of a transduction in DTWT su , and similarly for words. This is proved as follows. Let M = (F, H, Q, q in , R) be a single-use deterministic tree-walking transducer and let A = F, Q A , δ A , Acc A be a finite automaton. We will construct a singleuse deterministic tree-walking transducer M such that τ M (T (F × Q A )) = τ M (L(A )), where F × Q A is the functional signature such that each f, q ∈ F ×Q A has the same arity as f . First we define the finite automaton A := F × Q A , Q A , δ , Acc A where δ consists of the rules f, q [q 1 , . . . , q k ] → q such that f [q 1 , . . . , q k ] → A q. Clearly, the terms in L(A ) represent the accepting runs of A on the terms in L(A ). The transducer M first checks that the input tree s belongs to L(A ), using a depth-first walk verifying that each node with label f, q has sons with labels f 1 , q 1 , . . . , f k , q k such that f [q 1 , . . . , q k ] → A q. Then it stepwise simulates M on the tree obtained from s by changing every label f, q into f . It can even be shown rather easily that REGT can be replaced by the singleton class {T (F )}, where F is any fat signature (cf. Section 7.1.7). We omit the details.

{a n b n c n d n | n ≥ 0}, {w w | w ∈ A * } and {w k | w ∈ A * } for each k ≥ 2,
(2) The class of context-free languages is properly contained in the class of VR-equational languages (see Example 4.3(12) and see the discussion in the introduction of this chapter). To show the containment, it is straightforward to transform a context-free grammar into a Hyperedge Replacement grammar. Alternatively, Theorem 8.28 can be used as follows. Let G be a context-free grammar. It is well known, and easy to see, that the set P (G) of parse trees of G is a regular language. Since L(G) = yd (P (G)), where L(G) is the language generated by G from the initial nonterminal, and since the yield mapping yd is in DTWTW (see Example 8.1), L(G) is in DTWTW(REGT) and hence VRequational. Note that for each k ≥ 2 the language {w k | w ∈ L(G)} is also VR-equational: a tree-walking transducer can output the yield of the tree k times. The language {a n b n c n d n | n ≥ 0} of Example 8.2 is a noncontext-free (linear) VR-equational language.

(3) By Theorem 5.80, every VR-equational set L of terms (or words) has a decidable MS-satisfiability problem. As discussed in Section 7.5 (after Question 7.59), this is equivalent to the fact that it is decidable for a finite automaton A whether L ∩ L(A ) = ∅. The latter problem is, in fact, decidable for every language L in TWT(REGT) in exponential time (see [START_REF] Engelfriet | The time complexity of typechecking tree-walking tree transducers[END_REF]).

The use of the Equationality Theorem in the proof of Theorems 8.27 and 8.28 is not essential. The term generating power of Hyperedge Replacement graph grammars was first investigated in [START_REF] Engelfriet | Context-free hypergraph grammars have the same term-generating power as attribute grammars[END_REF], where it is shown by a direct proof, not involving MS logic, that DTWT(REGT) is the class of sets of terms that can be generated by HR grammars, if one allows the graph grammars to generate directed graphs without circuits (i.e., trees with shared subtrees), cf. the discussion at the end of Section 8.3. The construction transforms HR grammars and attribute grammars into each other (see Section 8.7). From this construction Theorem 8.27 easily follows. The present proof is given, also in terms of attribute grammars, in [START_REF] Bloem | A comparison of tree transductions defined by monadic second order logic and by attribute grammars[END_REF] (see Corollary 19 of [START_REF] Bloem | A comparison of tree transductions defined by monadic second order logic and by attribute grammars[END_REF]). The characterization in Theorem 8.28 of the VR-equational sets of words is shown in [START_REF] Engelfriet | The string generating power of context-free hypergraph grammars[END_REF] with a direct proof, not involving logic. The construction transforms HR grammars and tree-walking tree-to-word transducers into each other. The word generating power of HR grammars was first investigated in [HabKre] and Chapter V of [*Hab], see also Section 2.5.2 of [*DreKH].

The advantage of tree-walking transducers over VR equation systems is that they can be "programmed". To show that a given language is VR-equational, it is usually easier to describe the working of a tree-walking transducer than to construct a VR equation system.

Words

The two-way finite-state transducer is a particular type of two-tape Turing machine. It was first studied in [START_REF] Aho | A characterization of two-way deterministic classes of languages[END_REF]. Lemma 8.8 is a general technique for two-way machines, proved in Lemma 3 of [HopUll] (see also page 212 of [AhoHU]). Using this lemma, it is shown in [ChyJák] that the class 2DGSM is closed under composition.

The incomparability of MSOW and 2GSM (Proposition 8.23) is Corollary 16 of [START_REF] Engelfriet | MSO definable string transductions and two-way finite state transducers[END_REF]. It is shown in [START_REF] Engelfriet | Finitary compositions of two-way finite-state transductions[END_REF] that a word transduction τ is in the class MSOW if and only if [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] τ is in the class 2GSM • 2DGSM and (2) τ has finite images. 16 Moreover, it is decidable for τ ∈ 2GSM • 2DGSM (given as a composition of two two-way finite-state transducers) whether or not τ has finite images, i.e., whether or not it is in MSOW; and if so, a definition scheme for τ can be constructed. And finally, these results even hold for transductions τ that are compositions of arbitrarily many two-way finite-state transducers. It should also be noted that, in the above statements, 'has finite images' can be replaced by 'is of linear size increase'.

A Hennie machine is a two-way finite-state transducer that can also write on its input tape, just as a Turing machine. However, it may only visit each cell of its input tape a bounded number of times. It is shown in [START_REF] Engelfriet | MSO definable string transductions and two-way finite state transducers[END_REF] that MSOW (DMSOW) is the class of word transductions computed by nondeterministic (deterministic) Hennie machines.

Terms

As discussed in Section 8.7, the tree-walking transducer is essentially the attribute grammar of [Knu]. The single-use restriction was introduced (for attribute grammars) in [Gan, Gie], where it is shown that single-use attributed tree transducers are closed under composition.

The basic characterization DMSOT = DTWT MS su of Theorem 8.6 is one of the main results of [START_REF] Bloem | A comparison of tree transductions defined by monadic second order logic and by attribute grammars[END_REF]; more precisely, it is proved there, in terms of attribute grammars, that DMSOT = DMSOT-REL • DTWT su , see Theorem 8.26. How to get rid of jumps (Theorem 8.7) is shown in Theorems 8 and 9 of [START_REF] Bloem | Monadic second order logic and node relations on graphs and trees[END_REF]. The class DMSOT-REL is characterized in terms of finitevalued attribute grammars in Theorem 3.7 of [NevBus] and in Theorem 10 of [START_REF] Bloem | A comparison of tree transductions defined by monadic second order logic and by attribute grammars[END_REF] (independently), and in terms of compositions of bottom-up and top-down finite-state relabellings in Theorem 4.4 of [START_REF] Engelfriet | Macro tree transducers, attribute grammars, and MSO definable tree translations[END_REF] (cf. the discussion following Lemma 4.5 of [START_REF] Engelfriet | Macro tree transducers, attribute grammars, and MSO definable tree translations[END_REF]). This implies Theorem 8.14 (as stated in Corollary 18 of [START_REF] Bloem | A comparison of tree transductions defined by monadic second order logic and by attribute grammars[END_REF]).

The tree-walking pushdown tree-to-word transducer (also called checking tree-pushdown transducer) was introduced in [EngRS] and the tree-walking pushdown tree transducer (also called indexed tree transducer or RT(P(TR))transducer) in [START_REF] Engelfriet | Pushdown machines for the macro tree transducer[END_REF]. The pushdown of such a transducer can be viewed as a pushdown of (coloured) pebbles: the pebbles are placed on the ancestors of the current node. In [EngHS] the tree-walking pushdown tree transducer is generalized to a transducer called i-ptt, that can place the pebbles anywhere on the input tree; it also generalizes the pebble tree transducer of [MilSV]. The decomposition result of Theorem 8.15 is a special case of Lemma 3 of [EngHS] (where the special case allows the first transducer to be deterministic).

The inclusions of Theorems 8.13 and 8.16 are proved in [START_REF] Engelfriet | Macro tree transducers, attribute grammars, and MSO definable tree translations[END_REF] in the form DMSOT ⊆ DMT, cf. Theorem 8.22. The characterization in Theorem 8.17 of DMSOT as the class of transductions in DTWT ↓ • DTWT of linear size increase, is the main result of [START_REF] Engelfriet | Macro tree translations of linear size increase are MSO definable[END_REF], where it is proved for DMT rather than for DTWT ↓ • DTWT. The proof is for total functions only, but it should be clear from the proof of Theorem 6.18 of [START_REF] Engelfriet | Macro tree transducers[END_REF] (cf. the proof of Theorem 8.22) that it then also holds for partial functions: note that if a partial function τ is in DMSOT then it can be written as τ = τ 1 • τ 2 , where τ 1 is the identity on some regular language, and τ 2 ∈ DMSOT is a total function (just view the precondition χ of the definition scheme for τ as a separate transduction τ 1 , and take the definition scheme for τ 2 to be the one of τ with χ := True). It is announced in [Man] that the if-direction of Theorem 8.17 even holds for transductions τ that are compositions of arbitrarily many deterministic treewalking transducers (or macro tree transducers). In Theorem 7.1 of [START_REF] Engelfriet | Macro tree transducers, attribute grammars, and MSO definable tree translations[END_REF] DMSOT is characterized by syntactically restricted classes of macro tree transducers.

No results for MSOT and TWT are known that are similar to those for MSOW and 2GSM. Since it is easy to see that REL ⊆ TWT ↓ (the top-down tree transducer visits each node exactly once and guesses its new label), it follows from Proposition 8.24 and Theorem 8.16 that MSOT is included in TWT ↓ • DTWT ↓ • DTWT. But it is unknown whether MSOT equals the set of transductions of linear size increase in this class.

Characterizations of the class of VR-equational sets of terms that are closely related to Theorem 8.27, are given in Theorem 8.1 of [START_REF] Drewes | A characterization of the sets of hypertrees generated by hyperedge-replacement graph grammars[END_REF] (in terms of top-down tree transducers and hypergraph substitution) and in Theorem 5 of [START_REF] Engelfriet | Tree languages generated by contextfree graph grammars[END_REF] (in terms of macro tree transducers; see also Corollary 7.3 of [START_REF] Engelfriet | Macro tree transducers, attribute grammars, and MSO definable tree translations[END_REF]). In [START_REF] Engelfriet | Tree languages generated by contextfree graph grammars[END_REF] several natural types of term generating HR grammars are investigated.

We finally note that the equivalence problem is decidable for transductions in DMSOT, as proved in [START_REF] Engelfriet | The equivalence problem for deterministic MSO tree transducers is decidable[END_REF]. This result extends to MS-transductions from graphs to terms on VR-equational sets of graphs, but there is no hope to extend it to all graphs. It is shown in [AluDan] that the problem can be decided in exponential space, for given linear mbotts (in the formalism of [AluDan]). For words, i.e., for deterministic two-way finite-state transducers, the decidability of the equivalence problem was first proved in [Gur]. It is open whether it is decidable for deterministic tree-walking tree transducers (and hence for deterministic macro tree transducers, cf. [*Eng80]).

Chapter 9

Relational structures

In the previous chapters, we have used relational structures to represent labelled graphs, possibly with sources or ports. Such structures are binary, i.e., their relations have arity at most 2. However, the Recognizability Theorem has been stated and proved for the algebra STR of all relational structures, whose operations are the disjoint union and the (unary) quantifier-free definable operations. Monadic second-order transductions have been defined, and the Backwards Translation Theorem has been proved also for general relational structures.

In this chapter, we will show how the previous results concerning graphs, in particular the logical characterizations of sets of graphs of bounded tree-width and clique-width, and several algorithmic and decidability results, extend more or less easily to relational structures. Certain extensions raise challenging open problems.

In Section 9.2, we will consider relational structures of bounded tree-width represented by their incidence graphs. This representation will offer the possibility of writing monadic second-order formulas (to be called MS 2 formulas) where quantified variables can denote sets of tuples of the relations. The results about graphs of bounded tree-width and MS 2 formulas will generalize easily.

In Section 9.3, we will define a complexity measure on relational structures that extends clique-width and most of its properties. However, as said above, several important questions will remain open.

In Section 9.4, we will establish the Sparseness Theorem. It is a difficult theorem about the elimination of quantifications over sets of tuples, hence about cases where MS 2 formulas are no more expressive than MS formulas. Its particular case concerning graphs, that has been announced in Theorem 5.22 and Section 7.3 (see also Theorem 4.51), will be the basis of the induction establishing the general result. Its proof already uses relational structures.

Before developing technical notions, we will detail in Section 9.1 two uses of ternary relational structures in the theory of ordered sets (already presented in Section 1.9.2). 621 9.1 Two types of ternary relational structures related to ordered sets

In this section, we discuss the notions of betweenness and of cyclic ordering that are formalized as ternary relations.

Betweenness

With a finite linear order D, ≤ such that |D| ≥ 3, we associate the following ternary relation, called its betweenness relation1 :

B(x, y, z) :⇐⇒ (x < y < z) ∨ (z < y < x)
(where u < v means "u ≤ v and u = v"). We denote it by B(≤). This relation satisfies the following properties, for all x, y, z, t ∈ D:

(B1) B(x, y, z) ⇒ x = y ∧ x = z ∧ y = z (B2) B(x, y, z) ⇒ B(z, y, x) (B3) B(x, y, z) ⇒ ¬B(y, z, x) (B4) B(x, y, z) ∧ B(y, z, t) ⇒ B(x, y, t) ∧ B(x, z, t) (B5) B(x, y, z) ∧ B(y, t, z) ⇒ B(x, y, t) ∧ B(x, t, z) (B6) x = y ∧ x = z ∧ y = z ⇒ B(x, y, z) ∨ B(y, z, x) ∨ B(z, x, y).
By Property (B3), the three possibilities of Property (B6) are mutually exclusive. We will prove that these properties characterize betweenness relations. Third, we cannot have B(u, a, v). Otherwise, since we have B(a, u, b), hence B(b, u, a), we have B(b, a, v) by (B4), which contradicts our first observations. By using a, we define a binary relation ≤ as follows:

x ≤ y if and only if x = y or x = a or B(a, x, y).

This relation is reflexive. Properties (B1), (B2), (B3) and (B5) imply that it is antisymmetric and transitive. Hence it is a partial order. We now prove that it is linear. Consider x and y = x. If x = a or y = a, we have x ≤ y or y ≤ x respectively. Otherwise, by (B6) we have B(a, x, y) ∨ B(x, y, a) ∨ B(y, a, x). The last case is excluded by the third observation and the others give respectively x ≤ y and, with (B2), y ≤ x.

It remains to prove that B = B(≤). Let x, y and z be such that x < y < z. If x = a, we have B(x, y, z) (by the definition of y ≤ z). Otherwise, we cannot have y or z equal to a. Hence, we must have B(a, x, y) and B(a, y, z). Then (B5) gives B(x, y, z). Finally, let us assume B(x, y, z). Since ≤ is a linear order, we have one of the six cases: x < y < z, z < y < x, y < x < z, etc. The first two give B(≤)(x, y, z) as desired. The last four give B(y, x, z) and B(x, z, y) which are not possible by (B2) and (B3). This completes the proof.

If in this proof, we use b instead of a, then we obtain the opposite linear order, ≤ -1 .

A subset X of D 3 is consistent for betweenness if X ⊆ B for some betweenness relation B on D. The problem Betweenness that consists in deciding whether a given set X ⊆ D 3 is consistent (for betweenness) is NP-complete ([*GarJoh], Problem MS1; but no proof or reference to a published proof is given). If X is consistent, we define X as the intersection of all betweenness relations that contain X. We say that X is a partial betweenness relation on

D if X = X. It is clear that if Y = X, then Y = X.
Hence, X is a partial betweenness relation, and even the smallest partial betweenness relation that contains X. We will say that it is generated by X. The set X satisfies properties (B1)-(B5), but, as we will see in Remark 9.5(2), a set that satisfies these five properties is not necessarily a partial betweenness relation.

If X ⊆ D 3 , we denote by X + the least set Y ⊆ D 3 that contains X and satisfies Conditions (B2), (B4) and (B5). We have X + ⊆ X, and the inclusion may be strict (see Remark 9.5(1) for an example). This fact shows a difference with the case of partial orders that we now discuss. If Z ⊆ D2 is contained in some linear order (we will also say extended by instead of 'contained in'), we define Z as the intersection of all linear orders containing Z. We claim that Z is a partial order if and only if Z = Z. Note that this equivalence is not a definition because partial orders are defined independently, as reflexive, antisymmetric and transitive binary relations. It is clear that Z has these three properties because it is an intersection of relations satisfying them. Hence Z = Z implies that Z is a partial order. For the other direction, we let Z be a partial order and (x, y) belong to D 2 -Z. We must prove that (x, y) / ∈ Z, hence that there exists a linear order ≤ that extends Z in such a way that y < x. If (y, x) ∈ Z, then one can take for ≤ any linear order that extends Z. If (y, x) / ∈ Z, then the binary relation E on D consisting of (y, x) and the pairs (u, v) ∈ Z such that u = v is acyclic 2 (easy to check). Hence, its reflexive and transitive closure is a partial order, hence is extended by a linear order. Any such linear order has the desired property. This completes the proof.

Hence our definition of partial betweenness is a natural generalization of that of a partial order. However, it does not seem to be first-order definable, as is the notion of a partial order. The following questions are open: Questions 9.2

(1) Is the class of ternary relations that are consistent for betweenness MSdefinable?

(2) Is the class of partial betweenness relations MS-definable?

However, these classes are definable by monadic second-order sentences that allow quantifications over triples and sets of triples of the given ternary relation. Some definitions are needed.

We let T be a ternary relation symbol. We define the incidence graph of a {T }-structure D, X as the binary relational structure Inc( D, X )

:= D ∪ X, in 1 , in 2 , in 3 where in i (t, d) holds if and only if d ∈ D, t ∈ X and d is the i-th element of t. A class C of {T }-structures is MS 2 -definable if the membership of S in C is equivalent to Inc(S) |= ϕ for some sentence ϕ in MS({in 1 , in 2 , in 3 }, ∅).
Proposition 9.3 The class of ternary relations that are consistent for betweenness and the class of partial betweenness relations are MS 2 -definable.

Proof: We first prove the MS 2 -expressibility of consistency (implicitly, in the sequel, consistency for betweenness). Let X ⊆ D 3 . For Y ⊆ X, we define Z(Y ) ⊆ D 2 as follows:

Z(Y ) := {(x, y) | (x, y, z) or (z, x, y) belongs to Y for some z ∈ D} ∪ {(x, y) | (y, x, z) or (z, y, x) belongs to X -Y for some z ∈ D}. Claim 9.3.1 A set X ⊆ D 3 is consistent if and only if the relation Z(Y ) is acyclic for some subset Y of X. Proof: Let X ⊆ B(≤). We define Y := {(x, y, z) ∈ X | x < y < z}. Hence, if (x, y, z) ∈ X -Y , then z < y < x. Clearly, Z(Y ) is included in < and hence, is acyclic. Conversely, if Y ⊆ X and Z(Y ) is acyclic, then Z(Y )
is extended by some linear order ≤, and hence X ⊆ B(≤), because if (x, y, z) ∈ Y , then x < y < z, and if (x, y, z) ∈ X -Y , then z < y < x.

Since the transitive closure of an MS-definable relation is MS-definable (Section 5.2.2), the condition of this claim is expressible by an MS sentence over the structure Inc( D, X ). Hence consistency is an MS 2 -expressible property.

The following claim entails that partial betweenness is MS 2 -expressible. For every triple t = (x, y, z) ∈ D 3 , we define sh(t) (read "shift") as (y, z, x) and sh * (t) as {t, sh(t), sh(sh(t))}. Property (B3) says that if t ∈ B, then sh(t) / ∈ B. Property (B6) says that if t is a triple of pairwise distinct elements of D, then B ∩ sh * (t) = ∅.

Claim 9.3.2 Let X ⊆ D 3 be consistent. We have X = X if and only if X satisfies (B1)-(B5) and the following: (B7) For every triple t of pairwise distinct elements of D such that X ∩ sh * (t) = ∅, the set X ∪ {t } is consistent for at least two elements t of sh * (t).

Proof: As observed above, X satisfies (B1)-(B5). Let B be a betweenness relation such that X ⊆ B.

Assume that X = X and let t be a triple of pairwise distinct elements such that X ∩ sh * (t) = ∅. Since B satisfies (B6) and (B3), we have B ∩ sh * (t) = {t } for some t , hence X ∪ {t } is consistent. There exists a betweenness relation B ⊇ X such that B ∩ sh * (t) = {t } and t = t , because otherwise t ∈ X, which would contradict the hypotheses that X = X and X ∩ sh * (t) = ∅. Hence, X ∪ {t } is consistent and (B7) holds.

Let us conversely assume that X satisfies (B1)-( B5) and (B7). Assume that some triple t belongs to X -X. We have X ∩ sh * (t) = ∅ because if sh(t) ∈ X, then t and sh(t) belong to X, which contradicts (B3) that holds for X; and if sh 2 (t) belongs to X, then sh 2 (t) and sh(sh 2 (t)) = t belong to X, which again contradicts (B3). By (B7), the set X ∪ {t } is consistent for some triple t ∈ {sh(t), sh 2 (t)}. Hence X ∪ {t } ⊆ B where B is a betweenness relation. The relation B cannot contain t (because it contains also sh(t) or sh 2 (t)), which contradicts the assumption that t ∈ X. Hence X = X.

This ends the proof of the proposition. (d,c), (f, e)}. Its reflexive and transitive closure is a partial order that is not linear and has several linear extensions, in particular:

f < 1 a < 1 e < 1 d < 1 b < 1 c and f < 2 e < 2 d < 2 a < 2 b < 2 c. We have X ⊆ B(≤) for each of them.
An easy computation yields X + = X ∪ X -1 ∪ {(c, d, f ), (f, d, c), (c, e, f ), (f, e, c)} (where X -1 is the set of triples (x, y, z) such that (z, y, x) ∈ X). We will show that this set is equal to X, the partial betweenness relation generated by X. We have X + ⊆ X. It is not hard to see that the linear orders ≤ for which X ⊆ B(≤) are those such that a < b < c or c < b < a, and c < d < e < f or f < e < d < c. From this observation, we can check that X = X + , and thus, X + = X + . This set satisfies (B1)-(B5), but not (B6). Consider for example t = (a, b, d) not in X + . We have sh * (t) = {(a, b, d), (b, d, a), (d, a, b)} and X + ∩sh * (t) = ∅. For each triple sh i (t), with i = 0, 1, 2, the set X + ∪{sh i (t)} is consistent as it is included in B(≤ i ).

(2) Here is another example. We let D := {a, b, c, d} and X := {(a, b, c), (a, b, d)}. The only linear orders with betweenness relations containing X are a < b < c < d and a < b < d < c and the opposite orders. Again we have X + = X, equal to X ∪ X -1 . The triple t = (b, c, d) is not in X and the triple (d, b, c) = sh 2 (t) is not consistent with X. Hence sh * (t) contains only two triples that are consistent with X, namely t and sh(t) = (c, d, b).

Remarks 9.5

(1) Let X ⊆ D3 satisfy Condition (B1). The set X + satisfies (B2), (B4) and (B5) (by definition) and can be computed in polynomial time in |D|. If X + does not satisfy (B3), then X is not consistent. If X + satisfies (B3), we cannot conclude that X is consistent. Otherwise, we would have a polynomial algorithm for the problem Betweenness that is NP-complete.

(2) Here is an example such that X + = X. We let D := {a, b, c, d, e} and

X := {(a, c, b), (a, d, b), (c, e, d)}. Then X + = X ∪ X -1 . It is not hard to see that X contains (a, e, b) which is not in X + . Since X is consistent, X + satisfies (B1)-(B5).
It does not satisfy (B7): the sets X + ∪ {(e, b, a)} and X + ∪ {(b, a, e)} are not consistent.

We now define a notion of width (a variant of the tree-width of Definition 9.12 below) that will yield a fixed-parameter tractable algorithm for the problem Betweenness. For X ⊆ D 3 , we define twd Inc (X) as the tree-width of the labelled graph 3 Inc( D, X ), and the size of D, X as |D| + |X|.

Corollary 9.6 The problem Betweenness is fixed-parameter linear with respect to twd Inc .

Proof: This follows from Theorem 6.4(1) and Proposition 9.3.

We will leave the notion of betweenness with an open question.

Question 9.7 Can one compute in polynomial time, for each fixed k, the set X for any given set X ⊆ D 3 , assumed to be consistent and such that twd Inc (X) ≤ k? Is this even possible by a fixed-parameter tractable algorithm with twd Inc as parameter?

A subset X of D 3 is consistent for cyclic ordering if X ⊆ C for some cyclic ordering C on D. It is proved in [GalMeg] that the problem Cyclic Ordering that consists in deciding if a set X ⊆ D 3 is consistent for cyclic ordering is NPcomplete.

As for betweenness, if X ⊆ D 3 is consistent for cyclic ordering, we define X as the intersection of all cyclic orderings C on D such that X ⊆ C. A partial cyclic ordering on a set D is a subset X of D 3 such that X = X. If X is consistent (implicitly, in the sequel, for cyclic ordering), then X is the smallest partial cyclic ordering containing X, and we say that it is generated by X. We have the same open questions as for betweenness (cf. Questions 9.2), and the same positive results (cf. Proposition 9.3 and Corollary 9.6), based on the following proposition.

Proposition 9.9 The class of ternary relations that are consistent for cyclic ordering and the class of partial cyclic orderings are MS 2 -definable.

Proof: We first consider consistency. We observe that if X is a subset of C(≤), then we can partition it as X 0 ∪ X 1 ∪ X 2 where:

X 0 := {(x, y, z) ∈ X | x < y < z}, X 1 := {(x, y, z) ∈ X | y < z < x}, X 2 := {(x, y, z) ∈ X | z < x < y}.
Claim 9.9.1 The set X is consistent if and only if it can be partitioned into three sets X 0 , X 1 , X 2 such that the binary relation Z(X 0 , X 1 , X 2 ) associated with them by: (u, v) ∈ Z(X 0 , X 1 , X 2 ) if and only if for some w:

(u, v, w) or (w, u, v) belongs to X 0 , or (v, w, u) or (w, u, v) belongs to X 1 , or (u, v, w) or (v, w, u) belongs to X 2 , is acyclic. Proof: Let X be consistent, with X ⊆ C(≤) for some linear order ≤. The binary relation Z(X 0 , X 1 , X 2 ) associated as above with X 0 , X 1 and X 2 is included in ≤, hence, is acyclic. Conversely, if for some partition X 0 , X 1 , X 2 of X, the relation Z(X 0 , X 1 , X 2 ) is acyclic, then there is a linear order ≤ extending it, and we have X ⊆ C(≤).

The condition of this claim is MS 2 -expressible. The second assertion is proved as the corresponding one for betweenness by means of the following observation: for X ⊆ D 3 that is consistent, we have X = X if and only if X satisfies Conditions (C1)-(C4) and for every triple (x, y, z) of pairwise distinct elements, if (x, y, z) and (x, z, y) are not in X, then X ∪ {(x, y, z)} and X ∪ {(x, z, y)} are consistent.

An embedding of a loop-free graph on a surface yields, for each vertex x, a cyclic ordering C x of the set E x of edges incident with this vertex. Conversely, such an embedding can be specified, up to homeomorphism, by a family of cyclic orderings C x of E x , for each vertex x. (See [*MohaTho] for the theory of graphs on surfaces). If, instead of C x , one is given a subset of E 3

x for each vertex x, then one gets a partial specification (possibly unrealizable) of an embedding of the given graph on some surface. The problem of consistency of cyclic orderings is thus a subproblem of that of checking the realizability of a partial specification of an embedding. This topic is studied in [Dus].

The following notion of cyclic separation is defined from cyclic ordering like betweenness is defined from linear order. Let D be a set of at least 4 elements. A cyclic separation is a 4-ary relation E on D such that, for some cyclic ordering C on D we have:

E(u, v, w, x) ⇐⇒ (C(u, v, w) ∧ C(w, x, u)) ∨ (C(w, v, u) ∧ C(u, x, w)).
This definition means that for any layout of the elements of D on a circle, if C is the associated cyclic ordering, then the chord linking u and w crosses the chord linking v and x. We leave to the interested reader the task of axiomatizing cyclic separations and of establishing results analogous to Propositions 9.3 and 9.9.

Relational structures of bounded tree-width

We show how the results about graphs of bounded tree-width and CMS 2 logic extend (easily) to relational structures. We will first define CMS 2 formulas for expressing properties of relational structures. By representing a graph by its incidence graph (the corresponding relational structure is denoted by G for a graph G), we can express monadic second-order graph properties by formulas using quantifications on sets of edges. The notation CMS 2 refers to such formulas, to be interpreted in G . For expressing properties of relational structures, we can act similarly and replace any relational structure by a richer one where the tuples of its relations are elements of the domain. This structure, actually an edge-labelled graph, allows to use quantified variables denoting sets of tuples of the relations of the original structure. As for graphs, we get in this way a stronger expressive power than with "plain" monadic second-order formulas.

We recall from Definition 5.1 that if R is a relational signature, we denote by R 0 the set of its constant symbols, by R i for i > 0 the set of its symbols of arity i, and by R + the set R -R 0 . The maximal arity of a symbol in R is ρ(R). A relational signature is binary if ρ(R) ≤ 2. Note that each relation in i Inc(S) is functional. Since R Inc is a binary signature, the R Inc -structures can be identified with simple, directed, bipartite (R, In R )labelled graphs (cf. Example 5.2(2)). Thus, we do not distinguish the graph G := Inc(S) from the structure G = Inc(S).

It is clear that if S and S are isomorphic concrete structures, then so are Inc(S) and Inc(S ). Hence, the operation Inc is well defined for abstract structures too. If C is a set of (concrete or abstract) structures, then Inc(C) denotes the set of their (concrete or abstract) incidence graphs.

The purpose of introducing T S in the domain of the structure Inc(S) is to allow variables to denote sets of tuples of the relations of S. However, this is not necessary for unary relations. The pairs (R, d 1 ) in T S can be deleted, and we obtain in this way a smaller set, denoted by T S , and the same expressive power for monadic second-order formulas. Hence, we define for S as above: which is also an R Inc -structure.

For a fixed relational signature R, the injective mapping Inc(S) → Inc (S) is an FO-transduction, and its inverse is a (|R 1 | + 1)-copying FO-transduction. Thus, the two representations Inc(S) and Inc (S) are strongly equivalent, cf. Definition 7.9. All our results will hold for Inc as well as for Inc. The constructions with Inc will be simpler because unary relations will not have to be considered separately.

(3) The if direction is clear from (2). (4) Easy proofs.

Tree-decompositions and tree-width of relational structures

We will extend to relational structures the notion of a tree-decomposition defined for graphs in Section 2.4.1. We will also extend to them the main decidability and model-checking results obtained for graphs of bounded tree-width and CMS 2 formulas. Definition 9.12 (Tree-decompositions of relational structures) A tree-decomposition of a concrete R-structure S is a pair (T, f ) such that T is a concrete rooted tree and f is a mapping : N T → P(D S ) such that: We call Condition (iii) the connectivity condition. The width of (T, f ) is wd (T, f ) := max{|f (u)| | u ∈ N T } -1 and the tree-width of S, denoted by twd (S), is the smallest width of a tree-decomposition of S. Its path-width, denoted by pwd (S), is defined in a similar way with the additional condition that T is a directed path. We denote by TWD(R, ≤ k) and by PWD(R, ≤ k) the classes of R-structures of tree-width and, respectively, of path-width at most k.

Remark 9.13 Definition 9.12 states no condition about the constants of the considered structure. In order to have an exact generalization of the notion of tree-decomposition of a graph with sources, we could add to Conditions (i)-(iii) the following one:

(iv) all constants of S belong to the root box.

This would be natural because the sources of a graph become constants of the corresponding relational structure. However, we will not need this condition because we will not extend to relational structures the expression of tree-decompositions of graphs by terms in T (F HR ). Imposing condition (iv) would restrict the notion of tree-decomposition and yield a different notion of tree-width. If we denote it by twd (S), then we have twd (S) ≤ twd (S) ≤ twd (S) + |R 0 | for every S in STR(R), because every tree-decomposition can be made into one satisfying (iv) by adding the constants to all boxes. It follows that the same subsets of STR(R) have bounded tree-width according to both notions of tree-decomposition.

The tree-width and the path-width of a relational structure S are closely related to the tree-widths and path-widths of its incidence graph and of its adjacency graph4 that is the simple, loop-free and undirected graph Adj (S) with vertex set equal to D S and edges between d and d = d whenever d and d occur in some tuple of S.

We let twd Inc (S) denote the tree-width of the graph Inc(S). (We extend a notation introduced for stating Corollary 9.6.) This value is also the tree-width of Inc (S) except in the uninteresting case where ρ(R) ≤ 1.

Proposition 9.14 Let R be a relational signature such that ρ(R) ≥ 1. For every relational structure S ∈ STR c (R), we have:

(1) S and Adj (S) have the same tree-decompositions, and hence we have twd (S) = twd (Adj (S)).

(2) twd Inc (S) -1 ≤ twd (S) ≤ ρ(R) • (twd Inc (S) + 1) -1.

The same properties hold for path-width instead of tree-width.

Proof: (1) By the definitions, every tree-decomposition of S is also one of Adj (S). Conversely, if (Z, f ) is a tree-decomposition of Adj (S), then every tuple (d 1 , . . . , d n ) of a relation R S induces a clique in Adj (S) and hence, is contained in some box of (Z, f ) by Proposition 2.58. Hence, (Z, f ) is also a tree-decomposition of S.

(2) Let (Z 0 , f 0 ) be a tree-decomposition of S ∈ STR c (R). We extend it as follows to a tree-decomposition (Z, f ) of Inc(S). For each tuple (R, d 1 , . . . , d n ) in T S , i.e., such that R ∈ R + and (d 1 , . . . , d n ) ∈ R S , we select one node u of Z 0 such that d 1 , . . . , d n ∈ f 0 (u) (there exists one by Condition (ii) of Definition 9.12), we add to Z 0 a new node u that we make into a son of u in Z and we define f (u ) := f 0 (u) ∪ {(R, d 1 , . . . , d n )}. It is clear that Z is a rooted tree, that Z 0 ⊆ Z and that all nodes of Z that are not in Z 0 are leaves. Each element of T S belongs to a single box f (u) of (Z, f ), such that u is a leaf. The pair (Z, f ) is a tree-decomposition of Inc(S). If (Z 0 , f 0 ) has width k, then (Z, f ) has width k or k + 1. This gives the first inequality. If (Z 0 , f 0 ) is a path-decomposition, we construct similarly a path-decomposition (Z, f ) of Inc(S): instead of adding u as new leaf, we insert it between u and its son. Hence, Z is a path.

For proving the second inequality, we let (Z, f ) be a tree-decomposition of Inc(S) of width k. We turn it into a tree-decomposition (Z, f ) of S by defining, for each u ∈ N Z , the box f (u) as: The proof is the same for path-width because the class of graphs PWD(≤ k) is also characterized by a finite set of excluded minors.

CMS 2 -satisfiability and model-checking Theorem 9.18 For every relational signature R and every integer k, the class TWD(R, ≤ k) has a decidable CMS 2 -satisfiability problem.

Proof: The CMS 2 -satisfiability problem for a set of R-structures C is, by definition, the CMS-satisfiability problem for its set of incidence graphs Inc(C). By Proposition 9.17, the set Inc(TWD(R, ≤ k)) is HR-equational. Hence, by Theorem 5.80(2), its CMS-satisfiability problem is decidable. This result extends Corollary 5.81(2). Here is a converse that extends Theorem 7.55 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF].

Theorem 9.19 Let R be a relational signature. If a subset C of STR(R) has a decidable MS 2 -satisfiability problem, then it has bounded tree-width, equivalently, Inc(C) is included in τ (trees) for some MS-transduction τ .

Proof: Let C ⊆ STR(R) have a decidable MS 2 -satisfiability problem. The MS-satisfiability problem for Inc(C) is thus decidable by the definitions. By Lemma 9.15 and the Reduction Theorem (Theorem 7.54), its MS 2 -satisfiability problem is decidable. Hence, by Theorem 7.55 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF], it has bounded tree-width and so has C by Proposition 9.14(2).

If we only assume that C has a decidable MS-satisfiability problem, we cannot draw any similar conclusion. The following question is open (cf. Question 7.59).

Question 9.20 Is it true that, for every relational signature R, if a set of Rstructures has a decidable CMS-satisfiability problem, then it is included in τ (trees) for some monadic second-order transduction τ ? If R is binary, then the answer is positive and this follows from Theorem 7.55(2) since simple directed labelled graphs correspond to relational structures over binary signatures (cf. Definition 2.11). It is also positive if the considered set C is uniformly k-sparse for some k: this is a consequence of a result to be proved in Section 9.4. (Uniform sparsity means that the structures in C have "few tuples".) The question is open even if R consists of a single relation of arity 3.

We now consider the model-checking problem, i.e., the problem of checking whether a given sentence ϕ is true in a given relational structure S. The major concern is to have efficient, or at least fixed-parameter tractable, algorithms for fixed sentences. We recall from Definition 5.3 that the size of an R-structure S is defined as

S := R + |D S | + R∈R+ ρ(R) • |R S |,
hence, it is Θ( Inc(S) ) for fixed R. The following theorem is a direct application of Theorem 6.4(1) about graphs of bounded tree-width.

Theorem 9.21 The model-checking problem for relational structures and CMS 2 sentences is fixed-parameter linear with parameter (twd (S), ϕ) where S is the input structure and ϕ is the input sentence.

Proof: Let be given a relational signature R, a concrete R-structure S and a CMS 2 sentence ϕ. By the definitions, ϕ is true in S if and only Inc(S) |= ϕ. The structure Inc(S) can be constructed from S in time O( S ). Its size and its tree-width are proportional to those of S (by Proposition 9.14(2) for the tree-width). Hence, Theorem 6.4(1) can be applied to the (R, In R )-labelled graph Inc(S) and the CMS sentence ϕ, and it yields a fixed-parameter linear algorithm as desired.

The other algorithmic problems considered in Chapter 6 for graphs of bounded tree-width extend in a similar way.

By the proof of Theorem 9.21 and by Proposition 9.14(2) for path-width, the observations made in the introduction of Section 6.3.5 about the model-checking of CMS 2 sentences on graphs of bounded path-width extend to relational structures. In particular, given a structure S, we construct the labelled graph Inc(S): its size and path-width are proportional to those of S. We construct a slim HR-term evaluating to this graph, and from it a VR-term, as explained in the introduction of Section 6.3.5. We use an F VR [R,In R ] -automaton on this term. We obtain a fixed-parameter linear algorithm for parameter (pwd (S), ϕ), similar to that of Theorem 9.21. The advantage is that the corresponding automata are easier to construct.

Terms denoting relational structures

In Chapter 5 we have defined the many-sorted algebra STR of relational structures with signature F QF , of which the graph algebra GP t defined in Chapter 2 is a subalgebra. From this definition, we can obtain denotations of relational structures by terms. Our objective is to prove that the value mapping from terms (over finite subsignatures of F QF ) to relational structures is a monadic secondorder transduction. This result will generalize Proposition 7.30 that concerns in a similar way terms over the signature F VR and the graphs they define. We will also discuss the extension to relational structures of several notions and results relative to graphs, in particular clique-width, fixed-parameter model-checking algorithms and decidability of monadic second-order satisfiability problems.

We first review some definitions relative to the many-sorted F QF -algebra STR defined in Section 5.3.7 (Definition 5.62). Its set of sorts S is the countable set of relational signatures, and the set STR(R) of (abstract) R-structures is the domain of sort R. The operations of F QF are the disjoint union and the (unary) quantifier-free operations; its constant symbols denote the structures with at most one element. The many-sorted algebra GP t of graphs with ports defined in Section 2.6.3 is a subalgebra of STR.

Monadic second-order model-checking problems

If t ∈ T (F QF ), then we denote by Sig(t) the subsignature of F QF consisting of all symbols that have occurrences in t, and by val (t) the relational structure that is its value. The following result is an immediate application of the Recognizability Theorem for the algebra STR. It can be seen as a generalization of Theorem 6.3(3).

Theorem 9.22 Let R be a relational signature. The problem of checking if a sentence ϕ ∈ CMS(R, ∅) is true in the structure val (t) where t is a term in T (F QF ) is solvable by a fixed-parameter linear algorithm with parameter (Sig(t), ϕ).

Proof: Let be given a relational signature R and t ∈ T (F QF ). First, we compute Sig(t) and check whether val (t) is actually an R-structure. This can be done in time O(|t|). Together with Proposition 3.76(1,2) and Theorem 3.62, the Recognizability Theorem for STR (Theorem 5.75) yields that the set L of terms s ∈ T (Sig(t)) such that S := val (s) is an R-structure that satisfies ϕ is regular. It is recognized by a finite automaton that can be constructed from Sig(t) and ϕ. The membership of t in L can be checked in time O(|t|).

This algorithm operates in time bounded by f (Sig(t), ϕ) • |t| for some computable function f . We can consider R as part of the input and we still have a fixed-parameter linear algorithm with a function f depending also on R. However, in most cases, model-checking problems concern relational structures over fixed signatures. Statements and proofs are then slightly simpler.

The algorithm takes as input a term t denoting a relational structure S and not S itself. The parsing problem, that is, the construction of a term in T (F ) for some given finite subsignature F of F QF that evaluates to a given relational structure has presently no polynomial algorithm that can play the role of those of [START_REF] Bodlaender | A linear-time algorithm for finding treedecompositions of small treewidth[END_REF] and of [HliOum] and [OumSey] for graphs, that we have used in Theorem 6.4. Let us make an optimistic conjecture.

Conjecture 9.23 For every relational signature R and every finite subsignature F of F QF , one can construct a polynomial-time algorithm doing the following:

for every R-structure S, either it answers that S is not the value of any term in T (F ) or it outputs a term in T (F QF ) that evaluates to S. This conjecture would imply the following:

For every set C of R-structures that is generated by a finite subsignature F of F QF and every sentence ϕ ∈ CMS(R, ∅), one can decide in polynomial time if a given structure S belonging to C satisfies ϕ.

Note that such a polynomial algorithm is not required to check if S belongs to C, and is not necessarily fixed-parameter tractable for the parameter (F, ϕ).

Proposition 6.8 has established the validity of Conjecture 9.23 for binary signatures (and for F ⊆ F VR ) since the corresponding structures are the same as simple labelled graphs. The resulting algorithm is even fixed-parameter cubic.

From terms to relational structures by MS-transductions

We will prove that, for every finite subsignature F of F QF the evaluation mapping val from terms in T (F ) to relational structures is a monadic second-order transduction. Proposition 7.30 proves this result for the special case of graphs defined by terms over F VR . For R ∈ S, we will denote by F QF R the finite set of operations of F QF whose sorts are subsets of R.5 If F is a finite subsignature of F QF , then F ⊆ F QF R where R is the union of all signatures R that occur in the types of the symbols of F . Clearly, R is finite. 6We will denote by cval (t) the concrete structure defined as follows by a term t ∈ T (F QF ). Its domain is a subset of Occ 0 (t), the set of occurrences of the constant symbols that denote nonempty structures. For defining cval (t) if t = f (t 1 ), we use the operation on concrete structures specified by the definition scheme of f . We also use the union of disjoint concrete structures. The domain of cval (t) may be a proper subset of Occ 0 (t) because a QF operation f may delete elements of its input structures. If t = t 1 ⊕ t 2 , then cval (t) is the union of the disjoint structures cval (t)/u 1 and cval (t)/u 2 where u 1 and u 2 are the two sons of the root of t. They are actually disjoint because their domains are sets of leaves of t that are respectively below u 1 and below u 2 . Clearly, val (t) is the abstract structure isomorphic to cval (t). These definitions generalize in the obvious way those of Section 2.5.2.

If t ∈ T (F QF R), then cval (t) is an R -structure for some R ⊆ R. We will denote by T (F QF R) R the set of terms that evaluate to an R -structure. The following proposition generalizes Proposition 7.30. Proposition 9.24 For each R ∈ S and R ⊆ R, the mapping

val : T (F QF R) R → STR(R )
is a parameterless noncopying MS-transduction.

Proof: Let R ∈ S. We let F := F QF R and k := ρ(R), the maximal arity of a symbol in R.

If t ∈ T (F ) and u ∈ N t , then the concrete structure cval (t)/u isomorphic to val (t/u) has for domain a possibly proper subset of the set of elements of Occ 0 (t) that are below u.

For each m ≥ 1, we let X m be the (standard) set of first-order variables {x 1 , . . . , x m }, and Atom(R, X m ) be the set of atomic formulas of QF(R, X m ), including the trivial formulas x i = x i and a = a (for a ∈ R 0 ) that will be useful. For a formula β ∈ QF(R, X m ), we denote by Var (β) ⊆ X m the set of variables that occur in β, and by Con(β) ⊆ R 0 the set of constant symbols that occur in β.

Let t ∈ T (F ) and γ be an X m -assignment in t such that γ(x i ) is a leaf of t for each i. If u ∈ N t and β ∈ QF(R, X m ), then we write:

(cval (t)/u, γ) |= β if and only if (1) γ(x i ) ∈ D cval(t)/u for each i such that x i ∈ Var (β),

(2) Con(β) is included in the sort of t/u, and

(3) (cval (t)/u, γ Var (β)) |= β.

It follows that (cval (t)/u, γ) |= x i = x i if and only if γ(x i ) ∈ D cval(t)/u , which implies in particular that γ(x i ) ≤ t u. Also, (cval (t)/u, γ) |= a = a if and only if a is in the sort of t/u.

For t and γ as above and for every α ∈ Atom(R, X m ), we define: E α (t, γ) := {u ∈ N t | (cval (t)/u, γ) |= α}.

We will prove that these sets can be defined in t by a monadic second-order formula. For this purpose, we introduce a set variable Y α for every α ∈ A := Atom(R, X m ), and we let W m be the set of these set variables Y α . We will use the following auxiliary construction. If C is a Boolean set term7 over W m and if (E α ) α∈A is a family of sets, then we denote by C((E α ) α∈A ) the set defined by C with E α as value of Y α . Claim 9.24.1 For each β ∈ QF(R, X m ) there exists a Boolean set term C β over W m such that, for all t, γ and u as above, we have:

(cval (t)/u, γ) |= β if and only if u ∈ C β ((E α (t, γ)) α∈A ).

Proof: We can assume that β is built without disjunction, because if it is not, it can be transformed into an equivalent formula β in QF(R, X m ) without disjunctions that has the same free variables and constant symbols. The latter condition is necessary to ensure that (cval (t)/u, γ) |= β if and only if (cval (t)/u, γ) |= β, because of the particular meaning of |= that we are using. This equivalence would not hold with, e.g., β equal to R(x 1 , x 2 ) and β equal to R(x 1 , x 2 ) ∧ x 3 = x 3 .

We now define C β by the following induction:

C α is Y α if α is atomic, C β∧β is C β ∩ C β , C ¬β is C β ∩ D β
where D β is the intersection of all set variables Y xi=xi such that x i ∈ Var (β) and all set variables Y a=a such that a ∈ Con(β).

It is clear from the definitions that C β satisfies the required property.

The central part of the proof is the following claim.

Claim 9.24.2 There exists a formula Ψ m in MS(R F , W m ∪ X m ) such that a (W m ∪ X m )-assignment γ in t satisfies Ψ m if and only if, for every i, γ(x i ) is a leaf of t and, for every α ∈ A := Atom(R, X m ), we have:

γ(Y α ) = E α (t, γ X m ).
Proof: The construction of Ψ m will be based on the following informally stated fact:

if u is a node of t, then the condition "u ∈ E α (t, γ X m )" is equivalent to a Boolean combination of conditions of the form "u ∈ E α (t, γ X m )" for the sons u of u and atomic formulas α ∈ A. This condition will be expressed by a monadic second-order formula ψ f,α in MS(R F , W m ∪ X m ∪ {u}) where f is the label of u. And then, the formula Ψ m will be defined as: "x 1 is a leaf" ∧ • • • ∧ "x m is a leaf" ∧ α∈A,f ∈F ∀u(lab f (u) ⇒ (u ∈ Y α ⇔ ψ f,α )). We now describe the formulas ψ f,α . There are several cases depending on f occurring at u.

Case 1: u ∈ Occ(t, ∅ R ). We define ψ f,α as False, except that ψ f,True is True.

Case 2: u ∈ Occ(t, ♦ B,R ). We recall that ♦ B,R denotes the R -structure with a singleton domain equal to, say, { * } and empty relations for all R of positive arity not in B. The element * is the value of all constant symbols.

We define ψ f,α as the conjunction of the equalities x i = u for each x i ∈ Var (α) if Con(α) ⊆ R and ♦ B,R |= α( * , . . . , * ), and as False otherwise.

Case 3: u ∈ Occ(t, ⊕). The two sons of u will be denoted by u 1 and u 2 . We define ψ f,α as:

∃u 1 , u 2 [son 1 (u, u 1 ) ∧ son 2 (u, u 2 ) ∧ (u 1 ∈ Y α ∨ u 2 ∈ Y α )].
This is correct because an instantiated atomic formula (i.e., given with values to its variables) is valid in the disjoint union of two structures if and only if it is valid in one of them.

Case 4: u ∈ Occ(t, f ) where f is a unary QF operation of type R → R . The definition of ψ f,α will use Claim 9.24.1. We will write the formulas ψ f,α by using u ∈ C β as an abbreviation of the corresponding Boolean combination of formulas u ∈ Y α , where C β is as in Claim 9.24.1. We let f be defined by the QFO definition scheme δ, (θ R ) R∈R + , (κ c,d ) c∈R 0 ,d∈R 0 . The unique son of its occurrence u will be denoted by u 1 . We consider several cases.

Case (4.1): α is x i = x j . Then u ∈ E α (t, γ) if and only if (cval (t)/u 1 , γ) |= δ[x i /x] ∧ x i = x j . Hence, we define ψ f,α as the formula

∃u 1 (son 1 (u, u 1 ) ∧ u 1 ∈ C δ[xi/x] ∧ u 1 ∈ Y xi=xj ).
Case (4.2): α is x i = a or a = x i , where a ∈ R 0 . If a ∈ R 0 -R 0 , then ψ f,α is False. Now let a ∈ R 0 . We have u ∈ E α (t, γ) if and only if, for some c ∈ R 0 , we have (cval (t)/u 1 , γ) |= κ c,a ∧ x i = c. Hence, we define ψ f,α as the formula:

∃u 1 [son 1 (u, u 1 ) ∧ c∈R 0 (u 1 ∈ C κc,a ∧ u 1 ∈ Y xi=c )].
Case (4.3): α is a = b, where a, b ∈ R 0 . On the basis of similar observations, we define ψ f,α either as False or as the formula

∃u 1 [son 1 (u, u 1 ) ∧ c,d∈R 0 (u 1 ∈ C κc,a ∧ u 1 ∈ C κ d,b ∧ u 1 ∈ Y c=d )].
Case (4.4): α is R(t 1 , . . . , t n ), where R ∈ R n and the terms t i are variables or constant symbols. We assume, without loss of generality, that the formula θ R (x 1 , . . . , x n ) ⇒ δ[x i /x] is universally valid. If all terms t i are variables, then, since we have u ∈ E α (t, γ) if and only if (cval (t)/u 1 , γ) |= θ R [t 1 /x 1 , . . . , t n /x n ], we can define ψ f,α to be the formula If some (or all) of the terms t i are constant symbols, then we combine this definition and those used in Cases (4.2) and (4.3). Just to take an example, if t 1 is a ∈ R 0 and t 2 , . . . , t n are variables, then we define ψ f,α as the formula:

∃u 1 [son 1 (u, u 1 ) ∧ c∈R 0 (u 1 ∈ C κc,a ∧ u 1 ∈ C θ R [c/x1,t2/x2,...,tn/xn] )].
The extension to the case where several of the terms t i are constant symbols is straightforward but lengthy to write. This completes the construction of the formulas ψ f,α and the proof of the claim.

We now complete the proof of the proposition. Let R ⊆ R. The output structures may have constants, and these constants will be specified by unary relations. Hence, we will define an MS-definition scheme of type R F → R * , cf. Section 7.1.2. It will be of the form D * := χ, ∆, (Θ R ) R∈R * .

Its precondition χ must verify that the input structure actually represents a term t in T (F ) R , cf. Corollary 5.12. The other formulas are required to work correctly under the assumption that the input structure is of the form (or is isomorphic to) t for some term t in T (F ) R . We denote by W m a tuple enumerating the set W m . We assume that rt is in R F , with ρ(rt) = 0.

The formula ∆, with free variable x 1 , is defined as:

∃W 1 (Ψ 1 ∧ rt ∈ Y x1=x1 ).
Note that the tuple W 1 does not consist only of Y x1=x1 .

For each R in R m such that m ≥ 1, we define the relation formula Θ R with free variables x 1 , . . . , x m as: (x1,...,xm) ).

∃W m (Ψ m ∧ rt ∈ Y R
If a ∈ R 0 , then we let Θ laba with free variable x 1 be defined as:

∃W 1 (Ψ 1 ∧ rt ∈ Y x1=a ).
It follows from this construction that D * associates with every term t in T (F ) R the relational structure cval (t) * in STR c * (R * ).

Corollary 9.25 Every set of relational structures that is equational in STR is the image of trees under an MS-transduction.

Its converse, proved in [START_REF] Blumensath | Recognizability, hypergraph operations, and logical types[END_REF] (Proposition 63 and Theorem 68), gives an Equationality Theorem for relational structures that is analogous to Theorem 7.36. It will be stated in Theorem 9.31. Proposition 9.24 yields another proof of Theorem 9.22, that is not based on the proof of the Recognizability Theorem given in Chapter 5, cf. Remark 7.31 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. However, the proof of Proposition 9.24 uses complicated constructions and is thus not usable in practice. Constructions of finite automata generalizing those of Section 6.3.4 are left for future research.

Width notions for relational structures

In Chapter 2 we have defined the graph algebra GP with signature F VR and the closely related notion of clique-width. In Chapter 7, we have characterized the sets of graphs of bounded clique-width as the subsets of the images of trees under monadic second-order transductions. In the present section, we aim at generalizing the notion of clique-width and the associated results. We want to obtain the following:

(i) a "good" notion of width of a relational structure, defined in terms of its generation by a "small" finite subsignature of F QF , that is equivalent to clique-width for graphs,

(ii) such that bounded tree-width implies bounded width, (iii) and such that the sets of relational structures of bounded width have a logical characterization along the lines of Corollaries 7.38(1), 7. 49 and 9.16.

We first present a natural extension to relational structures of the signature F VR of the graph algebra GP. This extension is useful for handling relational structures of bounded path-width (cf. Proposition 9.28 and the remarks on model-checking at the end of Section 9.2), but it does not satisfy the above properties (ii) and (iii). This indicates that it has not enough operations. A richer signature and an associated satisfactory width notion will be defined in Section 9.3.4.

A first extension of F VR to relational structures

The following definitions are relative to a fixed relational signature R without constant symbols.

Definition 9.26 (The operations of F relVR on R-structures) Let A be a countable set of labels. We will construct structures in STR(R) by using at intermediate stages certain "A-labelled" R-structures. For each a ∈ A, we let lab a be a unary relation not in R. It will hold the set of elements of a structure labelled by a. We let Lab(C) := {lab a | a ∈ C} for each finite subset C of A.

The labels of the sets C will be attached to the elements of structures and will be used to construct structures similarly as port labels are used to construct graphs. However, an element may have several labels or no label at all, whereas in a p-graph, each vertex has one and only one port label.

We define a many-sorted signature F relVR We define mdf Z,C,C (S) as the concrete (R ∪ Lab(C ))-structure S such that D S := D S , R S := R S for every R ∈ R and, for every a ∈ C and x ∈ D S :

x ∈ lab aS if and only if x ∈ lab bS for some b ∈ C such that (b, a) ∈ Z.

(If there is no b such that (b, a) ∈ Z, then mdf Z,C,C deletes the label a.)

These unary operations are quantifier-free and domain preserving (i.e., they are DP-QF operations). The operation mdf Z,C,C is a quantifier-free relabelling (cf. Definition 7.20, Section 7.1.6).

For each finite set C, we define F relVR C as the set of operations of F relVR whose sorts (the sorts occurring in their input and output types) are subsets of C.

Every term t in T (F relVR

C

) evaluates to a concrete (R ∪ Lab(C))-structure cval (t) whose domain is the set Occ 0 (t) of all occurrences in t of constant symbols not defining empty structures (since the unary operations do not delete elements, each occurrence in Occ 0 (t) specifies an element of D cval(t) ). The definitions and the notation of Section 2.5.2 concerning the concrete graphs defined by terms in T (F VR ) extend in a straightforward manner.

Every structure S in STR(R ∪ Lab(C)) is isomorphic to cval (t) for some term t in T (F relVR We define the relational width relwd (S) of S ∈ STR(R ∪ Lab(C)) as the minimal cardinality of a set C such that some term in T (F relVR

C

) evaluates to (a concrete structure isomorphic to) S. The operations of F relVR and this notion of width have been introduced in Section 5 of [CouER] (but the term "relational width" is not used in this article). The subsets of STR(R) that are equational in the corresponding many-sorted F relVR -algebra, that we will denote by STR rel R , are the sets defined by certain grammars, called the separated handlerewriting hypergraph grammars (cf. Theorem 6.1 of [CouER]). This algebra and the corresponding notion of width satisfy Property (i) but not Properties (ii) and (iii) as we will prove. The following proposition and its proof are from [AdlAdl].

Proposition 9.27 Let R := {R} with R ternary. There exists a subset L of STR(R) that has tree-width 3, unbounded relational width and that is the image of trees under a monadic second-order transduction.

Proof: We let D be the class of simple, directed and loop-free graphs. For G ∈ D, we define f (G) in STR c (R) as follows:

D f (G) := V G ∪ E G , R f (G) := {(x, y, e) | e ∈ E G , e : x → G y}.
It is clear that twd (f (G)) ≤ twd (G) + 1.

We denote by ♦ the graph with the single vertex * and no edge. We recall that the binary symbol -→ ⊗ denotes the complete directed join on graphs (cf. Example 2.108, Section 2.5.4).

Every set of R-structures that is equational in the algebra STR rel R , has bounded relational width (cf. Proposition 4.44). Hence the set L of Proposition 9.27 is not equational in STR rel R . The following proposition, proved in [AdlAdl], establishes another relation between relational width and path-width. We have proved a similar fact in Proposition 2.114 (1.3).

Proposition 9.28 The relational width of a structure is at most its path-width + 1.

Proof: We sketch the proof. Let S be an R-structure having a path-decomposition (P, f ) of width k-1. Each box has at most k elements. By Propositions 2. 67 and 9.14(1), we can assume that it is 1-downwards increasing and that its root box has a single element. By Lemma 2.78, we can define a coloring γ of D S with k colors, say the elements of [k], such that any two elements in a box have different colors. Let the path P be d 1 → • • • → d n . Hence, {d 1 , . . . , d n } is in bijection with, and will be considered as identical to, the domain D S , cf. Example 5.2(4). For each i ∈ [n], we let S i be the substructure of S induced by the set {d 1 , . . . , d i }. Furthermore, if d ∈ D Si ∩ f (d i ), we label it in S i by γ(d); this label will be deleted in S j for some j > i or at the very end.

Then S i+1 is easily built from S i by the operations of F relVR that use the k labels of [k], called above colors. Informally, the tuples of S are added one by one as one builds successively S 1 , . . . , S n . At the end, all colors are deleted. This fact has consequences for the model-checking of CMS sentences on relational structures of bounded path-width. We have observed after Theorem 9.21 that we can construct path-decompositions in linear time, and from them, terms over F VR [R,In R ] with "few" port labels (because of Proposition 2.114(1.3)) allowing to check CMS 2 sentences. By Proposition 9.28, we can construct simpler terms over F relVR that suffice for checking CMS sentences. Furthermore, the corresponding finite automata, extending those of Section 6.3.4, are "easy" to build. (This point remains to be verified by an implementation extending that of [START_REF] Courcelle | Automata for the verification of monadic second-order graph properties[END_REF]). 9.3.4 A powerful subsignature of F QF and another width for relational structures

The converse of Corollary 9.25 is proved in [START_REF] Blumensath | Recognizability, hypergraph operations, and logical types[END_REF] (Proposition 63). It is even proved for a subsignature of F QF that is as powerful as F QF in the sense that it yields all the equational sets of STR: every equation system over F QF can be transformed into an equivalent one over this restricted signature. We will only state this result and the necessary definitions. We refer the reader to [START_REF] Blumensath | Recognizability, hypergraph operations, and logical types[END_REF] for the rather technical proofs.

In what follows, we only consider relational signatures without constants. In this way, we simplify the presentation and we focus on the main aspects. The case of constants will be discussed briefly afterwards (in Remark 9.32(b)).

Definition 9.29 (The signature F redQF R,B ) Let R and B be disjoint relational signatures without constants. The set B will play the role of Lab(C) in the previous definition. We will later require that ρ(B) < ρ(R).

We let F redQF R,B

be the "reduced" subsignature of F QF defined as follows. It has the single sort R ∪ B, with domain STR(R ∪ B). Its unique binary operation is the disjoint union ⊕. Its constant symbols are ∅ to denote the empty structure and the symbols ♦ C,R∪B for C ⊆ R∪B to denote the structures with one element (cf. Definition 5.62). Its unary operations are the following ones:

(a) For every C ⊆ B, the operation del C empties the relations of C, without modifying the domain of the input structure. We distinguish it from an operation fg C that would generalize the forgetting operation of Definition 7.19 by deleting C from the signature: here, del C keeps the relations of C in the signature of the output structure.

(b) For every arity preserving mapping h : R∪B → R∪B that is the identity on R, the operation relab h replaces every relation R S of the input structure S by the union of the relations R S such that R = h(R ). In other words, each tuple (R, d 1 , . . . , d n ) of T S is replaced by (h(R), d 1 , . . . , d n ). A relation R of arity n has a defining formula θ R equal to R ∈h -1 (R) R (x 1 , . . . , x n ).

(c) For every T, U ∈ B, every R ∈ R ∪ B and every surjective mapping

h : [m] → [k + l],
where k = ρ(T ), l = ρ(U ) and m = ρ(R), we define the quantifier-free operation add T,U,R,h : STR c (R) → STR c (R) that redefines R by means of the formula θ R : R(x 1 , . . . , x m ) ∨ [T (x i1 , . . . , x i k ) ∧ U (x i k+1 , . . . , x i k+l ) ∧ j,j ∈[m],h(j)=h(j ) x j = x j ] where, for each s ∈ [k + l], i s is the smallest element of h -1 (s). This operation modifies no relations other than R.

All these unary operations are domain preserving.

Here is the intuition: the relations of B are "temporary": they can be modified or deleted. They generalize the port labels used to build graphs of bounded clique-width. They can be used to add tuples to the relations in R. The tuples of a relation in R cannot be removed. Similarly, the operations of F VR cannot delete edges. (2) Let U ∈ B and U ∈ R∪B-{U } be of the same arity. If h : R∪B → R∪B is such that h(U ) = U and h(R) = R for R = U , then the operation relab h applied to a structure S empties U S and replaces U S by U S ∪ U S .

(3) We let B contain the binary relation symbol W and R the 6-ary symbol R. We let f be the unary operation add W,W,R,h where h : [6] → [4] is such that h(1) = h(2) = 1, h(3) = 2, h(4) = 3, h(5) = h(6) = 4. In a structure S where u, x, y, z ∈ D S and (u, x), (y, z) belong to W S , the operation f adds to R f (S) the tuple (u, u, x, y, z, z). Note that u, x, y, z need not be pairwise distinct.

Theorem 9.31 (Equationality Theorem for relational structures) Let R be a relational signature without constant symbols. The following properties of a subset L of STR(R) are equivalent:

(1) L is equational in the algebra STR.

(2) L is the image of trees under an MS-transduction.

(3) L = val (M ) for some regular subset M of T (F redQF R,B ) and some relational signature B such that ρ(B) < ρ(R).

Proof: (1) =⇒ (2) by Proposition 9.24 and the characterization of equational sets as images of regular languages (cf. Corollary 3. 19 and Proposition 3.23(3)).

(2) =⇒ (3): Proposition 63 of [START_REF] Blumensath | Recognizability, hypergraph operations, and logical types[END_REF] establishes this statement. It corresponds to Theorem 7.34 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] with T (F redQF R,B ) in place of T (F VR C,[K,Λ] ), and for a relational signature B such that ρ(B) < ρ(R). The result follows then with the usual tools like Proposition 7.27.

(3) =⇒ (1): Property (3) implies, with the results of Chapter 3, that L is equational in the subalgebra of STR generated by F redQF R,B . Hence, it is equational in STR.

Remarks 9.32 (a) Property ( 1) allows L to be defined by an equation system written with operations of F QF involving relational structures with constant symbols. (In particular, some unknowns of this system may generate structures with constants.) The equivalence with Property (3) implies that this system can be replaced, for defining L, by one not using such operations.

(b) If a set L ⊆ STR(R) where R contains constant symbols is equational in STR, then L * , the corresponding set of structures without constants, satisfies Property (2) and thus Property (3). In order to get an Equationality Theorem for R-structures, it suffices to prove that, if L * is equational, then so is L in the algebra STR. We will spare the reader this scholarly exercise.

(c) An alternative to Property (3) is established in [SheDor]: informally, auxiliary relations of arity at most 3 suffice, but not exactly in the sense of Property (3). This article proves that if L satisfies Property (2), then it is val (M ) for some regular subset M of T (F QF -{∅}) ∪ {∅}. We can eliminate ∅ from every term of M by a proof similar to the one of Claim 7.34.1, since we have g(∅) = ∅ for every unary operation g (together with the equalities for ∅ and ⊕ in Proposition 2.101 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]3)).

Yet another width? Definition 9.33 (The width w R ) We will use the following notion of size of a relational signature R without constant symbols that differs slightly from the one defined in Definition 5.3. We let:

R := {ρ(R) | R ∈ R}.

We assume that ρ(R) > 1, otherwise, R-structures are of no interest. For every S ∈ STR(R), we let w R (S) be the minimum size of a signature B, disjoint with R, such that ρ(B) < ρ(R) and S is the value of a term over F redQF R,B . It is clear that every R-structure S is the value of a term over F redQF R,B for some large enough set B. For example, if ρ(R) = 3 and n = |D S |, one can construct such a term by using a set B consisting of n unary relations and n(n -1)/2 binary relations. In general, we have w R (S) ≤ ρ(R) • n ρ(R)/2 . If L is a set of R-structures, we let w R (L) := max{w R (S) | S ∈ L}.

For the following proposition, we recall that R s,[K,Λ] is the relational signature used for representing simple (K, Λ)-labelled graphs (cf. Examples 5.2(2)).

Proposition 9.34

(1) For every simple (K, Λ)-labelled graph G, we have:

w R s,[K,Λ] ( G ) ≤ cwd (G) ≤ f (w R s,[K,Λ] ( G ))
for some fixed computable function f depending on (K, Λ).

(2) For every relational signature R and every S, S ∈ STR(R) such that S is a substructure 8 of S , we have w R (S ) ≤ w R (S).

(3) For every relational signature R and positive integer k, the set of Rstructures S such that w R (S) ≤ k is the image of trees under a monadic second-order transduction. Conversely, if L ⊆ STR(R) and L is included in the image of trees under a monadic second-order transduction, then w R (L) is finite.

(4) For every two relational signatures R and R without constant symbols, and every monadic second-order transduction τ of type R → R , there exists a computable function f τ such that w R (U ) ≤ f τ (w R (S)) for every S ∈ STR(R) and every U in τ (S). (2) The proof is similar to the proof of the corresponding result for cliquewidth (Proposition 2.105( 1)). Let S and S be as in the statement. Let S be the value of a term t in F redQF (3) The first assertion follows from Proposition 9.24 and Proposition 7.27. The second one follows from the implication (2) =⇒ (3) of Theorem 9.31.

(4) Immediate consequence of Proposition 9.24 and the usual arguments (cf. the proof of Corollary 7.38(2)).

We get also that w R (L) is finite if L has bounded tree-width (because Inc(L) is included in the image of trees under an MS-transduction by Corollary 9.16, hence L is included in the image of trees under an MS-transduction, hence w R (L) is finite). Hence, the numerical parameter w R (S) satisfied the Conditions (i) to (iii) stated at the beginning of Section 9.3.3. However, we give it no name because some equivalent one having better combinatorial and algorithmic properties may be found in the (next) future and names are not that easy to find for mathematical notions, so we prefer to spare them.

Sparse relational structures

We will prove that for expressing properties of simple graphs that are sparse, i.e., that have "few" edges in a precise sense to be defined, CMS 2 formulas are no more powerful than CMS formulas. This result, which we call the Sparseness Theorem, applies in particular to planar graphs, to graphs of bounded treewidth and, more generally, to the graphs that exclude some fixed graph as a minor. It applies also to graphs of bounded degree. These facts have been stated in connection with Theorems 1.44,1.49,4.51,4.59 and 5.22. We will actually prove this theorem for relational structures and not only for graphs.

The CMS 2 formulas over relational structures, that can use quantifications on sets of tuples, have been defined in Section 9.2.

All relational signatures will be without constant symbols. The incidence graph of a concrete R-structure is a simple, directed and labelled concrete graph, and it will be identified (as in Section 9.2, Definition 9.10) with the corresponding R Inc -structure.

The proofs of the Sparseness Theorem and all necessary lemmas will consist of constructions of definition schemes for specifying monadic second-order transductions. A definition scheme specifies in the first place a concrete transduction. We will have to construct definition schemes that specify particular concrete transductions, and not only transductions of abstract structures. Hence, in this section and unless otherwise specified:

Convention: All graphs, relational structures and transductions will be concrete.

Our tools concerning transductions, in particular Theorem 7.10 (the Backwards Translation Theorem) and Theorem 7.14 (about compositions of transductions) have been formulated for concrete MS-transductions. The following definitions concern only concrete structures and transductions.

:= R S ∪ R S if R ∈ R ∩ R , R T := R S if R ∈ R -R and R T := R S if R ∈ R -R.
If τ and τ are concrete transductions of respective types R → R and R → R , then we denote by τ + τ the concrete transduction of type R → R ∪ R such that, for every S ∈ Dom(τ ) ∩ Dom(τ ) (its domain), (τ + τ )(S) is the set of structures T + T such that T ∈ τ (S) and T ∈ τ (S). If τ and τ are concrete C r MS-transductions, then τ + τ is also a concrete C r MS-transduction. We sketch the construction of a definition scheme for τ +τ from definition schemes χ, (δ i ) i∈I , (θ w ) w∈R I and χ , (δ i ) i∈I , (θ w ) w∈R I for τ and τ respectively. Note that D T ⊆ D S × I if T ∈ τ (S) and that D T ⊆ D S × I if T ∈ τ (S). We can assume that the sets of parameters used for τ and for τ are disjoint. The definition scheme for τ + τ has all of them as parameters and has precondition χ ∧ χ . Its domain formulas are δ i for all i ∈ I ∪ I where:

δ i is δ i ∨ δ i if i ∈ I ∩ I , δ i is δ i if i ∈ I -I and δ i is δ i if i ∈ I -I.
The relation formulas are easy to write.

We recall from Definitions 9.10 and 5.1 that if S belongs to STR c (R), then T S denotes the set of tuples of S, and if X ⊆ D S , then S[X] denotes the (induced) substructure of S with domain X and relations R S[X] := R S ∩ X ρ(R) for every R ∈ R. A similar notion is defined for graphs in Section 5.2.5 (cf. Theorem 5.22): a graph G is uniformly k-sparse if |E H | ≤ k •|V H | for each of its induced subgraphs H. In Remark 9.39(2) below, we will compare uniform sparsity for labelled graphs and for the associated relational structures. We note immediately that whether a graph G is uniformly k-sparse does not depend on its possible vertex and edge labels. However, the relational structure G represents these labels and its size depends on them.

A set of graphs or relational structures is uniformly k-sparse if its elements are all uniformly k-sparse.

The main result of this section is formulated in the following two theorems.

Theorem 9.37 A class of simple labelled graphs or of R-structures that is uniformly k-sparse is CMS 2 -definable if and only if it is CMS-definable.

The if-direction of this theorem is immediate from the Backwards Translation Theorem (Corollary 7.12) and the fact that the inverse of the mapping Inc is an FO-transduction of abstract structures (Lemma 9.11(2)). Thus, again by Corollary 7.12, Theorem 9.37 is a consequence of the following more technical statement (cf. Theorem 1.49).

Theorem 9.38 (Sparseness Theorem)

The mapping Inc is a domain-extending MS-transduction on the following classes: the class US k (R) of uniformly k-sparse R-structures, for every k > 0 and every relational signature R without constant symbols, and the classes of simple, directed or undirected, uniformly k-sparse (K, Λ)-labelled graphs, for every k > 0 and every pair (K, Λ) of finite sets of labels. By Definition 7.2, this means that a domain-extending MS-transduction τ constructs, for every S in US k (R), one or more structures with domains included in D S ×I for some finite set I, that are all isomorphic to Inc(S) by an isomorphism that maps (a, i) to a for some fixed element i of I.

The proof of Theorem 9.38 will construct a domain-extending p-copying transduction that will extend the domain D S of an input structure S by new elements in bijection with the tuples of S. Such a construction is possible only if S has at most (p -1) • |D S | tuples. Theorem 9.38 shows that, conversely, such a construction is possible for any fixed k > 0 and for all structures in US k (R). We will first establish it for simple, labelled, directed and undirected graphs.9

The full proof will be given in Section 9.4.2, after Theorem 9.61.

Edge set quantifications in uniformly k-sparse graphs

We will denote by M u the class of loop-free undirected graphs, by M d the class of loop-free directed graphs, and by A d the subclass of M d consisting of the acyclic graphs (those without circuits). We recall from Definition 2.9 that an orientation H of a graph G ∈ M u is a directed graph such that und (H) = G: each edge is given a direction. Note that every graph in M u has an acyclic orientation in A d : order the vertices and let the direction of the edges respect the order.

We will denote by S u the class of simple, loop-free undirected graphs. An orientation of a graph G ∈ S u is thus a directed graph H such that V H = V G , edg H ∩ edg -1 H = ∅ and edg G = edg H ∪ edg -1 H . We will denote by S d * the class of orientations of the graphs in S u and by S d k the subclass of those of indegree at most k. Hence, S d * is the class of simple, loop-free directed graphs that have no pair of opposite edges. We will denote by US k the class of graphs in S u that are uniformly k-sparse.

Remarks 9.39

(1) In all this section, we will not consider an undirected graph G as a directed graph with pairs of opposite edges.

(2) If G is a simple directed graph, then |edg G | = |E G |. Hence, it is uniformly k-sparse if and only if the structure G is uniformly k-sparse. If G is undirected, then:

|E G | ≤ |edg G | = |E G | + |E G -Loops(G)| ≤ 2 • |E G |,
where Loops(G) is the set of loops of G. Hence, the structure G is uniformly 2k-sparse if G is uniformly k-sparse. Conversely, if G is uniformly k-sparse, then G is uniformly k-sparse.

Let us now consider a (K, Λ)-labelled graph G. The tuples of the structure G are the pairs representing the labelled edges (each edge has a unique label) and unary tuples representing the labels of the vertices. Hence, if G is directed then:

|E G | ≤ |T G | ≤ |E G | + |K| • |V G |.
It follows that G is uniformly (k + |K|)-sparse if G is uniformly k-sparse. If G is undirected, then we have similarly:

|E G | ≤ |T G | ≤ 2 • |E G | + |K| • |V G |.
These remarks entail that a set L of simple, directed or undirected, (K, Λ)labelled graphs is uniformly k-sparse for some k if and only if the set of structures L is uniformly m-sparse for some m.

(3) The reader will prove easily that for every (K, Λ)-labelled graph G, the relational structure G = Inc(G) is uniformly (2 + |K|)-sparse.

(4) We now compare uniform sparsity for graphs to some related notions.

The average degree of a graph G (possibly with loops and multiple edges) is defined as 2 • |E G |/|V G |. Hence, a set of graphs is uniformly k-sparse if and only if its graphs and their subgraphs have average degree at most 2k.

The property that a graph is uniformly k-sparse is also related with its arboricity. A graph G (possibly with multiple edges) has arboricity at most k if the undirected graph und (G) (or G if it is undirected) is the union of k edge-disjoint forests (i.e., is equal to G 1 ∪ • • • ∪ G k where each graph G i is a forest and E Gi ∩ E Gj = ∅ if i = j). The arboricity of G is the smallest such k. This value is thus undefined for graphs with loops. Arboricity has the following characterization: a loop-free graph G has arboricity at most k if and only if |E G[X] | ≤ k • (|X| -1) for every nonempty subset X of V G ([*Fra, Theorem 6.13]). Hence a graph of arboricity k is uniformly k-sparse. Conversely, a loop-free graph that is uniformly k-sparse has arboricity at most 2k as one checks easily. This bound is best possible since a graph with 2k parallel edges between two vertices has arboricity 2k and is uniformly k-sparse. Hence a set of loop-free graphs has bounded arboricity if and only if it is uniformly k-sparse for some k.

(5) It is clear from the definitions that every graph of degree at most 2d, and every directed graph of indegree at most d, is uniformly d-sparse. Every simple, loop-free, undirected and planar graph is uniformly 3-sparse ([*Die], Corollary 4.2.10). Corollary 2.74 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] shows that a simple, loop-free and undirected graph of tree-width at most k is uniformly k-sparse (cf. the proof of Theorem 4.51). More generally, if G is a simple graph that does not contain K p as a minor, then it has at most a • p log(p) • |V G | edges for some constant a (see [Thon]). The same holds for its subgraphs, hence G is uniformly (a • p log(p))-sparse.

The following proposition collects properties of uniformly k-sparse graphs that will be useful for our constructions. A homomorphism h : G → H where G and H belong to S d * is a mapping : V G → V H such that x → G y implies h(x) → H h(y). For each positive integer k, we define q(k) := 2 2k(k+1)+1 -1.

Proposition 9.40

(1) A graph in S u is uniformly k-sparse if and only if it has an orientation of indegree at most k.

(2) Every simple directed graph of indegree at most k has a proper vertex (2k + 1)-coloring.10

These conditions mean that for every tuple (U 1 , . . . , U n ) of sets of vertices satisfying χ, if W := {(u, v) | u, v ∈ V G and G |= θ(U 1 , . . . , U n , u, v)}, then the directed graph H := V G , W is an orientation of G. Furthermore, for each graph G in C there is such an n-tuple.

Equivalently, they mean that the domain-preserving MS-transduction with definition scheme χ, True, θ edg , where θ edg (the formula that specifies the relation edg H of an output graph H) is θ, associates with every graph G ∈ C one or more orientations of G. The variables in X n are its parameters. If (χ, θ) defines orientations of the graphs in C, then ( θ, θ) does the same, and for the graphs of a possibly larger class. However, it is frequently clearer to use χ instead of θ.

Similarly, if C is a set of directed or undirected graphs, a pair of formulas (χ, θ) as above defines partial orders on V G for every graph G in C (or partially orders the graphs of C) if the same conditions hold where θ is defined here as: ∀x. θ(x, x) ∧ ∀x, y[(θ(x, y) ∧ θ(y, x)) ⇒ x = y] ∧ ∀x, y, z[(θ(x, y) ∧ θ(y, z)) ⇒ θ(x, z)].

In this case, the set W := {(u, v) | u, v ∈ V G and G |= θ(U 1 , . . . , U n , u, v)} is a partial order on V G . The domain-preserving MS-transduction with definition scheme χ, True, θ edg , θ ≤ such that θ edg is edg(x 1 , x 2 ) and θ ≤ is θ, associates with G for G ∈ C one or more structures of the form V G , edg G , ≤ where ≤ is a partial order on V G . In Section 5.2.6 (Definition 5.28), we had a similar definition for specifying linear orders by MS formulas.

The integer q(k) in the following statement is defined before Proposition 9.40.

Proposition 9.42

(1) For each k > 0, there exists a pair of FO formulas (χ(X q(k) ), θ(X q(k) , x 1 ,

x 2 )) that defines orientations of indegree at most k of every graph in US k .

(2) For each k, the class of graphs US k is MS-definable.

Proof: (1) By Proposition 9.40(1), a graph G in S u is uniformly k-sparse if and only if it has an orientation of indegree at most k. We will specify such an orientation by means of a vertex coloring, based on the third assertion of Proposition 9.40 of which we will use the corresponding notions. A k-good coloring of G is a mapping γ : V G → [q(k)] such that: (i) if u and v are adjacent in G, then γ(u) and γ(v) are adjacent in Q(k), (ii) the orientation H of G defined by: u → H v if and only if γ(u) → Q(k) γ(v), has indegree at most k.

By Proposition 9.40(3), a graph G has an orientation of indegree at most k if and only if it has a k-good coloring: if G has an orientation H ∈ S d k , then the homomorphism from H to Q(k) is a k-good coloring. A coloring γ : V G → [q(k)] can be described by a q(k)-tuple of subsets of V G , (U 1 , . . . , U q(k) ) := (γ -1 (1), . . . , γ -1 (q(k))), that defines a partition of V G (some of its sets may be empty). The formulas χ and θ to be constructed have free variables X 1 , . . . , X q(k) and are easy to write. The formula χ expresses, for every graph G in S u , that -U 1 , . . . , U q(k) define a partition of V G , and -the mapping γ : V G → [q(k)] such that γ(u) := i for every i ∈ [q(k)] and u ∈ U i , is a k-good coloring.

The formula θ(x 1 , x 2 ) is edg(x 1 , x 2 ) ∧ i→ Q j (x 1 ∈ X i ∧ x 2 ∈ X j ), expressing that {x 1 , x 2 } is an edge such that γ(x 1 ) → Q(k) γ(x 2 ).

(2) It follows from ( 1) that US k is defined with respect to the class S u by the MS sentence ∃X q(k) . χ.11

For every vertex x of a directed graph G, we define Adj - G (x) as the set {y | y → G x}.

Proposition 9.43 For each k > 0, there exists a pair of MS formulas (χ(X n ), θ(X n , x 1 , x 2 )) that defines, for every graph G in S d k , partial orders on V G that are linear on Adj - G (x) for each x ∈ V G .

Before giving the quite complicated proof, we show that the last two propositions yield the assertions of the Sparseness Theorem (Theorem 9.38) relative to graphs and to binary relational structures, that we restate as follows.

Theorem 9.44 The mapping Inc is a domain-extending MS-transduction on the classes US k (R), for every k > 0 and every binary relational signature R, and on the classes of simple, directed or undirected, uniformly k-sparse (K, Λ)labelled graphs, for every k > 0 and every pair (K, Λ) of finite sets of labels.

Proof: The special case of undirected graphs. For making the proof more readable, we first prove that Inc is a domain-extending MS-transduction on the class US k . Thus, we have to construct a domain-extending MS-transduction τ that transforms each uniformly k-sparse graph G in S u into Inc(G) (more precisely, into a graph isomorphic to Inc(G)). By Propositions 9.42(1) and 9.43 there exists a domain-preserving MS-transduction τ 1 that transforms G into one or more structures V H , edg H , ≤ such that H ∈ S d k is an orientation of G and ≤ is a partial order on V H (= V G ) that is linear on each set Adj - H (x). Its parameters are the set variables of the involved formulas χ and θ, where those of Proposition 9.43 must be taken disjoint from those of Proposition 9.42 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. It remains to construct a parameterless domain-extending MS-transduction τ 2 that transforms this structure into Inc(G) = V G ∪ E G , in G . Then we can define the parameter-invariant MS-transduction τ to be τ 1 • τ 2 by Theorem 7.14 (on the composition of MS-transductions).

For each x ∈ V H , we enumerate Adj - H (x) as {p 1 (x), p 2 (x), . . . , p l (x)} with l ≤ k and p 1 (x) < p 2 (x) < • • • < p l (x). An edge p i (x) → H x (which is the edge between x and p i (x) in E G ) is then defined in Inc(G) as the pair (x, i).

For a unary relation R in R 1 , we need only make sure that R U ((x, 0)) holds if and only if R S (x) holds.

It is easy to write the relation formulas that define in 1 and in 2 . Note that The case of labelled graphs.

For directed (K, Λ)-labelled graphs, we can use the construction of the previous case with Λ in place of R 2 and K in place of R 1 . For undirected (K, Λ)labelled graphs, the construction is essentially the same except that we need only use [k + 1] instead of [2k + 1]. We omit the easy details.

The proof of Proposition 9.43, which will be given after Proposition 9.54, will use a number of definitions and results of independent interest.

In what follows we will not distinguish between a simple directed labelled graph G and the corresponding structure G . In particular, for an arbitrary labelled graph G, we will not distinguish between the graph Inc(G) and the structure G . Definition 9.45 (Normal and spanning forests) Let F 0 be a forest and R be a subset of V F0 that consists of one vertex from each connected component of F 0 . By Definition 2.13, F := (F 0 , R) is a rooted forest. The corresponding descendant relation is a partial order denoted by ≤ F ; its set of maximal elements is R, also denoted by roots F .

If furthermore F 0 is a subgraph of an undirected graph G, we say that F is a rooted forest in G. Such a forest is spanning if V F0 = V G . It is normal13 (without being necessarily spanning) if every two vertices of F that are adjacent in G are comparable with respect to ≤ F . If F is normal and spanning, then we let G(F ) be the orientation of G defined as follows: an edge linking x and y = x is directed from x to y if y < F x and from y to x if x < F y.

Proposition 9.46 The transduction und -1 : M u → M d is an MS 2,2 -transduction, and so is the transduction und -1 ∩ (M u × A d ) that defines the acyclic orientations of every graph in M u . 14 G by an MS-transduction: it uses a copy, say (x, 2), of such a vertex x as the element of Inc(H) representing the edge e x of H linking u and v. By Proposition 9.46, an MS-transduction can define from Inc(H) all (incidence graphs of) acyclic orientations of H. This can also be done by an MS-transduction taking G as input. The reflexive and transitive closure of each acyclic orientation (of H) yields an appropriate partial order on V G .

The following notion of (undirected) hypergraph will be used as a technical tool 15 . In such a hypergraph, a hyperedge is a nonempty set of vertices. The main application in this section will be to the hypergraph associated with a graph G in S d * : each nonempty set Adj - G (x), for x ∈ V G , is defined to be a hyperedge. In Definitions 9.53 and 9.57 below, we will define orientations of hypergraphs.

Definition 9.48 (Hypergraphs and forests in hypergraphs) (a) A hypergraph is a triple H = V H , E H , vert H such that V H ∩E H = ∅ and vert H (e) is a nonempty subset of V H for each e in E H . The elements of E H are the hyperedges of H. Those of V H (respectively of vert H (e)) are the vertices of H (respectively of e). The rank of a hyperedge e is the integer |vert H (e)|. The maximal rank of H (respectively its minimal rank ) is the maximal (respectively the minimal) rank of its hyperedges. We denote by H m the set of hypergraphs of maximal rank at most m. An m-hypergraph is a hypergraph with all hyperedges of rank m. We say that H is simple if vert H (e) = vert H (e ) for e = e .

The incidence graph of H is the simple directed bipartite graph Inc(H) := V H ∪ E H , in H such that in H := {(e, v) ∈ E H × V H | v ∈ vert H (e)}. We will use it as a relational structure for representing H faithfully. This representation allows quantifications over sets of hyperedges (viewed as a structure it would be natural to denote it by H ).

The following alternative, weaker representation, does not. For each positive integer m, we let edg m be an m-ary relation symbol. If H has maximal rank m, we define H := V H , edg 1 H , . . . , edg m H where edg p H := {(x 1 , . . . , x p ) | vert H (e) = {x 1 , . . . , x p } for some e ∈ E H of rank p} for each p. This definition yields a faithful representation of the simple hypergraphs of maximal rank m.

(b) Let H be a hypergraph of minimal rank at least 2. A forest in H, or an H-forest, is a rooted forest F defined as a triple N F , son F , roots F (where N F is its set of nodes and roots F its set of roots) such that: This sequence of H-forests has length at most |E H | by (2) and we take its last element as the result of the construction. Note that the maximal branch of F i is the path in F i from a root to e i . We now describe the construction of the sequence (F i ) i≥1 . We define e 1 as any hyperedge and we let F 1 consist only of it. Assuming F 1 , . . . , F i already constructed, we define F i+1 as follows.

Case 1: There exists e ∈ E H -N Fi such that |vert H (e) ∩ V (F i )| = 1. We let j ≤ i be the largest index such that |vert H (e)∩V (F i )| = |vert H (e)∩V (F i , e j )| = 1 for some e ∈ E H -N Fi , we let e i+1 be one of these hyperedges e and we define a forest F i+1 extending F i by letting N Fi+1 be N Fi ∪ {e i+1 } and e i+1 a son of e j . In this case, we let roots Fi+1 := roots Fi .

Case 2: There is no hyperedge e satisfying Case 1 and there exists e ∈ E H -N Fi such that vert H (e) ∩ V (F i ) = ∅. We take any of these hyperedges e as hyperedge e i+1 and we define F i+1 by letting N Fi+1 := N Fi ∪ {e i+1 } and roots Fi+1 := roots Fi ∪ {e i+1 }.

Case 3: Cases 1 and 2 are not applicable. This case terminates the construction. We return F i as the desired forest F .

As an example, Figure 9.1 shows a hypergraph with hyperedges all of rank 3 (they are drawn as triangles). The algorithm constructs a normal and spanning forest F = F 11 with N F = {1, 2, . . . , 11} (where e i is denoted by i). It has roots 1 and 11, and directed Going back to the general case, it is clear that each F i is an H-forest, and that the last one, say F m , is spanning (otherwise, F m could be extended by an application of Case 1 or 2). We denote by Touch(F i ) the set of hyperedges e of H not in N Fi such that |vert H (e) ∩ V (F i )| = 1. We now prove that each forest of the sequence is normal.

Claim 9.49.1 For every i ≥ 1:

(a) (e 1 , . . . , e i ) is depth-first in F i ;

(b) F i is a normal H-forest;

(c) if e ∈ Touch(F i ), then the vertex in vert H (e) ∩ V (F i ) belongs to V (F i , f ) for some hyperedge f on the maximal branch of F i .

Proof: We use induction on i. Properties (a), (b) and (c) are trivially true for F 1 .

We first assume that F i+1 is constructed by Case 1. We let e i+1 and e j be as in the description of Case 1.

Property (c) that holds for F i implies that e j is on the maximal branch of F i , and this implies Property (a) for F i+1 .

We now prove that F i+1 is normal, i.e., satisfies Property (b). Let e in E H be such that |vert H (e) ∩ V (F i+1 )| ≥ 2. If two vertices of vert H (e) belong to V (F i ), then the conclusion holds because, by the induction hypothesis, F i is normal. If e has only one vertex in V (F i ), say y, then it has another one, say x, in vert H (e i+1 ) -V (F i ); by Property (c) for F i , y ∈ V (F i , f ) for some f on its maximal branch, and f is above e j by the choice of j, and thus x Fi+1 y.

Otherwise, e has two vertices x, y in vert H (e i+1 ) -V (F i ) and x ≡ Fi+1 y. This completes the proof that F i+1 satisfies Property (b).

It remains to prove that F i+1 satisfies Property (c). Let e ∈ Touch(F i+1 ). If the vertex in vert H (e) ∩ V (F i+1 ) belongs to V (F i ), then, as above, by Property (c) for F i , this vertex is in V (F i , f ) for some f on its maximal branch, and f is above e j . Hence, f is on the maximal branch of F i+1 . Otherwise, it belongs to vert H (e i+1 ) -V (F i ), and we have the desired conclusion because e i+1 is on the maximal branch of F i+1 .

This completes the proof when F i+1 is constructed by Case 1.

We now consider F i+1 constructed by Case 2. Property (a) is clearly true from the definitions. The proof of Property (b) is the same as for Case 1, except that the hyperedge e cannot have only one vertex in V (F i ), because otherwise Case 2 would not have been applicable for defining F i+1 . Property (c) is also clear because Touch(F i ) is empty: if e ∈ Touch(F i+1 ), the vertex in vert H (e) ∩ V (F i+1 ) belongs to vert H (e i+1 ), and e i+1 is on the maximal branch of F i+1 .

This completes the proof of the claim.

Thus F m , the last forest of the sequence, is normal by Property (b) of the claim, and the proof of the lemma is complete.

We now prove that the notion of a normal and spanning H-forest can be formalized in monadic second-order logic. If H is a hypergraph, we say that X ⊆ E H is connected if the graph G(X) with vertex set X and edge set {(e, e ) | vert H (e) ∩ vert H (e ) = ∅} is connected.

With this notion, we can characterize certain paths in an H-forest F . For e ∈ N F , the nodes of the unique path in F from a root to e form the set P (e) ⊆ N F characterized as follows:

P (e) is the minimal connected subset of E H that contains e and some root, where minimality is understood with respect to set inclusion. 19 By using these paths, we can characterize the partial order ≤ F by: e ≤ F e if and only if P (e ) ⊆ P (e).

From these observations, the formula θ is easy to construct. We can use it to construct similar formulas that express that e is a son of e in F , that x ∈ V (F, e) and that x F y for x, y ∈ V H . Note that e is a son of e in F if and only if e < F e and vert H (e) ∩ vert H (e ) = ∅.

Using these formulas it is also easy to write the formula χ. A splitting (H 1 , H 2 ) of H will be represented by the relational structure S := V H ∪ E H , in 1 S , in 2 S such that in i S := {(e, v) | e ∈ E Hi , v ∈ vert Hi (e)}. We denote it by S(H 1 , H 2 ) if we need to refer to H 1 and H 2 . Note that the domain of S is that of Inc(H) and that in 1 S and in 2 S form a partition of in H . We have Inc(H i ) = V H ∪ E i , in i S where E i := {e ∈ E H | in i S (e, u) for some u ∈ V H }. Hence Inc(H 1 ) and Inc(H 2 ) can be obtained from S(H 1 , H 2 ) by FO-transductions. 19 Clearly, P (e) is connected by Definition 9.48(b)(ii). If X is a connected subset of E H that contains e and some root r, then there is a path π in G(X) from r to e. By Definition 9.48(b)(iii), the path π can contain nodes of F that are not in P (e). If f is such a node, then π has a subpath of the form h 1 -h 2 -• • • -f -• • • -hq such that h 1 and hq are in P (e) and h 2 , . . . , f, . . . , hq are sons of h 1 that, except hq, are not in P (e). All nodes of P (e) are on the path π, hence in X.

Let C be a set of hypergraphs. A triple of MS formulas (χ(X n ), θ 1 (X n , x 1 , x 2 ), θ 2 (X n , x 1 , x 2 )), over the relational signature {in}, defines splittings of every hypergraph in C if, for every hypergraph H in C, Inc(H) |= (∃X 1 , . . . , X n . χ) ∧ ∀X 1 , . . . , X n (χ ⇒ θ), where θ is the formula with free variables in X n defined as: ∀y, x[in(y, x) ⇔ (θ 1 (y, x) ∨ θ 2 (y, x))] ∧ ∀y, x. ¬(θ 1 (y, x) ∧ θ 2 (y, x)).

These conditions mean that for every tuple (U 1 , . . . , U n ) of subsets of V H ∪ E H satisfying χ in Inc(H), if W i := {(u, v) | u, v ∈ V H ∪ E H , Inc(H) |= θ i (U 1 , . . . , U n , u, v)}, then the structure V H ∪E H , W 1 , W 2 represents a splitting of H. Furthermore, for each hypergraph H in C there is such an n-tuple.

Equivalently, they mean that the domain-preserving MS-transduction with definition scheme χ, True, θ 1 , θ 2 associates with every incidence graph Inc(H), where H is a hypergraph in C, one or more structures S(H 1 , H 2 ) representing some of its splittings.

Recall that H m denotes the set of hypergraphs of maximal rank at most m. Lemma 9.52 For each m ≥ 2, there exists a triple of MS formulas (χ(X m+2 ), θ 1 (X m+2 , x 1 , x 2 ), θ 2 (X m+2 , x 1 , x 2 )) that defines splittings of every hypergraph in H m into pairs of hypergraphs in H m-1 .

Proof: We have to show that there is a domain-preserving MS-transduction that associates with Inc(H), for every hypergraph H of maximal rank at most m, one or more structures S(H 1 , H 2 ) representing splittings of H into hypergraphs H 1 , H 2 of maximal rank at most m -1.

Let H be of maximal rank at most m. We will put in H 1 all hyperedges of rank 1. We continue the construction for H obtained from H by deleting the hyperedges of rank 1.

Let F be a normal and spanning H -forest (Lemma 9.49) and let U = (U 1 , . . . , U m ) be a partition of V (F ) such that for every e ∈ N F , distinct vertices of V (F, e) belong to distinct sets U i . We refine the quasi-order F on the set V (F ) defined in Definition 9.48(c) into the partial order F,U defined as follows:

x F,U y if and only if, either x ≺ F y or, x ≡ F y and x ∈ U i , y ∈ U j with i ≤ j.

For every e ∈ E H , we let Min(e) be the set of minimal elements of vert H (e) ∩ V (F ) with respect to F,U ; this set is not empty since vert H (e) ∩ V (F ) = ∅ (because F is spanning). To complete the proof of the lemma, we construct a domain-preserving MStransduction that has a definition scheme D := χ, True, θ 1 , θ 2 with parameters X 1 , . . . , X m+2 . The formulas of D are constructed using the pair of formulas of Proposition 9.50. The precondition χ expresses that these parameters are intended to take values as follows, for input Inc(H):

X 1 , X 2 will determine a normal and spanning H -forest F such that N F is the value of X 1 and roots F is the value of X 2 , X 3 , . . . , X m+2 will define a partition U associated with F as described above.

The partial order F,U can be expressed by an MS formula α(X m+2 , x, y) from which we can build a formula α (X m+2 , e, x) expressing, for F, U defined by X 1 , . . . , X m+2 , that e ∈ E H and x ∈ Min(e). One obtains in this way a splitting (H 1 , H 2 ) of H such that E H 1 = E H2 = E H and, for e ∈ E H : vert H 1 (e) := Min(e) and vert H2 (e) := vert H (e) -Min(e).

We turn it into a splitting (H 1 , H 2 ) of H such that H 1 is obtained by adding to We define the MS formulas θ 1 and θ 2 with free variables in X m+2 ∪ {x 1 , x 2 } as follows: θ 1 is α (X m+2 , x 1 , x 2 ) ∨ ∀y(in(x 1 , y) ⇔ y = x 2 ), and θ 2 is in(x 1 , x 2 ) ∧ ¬θ 1 .

These formulas define respectively the relations in 1 S and in 2 S of S := S(H 1 , H 2 ). Hence, we have an MS-transduction transforming Inc(H) into one or more structures S(H 1 , H 2 ) as desired.

An undirected graph is a hypergraph of maximal rank at most 2. Splitting it is nothing but choosing an orientation for each of its edges that are not loops. The construction of Lemma 9.52 is thus a generalization of the construction of the transduction α in the proof of Proposition 9.46. Definition 9.53 (Orientations of hypergraphs) Let H = V H , E H , vert H be a hypergraph. An orientation of H is a pair (H, ≤) where ≤ is a mapping that associates with every e in E H a linear order ≤ e on its set of vertices vert H (e). If H is an orientation of H, we let H be the binary relation on V H defined as the reflexive and transitive closure of the union of the relations ≤ e for all e ∈ E H . We say that H is acyclic if H is antisymmetric, i.e., if it is a partial order. This is equivalent to requiring that the linear orders ≤ e have a common linear extension, and also, to the acyclicity of the directed loop-free graph G such that V G = V H and edg G = {(x, y) | x < e y for some e in E H }.

An As for splittings, we define how orientations can be determined by formulas. A pair of MS formulas (µ(X n ), ϕ(X n , x 1 , x 2 , x 3 )), over the relational signature {in}, defines orientations of every hypergraph in a set C if, for every hypergraph H ∈ C:

Inc(H) |= (∃X 1 , . . . , X n . µ) ∧ ∀X 1 , . . . , X n (χ ⇒ ϕ),

where ϕ is the formula with free variables in X n defined as: ∀e, x. ϕ(e, x, x) ∧ ∀e, x, y(ϕ(e, x, y) ∧ ϕ(e, y, x) ⇒ x = y) ∧ ∀e, x, y, z(ϕ(e, x, y) ∧ ϕ(e, y, z) ⇒ ϕ(e, x, z)) ∧ ∀e, x, y [(in(e, x) ∧ in(e, y)) ⇔ (ϕ(e, x, y) ∨ ϕ(e, y, x))]. This means that, for every n-tuple (U 1 , . . . , U n ) of subsets of V H ∪E H satisfying µ in Inc(H), if W := {(e, u, v) | e, u, v ∈ V H ∪E H , Inc(H) |= ϕ(U 1 , . . . , U n , e, u, v)} then the structure V H ∪ E H , W represents an orientation of H, and that there is at least one such n-tuple in Inc(H). Equivalently, it means that the domainpreserving MS-transduction with definition scheme µ, True, ϕ associates with every incidence graph Inc(H), where H is a hypergraph in C, one or more incidence structures Inc(H) representing some orientations H of H.

We will also consider similar formulas that define all orientations of H in C, and all its acyclic orientations.

20 For an undirected graph H, which is a hypergraph of maximal rank at most 2, the notion of an orientation H and its incidence graph Inc(H) were defined earlier, in a slightly different way. It should however be clear that this difference can be disregarded: structures V ∪ E, in 1 , in 2 and V ∪ E, order such that order = {(e, x, y) | (e, x) ∈ in 1 , (e, y) ∈ in 2 } and in 1 = {(e, x) | (e, x, y) ∈ order for some y ∈ V } (and similarly for in 2 ), can be transformed into each other by domain-preserving FO-transductions.

The next result generalizes Proposition 9.46. Proposition 9.54 For each integer m ≥ 2:

(1) there exists a pair of MS formulas (µ(X n ), ϕ(X n , x 1 , x 2 , x 3 )) that defines orientations of every hypergraph in H m , i.e., there exists a domain-preserving MS-transduction that defines one or more orientations of every hypergraph of maximal rank at most m, where hypergraphs and their orientations are represented by their incidence structures;21

(2) there exist domain-preserving MS-transductions that define all orientations and all acyclic orientations of every hypergraph of maximal rank at most m, where again, hypergraphs and their orientations are represented by their incidence structures.

Proof: [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] The construction is by induction on m. Since H 2 is the set of undirected graphs, the case m = 2 follows easily from Proposition 9.46. The corresponding formulas use two set variables. For m > 2, we will construct (µ(X n ), ϕ(X n , x 1 , x 2 , x 3 )) by using the corresponding pair of formulas for the case m -1.

We first give the idea. Let H belong to H m , and be given by its incidence graph Inc(H). By Lemma 9.52, a structure S(H 1 , H 2 ) representing a splitting (H 1 , H 2 ) of H with H 1 and H 2 in H m-1 , is defined by monadic second-order formulas using an (m + 2)-tuple U of parameters. We can use on Inc(H 1 ) and Inc(H 2 ) (definable in S := S(H 1 , H 2 ) by first-order formulas) the formulas µ , ϕ obtained by induction, that define orientations of H 1 and H 2 . By combining these orientations, which we define below by the local linear orders ≤ 1,e and ≤ 2,e , we can define an orientation of H as follows. For e ∈ E H and x, y ∈ vert H (e), we let:

x ≤ e y if and only if either x, y ∈ vert H1 (e) and x ≤ 1,e y in H 1 or x, y ∈ vert H2 (e) and x ≤ 2,e y in H 2 or

x ∈ vert H1 (e) and y ∈ vert H2 (e).

We now explain how X , µ and ϕ can be constructed. We will use pairwise disjoint tuples U, Y and Z of set variables (parameters). We let τ be the domain-preserving MS-transduction with definition scheme χ, True, θ 1 , θ 2 , where the triple (χ(U), θ 1 (U, x 1 , x 2 ), θ 2 (U, x 1 , x 2 )) defines splittings S(H 1 , H 2 ) of every hypergraph H in H m by Lemma 9.52. For i = 1, 2 we denote by τ i the composition of τ with the parameterless noncopying FO-transduction that transforms S(H 1 , H 2 ) into H i .

We let (µ (Y), ϕ (Y, x 1 , x 2 , x 3 )) be a pair of formulas that defines orientations of every hypergraph in H m-1 ; such formulas do exist by the induction hypothesis. We let µ 1 and ϕ 1 be the backwards translations of µ and ϕ relative to τ 1 , cf. Section 7.1.4; they define an orientation of H 1 . We let Z be a on V G that induces an orientation H of the corresponding hypergraph H, and we recall that V H = V G . Hence, this partial order is linear on each set Adj - G (x) by the definition of H.

The proof of Proposition 9.43 is now complete, and thus Theorem 9.44 (the Sparseness Theorem for graphs and binary structures) is also proved.

Example 9.55 Here is a set C of simple directed graphs that is not uniformly k-sparse for any k, but on which the mapping Inc is an FO-transduction. 22For each n ≥ 1, we let G n be the graph with vertex set consisting of the elements of [n] and of its subsets of cardinality 2. Its edges are i → j, i → {i, j} and j → {i, j} for 1 ≤ i < j ≤ n. These graphs are 3-sparse, but not uniformly k-sparse because the subgraphs of G n induced by [n] are not. It is easy to see that Inc is a domain-extending 4-copying FO-transduction on the class C := {G n | n ≥ 1}: a vertex x is represented by (x, 1), an edge i → j by ({i, j}, 2), an edge i → {i, j} by ({i, j}, 3) and an edge j → {i, j} by ({i, j}, 4), where in all these cases i < j.

In the next section, we will extend Theorem 9.44 to relational structures that are not binary, in order to prove the Sparseness Theorem (Theorems 9. 37 and 9.38). Before doing so, we apply some techniques developed in this section to the definition of optimal tree-decompositions of chordal graphs by MStransductions.

We recall from Example 5.2(4) that every graph G has tree-decompositions (T, f ), and even optimal ones, such that N T = V G . In such a case, the relational structure S 1 (G, T, f ) := V G , edg G , son T , box f represents simultaneously G and (T, f ) (with (u, x) ∈ box f if and only if x ∈ f (u)). We have observed that, in some cases, we can even omit the relation box f and use S 2 (G, T, f ) := V G , edg G , son T because box f (i.e., the mapping f ) can be determined from edg G and son T by a monadic second-order formula. This is the case if (T, f ) is a normal tree-decomposition (cf. Example 2.56(6)). We now show that optimal normal tree-decompositions of a chordal graph G can be defined by an MS-transduction that takes G as input, as already discussed in Example 5.18 (with a slightly different proof). For k-chordal graphs, G can be taken as input.

Proposition 9.56

(1) There exists an MS-transduction that associates with Inc(G), for every chordal graph G, one or more structures of the form S 1 (G, T, f ) such that (T, f ) is a normal tree-decomposition of G that is optimal.

(2) For each k ≥ 2, there exists an MS-transduction that associates with every k-chordal graph G one or more structures of the form S 1 (G, T, f ) such that (T, f ) is a normal tree-decomposition of G that is optimal.

Proof: (1) We recall from Proposition 2.72 that a nonempty, connected, simple, loop-free and undirected graph G is chordal if and only if it has a simplicial orientation, i.e., an acyclic orientation H such that for every vertex u, the set Adj - H (u) is a clique in G. According to the proof of (3) =⇒ (4) of Proposition 2.72, from such an orientation H, the binary relation on V H = V G defined as:

{(w, u) ∈ edg H | there is no directed path in H of length at least 2 from w to u}, is son T for some rooted tree T that is a normal spanning tree of H and also of G. Following the proof of ( 4) =⇒ (1) of Proposition 2.72, we define also, for every u ∈ N T = V G :

f (u) := {u} ∪ {w ∈ V G | (u, w) ∈ edg G and (w, u) ∈ son * T },
and we obtain a normal tree-decomposition of G that is optimal because every box is a clique. We let S 1 (G, T, f ) be the corresponding relational structure (it depends on the orientation H of G). By Proposition 9.46 there exists an MS-transduction τ that associates with Inc(G), for every undirected graph G, all its orientations. That an orientation H is simplicial is MS-expressible. Hence, by the Restriction Theorem (Theorem 7.16), there exists an MS-transduction τ that constructs (from Inc(G)) the simplicial orientations of G, whenever there exist some, which is the case if G is chordal. From a simplicial orientation of G, the relations son T and box f are definable by monadic second-order formulas: this is clear from their definitions above. We get in this way the desired transduction.

(2) The transduction τ defined above in (1) takes as input Inc(G), and not G itself, in order to be able to specify all orientations of G. If G is k-chordal, its simplicial orientations are of indegree at most k -1 and, by Proposition 9.42(1), they can be specified by an MS-transduction using q(k -1) parameters. This gives the stated result for k-chordal graphs.

Hence optimal tree-decompositions (T, f ) of k-chordal graphs G (for fixed k) can be specified by structures S 1 (G, T, f ) that can be defined "inside" G . As already said in Section 7.6, the extension of this result to graphs of tree-width at most k is an open question. In this section we prove the Sparseness Theorem (Theorem 9.38). A large part of the proof consists in showing that the mapping Inc is a domain-extending MS-transduction on the class US k,m (Theorem 9.61). Before giving an overview of the proof, we need a definition and a proposition. Proof: [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] The "if" part is clear since for every hypergraph H with a semiorientation -→ H , we have:

|E H | = v∈V H indeg-→ H (v).
"Only if". We generalize the proof of this result for the particular case of undirected graphs that is given in [*Fra, Theorem 6.13]. We have already used this case in the proof of Proposition 9.42. We first observe that, by the previous equality, if a hypergraph H is k-sparse and has a semi-orientation -→ H , then v∈V H indeg-→ H (v) ≤ k • |V H |, so that we must have indeg-→ H (w) < k for some w if, for some v, we have indeg-→ H (v) > k. Consider H uniformly k-sparse. Let -→ H = (H, hd ) be any semi-orientation of H. We say that a vertex v is bad if indeg-→ H (v) > k. We let the badness of -→ H be the sum of the indegrees indeg-→ H (v) such that v is bad. We are looking for a semi-orientation of badness 0.

Let the chosen semi-orientation -→ H have positive badness: we will transform it into a semi-orientation (H, hd ) of smaller badness. Let v be a bad vertex. Let X be the set of vertices u such that there is a directed path in Dir ( -→ H ) from u to v. Then, the induced hypergraph H[X] is k-sparse. Note that if hd (e) ∈ X, then vert H (e) ⊆ X, hence the indegree of a vertex in H[X] with respect to the semi-orientation of H[X] induced by hd is the same as its indegree in -→ H . By the initial observation, H[X] has a vertex w such that indeg-→ H (w) < k. Hence, there exists a sequence of hyperedges e 1 , . . . , e n and a directed path in Dir ( -→ H ) of the form (v 0 , v 1 , . . . , v n ) with v 0 = w and v n = v such that hd (e i ) = v i and v i-1 ∈ vert H (e i ) for each i ∈ [n]. Clearly, e 1 , . . . , e n are pairwise distinct, because if e i = e j , then v i = v j . We now define hd on E H from hd as follows:

hd (e i ) := v i-1

for i ∈ [n], hd (e) := hd (e) for e ∈ E H -{e 1 , . . . , e n }.

It is clear that in -→ K := (H, hd ) we have:

indeg-→ K (v) = indeg-→ H (v) -1, indeg-→ K (x) = indeg-→ H (x) for x ∈ V H -{v, w}, indeg-→ K (w) = indeg-→ H (w) + 1 ≤ k.
Hence the badness of -→ K is equal to the badness of -→ H minus 1, or minus (k + 1) if v is no longer bad. By repeating this step one obtains a semi-orientation of H that has badness 0 as desired.

(2) Let H be a hypergraph of maximal rank at most m and -→ H = (H, hd ) be a semi-orientation of H. A vertex v is bad for -→ H (in a different sense as in ( 1)) if v → w and w → v in Dir ( -→ H ) for some w. We assume that in -→ H :

(i) every bad vertex has indegree at most k, (ii) the other vertices have indegree at most mk 2 .

We will modify hd into hd such that (i) and (ii) still hold for -→ K := (H, hd ) and such that -→ K has less bad vertices than -→ H . By repeating this step, starting from a semi-orientation of indegree at most k, we will end up with a semiorientation -→ K of H without bad vertices and with indegree at most mk 2 as desired. It will follow that Dir ( -→ K ) ∈ S d k where k := (m -1)mk 2 . We do that as follows. Let v be a bad vertex. Let e 1 , . . . , e l , where l ≤ k, be the hyperedges e in For a simple m-hypergraph H, we will omit the relations edg Proof: For m = 2, we have the desired transduction by Proposition 9.42(1), and even with k instead of mk 2 . We now consider the general case. As in the proof of Proposition 9.42(1), we will specify the required semi-orientation by a vertex coloring of H. By Proposition 9.58, every hypergraph H in US k,m has a semi-orientation -→ H of indegree at most mk 2 such that D := Dir ( -→ H ) ∈ S d k where k := (m -1)mk 2 . By Proposition 9.40(3), there exists a directed graph Q with no pairs of opposite edges and with vertex set [q] where q := q(k ), such that there is a homomorphism γ : D → Q. Since V D = V H , γ is a mapping from V H to [q]. If x ∈ vert H (e) and y = hd (e) = x, then x → D y and so γ(x) → Q γ(y). Hence, γ is a good coloring, in the following sense. A good coloring of a hypergraph H is a mapping γ : V H → [q] such that: (i) each set vert H (e) contains a (unique) vertex x such that γ(y) → Q γ(x) for every other vertex y of vert H (e), 23 (ii) the semi-orientation -→ H := (H, hd ) where hd (e) is the unique vertex determined by (i), has indegree at most mk 2 .

As in the proof of Proposition 9.42(1), a coloring γ can be described by a partition X 1 , . . . , X q of V H , such that X i = γ -1 (i) for each i. It is straightforward to express Condition (i) by an MS formula with free variables X 1 , . . . , X q . The relation edg m - → H is MS-definable from edg m H and the sets X 1 , . . . , X q , because we have, for all x 1 , . . . , x m in V H , Moreover, it is easy to express by an MS formula that the semi-orientation -→ H represented by V H , edg m - → H has indegree at most mk 2 (using a subformula that expresses that two sets of vertices {x 1 , . . . , x m-1 } and {y 1 , . . . , y m-1 } are distinct). Altogether, it can be expressed by an MS formula that X 1 , . . . , X q is a partition that defines a good coloring, and this formula forms the precondition of the definition scheme of the desired (domain-preserving) monadic second-order transduction, whereas the MS formula for edg m - → H is its relation formula.

To prove the Sparseness Theorem for simple m-hypergraphs, we will have to compose functional transductions that are domain-extending MS-transductions on classes of structures (as defined in Definition 7.2). Thus, we strengthen Theorem 7.14(3) as follows.

Lemma 9.60 Let C 1 ⊆ STR c (R 1 ) and C 2 ⊆ STR c (R 2 ) be classes of structures, let f 1 : STR c (R 1 ) → STR c (R 2 ) be a domain-extending MS-transduction on C 1 such that f 1 (C 1 ) ⊆ C 2 , and let f 2 : STR c (R 2 ) → STR c (R 3 ) be a domainextending MS-transduction on C 2 . Then f 1 • f 2 : STR c (R 1 ) → STR c (R 3 ) is a domain-extending MS-transduction on C 1 .

Proof: Let τ i be a concrete domain-extending k i -copying MS-transduction that realizes f i (as explained in Definition 7.2). We may assume that, in the definition scheme of τ 1 , the domain D S of an input structure S ∈ C 1 is represented by the copy D S ×{1} in every output structure T (i.e., the first domain formula is True and there is an isomorphism from T to f 1 (S) that maps (a, 1) to a for every a in D S ). Similarly, we may assume that in the definition scheme of τ 2 the domain D T of an input structure T ∈ C 2 is represented by the copy D T × {1} in every output structure U , and hence D S is represented by (D S × {1}) × {1} in U . 24 The composition τ 1 • τ 2 is, in general, not a concrete MS-transduction. However, 23 The vertex x is unique because Q has no pairs of opposite edges. 24 Let h 1 be the isomorphism from T to f 1 (S) that maps (a, 1) to a. Similarly, let h 2 be the isomorphism from U to f 2 (T ) that maps (b, 1) to b and in particular ((a, 1), 1) to (a, 1). The isomorphism h 1 can be extended to an isomorphism h 1 from f 2 (T ) to f 2 (f 1 (S)); thus, it also maps (a, 1) to a. Hence, h 2 • h 1 is an isomorphism from U to f 2 (f 1 (S)) that maps ((a, 1), 1) to a. Proof: The proof is by induction on m, simultaneously for all k. The case m = 2 concerns graphs (in S u ) and is stated in Theorem 9.44.

We now consider m ≥ 3. Let s-US k,m be the class of semi-orientations of indegree at most mk 2 of hypergraphs in US k,m . By Proposition 9.59 (and Theorem 7.14) 25 In the proof of Theorem 7.14, the "identification" is denoted θ. It is an isomorphism from U to the corresponding structure θ(U ) and it maps ((a, 1), 1) to (a, 1). Then τ 1 • τ 2 • θ is a concrete MS-transduction that transforms S into θ(U ), and θ -1 • h 2 • h 1 is an isomorphism from θ(U ) to f 2 (f 1 (S)) that maps (a, 1) to a. So,

V ∂( - → H ) := E D = edg D ⊆ V H × V H , E ∂( -
τ 1 • τ 2 • θ realizes f 1 • f 2 .
τ i is (1 + k i )-copying, then τ is (1 + k 1 + • • • + k p )-copying.
We now consider a structure S in US k ({R}) such that R is n-ary. For convenience, we will identify each tuple (R, x 1 , . . . , x n ) in T S with the corresponding tuple ( x We now show that the structure S + Inc(H) can be transformed into a structure U isomorphic to Inc(S) = D S ∪ T S , in 1 Inc(S) , . . . , in n Inc(S) by an m n -copying MS-transduction µ 2 that "preserves" the elements of D S . We define U with domain included in (D S × {0}) ∪ (E H × [m] [n] ) where [m] [n] is the set of all mappings : [n] → [m]. The set (D S × {0}) is the copy of D S in U , and T S is defined as a subset of E H × [m] [n] .

By applying Proposition 9.43 to the directed graph D S ∪ E H , in -1

H

(which is in S d m ), we obtain a pair of MS formulas (χ(X ν ), θ(X ν , x 1 , x 2 )) that defines a partial order ≤ on D S ∪ E H that is linear on each set vert H (e), for e ∈ E H . The MS-transduction µ 2 has the set of parameters X ν and the precondition χ. It uses the formula θ, i.e., the partial order ≤, in its domain and relation formulas. For (e, π) ∈ E H × [m] [n] and i ∈ [n], we let π i (e) denote the π(i)-th element of the set vert H (e) with respect to ≤. The domain formulas of µ 2 define T S as the set of pairs (e, π) such that (π 1 (e), . . . , π n (e)) ∈ R S , and its relation formulas define in i Inc(S) , for i ∈ [n], as the set of all pairs ((e, π), (x, 0)) such (5) follows from the Reduction Theorem (Theorem 7.54, in Section 7.5). The second part follows from Theorem 7.55 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF].

We have some similar statements with the same proofs 27 for relational structures. Note that Assertion (2) is Theorem 9.37.

Theorem 3.7 of [FisMak] claims without proof and erroneously that a set of relational structures of bounded tree-width has bounded relational width, cf. Proposition 9.27. The proof of this proposition simplifies the proof of the same result given in Theorem 7.5 of [CouER]. We use a method from [AdlAdl] where a similar statement is proved. The proof of Proposition 9.28 is due to [AdlAdl].

Orientations defined by monadic second-order formulas have been studied in [START_REF] Courcelle | The monadic second-order logic of graphs VIII: Orientations[END_REF]. The main result of Section 9.4 is based on [START_REF] Courcelle | The monadic second-order logic of graphs XIV: Uniformly sparse graphs and edge set quantifications[END_REF], where Theorem 9.37 is stated for graphs and relational structures that are countable. However the proof of Theorem 1.4 in [START_REF] Courcelle | The monadic second-order logic of graphs XIV: Uniformly sparse graphs and edge set quantifications[END_REF] is incorrect. The error has been noted by Blumensath who gives a correct proof (with a different construction) for infinite relational structures of all cardinalities in [START_REF] Blumensath | Guarded second-order logic, spanning trees, and network flows[END_REF].

Conclusion and open problems

We will leave to the researchers of the next ten years and more to decide which of the results presented in this book are the most important ones. Here we will only indicate, what are, in our opinion, the main open problems and research directions, among those that are closely related with the topics of this book.

Algorithmic Applications

This topic, studied in Chapter 6, is the most difficult to discuss because of the large number of new articles published every year. Hence, the following comments have good chance to become obsolete rapidly.

The algorithmic consequences of the Recognizability Theorem depend crucially on algorithms that construct graph decompositions of the relevant types or, equivalently, that construct terms over the signatures F HR , F VR which evaluate to the input graphs or relational structures. The efficiency of such algorithms, either for all graphs, but perhaps more promisingly for particular classes of graphs, is a bottleneck for applications.

Another difficulty is due to the sizes of the automata that result from the "compilation" of monadic second-order formulas. Their "cosmological" sizes (cf. [START_REF] Frick | The complexity of first-order and monadic second-order logic revisited[END_REF][START_REF] Stockmeyer | Cosmological lower bound on the circuit complexity of a small problem in logic[END_REF][START_REF] Weyer | Decidability of S1S and S2S, Automata, Logics, and Infinite Games[END_REF]) make their constructions intractable for general formulas. However, for certain formulas arising from concrete problems of hardware and software verification they remain manageable, as reported by Klarlund and his group who have developed a software for that called MONA (cf. [Hen+, BasKla]). Using MONA for graphs of bounded tree-width and clique-width has been tried by Soguet [Sog], but even for basic graph properties like connectivity or 3-colorability, the automata are too large to be constructed as soon as one wishes to handle graphs of clique-width more than 3. A more promising perspective presented in [START_REF] Courcelle | Automata for the verification of monadic second-order graph properties[END_REF] consists in using "fly-automata", i.e., finite deterministic automata whose transitions are defined by programs and not stored in fixed (huge) tables. Hence, an automaton with, say, 2 100 transition rules specified as a "fly-automaton" will not be computed: for checking a term of size 1000, only the necessary 1000 transitions will be computed. More experiments must be done to verify whether this idea is usable for significant 687 graph properties and for graphs of not too small tree-width or clique-width.

The Recognizability Theorem entails that every MS-expressible graph problem is solvable in polynomial time on graphs of clique-width at most k for each fixed k, more precisely, by a fixed-parameter cubic algorithm. However some problems that are not expressible by MS-formulas also have polynomial algorithms on the same graphs (see [Wan]). The corresponding algorithms are not fixed-parameter tractable with respect to clique-width. The question is: Does there exist a common logical description for such problems?

Fixed-parameter tractable algorithms for first-order model-checking problems on certain classes of graphs of unbounded tree-width have been constructed: see Grohe's survey [*Gro]. 28 The graphs of these classes can be covered by sets of induced subgraphs of bounded tree-width satisfying certain overlapping constraints. These results use, among other tools, the Recognizability Theorem, applied to monadic second-order formulas that are derived from the first-order formula of interest.

Can one give a kind of algebraic and/or logical description of these graph classes? Can one extend the results surveyed in [*Gro] to fragments of monadic second-order logic that are more expressive than first-order logic?

Algorithms for enumeration problems and constructions of labelling schemes that answer monadic second-order queries have been briefly cited in Section 6.4.4. Several of these algorithms are based on the Recognizability Theorem.

Can one extend them to these classes of graphs and to first-order formulas?

Such an extension is developed in [CouGK] for labelling schemes intended to solve certain first-order queries.

Algebraic descriptions of graphs and relational structures

Two graph algebras have been studied in Chapter 2. The axiomatization of their equational properties leaves, for both of them, open questions presented in Sections 2.3.3 and 2.5.3. More important problems are left open for the algebra of relational structures studied in Chapters 5 and 9. The main one is certainly the parsing problem (see Section 9.3.1, Conjecture 9.23), because it is a bottleneck for the construction of fixed-parameter tractable model-checking algorithms for monadic second-order sentences on relational structures.

These algebras yield straightforward extensions to sets of graphs and relational structures of basic notions of Formal Language Theory: context-free and recognizable languages. These extensions are based on equation systems having least solutions and on finite congruences. A lot of work has also been done on graph and hypergraph grammars, that do not always yield equational sets, at least with respect to the algebras of Chapter 2 (see [*Roz, *Eng97]; cf. the last sections of Chapters 1, 2 and 4). These works leave open many questions.

The operations of the algebras of graphs and relational structures GP, JS and STR have been selected because of their good "compatibility" with monadic second-order logic: the Recognizability Theorems (Theorems 5.68 and 5.75) witness this "compatibility". However, the operation of unfolding that transforms a directed graph into a finite or infinite tree is also, in a certain sense, "compatible" with monadic second-order logic (as discussed in Section 7.7). It yields concise descriptions of finite graphs (and also of countable graphs). Can one integrate it as an operation into the present algebraic and logical framework? (It is already widely used for describing countable graphs, see the survey [*BluCL]).

Another question, discussed in Section 9.3.4, is the definition of a "width" parameter for relational structures. The one of Definition 9.33 generalizes cliquewidth and is robust with respect to monadic second-order transductions (the property of having bounded width for a set of R-structures is preserved under monadic second-order transductions) but one more property would be desirable: that the set of R-structures of width at most k be CMS-definable for every R and k.

We recall that tree-width and path-width satisfy such a property, by the excluded minor characterizations of TWD(≤ k) and PWD(≤ k). We have no monadic second-order characterization of the class CWD(≤ k) (as observed in Footnote 28 just before Corollary 5.12). However, the equivalent notion of rankwidth (defined in Section 6.2.3, Definition 6.6) enjoys such a property: the class of simple loop-free undirected graphs of rank-width at most k is characterized by finitely many excluded vertex-minors [START_REF] Oum | Rank-width and vertex-minors[END_REF], which yields, by the results of [CouOum], the C 2 MS-definability of this class.

Graph structure and logic

Many constructions of monadic second-order formulas use graph theoretical properties. The paradigmatic example is the characterization of planar graphs by excluded minors (cf. Chapters 1 and 5) from which a monadic second-order sentence characterizing them can be constructed. The same holds for graphs of tree-width or path-width bounded by a given integer. Other types of excluded configurations are also useful, for example the vertex-minors mentioned above, essential for the proof of Theorem 7.55(2). This notion is not presented in this (already thick) book: see [START_REF] Oum | Rank-width and vertex-minors[END_REF] for its relation with rank-width and [CouOum] for its logical expression. It yields a monadic second-order characterization of circle graphs, cf. [START_REF] Courcelle | Circle graphs and monadic second-order logic[END_REF].

Many important graph classes are characterized by excluded induced subgraphs. In most cases (cographs are an exception), the excluded induced subgraphs form infinite families. We have seen that for chordal graphs (Proposition 2.72). If such a family is monadic second-order definable, then the class of graphs that it characterizes is also monadic second-order definable. This is the case for interval graphs and comparability graphs, cf. [START_REF] Courcelle | The monadic second-order logic of graphs XV: On a conjecture by D. Seese[END_REF]. The infinite sets of forbidden induced subgraphs that characterize these two classes are VR-equational. Is there a general theorem behind this observation?

Colorability results are also crucial in the proof of the Sparseness Theorem in Section 9.4 about the elimination of edge set quantifications in the monadic second-order expression of graph properties. Hence, deep results of graph theory are useful for constructions of monadic second-order formulas. For example the Strong Perfect Graph Theorem ([*ChuRST]) entails a monadic second-order expression of perfectness, cf. Example 6.43(3).

In the other direction, certain graph theoretical notions like the decomposition of a graph in 3-blocks, its modular and its split decompositions can be expressed by monadic second-order transductions (cf. [START_REF] Courcelle | The monadic second-order logic of graphs X: Linear orderings[END_REF][START_REF] Courcelle | The monadic second-order logic of graphs XVI: Canonical graph decompositions[END_REF]). Lacking of time, we could not cover this aspect, but we wish to do so in a future edition of this book.

These various interactions between logic (especially monadic second-order logic) and graph theory deserve further investigations29 . Expressing graph properties in monadic second-order logic is useful in view of algorithmic applications but also raises interesting graph theoretical questions. Particular types of graph decompositions have been defined for proving results like the Strong Perfect Graph Theorem [*ChuRST] and to describe the structure of the graphs that exclude a fixed graph as a minor (e.g., clique-sum decompositions, see the surveys [*KawMoh] and [*Gro]). How do they fit with monadic second-order logic?

The well-studied notion of tree-decomposition yields a fascinating question, raised in [START_REF] Courcelle | The monadic second-order logic of graphs V: On closing the gap between definability and recognizability[END_REF] and discussed in Section 7.6 (and in Proposition 9.56): Does there exist, for each k, a function f and a monadic second-order transduction that defines, for every graph of tree-width at most k, a tree-decomposition of this graph of width at most f (k)?

A positive answer would characterize the recognizable sets of graphs of bounded tree-width as those that are CMS 2 -definable (and of bounded tree-width), see Conjecture 7.62. A negative answer to this conjecture would also be interesting: it would show the existence of model-checking problems that are not monadic second-order expressible but that can be solved by means of finite automata on terms, hence that are fixed-parameter linear with respect to tree-width.

Decidability questions

Among the questions discussed in Section 7.5, the following one (Question 7.56) raised by Seese in [See91] (in a different but equivalent way) is still open, although a partial solution has been given in [CouOum], see Theorem 7.55(2):

Is it true that a set of simple graphs must have bounded clique-width if it has a decidable monadic second-order satisfiability problem?

In this respect, relational structures are much simpler to handle through their incidence graphs rather than directly. This is clear from the constructions of Section 9.2, that reduce the MS 2 -satisfiability problem for relational structures to a similar problem for graphs, so that we get an easy extension of Theorem 7.55 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] in Theorem 9.19. But we have no such tool to answer the following question (Question 9.20) that we repeat:

Is it true that if a subset of STR(R) has a decidable CMS-satisfiability problem, then it is included in τ (trees) for some monadic secondorder transduction τ ?

MS-transductions of terms and tree transducers

By their very definition, MS-transductions of terms are of linear size increase. Tree-walking transducers and their compositions are far more powerful than MS-transductions of terms (cf. Theorem 8.17), but still have nice properties such as the decidability of type-checking (see [START_REF] Engelfriet | A comparison of pebble tree transducers with macro tree transducers[END_REF] and [EngHS]) and of the finiteness of their output languages (see [DreEng]). It would be of interest to generalize the definition of MS-transduction in such a way that it captures a larger class of tree transducer transformations, thus allowing the logical specification of such transducers. One could first think of tree transductions of polynomial size increase (see, e.g., the notion of a first-order query in Definition 1.26 of [*Imm]).

The precise relationship between nondeterministic (compositions of) tree transducers and MS-transductions of terms (of which the definition schemes use parameters) has not yet been investigated. For instance, the following problem is open.

Is it decidable whether or not a (nondeterministic) tree-walking transducer is an MS-transduction?

For deterministic tree-walking transducers the problem is decidable [START_REF] Engelfriet | Macro tree translations of linear size increase are MSO definable[END_REF], but its time-complexity is unknown. the composition in any order of functions f i that commute pairwise (i.e., such that f i • f j = f j • f i for all i, j ∈ I).

The We denote by [A → A] f the set of mappings : A → A that are the identity outside of a finite subset of A and by Perm f (A) the subset of those that are permutations, i.e., bijections : A → A.

Other symbols

Notation that is self-explanatory (e.g., Loops(G) for the set of loops of a graph G), or that is used in a single section, is not listed.

Terms and rooted trees (Sections 2. 1 and 2.6

Figure 1 :

 1 Figure 1: The main notions.

Figure 1 . 1 :

 11 Figure 1.1: A cograph.

Figure 1 .

 1 Figure 1.2: Series-and parallel-compositions.

Figure 1 .

 1 Figure 1.3: A series-parallel graph.

Figure 1 .

 1 Figure 1.4: The parse tree of D and the term d.

A

  * = {a, b, c} * (where x, y, z denote words in A * ): p(x, y) := axy, q(x, y) := xy, s(x, y, z) := bxyz, and the constant symbols r, u, v, w by the following words:

  edg n , edg n (x, y) :⇐⇒ x, y ∈ [n] and x = y, K n,m := [n + m], edg n,m edg n,m (x, y) :⇐⇒ 1 ≤ x ≤ n and n + 1 ≤ y ≤ n + m, or 1 ≤ y ≤ n and n + 1 ≤ x ≤ n + m.

P 1 :

 1 The cardinality |X| of the set X is even, P 2 : |X| is a prime number,P 3 : |X| = |Y |, P 4 : G has a non-trivial automorphism,

P 5 :

 5 G has a Hamiltonian cycle.

  For a, b ∈ A, a = b, we let ren a↔b (G) := G • , src where src (a) := src G (b) if b ∈ τ (G), src (b) := src G (a) if a ∈ τ (G), src (c) := src G (c) if c ∈ τ (G) -{a, b},and src is undefined otherwise. Henceτ (ren a↔b (Gb ∈ τ (G) or τ (G) ∩ {a, b} = ∅, (τ (G) -{a}) ∪ {b} if a ∈ τ (G), b / ∈ τ (G), (τ (G) -{b}) ∪ {a} if b ∈ τ (G), a / ∈ τ (G).We can write this more succinctly as τ (ren a↔b (G)) = τ (G)[b/a, a/b] where, for every set C, we denote by C[c/a, d/b] the result of the simultaneous replacement in C of a by c and of b by d.

  Transductions of words are studied in the books [*Ber] and [*Sak]. Transductions of terms, usually called tree transductions, are studied in [*Com+] and [*GecSte].

Figure 1 .

 1 Figure 1.5: The term s as a labelled tree.

  The collective book [*Com+] by Comon et al., readable online, is a thorough study of finite automata on terms. Another reference is the book chapter [*GecSte]. Graph grammars defined in terms of graph rewritings are surveyed in two chapters ([*EngRoz, *DreKH]) of the first volume of the handbook of graph grammars and graph transformations [*Roz] edited by Rozenberg. Another similar survey is the book chapter [*Eng97]. Most of the material referred to in Sections 1.1-1.8 is surveyed in [*Cou97], another chapter of [*Roz]. The books by Diestel [*Die] and by Mohar and Thomassen [*MohaTho] are our main references for general graph theory and for graphs embedded on surfaces respectively.

  [*Tho90] and [*Tho97a], and to the books [*GräTW] and [*FluGräW].

  a) = ρ(b) = ρ(c) = 0 will be written f (g(h(a), b), c, g(g(b, c), c)). (We have used this notation in Chapter 1 in the definition of terms.)

  1} we define ξ(i, b) := 2i + b. The set {True, False} has the standard encoding (2, {0, 1}, ξ) with ξ(True) := 1 and ξ(False) := 0, and similarly for any fixed finite set. The set {x 1 , x 2 , . . . } of standard variables (see Definition 2.5) has the standard encoding (ω, N , ξ) with ξ(x i ) := i. Let A, A , A 1 , . . . , A k be encoded sets. Standard encodings of sets like A ∪ A (for A and A disjoint), A × A and Seq(A) are derived in the obvious way from ξ A , ξ A and those of N × {0, 1}, N × N and Seq(N ), respectively. To be precise, for a, a 1 , . . . , a m ∈ A and a ∈ A we let ξ A∪A (a) := 2ξ A (a) and ξ A∪A (a ) := 2ξ A (a ) + 1, ξ A×A (a, a ) := ξ N ×N (ξ A (a), ξ A (a )), and ξ Seq(A) (a 1 , . . . , a m

Figure 2 . 1 :

 21 Figure 2.1: A syntactic tree.

  where G , F and Y are defined as follows. We construct G by removing from G : (a) the vertices that yield vertices in V H -V H by the contraction of the edges of F , (b) the edges incident with vertices removed in Step (a), (c) the edges of E H -E H that have not been removed by Step (b). We let

Proof: ( 1 )

 1 Clear since Obst(A) is, by definition, an antichain. (2) Let D, ≤ and A be as in the statement. Let d ∈ D -A. Since there is no infinite strictly decreasing sequence in D, the set {e | e ≤ d and e / ∈ A} contains a minimal element d . Hence d ∈ Obst(A) and d /

  and similarly for other notations. The domain of slab G is a set of vertices denoted by Src(G) and called the set of sources of G, and τ (G) := slab G (Src(G)) is the type of G, a finite subset of A.

Figure 2

 2 Figure 2.2: From left to right: H, K and H K.

  and ≈ is the equivalence relation generated by the pairs (src H (a), src K (a)) for all a ∈ τ (H) ∩ τ (K).

Figure 2

 2 Figure 2.3: From left to right: G, fg c (G) and ren h (G).

  [K,Λ] and by F HRd [K,Λ] the corresponding modifications of the signatures F HRu and F HRd . (The modifications concern only the constant symbols.) We denote by J S u [K,Λ] and J S d [K,Λ] the sets of abstract directed and undirected (K, Λ)-labelled s-graphs, and by JS u [K,Λ] and JS d [K,Λ] the corresponding algebras.

C

  will mean ambiguously F HRu C as well as F HRd C . Since F HR is the union of the signatures F HR C for all finite subsets C of A, and F HR C ⊆ F HR C if C ⊆ C , every finite subsignature of F HR is a subsignature of F HR C for some finite set C. Hence, every term in T (F HR ) belongs to T (F HR C ) for some finite set C. We denote by J S d [C] the set of s-graphs in J S d that have their type included in C. We obtain an F HRd C -algebra denoted by JS d [C], and similarly, J S u [C] and JS u [C] for undirected s-graphs. We use JS[C] and J S[C] for denoting simultaneously the F HR C -algebras of directed and undirected s-graphs and their domains. For (K, Λ)-labelled s-graphs, we will denote by F HR C,[K,Λ] and JS [K,Λ] [C] the corresponding signatures and algebras, defined by restricting source names to belong to C.

Figure 2 . 4 :

 24 Figure 2.4: An s-graph G.

  Lemma 2.37 Let g : B → B be a bijection between finite sets B and B . There exists a bijection f : B ∪ B → B ∪ B such that f B = g. Proof: Since g is a bijection, |B -B | = |B -B|. Let B -B = {b 1 , . . . , b n } and B -B = {b 1 , . . . , b n }. We define f (b) = g(b) for every b ∈ B, and f (b i ) = b i for every i ∈ [n].

1 )

 1 For each finite set C, F HR C is a finite subsignature of F HR . Two F HR Calgebras that are subalgebras of JS can be defined. The first one is JS[C] (cf. Definition 2.32). Its domain is the set J S[C] of s-graphs of type included in C. The second one is the subalgebra JS gen [C] of JS[C] that is generated by F HR C . Its domain J S gen [C] consists of the s-graphs that are the values of terms over F HR

  , b) for some (w, c) where w is a common ancestor of u and u , and furthermore (u, a) ≈ t,w (w, c) ≈ t,w (u , b). Hence, each equivalence class of ≈ t contains pairs (u, a) for a unique maximal node u. If it contains (u, a) and (u, b), then (u, a) ≈ t,u (u, b) hence a = b by Claim 2.41.1.

28

  In the directed case, there are k edges x → G y and n edges y → G x. If w(x) = (u, a) and w(y) = (v, b), then we replace the occurrence of ab by the parallel-composition of k symbols -→ ab and n symbols -→ ba.

  12) ren h (ab) = cd, where {c, d} = {h(a), h(b)}, a < b and c < d, (13) ren h ( -→ ab) = -→ cd, where c = h(a), d = h(b), (14) ren h (a) = c, where c = h(a), (15) ren h (a ) = c , where c = h(a), (16) a a = a and a a = a , (17) a ab = ab, a every edge label λ and every vertex label κ, we have: (12 ) ren h (ab λ ) = cd λ , where {c, d} = {h(a), h(b)}, a < b and c < d, (13 ) ren h ( -→ ab λ ) = -→ cd λ , where c = h(a), d = h(b), (14 ) ren h (a κ ) = c κ , where c = h(a), (15 ) ren h (a λ ) = c λ , where c = h(a), (16 ) a a κ = a κ , a κ a κ = a κ and a a λ = a λ , (

  On the other hand, since (T, f ) can consist of a unique box containing all vertices and since some box must contain all sources by Condition (4), we have |τ (G)| ≤ k ≤ |V G |. This implies:

Figure 2

 2 Figure 2.5: A graph G.

  (b) f (u) := {u, v, e} if e : v → u is the unique edge with head u (which implies u = r).

Figure 2

 2 Figure 2.6: A rich tree-decomposition (T, f ) of G.

Figure 2 . 7 :

 27 Figure 2.7: The tree T .

Figure 2

 2 Figure 2.8: Graph G of Remark 2.70.

  5.1 in [*Die]. Other characterizations and properties of chordal graphs can be found in the books [*BranLS], [*Die] and [*Gol].

Figure 2 .

 2 Figure 2.10: Illustration of Lemma 2.78.

Proposition 2 .

 2 85 Let C ∈ P f (A). An s-graph G is the value of a term in Slim(F HR C ) if and only if τ (G) ⊆ C and pwd (G) ≤ |C| -1.

Figure 2 .

 2 Figure 2.11: A graph with ports.

( 4 )

 4 If c = --→ add a,b (c 1 ) and c 1 , t 1 are obtained from the induction hypothesis, then we can take c := --→ add a,b (c 1 ) and define t as follows. First, we define ADD S such that it simulates --→ add a,b on the first components of the port labels in C: the set S ⊆ C × C consists of all pairs ((a, A, A ), (b, D, D )) with A, A , D, D ⊆ B. Second, assuming that c 1 = relab g1 (ADD R1 (x 1 )), we define k : C → C by k(a, A, A ) := (a, A ∪ g -1 1 (b), A ), k(b, A, A ) := (b, A, A ∪ g -1 1 (a)), and k(d, A, A ) := (d, A, A ) for d = a, b. And finally, we define t

  Definition 2.111 (Modules and prime induced subgraphs)To simplify the presentation, we only consider graphs without loops. A module

Figure 2 .

 2 Figure 2.12: Graphs H (left) and G (right) of Example 2.113.

1 )

 1 Every vertex of Pt(u, a) is adjacent to every vertex of Ext(u, a). Hence, one cannot have |Pt(u, a)| ≥ p and |Ext(u, a)| ≥ p.

  for every p-graph G. If h(a) = b and h (a) = b = b, then c GP (a) = b and c GP (a) = b and this contradicts the hypothesis (because b = b ). Hence h = h . If (a, b) ∈ R -R , then c GP (a ⊕ b) has one edge whereas c GP (a ⊕ b) has none. This is impossible, hence R ⊆ R and by symmetry we have an equality. For every R ⊆ C ×C and every h : C → C, we let ⊗ R,h be the binary derived operation defined by G ⊗ R,h H := relab h (ADD R (G ⊕ H)). We let F κVR C be the "compact" signature consisting of the same constants as F VR C (including ∅) and of the binary operations ⊗ R,h for all R ⊆ C × C and h : C → C. Proposition 2.121 Let C ∈ P f (A). The same p-graphs are defined by T (F VR C ), by T (F κVR C ) and by T (F κVR C -{∅}) ∪ {∅}. The corresponding transformations of terms can be done in linear time. Proof: Obviously, every term over F κVR C can be turned into an equivalent term over F VR C by replacing every subterm t

  for all a ∈ C: p(a) := p(a ) := a and p -(a ) := p -(a) := a.

  (a) For C, D ∈ S, we let C,D be the binary operation of type C ×D → C ∪D that is the restriction of to J S C × J S D . (b) For C ∈ S and B ⊆ C, we let fg B,C of type C → C -B be the restriction of fg B to J S C . (Note that for arbitrary B we have fg B J S C = fg B∩C,C ).

E

  and F tHR E , and to the subalgebras JS[E] and JS t [E] of JS and JS t respectively. The associated typing and untyping mappings are easy to define and Propositions 2.130 and 2.132 extend to them. It follows that val (T (F tHR C

  It is the domain of sort C of the many-sorted VR algebra. The operations of that algebra are obtained by restricting the operations of GP to the sets GP C , as in the case of JS, cf. Definition 2.128. Disjoint union ⊕ yields binary operations ⊕ C,D : C × D → C ∪ D. The unary operations add a,b and --→ add a,b yield add a,b,C and --→ add a,b,C respectively, for all sets (sorts) C containing a and b. These operations have type C

  and x • D y := Error in all other cases.

  We obtain a partition {A b } b∈B of A. We consider each element b of B as a letter of a new finite alphabet B. Let K be the set of words w ∈ B * such that k(w) ∈ C where k is the unique homomorphism : W(B) → B extending the identity : B → B (so that k(b) = b). It is clear that K is a recognizable language over a finite alphabet and that L = σ(K) where σ is the substitution that replaces a letter b in a word in K by any letter in A b (where different letters of A b can be substituted at distinct occurrences of b).

  Definition 3.65 (Syntactic congruence) Let M be an F -algebra and L ⊆ M . We define on M an equivalence relation as follows: m ≈ L m if and only if m and m have the same sort, say s, and for every linear 26 term c ∈ T (F, Y p ), where p ≥ 1, Y p = {y 1 , . . . , y p } and σ(y 1 ) = s, we have, for all

  Claim 3.80.1 For every m ∈ M , there exists a complete and deterministic (F ∪ {x})-automaton B with A states such that, for every c ∈ Ctxt(F ), we have c ∈ L(B) if and only if c M (m) ∈ L.

  For p ∈ P , we let sat(M, p) := {m ∈ M α(p) | p (m) = True}. Example 3.82 Let us consider the 2-colorability of series-parallel graphs, already detailed in Chapter 1, Example 1.11. The equalities (1.10) yield the following splitting of σ relative to •:

  with congruence defined by (n, n ) ∼ (p, p ) if and only if n = n and p = p or n = n and p = p . Hence Rec(N × N ) ⊃ Rec(N × N). However, Rec(N ) = Rec(N) because N and N are respectively isomorphic to W({a}) and to W right ({a}) which have the same recognizable sets as recalled in Example 3.57(2).

  23 and Theorem 3.62 (restricted to finite signatures), are due to them. This chapter is otherwise based on [*Cou86, *Cou96b, *Cou97], but the notions of effectivity are new. Recognizability is extended so as to allow elements of different sorts in the same recognizable set. Theorem 3.7 is Proposition 1.4.5 of the book [*ArnNiw]. The preservation of sets of solutions and of least solutions under unfoldings and related transformations is studied in detail in [*Cou86]. More general equation systems, called regular systems of equations are studied in [*Cou83, *Cou86, *Cou90a] with motivations from the semantics of recursive programs. Regular grammars and automata (cf. Section 3.3) are studied in [*GecSte] and [*Com+]. The recognizable and the equational sets of R, the algebra of rooted trees are characterized in terms of appropriate finite automata and of equivalent logical sentences in [*Lib06, BonTal, Cou89a] and [*Cou96b]. Chapter 8 of [*Com+] also considers rooted ordered unranked trees in which each node has a sequence of sons of unbounded length.

Figure 4

 4 Figure 4.1: A ladder.

  [k] (x). A bit more generally, for each finite set of source names C, the set TWD(≤ k -1, C) of s-graphs of tree-width at most k -1 and of type included in C is HR-equational. For |C| = k this follows from Theorem 2.83 as for C = [k]. For |C| = k we use Proposition 3.45. If |C| > k, then TWD(≤ k-1, C) is the union of all TWD(≤ k-1, D) with D ⊆ C and |D| = k, and if |C| < k, then TWD(≤ k-1, C) = fg D-C (TWD(≤ k-1, D)) for any set D with C ⊆ D and |D| = k.

  k+1, and e 1 , . . . , e p are the terms k (we let k := k+1) and i∈I ik , for all nonempty subsets I of [k]. Hence p = 2 k . The unknown y defines s-graphs of type [k].

  Figure 4.2 for an example with n = 7 and k = 3.

Figure 4

 4 Figure 4.2: A graph of cyclic bandwidth ≤ 3.

  [K,Λ] ) (or more precisely in T (F (S))) that evaluates to G. This transformation can be done in time proportional to the size of d (cf. Definition 3.43). The size of G, defined as the number of vertices and edges, is O(|t|). More precisely (cf. Section 2.3.2), |V G | ≤ 2 • |Occ 0 (t)| and |E G | ≤ |Occ 0 (t)|, where Occ 0 (t) is the set of occurrences of constant symbols in t different from ∅. Furthermore, |t| = Θ(|d|) if S is uniform. These facts follow from the various definitions.

  (a) either H belongs to the first component of S i P(JS) (∅), (b) or S i+1 P(JS) (∅) ∩ M = S i P(JS) (∅) ∩ M and Case (a) does not hold.

  c T := τ (c JS ), where c ∈ F HR 0 . If C is a subset of A, we denote by T[C] the subalgebra of T with signature F HR C obtained by replacing A by C in the above definitions. Lemma 4.11 The mapping τ is a homomorphism from the F HR -algebra JS to T. Its restriction to JS[C] is a homomorphism to T[C].

  Definition 4.15 (Size functions)

  and H has no edges and no internal vertices, because otherwise all terms c[c [c [• • • [c [t ]] • • • ]]]belong to K and the sizes of their values in J S are unbounded. Hence c[t ] belongs to K, is smaller than t and has value G (because c [t ] has the same value as t ). Repeating this procedure one obtains the required term.By this claim, the size of G is at most 3 • 2 n-1 by the same argument as in the proof of Proposition 4.5. Moreover, the cardinality of L is at most equal to the number of terms in T (F (S)) of height ≤ n -1, which is at most k,c,d (n -1) ≤ (c + d + 1) k n by the remarks preceding Proposition 3.53. In the present case, k = 2 and c + d = |F (S)| from which the required upper-bound is obtained.

  Figure 4.3 shows an example where τ (e) = τ (H) = [3] and vert G (e) maps 1, 2 and 3 respectively to u, v and w. The hyperedge e is shown as directed for readability.Definition 4.22 (Hyperedge replacement graph grammars)A hyperedge replacement graph grammar, an HR grammar for short, is a pair Γ = U, R consisting of a finite S-sorted set U of variables called nonterminal symbols and a finite set R of rules where a rule is a pair (x, H) such that x ∈ U and H is a U -hypergraph of type τ (x). The one step derivation relation on U -hypergraphs is defined by:

Figure 4

 4 Figure 4.3: Hyperedge replacement.

  Proposition 4.24 Let t, s ∈ T (F tHR ∪ U), let x ∈ U and let c be a context in Ctxt(F tHR ∪U) such that t = c[x] and τ (x) = τ (s). 12 Let e be the corresponding hyperedge labelled by x, in a concrete hypergraph G isomorphic to val (t). We have val (c[s]) = G[e ← val (s)].

Proposition 4. 27 ( 1 )

 271 Let S and Γ[S] be as in Definition 4.25. The least solution of S in P(JS t ) is (L(Γ[S], x 1 ), . . . , L(Γ[S], x n )).

  Example 4.28 We use the example of ladders defined in Example 4.3(5), and the typed equation system E := y = 12 ∪ f (y) with τ (y) = {1, 2}. The corresponding HR grammar Γ[E] consists of the two rules (y, 12) and (y, H) where H is the {y}-hypergraph defined by f (y) and shown as H 1 in Figure 4.4. An example of a derivation sequence of G(E) is y ⇒ f (y) ⇒ f (f (y)) ⇒ f (f (12)). The corresponding derivation sequence of Γ[E] is y ⇒ H 1 ⇒ H 2 ⇒ H 3 where the {y}-hypergraphs y, H 1 , H 2 , H 3 are shown in Figure 4.4.

Figure

  Figure 4.4: Ladders.

  It is locally finite since the number of occurrences of ∅ is bounded. More precisely, it has 3•B(|C|) classes of type C where B(k) is the k-th Bell number 15 that counts the number of partitions (with nonempty sets) of [k] if k > 0 and B(0) = 1. The set of connected s-graphs of type C ∈ P f (A) is θ -1 ({C}). The set of disconnected graphs is {G ∈ J S | τ (G) = ∅ and θ(G) = {∅, ∅} }. These sets are effectively recognizable by Proposition 3.78(2).

( 3 )

 3 the set of k-colorable graphs, (4) the set of biconnected graphs, (5) the set of graphs having at most k connected components, (6) the set of planar graphs, (7) the sets TWD(≤ k, C) for all finite sets C, 16 (8) any minor-closed set of simple, loop-free, undirected graphs such that the excluded minors are known, (9) the set of directed graphs having a Hamiltonian circuit (a directed cycle going through all vertices).

  Proposition 4.32 The following sets are not HR-recognizable: L 1 : the set of odd paths with the middle vertex as 1-source, 17 L 2 : the set of graphs of the form G ⊕ H with |V G | = |V H |, L 3 : the set of graphs of the form G ⊕ G. Proof: We first recall that the set of terms N = {f g n ag n b | n ≥ 0} ⊆ T ({f, g, a, b}) (4.4)

  where the unions extend to all a, b ∈ [k] with a < b and all mappings h in [[k] → [k]] f . A 1-port with an incident loop is denoted by the constant symbol 1 . By Proposition 2.118, one can replace the operations relab h by relab a→b for all a, b ∈ [k], a = b. For generating directed p-graphs, one replaces add a,b by --→ add a,b .

  Claim 4.47.1 For every p-graph G in L there exists a term t ∈ K of height at most n -1 such that |val (t)| = |G|. Proof: Using the same terminology as in the proof of Claim 4.19.1, we obtain that c GP (G ) = relab h (ADD R (G ⊕ H)) and that H must be empty, and hence c GP (val (t )) = ADD R (val (t )) because c [t ] and t have the same type. Hence |val (c[t ])| = |G| by the equations for | • | (|G ⊕ H| = |G| + |H| etc.) stated above.

  the set of internal vertices of G) equipped with the following mapping port Int(G) : port Int(G) (u) := A, A where

  .7) where src G (B) := {src G (b) | b ∈ B ∩ τ (G)}, ADD R(B) is as defined before Proposition 2.103 with R(B) := A,A ⊆τ (β(G)), b∈B {( A, A , b) | b ∈ A} ∪ {(b, A, A ) | b ∈ A } and RELAB B := relab k such that, for A, A ⊆ τ (β(G)) and b ∈ B, k( A, A ) := A -B, A -B and k(b) := A b , A b with

Figure 4

 4 Figure 4.5: Borders and interiors of s-graphs.

  if m is defined by a constant symbol, then m Int := ∅. In this definition, the operations RELAB h , RELAB B and ADD R(B) are as in Definition 4.50 (with β(y) instead of β(G)), and t B is a term in T VR τ (β(y))∪B denoting the p-graph β(y)[src β(y) (B)]. This construction concludes the proof. Its correctness is based on Equalities (4.5)-(4.8).

  Claim 4.51.1 For every VR-equational set L of (labelled) graphs there exists d ∈ N such that the following holds: if H is an induced subgraph of some graph G in L, then there exists a graph G ∈ L such that |V G | ≤ d • |V H | and H is isomorphic to an induced subgraph of G.

Examples 4. 54 ( 1 )

 541 Graphs with an even number of vertices. The set L v of simple graphs having an even number of vertices is VR-recognizable. For proving this we define the type-preserving equivalence relation ∼ by: G ∼ H if and only if G and H have the same type and |V G | and |V H | have the same parity, i.e., |V G | -|V H | is even. The verification that ∼ is a congruence on GP witnessing the VR-recognizability of L v is as for Example 4.30(1).

( 1 )

 1 |edg G | and |edg H | have the same parity, (2) |edg G (a, b)| and |edg H (a, b)| have the same parity for every two distinct port labels a and b, (3) |port -1 G (a)| and |port -1 H (a)| have the same parity for every port label a.

  a, b)|. It follows that the parity of |edg H | is a function of the parities of the cardinalities of the righthand side of this equality. (This equality has motivated the introduction of the sets edg G (a, b).) We also have: |edg H (a, b)

  ) such that c(G) has type {1} for every p-graph G of type B. If follows from Proposition 2.103 that there exists a finite set C of port labels disjoint with B, a binary relation S ⊆ (B × B) ∪ (C × B) ∪ (B × C) and a p-graph H of type included in C such that: c(G) := c GP (G) = relab 1 (ADD S (G ⊕ H)) for every p-graph G of type B. (See Definition 4.56 for relab 1 .) We let h B be a bijection of B to [k] and we define h C : C → [k +1, k +2 2k ] as follows. For a ∈ C, h C (a) := k+j such that A j = {h B (b) | b ∈ B and (a, b) ∈ S} and A j = {h B (b) | b ∈ B and (b, a) ∈ S}. We let R be the image of S under the mapping h

  and, either G and H have both multiple edges or they are both simple, β(G) = β(H) and Int(G) ∼ Int(H).

  a finite, possibly empty, set called the domain 1 of S, each R S is a ρ(R)-ary relation on D S , i.e., a subset of D ρ(R) S called the interpretation of R, and each c S is an element of D S called the interpretation of c. A (relational) structure is a concrete R-structure for some relational signature R. An element c S is also called a constant of S. Several constant symbols may have the same interpretation. We say that S is constant-separated if c S = d S for all c, d ∈ R 0 , c = d. An empty structure, i.e., a structure S with D S = ∅, is denoted ∅. The domain D S may be empty only if R 0 = ∅.

  lab aG ) a∈C , where lab aG (x) holds if and only if x is an a-port. Every p-graph is by definition simple, hence this representation is faithful for the p-graphs in GP[C]. If C ⊆ D ⊆ A (with D finite), then G C and G D are equivalent representations for the p-graphs in GP[C], for first-order and monadic second-order logic ( G D is obtained from G C by adding the empty sets lab aG for a ∈ D -C). If G has type C, we denote G C also simply by G . The mapping G → G is a faithful representation of all p-graphs. A structure S in STR(R s,C ) is of the form G C for some p-graph G of type included in C (of type C) if and only if the sets lab aS form a partition 7 of D S (a partition no part of which is empty, respectively).For representing an s-graph G of type τ (G) ⊆ C (in a faithful way if it is simple), we use the above signature and let lab aG (x) hold if and only if x is an a-source of G. A structure S in STR(R s,C ) is of the form G C for some s-graph G of type included in C (of type C) if and only if the sets lab aS are empty or singletons (or are all singletons, respectively). As for p-graphs, G C is also denoted by G if G has type C. For s-graphs of type C we will also need a variant of G in which the sources are viewed as constants. Thus, we use the relational signature R ss,C := {edg} ∪ C where each element of C is a constant symbol

  definitions are essentially the ones of [*FluGro] and [*Lib04], where they are justified by explicit encodings of structures by words of length O( S ). Let us see what these definitions yield when applied to the representations of words, graphs and terms. For a word w over A represented by the W A -structure w we have w = Θ(1 + |w| + |A|), but for the representation by a W A -structure, we have w = Θ(1 + |w| 2 + |A|) which justifies to prefer the first representation. For a p-graph G of type π(G) = C represented by the R s,C -structure G , we have G = Θ(1 + |V

  qh(¬ϕ) := qh(ϕ), |ϕ ∧ ψ| := |ϕ ∨ ψ| := |ϕ ⇒ ψ| := |ϕ ⇔ ψ| := |ϕ| + |ψ| + 1, qh(ϕ ∧ ψ) := qh(ϕ ∨ ψ) := qh(ϕ ⇒ ψ) := qh(ϕ ⇔ ψ) := max{qh(ϕ), qh(ψ)}, |∃X. ϕ| := |∀X. ϕ| := |∃x. ϕ| := |∀x. ϕ| := |ϕ| + 1, qh(∃X. ϕ) := qh(∀X. ϕ) := qh(∃x. ϕ) := qh(∀x. ϕ) := qh(ϕ) + 1.

  ary relation on D S for each i = 1, . . . , m and γ(x j ) ∈ D S for j = 1, . . . , n. It is just another way of formalizing a tuple (E 1 , . . . , E m , d 1 , . . . , d n ). We will also use the notation (S, γ) |= ϕ instead of S |= ϕ(E 1 , . . . , E m , d 1 , . . . , d n )

  In each case, several variants of these default representations are considered in Example 5.2, which are all L-equivalent for every L ∈ {FO, MS, SO} in the following precise sense. For another mapping rep : C → STR c (R ), we say that rep and rep are L-equivalent if the same properties of the elements of C are L-expressible via rep and via rep , effectively (i.e., the corresponding transformations of sentences in L(R, ∅) and L(R , ∅) are computable).For a set L ⊆ C, let rep(L) be the class of structures in STR c (R) that are isomorphic to some structure rep(H) with H ∈ L. It can easily be shown that L is L-definable via rep (with respect to C) if and only if rep(L) is L-definable with respect to rep(C). 18 If the class rep(C) of all structures that represent objects in C (modulo isomorphism) is L-definable, then: L is L-definable via rep if and only if rep(L) is L-definable (see Footnote 16). For example, if C is the class GP[C] of p-graphs of type included in C, then the class of structures C C is MS-definable (cf. Example 5.2(2)). Hence a set L of p-graphs is MS-definable if and only if L is MS-definable (see Example 5.2(2) for the definition of L ).

Figure 5 . 1 :

 51 Figure 5.1: The well-coloring of the grid G 4×4 .

Figure 5

 5 Figure 5.2: A proper 3-coloring of G u 4×4 .

  Example 5.2(2). We let R d m,C := R d m ∪{lab a | a ∈ C} and R d ms,C := R d m ∪C, and similarly 38 for R u m and R m . Let G be an s-graph with τ (G) ⊆ C. In the R d m,C -structure G C , we let lab a (x) hold if and only if x is an a-source of G. This representation is faithful for the s-graphs in J S d [C]. Similar to the case of p-graphs, if C ⊆ D ⊆ A, then G C and G D are equivalent representations for the s-graphs in J S d [C], for first-order and monadic second-order logic. Now let τ (G) = C. Then we denote G C also by G . The mapping G → G is a faithful representation of all s-graphs. Additionally, in the R d ms,C

Figure 5 .

 5 Figure 5.3 shows G(A, B) for |A| = 3 and |B| = 4. The graph G(A, B) has a

  hence S |= ϕ by the construction of ϕ . Conversely, if S |= ϕ, then there exist E 1 , . . . , E m satisfying θ 0 , hence S |= ϕ (E 1 , . . . , E m ). Thus we have S |= ϕ . Hence ϕ is equivalent to ϕ in every structure S in C. This result extends to formulas with free variables. Understanding "exactly" which sets of structures are MS-orderable is an open problem. Here are some partial answers. Proposition 5.30 Let d ∈ N + . The class of rooted trees of outdegree at most d is MS 1 -orderable. More generally, the class of rooted forests consisting of at most d rooted trees of outdegree at most d is MS 1 -orderable.

  .4 show other situations. Here are the examples establishing proper inclusions and incomparabilities in these tables.

  ¬θ i and similarly ψ I (with the ψ i 's). It is then clear that sat(S ⊕ T, ϕ, x; y) = I∩J =∅, I∪J⊆[p]

  perm π (sat(S, θ I , x) × sat(T, ψ I , y)) and the union is actually disjoint because each perm π is injective on the set D |x| S × D |y| T . This gives the desired result.

  and S ⊕ T |= ϕ(A, a, b), where A = (A 1 , . . . , A m ), a = (a 1 , . . . , a k ) and b = (b 1 , . . . , b ). In other words, sat(S ⊕ T, ϕ, X, x; y) is the intersection of sat(S ⊕ T, ϕ, X, x y) with P(D S⊕T ) m × D k S × D T . For combining sets sat(S, θ, X, x) and sat(T, ψ, X, y), we need a more complex operation than the Cartesian product used for first-order formulas. If A = (A 1 , . . . , A m , a 1 , . . . , a k ) ∈ P(D) m ×D k and B = (B 1 , . . . , B m , b 1 , . . . , b ) ∈ P(D ) m × D , we define the (m + k + )-tuple

  have sat = pr (sat(S ⊕ T, ϕ 1 , XU, x; y)) where the projection pr : P(D) m+1 × D n → P(D) m × D n "eliminates" the (m + 1)-th component. It is clear that for A ⊆ P(D) m+1 × D k and B ⊆ P(D ) m+1 × D , we have pr ( A B) = pr ( A) pr ( B). Then:sat = pr ( i sat(S, θ i , XU, x) sat(T, ψ i , XU, y)) = ipr (sat(S, θ i , XU, x)) pr (sat(T, ψ i , XU, y)) = i sat(S, ∃U. θ i , X, x) sat(T, ∃U. ψ i , X, y).

Example 5 .

 5 41 We examine how Lemmas 5.35 and 5.36 extend to the operation ⊗ by generalizing what has been done for ⊕. Lemma 5.35 obviously holds for ⊗. Case 3 of Lemma 5.36 reduces to the following one where G and H are graphs (we identify G and H with G and H respectively):

  and t ∈ y, or if t ∈ x and s ∈ y. This gives the following splitting (taking into account permutations of variables): sat(G ⊗ H, edg(x, y), xy) = sat(G, edg(x, y), xy) sat(H, edg(x, y), xy) sat(G, True, x) × sat(H, True, y)

  Since we have sat(G ⊕ H, edg(x, y), xy) = sat(G, edg(x, y), xy) sat(H, edg(x, y), xy), we get sat(G ⊕ H, ϕ, xy) = sat(G, edg(x, y), xy) ∪ sat(G, ϕ 1 , xy) ∪ sat(H, edg(x, y), xy) ∪ sat(H, ϕ 1 , xy) = sat(G, ϕ, xy) sat(H, ϕ, xy).

  S -D D(S) = {c S | S |= α c }. Thus, only constants can be deleted from D S . If α c is False for all c, then D is domain preserving. If S is constant-separated, then c S ∈ D S -D D(S) if and only if S |= α c . If it is not, we may have c S in D S -D D(S) with S |= ¬α c but c S is nevertheless not in D D(S) because c S = c S and S |= α c for some c = c.

  Example 5.45 (Fusion of constants) Let a and b be distinct constant symbols of a relational signature R. We define fuse a,b : STR(R) → STR(R) as the transformation of abstract structures that fuses a S and b S and reorganizes the tuples accordingly. If a S = b S , then fuse a,b (S) = S. Concretely, b S is deleted if a S = b S . This operation is our main example of a QDP-QF operation.

For

  every R ∈ R + : R S := {( e 1 , . . . , e ρ(R) ) | (e 1 , . . . , e ρ(R) ) ∈ R S }. where e := if e = b S then a S else e.

  c∈R0 (α c ⇒ x = c), where α c is a = b if c = b and is False otherwise. We will also use its variant ffuse a,b defined as fg b • fuse a,b that fuses a and b and then forgets b. It maps STR(R) to STR(R -{b}). It is also QDP-QF and preserves constant-separation, which is not the case for fuse a,b . Its definition scheme is obtained from that of fuse a,b by omitting the formulas κ c,b for all c.

  If ϕ is s = t, we have several cases. If s and t belong to y, then µ is ϕ; if s belongs to y and t = d ∈ R 0 , then µ is c∈R0 (κ c,d ∧ s = c); the case where t belongs to y and s = d ∈ R 0 is similar; if s = d ∈ R 0 and t = d ∈ R 0 , then we let µ be c,c ∈R0 (κ c,d ∧ κ c ,d ∧ c = c ).

  Finally, we let κ c,e be d∈R 0 κ c,d ∧ κ D d,e where, by Remark 5.48(2), S |= κ D d,e if and only if D(S) |= κ d,e . It follows from Theorem 5.47(2) that D defines g • f .

  Let h be a bijection : C → D where C, D ∈ P f (A). The operation ren h,C of type C → D is defined by the scheme D h,C := True, θ in , θ lab Edge , (κ a,b ) a∈C,b∈D of type R ms,C → R ms,D where θ in and θ lab Edge are as above and κ a,b is True if h(a) = b, False if h(a) = b. The QFO definition schemes D B,C and D h,C are domain preserving and they preserve constant-separation. Parallel-composition will be defined below in Example 5.55, in terms of disjoint union (⊕) and the QDP-QF operations ffuse a,b of Example 5.45.

  ren 2↔3 : R ms,{1,2} → R ms,{1,3} , ren 1↔4 : R ms,{1,2} → R ms,{2,4} , fuse 3,4 : R ms,{1,2,3,4} → R ms,{1,2,3,4} , and fg {3,4} : R ms,{1,2,3,4} → R ms,{1,2} .

  For s-graphs G and H of respective types C and D, faithfully represented by the constant-separated structures G ∈ STR(R ms,C ) and H ∈ STR(R ms,D ), we have G C,D H = G R ms,C ,R ms,D H . 63 Hence the parallel-composition operations of the many-sorted algebra JS t are binary QDP-QF operations. Example 5.56 (Concatenation of linearly ordered structures) Let us consider a relational signature R containing the binary symbol ≤. For S, T ∈ STR(R) we denote by S -→ ⊕ T the structure S ⊕ T where, furthermore, we let x ≤ y hold for every x ∈ D S and y ∈ D T . By an easy modification of the construction of Example 5.54, we obtain that -→ ⊕ : STR(R) × STR(R) → STR(R) is a binary DP-QF operation.

  denotes the disjoint union of an R-structure and an R -structure (extending the operation of Definition 5.34 as explained in Example 5.44); (b) for every R, R ∈ S and every QFO definition scheme D of type R → R (this implies that R 0 = ∅ if R 0 = ∅), the unary symbol qf D,R,R of the same type; it denotes the unary QF operation D : STR(R) → STR(R ) associated with D; (c) the constant symbols ∅ R (only if R 0 = ∅), to denote the empty Rstructure, and ♦ B,R where R 0 ⊆ B ⊆ R, to denote the R-structure S with a single element * such that a S := * if a ∈ R 0 , R S := {( * , . . . , * )} if R ∈ B -R 0 and R S := ∅ if R ∈ R -B.

  Corollary 5.69 (Weak Recognizability Theorem for graph algebras)(1) Every CMS-definable set L of (labelled) p-graphs of bounded clique-width is effectively recognizable in the algebra GP gen [C], where C is any finite subset of A such that L ⊆ GP gen [C] = val (T VR C ) (i.e., such that cwd (L) ≤ |C| and π(G) ⊆ C for every G ∈ L).

  The definition scheme D = δ, (θ R ) R∈R+ , (κ c,d ) c,d∈R0 is thus completely specified by δ. Its other formulas are θ R (x 1 , . . . , x n ) equal to R(x 1 , . . . , x n ), κ c,c equal to True for each c ∈ R 0 and κ c,d equal to False for distinct c, d ∈ R 0 . By Remark 5.43(1) there are, for each R, finitely many domain restricting QF operations : STR c (R) → STR c (R). Their definition schemes are obtained by considering only formulas δ ∈ QF(R, {x}) that are in disjunctive normal form. Lemma 5.78 Let R and R be relational signatures. Every QF operation f

  where DRQF R is the finite set of domain restricting QF operations of type R → R (more precisely, it is the set of their definition schemes). For d ∈ D and h ∈ DRQF R , we defined 1 (h) ∈ B and d 2 (h) ∈ A such that d(h) = d 1 (h), d 2 (h) .The operations of D are defined as follows. Let k be a QF operation of type R → R and let f ∈ DRQF R . We apply Proposition 5.49 and Lemma 5.78 to obtain h ∈ DRQF R and a QDP-QF operation g such that f • k = g • h. Then we define the operation k D such that k D (d)(f ) := g B×A (d(h)) for every d ∈ D R . Now consider disjoint union ⊕ of type R × R → R ∪ R and let f ∈ DRQF R ∪R . Then, using Lemma 5.79, we define the operation

Figure 5

 5 Figure 5.4: A structure S(t).

Proposition 5. 91 ( 1 )

 911 If ϕ ∈ B[L], then ϕ ≡ ϕ and ϕ is obtained from ϕ by applying the laws of Boolean calculus. (2) If |L| = m ∈ N , then | B[L]| ≤ β(m) and B[L] can be computed from L.

Case 2 :

 2 If ϕ is b(ϕ 1 , . . . , ϕ n ) where b ∈ B n , b / ∈ {p 1 , . . . , p n } and each formula ϕ i is either atomic or existential (i.e., of the form ∃u. ψ), then, abbreviating b( ϕ 1 Y , . . . , ϕ n Y ) by β, we let ϕ Y be β by using the Boolean normalization of Definition 5.90. Case 3: If ϕ is ∃u. ψ, where u is a first-order variable and ψ

72

  For instance in Case 3, if ϕ ≡α ϕ then ϕ is ∃u . ψ with ψ ≡α ψ [u/u ]. Hence ψ[y 1 /u] ≡α ψ [y 1 /u ] and hence ϕ Y = ϕ Y by induction.

  by induction. The variable y 1 does not occur free in ϕ, because Y ∩ X = ∅. Hence ϕ Y is ∼-equivalent to ∃y 1 . ψ[y 1 /u] (by the definition of ∼) and to ϕ by renaming bound variables. If ϕ = β Y for some formula β, then u = y 1 and ψ = θ Y-{y1} for some θ, and so ϕ Y is ∃y 1 . ψ Y-{y1} by definition, which equals ϕ by induction. The proof is similar for Case 4.

  Corollary 5.95 For every R and R , there are finitely many QF operations of type R → R . A finite set DS R,R of QFO definition schemes can be computed such that { D | D ∈ DS R,R } is the set of all QF operations of type R → R .Proof: A definition scheme for such an operation consists of p := 1 + |R + | + |R 0 | × |R 0 | formulas with at most ρ(R ) free variables, all quantifier-free ones, i.e., formulas in C 0 MS 0 (R, X ρ(R ) ). There are thus at most g(0, 0, R, ρ(R )) p = β(f (0, R, ρ(R ))) p inequivalent definition schemes. The definition schemes that consist of formulas in C 0 MS 0 (R, X ρ(R ) ) form the required set DS R,R .

Proof:

  By Proposition 5.93 and the proof of Theorem 5.64, the sort-preserving equivalence relation ≈ on the algebra STR pres defined by S ≈ R T if and only if for every sentence ψ in C r MS h (R , ∅), we have: S |= ψ if and only if T |= ψ, is a congruence on STR pres that saturates MOD(ϕ). It has thus at most 2 N classes of sort R where N := | C r MS h (R , ∅)|. The result follows then from Proposition 5.94.

  ) and the proof of Proposition 4.13, there is a uniform typed HR equation system S that generates the set TWD(≤ k -1, = E), and it has one unknown of type D for each D ⊆ C, where C is such that E ⊆ C and |C| = k. Thus, TWD(≤ k-1, = E) is equational in the finitely generated algebra JS t,gen [C]. By Proposition 3.56(1), L k = L ∩ TWD(≤ k -1, C) is recognizable in that algebra. By the Filtering Theorem (Theorem 3.88), L k = TWD(≤ k -1, = E) ∩ L is also equational in that algebra. By the proof of Theorem 3.88, L k is generated by a uniform typed HR equation system with B k unknowns, where B k is a complete and deterministic F tHR C -automaton recognizing {t ∈ T (F tHRC) | val (t) ∈ L k }.Let λx • exp(d, x) be an upper-bound to the recognizability index of L in JS t , which is also an upper-bound to the recognizability index of L k in JS t,gen [C]. By Propositions 3.69 and 3.73(2), B k is at most D⊆[k] exp(d, |D|) ≤ 2 k • exp(d, k) ≤ exp(d + 1, k).Hence, by Proposition 4.13(1), L k is generated by a uniform typable HR equation system with at most exp(d + 1, k) unknowns. Assertions (1) and (2) now follow from Propositions 4.5(3) and 4.19 respectively.The proof for CMS-definable sets of p-graphs is similar, using VR-equational sets, Example 4.43(5) and Proposition 4.46, and Propositions 4.42(3) and 4.47(3).

  The exponent of the polynomial in the time bound of this algorithm depends on S. Let us give an illustration. If G is a connected graph of degree at most d, we have Sep(G, k) ≤ k • d for every k. Since the set of connected graphs of degree at most d and of tree-width at most k -1 is defined by an HR equation system S with |A(S)| = k, by Example 4.3(

Figure 6 . 1 :

 61 Figure 6.1: An edge-labelled graph G and its encoding B [2] (G). The mappings B and B -1 are FO-transductions. It follows from Corollary 7.38(2) (also stated after Corollary 1.43) that there exist two computable integer functions p and p such that, for every simple directed graph G: cwd (B(G)) ≤ p(cwd (G)) and cwd (G) ≤ p(cwd (B(G))).

  Definition 6.19 (Block quantifier-height and Boolean arity) A Boolean term b has arity m ≥ 1 if it is in T ({∧, ∨, ¬}, {p 1 , . . . , p m }) and each variable p i has at least one occurrence in b. It is positive if b is written without ¬. We denote by Bool m the set of Boolean terms (positive or not) of arity m. We will use the notation b(ϕ 1 , . . . , ϕ m ) for b[ϕ 1 /p 1 , . . . , ϕ m /p m ] where ϕ 1 , . . . , ϕ m are logical formulas.

  We extend the composition of binary relations (denoted by • ) to A ⊆ C and B ⊆ C × C by letting: A B := {b ∈ C | (a, b) ∈ B for some a ∈ A}. This set is the image of A by the relation B, usually denoted B(A). If B ⊆ C×C then we write A B • B for A (B • B ), which equals (A B) • B . For a, b ∈ C with a = b, we let: a b := {(a, a), (a, b), (b, a), (b, b)}.

  }), (2, {{b}, {b}}, {(b, b)}). There is one class with 2 elements: (0, {(a, a), (b, b)}), (0, a b), one class with 5 elements: (1, {a}, {(a, a), (b, b)}), (1, {b}, {(a, a), (b, b)}), (1, {a}, a b), (1, {b}, a b), (1, {a, b}, a b), and one class with 9 elements: (2, {{a}, {a}}, {(a, a), (b, b)}), (2, {{b}, {b}}, {(a, a), (b, b)}), (2, {{a}, {a}}, a b), (2, {{b}, {b}}, a b), (2, {{a}, {b}}, {(a, a), (b, b)}), (2, {{a}, {b}}, a b), (2, {{a}, {a, b}}, a b), (2, {{b}, {a, b}}, a b) and (2, {{a, b}, {a, b}}, a b).

( 1 ,

 1 {a}, {(a, a)}) and (2, {{a}, {a}}, {(a, a)}), which are also states of A . The corresponding transition rules are those of A for a and ⊕ together with, for ⊗, the following ones: ⊗[(1, {a}, {(a, a)}), (1, {a}, {(a, a)})] → Ok , ⊗[(2, {{a}, {a}}, {(a, a)}), (0, {(a, a)})] → Ok and ⊗[(0, {(a, a)}), (2, {{a}, {a}}, {(a, a)})] → Ok , and all other rules for ⊗ are as for ⊕, for example: ⊗[(0, {(a, a)}), (1, {a}, {(a, a)})] → (1, {a}, {(a, a)}), which is like: ⊕[(0, {(a, a)}), (1, {a}, {(a, a)})] → (1, {a}, {(a, a)}).

  is the set of its connected components, π(CC (G)) is the multiset of the types π(H) for all H ∈ CC (G). We denote by |M | the cardinality of a multiset M and by Set(M ) the corresponding set (so that Set(M ) ⊆ M and |Set(M )| ≤ |M |). For a multiset M , we define Set † (M ) as the multiset consisting of two occurrences of d (and nothing else) if M consists of at least two occurrences of d, and as Set(M ) otherwise.

( 1 )

 1 The same graphs are defined by the terms in T (F HRd C ) ∅ and in T (F HRd C ) ∅ .

Figure 6 . 2 :

 62 Figure 6.2: The transformation of Proposition 6.45(2).

For

  each set R of pairs (a, b) of distinct elements of C, we denote by R the term (a,b)∈R ( -→ ab, 00) belonging to T (F HRd(2) C ). It is the parallel-composition of the constant symbols ( -→ ab, 00) for all (a, b) ∈ R (with ∅ := ∅). For a, b ∈ C with a = b, we let c a,b be the context in Ctxt(F HRd(2) C

  B = {b ∈ τ (t) | b is an end of an edge of c val (t) that belongs to X 1 and has its other end in X 1 }, (4) R is the set of sets {a, b} such that a, b ∈ τ (t), a = b and a and b are the ends of an edge of c val (t) that belongs to X 1 .

  for arbitrary nonempty sets A and B. Note that A and B are no longer available after the computation of A B.

Lemma 7. 7

 7 The transduction τ is a C r MS-transduction if and only if τ * is a C r MS-transduction if and only if τ * * is a C r MS-transduction. The same statement holds for FO-transductions. Proof: The first equivalence holds by definition. We now prove the second equivalence. Let us assume that τ * is a C r MS-transduction : STR c (R) → STR c * (R * ) with definition scheme D * . Then so is τ * * : STR c * (R * ) → STR c * (R * ) by the following construction. We let D be the definition scheme of type R * → R * obtained from D * by replacing each of its formulas ϕ by the formula ϕ * constructed in Lemma 7.5. Then, we change the precondition of D into χ D ∧ α where α is the first-order formula expressing that a structure in STR c (R * ) belongs to STR c * (R * ). This gives a definition scheme D * * of type R * → R * such that D * * = τ * * .

  γ) should be defined as D * * (S * , γ) † , and D as {(S † , T † ) | (S, T ) ∈ D * * }.

  Example 7.8 (The incidence graph of a forest) The incidence graph of a simple undirected graph G is the directed graph Inc(G)with vertex set V G ∪ E G and edge relation in G := {(e, v) | e ∈ E Gand v is an end vertex of e}, cf. Definition 5.17. We will show that the graph transduction Inc is an MS-transduction on the class C of forests, more precisely, that the mapping G → Inc(G) is a 2-copying domain-extending MS-transduction on the class C (cf. the proof of Corollary 5.23).

  Definition 7.9 (Strongly equivalent representations) In Section 5.1.1, we have also defined variants of the above representations that are all faithful. The notion of a monadic second-order transduction of objects like words, terms and graphs may depend on their chosen representations. We say that two representations w and w of a word w in A * are strongly MSequivalent if the relation α := {( w , w ) | w ∈ A * } and its inverse β := α -1 are injective MS-transductions (hence, α and β are invertible). More precisely, and in general, let C be a class of objects and let rep : C → STR c (R) and rep : C → STR c (R ) be two representations, i.e., mappings that map isomorphic objects to isomorphic structures. Then rep and rep are strongly L-equivalent (for L ∈ {MS, FO, . . . }) if the relation α := {(rep(H), rep (H)) | H ∈ C} is an injective L-transduction on rep(C) and β := α -1 is an (injective) L-transduction on rep (C). 8 Let τ ⊆ T (F ) × A * and τ := {( t , w ) | (t, w) ∈ τ } be as above, and let τ := {( t , w ) | (t, w) ∈ τ }. Then we have τ = τ • α and τ = τ • β.

  γ) and ( D * (S, γ), η [k] ∪ µ i ) |= β * . With Definition 7.6 and Lemma 7.5 we get the desired result by taking β D i := (β * ) D * i since we have D * (S, γ) = D(S, γ) * . Note that if R 0 = ∅, we get the same formulas as in the first case because D * = D and β * = β.

Proof:

  Let τ be specified by a C r MS-definition scheme D with set of parameters W = {Y 1 , . . . , Y p }. (We need not distinguish the case where R has constant symbols.) Let C := MOD(β) = {T ∈ STR c (R ) | T |= β} for some sentence β in C r MS(R , ∅). Then, S ∈ STR c (R) belongs to τ -1 (C) if and only if it has an image in MOD(β) under D, hence, by Theorem 7.10, if and only if it belongs to the class MOD(∃Y 1 , . . . , Y p . β D ). This shows that τ -1 (C) is C r MS-definable. Remarks 7.13 (1) If D is parameterless and β is a sentence, then we have: D(S) |= β if and only if S |= β D .

  (i) Its set of parameters is W ∪ W .(ii) The precondition χ is (χ ) D , with free variables in W ∪ W . By Theorem 7.10, χ expresses, for a(W ∪ W )-assignment γ in S ∈ STR c (R), that T := D(S, γ W) is defined, γ W is a W -assignment in T ,and (T, γ W ) |= χ , which means that U := D (T, γ W ) is defined. (iii) We have D U ⊆ D T ⊆ D S since τ and τ are noncopying. We define the domain formula δ as (δ ) D . Its free variables are in {x} ∪ W ∪ W . Again by Theorem 7.10, for every (W ∪ W )-assignment γ satisfying χ and every a ∈ D S , we have (S, γ) |= δ (a) if and only if a ∈ D T and (T, γ W ) |= δ (a), i.e., if and only if a ∈ D U . Hence δ characterizes D U as a subset of D S (that depends on γ assumed to satisfy χ ).

  easily replaceable by D S × [kk ]. Hence, we must define the domain formulas δ i,j for (i, j) ∈ [k] × [k ] such that for γ and η satisfying χ , we have, for each a ∈ D S : (a, (i, j)) ∈ D U if and only if (S, γ ∪ η) |= δ i,j (a).

  where d is any element of a set D. This relation defines a bijection from (D × [k]) × [k ] to D × [kk ]. For a concrete structure U with D U ⊆ (D × [k]) × [k ] for some set D, we define θ(U ) to be the unique concrete structure V with D V ⊆ D × [kk ] such that θ D U is an isomorphism from U to V . The definition scheme D constructed in the proof of Case 3 can easily be modified into one that defines the concrete transduction τ • τ • θ (where τ and τ are concrete k-copying and, respectively, k -copying monadic second-order transductions). Case 4: τ is k-copying with k > 1 and τ is noncopying. If T := D(S, γ) and U := D (T, γ ), we have D U ⊆ D T ⊆ D S × [k]. The construction given for Case 3 is easily adapted. As in Cases 1 and 2, D defines the concrete transduction τ • τ . We finally consider the general case where R and R may have constant symbols. It is actually an immediate consequence of the special case and Lemma 7.7 because (τ • τ ) * = τ * • τ * * . (We also have, with more symmetry, (τ • τ ) * * = τ * * • τ * * which gives the same proof).

  Theorem 7.16 (Restriction Theorem) Let τ be a (concrete) C r MS-transduction of type R → R , let α ∈ C r MS(R, ∅) and β ∈ C r MS(R , ∅). Then the relation τ ∩(MOD(α)×MOD(β)) is a (concrete) C r MS-transduction. If τ is k-copying and is defined with q parameters, then the same holds for τ ∩ (MOD(α) × MOD(β)). Proof: We first consider the case where R has no constant symbols. We let D = χ, (δ i ) i∈[k] , (θ w ) w∈R [k] be a definition scheme defining a concrete transduction τ . We construct D from D by replacing χ by α ∧ β D . (We recall that β D is χ ∧ β D ). It is clear from Theorem 7.10 that D defines the concrete transduction τ ∩ (MOD(α) × MOD(β)).

  It transforms a structure S = D S , (R S ) R∈R into the structure T := copy k (S) with domain D T := D S × [k]

CofF

  VR for finite sets C.For a p-graph G of type π(G) ⊆ C, we have defined in Example 5.2(2) the faithful representationG C as the R s,C -structure V G , edg G , (lab aG ) a∈C where lab aG is the set of a-ports of G. If π(G) = C, then G C is also denoted G . Moreover, if L is a set of p-graphs of bounded type, then L denotes the set { G D | G ∈ L} ⊆ STR c (R s,D )where D is the smallest set of port labels such that π(G) ⊆ D for every G ∈ L. Note that if D ⊆ C, then the representations G D and G C of a p-graph such that π(G) ⊆ D are strongly FO-equivalent (Definition 7.9). In fact, G C = ι R s,D ,R s,C ( G D ) and G D = fg U ( G C ) where U := R s,C -R s,D = {lab a | a ∈ C -D}, and both these transductions are QF operations, see Example 5.44. Proposition 7.30 For each finite set C of port labels, the mapping t → val (t) C with domain T (F VR C ) is a parameterless noncopying MS-transduction of type R F VR C → R s,C . If D ⊆ C, then the mapping t → val (t) D for π(val (t)) ⊆ D (or for π(val (t)) = D) is also a parameterless noncopying MStransduction, of type R F VR C → R s,D . These results extend to labelled graphs.

  We know from Proposition 4.41 and Corollary 3.19 (see also Proposition 3.23(3)) that L = val (R) where R is a regular subset of T (F VR C,[K,Λ] ) for some finite set C that includes D. By Proposition 7.30, the mapping t → val (t) D for π(val (t)) ⊆ D is an MS-transduction. So is its restriction to R , by the Restriction Theorem (Theorem 7.16), because R is MS-definable (by Theorem 5.15). Let τ be the resulting MS-transduction. Then L = L D = τ ( T (F VR C,[K,Λ] ) ). The fat signature F VR C,[K,Λ] has unary symbols, but it can be replaced by a fat finite signature F consisting only of binary and nullary symbols by Proposition 7.27(2). Corollary 7.33 If a set of (K, Λ)-labelled p-graphs of bounded type has bounded clique-width or bounded linear clique-width, then it is included in the image of the set of trees or, respectively, of the set of paths under a monadic secondorder p-graph transduction. Proof: If a set L of (K, Λ)-labelled p-graphs of bounded type has bounded clique-width, then it is included in the set M := val (T (F VR C,[K,Λ] )) for some finite set C. By Proposition 7.30, M = M C is the image of the set of terms T := T (F VR C,[K,Λ] ) under an MS-transduction. By Proposition 7.27(2) the set T is equivalent to the set of trees. The result follows. If L as above has bounded linear clique-width, then by the definition of linear clique-width (Definition 2.89), it is included in the set val (Slim(F VR C,[K,Λ] )) for some finite set C. By Proposition 7.27(1), the set Slim(F VR C,[K,Λ]

  actually entails that the set τ(T (F )) is VR-equational. Let N := µ(T (F )) ⊆ T (F VR C,[K,Λ] ). Then τ (T (F )) = val (N ), because τ = µ • val . Since µ -1 is an MS-transduction, N = Dom(µ -1 ) is MS-definable (see Definition 7.2),hence it is regular by Corollary 5.67. It follows that τ (T (F )) = val (N ) where N is a regular set of terms over F VR C,[K,Λ] , hence τ (T (F )) is VR-equational by Proposition 3.23(3).

  ) for F κVR C instead of F VR C . Later on, we will replace it by F VR C . The derived signature F κVR C of F VR C was defined in Section 2.5.6. It has only constant symbols and binary operations defined as compositions of ⊕ and of unary operations of F VR C . The operations of F κVR C are ⊗ R,h for R ⊆ C × C and h : C → C; they are defined by G ⊗ R,h H := relab h (ADD R (G ⊕ H)), where ADD R is the composition (in any order) of the operations --→ add a,b for all pairs (a, b) in R such that a = b. Its constant symbols are ∅, c and c for c ∈ C. We will use the definitions of Section 2.5.2, which can be adapted to F κVR in a straightforward way.Let us first give an overview of the construction. We will define a set C of port labels including D and a parameterless monadic second-order relabelling µ : T (F ) → T (F κVR C

  Step 3 above, the terms µ(t) in N may contain occurrences of ∅. If τ (t) is not the empty graph, one can replace µ(t) by an equivalent term without ∅ (Corollary 2.102). By the next claim, one can construct a regular language M included inT (F VR C,[K,Λ] -{∅}) ∪ {∅} such that val (M ) = val (N ). The proof given below for T (F VR C,[K,Λ]) can be adapted so as to work forT (F κVR C,[K,Λ] ). Claim 7.34.1 Let N be a regular subset of T (F VR C,[K,Λ] ). One can construct a regular subset M of T (F VR C,[K,Λ] -{∅}) ∪ {∅} such that val (M ) = val (N ).If N consists of slim terms, then so does M .

Finally

  , we have τ (T (F )) = val (M ) where M is a regular language included in T (F VR C,[K,Λ] -{∅}) ∪ {∅}. This completes the proof of Theorem 7.34. Let us stress the following consequence of Step 4: the operations of positive arity of a term µ(t) in µ(T (F )) ⊆ T (F κVR C,[K,Λ]

  The functions p Λ and p Λ exist and are computable by Assertion (2) of Corollary 7.38 and the remark that B Λ is an invertible parameterless FO-transduction. Assertion (3) yields the linear time algorithms for transforming a term witnessing that cwd (G) ≤ k into one witnessing that cwd (B Λ (G)) ≤ p Λ (k), and similarly for the other inequality.Assertion (2) of Corollary 7.38 can also give quick proofs that certain sets of graphs have bounded or unbounded clique-width. Here are some examples. Let C be the class of nonempty, connected, simple and loop-free undirected graphs.

  where in 1G := {(e, x) | e ∈ E G , x is the tail of e} and in 2G := {(e, x) | e ∈ E G , x is the head of e}. Hence Inc(G) is a simple bipartite directed graph where each edge is labelled by 1 or 2. If G is undirected, then in 1G and in 2G are replaced by the single binary relation inG := {(e, x) | e ∈ E G , x is an end vertex of e}. If G is an s-graph, then Inc(G) is the simple s-graph with Inc(G) • := Inc(G • ) and slab Inc(G) := slab G . If L is a set of s-graphs, we let Inc(L) := {Inc(G) | G ∈ L}.For a simple (possibly labelled) s-graph G of type τ (G) ⊆ C, we have defined in Example 5.2(2) the faithful representation G C as the structure obtained from G • by adding the unary relations (lab aG ) a∈C where lab aG is the set of a-sources of G (a singleton or the empty set). For an arbitrary s-graph G of type τ (G) ⊆ C, we have defined in Definition 5.17 the faithful representation G C in such a way that it equals Inc(G) C . 22 If τ (G) = C, then G C is also denoted G . Moreover, if L is a set of s-graphs of bounded type, then L denotes the set { G D | G ∈ L} = Inc(L) where D is the smallest set of port labels such that τ (G) ⊆ D for every G ∈ L. Note that if D ⊆ C, then the representations G D and G C of an s-graph such that τ (G) ⊆ D are strongly FO-equivalent.

  and the following conditions hold: M 1 : Y ⊆ E G where G := G -Z is the subgraph of G obtained by deleting all vertices and edges of Z, and all edges incident with vertices of Z, M 2 : X is a cross-section of the equivalence relation ≈ Y on V G (= V G -Z) such that x ≈ Y y if and only if x and y are linked by a path with all its edges in Y .

  We denote H by G[X, Y, Z]. There exists a noncopying definition scheme D with three parameters such that D( G , (X, Y, Z)) = G[X, Y, Z] for every triple of sets (X, Y, Z) satisfying conditions M 1 and M 2 . It is thus clear that D( G ) is the set of concrete minors of G. The construction of D uses Property P2 of Proposition 5.11 and Example 7.3(1).

  Proposition 7.48 For each finite set C of source labels, the mapping t → val (t) C with domainT (F HR C ) is a parameterless MS-transduction of type R F HR C → R m,C . If D ⊆ C, then the mapping t → val (t) D for τ (val (t)) ⊆ D (or for τ (val (t)) = D) is also a parameterless MS-transduction, of type R F HR C → R m,D .These results extend to labelled graphs.

  labelled s-graphs of bounded type, we let L * be the set of (D ∪ K, Λ)-labelled graphs G D for G ∈ L, where D is the smallest set of source labels such that τ (G) ⊆ D for every G ∈ L. Clearly, Inc(L * ) = Inc(L) * , L * = L and if all s-graphs in L are simple, L * = L .Theorem 7.50 Let F be a finite functional signature, let K and Λ be finite sets of vertex and edge labels and let D be a finite set of source labels. Letσ : T (F ) → J S [K,Λ] [D] be a CMS 1,2 -transduction, given by a definition scheme of type R F → R m,D,[K,Λ] .(1) One can construct a finite set C of source labels that includes D and an invertible MS-transduction µ :T (F ) → T (F HR C ,[K,Λ] ) such that σ = µ • val . If σ is parameterless, then so is µ. (2) One can construct a regular language M ⊆ T (F HR C ,[K,Λ] -{∅}) ∪ {∅} such that σ(T (F )) = val (M ). The set σ(T (F )) is HR-equational. Furthermore, if Dom(σ) ⊆ Slim(F ), then there exists k ≥ 1 such that µ(T (F )) ⊆ Slim k (F HR C ,[K,Λ]) and M is a set of k-slim terms. 24Proof: The proof of Assertion (2), from Assertion (1), is entirely similar to the one of Theorem 7.34. Hence, it remains to prove Assertion[START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. We first consider the case where D = ∅, i.e., σ(T (F )) is a set of labelled graphs (without sources). Moreover, we assume that the graphs in σ(T (F )) are directed and that the definition scheme has type R F → R d m,[K,Λ] . The proof extends without any difficulty to undirected graphs. The relation τ := {(t, Inc(G)) | (t, G) ∈ σ} is a CMS 1,1 -transduction : T (F ) → GP [K∪Λ,[2]] [∅]. Hence, by Theorem 7.34, we obtain a finite set C of source labels and an invertible MS-transduction µ 1 : T (F ) → T (F VR C,[K∪Λ,[2]]

  (a) (Syn(t), f ) is a tree-decomposition of Inc(G), each box of which has at most 12 • |C| elements. (b) each e ∈ E G is a leaf u of Syn(t), f (u) = {u} and the box f (v) where v is the father of u contains e and its end vertices, Property (b) is guaranteed by Lemma 2.116(

  Theorem 7.54 (Reduction Theorem) Let r ∈ N , let τ be a C r MS-transduction : STR(R) → STR(R ) and let C ⊆ STR(R). If C has a decidable C r MS-satisfiability problem, then so has τ (C).

  Example 5.2(1)). Clearly the CMS-satisfiability problem for D := {D n | n ≥ 1} is decidable. Proposition 7.60 If L is MS+Eq or CMS+P 23 , then the L-satisfiability problem for D is undecidable. intervals ]y , y] where y and y are consecutive elements of X. (We define ]y , y] as {z | y < z ≤ y}). Clearly I(X) consists of |X| pairwise disjoint intervals and [x] is their union.

  and β ∈ Γ * , and one of the following three cases holds: (a) ψ = up, β = ε, and s |= ∀x 1 [ϕ(x 1 ) ⇒ ∃ y. son(y, x 1 )] for every s ∈ T (F ), or (b) ψ = stay and β ∈ Γ, or (c) there exists i ∈ [ρ(F )] such that ψ = down i , β ∈ Γ 2 , and s |= ∀x 1 [ϕ(x 1 ) ⇒ ∃ y. son i (x 1 , y)] for every s ∈ T (F ).

  Theorem 8.18 Let D 1 , D 2 and C 1 be finite sets of port labels with D 1 ⊆ C 1 , and let τ :GP[D 1 ] → GP[D 2 ]be a parameterless monadic second-order transduction of p-graphs, given by a definition scheme of type R s,D1 → R s,D2 . One can construct a finite set of port labels C 2 that includes D 2 and a deterministic tree-walking pushdown transducer M with input signature F VR C1 and output signature F VR C2 such that τ (val (t)) = val (τ M (t)) for every t ∈ T (F VR C1 ) with π(val (t)) ⊆ D 1 . A similar result holds for labelled p-graphs.Proof: By Proposition 7.30 and Theorem 7.14, the mapping val • τ is a parameterless monadic second-order transduction :T (F VR C1 ) → GP[D 2 ].Hence, by Theorem 7.34 one can construct C 2 and a parameterless (invertible) MStransduction µ : T (F VR C1 ) → T (F VR C2 ) such that val •τ = µ•val . By Theorem 8.13, µ can be computed by a deterministic tree-walking pushdown transducer M . Remarks 8.19

  Proposition 8.24 The classes MSOT and REL • DMSOT are equal. Proof: The inclusion MSOT ⊆ REL • DMSOT is immediate from Proposition 7.24(2). The other inclusion follows from the fact that REL ⊆ MSOT and the closure of the class MSOT under composition.

Proposition 9. 1

 1 Every ternary relation on D satisfying Conditions (B1)-(B6) is B(≤) for some linear order ≤, hence is a betweenness relation.Proof: Let B be a ternary relation satisfying properties (B1)-(B6). For every two distinct elements u and v of D, we define[[u, v]] := {x ∈ D | B(u, x, v)}.We choose a pair {a, b} such that[[a, b]] has a maximal cardinality. We first make some observations about a and b.First, there is no element u satisfying B(u, a, b). Assume on the contrary that we have B(u, a, b). Then (B5) implies that, for everyx in [[a, b]], we have B(u, x, b). Hence [[a, b]] ∪ {a} ⊆ [[u, b]] and[[a, b]] is not of maximal cardinality by (B1). We can exchange a and b in this proof, hence we cannot have B(u, b, a). By (B2), we cannot have B(a, b, u) for any u. Second, we have D = {a, b} ∪ [[a, b]]. Because if some element u is not in {a, b}, we must have by (B6): B(a, u, b) ∨ B(u, b, a) ∨ B(b, a, u). By (B2) and the first observations, we must have B(a, u, b), hence u ∈ [[a, b]].

1 )

 1 We let D := {a, b, c, d, e, f }. The set X := {(a, b, c), (e, d, c), (d, e, f )} is consistent because X ⊆ B(≤ 0 ) where a < 0 b < 0 c < 0 d < 0 e < 0 f . In order to illustrate the proof of Proposition 9.3, we consider several sets Y . If Y := {(a, b, c), (d, e, f )}, then Z(Y ) = {(a, b), (b, c), (d, e), (e, f ), (c, d)}. Its reflexive and transitive closure is the linear order ≤ 0 . If Y := {(d, e, f ), (e, d, c)}, then Z(Y ) contains (d, e) and (e, d), hence is not acyclic. Let us now take Y := {(a, b, c), (e, d, c)}. Then Z(Y ) = {(a, b), (b, c), (e, d),

  Definition 9.10 (The incidence graph of a relational structure) Let R be a relational signature. We define R Inc as the binary relational signature R ∪ In R where In R := {in i | 1 ≤ i ≤ ρ(R)}. The symbols of R are all unary in R Inc and those of In R are binary.The incidence graph of a concrete R-structure S = D S , (R S ) R∈R is the concrete R Inc -structure Inc(S) defined asD S ∪ T S , (R Inc(S) ) R∈R , in 1 Inc(S) , . . . , in k Inc(S)where k := ρ(R) and:T S := {(R, d 1 , . . . , d ρ(R) ) | R ∈ R + , (d 1 , . . . , d ρ(R) ) ∈ R S }, if R ∈ R + , then: R Inc(S) (d) :⇐⇒ d = (R, d 1 , . . . , d ρ(R) ) ∈ T S for some d 1 , . . . , d ρ(R) ∈ D S , if R = c ∈ R 0 , then:R Inc(S) (d) :⇐⇒ d = c S , and for all i = 1, . . . , k: in i Inc(S) (d, d ) :⇐⇒ d ∈ T S , d ∈ D S and d = (R, d 1 , . . . , d ρ(R) ) for some R ∈ R + and d 1 , . . . , d ρ(R) such that d = d i .

T

  S := {(R, d 1 , . . . , d ρ(R) ) | R ∈ R, ρ(R) > 1, (d 1 , . . . , d ρ(R) ) ∈ R S },andInc (S) := D S ∪ T S , (R S ) R∈R1 , (R Inc(S) ) R∈R-R1 , in 1 Inc (S) , . . . , in k Inc (S) ,

  (i) D S = {f (u) | u ∈ N T }; (ii) for every R ∈ R + and (d 1 , . . . , d n ) ∈ R S , there exists a box f (u) containing d 1 , . . . , d n ; (iii) for every d ∈ D S , the set f -1 (d) := {u ∈ N T | d ∈ f (u)} is connected in T .

  (f (u) ∩ D S ) ∪ {d ∈ D S | d belongs to some tuple in f (u) ∩ T S }.This means that, in a box f (u), we replace each tuple (R,d 1 , . . . , d n ) by the elements d 1 , . . . , d n of D S . It follows that |f (u)| ≤ (k + 1) • ρ(R) because if p := |f (u)∩D S | and q := |f (u)∩T S |, then p+q ≤ k+1 and |f (u)| ≤ p+q•ρ(R) ≤ (k + 1) • ρ(R).It remains to check that (Z, f ) is a tree-decomposition. We first MS-definable. This class has also tree-width at most k+1 by Proposition 9.14(2), hence it is HR-equational by Example 4.3(8) and the Filtering Theorem (Corollary 5.71).

∃u 1 [

 1 son 1 (u, u 1 ) ∧ u 1 ∈ C θ R [t1/x1,...,tn/xn] ].

R,

  more simply denoted by F relVR since R is fixed. Each finite subset C of A is a sort and the corresponding domain is STR(R ∪ Lab(C)). The constant symbols of F relVR of sort C are a C for each a in C and ∅ C . Its operations are the disjoint union ⊕ C,C of type C × C → C ∪ C and the following unary operations: the tuple-creating operation add c1,...,c k ,R,C of type C → C for every k > 0, R ∈ R k and c 1 , . . . , c k ∈ C, and the label-modifying operation mdf Z,C,C of type C → C for every Z ⊆ C × C . The symbol ∅ C denotes the empty (R ∪ Lab(C))-structure and a C denotes the (R∪Lab(C))-structure S having a unique element that belongs to lab aS , with all other relations being empty. Hence, a C is another notation for ♦ {laba},R∪Lab(C) (cf. Definition 5.62, Section 5.3.7). The unary operations are as follows, for S in STR c (R ∪ Lab(C)). We define add c1,...,c k ,R,C (S) as the concrete (R ∪ Lab(C))-structure S such that D S := D S , R S := R S ∪ {(x 1 , . . . , x k ) | x i ∈ lab ciS for each i ∈ [k]}, U S := U S for every U ∈ (R -{R}) ∪ Lab(C).

C

  ) where C is a finite subset of A such that |C | ≤ |D S | + |C|: the proof of Proposition 2.104(1) extends easily.

  Examples 9.30 We clarify these definitions with some examples.(1) If G is a p-graph of type included in C, represented by the relational structure G C := V G , edg G , (lab aG ) a∈C , then:--→ add a,b (G) = G if and only if add laba,lab b ,edg,h ( G C ) = G Cwhere h is the identity :[2] → [2]. Also, if h : C → C, then relab h (G) = G if and only if relab g ( G C ) = G Cwhere g(edg) := edg and g(lab a ) := lab h (a) . Hence, F VR C is a subsignature of F redQF Rs,Lab(C) .

  nc (R ∪ B)) where the auxiliary set B consists of relation symbols of arity at most 3. (d) In Property (3) it can be required additionally that M is a subset of T (F redQF R,B

8

  We recall from Definition 5.1 that S is a substructure of S if D S ⊆ D S and R S = R S ∩ D ρ(R) S for every R ∈ R. It generalizes the notion of an induced subgraph.Proof:(1) If G has clique-width k, then it is the value of a term t in T (F VR C,[K,Λ] ) where |C| = k. Since F VR C,[K,Λ] is a subsignature of F redQF R s,[K,Λ] ,Lab(C) (cf.Example 9.30(1)) and Lab(C) = |C|, we get the first inequality. (We may have a strict inequality because the graphs defined by the terms in T (F redQF R s,[K,Λ] ,Lab(C) ) may have several labels from C attached to the same vertex. Hence, these terms are not necessarily terms in T (F VR C,[K,Λ] ).) The second inequality follows from Proposition 9.24 and Corollary 7.38(2). The function f is computable because Proposition 9.24 is effective (and see the last sentence of the proof of Corollary 7.38(2)).

  R,B such that B = w R (S). The elements of D S are in bijection with the occurrences of the constant symbols in t different from ∅ because the unary operations of F redQF R,B are all domain preserving. Let us replace by ∅ those occurrences that correspond to the elements of D S -D S . We obtain a term t in T (F redQF R,B ) that evaluates to the structure S[D S ] = S (because for every unary operation g in F redQF R,B , every structure U and every set D ⊆ D U , we have g(T )[D] = g(T [D]).) Hence w R (S ) ≤ w R (S). If needed, we can eliminate ∅ from t (cf. Remark 9.32(d)).

  Definition 9.35 (Unions of concrete structures and transductions) Let R, R and R be relational signatures without constant symbols. If S ∈ STR c (R) and S ∈ STR c (R ), then we denote by S + S the concrete R ∪ Rstructure T such that: D T := D S ∪ D S (D S and D S need not be disjoint), R T

  Definition 9.36 (Uniformly k-sparse relational structures) Let k be a positive integer. A relational structureS is k-sparse if |T S | ≤ k • |D S |. It is uniformly k-sparse if S[X] is k-sparse for every subset X of D S .We denote by US k (R) the class of uniformly k-sparse (concrete) R-structures.

  in 1U := {((x, (1, R)), (x, 0)) | (x, (1, R)) ∈ D U } ∪ {((y, (1 + i, R)), (x, 0)) | (y, (1 + i, R)) ∈ D U , x = p i (y)} ∪ {((x, (1 + k + i, R)), (x, 0)) | (x, (1 + k + i, R)) ∈ D U },and similarly for in 2U .The final transduction τ := τ 1 • τ 2 is parameter-invariant.

  (i) N F ⊆ E H , (ii) if e is a son of e, then |vert H (e) ∩ vert H (e )| = 1, (iii) if e, e ∈ N F , e = e and vert H (e) ∩ vert H (e ) = ∅, then either e and e are adjacent in F or they are two sons of some hyperedge e such that vert H (e ) ∩ vert H (e) = vert H (e ) ∩ vert H (e ) = vert H (e) ∩ vert H (e ). 16

  edges 1 → 2, 2 → 3, 2 → 4, etc. See Figure 9.2. The hyperedges marked * in Figure 9.1 are not in N F .

Figure 9

 9 Figure 9.2: A normal and spanning forest in H.

  Proposition 9.50 There exists a pair of MS formulas (χ(Y 1 , Y 2 ), θ(Y 1 , Y 2 , x 1 , x 2 )) over the signature {in} such that for every hypergraph H of minimal rank at least 2, and all sets N, R ⊆ E H :(i) Inc(H) |= χ(N, R) ifand only if there exists a normal and spanning Hforest F such that N F = N and roots F = R, (ii) for every (N, R) satisfying χ(N, R) and every e, e ∈ N , we have Inc(H) |= θ(N, R, e, e ) if and only if e ≤ F e where F is the H-forest such that N F = N and roots F = R. 18 Proof: Our first objective is to construct a formula θ(Y 1 , Y 2 , x 1 , x 2 ) such that, if F is an H-forest in a hypergraph H of minimal rank at least 2, then, for every e, e ∈ N F : Inc(H) |= θ(N F , roots F , e, e ) if and only if e ≤ F e .

  It expresses, for arbitrary subsets N and R of E H , that the tuple N, son, R is a normal and spanning H-forest, where son is the set of all (e , e) ∈ N × N such that e = e, Inc(H) |= θ(N, R, e, e ) and vert H (e) ∩ vert H (e ) = ∅. Definition 9.51 (Splittings of hypergraphs) A splitting of a hypergraph H is a pair (H 1 , H 2 ) of hypergraphs related to H as follows: (a) V H1 = V H2 = V H , (b) E H1 ∪ E H2 = E H , (c) if e ∈ E H1 ∩ E H2 , then vert H (e) = vert H1 (e) ∪ vert H2 (e) and vert H1 (e) ∩ vert H2 (e) = ∅, (d) if e ∈ E H1 -E H2 , then vert H (e) = vert H1 (e), (e) if e ∈ E H2 -E H1 , then vert H (e) = vert H2 (e).

1

 1 For every e ∈ E H , the set Min(e) is a proper subset of vert H (e). Proof:Let e ∈ E H , so |vert H (e)| ≥ 2. If vert H (e) ∩ V (F ) = {x}, thenMin(e) = {x} and Min(e) is a proper subset of vert H (e). Otherwise, since F is normal, the set vert H (e) ∩ V (F ) contains two elements x and y such that x F y. If x ≺ F y, then y / ∈ Min(e). If x ≡ F y, then either x ≺ F,U y and y / ∈ Min(e), or y ≺ F,U x and x / ∈ Min(e). In all cases, Min(e) is a proper subset of vert H (e).

H 1

 1 the hyperedges of rank 1 of H. By the claim, if e has rank p ∈ [2, m], then |Min(e)| ≤ p -1 and |vert H (e) -Min(e)| ≤ p -1. It follows that H 1 and H 2 have maximal ranks at most m -1.

  p H := {(x 1 , . . . , x p ) | vert H (e) = (x 1 , . . . , x p ) for some e ∈ E H of rank p}. It is a faithful representation of simple orientations of hypergraphs of maximal rank m. These definitions extend those of Definition 9.48(a).

  9.4.2 Uniformly k-sparse relational structuresWe recall from Definition 9.36 that a relational structure S is uniformly k-sparse if |T S[X] | ≤ k • |X| for every subset X of D S , where, by Definition 9.10, T S is the set of tuples of a structure S. Similarly, a hypergraphH is k-sparse if |E H | ≤ k • |V H |, and it is uniformly k-sparse if, for every X ⊆ V H , the induced hypergraph H[X] is k-sparse (the hyperedges of H[X]are those of H with all their vertices in X). For k ≥ 1 and m ≥ 2, we let US k,m denote the class of uniformly k-sparse simple m-hypergraphs. Hence, we have US k,2 = US k .

  Definition 9.57 (Semi-orientations of hypergraphs) A semi-orientation of a hypergraph H is a pair -→ H = (H, hd ) where hd is a mapping E H → V H such that hd (e) ∈ vert H (e) for every e ∈ E H . We call hd (e) the head of e. The indegree of a vertex v in -→ H is the number indeg-→ H (v) of hyperedges whose head is v. The indegree of -→ H is the maximal indegree of its vertices. We let Dir ( -→ H ) be the simple loop-free directed graph D such that V D := V H and edg D := {(x, y) | x ∈ vert H (e) and y = hd (e) = x for some e ∈ E H }. Clearly, the indegree of Dir ( -→ H ) is at most m -1 times the indegree of -→ H . If H has maximal rank m, then we define the relational structure -→ H similar to H (cf. Definition 9.48(a)) by using, for each p ∈ [m], the p-ary relation edg p , . . . , x p ) ∈ edg p -→ H if and only if vert H (e) = {x 1 , . . . , x p } for some e ∈ E H of rank p such that x p = hd (e), instead of edg p H . It is a faithful representation of semi-orientations of simple hypergraphs of maximal rank m.We prove two combinatorial properties of semi-orientations; the first generalizes Proposition 9.40[START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. Proposition 9.58 Let k ≥ 1 and m ≥ 2.(1) A hypergraph is uniformly k-sparse if and only if it has a semi-orientation of indegree at most k.(2) A hypergraph H of maximal rank at most m having a semi-orientation -→ H of indegree at most k has a semi-orientation -→ K of indegree at most mk 2 such that Dir ( -→ K ) ∈ S d * , whence Dir ( -→ K ) ∈ S d k where k := (m -1)mk 2 .

  Figure 9.3: A semi-oriented hypergraph -→ H .

Figure 9 .

 9 Figure 9.3 shows a semi-orientation -→ H of a 4-hypergraph H with hyperedges U , X, Y and Z represented by quadrangles. Their respective heads 0, 5, 0 and 5 are shown by small triangles. Figure 9.4 shows the directed graph Dir ( -→ H ) and Figure 9.5 shows the derived 3-hypergraph ∂( -→ H ) with the hyperedges represented by triangles. More comments will be given in the proof of Theorem 9.61.For a simple m-hypergraph H, we will omit the relations edg 1 H , . . . , edg m-1

Figure

  Figure 9.4: The graph Dir ( -→ H ).

Figure

  Figure 9.5: The derived 3-hypergraph ∂( -→ H ).

(x 1

 1 , . . . , x m ) ∈ edg m - → H if and only if (x 1 , . . . , x m ) ∈ edg m H and γ(x i ) → Q γ(x m ) for every i ∈ [m -1].

  as shown in Case 3 of the proof of Theorem 7.14, it is a concrete k1 k 2 -copying MS-transduction provided the set (D S × [k 1 ]) × [k 2 ] (which contains D U ) is "identified" with the set D S ×[k 1 k 2 ] (where, in particular, ((a, 1), 1) is identified with (a, 1)). Clearly, this identification turns τ 1 • τ 2 into a domain-preserving MS-transduction in which D S is represented by the copy D S × {1}. Thus,f 1 • f 2 is a domain-preserving MS-transduction on C 1 , realized by τ 1 • τ 2 . 25Theorem 9.61 Let k ≥ 1 and m ≥ 2. The mapping Inc that transforms H into Inc(H) is a domain-extending MS-transduction on US k,m .

  e) := {(x 1 , y), . . . , (x m-1 , y)} ⊆ edg D if vert H (e) = {x 1 , . . . , x m-1 , y} and y = hd (e), i.e., if (x 1 , . . . , x m-1 , y) ∈ edg m - → H . Let us observe that for every e ∈ E ∂( - → H ) , we have: {vert D (d) | d ∈ vert ∂( - → H ) (e)} = vert H (e). (9.1) This is immediate from the definition of ∂( -→ H ), because vert D ((x i , y)) = {x i , y}. Let us look again at Figures 9.3-9.5. Figure 9.3 shows a semi-orientation -→ H of a 4-hypergraph H with vertices 0, 1, . . . , 8 and hyperedges U, X, Y, Z with respective heads 0,5,0,5. Figure 9.4 shows the directed graph D = Dir ( -→ H ). Its edge c from 4 to 0 "comes from" each of the two hyperedges U and Y . This fact is also visible in the 3-hypergraph ∂( -→ H ) of Figure 9.5 because the edge c is a vertex common to the hyperedges U and Y . The vertices of ∂( -→ H ) are the edges of D. The hyperedge U has rank 4 in H and rank 3 in ∂( -→ H ); its vertices are the edges a = (1, 0), b = (2, 0) and c = (4, 0) of D.

  Claim 9.61.1 The (m -1)-hypergraph ∂( -→ H ) is uniformly 2k-sparse. Proof: Let X ⊆ V ∂( - → H ) = E D and Y := {vert D (d) | d ∈ X} ⊆ V H . We have E ∂( - → H ) = E H but these hyperedges have different sets of vertices in ∂( -→ H ) and in H. It follows from the definition of ∂( -→ H ) that E ∂( - → H )[X] ⊆ E H[Y ] : by Equality (9.1), if vert ∂( - → H ) (e) ⊆ X, then vert H (e) ⊆ Y . Since H is uniformly k-sparse, we have |E H[Y ] | ≤ k • |Y | and so |E ∂( - → H )[X] | ≤ k • |Y | ≤ 2k • |X|, since we have |Y | ≤ 2 • |X|. Hence ∂( -→ H) is uniformly 2k-sparse, which completes the proof of the claim.We now consider the definability of D = Dir ( . We have-→ H +Inc(D) = V H ∪E D , edg m - → H , in 1,D , in 2,D since V D = V H . (We use here the union of concrete structures, cf. Definition 9.35.) We have also-→ H + Inc(D) + ∂( -→ H ) = V H ∪ E D , edg m - → H , in 1,D , in 2,D , edg m-we have V ∂( - → H ) = E D . Note that if S is a structure isomorphic to V H ∪ E D , edg m - → H , in 1,D , in 2,D ,then the subset of its domain corresponding to E D is the set of elements e of D S such that (e, x) ∈ in 1,S for some x. It follows that a concrete transduction intended to receive input -→ H + Inc(D) can be described in terms of the sets V H and E D and the relations edg m - → H , in 1,D and in 2,D . For an input structure S isomorphic to -→ H + Inc(D), it will output structures isomorphic to those obtained for input -→ H + Inc(D). The same holds for -→ H + Inc(D) + ∂( -→ H ) and the similar structures defined below. The constructions of the next claim depend on the fixed integers k and m. Claim 9.61.2 The mapping τ that transforms the structure is a domain-extending MS-transduction on s-US k,m . Proof: We have the following MS-transductions: τ 2 , domain-preserving, that transforms -→ H into D: its existence is clear from the definition of D, and τ 3 , domain-extending, that transforms D into Inc(D), by Theorem 9.44 because D = Dir ( -→ H ) is of indegree at most k := (m -1)mk 2 and hence is uniformly k -sparse. The definition schemes of these two MS-transductions can be combined, by Definition 9.35, into one for τ 4 := Id 1 + τ 2 • τ 3 that transforms transduction τ 5 because we have: (e 1 , . . . , e m-1 ) ∈ edg m-1 ∂( -→ H ) if and only if Proof of Theorem 9.38: For R = ∅ the result is trivial. If R = {R 1 , . . . , R p } with p ≥ 1, then every structure S ∈ US k (R) is the union S = S 1 + • • • + S p of the structures S i ∈ US k ({R i }) such that S i := D S , R iS (cf. Definition 9.35 for unions of concrete structures). If we have domain-extending MS-transductions τ i that transform S i into Inc(S i ) for each i, then we can combine (cf. Definition 9.35) their definition schemes into one for a domain-extending MS-transduction τ that transforms S into Inc(S). In particular, if

  1 , . . . , x n ) in R S . The structure S can be written S = S 1 +• • •+S n where, for every m ∈ [n], S m is the structure with domain D S and relation R Sm consisting of the tuples of R S having exactly m pairwise distinct elements. As above, it suffices to define, for each m ∈ [n], a domain-extending MS-transduction τ m that transforms S m into Inc(S m ), and then to take their sum. The case m = 1 is easy, with a 2-copying MS-transduction τ 1 (cf. our comparison of Inc and Inc in Definition 9.10). It remains to consider the case where 1 < m ≤ n and to construct τ m .For an n-ary R, we let US k,m ({R}) be the class of structuresS := D S , R S in US k ({R}) such that, for every (x 1 , . . . , x n ) ∈ R S , the set {x i | i ∈ [n]} has cardinality m. For S ∈ US k,m ({R}), we let H be the simple m-hypergraph such that V H := D S and E H is the set of sets {x i | i ∈ [n]} such that (x 1 , . . . , x n ) ∈ R S withvert H (e) := e for every e ∈ E H . (Note that each e is defined as a subset of D S .) A domain-preserving MS-transduction can transform S = D S , R S into the structure H := D S , edg m H , and a domain-extending MS-transduction can transform H into the structure Inc(H) = D S ∪ E H , in H , by Theorem 9.61, since S, and hence H, is uniformly k-sparse. Thus, the mapping that transforms S into the structure D S ∪ E H , in H , R S , which is S + Inc(H), is a domainextending MS-transduction µ 1 on the class US k,m ({R}).

  Theorem 9.63 Let k, r ∈ N and i, j ∈ [2]. Let R be a relational signature, C be a set of uniformly k-sparse R-structures and D ⊆ C. Assertions (1), (2) and (5) of Theorem 9.62 hold for C and D.

  domain of a binary relation R ⊆ A × B is denoted by Dom(R) ⊆ A, and its image isR(A) ⊆ B. Thus, Dom(R) = {a ∈ A | (a, b) ∈ R for some b ∈ B} = R -1 (B). For a subset C of A, R(C) = {b ∈ B | (a, b) ∈ R for some a ∈ C}.The restriction of a mapping f :A → B to a subset C of A is denoted by f C. Two mappings f : A → B and g : A → B agree if f (a) = g(a) for every a ∈ A ∩ A , i.e., if f (A ∩ A ) = g (A ∩ A ).We denote by f ∪ g their common extension into a mapping : A ∪ A → B ∪ B .

  son t is the binary relation such that son t (u, v) holds if and only if v is a son of u in the tree 38 t;

• lab ⊕t , lab ⊗t and lab 1t are the unary relations such that lab ⊕t (u) holds if and only if u is an occurrence of ⊕ in t (i.e., is labelled by ⊕ as a node of the tree t) and similarly for lab ⊗t and lab 1t .

  1,1 and MS 2,2 are incomparable, that MS 1,1 ∪ MS 2,2 is a proper subclass of MS 2,1 and that MS 1,2 is a proper subclass of MS 1,1 ∩ MS 2,2 .

	Example 1.45 (The line graph transduction)

  and only if H and G are the isomorphism classes of concrete graphs H and G such that H ¢ G . Proposition 2.18 The relation ¢ is a partial order on abstract graphs.

Proof: Let G and H be abstract graphs. Clearly G¢G. Assume that H ¢G¢H, which means that H ¢ G and G ¢ H where H

  . However the intermediate steps of the transformation of a term into another one may use functions of the signature that are not in a fixed finite superset F HR

	C	of F HR C , as required. Furthermore, the (open) problem is to
	have C as small as possible.
	Proposition 2.49 Every term t over F HR C equivalent to a term t over F HR C written without fg ∅ , ∅ and the source renaming evaluating to a nonempty s-graph is
	operations, and such that | t | ≤ |t|.

  If t 1 = t 2 t 3 , then t = ren h (t 2 ) ren h (t 3 ) and the correctness follows from Equality (8). Perm f (C). It is clear by this inductive construction that t has no occurrences of renaming operations, that t is equivalent to t and that | t | = |t| -|t| ren , where |t| ren is the number of occurrences of renaming operations in t.

	(4.2) (4.3) If t 1 = fg B (t 2 ), then t = fg h(B) ( ren h (t 2 )) and the correctness follows
	from Equality (11).
	(4.4) If t 1 = ren h (t 2 ), then t = ren h•h (t 2 ) and the correctness follows
	from Equality (7).
	The inductive construction is well defined because in each case, t is defined
	either directly as in Cases (1) and (4.1) or in terms of t for terms t of size
	strictly smaller than t. For Case (4.4), we observe that if h, h ∈ Perm f (C) then
	h•h ∈
	1) If t 1 is a constant symbol, then t is the constant symbol obtained by
	Equalities (12) -(15) and (12 ) -(15 ) of Proposition 2.48.

  and so twd (C n ) ≥ 2 (and we know from Examples 2.56(3,6) that twd (C n ) ≤ 2).

	Proposition 2.59 If a graph H is obtained from a graph G by deleting or
	contracting an edge, or by deleting a vertex and the edges incident with this
	vertex, then twd

  • C is the clique K |C| . It follows from Proposition 2.58 and Remark 2.55(b) that an s-graph G of type included in C has tree-width at most k if and only if the (undirected) graph fg C (und (G) K C ) has tree-width at most k (where und (G) := und (G • ), slab G ), hence, if and only if the graph core(fg C (und (G) K C )) has no minor in Ω k .

  and [*Gol]. Let C be the class of nonempty, connected, simple and loop-free undirected graphs. Let k ∈ N + . A graph G in C is k-chordal if it has a tree-decomposition, each box of which is a nonempty clique with at most k vertices. (The graph of Figure

	Definition 2.71 (Chordal graphs)

of G of the same width can be obtained in time O(|E G | + |N T |) by a depth-first search of T during which each edge is assigned to the first box to which both its ends belong. Then Proposition 2.82(1) can be applied. The total time is

  O(|E G | + |N T |). Note that, in particular, if G is simple, then the total time is O(|N T |), cf. Remark 2.55(c).

	• f ) is a rich tree-
	decomposition of G (cf. Proposition 2.44(1)). The total time is O(|t|), assuming
	that w -1 can be applied in constant time.
	If (T, f ) is a tree-decomposition of G of width at most |C| -1, then a rich
	tree-decomposition (T, f )

is the set GP[C] of p-graphs of type included in C, and the second one is the subalgebra GP gen [C] of GP[C] that is generated by F VR

  C . Its domain GP gen [C] consists of the p-graphs that are the values of terms over F VR C . Similar notions can be defined for undirected p-graphs: GP u [C] and GP gen,u [C]. We will shortly extend these definitions to labelled p-graphs.

		VRu . Each term t over F VR evaluates into a p-graph
	t GP , also denoted by val (t). It t is a term over F VR with variables, then t GP
	denotes the corresponding derived operation.
	The signatures F VR C	and F VRu C	for C ⊆ A are obtained by restricting a, b to
	C and h to [C → C] f in the above definitions. It is easy to show (by induction
	on t) that π(val (t)) ⊆ C for every t ∈ F VR C , cf. Lemma 2.36.
	As for the HR algebra (cf. Definition 2.32 and Remark 2.39(1)), we can
	define two F VR C -algebras that are subalgebras of GP. The first one is GP[C] of
	which the domain Examples 2.88
	(1) The p-graph G of type π(G) = {1, 2} in Figure 2.11 is the value of the
	term relab 3→2

  R C and h := h ∪ h C satisfy the requirements. (The operation relab h is equivalent to relab h • relab h C by Equality (4) of Proposition 2.101).

  VR C with value G, where C is chosen such that |C| = k and π(G) ⊆ C (see Definition 2.89). By Corollary 2.102 it needs only consider terms with |V G | occurrences of constant symbols. Moreover, by the ⊕-free case of Proposition 2.103, it may additionally restrict attention to terms t that satisfy the following property: if c[s] is a subterm of t where c ∈ Ctxt(F VR C

  the substitution of H to the vertex u. Informally, the vertex u is replaced by H and each vertex w of H is linked to each neighbor v of u in G in the same way as u is linked to v, and w is an a-port in G[u ← H] if u is an a-port in G. We will define a term evaluating to G[u ← H] from terms evaluating to G and to H.We denote by relab D→a the mapping relab h such that h(d) = a for all d ∈ D and h(b) = b for all b ∈ A -D.

	Proposition 2.110
	(1) Let G be the value of a term in T (F cVR C

  C if |D| ≤ |C| and that C ⊂ D if |C| < |D|. It follows then that |C ∪ D| = max{|C|, |D|} and that cwd

	1) The equality G[u ← H] = val (t ) where t := t[relab π(H)→a (t )/a(u)]
	can be proved by induction on the structure of t.
	(2) By changing if necessary the port labels used in t , one can assume
	that D ⊆

where w is any vertex of H. Hence by Proposition 2.105(1) we have cwd

  Id ∅ where Id is the identity on C, and subterms t 1 ⊕ t 2 by t 1 ⊗ ∅,Id t 2 .

One can also transform a term t over F VR C -{∅} (see Corollary 2.102) into an equivalent term t over F κVR C -{∅}. This can be shown by induction on the size of t. Let t = c[t 1 ] where c ∈ Ctxt(F VR C ) is written without ⊕, and t 1 is either a constant symbol or of the form t 2 ⊕ t 3 . By Proposition 2.103, t is equivalent to a term relab h

  and t/u and t/v have the same type. By Proposition 2.51, there exist an s-graph H and operations ren h and fg B such that c JS

  lab H , slab H where V H is the set of vertices, E H is the set of edges and hyperedges, lab H is a partial function : E H → U , the domain of which is the set of hyperedges, vert H is a mapping with domain E H satisfying the following conditions: -if e is an edge (in this case lab H (e) is undefined 11 ) then vert H (e) is, as in Definition 2.9, a set of 1 or 2 vertices (if H is defined as undirected ) or an ordered pair of (possibly equal) vertices (if H is defined as directed ); -if lab H (e) = x ∈ U then vert H (e) is an injective mapping from τ (x) to V H , and we call τ (e) := τ (x) the type of e, slab H : V H → A is as in Definition 2.24. The elements of E H that have a label can be seen as hyperedges: their sets of vertices have cardinalities not restricted to 1 or 2. Their vertices are referred to by elements of A. A hyperedge of type ∅ has no vertex. The notations Src(H), τ (H), src H are defined from slab H as in Definition 2.24. Hence H has sources unless its type τ (H) is empty.

	Definition 4.21 (Hyperedge replacement)

  t [E] has finitely many sorts. Hence, if L is recognizable in JS t [E], it is also recognizable in JS[E] because every locally finite congruence on JS t [E] is a finite congruence on JS[E]. Let us conversely assume that L ⊆ J S[E] is recognizable in JS[E] with finite congruence ∼. This congruence may not be type-preserving. We define from it the equivalence relation ≈ by: G ≈ H if and only if τ (G) = τ (H) and G ∼ H. Since the sgraphs in J S[E] have finitely many possible types (the subsets of E), the typepreserving equivalence relation ≈ is finite. It is a congruence by Lemma 4.11. It saturates L hence witnesses its recognizability in the algebra JS t [E]. Thus, JS t [E] and JS[E] have the same recognizable sets. By Proposition 3.78(

  for some s-graph H that depends only on H 2 , . . . , H p . We show this by induction on the structure of c. If c = y 1 , we can take H := ∅. If c = y 1 P m e (and hence m = k), we can take H := e JN t (G, H 2 , . . . , H p ) which depends only on H 2 , . . . , H p because e has no occurrence of y 1 . If c = d P m e and d = y 1 has an occurrence of y 1 , then K = d JN t (G, H 2 , . . . , H p ) P m H e where H e := e JN t (G, H 2 , . . . , H p ) depends only on H 2 , . . . , H p . Since the type of d JN t (G, H 2 , . . . , H p ) is ∅ (and hence m = 0), we obtain by induction that K = (G P k H d ) P 0 H e where H d depends only on H 2 , . . . , H p . But (G P k H d ) P 0 H e = G P k (H d H e ) (by the definition of the operations of F 2 and Equality (18) after Proposition 2.48). Hence we can take H := H d H e . Since P m is commutative, it suffices to consider these cases. Since the elements of L have type ∅, this observation implies that if G ≡ L G and c JN t (G, H 2 , . . . , H p

  H ∼ H and K ∼ K . If one of them, say H P k K, equals ∅, then both H and K are the empty graph and hence (by the definition of ∼) so are H , K and H P k K . If H P k K and H P k K are not empty, then we need only prove that H

The relation ∼ is a type-preserving equivalence relation. It has at most

|B k | + 2 |B k | classes of type [k],

hence is locally finite. The 3 classes of type ∅ are B 0 = {∅}, L -B 0 and J N 0 -(L ∪ B 0 ). Hence the set L is saturated by ∼. It remains to check that ∼ is a congruence on the algebra JN t .

Let us prove that H P k K ∼ H P k K , where H, H , K, K are of type [k],

  or n ≥ 2k + 3 and at least one of G and H has at most k + k 2 < (2k + 2) 2 vertices. It is clear that B k is finite, which gives the result, again with Lemma 4.35.If A is a set of positive integers, the set L

  by Example 2.56(3) and Proposition 2.62), each set L ∩ TWD(≤ k) is finite, hence HR-recognizable (by Example 4.30(3)). However, the syntactic congruence ≈ L of L has infinitely many classes of type ∅ because for every n, G n×n ≈ L H if and only if H = G n×n as one checks easily. Hence, L is not HR-recognizable.

Table 4

 4

	HR-equational	=⇒	VR-equational
	HR-recognizable ⇐= VR-recognizable

.1. Their converses do not hold, with the set {K n,n | n > 0} as a counter-example (see Example 4.54(5)). For sets of simple graphs without K n,n for some n, the two implications in Table

4

.1 are equivalences. In both these cases, the family of

Table 4 .

 4 1: Sets of simple graphs.

  is an end vertex of e}, and this structure belongs to STR c (R u m ) where R u m := {in}. If G is directed, its incidence graph Inc(G) is also simple, directed and bipartite, but with labelled edges. Its vertex set is V G ∪ E G and its edges are e → v labelled by 1 if e ∈ E G has tail v and e → v labelled by 2 if e ∈ E G has head v. If e is a loop, we have two edges e → v, with labels 1 and 2. We let then G

  type [2] with m + 2 vertices and a loop on the last vertex. Then, val (t n,m ) |= ϕ if and only if n ≥ m + 1. If MOD(ϕ) ⊆ STR(R) would be recognizable in STR f pres , then it would be recognizable in STR f,g pres by Proposition 3.56(3), and, by Propositions 3.56(2) and 3.60, the set of terms t n,m such that val (t n,m ) |= ϕ would be recognizable in T({f, g 1 , g 2 , 1 }), hence regular by Theorem 3.62. But this is not the case.

  ϕ} is CMS-definable. By Corollary 5.70(2), one can test whether L ∩ K is empty, which solves the CMS-satisfiability problem. By Corollary 5.70(3), one can test whether L ⊆ K, i.e., whether every p-graph in L satisfies ϕ, hence whether ϕ belongs to the CMS-theory of L. Hence the CMS-theory of L is decidable.

  is faithfully represented by the R Fstructure t := N t , (son i t ) 1≤i≤k , (lab f t ) f ∈F . Its domain N t is the set of nodes of the syntactic tree of t. The set lab f t is the set of occurrences of f in t and son i t is the set of pairs (u, v) such that v is the i-th son of u. Slightly different but equivalent relational structures have been introduced in Example 5.2(3) for representing terms 17 .If ϕ is a sentence in CMS(R F , ∅) or in CMS (R F , ∅), then we define

  1.7 Comparing sets of structures via monadic secondorder transductions Let C ⊆ STR(R) and C ⊆ STR(R ) be two sets of structures. We say that C is generated by C if C = τ (C) for some MS-transduction of type R → R and we denote this by C C. By Theorem 7.14 (about the composition of CMS-transductions), this relation is transitive, hence it is a quasi-order. We say that C and C are equivalent if C C and C C. They are equivalent if and only if they generate the same sets of structures.

  G , E G ) and each e ∈ E G has degree 2 in Inc(G), this graph is without K 3,3 . Hence we have twd (H) ≤ 12 • f τ (2 4k+4 + k + 1) -1 by Proposition 2.115(2). This defines the function g τ .

	1,1 -
	transduction (defined by the same definition scheme as τ ). Let Inc(H) ∈
	τ (Inc(G)) and twd (G) = k (without loss of generality we assume k ≥ 2).
	Then twd (Inc(G)) = k by Example 2.56(5), hence cwd (Inc(G)) ≤ 2 4k+4 + k + 1
	by Proposition 2.114(1.1) (we have two edge labels in Inc(G) if G is directed).
	Hence cwd (Inc(H)) ≤ f τ (2 4k+4 + k + 1) where f τ is the function of Corol-
	lary 7.38(2). Since Inc(G) is bipartite with bipartition (V

  see Examples 8.2 and 8.4.

	Remarks 8.29

  orientation H of H can be identified with the tuple V H , E H , vert H such that, for every e ∈ E H , vert H (e) is the enumeration of vert H (e) in increasing order with respect to < e . It can be faithfully represented by the following relational structure that can be considered as a refinement of Inc(H). We define Inc(H) := V H ∪ E H , order H where order H := {(e, x, y) | x, y ∈ vert H (e), x ≤ e y}. 20 This ternary relation can replace in H because (e, x, x) ∈ order H if and only if x ∈ vert H (e). We will say that H as above is simple if vert H (e) = vert H (e ) for e = e . If H has maximal rank m, then we define H := V H , edg 1 H , . . . , edg m H where, for each p, we let edg

  , it suffices to prove that the mapping µ that transforms -→ H into Inc(H), where -→ H is a semi-orientation of H, is a domain-extending MStransduction on s-US k,m . In fact, if τ 1 is the domain-preserving MS-transduction that transforms H into -→ H , by Proposition 9.59, then Inc is τ 1 • µ on US k,m .

Let -→ H = (H, hd ) be in s-US k,m , i.e., H is in US k,m and -→ H has indegree at most mk 2 . Let D := Dir ( -→ H ). We let ∂( -→

H ) be the simple (m -1)-hypergraph such that:

  .1, Definitions 2.13 and 2.14)F , F i , F + /v 1 , . . . , t n /v n ], c[t] substitutions TWD(≤ k) tree-width ≤ k 123 PWD(≤ k, C), PWD(≤ k) path-width ≤ k 127 G[u ← H], G[e ← H] JS, JS u , JS d , JS tHR algebras of s-graphs 105, 106, J S, J S u , J S d , J S C their domains 101, 105, 106, 182 F HR , F HRu , F HRd , F tHR their operations 105, 106,F HR Trim(S, Z) trim systems obtained from S 213 F, Q A , δ A , Acc A F -automaton A 222 f [q 1 , . . . , q k ] → A q , suc, lab a representation of words w 317 R F , son i , lab f , rt, son, br i representation of terms t 320 R s , R s,C , R ss,C , R s,[K,Λ] , R u m ,etc. signatures for (p-, s-) graphs G 318, 319, 345, edg, edg λ , lab a , in, in 1 , in 2 , lab Edge relations for (p-, s-) graphs 318, 319, 345, w , t , G C , G , G C , G structures representing w, t, G 317-320, 345, 346 t /u, t ↑ u representation of subterm, context 321 L , L , L C , L C , Lab R , S * , STR c , ffuse a,b , qf , add , mdf unary operations on structures 375, 376, 392, STR, STR pres , STR sep , STR nc algebras of relational structures 392, 393 F QF , F QF pres , F QF sep , F QF Inc(S), R Inc , In R , T S incidence graph of S 629, 630 twd (S), pwd (S) tree-width, path-width of S 632 TWD(R, ≤ k), PWD(R, ≤ k) R-structures of twd , pwd ≤ k (θ R ) R∈R + , (κ c,d ) c∈R0,d∈R 0 Th(t, ↓u, . . . ), Th(t, ↑u, . . . ) bounded theories for term t 389, Th ↓ t (. . . ), Th ↑ t (. . . ), Th t (. . . (δ i ) i∈[k] , (θ w ) w∈R [k] , τ * * notions for constants 511 η [k] , µ i , β D i , β D , τ # (β) backwards translation 514-516 fg U , exp U , copy k

	functional signature functional signature arity subsignature sets of terms terms (AC signature) slim terms positions, occurrences height of term t variables in t t[t 1 85 82, 178 F -202 ρ(f ), ρ(F ) 82, 178 H ⊆ F 82, 178 T (F ), T (F, X) 83, 85, 179, 180 T (F )/≡ AC(H) 411 Slim(F ) 145 Pos(t), Occ(t, f ) 84 ht(t) 84 ListVar (t), t 86 θ H second-order substitution 181 Ctxt(F ), Ctxt(F, X) contexts over F 85 t ↑ u context above u 85 t/u subterm below u 85 N T , root T nodes, root of tree T 92 son T , ≤ T son, ancestor in T 93 T /u subtree below u 92 Syn(t), N t , ≤ t syntactic tree of t 93, 95 Syn(t) ↑ u syntactic tree of t ↑ u 94 N t /u, N t ↑ u nodes of Syn(t)/u, Syn(t) ↑ u 95 yd (t) yield of t 586 Algebras (Sections 2.1 and 2.6.1) M F -algebra H ⊆ G, H ⊆ i G subgraph, induced subgraph 92 G[X], G -X, G -u subgraphs 92 a λ , ab λ , --→ ab λ , a κ symbols for labelled graphs 106 • series-composition 21, 185 Sort(S), F (S) sorts, operations in S 193 S P(M) function associated with S 194 isomorphism class of S 317 MOD(ϕ) models of ϕ 323 [S] iso STR c (R), STR(R) concrete, abstract R-structures 317 Th L (C) L-theory of C 329 82, 178 M its domain 82, 178 f M operation defined by f 82, 178 T(F ), T AC (F, H) algebras of terms 83, 179, 411 W(A), W left (A), W right (A) algebras of words 86 F A , U A their signatures 86 val M (t) value of term t 83, 179 t M derived operation 83, 85, 179, 180 S set of sorts M s domain of sort s M (s1,...,sn) product of domains T (F ) s , T (F, X) s terms of sort s 179, 180 α(f ), σ(f ) input, output type of f σ(m) sort of m s 1 × • • • × s n → s type of an operation M ⊆ N subalgebra 82, 179 M × N Cartesian product 83, 179 (|A|, enc A , ξ A ), f encodings 86, 87 ζ M operations of M 87 M F , M S restriction M H derived algebra M/∼ quotient algebra N k free commutative monoid 205, 255 Graphs (Section 2.2) V G , E G vertices, edges of graph G 88 vert G incidence mapping 88 edg G adjacency relation 89 u → G v , u -G v directed, undirected edge 88 Isol G isolated vertices 108 Adj -(x) adjacent vertices 134, 657 ∅ empty graph 90 G size of G 90 Deg(G) (maximal) degree of G 53 (K, Λ) vertex and edge labels 91 G H isomorphism of graphs 90 [G] iso isomorphism class of G 90 Inc(G) incidence graph 68, 69, 127 und (G), core(G) undirected graphs from G 89 und (G) k distance k graph 549 Line(G) line graph of G 71 G ∪ H, G ∩ H union, intersection 100 G ⊕ H disjoint union 100 G ⊗ H complete join 19 G[F ], G -F , G -e subgraphs 92 G/≈ quotient graph 95 G/F , ¢, ¢ c edge contraction, minor 96 Forb(A), Obst(A) forbidden/excluded minors 99 ω(G) clique number 134 K n , K n,m , C n standard graphs 41, 125 G n×m , G u n×m , P n grids, paths 125, 161 wd width 109, 123, 137 twd , pwd tree-width, path-width 123, 127 TWD(≤ k, C), graph substitution 162, 279 B(G), B Λ (G) encodings of graph G 435, 436 G u simple undirected graphs 19 G simple directed graphs 47 J d 2 directed graphs with two sources 21 Graph algebras Graphs with sources (Section 2.3) C subsignature for C ⊆ A 106 JS[C], JS gen [C] subalgebras 106, 111, P HR C , F HRd C derived signatures 145, 477 J d 2 , J d 2 a derived subalgebra 21, 46, 185 JN t , J N a derived subalgebra 289 A source names/labels 101 τ (G) type of s-graph G 101 τ (t), τ (t), µ(t), wd(t) related notions 109 G • s-graph without sources 101 src G , slab G , Src(G) source designations 101 Int G internal vertices of G 101 β(G), Int(G) border, interior of G 299 G/≈ quotient s-graph 103 , P k parallel-composition 101, 103, C,D typed parallel-composition 182 fg B , fg b source forgetting 103 fg B,C typed source forgetting 183 miv a making internal vertex 477 ren h , ren a→b , ren a↔b source renaming 104 ren h,C typed source renaming 183 a, a , ab, -→ ab, ∅ constant symbols 104, 105 val (t) abstract value of term t 105, 112 cval (t), gval (t) concrete value of t 113, 115 Exp(t) expansion of t 112 Typ, Unt typing, untyping 183, 184, 273 Graphs with ports (Section 2.5) GP, GP u , GP t VR algebras of p-graphs µx • S P(M) (x) least solution of S in P(M) 195 µx • S P(M) (x) y its component defined by y 195 Equat(M) equational sets of M 195 Rat(M) rational sets of M 221 ⇒ G , ⇒ S one-step derivation relations 197, L(G, x), L(G, Y ) context-free languages 198 G[S], G(S), G(A ) context-free grammars 198, 201, 224 Sat L (C) formulas of L satisfiable in C 329 MC(C, L) model-checking problem 427 sat(S, ϕ, X, x) satisfying assignments 324 sat(S, ϕ, . . . ) counting function 430 Maxsat(S, ϕ, . . . ) optimizing function 430 sat(S ⊕ T, ϕ, X, x; y) notion for the Splitting Theorem 361, W A structures for a set L 318-321, 347 perm π notion for the Splitting Theorem 361, 148, GP, GP u , GP C their domains S S unfolding 208 • size functions 322, 492, 649 notion for the Splitting Theorem 365 147, F VR , F VRu , F tVR their operations 148, F VR C subsignature for C ⊆ A 148 GP[C], GP gen [C] subalgebras 148, F cVR concrete version of F VR 152 F VR , F iVR , F κVR variants of F VR 172, G u , G u a derived subalgebra 19, 46 A port labels 146 π(G) type of p-graph G 146 G • p-graph without ports 146 port G port mapping 146 ⊕ disjoint union R * (R * ) constants as unary relations 328, 509, 510 δ, QF operation definition scheme D 372, Trim(S), transition 223 δ f transition function 581 A , A size measures 223 L(A , q), L(A ) languages recognized by A 223, S(A ) equation system of A 224 run A ,t run of deterministic complete A 225 td -run A ,t top-down run of A 581 states of sort s 225 ⊕, ⊕ R,R disjoint union of structures 359, 375 + union of structures D QF operation defined by D 372 651 R,R parallel composition of structures ι R,R natural inclusion 374 384 ϕ D backwards translation 379 Th(S, R, . . . ) bounded theory 386, fuse a,b nc their functional signatures 392, 393 F QF R subsignature ) special cases 582 638 F relVR C , F redQF R,B related functional signatures Th ↑ rt root theory 582 644, 647 C r MS h (R, X ) normalized formulas 419 Q A ,s det(A ) determinization of A 226 F (n) , t * γ representation of assignments 447 100, ⊕ C,D typed disjoint union Rec(M) recognizable sets of M 228 632 L ϕ , L VR C,ϕ , L HR C,ϕ sets of terms for models of ϕ 448, 458, 482 186 --→ add a,b , add a,b edge addition A (B, C) automaton from algebra 231 Adj (S) adjacency graph of S 633 A ϕ , B C,ϕ , C C,ϕ automata recognizing these sets 448, 458, 482 147 --→ add a,b,C , add a,b,C typed edge addition 186 relab h , relab a→b , relab D→a port relabelling 147, relab h,C typed port relabelling ∼, (∼ s ) s∈S congruence 234 γ ∼ its index twd Inc (S) tree-width of Inc(S) MINOR H sentence expressing minor inclusion 44 633 234 quotient algebra 234 cval (t), Occ 0 (t) concrete structure defined by t 393, 638 Monadic second-order transductions (Chapters 7 and 9) M/∼ 186 a, a , a(x), a (x), ∅ constant symbols 148, --→ add a,b,λ , a M for labelled graphs 151 ADD R derived edge addition operation 157 ⊗, -→ ⊗ , ⊗ R,h complete join 19, 149, 162, 174 val (t), cval (t) abstract, concrete value of t 148, 152, 153 cval (t)/u concrete value of t/u 153 Occ 0 (t), port t notions for cval (t) 152, cwd , lcwd clique-width, linear cwd 149-151 CWD(≤ k, C), CWD(≤ k) clique-width ≤ k 296 Equational and recognizable sets; automata (Chapters 3, 4 and 6) P(M) powerset algebra ≈ L syntactic congruence of L 235, 288, 306 γ L recognizability index of L Logic (Chapters 5 and 6) [τ ] iso transduction of abstract structures 504 235, 288, 306 M (L) minimal automaton of L Standard logical notation is not reviewed. τ • τ , τ • τ composition 504 238 ( p ) p∈P family of predicates 246 sat(M, p) satisfaction set 246 L(S, x) s-graphs or p-graphs defined by (S, x) 263, L Term (S, x) terms defined by (S, x) |ϕ|, qh(ϕ) size, quantifier-height of formula ϕ τ -1 , Dom(τ ) inverse, domain 504 324 mfv (ϕ) maximal free variable of ϕ χ, definition scheme 505 443 bqh(ϕ) block quantifier-height of ϕ χ, δ, (θ R ) R∈R noncopying definition scheme 507 445 ba(ϕ) Boolean arity of ϕ 445 qh(D) quantifier-height of D 505 263, A(S) source or port labels in S ϕ[• • • ] substitutions in ϕ 332, 333 D transduction defined by D 505 263, A × B product of automata 438 A ∪ B, A ∩ B union, intersection of automata 438 A complement automaton ϕ X relativization 333, 334 TC[R; x, y], TC[(λu, v • ϕ); x, y] transitive closure 334 QF(R, X ) quantifier-free formulas over R, X 372 D particular transductions 523, 527 438 h(A ), h -1 (A ) images of automaton A FO(R, X ) first-order formulas 323, 324 µ F,n , π F,n relabellings 524 439 MS(R, X ) monadic second-order formulas 326 comparison of classes 529 190 ∪ s union of sets of sort s Relational structures (Chapters 5, 7 and 9) SO(R, X ) second-order formulas 324 trees the set of trees 546 190 Ω s empty set of sort s 190 F ∪ signature of P(M) 190 Pol (F, X) polynomial terms 191 Mon(t) monomials of t 191 P h set extension of homomorphism h 192 Unk (S) unknowns of system S 192 R, R i , etc. relational signatures 316 ρ(R), ρ(R) arity FO i , MS i , SO i , i = 1, 2 formulas expressing graph properties 347 x:v, x:e, X:v, X:e typed variables 349 paths the set of paths 551 -→ #sat, -→ #γ cardinality mappings 552 316 D S , (R S ) R∈R+ , (c S ) c∈R0 R-structure S ∅, ∅ R empty structures S[X], S/≈ S T isomorphism of structures 316 CMS Bool CMS logic with Boolean set terms 456 substructure, quotient structure 316, 508 CMS(R, X ), CMS 1 , CMS 2 counting MS logic 353 316, 392 Card p,q cardinality set predicates 353 316 Sgl singleton set predicate 443 MS i,j , CMS i,j transductions of incidence graphs 554

* * , τ *

Traces are equivalence classes of words for congruences generated by commutations of letters; see the book [*DiekRoz]. For program schemes, see [*Cou90a]. The list of references is divided into two parts. The first part lists books, book chapters and survey articles: the * in, e.g., [*DiekRoz] indicates a reference of this kind. The second part lists research articles and dissertations.

In Semantics, one is also interested in infinite words, traces and terms. In this book these will not be considered.

In addition to being words, terms have canonical representations as labelled, rooted and ordered trees. They are thus called "trees" but this terminology is inadequate.

This logical language and the related one called µ-calculus ([*ArnNiw]) are also convenient for expressing properties of programs.

These classes can actually be generated by certain context-free graph grammars and the corresponding hierarchical structures of the generated graphs are represented by their derivation trees. There is thus a close relationship between the algorithmic issues and the extensions of language theoretic concepts discussed above.

In order to simplify the discussion, we only discuss simple graphs, i.e., graphs without parallel edges.

In particular, the rational transductions that are transductions of words defined either by finite(-state) transducers or, algebraically, in terms of homomorphisms and regular languages.

This means, informally, that it is the set of graphs "defined inside finite trees" by a fixed finite tuple of monadic second-order formulas. These transductions are based on, and extend, the model-theoretical notion of "interpretation".

The other one is a polynomial-time algorithm that finds a term evaluating to a given graph G if there exists one.

One can generate all finite graphs by a finite number of graph operations, but the Recognizability Theorem fails for the corresponding algebra. So this algebra is useless for our purposes.

Relational structures are used to prove the case of the theorem that concerns graphs. A relational structure is uniformly k-sparse if its number of tuples is at most k times the cardinality of its domain, and the same holds for all its substructures.

Since L(G, S) ⊆ A + = AA * , the pair (A * , bA * ∪ {a, c, ε}) is a solution of Σ G that differs from (L(G, S), L(G, T )).

In this book, all graphs are finite. A graph is simple if it has no two parallel edges, i.e., no two edges with the same ends, and the same directions in the case of directed graphs. Parallel edges are also called multiple edges. An edge with equal ends is a loop. The superscript "u" in G u refers to undirected graphs.

We denote by P(X) the powerset of a set X, i.e., its set of subsets.

The letter "J" in the notations J d 2 and, below, in J d 2 , JS and the related notions refers to graphs that can have multiple edges. By contrast, the letter "G" used in the notations G u and, below, G u , GP etc. refers to simple graphs. The subscript "2" refers to the two sources, and the superscript "d" to directed graphs.

The term "series-parallel" is also used for partial orders ([*Möhr]) and, in a wider sense for undirected graphs without K 4 as a minor ([*Die]). Our series-parallel graphs are called two-terminal series-parallel digraphs in [*Möhr].

For associative binary operations the more readable infix notation will be used, although it is ambiguous as already observed. The infix notation of this term is ((e e) • e) (e • e).

In general, a homomorphism from N to M, where N = N, (f N ) f ∈F is another F -algebra, is a mapping h : N → M such that for every f ∈ F and all n 1 , . . . , n ρ(f ) ∈ N , we have h(f N (n 1 , . . . , n ρ(f ) )) = f M (h(n 1 ), . . . , h(n ρ(f ) )).

A function M k → M defined by a term in T (F ∪ {y 1 , . . . , y k }) is a k-ary derived operation of M.

Q = Q, • Q , 1 Q is a monoid if the binary operation • Q is associative with 1 Q as unit element.

One can prove by fixed-point induction that every series-parallel graph is 3-colorable in such a way that its two sources have different colors.

The set Pos(t) of positions of t is the set of occurrences of the symbols of F . We denote by t/u the subterm of t issued from u and by roott the first position of t. Formal definitions are in Chapter 2.

In some cases, we will write G instead of G .

Relational structures are first-order logical structures without functions of positive arity. See Section 1.9 and Chapter 5 for detailed definitions.

[n] denotes {1, . . . , n}.

A sentence is a formula without free variables. The notation S |= ϕ means that a sentence ϕ is true in the relational structure S; in that case S is said to be a model of ϕ.

We have actually no proof of this failure for Card Prime (X). We will give the proof for another numerical predicate (see the end of Section 7.5).

Using MS 2 or C 2 MS sentences for defining sets of terms would not yield a wider class of definable sets.

We call it in this way because its equational sets, the VR-equational sets of graphs, are the sets of graphs generated by certain context-free graph grammars whose rewritings are based on Vertex Replacement. See [*EngRoz] or [*Eng97] for comprehensive surveys.

"Abstract" means that two isomorphic graphs are considered as equal. This notion will be formalized in Chapter 2.

We assume G and H disjoint. If they are not, for instance if H = G, we replace H by an isomorphic copy disjoint from G. It follows that ⊕ is a well-defined binary function on isomorphism classes of graphs, i.e., on abstract graphs.

To add undirected edges, we use --→ add b,a ( --→ add a,b (G)). We will denote by add a,b the unary

The unary operation add a,b is also a derived operation of GP, defined by the term --→ add b,a ( --→ add a,b (x 1 )). The operations r of the P -algebra M in Section 1.1.5 are derived operations of the F -algebra M, defined by terms tr.

 26 Recall that [k] = {1, . . . , k} for k ∈ N with [k] = ∅.

We call it in this way because its equational sets, the HR-equational sets of graphs, are the sets of graphs generated by certain context-free graph grammars whose rewritings are based on Hyperedge Replacement. We will define them in Chapter 4, Section 4.1.5. For a thorough study, see [*DreKH] or [*Hab].

H isomorphic to H implies that τ (H ) = τ (H).

Formal definitions of |t| and |ϕ| will be given in Chapters 2 and 5, respectively.

In many cases, ϕ is fixed because one is interested in a particular graph property, and then the parameters are just tree-width and clique-width.

For Conjecture 1.28, Kawarabayashi[Kaw] has found such bounds for all k. It follows that each level of the conjecture is decidable, but by an intractable algorithm.

An oriented graph G (i.e., a graph without loops and pairs of opposite directed edges) has oriented chromatic number at most k if there exists a tournament (a complete oriented graph) H with k vertices and a homomorphism h : G → H that maps V G into V H and every directed edge u → v of G to a directed edge h(u) → h(v) of H.

We recall (from Section 1.3.1) that the acronym C 2 MS refers to MS logic extended by the even cardinality set predicate.

The formula CONN(Y ) is defined in Section 1.3.1. We use X ⊆ Y as a shorthand for ∀x(x ∈ X ⇒ x ∈ Y ).

We describe the relations between occurrences of symbols in t with the terminology of trees. Chapter 2 will detail the terminology about terms and the trees that represent them.

Alphabets and signatures will always be finite or countably infinite.

There is a unique set L ⊆ F * satisfying Equality (2.1), see Proposition

3.15. If F is finite, then L is a context-free language.

This means that the membership problem of enc A is decidable, i.e., an algorithm can check whether or not an element of N belongs to enc A .

Enumerate the elements i of N , test whether i belongs to enc A , and halt when |A| elements of enc A have been found.

When an encoding of a set is not mentioned, as here for Seq(M ) and Seq M , we silently

We will never use "class" in the set-theoretical sense of a collection of objects that may not form a set. By the footnote in Definition 2.9, every collection of graphs is a set.

The assumption that K and Λ are disjoint simplifies some definitions and statements but is not essential.

In this book, we will not give any more details on data structures and implementations of algorithms.

This example also works for the subgraph relation.

Here 'Forb' stands for 'Forbidden' and 'Obst' for 'Obstruction'.

Dom(h) is the definition domain of h, i.e., the set of elements a such that h(a) is defined.

For a set X, P f (X) denotes the set of finite subsets of X.

Here and from now on, we use the convention that t 1 • • • tn denotes ∅ if n = 0.

The property for u is proved by using the validity of the same property for nodes strictly below u.

The term "equational" refers here to equational logic and term rewriting systems [*BaaNip], not to the equational sets to be studied in Chapter 3.

Such terms are said to be ground in the theory of term rewriting systems.

Recall from Definition 2.13 that, in a rooted tree T , there is a unique (undirected) path between any two nodes u and v of T . This path contains the least common ancestor of u and v.

In this contraction the "new node" u disappears, by Definition 2.63.

The elimination order is usually taken to be (vn, . . . , v 1 ), but it is more convenient to reverse it while keeping the well-known terminology.

The arboricity of a loop-free graph is the least number of edge-disjoint forests of which it is the union.

A result by Cayley: see Section II.5.1 of [*FlaSed].

If B i = ∅, we can omit fg B i because fg ∅ defines the identity mapping. If (T, f ) is downwards increasing, we have B i = ∅ for all i. We can also take B i := C -f (u) for each i = 1, . . . , p.

Vertex sets will be included in U , the universal set of vertices mentioned in the footnote in Definition 2.9.

Clique-width is defined in[CouOla] in terms of the operations relab a→b and not in terms of the larger set of operations of the form relab h . However the corresponding values are the same as we will prove in Section 2.5.6 (Proposition 2.118).

Recall from Definition 2.11 that simple [K, Λ]-labelled graphs may have multiple edges with different labels.

A [K, Λ]-labelled p-graph is undirected if for every edge from x to y there is an edge from y to x with the same label.

We denote in the same way a constant symbol in F cVR and the corresponding graph.

Even if t /u = t /v where t ∈ T (F VR ) is obtained from t by replacing each a(x) or a (x) respectively by a or a .

Note that if u is not the root, then t Id /u = (t/u) Id and cval(t)/u = cval(t/u) (however, they are isomorphic). If u and v are incomparable in t, then cval(t)/u and cval(t)/v are disjoint concrete p-graphs.

This implies, by the way, that a bijection w : V G → Occ 0 (t) is a witness of G val(t) if and only if G = cval(tw).

We assume here that the elements of B × P(B) × P(B) are appropriately encoded as natural numbers that are not in B, which is possible because B is finite.

It is preserved under simultaneous reversal of all edge directions.

It actually suffices to assume that H and G -u are disjoint, where G -u denotes the induced subgraph G[V G -{u}].

Here t[t /a(u)] denotes the term obtained from t by replacing the occurence of a(u) in t by the term t .

This is called the modular decomposition of G. The theory of modular decomposition is exposed in [*EhrHR] and in [*MöhRad].

The term "complexity" refers to the number of basic operations from a given signature necessary to construct the considered graph. It follows that cliques are "difficult" to build with the operations of F HR but "easy" to build with the operations of F VR .

Theorem 5.5 of this article states that cwd(G) ≤ 2 2twd(G)+1 + 1, however, the proof establishes the upper-bound 2 2twd(G)+2 + 1. See also Section 2.7 about this proof.

The first requirement on h means that h is sort-preserving, i.e., that σ(h(m)) = σ(m) for every m ∈ M .

Do not confuse J S C with J S[C] = {G ∈ J S | τ (G) ⊆ C}, cf. Remark 2.39[START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. Note that J S ∅ = J S[∅] is the set of all graphs.

The set J S [2] = {G ∈ J S | τ (G) = {1, 2}} is equal to the set J d 2 ofSection 1.1.3.

The C stands for "context-free" (or "confluent") and the NCE stands for "Neighborhood Controlled Embedding".

The NLC graph grammars, where NLC stands for "Node Label Controlled", are particular NCE graph grammars, see [*EngRoz].

Strictly speaking, we have an empty set of each sort. Thus, the powersets P(Ms) are pairwise disjoint.

Two consecutive elements may be equal; a sequence is strictly increasing if no two elements are equal.

This theorem, usually attributed to Tarski and/or to Kleene, says that every monotone and ω-continuous function : E → E where E is an ω-complete partial order with a least element has a least fixed-point. See[LasNS] for a review of its uses in Semantics.

The only-if direction of this important property is stated and proved in [*Har] as the "technical lemma 3.3.1".

We recall from Definition 3.5 that P h denotes the extension of h to subsets of M and that it is a homomorphism of F∪-algebras : P(M) → P(M ). We let also P h((L 1 , . . . , Ln)) := ( P h(L 1 ), . . . , P h(Ln)).

A monoid is a set equipped with an associative binary operation and a unit element.

The formal definition of this standard notion is in Definition 3.63.

usually called Parikh's Theorem. The homomorphism h : W(A) → N k is called the Parikh mapping.

It is the one-step derivation relation of the regular grammar G = F∪, Xn, R with R = {x 1 → p 1 , . . . , xn → pn}. Note that this is not the regular grammar G(S). The languages generated by G are of no interest.

The sort of a variable y l is not necessarily the same in different terms m i,j . We could waive this "difficulty" by using variables y i,j,l instead of y l in m i,j , but we prefer lighter notation.

The terms of the µ-calculus are called µ-terms.

The book by Sakarovich [*Sak] interleaves finite automata, rationality and recognizability without emphasizing the fundamental differences between these three notions.

We recall from Definition 2.123 that this implies that S is finite.

These automata are frequently called bottom-up (or frontier-to-root) tree automata in the literature on tree language theory.

Space efficient representations of automata are used in the software MONA: see[BasKla, Hen+, Kla].

The term "son" refers to the syntactic tree of t, cf. Definition 2.14 in Section 2.2.

We recall from Definition 3.8 that a set is defined by an equation system if it is a union of components of its least solution in the considered powerset algebra that are all of the same sort.

This condition is not trivial since the set of states may be infinite (but should be effectively given).

In most classical uses of automata, e.g., in compilation, the size of the input is much larger than the number of states and the value a may be considered as a constant. But in Chapter 6, we will construct automata that are much larger than their intended input terms.

In the U A -algebra W left (A), the word w corresponds to the term t:= a 1 (• • • (an( )) • • • ).In this case, the runs of an automaton on w correspond to those of a "top-down (or root-tofrontier) automaton" on t (cf. Section 8.1.2).

For another method to decide the finiteness of L, see Sections 4.1 and 4.3 of the next chapter.

We recall that the sets Bs are pairwise disjoint.

Here we assume that the arities of the function symbols that occur in the terms of the set are fixed, cf. Remark 3.20[START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF].

If this preservation property holds for all operations, it also holds for all derived operations.

For an equivalence relation ∼ on a set A, we denote by [a]∼ (or just [a]) the equivalence class of a ∈ A, and C/∼ := {[a]∼ | a ∈ C} for every C ⊆ A. We also denote C/∼ by [C]∼ (or just [C]).

We recall that a term in T (F, Yp) is linear if each variable of Yp has most one occurrence. Actually, by the proof of the next proposition, the equivalence relation ≈ L is the same if we omit the restriction to linear terms.

Here and in Proposition 3.73 we do not distinguish two automata that are the same up to a renaming of states. Formally, we would have to define isomorphism of automata.

Recall from Definition 2.8 that, for an encoded set A, ξ A is the bijection : A → enc A ⊆ N that encodes the elements of A as natural numbers.

Here we assume that F is effectively given by its standard encoding as a decidable subset of F (and similarly for its set of sorts), see Definition 2.8.

For sets B and A with B ⊆ A, the inclusion mapping in B,A : B → A is defined by in B,A (b) = b for all b ∈ B.

Here S and S are the sets of sorts of F and F , respectively. Note that we do not assume that S is encoded by its standard encoding as a subset of S (see Definition 2.8), and similarly for F and M .

The set A can be viewed as the decidable subset of Seq(P ) consisting of all sequences (p 1 , . . . , pr) such that α(p i ) = α(p j ) and ξ P (p i ) < ξ P (p j ) for all i < j.

We have observed in Section 3.4.2 that a complete deterministic F -semi-automaton is nothing but an F -algebra. The use of A × A corresponds to the classical product of automata (cf. Section 6.3.1 below, Proposition 7.1 of [*GecSte] or Section 1.3 of [*Com+]).

Equivalently, run B ,t (roott) = q, where the automaton B is obtained from B by adding the transition rules y 1 → q 1 , . . . , y k → q k .

This means that if v ∈ L and h(v) = h(w) then w ∈ L, where h is the homomorphism : W({a, b}) → N × N defined in Section 3.1.6.

In examples, we write fg 12 or fg abc for fg {1,2} or fg {a,b,c} respectively.

See Definition 2.53 for TWD(≤ k, C) and TWD(≤ k).

We recall from Definition 2.53 that TWD(≤ k, C) is the set of s-graphs of tree-width at most k and of type included in C.

The type τ (G) of an s-graph G is the set of names of its sources; we let τ (L) := {τ (G) | G ∈ L}.

Proposition 3.10 is applicable because the finite algebra T[A(S)] is effectively given. In fact, F HR A(S) and T[A(S)] can be computed from S (and F HR ).

Not to be confused with τ (L(S, x i )) = {∅}, which implies that L(S, x i ) is not empty and contains only graphs (without sources).

See Theorem 7.42 and the end of Section 7.4.

We note that the algebra JS is also infinity-preserving, by a slightly more complicated argument (if τ (L) is infinite where L is one of the arguments of an operation, then τ (M ) is infinite where M is the result).

The symbols in U are nullary. We call them variables because they will be the unknowns of equation systems associated with regular grammars having U as set of nonterminals.

or belongs to Λ if we consider (K, Λ)-labelled graphs; the reader will make easily the necessary modifications for the case of labelled graphs.

The notion of context is defined in Definition 2.6. Writing t = c[x] corresponds to distinguishing an occurrence of x in t.

As for HR-equational sets, HR-recognizability concerns sets of abstract (labelled) s-graphs. A set L of concrete (labelled) s-graphs is HR-recognizable if and only if the set {[G] iso | G ∈ L} is HR-recognizable. If we specify a congruence on concrete (labelled) s-graphs, we impose that two isomorphic (labelled) s-graphs are equivalent.

This can also be shown for JS t [E] and JS[E], by a proof based on Definition 3.74.

We have k k/2 ≤ B(k) ≤ k! for every k ≥ 8.

We recall from Definition 2.53 that TWD(≤ k, C) denotes the set of s-graphs of tree-width at most k and of type included in C.

This set is also used in Counterexample 4.8.

The reason is of course that there are only countably many finite graph automata and logical formulas. For the same reason, "most" HR-recognizable sets are not effectively HRrecognizable (nor semi-effectively HR-recognizable).

The mapping h defined by h(G) = β(G) if G is simple and h(G) = ⊥ otherwise, is a homomorphism from JS[A(S)] to a finite algebra with domain {G ∈ J S s | τ (G) ⊆ A(S), Int G = ∅} ∪ {⊥}, cf. the proof of Proposition 4.13(3).

By Lemma 3.59, because val B (t) = (t ↑ v) B (c B (val B (t/u))) and similarly for t and c .

As one example, for a bijection h : D → E, we define (ren h,D ) B (⊥ D ) := ⊥ E and (ren h,D ) B (β, a) := (ren h (β), RELAB h (a)), where RELAB h := (relabg) A such that g( A, A ) = h(A), h(A ) for all A, A ⊆ D, cf. (4.6) of Definition 4.50.

See Corollary 4.38.

The domain of an R-structure is also frequently called its universe [*Lib04]. Since we only consider finite structures the term "domain" is more appropriate. It is also customary to forbid empty domains. Allowing or forbidding empty domains makes a difference for proof systems: ∃x. (x = x) is true in nonempty domains only. Since we will not use any proof system (we only use logical formulas to describe classes of graphs and more generally of relational structures), allowing empty structures is harmless. Relational signatures and structures will always be finite as opposed to functional signatures and algebras.

Instead of [n], we could take as domain of w the interval [0, n -1] and we get an isomorphic structure. Since isomorphic structures satisfy the same logical formulas, by Lemma 5.4 below, this alternative representation yields the same logical expression of properties of words.

 3 The notion of monadic second-order transduction, to be studied in Chapter 7, can formalize the transformation of a representation into another equivalent one and the corresponding translations of formulas. But it is not necessary to use it at this stage, because the translations of formulas are easy to write directly.

We denote D G by V G and edg G by edg G .

To be precise, for simple graphs G and H, a mapping : V G → V H is an isomorphism from G to H if and only if it is one from G to H .

The type of a p-graph G is the set π(G) of its port labels. The type of an s-graph G is the set τ (G) of its source labels.

We allow the sets forming a partition of a set to be empty.

To be precise this only holds if R 2 = ∅, due to the convention in Definition 2.11 that (K, ∅)-labelled graphs are graphs with unlabelled edges.

For representing terms defining cographs, the relations br i are not necessary as we have seen in Example 1.38 of Section 1.7.1 because the operations ⊕ and ⊗ are commutative.

For discussing syntax, a relational signature is frequently called a vocabulary. We prefer the term "relational signature" which refers to the types of objects described by formulas. Furthermore, it is similar to the term "functional signature" used for algebras.

An automorphism of G is an isomorphism of G to itself.

We write x = y instead of ¬x = y in order to get shorter and more readable formulas.

If C is L-definable, then a class of structures D ⊆ C is L-definable with respect to C if and only if it is L-definable, and the same holds for L-expressibility defined next. See Corollary 5.12 for a use of this observation.

Note that L-definability is only defined for sets of p-graphs of bounded type, and similarly for simple s-graphs.

In both directions, the same sentence can be used. Faithfulness of rep is needed in the if direction.

i.e., disjoint from R.

Conversely, every first-order, second-order or monadic second-order formula expressing a property of structures in STR c * (R * ) can be rewritten into an equivalent formula over R that is respectively first-order, second-order or monadic second-order. See Lemma 7.5 for the details.

These results concern only finite graphs. However, the first-order theory of the class of all finite and infinite graphs is also undecidable. See any textbook on first-order logic.

We recall that a term is either a first-order variable or a constant symbol (we do not use function symbols of positive arity for writing logical formulas).

Since set variables, such as Y , are always used in formulas of the form x ∈ Y , we need not specify that Y ⊆ X (and similarly for arbitrary relation variables). This construction must be modified if we use set predicates as we will do in Section 5.2.6, cf. Remark 5.26.

More precisely, this means that the property of being a rooted tree is MS-expressible with respect to the class C of simple directed graphs (see Section 5.1.5). Similarly in the next property P5, C is the class of directed graphs without circuit.

In other words, the set of s-graphs TWD(≤ k, C) is MS-definable. For the definition of G C see Example 5.2(2).

For readability, Y ⊆ X replaces ∀y[y ∈ Y ⇒ y ∈ X], X = Y replaces ∀x[x ∈ X ⇔ x ∈ Y ]and ϕ 2 (x, y, Y ) stands for ϕ 2 [Y /X], cf. Section 5.2.1 for substitutions.

We will actually reprove this result in a more general setting in Section 5.3.9, cf. Corollary 5.66.

Proper means that two adjacent vertices have different colors.

Some sets U i may be empty.

Thomas has proved in [Tho82] that a sentence ϕ as in this theorem, can be constructed with a single existential set quantification, however large n may be.

We use the notation G as for the first representation, because the two representations are very similar and equivalent. (They allow to express the same properties by first-order and by monadic second-order formulas.)

In the subscripts of these signatures "m","C" and "s" recall that multiple edges are represented, that C is a set of source labels and that the sources are constants rather than unary relations, respectively.

Thus, in statements (1)-(3), expressibility is with respect to the class C of simple (labelled) graphs.

Theorem 5.22 actually holds, for every r, for CrMS 2 -and CrMS 1 -expressibility.

The expression of vertex-minor inclusion (a variant of minor inclusion relevant to cliquewidth) is another, much more complicated one. See[CouOum].

 43 This is clear for k = 1, and hence also fork ≥ 2 because A × (B ∪ C) = (A × B) ∪ (A × C)for arbitrary sets A, B, C.

The formula γq uses a linear order to express a property of X that does not depend on any linear order: we say that such a formula is order-invariant.

A more general union, for which we will waive the restriction that R + = R + , will be defined in Example 5.44. The Splitting Theorem will extend to it.

We may have I = ∅ or I = [n]. In these cases, π I is the identity, x = ε in the first case and y = ε in the second case.

If x = ε, then sat(S, θ i ) = sat(S, θ i , ε) is either ∅ if S |= ¬θ i or {ε} if S |= θ i . If S is the empty structure, then sat(S, θ i , x) = ∅ if |x| ≥ 1.

If T = ∅, then D T = ∅ if ≥ 1 and D 0 T = {ε}.

Since conjunction can be expressed in terms of disjunction (Case 4) and negation (Case 6), we could omit this case. However, the direct construction given in this case is more clear than the one that uses a combination of the constructions of Cases 4 and 6.

The set sat(S, ϕ, X, z) is undefined if S is an abstract structure, unless the sequences X and z are both empty, which implies that ϕ is a sentence (cf. Lemma 5.4).

Since we allow G, H to be empty, we cannot replace sat(H, ∃z.True, ε) by sat(H, True, ε), because sat(H, ∃z.True, ε) = ∅ if H = ∅ and is {ε} otherwise. The projection mapping pr : A × B → A does not satisfy the rule pr (X × B) = X for all X ⊆ A because this equality is false if B = ∅ and X = ∅.

When we discuss several signatures R and R , we assume, unless otherwise specified, that a symbol in R ∩ R has the same arity with respect to both of them.

Note that S and D(S) are concrete structures. A set sat(S, ϕ, U , u) is well defined only if S is a concrete structure, or if S is abstract and U = u = ε, i.e., if ϕ is a sentence.

Note that ffuse is also the composition in any order of the operations ffuse a,a for all a ∈ A.

For handling directed graphs, replacing {in, lab Edge } by {in 1 , in 2 } would not change this equality, and its consequences remain valid.

In the case where rt is a unary relation symbol, the atomic formula rt(x 1 ) is replaced by labw(x 1 ), except that the definition of θrt (x 1 ) as rt(x 1 ) remains unchanged.

Note that the constants of GP t are also constants of STRnc,pres: ∅ is ∅ R s,∅ , a is ♦ B,R s,{a} with B = {laba}, and a is ♦ B ,R s,{a} with B = {edg, laba}.

To ensure that the domains of A are pairwise disjoint, we assume that the sets CMS(R , ∅) are pairwise disjoint, i.e., that a sentence is always given together with a relational signature.

The structure w , also defined in Example 5.2(1), uses a successor relation suc. The order relation of w is the reflexive and transitive closure of suc. It follows that the same

The set L ∩ K is a set of abstract p-graphs. Computing this set means producing one concrete graph from each isomorphism class of an abstract graph in L ∩ K.

The function exp : N 2 → N is defined by: exp(0, n) = n and exp(d + 1, n) = 2exp(d,n) .

that is, γ(k) ≤ exp(d, k) for every k, for some fixed d. Such functions are said to be elementary, which is a rather counter-intuitive terminology!

This construction is similar to the transformation of a regular expression into a finite automaton, see [*AhoLSU] or [*Cre].

We use the convention that the computation time 0, for example if |d| = 0 or if f (k) := 100 • k

and p(d) = 0, indicates a computation taking constant time.3 In the case of tree-width, one should take the parameter twd(G) + 1 to meet the requirement that p(d) ∈ N .

under the natural assumption that g(k, ϕ) = g(k, ϕ ) if ϕ is obtained from ϕ by a renaming of bound variables, and/or of vertex and edge labels.

So, more precisely, Statement (1) says that the problem MC( F T (F ), CMS) is fixedparameter linear with respect to (F, ϕ), where the union extends over all finite functional signatures F .

Flow-graphs of structured C programs have tree-width at most 6[Thop]. The corresponding tree-decompositions can be obtained easily from the derivation trees of the programs, relative to the grammar of the C language.

 9 These results are formulated in terms of HR grammars (hyperedge replacement graph grammars), that correspond closely to HR equation systems, as we have seen in Section 4.1.5.

Such a pair is usually called a "rank-decomposition". However, its definition is not based on the rank of any matrix. The notion of rank is used to associate a value with a layout, and this value measures its complexity. Other values can be associated with layouts, see for example[START_REF] Courcelle | Clique-width of countable graphs: a compactness property[END_REF].

As the linear algorithm of Bodlaender[START_REF] Bodlaender | A linear-time algorithm for finding treedecompositions of small treewidth[END_REF] for deciding tree-width, this algorithm is not implementable.

If we use V G × [0, 3] instead of V G × [3],and if we replace in E B(G) the edge (v, 1) -(v, 2) by the two edges (v, 1) -(v, 0) and (v, 0) -(v, 2), then we get a bipartite graph B(G). This variant is useful for proving the result of[CouOum] discussed in Section 7.5, Theorem 7.55(2). The same observation holds for the encoding B Λ defined below.

For terms, this translation (presented in Section 6.3.3) is the classical one used to prove Theorem 1.16.

We recall that exp : N × N → N is defined by exp(0, n) = n, exp(d + 1, n) = 2exp(d,n) .

For sets of terms T 1 , T 2 , we let f (T 1 , T 2 ) denote {f (t 1 , t 2 ) | t 1 ∈ T 1 , t 2 ∈ T 2 }.

We recall that ∀X 1 • • • is a shorthand for ¬∃X 1 ¬ • • • , and that, e.g., ∃X 1 , X 2 . ϕ abbreviates ∃X 1 ∃X 2 . ϕ. Similarly, ∀X 1 , X 2 . ϕ abbreviates ∀X 1 ∀X 2 . ϕ which, on its turn, we will view as an abbreviation of ¬∃X 1 ∃X 2 . ¬ϕ (not of ¬∃X 1 ¬¬∃X 2 . ¬ϕ).

In Example 5.2(3), we have defined a relational signature with a constant symbol rt for denoting the root. We will not use this symbol in this chapter. We have also defined a relational signature consisting of a single binary son relation and of unary relations br i for 1 ≤ i ≤ k meaning that the considered node is the i-th son of its father. The corresponding representations of terms are equivalent for expressing properties of terms by first-order or monadic second-order formulas.

If L P (X 1 ,...,Xn) is defined by an MS sentence ϕ over R F (n) (in which the variables X 1 , . . . , Xn are not quantified), then P is monadic second-order expressible by the MS formula ψ(X 1 , . . . , Xn) over R F that is obtained from ϕ by changing every atomic subformula lab (f,w) (x) into the formula lab f (x) ∧ ( w i =1 x ∈ X i ) ∧ ( w i =0 x / ∈ X i ).

We first observe that m • exp(h, x) ≤ exp(h, x + m) if h > 0, and then we prove the inequality by induction on h.

Recall from Section 2.5.2 that cval(t)/u denotes the p-graph cval(t Id /u), and note that γ(X i ) ∩ (Nt/u) = γ(X i ) ∩ V cval(t)/u .

Since x -G y means that x and y are adjacent, x - * G y means that x and y are equal or linked by a path.

All computations have been done by Durand with her software AUTOWRITE[Dur] that trims, reduces, determinizes and minimizes automata on terms.

VR(n) [k]

If G is a concrete graph and g is a bijection between V G and some set V , then the graph obtained by renaming every v ∈ V G into g(v) is the unique graph H with V H = V such that (g, Id) is an isomorphism : G → H, where Id is the identity on E G .

For the replacement of a by ∅ see the observation after Proposition 2.49.

There are two small technical problems here, that can easily be solved. Since several labels may be needed for one edge, these must be coded as one label. Also, a label may be on both a vertex and an edge, so these labels must be distinguished from each other (because K and Λ must be disjoint).

Note that in this computation we can actually work with Booleans and replace multiplication and addition by ∨ and ∧ respectively (because x • y = 0 if and only if x = 0 or y = 0, and x + y = 0 if and only if x = 0 and y = 0).

 31 This presentation corrects some imprecisions of [

FluFG].32 A set can be represented by a linked list with an additional pointer to the end of the list. To compute the union of two disjoint sets, the end of the first set is linked to the beginning of the second set. Note that this destroys the given sets.

To be precise, |A B| = |A| • |B| ≤ 2 + A B 0 -A 0 -B 0 .

For Result 1, recall from the proof of Theorem 4.51 that every simple graph of bounded tree-width is p-sparse for some p, i.e., has at most p • |V G | edges.

The domain of τ should not be confused with the domain of a particular structure S in the domain of τ .

We will usually write w = (R, i 1 , . . . , i ρ(R) ) for w = (R, (i 1 , . . . , i ρ(R) )) and θ R,i 1 ,...,i ρ(R) for θ (R,i 1 ,...,i ρ(R) ) .

In Section 5.3.2 (Definition 5.42) we have defined the notion of a quantifier-free operation definition scheme, a QFO definition scheme in short, that defines a QF operation. Every such operation is a QF-transduction. See Example 7.3(2) and (the paragraph after) Definition 7.6 below.

Unless otherwise stated, a graph transduction is a relation between simple graphs such that a graph G is faithfully represented by the structure G .

The line graph of G, denoted by Line(G), is the undirected graph having E G as vertex set and an edge between u and v if and only if these edges of G have at least one common end vertex.

By Definitions

7.1 and 7.2, this means that the transduction [{( t , θ H (t) ) | t ∈ T (H)}] iso = {([ t ] iso , [ θ H (t) ] iso ) | t ∈ T (H)} of abstract structures is an MS-transduction.

This means that [τ ] iso is an MS-transduction, cf. Footnote 6 in Example 7.3(4).

This syntactic definition is more restricted than the semantical definition of L-equivalence given in Example 5.2 and Section 5.1.5. If rep and rep are strongly MS-equivalent, then they are MS-equivalent, by the Backwards Translation Theorem to be proved in Section 7.1.4. The converse does not hold, as shown below.

The notation τ # (β) is slightly imprecise because β D depends on D, not only on τ . A transduction may have different definition schemes.

We do not call it the Composition Theorem because this terminology is widely used for another result. See the introduction of Section 5.3.

A path is a graph of the form Pn for some n ≥ 1. We identify Pn with the structure Pn and similarly for words and terms.

It will be used in Section 7.6. It is generalized in[START_REF] Blumensath | On the monadic second-order transduction hierarchy[END_REF].

The special case of cographs has been presented in Section 1.7.1 (Example 1.38).

For the notion of an FPT algorithm with output, see the paragraph before Theorem 6.55. The size of the input graph G can be taken as |G| = |V G |; the size of the output graph is τ (G) .

More precisely, this means that L = τ ( T (F ) ).

See Definition 7.20 for the notion of a monadic second-order relabelling of terms and note that µ is invertible by Proposition 7.22[START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]. Note also that N µ(t) = Nt.

Since the proof is effective, there is a single algorithm that takes as input θ, k and t and produces the integer f θ (k) and the term t .

Formally, we would have to use C ∪ K where C is a copy of C disjoint with the set of all source labels (cf. Remark 6.51), but we prefer to disregard this technicality here. Note also that if C ⊆ D, then G C and G D are the same labelled graph, but with different sets of vertex labels.

For the definition of k-slim terms see the paragraphs before Theorem 7.41.

This is, in fact, a particular case of the more general result that for every MS-transduction

To obtain a version of Theorem 5.6 for rectangular grids, we apply the Reduction Theorem to the MS-transduction that transforms the rectangular grid G n×k into the square grid G m×m where m = min{n, k}, cf.(1.7) in the proof of Proposition 5.14.

We note that every parameter-invariant MS-transduction of terms and/or words is a parameterless MS-transduction, cf. Footnote

in the proof of Theorem 7.50.

To be precise, δ f (Φ 1 , . . . , Φ k ) = Z f * ,q,0,(1,0,...,0) (Φ 1 , . . . , Φ k ) where Φ i ⊆ L 1 and Φ i = Φ i ∩ L 0 .

This idea is taken from[START_REF] Engelfriet | MSO definable string transductions and two-way finite state transducers[END_REF], where the hybrid MS two-way finite-state transducer was introduced.

A global property of a node u of s is a property of the pair (s, u), such as: u is the rightmost leaf of s, or: all descendants of u that are not leaves have two sons. A local property of u is a property of the subgraph of Syn(s) induced by u, its father and its sons (without the labels of the father and the sons), such as: u does not have label f , or: u is the second son of its father.

The transducer jumps from node u to node v by moving its reading head from u directly to v, where v need not be the father or a son of u (or u itself).

Note that son(x 2 , x 1 ) abbreviates i∈[ρ(F )] son i (x 2 , x 1 ).

This definition is due to Nivat[Niv]; see also [*Ber].

For the formula son(u, v) see Footnote 6, and for the transitive closure construction TC see Section 5.2.2.

This means (still informally speaking) that every computation of M can be mapped to a computation of M , by a fixed mapping from the set of states of M to the set of states of M , provided the intermediate steps that are needed to determine the state of A are first deleted from the computation of M ; moreover, every computation of M is obtained in this way.

To summarize, apart from the finite control, a state of M contains (at most) a state of M , three states of A , and two functions from Q to P(Q).

More strongly, it contains one that is not even in TWTW, the class of transductions computed by nondeterministic tree-walking tree-to-word transducers.

To be precise, the depth of the root is one, and the depth of a son of a node u is the depth of u plus one.

In that theorem, one should take the storage type S to be the tree storage type TR (as defined in Definition 3.17 of[START_REF] Engelfriet | Pushdown machines for the macro tree transducer[END_REF]).

In the only-if direction one first obtains a transducer with a unary input signature that may have several constant symbols, which can easily be replaced by one with a unary input signature that only has the constant symbol .

It is straightforward to show that DMBOTsu(REGT) = DMBOT lin (REGT) and 1DMWTsu(REGW) = 1DMWT lin (REGW): a monadic second-order relabelling can add the set var (u) to the label of every node u of the input tree (cf. the second part of the proof of Theorem 8.21); the mbott can then assign the empty word to the variables not in var (u).

Since, obviously, every rational transduction is in 2GSM, this proves(and strengthens) the result mentioned at the end of Example 8.3: a rational transduction is an MS-transduction if and only if it has finite images.

This notion arises in a natural way in axiomatizations of planar geometry in terms of points, lines and intersections of lines. See, e.g.,[CouOli].

A binary relation E on D is acyclic if the directed graph D, E has no circuit.

Another possibility is to define the tree-width of D, X as that of the graph with vertex set D and an edge between any two vertices that are components of some triple in X. By Proposition 9.14[START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF], this notion of tree-width is the same as the one of Definition 9.12. By Proposition 9.14(2), the two notions of width are related by linear inequalities. Hence Corollary 9.6 also holds for this alternative definition.

This graph, augmented with a loop on each vertex, is called the Gaifman graph of S in [*Lib04]. It is useful for the study of the expressive power of first-order formulas.

To be precise, we select finitely many QFO definition schemes for the finitely many QF operations, cf. Corollary 5.95.

Extending the convention of Example 5.44 and Definition 5.62, we assume that the arity mappings of all relational signatures in S agree. Hence, the union of two sorts in S belongs to S.

i.e., a term in T ({∪, ∩, }, Wm), cf. Definition 6.32.

It was proved for words and terms (viewed as graphs) in Corollary 5.23, and for forests in Example 7.8.

Proper means that two adjacent vertices have different colors.

The definition of US k is not monadic second-order expressible, but the characterization of Proposition 9.40(1) yields the result. The class of graphs G that are 2-sparse, i.e., for which|E G | ≤ 2 • |V G |, is not MS-definable.The proof technique of Proposition 5.13 can be adapted to prove this fact.

This notion extends that of a normal tree defined in [*Die]. See also Definition 2.13 and Example 2.56(6).

Here, we can define all orientations of any given graph by an MS 2,2 -transduction. The construction differs from that of Proposition 9.42[START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] in which we defined one or more orientations by an MS 1,1 -transduction. It is not possible to define all orientations of every simple undirected graph by a single MS 1,1 -transduction, see Example 7.46.

We have used hypergraphs of a different type in Section 4.1.5.

By (ii), this implies that |vert H (e) ∩ vert H (e )| = 1.

As observed in Definition 9.48(b), there is at most one H-forest F such that N F = N and roots F = R.

Generalizing the terminology of Section 5.2.5 in an obvious way, such a transduction could be called an MS 2,2 -transduction.

This example answers Problem 5.1 of[START_REF] Blumensath | Guarded second-order logic, spanning trees, and network flows[END_REF].

Transductions are here abstract, not concrete (as postulated in the beginning of Section 9.4).

The most powerful result that subsumes all previous ones is in[DvoKT].

Monadic second-order logic is also useful for the definition, the computation and the evaluation (for particular values of their variables) of numerous graph polynomials: see [*CouMR] and[START_REF] Courcelle | A multivariate interlace polynomial and its computation for graphs of bounded clique-width[END_REF].

The references are organized in two parts: the first part (with reference labels starting with *) lists books, book chapters and survey articles. The second one lists research articles and dissertations. For each reference, we indicate between parentheses the pages where it is cited.

Acknowledgements

We thank M. Nivat for writing a preface. The L A T E X typing of the first drafts of most chapters has been done by graduate and doctoral students of Bordeaux 1 University: M. Kanté, R. Chen, R. Synave, R. Li and S. Abbas. We thank them warmly for their care and patience. We also thank A. Arnold, A. Blumensath, S. Djelloul, I. Durand and S. Oum who have read and commented some chapters.

Without being a member of the "Institut Universitaire de France" (IUF), B. Courcelle could not have started the project of writing this book. He thanks M. Nivat and W. Thomas who presented his application to IUF, and all those who supported it by writing recommendation letters. He dedicates his work to the memory of Philippe Flajolet (1948Flajolet ( -2011)), a forty year friend with whom he began his career of researcher at INRIA in 1973.

We obtain (by omitting some computations):

We get the splitting for ϕ 1 from the general scheme: sat(G ⊗ H, ∃z. ϕ 2 , u; v) = pr (sat(G ⊗ H, ϕ 2 , uz; v) ∪ pr (sat(G ⊗ H, ϕ 2 , u; vz)), where pr and pr are the appropriate projections 56 . We obtain: (5.3)

Let us continue our computations. According to Equality (5.2), if we now take the union of the righthand sides of (5.1) and (5.3), we get a splitting of sat(G ⊗ H, ϕ, xy). However, this expression can be simplified because, e.g., sat(G, ∃z.edg(x, z), x) × sat(H, True, y) ⊆ sat(G, True, x) × sat(H, True, y).

We obtain finally the following expression: We will see in Section 5.3.5 (Example 5.54) another proof of the Splitting Theorem for ⊗.

(1) there exist a unique I ⊆ [n] such that T |= χ I and a unique J ⊆ [m] such that S |= χ J ;

(2) we have f (S ⊕ T ) = g I (S) ⊕ g J (T ) where I and J are as in [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF].

We have the desired families (χ i , g i ) 1≤i≤p and (χ j , g j ) 1≤j≤p with p = 2 n and p = 2 m .

Proof of Theorem 5.76: Let L be STR pres -recognizable, with congruence ≡ witnessing its recognizability. First, we define from it another equivalence relation. For S, T ∈ STR(R) we let: S ∼ R T if and only if S ≡ R T and S ∼ 0 T , where S ∼ 0 T means that Th(S, R, 0, 0) = Th(T, R, 0, 0) (i.e., S and T satisfy the same quantifier-free sentences). Since, as shown in the proof of Theorem 5.64, ∼ 0 is a (decidable) locally finite congruence, the equivalence ∼ is also a locally finite congruence witnessing the STR pres -recognizability of L.

We now define from ∼ another equivalence relation ≈ by letting S ≈ R T if and only if f (S) ∼ R f (T ) for every domain restricting QF operation f of type R → R. It is clear that S ≈ R T implies S ∼ R T (because the identity on STR(R) is domain restricting) and hence L is a union of classes of ≈. Each equivalence relation ≈ R has at most p • q classes where p is the number of classes of ∼ R and q is the number of domain restricting QF operations of type R → R, cf. Definition 5.77. Hence the equivalence relation ≈ is locally finite. It remains to prove that it is a congruence on STR.

We first consider disjoint union. We let S, S 1 ∈ STR(R ) and T, T 1 ∈ STR(R ) with S ≈ R S 1 and T ≈ R T 1 . We claim that S ⊕ T ≈ R ∪R S 1 ⊕ T 1 . The goal is to prove that f (S ⊕ T ) ∼ f (S 1 ⊕ T 1 ) for every domain restricting QF operation f of type R ∪ R → R ∪ R . Consider one of them, f , to which we apply Lemma 5.79. Since S ≈ R S 1 , we have S ∼ R S 1 and hence S and S 1 satisfy the same quantifier-free sentences. The same holds for T and T 1 . Hence we have indices i and j (cf. Lemma 5.79) for which T |= χ i and S |= χ j , so that we also have T 1 |= χ i and S 1 |= χ j . Hence we have f (S ⊕T ) = g i (S)⊕g j (T ) and also f (S 1 ⊕ T 1 ) = g i (S 1 ) ⊕ g j (T 1 ). We have g i (S) ∼ g i (S 1 ) and g j (T ) ∼ g j (T 1 ) since S ≈ R S 1 and T ≈ R T 1 . Hence g i (S) ⊕ g j (T ) ∼ g i (S 1 ) ⊕ g j (T 1 ), i.e., f (S ⊕ T ) ∼ R ∪R f (S 1 ⊕ T 1 ). Hence S ⊕ T ≈ S 1 ⊕ T 1 as was to be proved.

We now consider S, S 1 ∈ STR(R) such that S ≈ S 1 , and a QF operation k of type R → R . We must prove that k(S) ≈ k(S 1 ). Let f be domain restricting of type R → R . The mapping f • k is a QF operation of type R → R by Proposition 5.49. Let us apply Lemma 5.78. We have f (k(S)) = g(h(S)) and f (k(S 1 )) = g(h(S 1 )). Since S ≈ S 1 , we have h(S) ∼ h(S 1 ) hence g(h(S)) ∼ g(h(S 1 )) since g is quasi-domain preserving and ∼ is a congruence on STR pres . Hence the equivalence ≈ is a congruence on STR. This completes the proof of recognizability.

If ≡ is a decidable congruence, then so are ∼ and ≈ (cf. Corollary 5.95). Hence the result for semi-effective recognizability follows from Proposition 3.78 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF].

The proof for effective recognizability is essentially the same as the above proof, using locally finite algebras rather than congruences. It also proves the CHAPTER 5. MONADIC SECOND-ORDER LOGIC one checks easily. Hence is a homomorphism : N k , +, 0 → Q and -1 (q) is recognizable in N k for each q ∈ Q. From these remarks and Proposition 5.25, we get the existence of a CMS sentence ϕ that defines L. This sentence can be written: ∃X 1 , . . . , X k [ "(X 1 , . . . , X k ) is a partition of the set of nodes" ∧ ( qi∈Q0 rt ∈ X i ) ∧ "for every i ∈ [k] and every u ∈ X i , if S is the set of sons of u, then the k-tuple (|S ∩ X 1 |, . . . , |S ∩ X k |) belongs to -1 (q i )" ].

We now consider the case where L is a set of trees. Then, we have (4) =⇒ ( 1) and ( 1) =⇒ (2). For proving (2) =⇒ (3 ), assume that L is recognizable in JS t . Let R be the set of all rooted trees; it is recognizable in JS t . Since Unr -1 (L) = R∩fg -1 rt (und -1 (L)), it is recognizable in JS t by Proposition 3.85(1) (for the intersection, and for fg -1 rt because fg rt is an operation of the algebra JS t ) and by Proposition 3.56(2) (for und -1 because und is a homomorphism from the directed version of JS t to its undirected version). Hence Unr -1 (L) is recognizable in R by the implication (2) =⇒ (3) for rooted trees. For proving (3 ) =⇒ (4), we assume that Unr -1 (L) is recognizable in R. It is thus CMSdefinable, from which we get easily that L is CMS-definable.

Remarks 5.84

(1) Finite automata, called R-automata, that run bottom-up on rooted trees are studied in [START_REF] Boneva | Automata and logics for unranked and unordered trees[END_REF][START_REF] Courcelle | On recognizable sets and tree automata[END_REF][START_REF] Courcelle | Basic notions of universal algebra for language theory and graph grammars[END_REF]] and [*Lib06]. Rooted trees are called in these works unranked, unordered trees, because terms are (inadequately) called trees. These automata have infinitely many transition rules, because rooted trees have unbounded degree, but their rules are described in finitary ways. In the proof of the previous theorem, the sets -1 (q) describe the transition rules of a finite R-automaton with set of states Q. Since the sets -1 (q) are recognizable in N k , they can be described by CMS formulas by Proposition 5.25. The corresponding automaton with states q 1 , . . . , q k works as follows: if the sons u 1 , . . . , u n of a node u are in states p 1 , . . . , p n respectively, if m j for j = 1, . . . , k is the number of indices i such that p i = q j and if (m 1 , . . . , m k ) ∈ -1 (q), then q is a possible state for u. The accepting states are those of Q 0 , cf. the proof that (3) implies (4). This proof shows that if a set of rooted trees is recognizable in R, then it is accepted by an R-automaton. The R-automata constructed in this proof are actually deterministic and complete because is a mapping from N k to Q. More details on these automata can be found in the above quoted references.

(2) The set of odd stars {K 1,2n+1 | n ≥ 0} (i.e., of rooted trees where the root is the node of degree 2n+1) is recognizable in R (the construction of a congruence is easy), and C 2 MS-definable. It is not . (and similarly for Case (3)). Parsing algorithms will be reviewed in Section 6.2. More concrete constructions of automata than those based on the proof of the Recognizability Theorem (Theorem 5.64) will be given in Section 6.3.

From Theorem 6.3 and by using the algorithms reviewed in Section 6.2 below, we get the following result on the model-checking of graphs. Theorem 6.4

(1) For all finite sets K and Λ of vertex and edge labels, the model-checking problem MC(J S [K,Λ] [∅], CMS 2 ) is fixed-parameter linear with respect to (twd (G), ϕ), where G is the input graph and ϕ is the input sentence.

(2) For all finite sets K and Λ of vertex and edge labels, the model-checking problem MC(GP [K,Λ] [∅], CMS) is fixed-parameter cubic with respect to (cwd (G), ϕ), where G is the input graph and ϕ is the input sentence.

In these statements, we consider K and Λ as parts of the input, 6 but not as parts of the parameter.

Proof: [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] Let G be a (K, Λ)-labelled graph with n vertices and edges (i.e.,

We first show that it suffices to prove the result for parameter (twd (G), K, Λ, ϕ) instead of (twd (G), ϕ). The validity of ϕ in G depends only on the labels from K ∪ Λ that actually occur in ϕ.

The function f is computable because the sets K ϕ and Λ ϕ of useful labels are computable from ϕ.

We now prove the result for parameter (twd (G), K, Λ, ϕ). We know from the proof of Theorem 1.25 that an algorithm can compute an optimal treedecomposition of the unlabelled undirected graph core(G) in time at most f (twd (G)) • n for some computable function f . 7 The linear time algorithm of Theorem 2.83 transforms this tree-decomposition into a term s in T (F HR [twd(G)+1] ) that evaluates to core(G); this algorithm computes also a corresponding witness. The algorithms of Proposition 2.47 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF]2)

The result follows then from Theorem 6.3(2).

(2) The proof for parameter (cwd (G), K, Λ, ϕ) is similar to the one in ( 1), but the corresponding parsing problem is more difficult. In Section 6.2.3 we will prove the existence of an algorithm that, for a simple (K, Λ)-labelled graph G 6 So, more precisely, Statement [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] says that the problem MC( K,Λ J S [K,Λ] [∅], CMS 2 ) is fixed-parameter linear with respect to (twd(G), ϕ), where the union extends over all finite sets K and Λ of vertex and edge labels. Note that K,Λ J S [K,Λ] [∅] is the class of all labelled graphs.

7 Recall from Remark 2.55(d) that twd(core(G)) = twd(G).

We now define from b a set of accepting states for C . We let Acc be the set of m-tuples (q 1 , . . . , q m ) ∈ Q C such that b(v 1 , . . . , v m ) = True where v j is True if q j ∈ Acc Aj and is False otherwise. Here, b is evaluated on truth values with ∪, ∩ and interpreted respectively as ∨, ∧ and ¬. We let B be the F -automaton consisting of the semi-automaton C and Acc as set of accepting states. It is clear that

, written without the complementation operation , then this construction is valid provided the automata A i are complete; they need not be deterministic. The automaton B is then complete.

In all cases, B = A 1 × • • • × A m , but B may be replaced by a smaller automaton by reduction or by minimization in the case where it is deterministic. Hence, we have proved the following proposition. Proposition 6.10 Let F be a functional signature. If L 1 , . . . , L m are regular subsets of T (F ), recognized by complete and deterministic automata with, respectively, n 1 , . . . , n m states, then every Boolean combination of L 1 , . . . , L m is recognized by a complete and deterministic automaton with at most n 1 × • • • × n m states. The same holds for a positive Boolean combination of languages L 1 , . . . , L m and automata that are complete but not necessarily deterministic.

Direct and inverse images of automata

We will need certain images and inverse images of languages recognized by automata. Let H be a functional signature (possibly H = F ), and h : H → F be an arity preserving mapping, i.e., such that ρ(h(f )) = ρ(f ) for every f ∈ H. For every t ∈ T (H), we let h(t) ∈ T (F ) be the term obtained from t by replacing f by h(f ) at each of its occurrences. The mapping h on terms is an alphabetic relabelling (cf. the paragraph before Proposition 2.126).

If L ⊆ T (H), then h(L) := {h(t) | t ∈ L}. If A is an H-semi-automaton, we let h(A ) be the F -semi-automaton obtained from A by replacing each transition rule f [q 1 , . . . , q ρ(f ) ] → q by h(f )[q 1 , . . . , q ρ(f ) ] → q. Clearly, h(L(A , q)) = L(h(A ), q) for every state q. In general, h(A

, where h(A ) has the same accepting states as A . We call this transformation the direct image construction.

We now consider inverse images.

We have L(h -1 (A ), q) = h -1 (L(A , q)) for every state q, and L(h

We call this transformation the inverse image construction. Proposition 6.11 Let h : H → F be an arity preserving mapping between functional signatures.

Similarly for ⇒, ⇔ and False. In order to facilitate formal constructions, variables will be of the forms X i and x j for i, j ∈ N + . Relational signatures will be without constant symbols. Definition 6.16 (Formulas without first-order variables) Let R be a relational signature without constant symbols. For each n ∈ N , we let X n := {X 1 , . . . , X n } and X ω := {X i | i ∈ N + }. In order to write formulas without first-order variables, we will use the following atomic formulas, whose meanings are specified unless they are clear: True, Card p,q (X i ) for 0 ≤ p < q and q ≥ 2,

We could express

), at the cost of introducing more quantifiers. Since these formulas are used frequently, it is convenient to take them as atomic formulas. The equality X i = X j is expressed by X i ⊆ X j ∧ X j ⊆ X i but it could also be added as another atomic formula.

We will denote by C r MS (R, X ) (for r ∈ N and X ⊆ X ω ) the set of monadic second-order formulas that have their free variables in X and are written with these atomic formulas for i, j, i 1 , . . . , i ρ(R) ∈ N + and q ≤ r, the Boolean connectives and existential quantifications on set variables. We will write CMS (R, X ) if we do not wish to bound q in the atomic formulas Card p,q (X i ).

We will denote by mfv (ϕ) the maximal index i ∈ N + of a free variable in a formula ϕ in CMS (R, X ω ).

The following lemma says that the languages C r MS and C r MS have the same expressive power. Lemma 6.17

State q

Property P q (0, B)

there is no path between v and v in G(t, X 2 )

Error all other cases Table 6.10: Meanings of the states of B C,Path(X1,X2) .

auxiliary functions:

These definitions reflect respectively Properties (4) and (3) of Claim 6.39.1. This completes the construction of B C,Path(X1,X2) .

As for the previously constructed automata, we omit the correctness proof. Hence, we admit that all computations of the semi-automaton B C,Path(X1,X2) (as defined by Table 6.11) satisfy the properties of Table 6.10. This table shows that some states cannot occur in any computation. For example, by the definition of the function β, the component B of each accessible state must be a symmetric and reflexive relation. All states for which B is not so are inaccessible and, consequently, are eliminated if we trim the automaton (cf. Section 3.3.1, Definition 3.48). The state (1, {a}, ∅)

. The cardinality of the set of accessible states is somewhat less than that, but it lies between 2 k(k-1)/2 and 2 k 2 +2 as one can easily check. Determining its exact value is of no interest because the corresponding minimal automaton matters more than this one, even after trimming.

Let us now see what would give the expression of the property Path(X 1 , X 2 ) by the MS formula:

of quantifier-height 5 (its construction uses Property P2 of Proposition 5.11). Its translation into a formula without first-order variables has the same quantifier-

Transition rules

Conditions

A is the set of port labels in G(t) of the vertices x in X 1 that are not the head of an edge with tail in X 2 . P Error : X 1 ∩ X 2 = ∅.

Bounded indegree: An automaton for InDeg p (X 1 , X 2 ), where p ≥ 0, with less than (p + 2) 2k states is constructed and proved to be correct in [START_REF] Courcelle | Automata for the verification of monadic second-order graph properties[END_REF]. It is intended to run on irredundant terms.

A term t in T (F

) is irredundant if, for every occurrence w of an operation --→ add a,b (or add a,b ) with son w 1 , the p-graph cval (t)/w 1 has no edge from an a-port to a b-port (or between an a-port and a b-port). The edge addition operations strictly below w that create these edges can be removed: the term obtained in this way is equivalent to t. Hence, every term t ∈ T (F Example 6.43(3): Perfect graphs A (simple, loop-free and undirected) graph G is perfect if, for every induced subgraph H of G, the chromatic number is equal to the clique number, i.e., the smallest number p such that H is p-vertex colorable equals the maximum size of a clique of H.

We first consider chordal graphs: they are all perfect ([*Gol]). A nonempty connected (simple, loop-free and undirected) graph is chordal (Section 2.4.4, Proposition 2.72) if and only if it does not contain an induced cycle C n for any n ≥ 4. The existence of such a cycle is expressed as follows:

This example is not intended to provide an efficient algorithm for testing chordality, but to illustrate the use of set terms to get a compact formula. The validity of Path(X ∩ Y, X) implies that X ∩ Y has cardinality 2. Hence the condition St(X ∩ Y ) can be replaced by St 2 (X ∩ Y ) where St 2 (Z) means that Z is stable and has two elements. This is interesting because a complete and deterministic automaton for this property with only 3 + k(k + 1)/2 states (instead of 2 k + 1 for St(Z)) can be easily constructed; it is similar to the one for edge(X 1 , X 2 ). Hence, by this observation, we get (before minimization), a smaller automaton for the nonchordality of nonempty, connected, simple, loop-free and undirected graphs.

The definition of perfect graphs is not monadic second-order expressible (because the fact that two sets have the same cardinality is not) but their characterization established in [ChuRST] in terms of excluded holes and antiholes is. A hole is an induced cycle of odd length at least 5 and an antihole is the edge-complement of a hole. A graph has a hole if and only if it satisfies the following sentence:

where Deg 2 (X 1 , X 2 ) means that each vertex in X 1 is adjacent to exactly two vertices in X 2 . However, since we consider loop-free graphs, Deg 2 (X 1 , X 2 ) is equivalent to InDeg 2 (X 1 , X 2 ) (an undirected edge is a pair of opposite directed edges). Thus, the property of having a hole (for a loop-free undirected graph) is in EB(P Bool ).

Every term t ∈ T (F VR [k] ) can be transformed in linear time (for fixed k) into an equivalent irredundant one t in T (F VR [k] ) and into an irredundant term t ∈ T (F VR [2k] ) that defines the edge-complement of the graph val (t), see the proof of Proposition 2.105(4). We obtain that a graph val (t) is perfect if and only if the F VR [2k] -automaton for holes rejects both t and t. The algorithm of [ChuCLSV] can test if G is perfect in time O(n 9 ) (where n is the number of vertices). From this logical expression of holes, we get a transduction. By contrast, the class of rational transductions ([*Sak, Niv]) is closed under inverse.

For L ∈ {CMS, MS, FO, . . . }, an L-transduction τ is invertible if its inverse τ -1 is an L-transduction. This condition does not imply that τ is injective. (We will also use in Definition 7.9 injective and invertible CMS-transductions.) If a CMS-transduction is invertible, there are two positive rational numbers k and k such that k

Examples 7.3

(1) Quotient structures. Let us assume that a CMS formula ϕ(x, y) defines on each structure S of a class C ⊆ STR c (R) an equivalence relation ≈. Such a relation may be the equivalence relation generated by a relation E ⊆ D S × D S defined in each S ∈ C by a CMS formula ψ(x, y) (in particular because the reflexive and transitive closure of a CMS-definable relation is CMS-definable, cf. Section 5.2.2).

We define the quotient structure S/≈ as the R-structure and [a] denotes the equivalence class of a (cf. Example 1.35 and Definition 2.15).

We must actually define S/≈ as [T ] iso for a concrete structure T . As domain D T of T , we take a cross-section of ≈ as value of a parameter Y and we specify the relations R T accordingly. This can be done by a noncopying definition scheme D with one parameter Y ; its precondition expresses that Y denotes a cross-section of ≈ (for a structure S in C). For each S in C, all structures in D(S) are isomorphic to one another. Hence the total function S → S/ ≈ from C to STR(R) is a CMS-transduction on C, and the definition scheme D is parameter-invariant. The concrete transduction D is not functional.

(2) Quantifier-free operations. Quantifier-free operations : STR c (R) → STR c (R ) where R 0 = ∅ are defined in Section 5.3.2 (Definition 5.42) by means of QFO definition schemes which are parameterless noncopying QF-definition schemes with True as precondition. Note that if R 0 = ∅ and D is quantifier-free and parameterless, then its precondition can only be True or False.

(3) Transductions that order linearly. In Definition 5.28 we have defined the notion of a pair of MS formulas (α(X 1 , . . . , X m ), β(X 1 , . . . , X m , x 1 , x 2 )) that orders linearly the structures of a set C of concrete R-structures. Such a pair can be made into a noncopying definition scheme

The corresponding MS-transduction D expands each structure S in C by a linear order (in one or several ways). If S ∈ STR c (R) -C, then D(S) may be empty or contain expansions of S by binary relations that are not linear orders of D S .

(4) Second-order substitutions. Let F and H be finite functional signatures and, for each g in H, let t g be a term in T (F, {x 1 , . . . , x ρ(g) }). The associated second-order substitution θ H : T (H) → T (F ) replaces each g in H by the term t g that is its definition over F ; a formal definition is in Section 2.6.1, Definition 2.125. We say that θ H is linear if each term t g is linear, that is, if no

The quantifier-height of

We let then β D i be:

We will drop the subscript i, writing β D and β D , whenever [k] n is a singleton, i.e., either k = 1 and n ≥ 1, and so i = (1, . . . , 1), or n = 0, and so i

We call the family

n the backwards translation of β relative to the definition scheme D. We will also use the notation τ # (β) for β D , where τ = D. 9 Lemma 7.11 For every concrete R-structure S, every W-assignment γ in S such that D(S, γ) is defined, every {X 1 , . . . , X m } (k) -assignment η in S such that η [k] is an {X 1 , . . . , X m }-assignment in D(S, γ), every {y 1 , . . . , y n }-assignment µ in S and every i ∈ [k] n such that µ i is a {y 1 , . . . , y n }-assignment in D(S, γ), we have:

Proof: The proof is a straightforward verification by induction on the structure of β. We only check a few cases. We let T := D(S, γ).

If β is y j = y j , then µ i (y j ) = (µ(y j ), i[j]) and similarly for j ; hence µ i (y j ) = µ i (y j ) in T if and only if µ(y j ) = µ(y j ) and i

can be expressed by the validity of δ i (X (i) ) with A (i) as value of X (i) for each i. By using the induction hypothesis for β , we have:

Evaluation of monadic second-order transductions

The following result is an application of the fixed-parameter algorithms for the problems considered in Sections 6.4. 1 and 6.4.2. As usual, F is a finite functional signature and R a relational signature.

Theorem 7.29 Let τ be a CMS-transduction : T (F ) → STR c (R) defined with a set of parameters W. Given a term t in T (F ) and a W-assignment γ in t , one can decide in time O(|t|) whether the structure Proof: Let be given a definition scheme D for τ , with set of parameters W. Given a term t in T (F ) and a W-assignment γ in t , one can decide in time O(|t|) whether ( t , γ) |= χ D by the results of Section 6.4.1 showing that Theorem 6.3(1) extends to property-checking problems. The structure S := τ (t, γ) is defined if and only if the answer is positive.

If this is the case, in order to compute S, we must compute the sets defined by the other formulas of D. Together with Lemma 6.17, Theorem 6.55 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] shows that, for every formula ϕ with free variables in W ∪ {x 1 , . . . , x n }, one can compute the set Note that the time to compute S is polynomial in |t|:

The evaluation of (parameterless) monadic second-order graph transductions is discussed in Remarks 7.31(2) and 8.19(3).

The Equationality Theorem for the VR algebra

The main result of this section is a logical characterization of the VR-equational sets of (simple) graphs as the images of trees under monadic second-order graph transductions. 13 This theorem links structural aspects (algebraic descriptions of certain sets of graphs) and logical ones. It shows how tightly monadic secondorder logic is linked with a certain type of graph structuring. There will be a companion theorem for HR-equational sets. These Equationality Theorems link Corollary 7.38

(1) A set of labelled p-graphs of bounded type has bounded clique-width if and only if it is included in the image of trees under a monadic second-order p-graph transduction (MS or CMS).

(2) For every monadic second-order p-graph transduction τ there exists a computable function f τ : N → N such that, for every (possibly labelled) p-graph G and every (possibly labelled) p-graph

(3) For every parameterless monadic second-order graph transduction θ there exists a computable function f θ : N → N and an algorithm 19 that transforms a term t in ] ) that evaluates to θ(val (t)), provided θ(val (t)) is defined. This algorithm operates in time g(θ, k)•|t| for some computable function g.

Proof:

(1) The only-if direction was proved in Corollary 7.33 but is also an immediate consequence of Theorem 7.36 because the set L of (K, Λ)-labelled p-graphs of clique-width at most k and of type included in a finite set D is VRequational (Example 4.43( 5)). The if direction is immediate from Theorem 7.36 because every VR-equational set has bounded clique-width (Proposition 4.44).

(2) We apply Corollary 7.37 to the VR-equational set L of ( 1). One can construct (at least in principle) a VR equation system defining its image L under τ , and from it, one can determine some integer k that bounds the cliquewidth of the p-graphs in L . Hence we can take f τ (k) := k . This proves the existence of the desired computable function f τ . Note that f τ (k) is computable by an algorithm that takes as input k and a definition scheme of τ .

(3) Let be given a parameterless monadic second-order graph transduction θ that maps (K, Λ)-labelled graphs to (K , Λ )-labelled ones. We will apply Theorem 7.34 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF], with D := ∅, to the parameterless MS-transduction τ :

) into a (K , Λ )-labelled graph. The set C defined by this theorem can be taken equal to [k ] and we let f θ (k) := k . The mapping µ resulting from this theorem is a parameterless MS-transduction from terms to terms and so, t := µ(t) can be computed in linear time in |t| (Theorems 7. 29 and 8.14). The construction of µ takes time g 1 (θ, k) and the computation of µ(t) takes time g 2 (θ, k) • |t| for fixed computable functions g 1 and g

This corollary establishes the fact used in the proof of Proposition 6.8 (in Section 6.2.3) that relates the clique-width of an edge-labelled directed graph G and that of its encoding by a vertex-labelled undirected graph B Λ (G), where Λ is the set of edge labels:

We know from Section 6.3.3 that the set L ϕ,n defined as {t *

The result follows then from Corollary 3.26.

If L is a VR-equational set of graphs or, more generally by Theorem 7.36, the image of trees under a CMS-transduction, then L = τ (T (F )) for a finite functional signature F and an MS-transduction τ that is parameterless and noncopying (Proposition 7.27(2) and Lemma 7.35). By the Backwards Translation Theorem (Theorem 7.10), an MS formula τ # (ϕ) can be constructed from τ and ϕ such that, for every t ∈ T (F ), we have

The result follows then from the first case.

As an example of the use of this theorem, let L be a VR-equational set of graphs and ϕ(X, Y ) be a formula expressing that X ∩ Y = ∅ and every vertex in X is adjacent to every vertex of Y . Then

Since the class of semi-linear sets is (effectively) closed under intersection (Theorem 6.1 of [GinSpa]), it is therefore decidable whether

, whether there exists n ∈ N such that every graph of L is without K n,n , see Theorem 4.51. Hence, by Theorem 4.51, it is decidable whether L is HR-equational. (The implication (3) =⇒ (1) of Theorem 4.51 will be proved in Section 9.4.3.)

Let us finally raise a question:

Question 7.43 Is it true that if a set L of R-structures satisfies the semilinearity property, i.e., is such that -→ #sat(L, ϕ, X) is semi-linear for every CMS formula ϕ, then its image under a CMS-transduction satisfies also this property?

Graph transductions using incidence graphs

Monadic second-order formulas can express graph properties by means of two representations of a graph G by relational structures denoted respectively by G and G (cf. Definition 5.17). Hence there are four types of monadic second-order graph transductions since there are two possibilities for the inputs and the outputs.

The notations MS i,j and C r MS i,j for i, j ∈ [2] (already defined in Section 1.8.2) refer to these different types where i = 1 (resp. j = 1) if and only if the representation • is used for the input (resp. the output). The same Proof: We let U 1 , U 2 , U 3 be unary relation symbols and W be a ternary symbol. We let C be the set of {≤, U 1 , U 2 , U 3 , W }-structures S that expand the structures D n with subsets A, B, C interpreting respectively U 1 , U 2 , U 3 and a ternary relation Let L be an extension of monadic second-order logic such as MS+Eq or CMS+P 23 . Assume that θ A (x 1 ), θ B (x 1 ), θ C (x 1 ) and θ R (x 1 , x 2 , x 3 ) are formulas in L({≤}, {x 1 , x 2 , x 3 }) satisfying the following, for every n > 1:

Then, we define C ⊆ C as the set of structures S n and we have:

The last sentence belongs to L({≤}, ∅). It follows that the MS-satisfiability problem for τ (C ) reduces to the L-satisfiability problem for D. If the integers α(S n ) are unbounded, then the monadic second-order satisfiability problem for τ (C ) is undecidable (by Theorem 5.6 and the Reduction Theorem 28 ), and so is the L-satisfiability problem for D.

We will prove that this is actually the case if L = MS+Eq and if L = CMS+P 23 . In each case, we will construct formulas θ From the above Remark (a) these facts imply that all intervals of I(Y ) have the same cardinality and, finally, that z = min(Y ) • |Y |, min(Y ) is a power of 2 and |Y | is a power of 3. If z = 2 k 3 m with k ≥ 1 and m ≥ 1, then there exists a (unique) set Y as above and 2 k is its least element. We let ϕ(z, x) be the CMS+P 23 formula expressing that there exists a set Y with least element x that satisfies conditions (i), (ii) and (iii).

We now consider the following conditions similar to (i), (ii) and (iii): Hence, the CMS+P 23 formula ϕ(z, x) ∧ ϕ (z, y) expresses that z = x • y with x = 2 k for some k ≥ 2 and y = 3 m for some m ≥ 1.

If n ≥ 12, then there exist a, b ∈ [n] such that:

(C) a = 2 p for some p ≥ 2, b = 3 q for some q ≥ 1, ab ≤ n and b < a.

Furthermore, there is a unique such pair (a, b) such that (b, a) is lexicographically maximal and satisfies Condition (C). This pair is of the form (2 pn , 3 qn ).

From the above constructions, we can see that the elements 2 pn , 3 qn and 2 pn •3 qn can be defined in D n by CMS+P 23 formulas. So can the sets Hence, for a maximal pair (as defined above), we have q n ≥ r. It follows that α(S n ) ≥ log(n)/4 , hence the numbers α(S n ) are unbounded. This completes the proof.

This proof suggests one more question.

Question 7.61 Is the (CMS+Prime)-satisfiability problem for D decidable, where Prime is the set of prime numbers?

One can raise a similar question for VR-recognizability, about which we make no conjecture.

Question 7.63 Is it true that every VR-recognizable set of simple graphs of bounded clique-width is CMS-definable?

A positive answer would imply a positive answer to Conjecture 7.62 relativized to the class of simple graphs. Let us prove this implication: if L is an HR-recognizable set of simple graphs of bounded tree-width, then, by Theorem 4.59 (proved in [CouWei]), it is VR-recognizable because it is without K n,n for some n, hence it is CMS-definable (assuming positive the answer to the question) and thus CMS 2 -definable.

All above-cited articles use (essentially) the same technique that we now describe. The binary signature F HR

[k] has a unique binary operation which is associative and commutative. Hence, the homomorphism val :

); we will denote by val AC the corresponding homomorphism :

The objective is to apply Theorem 5.88 of Section 5.5. Note that we drop H := { } from the notation of Definition 5.85, i.e., we write T AC (F HR

[k] ) for T AC (F HR [k] , H). Moreover, we will denote the domain of this algebra by T AC (F HR [k] ) instead of T (F HR [k] )/≡ AC(H) , and refer to its elements as terms (they are, in fact, equivalence classes of terms with respect to the equivalence ≡ AC(H) ); see Section 5.5 for the representation of these "terms" by relational structures.

Let C be a set of graphs, k be a nonnegative integer and C k be the set of graphs in C of tree-width at most k. Assume that there exists an integer f (k) ≥ k and a CMS 2,1 -transduction τ k :

(1) that associates with every graph G in C k at least one term in T AC (F HR [f (k)] ) in such a way that:

(2) val AC (t) = G for every term t in the set τ k (G).

If L ⊆ C k is HR-recognizable, then it is also recognizable in the algebra JS gen [[k]] (cf. the proof of Corollary 5.69). Hence the set val

) (cf. Definition 5.85), and so it is CMS-definable by Theorem 5.88. Then the set of graphs L is τ -1 k (val -1 AC (L)) and is CMS-definable by the Backwards Translation Theorem (Theorem 7.10).

The key point is thus the construction of τ k . We make two observations. First, unless C is finite or in some other way very particular (for example the set paths), we cannot replace

) (and val AC by val ) in the above proof method. Consider the set C of graphs without edges. We have proved in Proposition 7.28 that the rooted trees generated from C by a fixed CMS-transduction have a bounded number of nonleaf nodes. Hence Conditions (1) and (2) cannot be satisfied with

), and even for k = 0.

For a functional signature F , we use the relational signature R

where N t is the set of nodes of the syntactic tree of t, lab f t = Occ(t, f ), son i t is the set of pairs (u, v) such that v is the i-th son of u and rt t = {root t }. Without rt, this definition of R F and t is the same as in the beginning of Example 5.2(3) and the beginning of Section 6.3.3. Note that we have taken the rt relation to be of arity 1, to avoid relational signatures with constants. In fact (as observed in Example 5.2(3)), the relation rt is superfluous, because it is FO-expressible in terms of the others: rt(x) ⇐⇒ ¬ i∈[ρ(F )] ∃y. son i (y, x). Thus, whenever we define a monadic second-order transduction to T (F ), we need not (and usually will not) specify the relation formulas θ rt,i that define the rt relation in the output structure. The rt relation is, however, needed because we will use Application 5.61 (see Sections 8. 1.3 and 8.4).

In this chapter we view words as a special case of terms, viz. unary terms. In this way we avoid the duplication of definitions and proofs. For an alphabet A, there is a natural bijection µ A : A * → T (U A ), where U A is the unary functional signature A ∪ { } ( / ∈ A) with ρ(a) = 1 for every a ∈ A and ρ( ) = 0: the word

In fact, µ A is the inverse of the mapping val W left (A) , see Definition 2.7. A language L ⊆ A * is regular if and only if the set of unary terms µ A (L) ⊆ T (U A ) is regular (see Remark 3.20(4), the discussion after Proposition 3.23, and Remark 3.51(2)).

A word w ∈ A * is faithfully represented by the R U A -structure w := µ A (w) (cf. Example 5.2(3)). In this chapter it is important that the empty word ε is represented by a structure with a singleton as domain rather than by the empty structure. The reason is that an MS-transduction transforms the empty structure into itself, whereas it can transform a singleton structure into any other structure (Proposition 7.17). For MS-transductions, the definition of w in Example 5.2( 1) is strongly equivalent to the above definition, provided ε is defined to have a singleton as domain (see Definition 7.9).

By Propositions 5.29 and 5.30, CMS-transductions taking terms or words as input are also MS-transductions. Hence, without loss of generality, we will only consider MS-transductions of terms and words. We will mainly consider deterministic devices, i.e., parameterless definition schemes and deterministic transducers; to stress this, we will also use 'deterministic' instead of 'parameterless'. We recall that parameterless MS-transductions are partial functions. We denote by DMSOW the class of parameterless MS-transductions of words (where the 'D' stands for 'deterministic' whence 'parameterless'), by DMSOT the class of parameterless MS-transductions of terms, and by DMSOTW those from terms to words. Thus, DMSOT is the class of all transductions τ : T (F ) → T (H) such that τ := {( s , t ) | (s, t) ∈ τ } (or more precisely, [τ ] iso ) is a parameterless MS-transduction from STR(R F ) to STR(R H ), and similarly for the other two classes (cf. Section 7.1.3). 1 It follows from Theorem 7.14 that DMSOW and DMSOT are closed under composition.

A term t ∈ T (F ) is a special kind of word over the alphabet F (cf. Definition 2.2). If w t denotes the term t viewed as a word, then t and w t are different structures. However, the mapping t → w t is a noncopying parameterless MS-transduction. Thus, by the closure of the class of MS-transductions under composition, we have that DMSOT ⊆ DMSOTW.

As observed in Definition 7.2 (and in Fact 1.37), every MS-transduction τ (of structures) is of linear size increase, i.e., there is an integer k such that |D T | ≤ k • |D S | for every (S, T ) ∈ τ . For terms and words this implies |t| ≤ k • |s| for every (s, t) ∈ τ , i.e., the size of the output is linear in the size of the input. An arbitrary transduction τ has finite images if τ (S) = {T | (S, T ) ∈ τ } is finite (up to isomorphism) for every input structure S. Since, for given n and R, there are only finitely many R-structures T such that |D T | ≤ n (up to isomorphism), every transduction of linear size increase (of type R → R), in particular every MS-transduction, has finite images.

Automata

Recall from Definition 3.46 in Section 3.3.1 that, given a functional signature F , a (bottom-up, ε-free) automaton over F (or F -automaton) is a tuple A = F, Q, δ, Acc where Q is a set of states, Acc ⊆ Q is the set of accepting states, and δ is a set of transition rules of the form f [q 1 , . . . , q k ] → q with f ∈ F k and q, q 1 , . . . , q k ∈ Q (if k = 0, the transition rule is also written f → q). An automaton without accepting states is called a semi-automaton. Recall from Definition 3.49 that A is complete and deterministic if for every f ∈ F k and q 1 , . . . , q k ∈ Q there is exactly one transition rule f [q 1 , . . . , q k ] → q in δ (with q ∈ Q). This definition is based on viewing A as a bottom-up device.

In Section 8.5 we will also view A as running top-down. In that case, intuitively, Acc is the set of initial states (because A starts at the root of the input tree), and a transition rule f [q 1 , . . . , q k ] → q in δ is used from right to left: if A is in state q at node u with label f , then A branches and moves to the i-th son of u in state q i , for each i ∈ [k]. With this view in mind, we say that A is top-down complete and deterministic if Acc is a singleton and for every q ∈ Q and f ∈ F k with k = 0 there is exactly one transition rule f [q 1 , . . . , q k ] → q in δ (with q 1 , . . . , q k ∈ Q).

Let A = F, Q, δ be a complete and deterministic semi-automaton. For f ∈ F k and q 1 , . . . , q k ∈ Q we denote by δ f (q 1 , . . . , q k ) the unique state q such that f [q 1 , . . . , q k ] → q is a transition rule in δ. For s ∈ T (F ) and u ∈ N s , the state in which A reaches u is the state run A ,s (u), where run A ,s is the unique run of A on s, cf. Definition 3.49. This state can also be defined recursively, as follows: if u ∈ Occ(s, f ) with ρ(f ) = k, then run A ,s (u) = δ f (run A ,s (u 1 ), . . . , run A ,s (u k )), where u 1 , . . . , u k are the sons of u.

Now let A = F, Q, δ, Acc be top-down complete and deterministic. For s ∈ T (F ) and u ∈ N s we define td -run A ,s (u) ∈ Q, the state in which A reaches u top-down, recursively as follows: td -run A ,s (root s ) is the state q such that Acc = {q}, and if u ∈ Occ(s, f ) with ρ(f ) = k = 0 and with sons u 1 , . . . , u k , To define the computations of the MS tree-walking tree transducer M we will use regular grammars (Definition 3.17). For every input term s ∈ T (F ) we define a regular grammar G M,s := H, X M,s , R M,s over the output signature H. The set X M,s of nonterminals consists of all pairs q, u with q ∈ Q and u ∈ N s (i.e., u is a node of s). Such a pair is called a configuration of M on s. If q, ϕ → ζ is a rule in R, then R M,s contains a rule q, u → ζ for every u ∈ N s such that s |= ϕ(u), where ζ equals 1. q , v and v is the unique node such that s |= ψ(u, v), or

respectively (according to the two possible forms of ζ mentioned above). The computations of M on input s are the derivation sequences of the grammar G M,s .

There may be infinitely many such sequences. The transduction computed by M , denoted τ M , is defined as

In other words, (s, t) is in τ M if t is in the language generated by G M,s from the initial configuration q in , root s . If M is deterministic then distinct rules of G M,s have distinct lefthand sides. This implies that M has exactly one (possibly infinite) maximal computation on s starting with q in , root s , to which we will refer as the computation of M on s. Consequently, L(G M,s , q in , root s ) is either empty or a singleton, and hence τ M is a (partial) function.

The MS tree-walking transducer M is single-use if it satisfies the following property: for every s ∈ T (F ), ξ ∈ T (H, X M,s ), t ∈ T (H), and q, u ∈ X M,s , if q 0 , root s ⇒ * G M,s ξ ⇒ * G M,s t then q, u has at most one occurrence in the term ξ. Note that every ms-twt with a unary output signature is single-use. The class of transductions computed by single-use deterministic MS tree-walking transducers is denoted DTWT MS su . We will prove in Theorem 8.6 that it equals DMSOT. It follows from the proof that the single-use property is decidable.

The transducer M is an MS tree-walking tree-to-word transducer if H is unary (with the constant symbol ).

In this case, one may view M as having a one-way output tape on which the output word is written. The class of transductions computed by deterministic MS tree-walking tree-to-word transducers is denoted DTWTW MS .

The transducer M is an MS two-way finite-state transducer if both F and H are unary.

Finally, M is an MS tree-walking automaton if H = { }, with ρ( ) = 0. In that case the language recognized by M is defined as

The transduction computed by M is

Note that, by Theorem 8.7, for every ms-twt there is an equivalent p-ms-twt (with Γ = {γ in }).

As for an ms-twt, an MS tree-walking pushdown transducer is a tree-toword transducer if its output signature is unary. Locality of an MS tree-walking pushdown transducer is defined in the same way as for an ms-twt. By P-DTWT we denote the class of transductions computed by deterministic tree-walking pushdown transducers (i.e., by local deterministic MS tree-walking pushdown transducers), and by P-DTWTW the corresponding class in the tree-to-word case.

Theorem 8.12 For every MS tree-walking pushdown transducer an equivalent (local) tree-walking pushdown transducer can be constructed. Determinism is preserved.

Proof: Let M be a p-ms-twt with input signature F . As in Theorem 8.9, the problem is how to simulate a global test, defined by a formula in the lefthand side of a rule of M , by a walk that uses local tests only. Let ϕ ∈ MS(R F , {x 1 }) be a formula that defines a global test and let q be the quantifier-height of ϕ. As in the proof of Theorem 8.9, it suffices to prove that M can be changed into a p-ms-twt M that stepwise simulates M and, moreover, for input tree s ∈ T (F ) and current node u ∈ N s , additionally keeps track of p 1 := Th ↓ s (u 1 ), . . . , p k := Th ↓ s (u k ) (if u has k sons u 1 , . . . , u k ) and of P := Th ↑ s (u). We first show how M can compute the theories p 1 , . . . , p k (they will be recomputed each time M visits u). Recall again from Section 8.1.3 that there is a complete and deterministic finite semi-automaton A = F, Q, δ such that for every s ∈ T (F ) and u ∈ N s , run A ,s (u) = Th ↓ s (u). Thus, p i = run A ,s (u i ) for every i ∈ [k]. Recall from Section 8.1.2 that run A ,s (u) can be defined recursively. Thus, to compute p i , M implements this recursion on its pushdown in the obvious way: it executes a depth-first search of the subtree with root u i and computes run A ,s (u ) for every descendant u of u i , in a bottom-up fashion. To this end, it uses additional pushdown symbols of the form (b, q 1 • • • q n ) with b ∈ {0, 1} and q 1 , . . . , q n ∈ Q. The boolean b just indicates whether or not the corresponding node u is u i (this is because M needs to know when it has returned to u i ). The states q 1 , . . . , q n are the states of A in which it reaches the first n sons of u . Thus, after having computed p 1 , . . . , p i-1 (and having stored them in its state), M calls a subroutine that moves down to the i-th son of u in state ↓ and pushes the symbol (1, ε), where ε is the empty sequence of states of A . The subroutine then applies the following rules, for every f ∈ F with A mapping α : X → (B ∪ (X × [k])) * can be viewed as a set of assignments x := α(x) for x ∈ X , where α(x) is of the form w 0

If the above rule is used at a node u with sons u 1 , . . . , u k , then the pair x, i stands for the variable x of the i-th son (and x for the one of the father).

To define the runs of the mbott M we use the (complete and deterministic) infinite F -automaton

of all pairs q, β such that q ∈ Q and β is a valuation, i.e., a mapping : X → B * . Such a pair is called a configuration of M ; intuitively, β(x) is the current value of the variable x. If f [q 1 , . . . , q k ] → [q, α] is a transition rule in δ and β 1 , . . . , β k are valuations, then δ ∞ contains the transition rule f [ q 1 , β 1 , . . . , q k , β k ] → q, β where β is the valuation defined as follows: if

The set Acc ∞ of accepting states consists of all configurations q, β with q ∈ Acc. The runs of M are the runs of A M . The transduction computed by M , denoted τ M , is defined as

Note that L(A M ) is the domain of τ M ; obviously, it is a regular language (because the values of the variables do not influence the runs of A M ).

The mbott M is a one-way multi word transducer if F is unary. Then M computes the word transduction

It can be viewed as having a one-way input tape, on which it walks from right to left.

The mbott M is linear if every set α of assignments is linear, i.e., if each x, i occurs at most once in α(x 1 ) • • • α(x m ), where X = {x 1 , . . . , x m }. Intuitively, such a transducer is "single-use" in the sense that, for a run of M , the value of each variable in a configuration of that run is used at most once as a subword of the output word. To formally define the single-use property, we need some more notation.

Let s ∈ T (F ). For a node u ∈ N s we denote by run M,s (u) the state in which M reaches u: the first component of run A M ,s (u). By α u we denote the set of assignments that is used by M when reaching u: the second component of δ f (run M,s (u 1 ), . . . , run M,s (u k )), where u has label f and sons u 1 , . . . , u k . We now define a binary relation γ(u) on the set of variables X . Intuitively, (x, y) is in γ(u) if the current values of x and y both contain as a subword the value of a variable z at some proper descendant of u; we say that x and y are linked and that γ(u) is a linking relation. Formally, γ(u) is the set of all (x, y) such that α u (x) has an occurrence x , i and α u (y) has an occurrence y , i (with the same i ∈ [k]) and either x = y or (x , y ) ∈ γ(u i ). We now define an mbott to be single-use by forbidding it to use a variable (of a son) twice or to use two linked variables (of a son) in the righthand side of an assignment.

The mbott M is single-use if for every s ∈ T (F ), u ∈ N s and x ∈ X , (1) each y, i has at most one occurrence in α u (x), and (2) if y, i and z, i (with the same i ∈ [k] and y = z) both occur in α u (x), then (y, z) / ∈ γ(u i ).

will from now on say that the mbott has registers rather than variables. Then, a deterministic macro tree transducer is a tuple M = (F, H, Q, X , x out , δ, Acc), defined in the same way as the mbott, except that both H (the set of output symbols) and X (the set of registers) are functional signatures, and x out has arity 0. If the register x has rank n, then its values are terms with variables in T (H, {y 1 , . . . , y n }), where we use y 1 , y 2 , . . . (not in X ) as standard variables, also called parameters. Moreover, a set of assignments α (used in a transition rule) consists of assignments x := α(x) with α(x) ∈ T ((X × [k]) ∪ H, {y 1 , . . . , y n }) if x has arity n, where each x , i ∈ X × [k] has the same arity as x . The value β(x) of register x at a father node is obtained by applying to α(x) the second-order substitution that interprets each x , i as the derived function defined by the term with variables β i (x ) (the value of register x at the i-th son).

For readers familiar with the macro tree transducer we note that in the usual formulation of a macro tree transducer, X is called the set of states, x out the initial state, and Q is the set of states of a "look-ahead automaton" employed by the transducer (so it is actually a macro tree transducer with "regular lookahead", cf. [START_REF] Engelfriet | Macro tree transducers[END_REF]). A transition rule f [q 1 , . . . , q k ] → [q, α] in δ combines the transition rule f [q 1 , . . . , q k ] → q of the look-ahead automaton with the rules x := α(x) of the macro tree transducer for input symbol f . Note that if all registers have arity 0, we obtain the multi bottom-up tree transducer of [START_REF] Fülöp | A bottom-up characterization of deterministic top-down tree transducers with regular look-ahead[END_REF]. The main result of [START_REF] Fülöp | A bottom-up characterization of deterministic top-down tree transducers with regular look-ahead[END_REF] is that it has the same power as the deterministic top-down tree transducer with "regular look-ahead".

Let DMT denote the class of tree transductions computed by deterministic macro tree transducers (it is denoted DMT OI in [START_REF] Engelfriet | Macro tree transducers[END_REF]). The proof of Theorem 8.21 can be generalized to show that DTWT MS ⊆ DMT. In fact, the macro tree transducer has the same power as the tree-walking pushdown transducer, as shown for total functions in Theorem 5.16 of [START_REF] Engelfriet | Pushdown machines for the macro tree transducer[END_REF]. 13 For partial functions we now fill a gap in the litterature, for completeness sake. Proof: In Theorem 6.18 of [START_REF] Engelfriet | Macro tree transducers[END_REF] it is shown that every τ ∈ DMT can be written as τ = τ 1 • τ 2 , where τ 1 is the identity on some regular set R of trees, and τ 2 ∈ DMT is a total function and hence τ 2 ∈ P-DTWT by Theorem 5.16 of [START_REF] Engelfriet | Pushdown machines for the macro tree transducer[END_REF]. It should be clear that τ 1 •τ 2 is in P-DTWT: the p-twt just starts by checking that the input tree is in R (see the proof of Theorem 8.12). This proves that DMT ⊆ P-DTWT. The inclusion P-DTWT ⊆ DTWT ↓ • DTWT is shown in Theorem 8.15. Finally, the inclusion DTWT ↓ • DTWT ⊆ DMT follows from Theorem 35 of [START_REF] Engelfriet | A comparison of pebble tree transducers with macro tree transducers[END_REF] (which shows, for n = 0, that DTWT ⊆ DMT) and Theorem 7.6(3) of [START_REF] Engelfriet | Macro tree transducers[END_REF] (which shows that DTWT ↓ • DMT ⊆ DMT). Thus, by Theorem 8.17, DMSOT is the class of deterministic macro tree transductions of linear size increase, and, by Theorem 8.18, every monadic denote the class of monadic second-order relabellings of terms, cf. Definition 7.20. As usual, DMSOT-REL denotes the restriction to parameterless definition schemes. Proof: The inclusion from right to left follows from Theorem 8.6 and the fact that DMSOT is closed under composition. To prove the inclusion in the other direction, let M = (F, H, Q, q in , R) be a deterministic single-use MS treewalking transducer. By Theorem 8.7 we may assume that M is nonjumping. Let ϕ 1 , . . . , ϕ n ∈ MS(R F , {x 1 }) be the formulas that are used in the lefthand sides of the rules of M . Recall the notation from Definition 6.24(c). We will define a monadic second-order relabelling τ from T (F ) to T (F (n) ) such that τ (s) = s * γ s , where γ s is the assignment

. Then M can be changed into a (local) tree-walking transducer M that receives τ (s) as input and stepwise simulates M on input s: in the lefthand sides of its rules, it uses the boolean information in the label (f, (w 1 , . . . , w n )) of the current node (with w i ∈ {0, 1}) instead of the tests ϕ 1 , . . . , ϕ n .

To ensure that M is deterministic, we take τ from T (F ) to T (F ), where F is the subset of F (n) consisting of the symbols (f, (w 1 , . . . , w n )) such that for all i, j ∈ [n], if ϕ i and ϕ j are mutually exclusive on T (F ), then w i = 0 or w j = 0. The parameterless definition scheme of τ has type R F → R F and relation formulas θ lab (f,(w 1 ,...,wn)) equal to lab f (x 1 ) ∧ ( i∈[n],wi=1 ϕ i ) ∧ ( i∈[n],wi=0 ¬ϕ i ). Note the similarity with Definition 7.21. The tree-walking transducer M is obtained from M by changing, in the lefthand sides of its rules, each ϕ i into the disjunction of all formulas lab (f,(w1,...,wn)) (x 1 ) such that (f, (w 1 , . . . , w n )) ∈ F and w i = 1. Obviously, M is deterministic and single-use. Proof: The first equality is immediate from Theorems 8.6 and 8.25. The second equality then follows from Proposition 8.24 and the fact that the equality REL • DMSOT-REL = MSOT-REL is an easy special case of that same proposition. Now we can characterize the VR-equational sets of terms and words. The class of regular sets of terms is denoted REGT. For a class X of transductions, X(REGT) denotes {τ (L) | L ∈ REGT}, i.e., the images of the regular languages under the transductions from X.

Theorem 8.27 Let L be a set of terms. The language L is VR-equational if and only if it is in DTWT su (REGT).

Proof: Let L ⊆ T (H) be VR-equational, where H is a functional signature. By the Equationality Theorem (Theorem 7.36) and by Theorem 7.27(2), there is a

Cyclic ordering

We now consider in a similar way the notion of cyclic ordering. With a finite linear order D, ≤ such that |D| ≥ 3, we associate the ternary relation: andd 1 , . . . , d n are points on a circle such that, according to some orientation of the circle, d i+1 follows d i and d 1 follows d n , then C(x, y, z) expresses that, if one "walks" along the circle according to this orientation by starting at x, then one meets y before z. We denote by C(≤) the ternary relation associated with ≤ in this way. A relation of this form is a cyclic ordering. A cyclic ordering C satisfies the following properties, for all x, y, z in its domain D: Proof: Let C satisfy (C1)-(C5). We let a be any element of D and we define on D a binary relation ≤ in a similar way as in the case of betweenness:

x ≤ y if and only if x = y or x = a or C(a, x, y).

We claim that this relation is a linear order on D such that C = C(≤). It is reflexive. By (C1), (C2) and (C4), it is antisymmetric and transitive. Hence, it is a partial order. Condition (C5) implies that this partial order is linear. It remains to prove that C = C(≤).

We first prove that C(≤) ⊆ C. Let x, y, z be such that x < y < z. We have C(a, y, z) by the definition of ≤, and we want to prove C(x, y, z). If x = a, we are done. Otherwise, we have C(a, x, y) and C(a, y, z), hence by Properties (C2) and (C4) we have C(x, y, z), as was to be proved.

For the converse, we let x, y, z be such that C(x, y, z). Since ≤ is a linear order and x, y and z are pairwise distinct, we have one of the six possibilities x < y < z, x < z < y, y < z < x, etc. Three of them entail C(≤)(x, y, z). The three others would yield C(x, z, y), which contradicts Condition (C3) that C was assumed to satisfy. Hence we have C(≤)(x, y, z).

The next lemma will prove that relational structures are faithfully represented by their incidence graphs. It is thus natural to use monadic second-order sentences interpreted over incidence graphs to characterize classes of relational structures. A CMS formula over R Inc will be called a CMS 2 formula over R. A property of R-structures S is CMS 2 -expressible if it is equivalent to Inc(S) |= ϕ (or to Inc (S) |= ϕ) for some CMS sentence ϕ. A class of R-structures is CMS 2definable if the membership of an R-structure in this class is a CMS 2 -expressible property. All the terminology related with CMS 2 formulas will thus be applied to relational structures via their incidence graphs.

Lemma 9.11 Let R be a relational signature.

(1) A structure U in STR c (R Inc ) is isomorphic to Inc(S) for some concrete R-structure S if and only if the following conditions hold, where

check the connectivity condition. Let d in D S belong to the tuples t 1 , . . . , t p . We have

where each component of this union is connected. Since for each i there is a box f (u) that contains t i and d, we have

The other conditions are clearly satisfied.

By the first assertion of this proposition, the algorithms that construct treedecompositions of graphs (cf. Section 6.2.1) can be used to construct treedecompositions of relational structures. The next results exploit the particular structure of incidence graphs.

Lemma 9.15 Let R be a relational signature. The identity on Inc(STR(R)) (and on

Proof: Let k := ρ(R) and G := Inc(S) for S in STR(R). The edges of G are directed and labelled by in 1 , in 2 , . . . or in k , and two edges with the same tail have different labels. Hence, an MS 1,2 -transduction can specify an edge from x to y that is labelled by in j as the pair (x, j +1), and a vertex x as the pair (x, 1). Hence, G is defined from G (i.e., from Inc(S) by a convention made in Definition 9.10) by a (k + 1)-copying MS-transduction. The detailed construction is similar to that for the incidence graphs of forests done in Example 7.8. The proof is almost the same for Inc . This lemma and Proposition 9.14 yield the following corollary, which extends Corollary 7.49. Corollary 9.16 A subset C of STR(R) has bounded tree-width if and only if Inc(C) is included in the image of trees under an MS-transduction.

Proof: By Proposition 9.14(2), a subset C of STR(R) has bounded treewidth if and only if Inc(C) has bounded tree-width, hence, by Corollary 7.49, if and only if Inc(C) is included in τ (trees) for some MS 1,2 -transduction τ . By Lemma 9.15, the last equivalence is valid with τ assumed to be an MStransduction (cf. Section 7.3).

Proposition 9.17 For every relational signature R and integer k, the classes Inc(TWD(R, ≤ k)) and Inc(PWD(R, ≤ k)) are HR-equational.

Proof: The class of labelled graphs Inc(STR(R)) is characterized by an FO sentence α as we have seen in the proof of Lemma 9.11. There exists a (noncopying) FO-transduction τ such that Dom(τ ) = Inc(STR(R)) and τ (Inc(S)) = Adj (S) for every R-structure S. Its precondition is α and the other formulas are easy to write. By Proposition 9.14(1), the class τ -1 (TWD(≤ k)) = {Inc(S) | twd (Adj (S)) ≤ k} equals Inc(TWD(R, ≤ k)). By the Backwards Translation Theorem (Corollary 7.12) and since the class of graphs TWD(≤ k) is MSdefinable (because it is characterized by a finite set of excluded minors, cf. Corollary 2.60(2) and Proposition 5.11), it follows that

). Let u ∈ N t and x ∈ D S with x ≤ t u. For i ∈ [k], we say that x has label i at u in t if lab iU (x) holds for U := cval (t)/u (hence U is the substructure of S induced by the elements of its domain that are below u). We say that x is distinguished at u if there exist w ∈ N t and a, b, c ∈ [k] such that:

(i) u ≤ t w, (ii) w is an occurrence of add a,b,c,R , (iii) for each j ∈ {a, b, c} there exists y ∈ D cval(t)/w such that y has label j at w, and (iv) there exists i ∈ {a, b, c} such that x has label i at w. We observe that if x and x are two vertices of G such that x, x ≤ t u and x is distinguished at u, then x and x do not have the same labels at u, i.e., x has some label i at u that x has not at u or vice-versa. To see this, we let w and a, b, c satisfy conditions (i)-(iv) above, and assume that x and x do have the same labels at u. Then, they also have the same labels at w. By conditions (i)-(iv), R cval(t)/w (and hence R S ) contains either two triples (x, y, z) and (x , y, z), or two triples (y, x, z) and (y, x , z). This fact contradicts the fact that S = f (G ) for some graph G .

We let P be the path in t from the root to the leaf * . For every node w on P , we let g(w) be the set of vertices of G that are distinguished at w. We now check that (P, g) is a path-decomposition of G.

For every x ∈ V G , we let I(x) be the set of nodes w of t at which x is distinguished. It is an interval, i.e., a set of consecutive nodes, of the path in t from the root to the leaf x. For every (x, y, z) ∈ R S , there is in t an occurrence w of an operation add a,b,c,R that creates this triple, and so, x, y, z are distinguished at w. Hence the set I(x) ∩ I(y) is not empty and is an interval. Since for every x ∈ V G , we have (x, * , z) ∈ R S for some z, we have I(x) ∩ I( * ) = ∅ and so, x belongs to g(w) for some w on P .

If x → G y, then (x, y, z) belongs to R S for some z, hence I(x) ∩ I(y) = ∅. Since the three intervals I(x), I(y) and I( * ) have pairwise nonempty intersections, there is some w in I(x) ∩ I(y) ∩ I( * ) hence x, y ∈ g(w) and w is on P . The connectivity condition holds since g -1 (x) = I(x) ∩ I( * ) is an interval for every x in V G . Hence (P, g) is a path-decomposition of G. Since each box g(w) consists of vertices having different sets of labels from [k] at w, we have |g(w)| ≤ 2 k . Hence pwd (G) ≤ 2 k -1. This completes the proof of the claim.

For proving the proposition, we let K be the set of rooted trees, so that K ⊆ D, and L be the set f (K -→ ⊗ ♦) ⊆ STR(R). Since trees have unbounded path-width (cf. Section 2.4.1), it follows from the claim that L has unbounded relational width. We have twd

is a 2-copying FO-transduction. This completes the proof.

(3) For every k > 0, there exists a graph Q(k) in S d * with vertex set [q(k)] such that for every G ∈ S d k there exists a homomorphism : G → Q(k). Proof: [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF] This fact is proved in [*Fra], Theorem 6.13. We will prove a generalization of it to hypergraphs in Proposition 9.58.

(2) Let G belong to S d k . By induction on |V G |, we will construct a proper vertex (2k + 1)-coloring defined as a mapping γ : V G → [2k + 1]. Since the sum of the indegrees of all vertices is equal to that of their outdegrees (and to |E G |), some vertex v has outdegree at most k, hence degree at most 2k. Since the graph G -v also belongs to S d k it has by induction a proper vertex (2k + 1)coloring defined as a mapping γ . Since the degree of v is at most 2k, γ can be extended into a proper vertex (2k + 1)-coloring of G.

(3) This fact is proved in [NešSV], Theorem 10. For completeness we reproduce its proof. Let us fix k > 0 and define p := 2k(k + 1) + 1. We construct as follows a directed graph Q(k) with q(k) = 2 p -1 vertices. Its vertices are the tuples (i; a 1 , . . . , a i-1 ) for i ∈ [p] and a s ∈ {0, 1} for all s ∈ [i -1]. If a = (i; a 1 , . . . , a i-1 ) and b = (j; b 1 , . . . , b j-1 ) with j < i, there is an edge from a to b if a j = 1 and one from b to a if a j = 0. (There is no edge between (i; a 1 , . . . , a i-1 ) and (i; b 1 , . . . , b i-1 )).

Let G belong to S d k . We first show that it has a proper vertex p-coloring γ such that, if x → G y → G z, then γ(x) = γ(z): consider the graph G consisting of G augmented with the edges from x to z for all triples (x, y, z) as above. This graph has indegree at most k(k + 1) hence, by ( 2), it has a proper vertex p-coloring γ which is the desired one for G.

We now define a homomorphism h from G to Q(k). If x ∈ V G we define h(x) := (i; a 1 , . . . , a i-1 ) where i := γ(x) and, for 1 ≤ j < i, a j := 0 if and only if there is an edge y → G x for some vertex y such that γ(y) = j.

We now check that h is indeed a homomorphism. Let x and y be adjacent vertices of G such that j = γ(y) < i = γ(x). Let h(x) = a = (i; a 1 , . . . , a i-1 ) and h(y) = b = (j; b 1 , . . . , b j-1 ). If y → G x, then a j = 0, hence we have b → Q(k) a. If x → G y, then there is no vertex z such that z → G x and γ(z) = j, because γ is a proper coloring of G . Hence, a j = 1 and we have a → Q(k) b.

The vertices of Q(k) can be encoded by the integers in [q(k)], which gives the stated result.

In the next definition and until the end of this section, we denote by X n any n-tuple of distinct set variables (X 1 , . . . , X n ).

Definition 9.41 (Orientations and orderings defined by MS formulas) Let C be a set of simple, loop-free undirected graphs. A pair of MS formulas (χ(X n ), θ(X n , x 1 , x 2 )) defines orientations of every graph in C (or orients the graphs of C) if, for every graph G in C,

where θ is the formula with free variables in X n defined as: ∀x, y[edg(x, y) ⇔ (θ(x, y) ∨ θ(y, x))] ∧ ∀x, y[θ(x, y) ⇒ ¬θ(y, x)].

Hence we can construct a (k + 1)-copying MS-transduction τ 2 that associates with (H, ≤) given as V G , edg H , ≤ the structure T = D T , in T such that:

It is convenient here to define D T as a subset of

, by an isomorphism that maps (x, 0) to x (and that maps (x, i) to the edge between x and p i (x) for i ≥ 1). It is straightforward to write a (k + 1)-copying domain-extending definition scheme D such that D( V G , edg H , ≤ ) = T . Hence, Inc is a domain-extending MS-transduction on the class US k .

The case of binary relational structures.

Let S = D S , (R S ) R∈R ∈ US k (R) and let G := Adj (S) ∈ S u be its adjacency graph (with V G = D S , cf. Proposition 9.14). Since |E G | ≤ |T S |, the graph G is in US k . Thus, by Propositions 9.42(1) and 9.43 there exists a domain-preserving MS-transduction τ 1 that transforms S into one or more structures D S , (R S ) R∈R , edg H , ≤ , where the structure V H , edg H , ≤ satisfies the same conditions as in the above special case, with V H = V G = D S . 12 For each x ∈ D S , we define the enumeration p 1 (x), . . . , p l (x) of Adj - H (x) as above. Our goal is now to define a parameterless domain-extending MS-transduction τ 2 that transforms each such structure D S , (R S ) R∈R , edg H , ≤ into Inc(S). Clearly, it suffices to construct a structure U isomorphic to Inc (S) (the simplified version of Inc(S), cf. Definition 9.10) by a domain-extending MS-transduction: by composing that transduction with the domain-preserving FO-transduction that transforms Inc (S) into Inc(S) we get the result.

We define U with domain included in D S × ({0} ∪ ([2k + 1] × R 2 )).

(1) Every element x of D S corresponds to (x, 0) in D U .

(2) If (x, x) ∈ R S , for R ∈ R 2 , then the triple (R, x, x) in T S corresponds to (x, (1, R)) in D U .

We now consider (x, y) ∈ R S with x = y, for R ∈ R 2 .

(3) If x = p i (y), then the triple (R, x, y) in T S corresponds to (y, (1 + i, R)) in D U ;

(4) If y = p i (x), then (R, x, y) corresponds to (x, (1

In cases (2) and (4), we define R U ((x, a)) to hold (with a equal to (1, R) or (1+k+i, R)); in case (3), we define R U ((y, a)) to hold (with a equal to (1+i, R)).

12 To be precise, τ 1 := Id R +Adj •τ 1 where Id R is the identity on STR c (R) and τ 1 is defined above (and for + see Definition 9.35). Note that, without loss of generality, we assume that edg / ∈ R.

Proof: We first construct an MS 2,2 -transduction α : M u → M d such that α ⊆ und -1 and M u ⊆ Dom(α). It will define one or more orientations of each undirected graph G. To be precise, it will define all orientations G(F ) where F is a normal spanning forest in G.

We let D be the domain-preserving definition scheme χ, True, θ in1 , θ in2 with two parameters such that:

(1)

normal spanning forest in G where F 0 is the subgraph of G with edge set X and vertex set V G ;

(2) for every X, U satisfying ( 1) and every e ∈ E G with two end vertices x and y, if y < F x then (3) for every X, U satisfying (1), if Inc(G) |= θ ini (X, U, w, z) for i = 1 or 2, then w is an edge of G (and z is an end vertex of w).

These conditions can easily be expressed in monadic second-order logic; for Condition (1) see Example 5.18.

Since every graph has a normal spanning forest (such a forest can be constructed by a depth-first traversal of each connected component), the transduction α := D defines one or more orientations for all graphs in M u . In the orientations constructed by α, any two parallel edges are oriented in the same direction, but even for simple graphs, α does not produce all orientations. An additional transduction can reverse the orientations of an arbitrary set of edges, hence yield all orientations.

There exists a domain-preserving MS 2,2 -transduction β : M d → M d that is equal to und • und -1 , i.e., that associates with every loop-free directed graph G the set of all orientations of und (G). This transduction uses a parameter intended to take for values any set of edges: the edges whose direction is to be reversed. Hence α • β is the desired transduction. It uses three parameters.

The second assertion is an application of the Restriction Theorem (Theorem 7.16) since the class A d is MS 2 -definable with respect to M d . Remark 9.47 This proposition yields the particular case of Proposition 9.43 where k = 2:

There is a pair (χ, θ) of MS formulas that defines, for every G ∈ S d 2 (the set of orientations of indegree at most 2 of the simple undirected graphs), one or more partial orders on its vertex set that are linear on each set Adj - G (x). We sketch the proof. Consider G ∈ S d 2 and let H be the undirected graph having the same vertices as G and having an edge e x between u and v = u for each x such that u → G x and v → G x. The graph Inc(H) is easily constructed from Note that the binary relation son F can be determined (in a unique way) from the sets N F and roots F and the mapping vert H . 17 We will do this by a monadic second-order formula in the proof of Proposition 9.50.

(c) Let F be an H-forest. We define V (F ) as the set of vertices of the hyperedges of H that belong to N F . For e ∈ N F , we let

if e is a root of F, vert H (e) -vert H (e ) if e is the father of e.

Hence {V (F, e) | e ∈ N F } is a partition of V (F ). We let F be the quasi-order on V (F ) defined as follows:

x F y if and only if x ∈ V (F, e) and y ∈ V (F, e ) for some e, e such that e ≤ F e .

We write x ≺ F y if x F y and we do not have y F x; we let x ≡ F y if x F y F x, equivalently, if x and y belong to V (F, e) for some e. Proof: We adapt the classical depth-first traversal algorithm for graphs. Let F be a rooted forest. A linear order ≤ on its set of nodes N F is depth-first if, for all e, e , f in N F : (i) if e ≤ F e, then e ≤ e , (ii) if e and f are incomparable with respect to ≤ F , e < f and e ≤ F e, then e < f .

The maximal branch of F is the path from a root to the node that is maximal with respect to ≤. By (i), that node is a leaf of F . We will construct a finite increasing sequence of H-forests

(2) N F1 = {e 1 } and N Fi+1 = N Fi ∪ {e i+1 } for some sequence e 1 , e 2 , . . . , e i , . . . of pairwise distinct hyperedges;

(3) the linear order (e 1 , . . . , e i ) is depth-first in F i . disjoint copy of Y, µ (Z) and ϕ (Z, x 1 , x 2 , x 3 ) be obtained from µ and ϕ by the corresponding substitution of variables and finally, we let µ 2 and ϕ 2 be the backwards translations of µ and ϕ relative to τ 2 ; they define an orientation of H 2 . We will use the tuple of parameters X n := U • Y • Z and the precondition µ defined as χ(U) ∧ µ 1 (Y) ∧ µ 2 (Z). The following formula ϕ expresses the above definition of ≤ e in terms of ≤ 1,e and ≤ 2,e . We define it as:

so that we have the desired pair (µ, ϕ).

(2) For each m, there is an MS-transduction β m that transforms Inc(H) into the incidence graphs representing all the orientations of H. Its construction generalizes the construction of the MS 2,2 -transduction β that defines und •und -1 (in the proof of Proposition 9.46). Its definition uses m!-1 parameters to specify, for each e ∈ E H , if and how its linear order ≤ e on vert H (e) must be permuted into another linear order.

The construction of all acyclic orientations follows then by the Restriction Theorem (Theorem 7.16), because the property of an orientation to be acyclic is MS-expressible (due to the fact that the acyclicity of a directed graph is MSexpressible). We omit the routine details.

Proof of Proposition 9.43:

We will denote by ω m the transduction that constructs all acyclic orientations of the hypergraphs of maximal rank at most m, see Proposition 9.54(2). Note that every hypergraph has at least one acyclic orientation: take any linear order of all its vertices.

Let G be a directed graph in S d k , i.e., such that each set Adj - G (x) defined as {y | y → G x} has at most k elements. We let H be the hypergraph of maximal rank at most k such that: The MS-transduction γ • ω k transforms such a graph G into Inc(H) where H is an acyclic orientation of H. It uses a (large!) tuple of parameters, say X ; let χ(X ) be its precondition.

We let ν(x 1 , x 2 ) be the MS formula that defines, in every structure Inc(H) representing an oriented hypergraph, the binary relation H on V H ; this relation is a partial order if and only if H is acyclic.

We let θ(X , x 1 , x 2 ) be the backwards translation of ν(x 1 , x 2 ) relative to γ•ω k , cf. Section 7.1.4. The pair (χ, θ) satisfies the required conditions: for every Xassignment in G ∈ S d k that satisfies χ, the formula θ defines in G a partial order

In Overview of the proof of Theorem 9.38. First, we reduce the general case to that of simple m-hypergraphs, i.e., such that all hyperedges have the same rank m and no two hyperedges have the same sets of vertices. The proof for these hypergraphs will be by induction on m. Since a simple 2-hypergraph is a simple loop-free undirected graph, the case of m = 2 is stated in Theorem 9.44 (cf. the first part of its proof).

For the induction step of the proof, we consider a uniformly k-sparse simple m-hypergraph H. In each hyperedge we select a vertex called its head. We obtain thus a semi-

The transductions ρ 2 and ρ 3 just eliminate components of their input structures.

There exists a noncopying MS-transduction µ 3 that transforms the structure Hence Inc(H) is definable from -→ H by the domain-extending MS-transduction µ defined as τ • µ 2 • µ 3 , so, going back to the elementary transductions used in this proof and in that of Claim 9.61.2, we have:

The validity of the global construction follows from the observations made along the constructions of the different transductions in the above expression. that x = π i (e).

By an argument similar to the proof of Lemma 9.60, τ m := µ 1 •µ 2 is a domainpreserving MS-transduction that transforms S into a structure isomorphic to Inc(S), and hence the mapping Inc is a domain-preserving MS-transduction on the class US k,m ({R}).

This completes the proof of the Sparseness Theorem, one of the main results of this book.

Consequences

The Sparseness Theorem (Theorem 9.38) has several consequences. We first state those concerning graphs; they follow from Theorem 9.44 proved in Section 9.4.1. (2) D is C r MS-definable with respect to C if and only if it is C r MS 2 -definable with respect to C.

(3) D has bounded clique-width if and only if it has bounded tree-width.

(4) D is VR-equational if and only if it is HR-equational.

(5) D has a decidable C r MS-satisfiability problem if and only if it has a decidable C r MS 2 -satisfiability problem, and decidability implies that D has bounded tree-width.

Proof: (1) follows from Theorem 7.14 (about the composition of CMS-transductions); see the discussion in Section 7.3 (before Example 7.44).

(2) follows from Corollary 7.12 (of the Backwards Translation Theorem). It was already stated in Theorem 5.22 (for r = 0). The only-if direction was stated in Theorem 1.44. The if-direction holds in general and is stated in Proposition 5.20(3).

(3) follows from Theorem 7.47(2,3). The if-direction holds in general and is stated in Proposition 2.114 [START_REF]s8.6 one-way multi word transducer, s8.6 tree-walking transducer[END_REF].

(4) follows from (1) and from the Equationality Theorems (Theorems 7.36 and 7.51), cf. Corollary 7.52. Since the graphs in D do not have ports or sources, these theorems say that D is VR-equational (HR-equational) if and only if D (respectively, D ) is the image of trees under an MS-transduction. The ifdirection holds in general and is stated in Theorem 4.49. A result stronger than the only-if direction was stated in Theorem 4.51: it holds without "uniformly".

Index of notation

Sets and sequences

We denote by P(A) the set of subsets of a set A (its powerset), and by P f (A) its set of finite subsets. The difference of two sets A and B is the set A -B := {a ∈ A | a / ∈ B}. The empty set is ∅. We denote by Seq(A) the set of finite sequences of elements of a set A, and by s[i] the i-th element of s ∈ Seq(A). The empty sequence is (). If A is an alphabet, we denote Seq(A) also by A * . Its elements are then called words, which are sequences of letters (or symbols). The empty word is also denoted by ε.

We denote by |A| the cardinality of a set A, and also by |s| the length of a sequence s (in particular, of a word). The cardinality of a set A is also denoted by Card (A) in certain cases, for better readability of formulas. We denote by |s| a the number of occurrences of a ∈ A in a sequence s ∈ Seq(A). If p, q ∈ N , q ≥ 2, we let mod q (p) be the unique integer r in [0, q -1] such that p ≡ r (mod q). If n ∈ N , then exp(n) denotes 2 n . All logarithms are in base 2. The function exp : N 2 → N is defined by exp(0, n) = n and exp(d + 1, n) = 2 exp(d,n) ; thus, exp(1, n) = exp(n). , s4.1.5, d4.22 graph, s1.10, s2.7, s4.1.5, s4.6 regular, d3.17 uniform, quasi-uniform, d3.17 grid, e2.56(3), p2.106, p4.36, t5.6, s5.2.3, p7.40, p7.60 height of a forest, d2.13 of a term, d2.3 homogenous, d2.123, d4.12 homomorphism

Integers

Binary relations and functions