Hubert Comon

Max Dauchet

Rémi Gilleron

Florent Jacquemard

Denis Lugiez

Christof Löding

Sophie Tison

Marc Tommasi

Tree Automata Techniques and Applications

Clause 11 subsumes 10, which is deleted.

From 9 + 7:

12. P 1 (y) ← P 1 (x), P 2 (y) From 12 +1: 13. P 1 (y) ← P 2 (y), P 5 (x), P 2 (z) From 13 + 8: 14. P 1 (y) ← P 2 (y), P 2 (x 1 ), P 2 (x 2 ), P 2 (z) Clause 14. can be simplified and, by superposition with 2. we get From 14 + 2: 15. P 1 (y) ← P 2 (y) At this stage, from 11. and 15. we have P 1 (x) ↔ P 2 (x), hence, for simplicity, we will only consider P 1 , replacing every occurrence of P 2 with P 1 .

From 1 +5: 16. P 4 (f (x, y)) ← P 3 (f (x, y)), P 5 (x), P 1 (y) From 1 + 9:

17. P 4 (f (x, y)) ← P 1 (x), P 1 (y), P 5 (x) From 2 +5: 18. P 4 (a) ← P 3 (a) From 3 +5:

19. P 4 (f (a, x)) ← P 3 (f (a, x)), P 1 (x) From 3+ 9: 20. P 4 (f (a, x)) ← P 1 (x), P 1 (a) From 2 + 20: 21. P 4 (f (a, x)) ← P 1 (x) Clause 21. subsumes both 20 and 19. These two clauses are deleted.

From 5 + 6:

22. P 1 (x) ← P 3 (f (x, y)), P 1 (f (x, y)) From 5 +7:

23. P 1 (y) ← P 3 (f (x, y)), P 1 (f (x, y)) From 16 + 6: 24. P 1 (x) ← P 3 (f (x, y)), P 5 (x), P 1 (y) From 23 +1: 25. P 1 (y) ← P 3 (f (x, y)), P 5 (x), P 1 (y) Now every new inference yields a redundant clause and the saturation terminates, yielding the automaton:

Introduction

During the past few years, several of us have been asked many times about references on finite tree automata. On one hand, this is the witness of the liveness of this field. On the other hand, it was difficult to answer. Besides several excellent survey chapters on more specific topics, there is only one monograph devoted to tree automata by Gécseg and Steinby. Unfortunately, it is now impossible to find a copy of it and a lot of work has been done on tree automata since the publication of this book. Actually using tree automata has proved to be a powerful approach to simplify and extend previously known results, and also to find new results. For instance recent works use tree automata for application in abstract interpretation using set constraints, rewriting, automated theorem proving and program verification, databases and XML schema languages. Tree automata have been designed a long time ago in the context of circuit verification. Many famous researchers contributed to this school which was headed by A. Church in the late 50's and the early 60's: B. Trakhtenbrot, J.R. Büchi, M.O. Rabin, Doner, Thatcher, etc. Many new ideas came out of this program. For instance the connections between automata and logic. Tree automata also appeared first in this framework, following the work of Doner, Thatcher and Wright. In the 70's many new results were established concerning tree automata, which lose a bit their connections with the applications and were studied for their own. In particular, a problem was the very high complexity of decision procedures for the monadic second order logic. Applications of tree automata to program verification revived in the 80's, after the relative failure of automated deduction in this field. It is possible to verify temporal logic formulas (which are particular Monadic Second Order Formulas) on simpler (small) programs. Automata, and in particular tree automata, also appeared as an approximation of programs on which fully automated tools can be used. New results were obtained connecting properties of programs or type systems or rewrite systems with automata.

Our goal is to fill in the existing gap and to provide a textbook which presents the basics of tree automata and several variants of tree automata which have been devised for applications in the aforementioned domains. We shall discuss only finite tree automata, and the reader interested in infinite trees should consult any recent survey on automata on infinite objects and their applications (See the bibliography). The second main restriction that we have is to focus on the operational aspects of tree automata. This book should appeal the reader who wants to have a simple presentation of the basics of tree automata, and to see how some variations on the idea of tree automata have provided a nice tool for solving difficult problems. Therefore, specialists of the domain probably know almost all the material embedded. However, we think that this book can be helpful for many researchers who need some knowledge on tree automata. This is typically the case of a PhD student who may find new ideas and guess connections with his (her) own work.

Again, we recall that there is no presentation nor discussion of tree automata for infinite trees. This domain is also in full development mainly due to applications in program verification and several surveys on this topic do exist. We have tried to present a tool and the algorithms devised for this tool. Therefore, most of the proofs that we give are constructive and we have tried to give as many complexity results as possible. We don't claim to present an exhaustive description of all possible finite tree automata already presented in the literature and we did some choices in the existing menagerie of tree automata. Although some works are not described thoroughly (but they are usually described in exercises), we think that the content of this book gives a good flavor of what can be done with the simple ideas supporting tree automata.

This book is an open work and we want it to be as interactive as possible. Readers and specialists are invited to provide suggestions and improvements. Submissions of contributions to new chapters and improvements of existing ones are welcome.

Among some of our choices, let us mention that we have not defined any precise language for describing algorithms which are given in some pseudo algorithmic language. Also, there is no citation in the text, but each chapter ends with a section devoted to bibliographical notes where credits are made to the relevant authors. Exercises are also presented at the end of each chapter.

Tree Automata Techniques and Applications is composed of eight main chapters (numbered 1-8). The first one presents tree automata and defines recognizable tree languages. The reader will find the classical algorithms and the classical closure properties of the class of recognizable tree languages. Complexity results are given when they are available. The second chapter gives an alternative presentation of recognizable tree languages which may be more relevant in some situations. This includes regular tree grammars, regular tree expressions and regular equations. The description of properties relating regular tree languages and context-free word languages form the last part of this chapter. In Chapter 3, we show the deep connections between logic and automata. In particular, we prove in full details the correspondence between finite tree automata and the weak monadic second order logic with k successors. We also sketch several applications in various domains.

Chapter 4 presents a basic variation of automata, more precisely automata with equality constraints. An equality constraint restricts the application of rules to trees where some subtrees are equal (with respect to some equality relation). Therefore we can discriminate more easily between trees that we want to accept and trees that we must reject. Several kinds of constraints are described, both originating from the problem of non-linearity in trees (the same variable may occur at different positions).

In Chapter 5 we consider automata which recognize sets of sets of terms. Such automata appeared in the context of set constraints which themselves are used in program analysis. The idea is to consider, for each variable or each predicate symbol occurring in a program, the set of its possible values. The program gives constraints that these sets must satisfy. Solving the constraints gives an upper approximation of the values that a given variable can take. Such an approximation can be used to detect errors at compile time: it acts exactly as a typing system which would be inferred from the program. Tree set automata (as we call them) recognize the sets of solutions of such constraints (hence sets of sets of trees). In this chapter we study the properties of tree set automata and their relationship with program analysis.

Originally, automata were invented as an intermediate between function description and their implementation by a circuit. The main related problem in the sixties was the synthesis problem: which arithmetic recursive functions can be achieved by a circuit? So far, we only considered tree automata which accepts sets of trees or sets of tuples of trees (Chapter 3) or sets of sets of trees (Chapter 5). However, tree automata can also be used as a computational device. This is the subject of Chapter 6 where we study tree transducers.

In Chapter 7 we present basic properties of alternating automata. As an application we consider set constraints that have already been introduced in Chapter 5.

In Chapter 8 we drop the restriction for ranked trees that the label of a node determines the number of successors of this node, so we consider the model of unranked ordered trees. This model is used for representing the structure of XML documents. We discuss the basic model of hedge automaton, study its algorithmic and closure properties, and then present some formalisms used in practice to define classes of XML documents.

Preliminaries Terms

We denote by N the set of positive integers. We denote the set of finite strings over N by N * . The empty string is denoted by ε.

A ranked alphabet is a couple (F, Arity) where F is a finite set and Arity is a mapping from F into N . The arity of a symbol f ∈ F is Arity(f ). The set of symbols of arity p is denoted by F p . Elements of arity 0, 1, . . . p are respectively called constants, unary, . . . , p-ary symbols. We assume that F contains at least one constant. In the examples, we use parenthesis and commas for a short declaration of symbols with arity. For instance, f (, ) is a short declaration for a binary symbol f . Let X be a set of constants called variables. We assume that the sets X and F 0 are disjoint. The set T (F, X ) of terms over the ranked alphabet F and the set of variables X is the smallest set defined by: -F 0 ⊆ T (F, X ) and -X ⊆ T (F, X ) and -if p ≥ 1, f ∈ F p and t 1 , . . . , t p ∈ T (F, X ), then f (t 1 , . . . , t p ) ∈ T (F, X ). If X = ∅ then T (F, X ) is also written T (F). Terms in T (F) are called ground terms. A term t in T (F, X ) is linear if each variable occurs at most once in t.

Example 0.0.1. Let F = {cons(, ), nil, a} and X = {x, y}. Here cons is a binary symbol, nil and a are constants. The term cons(x, y) is linear; the term cons(x, cons(x, nil)) is non linear; the term cons(a, cons(a, nil)) is a ground term. Terms can be represented in a graphical way. For instance, the term cons(a, cons(a, nil)) is represented by: a a nil cons cons

Terms and Trees

A finite ordered tree t over a set of labels E is a mapping from a prefix-closed set Pos(t) ⊆ N * into E. Thus, a term t ∈ T (F, X ) may be viewed as a finite ordered ranked tree, the leaves of which are labeled with variables or constant symbols and the internal nodes are labeled with symbols of positive arity, with out-degree equal to the arity of the label, i.e. a term t ∈ T (F, X ) can also be defined as a partial function t : N * → F ∪ X with domain Pos(t) satisfying the following properties:

(i) Pos(t) is nonempty and prefix-closed.

(ii) ∀p ∈ Pos(t), if t(p) ∈ F n , n ≥ 1, then {j | pj ∈ Pos(t)} = {1, . . . , n}.

(iii) ∀p ∈ Pos(t), if t(p) ∈ X ∪ F 0 , then {j | pj ∈ Pos(t)} = ∅.

We confuse terms and trees, that is by "tree" we always mean a finite ordered ranked tree satisfying (i), (ii) and (iii). In the later chapters we also consider unranked trees but we then we give the corresponding definitions in the respective chapter.

The reader should note that finite ordered trees with bounded rank k -i.e. there is a bound k on the out-degrees of internal nodes -can be encoded in finite ordered ranked trees: a label e ∈ E is associated with k symbols (e, 1) of arity 1, . . . , (e, k) of arity k.

Each element in Pos(t) is called a position. A frontier position is a position p such that ∀j ∈ N , pj ∈ Pos(t). The set of frontier positions is denoted by FPos(t). Each position p in t such that t(p) ∈ X is called a variable position. The set of variable positions of p is denoted by VPos(t). We denote by Head (t) the root symbol of t which is defined by Head (t) = t(ε).

SubTerms

A subterm t| p of a term t ∈ T (F, X ) at position p is defined by the following:

-Pos(t| p ) = {j | pj ∈ Pos(t)}, -∀q ∈ Pos(t| p ), t| p (q) = t(pq).

We denote by t[u] p the term obtained by replacing in t the subterm t| p by u.

We denote by ¤ the subterm ordering, i.e. we write t ¤ t ′ if t ′ is a subterm of t. We denote t £ t ′ if t ¤ t ′ and t = t ′ .

A set of terms F is said to be closed if it is closed under the subterm ordering, i.e. ∀t ∈ F (t ¤ t ′ ⇒ t ′ ∈ F ).

Functions on Terms

The size of a term t, denoted by t and the height of t, denoted by Height(t) are inductively defined by:

-Height(t) = 0, t = 0 if t ∈ X , -Height(t) = 1, t = 1 if t ∈ F 0 , -Height(t) = 1+max({Height(t i ) | i ∈ {1, . . . , n}}), t = 1+ i∈{1,...,n} t i if Head (t) ∈ F n .

Example 0.0.2. Let F = {f (, , ), g(, ), h(), a, b} and X = {x, y}. Consider the terms The root symbol of t is f ; the set of frontier positions of t is {11, 12, 2, 31}; the set of variable positions of t ′ is {11, 12, 31, 32}; t| 3 = h(b); t[a] 3 = f (g(a, b), a, a); Height(t) = 3; Height(t ′ ) = 2; t = 7; t ′ = 4.

Substitutions

A substitution (respectively a ground substitution) σ is a mapping from X into T (F, X ) (respectively into T (F)) where there are only finitely many variables not mapped to themselves. The domain of a substitution σ is the subset of variables x ∈ X such that σ(x) = x. The substitution {x 1 ←t 1 , . . . , x n ←t n } is the identity on X \ {x 1 , . . . , x n } and maps x i ∈ X on t i ∈ T (F, X ), for every index 1 ≤ i ≤ n. Substitutions can be extended to T (F, X ) in such a way that:

∀f ∈ F n , ∀t 1 , . . . , t n ∈ T (F, X ) σ(f (t 1 , . . . , t n )) = f (σ(t 1 ), . . . , σ(t n )).

We confuse a substitution and its extension to T (F, X ). Substitutions will often be used in postfix notation: tσ is the result of applying σ to the term t.

Example 0.0.3. Let F = {f (, , ), g(, ), a, b} and X = {x 1 , x 2 }. Let us consider the term t = f (x 1 , x 1 , x 2 ). Let us consider the ground substitution σ = {x 1 ← a, x 2 ←g(b, b)} and the substitution σ ′ = {x 1 ←x 2 , x 2 ←b}. Then

tσ = t{x 1 ←a, x 2 ←g(b, b)} = a a b b g f ; tσ ′ = t{x 1 ←x 2 , x 2 ←b} = x 2 x 2 b f

Contexts

Let X n be a set of n variables. A linear term C ∈ T (F, X n ) is called a context and the expression C[t 1 , . . . , t n ] for t 1 , . . . , t n ∈ T (F) denotes the term in T (F) obtained from C by replacing variable x i by t i for each 1 ≤ i ≤ n, that is C[t 1 , . . . , t n ] = C{x 1 ← t 1 , . . . , x n ← t n }. We denote by C n (F) the set of contexts over (x 1 , . . . , x n ). We denote by C(F) the set of contexts containing a single variable. A context is trivial if it is reduced to a variable. Given a context C ∈ C(F), we denote by C 0 the trivial context, C 1 is equal to C and, for n > 1,

C n = C n-1 [C] is a context in C(F).
Chapter 1

Recognizable Tree Languages and Finite Tree Automata

In this chapter, we present basic results on finite tree automata in the style of the undergraduate textbook on finite automata by Hopcroft and Ullman [START_REF] Hopcroft | Introduction to Automata Theory, Languages, and Computation[END_REF]. Finite tree automata deal with finite ordered ranked trees or finite ordered trees with bounded rank. We discuss finite automata for unordered and/or unranked finite trees in subsequent chapters. We assume that the reader is familiar with finite automata. Words over a finite alphabet can be viewed as unary terms. For instance a word abb over A = {a, b} can be viewed as a unary term t = a(b(b(♯))) over the ranked alphabet F = {a(), b(), ♯} where ♯ is a new constant symbol. The theory of tree automata arises as a straightforward extension of the theory of word automata when words are viewed as unary terms.

In Section 1.1, we define bottom-up finite tree automata where "bottom-up" has the following sense: assuming a graphical representation of trees or ground terms with the root symbol at the top, an automaton starts its computation at the leaves and moves upward. Recognizable tree languages are the languages recognized by some finite tree automata. We consider the deterministic case and the nondeterministic case and prove the equivalence. In Section 1.2, we prove a pumping lemma for recognizable tree languages. This lemma is useful for proving that some tree languages are not recognizable. In Section 1.3, we prove the basic closure properties for set operations. In Section 1.4, we define tree homomorphisms and study the closure properties under these tree transformations. In this Section the first difference between the word case and the tree case appears. Indeed, recognizable word languages are closed under homomorphisms but recognizable tree languages are closed only under a subclass of tree homomorphisms: linear homomorphisms, where duplication of trees is forbidden. We will see all along this textbook that non linearity is one of the main difficulties for the tree case. In Section 1.5, we prove a Myhill-Nerode Theorem for tree languages and the existence of a unique minimal automaton. In Section 1.6, we define top-down tree automata. A second difference appears with the word case because it is proved that deterministic top-down tree automata are strictly less powerful than nondeterministic ones. The last section of the present chapter gives a list of complexity results.

Finite Tree Automata Nondeterministic Finite Tree Automata

A finite Tree Automaton (NFTA) over F is a tuple A = (Q, F, Q f , ∆) where Q is a set of (unary) states, Q f ⊆ Q is a set of final states, and ∆ is a set of transition rules of the following type: f (q 1 (x 1 ), . . . , q n (x n )) → q(f (x 1 , . . . , x n )), where n ≥ 0, f ∈ F n , q, q 1 , . . . , q n ∈ Q, x 1 , . . . , x n ∈ X .

Tree automata over F run on ground terms over F. An automaton starts at the leaves and moves upward, associating along a run a state with each subterm inductively. Let us note that there is no initial state in a NFTA, but, when n = 0, i.e. when the symbol is a constant symbol a, a transition rule is of the form a → q(a). Therefore, the transition rules for the constant symbols can be considered as the "initial rules". If the direct subterms u 1 , . . . , u n of t = f (u 1 , . . . , u n ) are labeled with states q 1 , . . . , q n , then the term t will be labeled by some state q with f (q 1 (x 1 ), . . . , q n (x n )) → q(f (x 1 , . . . , x n )) ∈ ∆. We now formally define the move relation defined by a NFTA.

Let A = (Q, F, Q f , ∆) be a NFTA over F. The move relation → A is defined by: let t, t

′ ∈ T (F ∪ Q), t → A t ′ ⇔         
∃C ∈ C(F ∪ Q), ∃u 1 , . . . , u n ∈ T (F), ∃f (q 1 (x 1 ), . . . , q n (x n )) → q(f (x 1 , . . . , x n )) ∈ ∆, t = C[f (q 1 (u 1 ), . . . , q n (u n ))], t ′ = C[q(f (u 1 , . . . , u n ))]. * -→ A is the reflexive and transitive closure of → A .

Example 1.1.1. Let F = {f (, ), g(), a}. Consider the automaton A = (Q, F, Q f , ∆) defined by: Q = {q a , q g , q f }, Q f = {q f }, and ∆ is the following set of transition rules:

{

a → q a (a) g(q a (x)) → q g (g(x)) g(q g (x)) → q g (g(x))

f (q g (x), q g (y)) → q f (f (x, y)) }

We give two examples of reductions with the move relation →

A a a f → A a q a a f → A a q a a q a f a g a g f * -→ A a q a g a q a g f * -→ A a g q g a g q g f → A a g a g f q f
A ground term t in T (F) is accepted by a finite tree automaton

A = (Q, F, Q f , ∆) if t * -→ A q(t)
for some state q in Q f . The reader should note that our definition corresponds to the notion of nondeterministic finite tree automaton because our finite tree automaton model allows zero, one or more transition rules with the same lefthand side. Therefore there are possibly more than one reduction starting with the same ground term. And, a ground term t is accepted if there is one reduction (among all possible reductions) starting from this ground term and leading to a configuration of the form q(t) where q is a final state. The tree language L(A) recognized by A is the set of all ground terms accepted by A. A set L of ground terms is recognizable if L = L(A) for some NFTA A. The reader should also note that when we talk about the set recognized by a finite tree automaton A we are referring to the specific set L(A), not just any set of ground terms all of which happen to be accepted by A. Two NFTA are said to be equivalent if they recognize the same tree languages.

Example 1.1.2. Let F = {f (, ), g(), a}. Consider the automaton A = (Q, F, Q f , ∆) defined by: Q = {q, q g , q f }, Q f = {q f }, and ∆ = { a → q(a) g(q(x)) → q(g(x)) g(q(x)) → q g (g(x))

g(q g (x)) → q f (g(x)) f (q(x), q(y)) → q(f (x, y)) }.

We now consider a ground term t and exhibit three different reductions of term t w.r.t. move relation → A . t = g(g(f (g(a), a))) * -→ A g(g(f (q g (g(a)), q(a))))

t = g(g(f (g(a), a))) * -→ A g(g(q(f (g(a), a)))) * -→ A q(t) t = g(g(f (g(a), a))) * -→ A g(g(q(f (g(a), a)))) * -→ A q f (t)
The term t is accepted by A because of the third reduction. It is easy to prove that L(A) = {g(g(t)) | t ∈ T (F)} is the set of ground instances of g(g(x)).

The set of transition rules of a NFTA A can also be defined as a ground rewrite system, i.e. a set of ground transition rules of the form: f (q 1 , . . . , q n ) → q. A move relation → A can be defined as before. The only difference is that, now, we "forget" the ground subterms. And, a term t is accepted by a NFTA A if t *

-→

A q for some final state q in Q f . Unless it is stated otherwise, we will now refer to the definition with a set of ground transition rules. Considering a reduction starting from a ground term t and leading to a state q with the move relation, it is useful to remember the "history" of the reduction, i.e. to remember in which states the ground subterms of t are reduced. For this, we will adopt the following definitions. Let t be a ground term and A be a NFTA, a run r of A on t is a mapping r : Pos(t) → Q compatible with ∆, i.e. for every position p in Pos(t), if t(p) = f ∈ F n , r(p) = q, r(pi) = q i for each i ∈ {1, . . . , n}, then f (q 1 , . . . , q n ) → q ∈ ∆. A run r of A on t is successful if r(ǫ) is a final state. And a ground term t is accepted by a NFTA A if there is a successful run r of A on t.

Example 1.1.3. Let F = {or(, ), and(, ), not(), 0, 1}. Consider the automaton A = (Q, F, Q f , ∆) defined by: Q = {q 0 , q 1 }, Q f = {q 1 }, and ∆ = { 0 → q 0 1 → q 1 not(q 0 ) → q 1 not(q 1 ) → q 0 and(q 0 , q 0 ) → q 0 and(q 0 , q 1 ) → q 0 and(q 1 , q 0 ) → q 0 and(q 1 , q 1 ) → q 1 or(q 0 , q 0 ) → q 0 or(q 0 , q 1 ) → q 1 or(q 1 , q 0 ) → q 1 or(q 1 , q 1 ) → q 1 }.

A ground term over F can be viewed as a boolean formula without variable and a run on such a ground term can be viewed as the evaluation of the corresponding boolean formula. For instance, we give a reduction for a ground term t and the corresponding run given as a tree 0 1

or not 1 0 not or and * -→ A q 0 ; the run r: q 0 q 1 q 1 q 0 q 1 q 0 q 1 q 1 q 0

The tree language recognized by A is the set of true boolean expressions over F.

NFTA with ǫ-rules

Like in the word case, it is convenient to allow ǫ-moves in the reduction of a ground term by an automaton, i.e. the current state is changed but no new symbol of the term is processed. This is done by introducing a new type of rules in the set of transition rules of an automaton. A NFTA with ǫ-rules is like a NFTA except that now the set of transition rules contains ground transition rules of the form f (q 1 , . . . , q n ) → q, and ǫ-rules of the form q → q ′ . The ability to make ǫ-moves does not allow the NFTA to accept non recognizable sets. But NFTA with ǫ-rules are useful in some constructions and simplify some proofs.

Example 1.1.4. Let F = {cons(, ), s(), 0, nil}. Consider the automaton A = (Q, F, Q f , ∆) defined by: Q = {q Nat , q List , q List * }, Q f = {q List }, and ∆ = { 0 → q Nat s(q Nat ) → q Nat nil → q List cons(q Nat , q List ) → q List * q List * → q List }.

The recognized tree language is the set of Lisp-like lists of integers. If the final state set Q f is set to {q List * }, then the recognized tree language is the set of non empty Lisp-like lists of integers. The ǫ-rule q List * → q List says that a non empty list is a list. The reader should recognize the definition of an order-sorted algebra with the sorts Nat, List, and List * (which stands for the non empty lists), and the inclusion List * ⊆ List (see Section 3.4.1).

Theorem 1.1.5 (The equivalence of NFTAs with and without ǫ-rules). If L is recognized by a NFTA with ǫ-rules, then L is recognized by a NFTA without ǫ-rules.

Proof. Let A = (Q, F, Q f , ∆) be a NFTA with ǫ-rules. Consider the subset ∆ ǫ consisting of those ǫ-rules in ∆. We denote by ǫ-closure(q) the set of all states q ′ in Q such that there is a reduction of q into q ′ using rules in ∆ ǫ . We consider that q ∈ ǫ-closure(q). This computation is a transitive closure computation and can be done in O(|Q| 3 ). Now let us define the NFTA A ′ = (Q, F, Q f , ∆ ′ ) where ∆ ′ is defined by: ∆ ′ = {f (q 1 , . . . , q n ) → q ′ | f (q 1 , . . . , q n ) → q ∈ ∆, q ′ ∈ ǫ-closure(q)} Then it may be proved that t

* -→ A q iff t * --→ A ′ q.
Unless it is stated otherwise, we will now consider NFTA without ǫ-rules.

Deterministic Finite Tree Automata

Our definition of tree automata corresponds to the notion of nondeterministic finite tree automata. We will now define deterministic tree automata (DFTA) which are a special case of NFTA. It will turn out that, like in the word case, any language recognized by a NFTA can also be recognized by a DFTA.

A tree automaton A = (Q, F, Q f , ∆) is deterministic (DFTA) if there are no two rules with the same left-hand side (and no ǫ-rule). A DFTA is unambiguous, that is there is at most one run for every ground term, i.e. for every ground term t, there is at most one state q such that t * -→ A q. The reader should note that it is possible to define a non deterministic tree automaton which is unambiguous (see Example 1.1.6).

It is also useful to consider tree automata such that there is at least one run for every ground term. This leads to the following definition. A NFTA A is complete if there is at least one rule f (q 1 , . . . , q n ) → q ∈ ∆ for all n ≥ 0, f ∈ F n , and q 1 , . . . , q n ∈ Q. Let us note that for a complete DFTA there is exactly one run for every ground term.

Lastly, for practical reasons, it is usual to consider automata in which unnecessary states are eliminated. A state q is accessible if there exists a ground term t such that t * -→ A q. A NFTA A is said to be reduced if all its states are accessible.

Example 1.1.6. The automaton defined in Example 1.1.2 is reduced, not complete, and it is not deterministic because there are two rules of left-hand side g(q(x)). Let us also note (see Example 1.1.2) that at least two runs (one is successful) can be defined on the term g(g(f (g(a), a))).

The automaton defined in Example 1.1.3 is a complete and reduced DFTA. Let F = {g(), a}. Consider the automaton A = (Q, F, Q f , ∆) defined by: Q = {q 0 , q 1 , q}, Q f = {q 0 }, and ∆ is the following set of transition rules:

{

a → q 0 g(q 0 ) → q 1 g(q 1 ) → q 0 g(q) → q 0 g(q) → q 1 }. This automaton is not deterministic because there are two rules of left-hand side g(q), it is not reduced because state q is not accessible. Nevertheless, one should note that there is at most one run for every ground term t.

Let F = {f (, ), g(), a}. Consider the automaton A = (Q, F, Q f , ∆) defined in Example 1.1.1 by: Q = {q a , q g , q f }, Q f = {q f }, and ∆ is the following set of transition rules:

{

a → q a g(q a ) → q g g(q g ) → q g f (q g , q g ) → q f }.

This automaton is deterministic and reduced. It is not complete because, for instance, there is no transition rule of left-hand side f (q a , q a ). It is easy to define a deterministic and complete automaton A ′ recognizing the same language by adding a "dead state". The automaton A ′ = (Q ′ , F, Q f , ∆ ′ ) is defined by:

Q ′ = Q ∪ {π}, ∆ ′ = ∆∪ { g(q f ) → π g(π) → π f (q a , q a ) → π f (q a , q g ) → π . . . f (π, π) → π }.
It is easy to generalize the construction given in Example 1.1.6 of a complete NFTA equivalent to a given NFTA: add a "dead state" π and all transition rules with right-hand side π such that the automaton is complete. The reader should note that this construction could be expensive because it may require O(|F| × |Q| Arity(F ) ) new rules where Arity(F) is the maximal arity of symbols in F. Therefore we have the following: Theorem 1.1.7. Let L be a recognizable set of ground terms. Then there exists a complete finite tree automaton that accepts L.

We now give a polynomial algorithm which outputs a reduced NFTA equivalent to a given NFTA as input. The main loop of this algorithm computes the set of accessible states.

Reduction Algorithm RED input

: NFTA A = (Q, F, Q f , ∆) begin
Set Marked to ∅ /* Marked is the set of accessible states */ repeat Set Marked to Marked ∪ {q} where f ∈ F n , q 1 , . . . , q n ∈ Marked , f (q 1 , . . . , q n ) → q ∈ ∆ until no state can be added to Marked Set Q r to Marked Set Q r f to Q f ∩ Marked Set ∆ r to {f (q 1 , . . . , q n ) → q ∈ ∆ | q, q 1 , . . . , q n ∈ Marked } output:

NFTA A r = (Q r , F, Q r f , ∆ r ) end
Let us recall that the case n = 0, in our notation, corresponds to rules of the form a → q where a is a constant symbol. Obviously all states in the set Marked are accessible, and an easy induction shows that all accessible states are in the set Marked . And, the NFTA A r accepts the tree language L(A). Consequently we have: Theorem 1.1.8. Let L be a recognizable set of ground terms. Then there exists a reduced finite tree automaton that accepts L. Now, we consider the reduction of nondeterminism. Since every DFTA is a NFTA, it is clear that the class of recognizable languages includes the class of languages accepted by DFTAs. However it turns out that these classes are equal. We prove that, for every NFTA, we can construct an equivalent DFTA. The proof is similar to the proof of equivalence between DFAs and NFAs in the word case. The proof is based on the "subset construction". Consequently, the number of states of the equivalent DFTA can be exponential in the number of states of the given NFTA (see Example 1.1.11). But, in practice, it often turns out that many states are not accessible. Therefore, we will present in the proof of the following theorem a construction of a DFTA where only the accessible states are considered, i.e. the given algorithm outputs an equivalent and reduced DFTA from a given NFTA as input.

Theorem 1.1.9 (The equivalence of DFTAs and NFTAs). Let L be a recognizable set of ground terms. Then there exists a DFTA that accepts L.

Proof. First, we give a theoretical construction of a DFTA equivalent to a NFTA. Let A = (Q, F, Q f , ∆) be a NFTA. Define a DFTA A d = (Q d , F, Q df , ∆ d ), as follows. The states of Q d are all the subsets of the state set Q of A. That is, Q d = 2 Q . We denote by s a state of Q d , i.e. s = {q 1 , . . . , q n } for some states q 1 , . . . , q n ∈ Q. We define f (s 1 , . . . , s n ) → s ∈ ∆ d iff s = {q ∈ Q | ∃q 1 ∈ s 1 , . . . , ∃q n ∈ s n , f (q 1 , . . . , q n ) → q ∈ ∆}.

And Q df is the set of all states in Q d containing a final state of A. It is easy to prove that L(A) = L(A d ). We now give an algorithmic construction where only the accessible states are considered.

Determinization Algorithm DET input

: NFTA A = (Q, F, Q f , ∆) begin /* A state s of the equivalent DFTA is in 2 Q */ Set Q d to ∅; set ∆ d to ∅ repeat Set Q d to Q d ∪ {s}; Set ∆ d to ∆ d ∪ {f (s 1 , . . . , s n ) → s} where f ∈ F n , s 1 , . . . , s n ∈ Q d , s = {q ∈ Q | ∃q 1 ∈ s 1 , .
. . , q n ∈ s n , f (q 1 , . . . , q n ) → q ∈ ∆} until no rule can be added to

∆ d Set Q df to {s ∈ Q d | s ∩ Q f = ∅} output: DFTA A d = (Q d , F, Q df , ∆ d ) end
It is immediate from the definition of the determinization algorithm that A d is a deterministic and reduced tree automaton. In order to prove that L(A) = L(A d ), we now prove that:

(t * --→ A d s) iff (s = {q ∈ Q | t * -→ A q}).
The proof is an easy induction on the structure of terms.

• base case: let us consider t = a ∈ F 0 . Then, there is only one rule a → s in ∆ d where s = {q ∈ Q | a → q ∈ ∆}.

• induction step: let us consider a term t = f (t 1 , . . . , t n ).

-First, let us suppose that t * --→ . . , q n ∈ s n , f (q 1 , . . . , q n ) → q ∈ ∆}. Thus,

s = {q ∈ Q | t * -→ A q}.
-Second, let us consider

s = {q ∈ Q | t = f (t 1 , . . . , t n ) * -→ A q}.
Let us consider the state sets s i defined by

s i = {q ∈ Q | t i * -→ A q}.
By induction hypothesis, for each i ∈ {1, . . . , n}, t i *

--→

A d s i . Thus s = {q ∈ Q | ∃q 1 ∈ s 1 , . . . , q n ∈ s n , f (q 1 , . . . , q n ) → q ∈ ∆}. The rule f (s 1 , . . . , s n ) ∈ ∆ d by definition of the state set ∆ d in the determinization algorithm and t * --→

A d s.
Example 1.1.10. Let F = {f (, ), g(), a}. Consider the automaton A = (Q, F, Q f , ∆) defined in Example 1.1.2 by: Q = {q, q g , q f }, Q f = {q f }, and ∆ = { a → q g(q) → q g(q) → q g g(q g ) → q f f (q, q) → q }. Given A as input, the determinization algorithm outputs the DFTA A d = (Q d , F, Q df , ∆ d ) defined by: Q d = {{q}, {q, q g }, {q, q g , q f }}, Q df = {{q, q g , q f }}, and ∆ d = { a → {q} g({q}) → {q, q g } g({q, q g }) → {q, q g , q f } g({q, q g , q f }) → {q, q g , q

f } } ∪ { f (s 1 , s 2 ) → {q} | s 1 , s 2 ∈ Q d }.
We now give an example where an exponential blow-up occurs in the determinization process. This example is the same used in the word case.

Example 1.1.11. Let F = {f (), g(), a} and let n be an integer. And let us consider the tree language L = {t ∈ T (F) | the symbol at position 1 . . .

1 n is f }.
Let us consider the NFTA A = (Q, F, Q f , ∆) defined by: Q = {q, q 1 , . . . , q n+1 }, Q f = {q n+1 }, and ∆ = { a → q f (q) → q g(q) → q f (q) → q 1 g(q 1 ) → q 2 f (q 1 ) → q 2 . . . . . . g(q n ) → q n+1 f (q n ) → q n+1 }.

The NFTA A = (Q, F, Q f , ∆) accepts the tree language L, and it has n + 2 states. Using the subset construction, the equivalent DFTA A d has 2 n+1 states.

Any equivalent automaton has to memorize the n + 1 last symbols of the input tree. Therefore, it can be proved that any DFTA accepting L has at least 2 n+1 states. It could also be proved that the automaton A d is minimal in the number of states (minimal tree automata are defined in Section 1.5).

If a finite tree automaton is deterministic, we can replace the transition relation ∆ by a transition function δ. Therefore, it is sometimes convenient to consider a DFTA A = (Q, F, Q f , δ) where

δ : n F n × Q n → Q .
The computation of such an automaton on a term t as input tree can be viewed as an evaluation of t on finite domain Q. Indeed, define the labeling function δ : T (F) → Q inductively by δ(f (t 1 , . . . , t n )) = δ(f, δ(t 1 ), . . . , δ(t n )) .

We shall for convenience confuse δ and δ.

We now make clear the connections between our definitions and the language theoretical definitions of tree automata and of recognizable tree languages. Indeed, the reader should note that a complete DFTA is just a finite F-algebra A consisting of a finite carrier |A| = Q and a distinguished n-ary function f A : Q n → Q for each n-ary symbol f ∈ F together with a specified subset Q f of Q. A ground term t is accepted by A if δ(t) = q ∈ Q f where δ is the unique F-algebra homomorphism δ : T (F) → A.

Example 1.1.12. Let F = {f (, ), a} and consider the F-algebra A with |A| = Q = Z 2 = {0, 1}, f A = + where the sum is formed modulo 2, a A = 1, and let Q f = {0}. A and Q f defines a DFTA. The recognized tree language is the set of ground terms over F with an even number of leaves.

Since DFTA and NFTA accept the same sets of tree languages, we shall not distinguish between them unless it becomes necessary, but shall simply refer to both as tree automata (FTA).

The Pumping Lemma for Recognizable Tree Languages

We now give an example of a tree language which is not recognizable.

Example 1.2.1. Let F = {f (, ), g(), a}. Let us consider the tree language L = {f (g i (a), g i (a)) | i > 0}. Let us suppose that L is recognizable by an automaton A having k states. Now, consider the term t = f (g k (a), g k (a)). t belongs to L, therefore there is a successful run of A on t. As k is the cardinality of the state set, there are two distinct positions along the first branch of the term labeled with the same state. Therefore, one could cut the first branch between these two positions leading to a term t ′ = f (g j (a), g k (a)) with j < k such that a successful run of A can be defined on t ′ . This leads to a contradiction with L(A) = L.

This (sketch of) proof can be generalized by proving a pumping lemma for recognizable tree languages. This lemma is extremely useful in proving that certain sets of ground terms are not recognizable. It is also useful for solving decision problems like emptiness and finiteness of a recognizable tree language (see Section 1.7).

Pumping Lemma. Let L be a recognizable set of ground terms. Then, there exists a constant k > 0 satisfying: for every ground term t in L such that Height(t) > k, there exist a context C ∈ C(F), a non trivial context C ′ ∈ C(F), and a ground term u such that t = C[C ′ [u]] and, for all

n ≥ 0 C[C ′ n [u]] ∈ L.
Proof. Let A = (Q, F, Q f , ∆) be a FTA such that L = L(A) and let k = |Q| be the cardinality of the state set Q. Let us consider a ground term t in L such that Height(t) > k and consider a successful run r of A on t. Now let us consider a path in t of length strictly greater than k. As k is defined to be the cardinality of the state set Q, there are two positions p 1 < p 2 along this path such that r(p 1 ) = r(p 2 ) = q for some state q. Let u be the ground subterm of t at position p 2 . Let u ′ be the ground subterm of t at position p 1 , there exists a non-trivial context

C ′ such that u ′ = C ′ [u]. Now define the context C such that t = C[C ′ [u]]. Consider a term C[C ′ n [u]
] for some integer n > 1, a successful run can be defined on this term. Indeed suppose that r corresponds to the reduction t * -→ A q f where q f is a final state of A, then we have:

C[C ′ n [u]] * -→ A C[C ′ n [q]] * -→ A C[C ′ n-1 [q]] . . . * -→ A C[q] * -→ A q f .
The same holds when n = 0.

Example 1.2.2. Let F = {f (, ), a}. Let us consider the tree language L = {t ∈ T (F) | |Pos(t)| is a prime number}. We can prove that L is not recognizable. For all k > 0, consider a term t in L whose height is greater than k. For all contexts C, non trivial contexts C ′ , and terms u such that t = C[C ′ [u]], there exists n such that C[C ′ n [u]] ∈ L.

From the Pumping Lemma, we derive conditions for emptiness and finiteness given by the following corollary:

Corollary 1.2.3. Let A = (Q, F, Q f , ∆) be a FTA. Then L(A) is non empty if and only if there exists a term t in L(A) with Height(t) ≤ |Q|. Then L(A) is infinite if and only if there exists a term t in L(A) with |Q| < Height(t) ≤ 2|Q|.

Closure Properties of Recognizable Tree Languages

A closure property of a class of (tree) languages is the fact that the class is closed under a particular operation. We are interested in effective closure properties where, given representations for languages in the class, there is an algorithm to construct a representation for the language that results by applying the operation to these languages. Let us note that the equivalence between NFTA and DFTA is effective, thus we may choose the representation that suits us best. Nevertheless, the determinization algorithm may output a DFTA whose number of states is exponential in the number of states of the given NFTA.

For the different closure properties, we give effective constructions and we give the properties of the resulting FTA depending on the properties of the given FTA as input. In this section, we consider the Boolean set operations: union, intersection, and complementation. Other operations will be studied in the next sections. Complexity results are given in Section 1.7.

Theorem 1.3.1. The class of recognizable tree languages is closed under union, under complementation, and under intersection.

Union

Let L 1 and L 2 be two recognizable tree languages. Thus there are tree automata

A 1 = (Q 1 , F, Q f 1 , ∆ 1 ) and A 2 = (Q 2 , F, Q f 2 , ∆ 2 ) with L 1 = L(A 1 )
and L 2 = L(A 2 ). Since we may rename states of a tree automaton, without loss of generality, we may suppose that

Q 1 ∩ Q 2 = ∅. Now, let us consider the FTA A = (Q, F, Q f , ∆) defined by: Q = Q 1 ∪ Q 2 , Q f = Q f 1 ∪ Q f 2 , and ∆ = ∆ 1 ∪∆ 2 .
The equality between L(A) and L(A 1 )∪L(A 2 ) is straightforward. Let us note that A is nondeterministic and not complete, even if A 1 and A 2 are deterministic and complete. We now give another construction which preserves determinism. The intuitive idea is to process in parallel a term by the two automata. For this we consider a product automaton. Let us suppose that A 1 and A 2 are complete. And, let us consider the FTA A = (Q, F, Q f , ∆) defined by:

Q = Q 1 × Q 2 , Q f = Q f 1 × Q 2 ∪ Q 1 × Q f 2 , and ∆ = ∆ 1 × ∆ 2 where ∆ 1 × ∆ 2 = {f ((q 1 , q ′ 1 ), . . . , (q n , q ′ n )) → (q, q ′ ) | f (q 1 , . . . , q n ) → q ∈ ∆ 1 f (q ′ 1 , . . . , q ′ n ) → q ′ ∈ ∆ 2 }
The proof of the equality between L(A) and L(A 1 ) ∪ L(A 2 ) is left to the reader, but the reader should note that the hypothesis that the two given tree automata are complete is crucial in the proof. Indeed, suppose for instance that a ground term t is accepted by A 1 but not by A 2 . Moreover suppose that A 2 is not complete and that there is no run of A 2 on t, then the product automaton does not accept t because there is no run of the product automaton on t. The reader should also note that the construction preserves determinism, i.e. if the two given automata are deterministic, then the product automaton is also deterministic.

Complementation

Let L be a recognizable tree language. Let A = (Q, F, Q f , ∆) be a complete DFTA such that L(A) = L. Now, complement the final state set to recognize the complement of L. That is, let

A c = (Q, F, Q c f , ∆) with Q c f = Q \ Q f , the DFTA A c recognizes the complement of set L in T (F).
If the input automaton A is a NFTA, then first apply the determinization algorithm, and second complement the final state set. This could lead to an exponential blow-up.

Intersection

Closure under intersection follows from closure under union and complementation because

L 1 ∩ L 2 = L 1 ∪ L 2 .
where we denote by L the complement of set L in T (F). But if the recognizable tree languages are defined by NFTA, we have to use the complementation construction, therefore the determinization process is used leading to an exponential blow-up. Consequently, we now give a direct construction which does not use the determinization algorithm. Let

A 1 = (Q 1 , F, Q f 1 , ∆ 1 ) and A 2 = (Q 2 , F, Q f 2 , ∆ 2 ) be FTA such that L(A 1 ) = L 1 and L(A 2 ) = L 2 . And, consider the FTA A = (Q, F, Q f , ∆) defined by: Q = Q 1 ×Q 2 , Q f = Q f 1 ×Q f 2 , and ∆ = ∆ 1 × ∆ 2 . A recognizes L 1 ∩ L 2 .
Moreover the reader should note that A is deterministic if A 1 and A 2 are deterministic.

Tree Homomorphisms

We now consider tree transformations and study the closure properties under these tree transformations. In this section we are interested with tree transformations preserving the structure of trees. Thus, we restrict ourselves to tree homomorphisms. Tree homomorphisms are a generalization of homomorphisms for words (considered as unary terms) to the case of arbitrary ranked alphabets. In the word case, it is known that the class of regular sets is closed under homomorphisms and inverse homomorphisms. The situation is different in the tree case because whereas recognizable tree languages are closed under inverse homomorphisms, they are closed only under a subclass of homomorphisms, i.e. linear homomorphisms (duplication of terms is forbidden). First, we define tree homomorphisms.

Let F and F ′ be two sets of function symbols, possibly not disjoint. For each n > 0 such that F contains a symbol of arity n, we define a set of variables X n = {x 1 , . . . , x n } disjoint from F and F ′ .

Let h F be a mapping which, with f ∈ F of arity n, associates a term t f ∈ T (F ′ , X n ). The tree homomorphism h : T (F) → T (F ′ ) determined by h F is defined as follows:

• h(a) = t a ∈ T (F ′ ) for each a ∈ F of arity 0, • h(f (t 1 , . . . , t n )) = t f {x 1 ← h(t 1 ), . . . , x n ← h(t n )} where t f {x 1 ← h(t 1 ), . . . , x n ← h(t n )} is the result of applying the substi- tution {x 1 ← h(t 1 ), . . . , x n ← h(t n )} to the term t f .
Example 1.4.1. Let F = {g(, , ), a, b} and F ′ = {f (, ), a, b}. Let us consider the tree homomorphism h determined by h F defined by: h

F (g) = f (x 1 , f (x 2 , x 3 )), h F (a) = a and h F (b) = b.
For instance, we have:

If t = a b b b g a g , then h(t) = a b b b f f a f f
The homomorphism h defines a transformation from ternary trees into binary trees.

Let us now consider F = {and(, ), or(, ), not(), 0, 1} and F ′ = {or(, ), not(), 0, 1}. Let us consider the tree homomorphism h determined by h F defined by: h F (and) = not(or(not(x 1 ), not(x 2 )), and h F is the identity otherwise. This homomorphism transforms a boolean formula in an equivalent boolean formula which does not contain the function symbol and.

A tree homomorphism is linear if for each f ∈ F of arity n, h F (f ) = t f is a linear term in T (F ′ , X n ).
The following example shows that tree homomorphisms do not always preserve recognizability.

Example 1.4.2. Let F = {f (), g(), a} and F ′ = {f ′ (, ), g(), a}. Let us consider the tree homomorphism h determined by h F defined by: h

F (f ) = f ′ (x 1 , x 1 ), h F (g) = g(x 1 ), and h F (a) = a. h is not linear. Let L = {f (g i (a)) | i ≥ 0}, then L is a recognizable tree language. h(L) = {f ′ (g i (a), g i (a)) | i ≥ 0} is not recognizable (see Example 1.2.1).
Theorem 1.4.3 (Linear homomorphisms preserve recognizability). Let h be a linear tree homomorphism and L be a recognizable tree language, then h(L) is a recognizable tree language.

Proof. Let L be a recognizable tree language. Let A = (Q, F, Q f , ∆) be a reduced DFTA such that L(A) = L. Let h be a linear tree homomorphism from T (F) into T (F ′ ) determined by a mapping h F .

First, let us define a NFTA

A ′ = (Q ′ , F ′ , Q ′ f , ∆ ′ ).
Let us consider a rule r = f (q 1 , . . . , q n ) → q in ∆ and consider the linear term t f = h F (f ) ∈ T (F ′ , X n ) and the set of positions Pos(t f ). We define a set of states Q r = {q r p | p ∈ Pos(t f )}, and we define a set of rules ∆ r as follows: for all positions p in Pos(t f )

• if t f (p) = g ∈ F ′ k , then g(q r p1 , . . . , q r p k ) → q r p ∈ ∆ r , • if t f (p) = x i , then q i → q r p ∈ ∆ r , • q r ǫ → q ∈ ∆ r .
The preceding construction is made for each rule in ∆. We suppose that all the state sets Q r are disjoint and that they are disjoint from Q. Now define A ′ by:

• Q ′ = Q ∪ r∈∆ Q r , • Q ′ f = Q f , • ∆ ′ = r∈∆ ∆ r .
Second, we have to prove that h(L) = L(A ′ ).

h(L) ⊆ L(A ′ ). We prove that if t * -→ A q then h(t) * --→
A ′ q by induction on the length of the reduction of ground term t ∈ T (F) by automaton A.

• Base case. Suppose that t → A q. Then t = a ∈ F 0 and a → q ∈ ∆.

Then there is a reduction h(a) = t a * --→ A ′ q using the rules in the set ∆ a→q .

• Induction step. Suppose that t = f (u 1 , . . . , u n ), then h(t) = t f {x 1 ←h(u 1 ), . . . , x n ← h(u n )}. Moreover suppose that t * -→ A f (q 1 , . . . , q n ) → A q. By induc- tion hypothesis, we have h(u i ) * --→ A ′ q i , for each i in {1, . . . , n}.
Then there is a reduction t f {x 1 ← q 1 , . . . , x n ← q n } * --→ A ′ q using the rules in the set ∆ f (q1,...,qn)→q .

h(L) ⊇ L(A ′ ). We prove that if t ′ * --→ A ′ q ∈ Q then t ′ = h(t) with t * -→ A q for some t ∈ T (F).
The proof is by induction on the number of states in Q occurring along the reduction t ′ * --→ A ′ q ∈ Q.

• Base case. Suppose that t ′ * --→ A ′ q ∈ Q and no state in Q apart from q occurs in the reduction. Then, because the state sets Q r are disjoint, only rules of some ∆ r can be used in the reduction. Thus, t ′ is ground, t ′ = h F (f ) for some symbol f ∈ F, and r = f (q 1 , . . . , q n ) → q. Because the automaton is reduced, there is some ground term t with Head (t) = f such that t ′ = h(t) and t * -→ A q.

• Induction step. Suppose that

t ′ * --→ A ′ v{x ′ 1 ←q 1 , . . . , x ′ m ←q m } * --→ A ′ q
where v is a linear term in

T (F ′ , {x ′ 1 , . . . , x ′ m }), t ′ = v{x ′ 1 ← u ′ 1 , . . . , x ′ m ← u ′ m }, u ′ i * --→ A ′ q i ∈ Q, and no state in Q apart from q occurs in the reduction of v{x ′ 1 ← q 1 , . . . , x ′ m ← q m } to q.
The reader should note that different variables can be substituted by the same state. Then, because the state sets Q r are disjoint, only rules of some ∆ r can be used in the reduction of v{x ′ 1 ← q 1 , . . . , x ′ m ← q m } to q. Thus, there exists some linear term t f such that v{x ′ 1 ← q 1 , . . . , x ′ m ← q m } = t f {x 1 ← q 1 , . . . , x n ← q n } for some symbol f ∈ F n and r = f (q 1 , . . . , q n ) → q ∈ ∆. By induction hypothesis, there are terms u 1 , . . . , u m in L such that u

′ i = h(u i ) and u i * -→ A q i for each i in {1, . . . , m}. Now consider the term t = f (v 1 , . . . , v n ), where v i = u i if x i occurs in t f and v i is some term such that v i * -→ A q i otherwise (terms v i always exist because A is reduced). We have h(t) = t f {x 1 ←h(v 1 ), . . . , x n ←h(v n )}, h(t) = v{x ′ 1 ←h(u 1 ), . . . , x ′ m ← h(u m )}, h(t) = t ′ .
Moreover, by definition of the v i and by induction hypothesis, we have t * -→ A q. Note that if q i occurs more than once, you can substitute q i by any term satisfying the conditions. The proof does not work for the non linear case because you have to check that different occurrences of some state q i corresponding to the same variable x j ∈ Var (t f ) can only be substituted by equal terms.

Only linear tree homomorphisms preserve recognizability. But, for linear and non linear homomorphisms, we have: Theorem 1.4.4 (Inverse homomorphisms preserve recognizability). Let h be a tree homomorphism and L be a recognizable tree language, then h -1 (L) is a recognizable tree language.

Proof. Let h be a tree homomorphism from

T (F) into T (F ′ ) determined by a mapping h F . Let A ′ = (Q ′ , F ′ , Q ′ f , ∆ ′ ) be a complete DFTA such that L(A ′ ) = L. We define a DFTA A = (Q, F, Q f , ∆) by Q = Q ′ ∪ {s} where s ∈ Q ′ , Q f = Q ′
f and ∆ is defined by the following:

• for a ∈ F 0 , if t a * --→ A ′ q then a → q ∈ ∆; • for f ∈ F n where n > 0, for p 1 , . . . , p n ∈ Q, if t f {x 1 ← p 1 , . . . , x n ← p n } * --→ A ′ q then f (q 1 , . . . , q n ) → q ∈ ∆ where q i = p i if x i occurs in t f and q i = s otherwise; • for a ∈ F 0 , a → s ∈ ∆; • for f ∈ F n where n > 0, f (s, . . . , s) → s ∈ ∆.
The rule set ∆ is computable. The proof of the equivalence t * -→ A q if and only if h(t) * --→ A ′ q is left to the reader. It can be proved that the class of recognizable tree languages is the smallest non trivial class of tree languages closed by linear tree homomorphisms and inverse tree homomorphisms. Tree homomorphisms do not in general preserve recognizability, therefore let us consider the following problem: given as instance a recognizable tree language L and a tree homomorphism h, is the set h(L) recognizable? It is not known whether this problem is decidable.

As a conclusion, we consider different special types of tree homomorphisms. These homomorphisms will be used in the next sections in order to simplify some proofs and will be useful in Chapter 6. Let h be a tree homomorphism determined by h F . The tree homomorphism h is said to be:

• ǫ-free (or non erasing) if for each symbol f ∈ F, t f is not reduced to a variable.

• symbol to symbol if for each symbol f ∈ F, Height(t f ) = 1. The reader should note that with our definitions a symbol to symbol tree homomorphism is ǫ-free. A linear symbol to symbol tree homomorphism changes the label of the input symbol, possibly erases some subtrees and possibly modifies order of subtrees.

• complete if for each symbol f ∈ F n , Var (t f ) = X n .
• a delabeling if h is a complete, linear, symbol to symbol tree homomorphism. Such a delabeling only changes the label of the input symbol and possibly order of subtrees.

• alphabetic (or a relabeling) if for each symbol f ∈ F n , t f = g(x 1 , . . . , x n ), where g ∈ F ′ n .

As a corollary of Theorem 1.4.3, alphabetic tree homomorphisms, delabelings and linear, symbol to symbol tree homomorphisms preserve recognizability. It can be proved that for these classes of tree homomorphisms, given h and a FTA A such that L(A) = L as instance, a FTA for the recognizable tree language h(L) can be constructed in linear time. The same holds for h -1 (L).

Example 1.4.5. Let F = {f (, ), g(), a} and F ′ = {f ′ (, ), g ′ (), a ′ }. Let us consider some tree homomorphisms h determined by different h F .

• h F (f ) = x 1 , h F (g) = f ′ (x 1 , x 1
), and h F (a) = a ′ defines a tree homomorphism which is not linear, not ǫ-free, and not complete.

• h F (f ) = g ′ (x 1 ), h F (g) = f ′ (x 1 , x 1 )
, and h F (a) = a ′ defines a tree homomorphism which is a non linear symbol to symbol tree homomorphism, and it is not complete.

• h F (f ) = f ′ (x 2 , x 1 ), h F (g) = g ′ (x 1
), and h F (a) = a ′ defines a tree homomorphism which is a delabeling.

• h F (f ) = f ′ (x 1 , x 2 ), h F (g) = g ′ (x 1
), and h F (a) = a ′ defines a tree homomorphism which is an alphabetic tree homomorphism.

Minimizing Tree Automata

In this section, we prove that, like in the word case, there exists a unique minimal automaton in the number of states for a given recognizable tree language.

A Myhill-Nerode Theorem for Tree Languages

The Myhill-Nerode Theorem is a classical result in the theory of finite automata. This theorem gives a characterization of the recognizable sets and it has numerous applications. A consequence of this theorem, among other consequences, is that there is essentially a unique minimum state DFA for every recognizable language over finite alphabet. The Myhill-Nerode Theorem generalizes in a straightforward way to automata on finite trees. An equivalence relation

≡ on T (F) is a congruence on T (F) if for every f ∈ F n u i ≡ v i 1 ≤ i ≤ n ⇒ f (u 1 , . . . , u n ) ≡ f (v 1 , . . . , v n ) .
It is of finite index if there are only finitely many ≡-classes. Equivalently a congruence is an equivalence relation closed under context, i.e. for all contexts

C ∈ C(F), if u ≡ v, then C[u] ≡ C[v].
For a given tree language L, let us define the congruence ≡ L on T (F) by: u ≡ L v if for all contexts C ∈ C(F),

C[u] ∈ L iff C[v] ∈ L.
We are now ready to give the Theorem:

Myhill-Nerode Theorem. The following three statements are equivalent:

(i) L is a recognizable tree language (ii) L is the union of some equivalence classes of a congruence of finite index (iii) the relation ≡ L is a congruence of finite index.

Proof.

• (i) ⇒ (ii) Assume that L is recognized by some complete DFTA A = (Q, F, Q f , δ).
We consider δ as a transition function. Let us consider the relation ≡ A defined on T (F) by: u

≡ A v if δ(u) = δ(v).
Clearly ≡ A is a congruence relation and it is of finite index, since the number of equivalence classes is at most the number of states in Q. Furthermore, L is the union of those equivalence classes that include a term u such that δ(u) is a final state.

• (ii) ⇒ (iii) Let us denote by ∼ the congruence of finite index. And let us assume that u ∼ v. By an easy induction on the structure of terms, it can be proved that C[u] ∼ C[v] for all contexts C ∈ C(F). Now, L is the union of some equivalence classes of ∼, thus we have

C[u] ∈ L iff C[v] ∈ L. Thus u ≡ L v,
and the equivalence class of u in ∼ is contained in the equivalence class of u in ≡ L . Consequently, the index of ≡ L is lower than or equal to the index of ∼ which is finite.

• (iii) ⇒ (i) Let Q min be the finite set of equivalence classes of ≡ L . And let us denote by [u] the equivalence class of a term u. Let the transition function δ min be defined by:

δ min (f, [u 1 ], . . . , [u n ]) = [f (u 1 , . . . , u n )].
The definition of δ min is consistent because ≡ L is a congruence. And let

Q min f = {[u] | u ∈ L}. The DFTA A min = (Q min , F, Q min f , δ min ) recognizes the tree language L.
As a corollary of the Myhill-Nerode Theorem, we can deduce an other algebraic characterization of recognizable tree languages. This characterization is a reformulation of the definition of recognizability. A set of ground terms L is recognizable if and only if there exist a finite F-algebra A, an F-algebra homomorphism φ : T (F) → A and a subset A ′ of the carrier |A| of A such that L = φ -1 (A ′ ).

Minimization of Tree Automata

First, we prove the existence and uniqueness of the minimum DFTA for a recognizable tree language. It is a consequence of the Myhill-Nerode Theorem because of the following result:

Corollary 1.5.1. The minimum DFTA recognizing a recognizable tree language L is unique up to a renaming of the states and is given by A min in the proof of the Myhill-Nerode Theorem.

Proof. Assume that L is recognized by some DFTA A = (Q, F, Q f , δ). The relation ≡ A is a refinement of ≡ L (see the proof of the Myhill-Nerode Theorem). Therefore the number of states of A is greater than or equal to the number of states of A min . If equality holds, A is reduced, i.e. all states are accessible, because otherwise a state could be removed leading to a contradiction. Let q be a state in Q and let u be such that δ(u) = q. The state q can be identified with the state δ min (u). This identification is consistent and defines a one to one correspondence between Q and Q min .

Second, we give a minimization algorithm for finding the minimum state DFTA equivalent to a given reduced DFTA. We identify an equivalence relation and the sequence of its equivalence classes.

Minimization Algorithm MIN input: complete and reduced DFTA

A = (Q, F, Q f , δ) begin Set P to {Q f , Q -Q f } /* P
is the initial equivalence relation*/ repeat P ′ = P /* Refine equivalence P in P ′ */ qP ′ q ′ if qP q ′ and ∀f ∈ F n ∀q 1 , . . . , q i-1 , q i+1 , . . . , q n ∈ Q δ(f (q 1 , . . . , q i-1 , q, q i+1 , . . . , q n ))P δ(f (q 1 , . . . , q i-1 , q ′ , q i+1 , . . . , q n )) until P ′ = P Set Q min to the set of equivalence classes of P /* we denote by [q] the equivalence class of state q w.r.t.

P */ Set δ min to {(f, [q 1 ], . . . , [q n ]) → [f (q 1 , . . . , q n )]} Set Q min f to {[q] | q ∈ Q f } output: DFTA A min = (Q min , F, Q min f , δ min ) end
The DFTA constructed by the algorithm MIN is the minimum state DFTA for its tree language. Indeed, let A = (Q, F, Q f , ∆) the DFTA to which is applied the algorithm and let L = L(A). Let A min be the output of the algorithm. It is easy to show that the definition of A min is consistent and that L = L(A min ). Now, by contradiction, we can prove that A min has no more states than the number of equivalence classes of ≡ L .

Top Down Tree Automata

The tree automata that we have defined in the previous sections are also known as bottom-up tree automata because these automata start their computation at the leaves of trees. In this section we define top-down tree automata. Such an automaton starts its computation at the root in an initial state and then simultaneously works down the paths of the tree level by level. The tree automaton accepts a tree if a run built up in this fashion can be defined. It appears that top-down tree automata and bottom-up tree automata have the same expressive power. An important difference between bottom-up tree automata and top-down automata appears in the question of determinism since deterministic top-down tree automata are strictly less powerful than nondeterministic ones and therefore are strictly less powerful than bottom-up tree automata. Intuitively, it is due to the following: tree properties specified by deterministic top-down tree automata can depend only on path properties. We now make precise these remarks, but first formally define top-down tree automata.

A nondeterministic top-down finite Tree Automaton (top-down NFTA) over F is a tuple A = (Q, F, I, ∆) where Q is a set of states (states are unary symbols), I ⊆ Q is a set of initial states, and ∆ is a set of rewrite rules of the following type :

q(f (x 1 , . . . , x n )) → f (q 1 (x 1 ), . . . , q n (x n )),
where n ≥ 0, f ∈ F n , q, q 1 , . . . , q n ∈ Q, x 1 , . . . , x n ∈ X .

When n = 0, i.e. when the symbol is a constant symbol a, a transition rule of top-down NFTA is of the form q(a) → a. A top-down automaton starts at the root and moves downward, associating along a run a state with each subterm inductively. We do not formally define the move relation → A defined by a topdown NFTA because the definition is easily deduced from the corresponding definition for bottom-up NFTA. The tree language L(A) recognized by A is the set of all ground terms t for which there is an initial state q in I such that

q(t) * -→ A t.
The expressive power of bottom-up and top-down tree automata is the same. Indeed, we have the following Theorem: Theorem 1.6.1 (The equivalence of top-down and bottom-up NFTAs). The class of languages accepted by top-down NFTAs is exactly the class of recognizable tree languages.

Proof. The proof is left to the reader. Hint. Reverse the arrows and exchange the sets of initial and final states.

Top-down and bottom-up tree automata have the same expressive power because they define the same classes of tree languages. Nevertheless they do not have the same behavior from an algorithmic point of view because nondeterminism can not be reduced in the class of top-down tree automata.

Proposition 1.6.2 (Top-down NFTAs and top-down DFTAs). A top-down finite Tree Automaton (Q, F, I, ∆) is deterministic (top-down DFTA) if there is one initial state and no two rules with the same left-hand side. Top-down DFTAs are strictly less powerful than top-down NFTAs, i.e. there exists a recognizable tree language which is not accepted by a top-down DFTA.

Proof. Let F = {f (, ), a, b}. And let us consider the recognizable tree language T = {f (a, b), f (b, a)}. Now let us suppose there exists a top-down DFTA that accepts T , the automaton should accept the term f (a, a) leading to a contradiction. Obviously the tree language T = {f (a, b), f (b, a)} is recognizable by a finite union of top-down DFTA but there is a recognizable tree language which is not accepted by a finite union of top-down DFTA (see Exercise 1.2).

The class of languages defined by top-down DFTA corresponds to the class of path-closed tree languages (see Exercise 1.6).

Decision Problems and their Complexity

In this section, we study some decision problems and their complexity. The size of an automaton will be the size of its representation. More formally:

Definition 1.7.1. Let A = (Q, F, Q f , ∆) be a NFTA over F. The size of a rule f (q 1 (x 1 ), . . . , q n (x n )) → q(f (x 1 , . . . , x n )) is arity(f ) + 2. The size of A noted A , is defined by: A = |Q| + f (q1(x1),...,qn(xn))→q(f (x1,...,xn))∈∆ (arity(f ) + 2).
We will work in the frame of RAM machines, with uniform measure.

Membership

Instance A ground term.

Answer "yes" if and only if the term is recognized by a given automaton.

Let us first remark that, in our model, for a given deterministic automaton, a run on a tree can be computed in O( t ). The complexity of the problem is: Theorem 1.7.2. The membership problem is ALOGTIME-complete.

Uniform Membership

Instance A tree automaton and a ground term.

Answer "yes" if and only if the term is recognized by the given automaton.

Theorem 1.7.3. The uniform membership problem can be decided in linear time for DFTA, in polynomial time for NFTA.

Proof. In the deterministic case, from a term t and the automaton A , we can compute a run in O( t + A ). In the nondeterministic case, the idea is similar to the word case: the algorithm determinizes along the computation, i.e. for each node of the term, we compute the set of reached states. The complexity of this algorithm will be in O( t × A ).

The uniform membership problem has been proved LOGSPACE-complete for deterministic top-down tree automata, LOGCFL-complete for NFTA under log-space reductions. For DFTA, it has been proven LOGDCFL, but the precise complexity remains open.

Emptiness

Instance A tree automaton Answer "yes" if and only if the recognized language is empty.

Theorem 1.7.4. It can be decided in linear time whether the language accepted by a finite tree automaton is empty.

Proof. The minimal height of accepted terms can be bounded by the number of states using Corollary 1.2.3; so, as membership is decidable, emptiness is decidable. Of course, this approach does not provide a practicable algorithm.

To get an efficient algorithm, it suffices to notice that a NFTA accepts at least one tree if and only if there is an accessible final state. In other words, the language recognized by a reduced automaton is empty if and only if the set of final states is non empty. Reducing an automaton can be done in O(|Q| × A ) by the reduction algorithm given in Section 1.1. Actually, this algorithm can be improved by choosing an adequate data structure in order to get a linear algorithm (see Exercise 1.18). This linear least fixpoint computation holds in several frameworks. For example, it can be viewed as the satisfiability test of a set of propositional Horn formulae. The reduction is easy and linear: each state q can be associated with a propositional variable X q and each rule r : f (q 1 , . . . , q n ) → q can be associated with a propositional Horn formula

F r = X q ∨¬X q1 ∨• • •∨¬X qn . It is straightforward that satisfiability of {F r }∪{¬X q /q ∈ Q f } is equivalent to emptiness of the language recognized by (Q, F, Q f , ∆).
So, as satisfiability of a set of propositional Horn formulae can be decided in linear time, we get a linear algorithm for testing emptiness for NFTA.

The emptiness problem is P-complete with respect to logspace reductions, even when restricted to deterministic tree automata. The proof can easily be done since the problem is very close to the solvable path systems problem which is known to be P-complete (see Exercise 1.19).

Intersection non-emptiness

Instance A finite sequence of tree automata.

Answer "yes" if and only if there is at least one term recognized by each automaton of the sequence.

Theorem 1.7.5. The intersection problem for tree automata is EXPTIMEcomplete.

Proof. By constructing the product automata for the n automata, and then testing non-emptiness, we get an algorithm in O(

A 1 × • • • × A n ).
The proof of EXPTIME-hardness is based on simulation of an alternating linear spacebounded Turing machine. Roughly speaking, with such a machine and an input of length n can be associated polynomially n tree automata whose intersection corresponds to the set of accepting computations on the input. It is worth noting that the result holds for deterministic top down tree automata as well as for deterministic bottom-up ones.

Finiteness

Instance A tree automaton

Answer "yes" if and only if the recognized language is finite.

Theorem 1.7.6. Finiteness can be decided in polynomial time.

Proof. Let us consider a NFTA A = (Q, F, Q f , ∆).
C ′ such that C[q] * -→ A q and C ′ [q] * -→
A q ′ for some final state q ′ . Computing accessible and coaccessible states can be done in O(|Q| × A ) or in O( A ) by using an ad hoc representation of the automaton. For a given q, deciding if there is a loop on q can be done in O( A ). So, finiteness can be decided in O(|Q| × A ).

Emptiness of the Complement

Instance A tree automaton.

Answer "yes" if and only if every term is accepted by the automaton Deciding whether a deterministic tree automaton recognizes the set of all terms is polynomial for a fixed alphabet: we just have to check whether the automaton is complete (which can be done in O(|F| × |Q| Arity(F ) )) and then it remains only to check that all accessible states are final. For nondeterministic automata, the following result proves in some sense that determinization with its exponential cost is unavoidable: Theorem 1.7.7. The problem whether a tree automaton accepts the set of all terms is EXPTIME-complete for nondeterministic tree automata.

Proof. The proof of this theorem is once more based on simulation of a linear space bounded alternating Turing machine: indeed, the complement of the accepting computations on an input w can be coded polynomially in a recognizable tree language.

Equivalence

Instance Two tree automata Answer "yes" if and only if the automata recognize the same language.

Theorem 1.7.8. Equivalence is decidable for tree automata.

Proof. Clearly, as the class of recognizable sets is effectively closed under complementation and intersection, and as emptiness is decidable, equivalence is decidable. For two deterministic complete automata A 1 and A 2 , we get by these means an algorithm in O( A 1 × A 2 ). (Another way is to compare the minimal automata). For nondeterministic ones, this approach leads to an exponential algorithm.

As we have proved that deciding whether an automaton recognizes the set of all ground terms is EXPTIME-hard, we get immediately: Corollary 1.7.9. The inclusion problem and the equivalence problem for NF-TAs are EXPTIME-complete.

Singleton Set Property

Instance A tree automaton Answer "yes" if and only if the recognized language is a singleton set.

Theorem 1.7.10. The singleton set property is decidable in polynomial time.

Proof. There are several ways to get a polynomial algorithm for this property. A first one would be to first check non-emptiness of L(A) and then "extract" from A a DFA B whose size is smaller than A and which accepts a single term recognized by A. Then it remains to check emptiness of L(A) ∩ L(B). This can be done in polynomial time, even if B is non complete.

Another way is: for each state of a bottom-up tree automaton A, compute, up to 2, the number C(q) of terms leading to state q. This can be done in a straightforward way when A is deterministic; when A is non deterministic, this can be also done in polynomial time:

Singleton Set Test Algorithm input: NFTA A = (Q, F, Q f , ∆) begin
Set C(q) to 0, for every q in Q /* C(q) ∈ {0, 1, 2} is the number, up to 2, of terms leading to state q */ /* if C(q) = 1 then T (q) is a representation of the accepted tree */ repeat for each rule f (q 1 , . . . , q n ) → q ∈ ∆ do Case ∧ j C(q j ) >= 1 and C(q i ) = 2 for some i: Set C(q) to 2 Case ∧ j C(q j ) = 1 and C(q) = 0: Set C(q) to 1, T (q) to f (q 1 , ...q n ) Case ∧ j C(q j ) = 1, C(q) = 1 and Diff (T (q), f (q 1 , . . . , q n )): Set C(q) to 2 Others null where Diff (f (q 1 , ..., q n ), g(q ′ 1 , ..., q ′ n )) defined by: /* Diff can be computed polynomially by using memorization. */ if (f = g) then return true elseif Diff (T (q i ), T (q ′ i ) for some q i then return True else return False until C can not be changed output: /*L(A) is empty */ if ∧ q∈Q f C(q) = 0 then return False /* two terms in L(A) accepted in the same state or two different states */ elseif ∃q ∈ Q f C(q) = 2 then return False elseif ∃q, q ′ ∈ Q f C(q) = C(q ′ ) = 1 and Diff (T (q), T (q ′ )) then return False /* in all other cases L(A) is a singleton set*/ else return True. end Other complexity results for "classical" problems can be found in the exercises. E.g., let us cite the following problem whose proof is sketched in Exercise 1.12

Ground Instance Intersection Problem

Instance A term t, a tree automaton A.

Answer "yes" if and only if there is at least a ground instance of t which is accepted by A.

Theorem 1.7.11. The Ground Instance Intersection Problem for tree automata is P when t is linear, NP-complete when t is non linear and A deterministic, EXPTIME-complete when t is non linear and A non deterministic.

Exercises

Starred exercises are discussed in the bibliographic notes.

Exercise 1.1. Let F = {f (, ), g(), a}. Define a top-down NFTA, a NFTA and a DFTA for the set G(t) of ground instances of term t = f (f (a, x), g(y)) which is defined by

G(t) = {f (f (a, u), g(v)) | u, v ∈ T (F )}.
Is it possible to define a top-down DFTA for this language?

Exercise 1.2. Let F = {f (, ), g(), a}. Define a top-down NFTA, a NFTA and a DFTA for the set M (t) of terms which have a ground instance of term t = f (a, g(x)) as a subterm, that is

M (t) = {C[f (a, g(u))] | C ∈ C(F ), u ∈ T (F )}.
Is it possible to define a top-down DFTA for this language? A finite union of top-down DFTA ?

Exercise 1.3. Let F = {g(), a}. Is the set of ground terms whose height is even recognizable? Let F = {f (, ), g(), a}. Is the set of ground terms whose height is even recognizable?

Exercise 1.4. Let F = {f (, ), a}. Prove that the set L = {f (t, t) | t ∈ T (F )} is not recognizable. Let F be any ranked alphabet which contains at least one constant symbol a and one binary symbol f (, ). Prove that the set

L = {f (t, t) | t ∈ T (F )} is not recognizable.
Exercise 1.5. Prove the equivalence between top-down NFTA and NFTA.

Exercise 1.6. Let t be a ground term, the path language π(t) is defined inductively by:

• if t ∈ F0, then π(t) = t • if t = f (t1, . . . , tn), then π(t) = S i=n i=1 {f iw | w ∈ π(ti)}
Let L be a tree language, the path language of L is defined as π(L) = ∪t∈Lπ(t), the path closure of L is defined as pathclosure

(L) = {t | π(t) ⊆ π(L)}. A tree language L is path-closed if pathclosure(L) = L.
1. Prove that if L is a recognizable tree language, then π(L) is a recognizable language 2. Prove that if L is a recognizable tree language, then pathclosure(L) is a recognizable language 3. Prove that a recognizable tree language is path-closed if and only if it is recognizable by a top-down DFTA.

4. Is it decidable whether a recognizable tree language defined by a NFTA is pathclosed ?

Exercise 1.7. Let F = {f (, ), g(), a} and F ′ = {f ′ (, ), g(), a}. Let us consider the tree homomorphism h determined by hF defined by: hF

(f ) = f ′ (x1, x2), hF (g) = f ′ (x1, x1), and hF (a) = a. Is h(T (F )) recognizable? Let L1 = {g i (a) | i ≥ 0}, then
L1 is a recognizable tree language, is h(L1) recognizable? Let L2 be the recognizable tree language defined by L2 = L(A) where

A = (Q, F , Q f , ∆) is defined by: Q = {qa, qg, q f }, Q f = {q f },
and ∆ is the following set of transition rules:

{ a → qa g(qa) → qg f (qa, qa) → q f f (qg, qg) → q f f (qa, qg) → q f f (qg, qa) → q f f (qa, q f ) → q f f (q f , qa) → q f f (qg, q f ) → q f f (q f , qg) → q f f (q f , q f ) → q f }.

Is h(L2) recognizable?

Exercise 1.8. Let F1 = {or(, ), and(, ), not(), 0, 1, x}. A ground term over F can be viewed as a boolean formula over variable x. Define a DFTA which recognizes the set of satisfiable boolean formulae over x. Let Fn = {or(, ), and(, ), not(), 0, 1, x1, . . . , xn}. A ground term over F can be viewed as a boolean formula over variables x1, . . . , xn. Define a DFTA which recognizes the set of satisfiable boolean formulae over x1, . . . , xn.

Exercise 1.9. Let t be a linear term in T (F , X ). Prove that the set G(t) of ground instances of term t is recognizable. Let R be a finite set of linear terms in T (F , X ). Prove that the set G(R) of ground instances of set R is recognizable.

Exercise 1.10. * Let R be a finite set of linear terms in T (F , X ). We define the set Red(R) of reducible terms for R to be the set of ground terms which have a ground instance of some term in R as a subterm.

1. Prove that the set Red(R) is recognizable.

2. Prove that the number of states of a DFTA recognizing Red(R) can be at least 2 n-1 where n is the size (number of nodes) of R. Hint: Consider the set reduced to the pattern h(f

(x1, f (x2, f (x3), . . . , (f (xp-1, f (a, xp) • • • ).
3. Let us now suppose that R is a finite set of ground terms. Prove that we can construct a DFTA recognizing Red(R) whose number of states is at most n + 2 where n is the number of different subterms of R.

Exercise 1.11. * Let R be a finite set of linear terms in T (F , X ). A term t is inductively reducible for R if all the ground instances of term t are reducible for R.

Prove that inductive reducibility of a linear term t for a set of linear terms R is decidable.

Exercise 1.12. * We consider the following decision problem:

Instance t a term in T (F , X ) and A a NFTA Answer "yes" if and only if at least one ground instance of t is accepted by A.

1. Let us first suppose that t is linear; prove that the property is P .

Hint: a NFTA for the set of ground instances of t can ce computed polynomially (see Exercise 1.9

2. Let us now suppose that t is non linear but that A is deterministic.

(a) Prove that the property is NP. Hint: we just have to guess a substitution of the variables of t by states.

(b) Prove that the property is NP-hard.

Hint: just consider a term t which represents a boolean formula and A a DFTA which accepts valid formulas.

3. Let us now suppose that t is non linear and that A is non deterministic.

Prove that the property is EXP T IM E-complete.

Hint: use the EXPTIME-hardness of intersection non-emptiness.

Exercise 1.13. * We consider the following two problems. First, given as instance a recognizable tree language L and a tree homomorphism h, is the set h(L) recognizable? Second, given as instance a set R of terms in T (F , X ), is the set Red(R) recognizable? Prove that if the first problem is decidable, the second problem is easily shown decidable.

Exercise 1.14. Let F = {f (, ), a, b}.

1. Let us consider the set of ground terms L1 defined by the following two conditions:

• f (a, b) ∈ L1, • t ∈ L1 ⇒ f (a, f (t, b)) ∈ L1.
Prove that the set L1 is recognizable. 3. Let L be a recognizable tree language over F . Let us suppose that f is a commutative symbol. Let C(L) be the congruence closure of set L for the set of equations C = {f (x, y) = f (y, x)}. Prove that C(L) is recognizable.

4. Let L be a recognizable tree language over F . Let us suppose that f is a commutative and associative symbol. Let AC(L) be the congruence closure of set L for the set of equations

AC = {f (x, y) = f (y, x); f (x, f (y, z)) = f (f (x, y), z)}.
Prove that in general AC(L) is not recognizable.

5. Let L be a recognizable tree language over F . Let us suppose that f is an associative symbol. Let A(L) be the congruence closure of set L for the set of equations

A = {f (x, f (y, z)) = f (f (x, y), z)}. Prove that in general A(L) is not recognizable.
Exercise 1.15. * Consider the complement problem:

• Instance A term t ∈ T (F , X ) and terms t1, . . . , tn,

• Question There is a ground instance of t which is not an instance of any ti.

Prove that the complement problem is decidable whenever term t and all terms ti are linear. Extend the proof to handle the case where t is a term (not necessarily linear).

Exercise 1.16. * Let F be a ranked alphabet and suppose that F contains some symbols which are commutative and associative. The set of ground AC-instances of a term t is the AC-congruence closure of set G(t). Prove that the set of ground ACinstances of a linear term is recognizable. The reader should note that the set of ground AC-instances of a set of linear terms is not recognizable (see Exercice 1.14).

Prove that the AC-complement problem is decidable where the AC-complement problem is defined by:

• Instance A linear term t ∈ T (F , X ) and linear terms t1, . . . , tn,

• Question There is a ground AC-instance of t which is not an AC-instance of any ti.

Exercise 1.17. * Let F be a ranked alphabet and X be a countable set of variables.

Let S be a rewrite system on T (F , X ) (the reader is referred to [START_REF] Dershowitz | Handbook of Theoretical Computer Science, volume B, chapter Rewrite Systems[END_REF]) and L be a set of ground terms. We denote by S * (L) the set of reductions of terms in L by S and by S(L) the set of ground S-normal forms of set L. Formally,

S * (L) = {t ∈ T (F ) | ∃u ∈ L u * → t}, S(L) = {t ∈ T (F ) | t ∈ IRR(S) and ∃u ∈ L u * → t} = IRR(S) ∩ S * (L)
where IRR(S) denotes the set of ground irreducible terms for S. We consider the two following decision problems:

(1rst order reachability)

• Instance A rewrite system S, two ground terms u and v,

• Question v ∈ S * ({u}).

(2nd order reachability)

• Instance A rewrite system S, two recognizable tree languages L and L ′ ,

• Question S * (L) ⊆ L ′ .
1. Let us suppose that rewrite system S satisfies:

(PreservRec) If L is recognizable, then S * (L) is recognizable.
What can be said about the two reachability decision problems? Give a sufficient condition on rewrite system S satisfying (PreservRec) such that S satisfies (NormalFormRec) where (NormalFormRec) is defined by:

(NormalFormRec) If L is recognizable, then S(L) is recognizable. 2. Let F = {f (, ), g(), h(), a}. Let L = {f (t1, t2) | t1, t2 ∈ T ({g(), h(),
a}}, and S is the following set of rewrite rules:

{ f (g(x), h(y)) → f (x, y) f (h(x), g(y)) → f (x, y) g(h(x)) → x h(g(x)) → x f (a, x) → x f (x, a) → x }
Are the sets L, S * (L), and S(L) recognizable?

3. Let F = {f (, ), g(), h(), a}. Let L = {g(h n (a)) | n ≥ 0}, and S is the following set of rewrite rules:

{ g(x) → f (x, x) }
Are the sets L, S * (L), and S(L) recognizable?

4. Let us suppose now that rewrite system S is linear and monadic, i.e. all rewrite rules are of one of the following three types:

(1) l → a , a ∈ F0 (2) l → x , x ∈ Var (l) (3) l → f (x1, . . . , xp) , x1, . . . , xp ∈ Var (l), f ∈ Fp
where l is a linear term (no variable occurs more than once in t) whose height is greater than 1. Prove that a linear and monadic rewrite system satisfies (PreservRec). Prove that (PreservRec) is false if the right-hand side of rules of type (3) may be non linear.

Exercise 1.18. Design a linear-time algorithm for testing emptiness of the language recognized by a tree automaton:

Instance A tree automaton
Answer "yes" if and only if the language recognized is empty.

Hint: Choose a suitable data structure for the automaton. For example, a state could be associated with the list of the "adresses" of the rules whose left-hand side contain it (eventually, a rule can be repeated); each rule could be just represented by a counter initialized at the arity of the corresponding symbol and by the state of the right-hand side. Activating a state will decrement the counters of the corresponding rules. When the counter of a rule becomes null, the rule can be applied: the right-hand side state can be activated.

Exercise 1.19. The Solvable Path Problem is the following:

Instance a finite set X and three sets R ⊂ X × X × X, Xs ⊂ X and Xt ⊂ X.

Answer "yes" if and only if Xt ∩ A is non empty, where A is the least subset of X such that Xs ⊂ A and if y, z ∈ A and (x, y, z) ∈ R, then x ∈ A.

Prove that this Pcomplete problem is log-space reducible to the emptiness problem for tree automata.

Exercise 1.20. A flat automaton is a tree automaton which has the following property: there is an ordering ≥ on the states and a particular state q ⊤ such that the transition rules have one of the following forms:

1. f (q ⊤ , . . . , q ⊤ ) → q ⊤ 2. f (q1, . . . , qn) → q with q > qi for every i 3. f (q ⊤ , . . . , q ⊤ , q, q ⊤ , . . . , q ⊤ ) → q Moreover, we assume that all terms are accepted in the state q ⊤ . (The automaton is called flat because there are no "nested loop").

Prove that the intersection of two flat automata is a finite union of automata whose size is linear in the sum of the original automata. (This contrasts with the construction of Theorem 1.3.1 in which the intersection automaton's size is the product of the sizes of its components).

Deduce from the above result that the intersection non-emptiness problem for flat automata is in NP (compare with Theorem 1.7.5).

Bibliographic Notes

Tree automata were introduced by Doner [Don65, Don70] and Thatcher and Wright [START_REF] Thatcher | Generalized finite automata[END_REF][START_REF] Thatcher | Generalized finite automata with an application to a decision problem of second-order logic[END_REF]. Their goal was to prove the decidability of the weak second order theory of multiple successors. The original definitions are based on the algebraic approach and involve heavy use of universal algebra and/or category theory.

Many of the basic results presented in this chapter are the straightforward generalization of the corresponding results for finite automata. It is difficult to attribute a particular result to any one paper. Thus, we only give a list of some important contributions consisting of the above mentioned papers of Doner, Thatcher and Wright and also Eilenberg and Wright [START_REF] Eilenberg | Automata in general algebras[END_REF], Thatcher [START_REF] Thatcher | Generalized sequential machines[END_REF], Brainerd [START_REF] Brainerd | The minimalization of tree automata[END_REF][START_REF] Brainerd | Tree generating regular systems[END_REF], Arbib and Give'on [START_REF] Arbib | Algebra automata I: Parallel programming as a prolegomena to the categorical approach[END_REF]. All the results of this chapter and a more complete and detailed list of references can be found in the textbook of Gécseg and Steinby [START_REF] Gécseg | Tree Automata[END_REF] and their survey [START_REF] Gécseg | Tree languages[END_REF]. For an overview of the notion of recognizability in general algebraic structures see Courcelle [START_REF] Courcelle | On Recognizable Sets and Tree Automata, chapter Resolution of Equations in Algebraic Structures[END_REF] and the fundamental paper of Mezei and Wright [START_REF] Mezei | Algebraic automata and context-free sets[END_REF]. In Nivat and Podelski [START_REF] Nivat | Resolution of Equations in Algebraic Structures, volume 1, chapter Tree monoids and recognizable sets of finite trees[END_REF] and [START_REF] Podelski | A monoid approach to tree automata[END_REF], the theory of recognizable tree languages is reduced to the theory of recognizable sets in an infinitely generated free monoid.

The results of Sections 1.1, 1.2, and 1.3 were noted in many of the papers mentioned above, but, in this textbook, we present these results in the style of the undergraduate textbook on finite automata by Hopcroft and Ullman [START_REF] Hopcroft | Introduction to Automata Theory, Languages, and Computation[END_REF]. Tree homomorphisms were defined as a special case of tree transducers, see Thatcher [START_REF] Thatcher | Tree automata: an informal survey[END_REF]. The reader is referred to the bibliographic notes in Chapter 6 of the present textbook for detailed references. The reader should note that our proof of preservation of recognizability by tree homomorphisms and inverse tree homomorphisms is a direct construction using FTA. A more classical proof can be found in [START_REF] Gécseg | Tree Automata[END_REF] and uses regular tree grammars (see Chapter 2).

Minimal tree recognizers and Nerode's congruence appear in Brainerd [START_REF] Brainerd | The minimalization of tree automata[END_REF][START_REF] Brainerd | Tree generating regular systems[END_REF], Arbib and Give'on [START_REF] Arbib | Algebra automata I: Parallel programming as a prolegomena to the categorical approach[END_REF], and Eilenberg and Wright [START_REF] Eilenberg | Automata in general algebras[END_REF]. The proof we presented here is by Kozen [START_REF] Kozen | On the Myhill-Nerode theorem for trees[END_REF] (see also Fülöp and Vágvölgyi [FV89]). Top-down tree automata were first defined by Rabin [START_REF] Rabin | Decidability of Second-Order Theories and Automata on Infinite Trees[END_REF]. Deterministic top-down tree automata define the class of path-closed tree languages (see Exercice 1.6). An alternative definition of deterministic top-down tree automata was given in [START_REF] Nivat | Minimal ascending and descending tree automata[END_REF] leading to "homogeneous" tree languages, also a minimization algorithm was given. Residual finite automata were defined in [CGL + 03] via bottom-up or top-down congruence closure. Residual finite automata have a canonical form even in the non deterministic case. Some results of Sections 1.7 are "folklore" results. Complexity results for the membership problem and the uniform membership problem could be found in [START_REF] Lohrey | On the parallel complexity of tree automata[END_REF]. Other interesting complexity results for tree automata can be found in Seidl [START_REF] Seidl | Deciding equivalence of finite tree automata[END_REF], [START_REF] Seidl | Deciding equivalence of finite tree automata[END_REF]. The EXPTIME-hardness of the problem of intersection non-emptiness is often used; this problem is close to problems of type inference and an idea of the proof can be found in [START_REF] Frühwirth | Logic programs as types for logic programs[END_REF]. A proof for deterministic top-down automata can be found in [START_REF] Seidl | Haskell overloading is DEXPTIME-complete[END_REF]. A detailed proof in the deterministic bottom-up case as well as some other complexity results are in [START_REF] Veanes | On computational complexity of basic decision problems of finite tree automata[END_REF], [START_REF] Veanes | On simultaneous rigid E-unification[END_REF].

Numerous exercises of the present chapter illustrate applications of tree automata theory to automated deduction and to the theory of rewriting systems. These applications are studied in more details in Section 3.4. Results about tree automata and rewrite systems are collected in Gilleron and Tison [START_REF] Gilleron | Regular tree languages and rewrite systems[END_REF]. Let S be a term rewrite system (see for example Dershowitz and Jouannaud [START_REF] Dershowitz | Handbook of Theoretical Computer Science, volume B, chapter Rewrite Systems[END_REF] for a survey on rewrite systems), if S is left-linear the set IRR(S) of irreducible ground terms w.r.t. S is a recognizable tree language. This result first appears in Gallier and Book [START_REF] Gallier | Reductions in tree replacement systems[END_REF] and is the subject of Exercise 1.10. However not every recognizable tree language is the set of irreducible terms w.r.t. a rewrite system S (see Fülöp and Vágvölgyi [FV88]). It was proved that the problem whether, given a rewrite system S as instance, the set of irreducible terms is recognizable is decidable (Kucherov [Kuc91]). The problem of preservation of regularity by tree homomorphisms is not known decidable. Exercise 1.13 shows connections between preservation of regularity for tree homomorphisms and recognizability of sets of irreducible terms for rewrite systems.

The notion of inductive reducibility (or ground reducibility) was introduced in automated deduction. A term t is S-inductively (or S-ground) reducible for S if all the ground instances of term t are reducible for S. Inductive reducibility is decidable for a linear term t and a left-linear rewrite system S. This is Exercise 1.11, see also Section 3.4.2. Inductive reducibility is decidable for finite S (see Plaisted [START_REF] Plaisted | Semantic confluence tests and completion method[END_REF]). Complement problems are also introduced in automated deduction. They are the subject of Exercises 1.15 and 1.16. The complement problem for linear terms was proved decidable by Lassez and Marriott [START_REF] Lassez | Explicit representation of terms defined by counter examples[END_REF] and the AC-complement problem by Lugiez and Moysset [START_REF] Lugiez | Tree automata help one to solve equational formulae in ac-theories[END_REF].

The reachability problem is defined in Exercise 1.17. It is well known that this problem is undecidable in general. It is decidable for rewrite systems preserving recognizability, i.e. such that for every recognizable tree language L, the set of reductions of terms in L by S is recognizable. This is true for linear and monadic rewrite systems (right-hand sides have depth less than 1). This result was obtained by K. Salomaa [START_REF] Salomaa | Deterministic tree pushdown automata and monadic tree rewriting systems[END_REF] and is the matter of Exercise 1.17. This is true also for linear and semi-monadic (variables in the right-hand sides have depth at most 1) rewrite systems, Coquidé et al. [START_REF] Coquide | Bottomup tree pushdown automata : Classification and connection with rewrite systems[END_REF]. Other interesting results can be found in [START_REF] Jacquemard | Decidable approximations of term rewriting systems[END_REF] and [START_REF] Nagaya | Decidability for left-linear growing term rewriting systems[END_REF].

Chapter 2 Regular Grammars and Regular Expressions

Tree Grammar

In the previous chapter, we have studied tree languages from the acceptor point of view, using tree automata and defining recognizable languages. In this chapter we study languages from the generative point of view, using regular tree grammars and defining regular tree languages. We shall see that the two notions are equivalent and that many properties and concepts on regular word languages smoothly generalize to regular tree languages, and that algebraic characterizations of regular languages do exist for tree languages. Actually, this is not surprising since tree languages can be seen as word languages on an infinite alphabet of contexts.

Definitions

When we write programs, we often have to know how to produce the elements of the data structures that we use. For instance, a definition of the lists of integers in a functional language like ML is similar to the following definition:

N at = 0 | s(N at) List = nil | cons(N at, List)
This definition is nothing but a tree grammar in disguise, more precisely the set of lists of integers is the tree language generated by the grammar with axiom List, non-terminal symbols List, N at, terminal symbols 0, s, nil, cons and rules

N at → 0 N at → s(N at) List → nil List → cons(N at, List)
Tree grammars are similar to word grammars except that basic objects are trees, therefore terminals and non-terminals may have an arity greater than 0. More precisely, a tree grammar G = (S, N, F, R) is composed of an axiom S, a set N of non-terminal symbols with S ∈ N , a set F of terminal symbols, a set R of production rules of the form α → β where α, β are trees of T (F ∪ N ∪ X ) where X is a set of dummy variables and α contains at least one nonterminal. Moreover we require that F ∩ N = ∅, that each element of N ∪ F has a fixed arity and that the arity of the axiom S is 0. In this chapter, we shall concentrate on regular tree grammars where a regular tree grammar G = (S, N, F, R) is a tree grammar such that all non-terminal symbols have arity 0 and production rules have the form A → β, with A a non-terminal of N and β a tree of T (F ∪ N ).

Example 2.1.1. The grammar G with axiom List, non-terminals List, N at terminals 0, nil, s(), cons(, ), rules

List → nil List → cons(N at, List) N at → 0 N at → s(N at)
is a regular tree grammar.

A tree grammar is used to build terms from the axiom, using the corresponding derivation relation. Basically the idea is to replace a non-terminal A by the right-hand side α of a rule A → α. More precisely, given a regular tree grammar G = (S, N, F, R), the derivation relation → G associated to G is a relation on pairs of terms of T (F ∪ N ) such that s → G t if and only if there are a rule

A → α ∈ R and a context C such that s = C[A] and t = C[α].
The language generated by G, denoted by L(G), is the set of terms of T (F) which can be reached by successive derivations starting from the axiom, i.e. L(G) = {s ∈ T F | S + → G s} with + → the transitive closure of → G . We write → instead of → G when the grammar G is clear from the context. A regular tree language is a language generated by a regular tree grammar.

Example 2.1.2. Let G be the grammar of the previous example, then a derivation of cons(s(0), nil) from List is

List → G cons(N at, List) → G cons(s(N at), List) → G cons(s(N at), nil) → G cons(s(0), nil)
and the language generated by G is the set of lists of non-negative integers.

From the example, we can see that trees are generated top-down by replacing a leaf by some other term. When A is a non-terminal of a regular tree grammar G, we denote by L G (A) the language generated by the grammar G ′ identical to G but with A as axiom. When there is no ambiguity on the grammar referred to, we drop the subscript G. We say that two grammars G and G ′ are equivalent when they generate the same language. Grammars can contain useless rules or non-terminals and we want to get rid of these while preserving the generated language. A non-terminal is reachable if there is a derivation from the axiom containing this non-terminal. A non-terminal A is productive if L G (A) is nonempty. A regular tree grammar is reduced if and only if all its non-terminals are reachable and productive. We have the following result: Proposition 2.1.3. Each regular tree grammar is equivalent to a reduced regular tree grammar.

Proof. Given a grammar G = (S, N, F, R), we can compute the set of reachable non-terminals and the set of productive non-terminals using the sequences (Reach) n and (P rod) n which are defined in the following way.

P rod 0 = ∅ P rod n = P rod n-1 ∪ {A ∈ N | ∃(A → α) ∈ R s.t. each non-terminal of α is in P rod n-1 } Reach 0 = {S} Reach n = Reach n-1 ∪ {A ∈ N | ∃(A ′ → α) ∈ R s.t.
A ′ ∈ Reach n-1 and A occurs in α}

For each sequence, there is an index such that all elements of the sequence with greater index are identical and this element is the set of productive (resp. reachable) non-terminals of G. Each regular tree grammar is equivalent to a reduced tree grammar which is computed by the following cleaning algorithm.

Computation of an equivalent reduced grammar input: a regular tree grammar G = (S, N, F, R).

1. Compute the set of productive non-terminals N P rod = n≥0 P rod n for G and let G ′ = (S, N P rod , F, R ′ ) where R ′ is the subset of R involving rules containing only productive non-terminals.

2. Compute the set of reachable non-terminals N Reach = n≥0 Reach n for G ′ (not G) and let G ′′ = (S, N Reach , F, R ′′ ) where R ′′ is the subset of R ′ involving rules containing only reachable non-terminals.

output: G ′′

The equivalence of G, G ′ and G ′′ is left to the reader. Moreover each nonterminal A of G ′′ must appear in a derivation S *

→ G ′′ C[A] * → G ′′ C[s]
which proves that G ′′ is reduced. The reader should notice that exchanging the two steps of the computation may result in a grammar which is not reduced (see Exercise 2.3).

Actually, we shall use even simpler grammars, i.e. normalized regular tree grammar, where the production rules have the form A → f (A 1 , . . . , A n ) or A → a where f, a are symbols of F and A, A 1 , . . . , A n are non-terminals. The following result shows that this is not a restriction. Proposition 2.1.4. Each regular tree grammar is equivalent to a normalized regular tree grammar.

Proof. Replace a rule

A → f (s 1 , . . . , s n ) by A → f (A 1 , . . . , A n ) with A i = s i if s i ∈ N otherwise A i is a new non-terminal.
In the last case add the rule A i → s i . Iterate this process until one gets a (necessarily equivalent) grammar with rules of the form A → f (A 1 , . . . , A n ) or A → a or A 1 → A 2 . The last rules are replaced by the rules A 1 → α for all α ∈ N such that A 1 + → A i and A i → α ∈ R (these A ′ i s are easily computed using a transitive closure algorithm).

From now on, we assume that all grammars are normalized, unless this is stated otherwise explicitly.

Regularity and Recognizabilty

Given some normalized regular tree grammar G = (S, N, F, R G ), we show how to build a top-down tree automaton which recognizes L(G). We define A = (Q, F, I, ∆) by

• Q = {q A | A ∈ N } • I = {q S } • q A (f (x 1 , . . . , x n )) → f (q A1 (x 1 ), . . . , q An (x n )) ∈ ∆ if and only if A → f (A 1 , . . . , A n ) ∈ R G .
A standard proof by induction on derivation length yields L(G) = L(A). Therefore we have proved that the languages generated by regular tree grammar are recognizable languages. The next question to ask is whether recognizable tree languages can be generated by regular tree grammars. If L is a regular tree language, there exists a top-down tree automata A = (Q, F, I, ∆) such that L = L(A). We define G = (S, N, F, R G ) with S a new symbol, N = {A q | q ∈ Q}, R G = {A q → f (A q1 , . . . , A qn ) | q(f (x 1 , . . . , x n )) → f (q 1 (x 1 ), . . . , q n (x n )) ∈ R} ∪ {S → A I | A I ∈ I}. A standard proof by induction on derivation length yields L(G) = L(A).

Combining these two properties, we get the equivalence between recognizability and regularity.

Theorem 2.1.5. A tree language is recognizable if and only if it is a regular tree language.

Regular Expressions. Kleene's Theorem for Tree Languages

Going back to our example of lists of non-negative integers, we can write the sets defined by the non-terminals N at and List as follows.

N at = {0, s(0), s(s(0)), . . .} List = {nil, cons( , nil), cons( , cons( , nil)), . . .}

where stands for any element of N at. There is some regularity in each set which reminds of the regularity obtained with regular word expressions constructed with the union, concatenation and iteration operators. Therefore we can try to use the same idea to denote the sets N at and List. However, since we are dealing with trees and not words, we must put some information to indicate where concatenation and iteration must take place. This is done by using a new symbol which behaves as a constant. Moreover, since we have two independent iterations, the first one for N at and the second one for List, we shall use two different new symbols P 1 and P 2 and a natural extension of regular word expressions leads us to denote the sets N at and List as follows.

N at = s(P 1 ) * ,21 . 21 0 List = nil + cons( (s(P 1 ) * ,21 . 21 0) , P 2 ) * ,22 . 22 nil

Actually the first term nil in the second equality is redundant and a shorter (but slightly less natural) expression yields the same language.

We are going to show that this is a general phenomenon and that we can define a notion of regular expressions for trees and that Kleene's theorem for words can be generalized to trees. Like in the example, we must introduce a particular set of constants K which are used to indicate the positions where concatenation and iteration take place in trees. This explains why the syntax of regular tree expressions is more cumbersome than the syntax of word regular expressions. These new constants are usually denoted by P 1 , P 2 , . . . Therefore, in this section, we consider trees constructed on F ∪K where K is a distinguished finite set of symbols of arity 0 disjoint from F.

Substitution and Iteration

First, we have to generalize the notion of substitution to languages, replacing some P i by a tree of some language L i . The main difference with term substitution is that different occurrences of the same constant P i can be replaced by different terms of L i . Given a tree t of T (F ∪ K), P 1 , . . . , P n symbols of K and L 1 , . . . , L n languages of T (F ∪ K), the tree substitution (substitution for short) of P 1 , . . . , P n by L 1 , . . . , L n in t, denoted by t{P 1 ←L 1 , . . . , P n ←L n }, is the tree language defined by the following identities.

• P i {P 1 ←L 1 , . . . , P n ←L n } = L i for i = 1, . . . , n,

• a{P 1 ←L 1 , . . . , P n ←L n } = {a} for all a ∈ F ∪ K such that arity of a is 0 and a = P 1 , . . . , a = P n ,

• f (s 1 , . . . , s n ){P 1 ←L 1 , . . . , P n ←L n } = {f (t 1 , . . . , t n ) | t i ∈ s i {P 1 ←L 1 , . . . , P n ←L n }} Example 2.2.1. Let F = {0, nil, s(), cons(, )} and K = {P 1 , P 2 }, let t = cons(P 1 , cons(P 1 , P 2 ))
and let L 1 = {0, s(0)} then t{P 1 ←L} = {cons(0, cons(0, P 2 )), cons(0, cons(s(0), P 2 )), cons(s(0), cons(0, P 2 )), cons(s(0), cons(s(0), P 2 ))} Symbols of K are mainly used to distinguish places where the substitution must take place, and they are usually not relevant. For instance, if t is a tree on the alphabet F ∪ {P} and L be a language of trees on the alphabet F, then the trees of t{P ← L} don't contain the symbol P.

The substitution operation generalizes to languages in a straightforward way. When L, L 1 , . . . , L n are languages of T (F ∪ K) and P 1 , . . . , P n are elements of K, we define L{P 1 ← L 1 , . . . , P n ← L n } to be the set t∈L { t{P 1 ← L 1 , . . . , P n ← L n }}. Now, we can define the concatenation operation for tree languages. Given L and M two languages of T F ∪K , and P be an element of K, the concatenation of M to L through P, denoted by L . 2 M , is the set of trees obtained by substituting the occurrence of P in trees of L by trees of M , i.e. L . 2 M = t∈L {t{P←M }}.

To define the closure of a language, we must define the sequence of successive iterations. Given L a language of T (F ∪K) and P an element of K, the sequence L n,2 is defined by the equalities.

• L 0, 2 = {P} • L n+1, 2 = L n, 2 ∪ L . 2 L n, 2
The closure L * ,2 of L is the union of all L n, 2 for non-negative n, i.e., L * ,2 = ∪ n≥0 L n,2 . From the definition, one gets that {P} ⊆ L * ,2 for any L.

Example 2.2.2. Let F = {0, nil, s(), cons(, )}, let L = {0, cons(0, P)} and M = {nil, cons(s(0), P)}, then L . 2 M = {0, cons(0, nil), cons(0, cons(s(0), P))} L * ,2 = {P}∪ {0, cons(0, P)}∪ {0, cons(0, P), cons(0, cons(0, P))} ∪ . . .

We prove now that the substitution and concatenation operations yield regular languages when they are applied to regular languages.

Proposition 2.2.3. Let L be a regular tree language on F ∪K, let L 1 , . . . , L n be regular tree languages on F ∪ K, let P 1 , . . . , P n ∈ K, then L{P 1 ←L 1 , . . . , P n ← L n } is a regular tree language.

Proof. Since L is regular, there exists some normalized regular tree grammar G = (S, N, F ∪ K, R) such that L = L(G), and for each i = 1, . . . , n there exists a normalized grammar

G i = (S i , N i , F ∪ K, R i ) such that L i = L(G i ).
We can assume that the sets of non-terminals are pairwise disjoint. The idea of the proof is to construct a grammar G ′ which starts by generating trees like G but replaces the generation of a symbol P i by the generation of a tree of L i via a branching towards the axiom of G i . More precisely, we show that

L{P 1 ←L 1 , . . . , P n ←L n } = L(G ′ ) where G ′ = (S, N ′ , F ∪ K, R ′ ) such that • N ′ = N ∪ N 1 ∪ . . . ∪ N n ,
• R ′ contains the rules of R i and the rules of R but the rules A → P i which are replaced by the rules A → S i , where S i is the axiom of L i .

A straightforward induction on the height of trees proves that G ′ generates each tree of L{P 1 ←L 1 , . . . , P n ←L n }.

The converse is to prove that L(G ′ ) ⊆ L{P 1 ← L 1 , . . . , P n ← L n }. This is achieved by proving the following property by induction on the derivation length. A + → s ′ where s ′ ∈ T (F ∪ K) using the rules of G ′ if and only if there is some s such that A + → s using the rules of G and s ′ ∈ s{P 1 ←L 1 , . . . , P n ←L n }.

• base case: A → s in one step. Therefore this derivation is a derivation of the grammar G and no P i occurs in s, yielding s ∈ L{P 1 ←L 1 , . . . , P n ← L n }

• induction step: we assume that the property is true for any terminal and derivation of length less than n. Let A be such that A → s ′ in n steps. This derivation can be decomposed as A → s 1 + → s ′ . We distinguish several cases depending on the rule used in the derivation A → s 1 .

-the rule is A → f (A 1 , . . . , A m ), therefore s ′ = f (t 1 , . . . , t m ) and t i ∈ L(A i ){P 1 ← L 1 , . . . , P n ← L n }, therefore s ′ ∈ L(A){P 1 ← L 1 , . . . , P n ← L n }, -the rule is A → S i , therefore A → P i ∈ R and s ′ ∈ L i and s ′ ∈ L(A){P 1 ←L 1 , . . . , P n ←L n }.
the rule A → a with a ∈ F, a of arity 0, a = P 1 , . . . , a = P n are not considered since no further derivation can be done.

The following proposition states that regular languages are stable also under closure.

Proposition 2.2.4. Let L be a regular tree language of T (F ∪ K), let P ∈ K, then L * ,2 is a regular tree language of T (F ∪ K).

Proof. There exists a normalized regular grammar G = (S, N, F ∪ K, R) such that L = L(G) and we obtain from G a grammar G ′ = (S ′ , N ∪ {S ′ }, F ∪ K, R ′ ) for L * ,2 by replacing rules leading to P such as A → P by rules A → S ′ leading to the (new) axiom. Moreover we add the rule S ′ → P to generate {P} = L 0,2 and the rule S ′ → S to generate L i,2 for i > 0. By construction G ′ generates the elements of L * ,2 .

Conversely a proof by induction on the length on the derivation proves that L(G ′ ) ⊆ L * ,2 .

Regular Expressions and Regular Tree Languages

Now, we can define regular tree expression in the flavor of regular word expression using the +, . 2 , * ,2 operators. Definition 2.2.5. The set Regexp(F, K) of regular tree expressions on F and K is the smallest set such that:

• the empty set ∅ is in Regexp(F, K) • if a ∈ F 0 ∪ K is a constant, then a ∈ Regexp(F, K),
• if f ∈ F n has arity n > 0 and E 1 , . . . , E n are regular expressions of Regexp(F, K) then f (E 1 , . . . , E n ) is a regular expression of Regexp(F, K),

• if E 1 , E 2 are regular expressions of Regexp(F, K) then (E 1 + E 2 ) is a regular expression of Regexp(F, K),

• if E 1 , E 2 are regular expressions of Regexp(F, K) and P is an element of

K then E 1 . 2 E 2 is a regular expression of Regexp(F, K),
• if E is a regular expression of Regexp(F, K) and P is an element of K then E * ,2 is a regular expression of Regexp(F, K).

Each regular expression E represents a set of terms of T (F ∪ K) which we denote [[E]] and which is formally defined by the following equalities.

• [[∅]] = ∅, • [[a]] = {a} for a ∈ F 0 ∪ K, • [[f (E 1 , . . . , E n )]] = {f (s 1 , . . . , s n ) | s 1 ∈ [[E 1 ]], . . . , s n ∈ [[E n ]]}, • [[E 1 + E 2 ]] = [[E 1 ]] ∪ [[E 2 ]], • [[E 1 . 2 E 2 ]] = [[E 1 ]]{P←[[E 2 ]]}, • [[E * ,2 ]] = [[E]] * ,2
Example 2.2.6. Let F = {0, nil, s(), cons(, )} and P ∈ K then (cons(0, P) * ,2 ). 2 nil is a regular expression of Regexp(F, K) which denotes the set of lists of zeros: {nil, cons(0, nil), cons(0, cons(0, nil)), . . .}

In the remainder of this section, we compare the relative expressive power of regular expressions and regular languages. It is easy to prove that for each regular expression E, the set [[E]] is a regular tree language. The proof is done by structural induction on E. The first three cases are obvious and the two last cases are consequences of Propositions 2.2.4 and 2.2.3. The converse, i.e. a regular tree language can be denoted by a regular expression, is more involved and the proof is similar to the proof of Kleene's theorem for word languages. Let us state the result first.

Proposition 2.2.7. Let A = (Q, F, Q F , ∆) be a bottom-up tree automaton, then there exists a regular expression

E of Regexp(F, Q) such that L(A) = [[E]].
The occurrence of symbols of Q in the regular expression denoting L(A) doesn't cause any trouble since a regular expression of Regexp(F, Q) can denote a language of T F .

Proof. The proof is similar to the proof for word languages and word automata. For each 1 ≤ i, j, ≤ |Q|, K ⊆ Q, we define the set T (i, j, K) as the set of trees t of T (F ∪ K) such that there is a run r of A on t satisfying the following properties:

• r(ǫ) = q i , • r(p) ∈ {q 1 , . . . , q j } for all p = ǫ labelled by a function symbol.

Roughly speaking, a term is in T (i, j, K) if we can reach q i at the root by using only states in {q 1 , . . . , q j } when we assume that the leaves are states of K. By definition, L(A), the language accepted by A, is the union of the T (i, |Q|, ∅)'s for i such that q i is a final state: these terms are the terms of T (F) such that there is a successful run using any possible state of Q. Now, we prove by induction on j that T (i, j, K) can be denoted by a regular expression of Regexp(F, Q).

• Base case j = 0. The set T (i, 0, K) is the set of trees t where the root is labelled by q i , the leaves are in F ∪ K and no internal node is labelled by some q. Therefore there exist a 1 , . . . , a n , a ∈ F ∪ K such that t = f (a 1 , . . . , a n ) or t = a, hence T (i, 0, K) is finite and can be denoted by a regular expression of Regexp(F ∪ Q).

• Induction case. Let us assume that for any i ′ , K ′ ⊆ Q and 0 ≤ j ′ < j, the set T (i ′ , j ′ , K ′ ) can be denoted by a regular expression. We can write the following equality:

T (i, j, K) = T (i, j -1, K) ∪ T (i, j -1, K ∪ {qj})
.qj T (j, j -1, K ∪ {qj}) * ,q j .qj T (j, j -1, K)

The inclusion of T (i, j, K) in the right-hand side of the equality can be easily seen from Figure 2.2.2.

The converse inclusion is also not difficult. By definition:

T (i, j -1, K) ⊆ T (i, j, K)
and an easy proof by induction on the number of occurrences of q j yields:

T (i, j -1, K ∪ {qj}) .qj T (j, j -1, K ∪ {qj}) * ,q j .qj T (j, j -1, K) ⊆ T (i, j, K)
By induction hypothesis, each set of the right-hand side of the equality defining T (i, j, K) can be denoted by a regular expression of Regex(F ∪Q). This yields the desired result because the union of these sets is represented by the sum of the corresponding expressions.

Since we have already seen that regular expressions denote recognizable tree languages and that recognizable languages are regular, we can state Kleene's theorem for tree languages.

Theorem 2.2.8. A tree language is recognizable if and only if it can be denoted by a regular tree expression. q j q j q j T (j, j -1, K ∪ {q j }) * ,q j .q j T (j, j -1, K) q i q j q j T (j, j -1, K) T (j, j -1, K ∪ {q j }) * ,q j .q j T (j, j -1, K) T (j, j -1, K) q j Figure 2.1: Decomposition of a term of T (i, j, K)

Regular Equations

Looking at our example of the set of lists of non-negative integers, we can realize that these lists can be defined by equations instead of grammar rules. For instance, denoting set union by +, we could replace the grammar given in Section 2.1.1 by the following equations.

N at = 0 + s(N at) List = nil + cons(N at, List)
where the variables are List and N at. To get the usual lists of non-negative numbers, we must restrict ourselves to the least fixed-point solution of this set of equations. Systems of language equations do not always have a solution nor does a least solution always exists. Therefore we shall study regular equation systems defined as follows.

Definition 2.3.1. Let X 1 , . . . , X n be variables denoting sets of trees, for 1 ≤ j ≤ p, 1 ≤ i ≤ m j , let s j i be a term over F ∪ {X 1 , . . . , X n }, then a regular equation system S is a set of equations of the form:

X 1 = s 1 1 + . . . + s 1 m1 . . . X p = s p 1 + . . . + s p mp A solution of S is any n-tuple (L 1 , . . . , L n ) of languages of T (F) such that L 1 = s 1 1 {X 1 ←L 1 , . . . , X n ←L n } ∪ . . . ∪ s 1 m1 {X 1 ←L 1 , . . . , X n ←L n } . . . L p = s p 1 {X 1 ←L 1 , . . . , X n ←L n } ∪ . . . ∪ s p mp {X 1 ←L 1 , . . . , X n ←L n }
Since equations with the same left-hand side can be merged into one equation, and since we can add equations X k = X k without changing the set of solutions of a system, we assume in the following that p = n.

The ordering ⊆ is defined on

T (F) n by (L 1 , . . . , L n ) ⊆ (L ′ 1 , . . . , L ′ n ) iff L i ⊆ L ′
i for all i = 1, . . . , n By definition (∅, . . . , ∅) is the smallest element of ⊆ and each increasing sequence has an upper bound. To a system of equations, we associate the fixedpoint operator T S : T (F) n → T (F) n defined by:

T S(L 1 , . . . , L n ) = (L ′ 1 , . . . , L ′ n )
where

L ′ 1 = L 1 ∪ s 1 1 {X 1 ←L 1 , . . . , X n ←L n } ∪ . . . ∪ s 1 m1 {X 1 ←L 1 , . . . , X n ←L n } . . . L ′ n = L n ∪ s n 1 {X 1 ←L 1 , . . . , X n ←L n } ∪ . . . ∪ s n mn {X 1 ←L 1 , . . . , X n ←L n } Example 2.3.2. Let S be N at = 0 + s(N at) List = nil + cons(N at, List) then T S(∅, ∅) = ({0}, {nil}) T S 2 (∅, ∅) = ({0, s(0)}, {nil, cons(0, nil)})
Using a classical approach we use the fixed-point operator to compute the least fixed-point solution of a system of equations.

Proposition 2.3.3. The fixed-point operator T S is continuous and its least fixed-point T S ω (∅, . . . , ∅) is the least solution of S.

Proof. We show that T S is continuous in order to use Knaster-Tarski's theorem on continuous operators. By construction, T S is monotonous, and the last point is to prove that if S 1 ⊆ S 2 ⊆ . . . is an increasing sequence of n-tuples of languages, the equality T S( i≥1 S i ) = i≥1 T S(S i ) holds. By definition, each S i can be written as (S i 1 , . . . , S i n ).

• We have that i≥1 T S(S i ) ⊆ T S i≥1 (S i ) holds since the sequence S 1 ⊆ S 2 ⊆ . . . is increasing and the operator T S is monotonous.

• Conversely we must prove T S( i≥1 S i ) ⊆ i≥1 T S(S i ). Let v = (v 1 , . . . , v n ) ∈ T S( i≥1 S i ). Then for each k = 1, . . . , n ei- ther v k ∈ i≥1 S i hence v k ∈ S l k for some l k , or there is some u = (u 1 , . . . , u n ) ∈ i≥1 S i such that v k = s k j k {X 1 ← u 1 , . . . , X n ← u n }. Since the sequence (S i, i≥1
) is increasing we have that u ∈ S l k for some l k . Therefore v k ∈ T S(S L ) ⊆ i≥1 T S(S i ) for L = max{l k | k = 1, . . . , n}.

We have introduced systems of regular equations to get an algebraic characterization of regular tree languages stated in the following theorem.

Theorem 2.3.4. The least fixed-point solution of a system of regular equations is a tuple of regular tree languages. Conversely each regular tree language is a component of the least solution of a system of regular equations.

Proof. Let S be a system of regular equations. Let

G i = (X i , {X 1 , . . . , X n }, F, R) where R = ∪ k=1,...,n {X k → s 1 k , . . . , X k → s j k k } if the k th equation of S is X k = s 1 k + . . . + s j k k . We show that L(G i ) is the i th component of (L 1 , . . . , L n ) the least fixed-point solution of S.
• We prove that T S p (∅, . . . , ∅) ⊆ (L(G 1 ), . . . , L(G n )) by induction on p.

Let us assume that this property holds for all p ′ ≤ p. Let u = (u 1 , . . . , u n ) be an element of T S p+1 (∅, . . . , ∅) = T S(T S p (∅, . . . , ∅)). For each i in 1, . . . , n, either u i ∈ T S p (∅, . . . , ∅) and u i ∈ L(G i ) by induction hypothesis, or there exist v i = (v i 1 , . . . , v i n ) ∈ T S p (∅, . . . , ∅) and s j i such that

u i = s j i {X 1 → v i 1 , . . . , X n → v i n }. By induction hypothesis v i j ∈ L(G j ) for j = 1, . . . , n therefore u i ∈ L(G i ).
• We prove now that (L(X 1 ), . . . , L(X n )) ⊆ T S ω (∅, . . . , ∅) by induction on derivation length.

Let us assume that for each i = 1, . . . , n, for each

p ′ ≤ p, if X i → p ′ u i then u i ∈ T S p ′ (∅, . . . , ∅). Let X i → p+1 u i , then X i → s j i (X 1 , . . . , X n ) → p v i with u i = s j i (v 1 , . . . , v n
) and X j → p ′ v j for some p ′ ≤ p. By induction hypothesis v j ∈ T S p ′ (∅, . . . , ∅) which yields that u i ∈ T S p+1 (∅, . . . , ∅).

Conversely, given a regular grammar G = (S, {A 1 , . . . , A n }, F, R), with R = {A 1 → s 1 1 , . . . , A 1 → s 1 p1 , . . . , A n → s n 1 , . . . , A n → s n pn }, a similar proof yields that the least solution of the system

A 1 = s 1 1 + . . . + s 1 p1 . . . A n = s n 1 + . . . + s n pn is (L(A 1 ), . . . , L(A n )).
Example 2.3.5. The grammar with axiom List, non-terminals List, N at terminals 0, s(), nil, cons(, ) and rules

List → nil List → cons(N at, List) N at → 0 N at → s(N at)
generates the second component of the least solution of the system given in Example 2.3.2.

Context-free Word Languages and Regular Tree Languages

Context-free word languages and regular tree languages are strongly related. This is not surprising since derivation trees of context-free languages and derivations of tree grammars look alike. For instance let us consider the context-free language of arithmetic expressions on +, * and a variable x. A context-free word grammar generating this set is

E → x | E + E | E * E where E is the axiom.
The generation of a word from the axiom can be described by a derivation tree which has the axiom at the root and where the generated word can be read by picking up the leaves of the tree from the left to the right (computing what we call the yield of the tree). The rules for constructing derivation trees show some regularity, which suggests that this set of trees is regular. The aim of this section is to show that this is true indeed. However, there are some traps which must be avoided when linking tree and word languages. First, we describe how to relate words and trees. The symbols of F are used to build trees but also words (by taking a symbol of F as a letter). The Yield operator computes a word from a tree by concatenating the leaves of the tree from the left to the right. More precisely, it is defined as follows.

Yield (a) = a if a ∈ F 0 Yield (f (s 1 , . . . , s n )) = Yield (s 1 ) . . . Yield (s n ) if f ∈ F n , s i ∈ T (F).
Example 2.4.1. Let F = {x, +, * , E(, , )} and let

s = x * x + x E E then Yield (s) = x * x +
x which is a word on {x, * , +}. Note that * and + are not the usual binary operator but syntactical symbols of arity 0. If

t = x * x E + x E then Yield (t) = x * x + x.
We recall that a context-free!word grammar G is a tuple (S, N, T, R) where S is the axiom, N the set of non-terminal letters, T the set of terminal letters, R the set of production rules of the form A → α with A ∈ N, α ∈ (T ∪N ) * . The usual definition of derivation trees of context free word languages allow nodes labelled by a non-terminal A to have a variable number of sons, which is equal to the length of the right-hand side α of the rule A → α used to build the derivation tree at this node.

Since tree languages are defined for signatures where each symbol has a fixed arity, we introduce a new symbol (A, m) for each A ∈ N such that there is a rule A → α with α of length m. Let G be the set composed of these new symbols and of the symbols of T . The set of derivation trees issued from a ∈ G, denoted by D(G, a) is the smallest set such that: By definition, the language generated by a context-free word grammar G is the set of words computed by applying the Yield operator to derivation trees of G. The next theorem states how context-free word languages and regular tree languages are related.

• D(G, a) = {a} if a ∈ T , • (a, 0)(ǫ) ∈ D(G, a) if a → ǫ ∈ R where ǫ is the empty word, • (a, p)(t 1 , . . . , t p ) ∈ D(G, (a, p)) if t 1 ∈ D(G, a 1 ), . . . , t p ∈ D(G, a p
Theorem 2.4.3. The following statements hold.

1. Let G be a context-free word grammar, then the set of derivation trees of L(G) is a regular tree language.

2. Let L be a regular tree language then Yield (L) is a context-free word language.

3. There exists a regular tree language which is not the set of derivation trees of a context-free language.

Proof. We give the proofs of the three statements.

1. Let G = (S, N, T, R) be a context-free word language. We consider the tree grammar G ′ = (S, N, F, R ′ ) such that

• the axiom and the set of non-terminal symbols of G and G ′ are the same,

• F = T ∪ {ǫ} ∪ {(A, n) | A ∈ N, ∃A → α ∈ R with α of length n}, • if A → ǫ ∈ R then A → (A, 0)(ǫ) ∈ R ′ • if (A → a 1 . . . a p ) ∈ R then A → (A, p)(a 1 , . . . , a p ) ∈ R ′ Then L(G) = {Yield (s) | s ∈ L(G ′ )}.
The proof is a standard induction on derivation length. It is interesting to remark that there may and usually do exist several tree languages (not necessarily regular) such that the corresponding word language obtained via the Yield operator is a given context-free word language.

2. Let G be a normalized tree grammar (S, X, N, R). We build the word context-free grammar

G ′ = (S, X, N, R ′ ) such that a rule X → X 1 . . . X n (resp. X → a) is in R ′ if and only if the rule X → f (X 1 , . . . , X n ) (resp.
X → a) is in R for some f . It is straightforward to prove by induction on the length of derivation that L(G ′ ) = Yield (L(G)).

3. Let G be the regular tree grammar with axiom S, non-terminals S, G 1 , G 2 , terminals s(, ), g(), a, b and rules S → s(G 1 , G 2 ), G 1 → g(a), and G 2 → g(b). The language L(G) consists of the single tree s(g(a), g(b)).

Assume that L(G) is the set of derivation trees of some context-free word grammar. To generate the first node of the tree, one must have a rule S → G G where S is the axiom, and rules G → a, G → b (to get the inner nodes). Therefore the tree S(G(a), G(a)) should be in L(G) which is not the case.

We have shown that the class of derivation tree languages is a strict subset of the class of regular tree languages. It can be shown (see Exercise 2.5) that the class of derivation tree languages is the class of local languages. Moreover, every regular tree language is the image of a local tree language by an alphabetic homomorphism. For instance, on the running example, we can consider the context-free word grammar S → G 1 G 2 where S is the axiom, and rules G 1 → a, G 2 → b. The derivation tree language is the single tree S(G 1 (a), G 2 (b)). Now, L(G) can be obtained by applying the tree homomorphism h determined by h F defined by: h

F (S) = s(x 1 , x 2 ), h F (G 1 ) = g(x 1 ) and h F (G 2 ) = g(x 1 ).
The class of derivation trees of context-free languages is a strict subclass of the class of recognizable tree languages. Sets of derivation trees correspond to local tree languages and the class of recognizable tree languages is the image of the class of local languages by alphabetic homomorphisms (see Exercice 2.5).

Beyond Regular Tree Languages: Contextfree Tree Languages

For word language, the story doesn't end with regular languages but there is a strict hierarchy.

regular ⊂ context-free ⊂ recursively enumerable Recursively enumerable tree languages are languages generated by tree grammars as defined in the beginning of the chapter, and this class is far too general to have good properties. Actually, any Turing machine can be simulated by a one rule rewrite system which shows how powerful tree grammars are (any grammar rule can be seen as a rewrite rule by considering both terminals and non-terminals as syntactical symbols). Therefore, most of the research has been done on context-free tree languages which we describe now.

Context-free Tree Languages

A context-free!tree grammar is a tree grammar G = (S, N, F, R) where the rules have the form X(x 1 , . . . , x n ) → t with t a tree of T (F ∪ N ∪ {x 1 , . . . , x n }), x 1 , . . . , x n ∈ X where X is a set of reserved variables with X ∩ (F ∪ N ) = ∅, X a non-terminal of arity n.

Example 2.5.1. The grammar of axiom Prog, set of non-terminals {Prog, Nat, Fact()}, set of terminals {0, s, if (, ), eq(, ), not(), times(, ), dec()} and rules

Prog → Fact(Nat) Nat → 0 Nat → s(Nat) Fact(x) → if (eq(x, 0), s(0)) Fact(x) → if (not(eq(x, 0)), times(x, Fact(dec(x))))
where X = {x} is a context-free tree grammar. The reader can easily see that the last rule is the classical definition of the factorial function.

The derivation relation associated to a context-free tree grammar G is a generalization of the derivation relation for regular tree grammar. The derivation relation → is a relation on pairs of terms of

T (F ∪ N ) such that s → t iff there is a rule X(x 1 , . . . , x n ) → α ∈ R, a context C such that s = C[X(t 1 , . . . , t n )] and t = C[α{x 1 ← t 1 , . . . , x n ← t n }].
For instance, the previous grammar can yield the sequence of derivations

Prog → Fact(Nat) → Fact(0) → if (eq(0, 0), s(0))
The language generated by G, denoted by L(G) is the set of terms of T (F) which can be reached by successive derivations starting from the axiom. Such languages are called context-free!tree languages. Context-free tree languages are closed under union, concatenation and closure. Like in the word case, one can define pushdown tree automata which recognize exactly the set of context-free tree languages. We discuss only IO and OI grammars and we refer the reader to the bibliographic notes for more information.

IO and OI Tree Grammars

Context-free tree grammars have been extensively studied in connection with the theory of recursive program scheme. A non-terminal F can be seen as a function name and production rules F (x 1 , . . . , x n ) → t define the function. Recursive definitions are allowed since t may contain occurrences of F . Since we know that such recursive definitions may not give the same results depending on the evaluation strategy, IO and OI tree grammars have been introduced to account for such differences.

A context-free grammar is IO (for innermost-outermost) if we restrict legal derivations to derivations where the innermost terminals are derived first. This restriction corresponds to call-by-value evaluation. A context-free grammar is OI (for outermost-innermost) if we restrict legal derivations to derivations where the outermost terminals are derived first. This corresponds to call-byname evaluation. Therefore, given one context-free grammar G, we can define IO-G and OI-G and the next example shows that the languages generated by these grammars may be different.

Example 2.5.2. Let G be the context-free grammar with axiom Exp, nonterminals {Exp, Nat, Dup}, terminals {double, s, 0}) and rules

Exp → Dup(Nat) Nat → s(Nat) Nat → 0 Dup(x) → double(x, x) Then outermost-innermost derivations have the form Exp → Dup(Nat) → double(Nat, Nat) * → double(s n (0), s m (0))
while innermost-outermost derivations have the form

Exp → Dup(Nat) * → Dup(s n (0)) → double(s n (0), s n (0)) Therefore L(OI-G) = {double(s n (0), s m (0)) | n, m ∈ N} and L(IO-G) = {double(s n (0), s n (0)) | n ∈ N}.
A tree language L is IO if there is some context-free grammar G such that L = L(IO-G). The next theorem shows the relation between L(IO-G), L(OI-G) and L(G).

Theorem 2.5.3. The following inclusion holds:

L(IO-G) ⊆ L(OI-G) = L(G)
Example 2.5.2 shows that the inclusion can be strict. IO-languages are closed under intersection with regular languages and union, but the closure under concatenation requires another definition of concatenation: all occurrences of a constant generated by a non right-linear rule are replaced by the same term, as shown by the next example.

Example 2.5.4. Let G be the context-free grammar with axiom Exp, nonterminals {Exp, N at, F ct}, terminals {P, f ( , , )} and rules Exp → F ct(N at, N at) N at → P F ct(x, y) → f (x, x, y) and let L = IO-G and M = {0, 1}, then L .2 M contains f (0, 0, 0),f (0, 0, 1),

f (1, 1, 0), f (1, 1, 1) but not f (1, 0, 1) nor f (0, 1, 1).
There is a lot of work on the extension of results on context-free word grammars and languages to context-free tree grammars and languages. Unfortunately, many constructions and theorem can't be lifted to the tree case. Usually the failure is due to non-linearity which expresses that the same subtrees must occur at different positions in the tree. A similar phenomenon occurred when we stated results on recognizable languages and tree homomorphisms: the inverse image of a recognizable tree language by a tree homorphism is recognizable, but the assumption that the homomorphism is linear is needed to show that the direct image is recognizable.

Exercises

Exercise 2.1. Let F = {f (, ), g(), a}. Consider the automaton A = (Q, F , Q f , ∆) defined by: Q = {q, qg, q f }, Q f = {q f }, and ∆ = { a → q(a) g(q(x)) → q(g(x)) g(q(x)) → qg(g(x)) g(qg(x)) → q f (g(x)) f (q(x), q(y)) → q(f (x, y)) }.

Define a regular tree grammar generating L(A).

Exercise 2.2.

1. Prove the equivalence of a regular tree grammar and of the reduced regular tree grammar computed by algorithm of proposition 2.1.3.

2. Let F = {f (, ), g(), a}. Let G be the regular tree grammar with axiom X, non-terminal A, and rules

X → f (g(A), A) A → g(g(A))
Define a top-down NFTA, a NFTA and a DFTA for L(G). Is it possible to define a top-down DFTA for this language?

Exercise 2.3. Let F = {f (, ), a}. Let G be the regular tree grammar with axiom X, non-terminals A, B, C and rules

X → C X → a X → A A → f (A, B) B → a
Compute the reduced regular tree grammar equivalent to G applying the algorithm defined in the proof of Proposition 2.1.3. Now, consider the same algorithm, but first apply step 2 and then step 1. Is the output of this algorithm reduced? equivalent to G?

Exercise 2.4. 1. Prove Theorem 1.4.3 using regular tree grammars.

2. Prove Theorem 1.4.4 using regular tree grammars.

Exercise 2.5. (Local languages) Let F be a signature, let t be a term of T (F ), then we define f ork(t) as follows:

• f ork(a) = ∅, for each constant symbol a;

• f ork(f (t1, . . . , tn)) = {f (Head (t1), . . . , Head (tn))} ∪ S i=n i=1 f ork(ti) A tree language L is local if and only if there exist a set F ′ ⊆ F and a set G ⊆ f ork(T (F )) such that t ∈ L iff root(t) ∈ F ′ and f ork(t) ⊆ G. Prove that every local tree language is a regular tree language. Prove that a language is local iff it is the set of derivation trees of a context-free word language. Prove that every regular tree language is the image of a local tree language by an alphabetic homomorphism.

Exercise 2.6. The pumping lemma for context-free word languages states:

for each context-free language L, there is some constant k ≥ 1 such that each z ∈ L of length greater than or equal to k can be written z = uvwxy such that vx is not the empty word, vwx has length less than or equal to k, and for each n ≥ 0, the word uv n wx n y is in L.

Prove this result using the pumping lemma for tree languages and the results of this chapter.

Exercise 2.7. Another possible definition for the iteration of a language is:

• L 0, 2 = {2} • L n+1, 2 = L n, 2 ∪ L n, 2 .2 L
(Unfortunately that definition was given in the previous version of TATA) 1. Show that this definition may generate non-regular tree languages. Hint: one binary symbol f ( , ) and 2 are enough.

2. Are the two definitions equivalent (i.e. generate the same languages) if Σ consists of unary symbols and constants only?

Exercise 2.8. Let F be a ranked alphabet, let t be a term of T (F ), then we define the word language Branch(t) as follows:

• Branch(a) = a, for each constant symbol a;

• Branch(f (t1, . . . , tn)) = S i=n i=1 {f u | u ∈ Branch(ti)} Let L be a regular tree language, prove that Branch(L) = S t∈L Branch(t) is a regular word language. What about the converse? Exercise 2.9.

1. Let F be a ranked alphabet such that F0 = {a, b}. Find a regular tree language L such that Exercise 2.10.

Yield (L) = {a n b n | n ≥ 0}. Find a non regular tree language L such that Yield (L) = {a n b n | n ≥ 0}.
1. Let G be the context free word grammar with axiom X, terminals a, b, and rules

X → XX X → aXb X → ǫ
where ǫ stands for the empty word. What is the word language L(G)? Give a derivation tree for u = aabbab.

2. Let G ′ be the context free word grammar in Greibach normal form with axiom X, non terminals X ′ , Y ′ , Z ′ terminals a, b, and rules l

X ′ → aX ′ Y ′ X ′ → aY ′ X ′ → aX ′ Z ′ X ′ → aZ ′ Y ′ → bX ′ Z ′ → b prove that L(G ′ ) = L(G).
Give a derivation tree for u = aabbab.

3. Find a context free word grammar G ′′ such that L(G ′′ ) = A1 ∪ A2 (A1 and A2 are defined in Exercise 2.9). Give two derivation trees for u = abc.

Exercise 2.11. Let F be a ranked alphabet.

1. Let L and L ′ be two regular tree languages. Compare the sets Yield (L ∩ L ′ ) and Yield (L) ∩ Yield (L ′ ).

2. Let A be a subset of F0. Prove that T (F , A) = T (F ∩ A) is a regular tree language. Let L be a regular tree language over F , compare the sets Yield (L ∩ T (F , A)) and Yield (L) ∩ Yield (T (F , A)).

3. Let R be a regular word language over F0.

Let T (F , R) = {t ∈ T (F ) | Yield (t) ∈ R}. Prove that T (F , R
) is a regular tree language. Let L be a regular tree language over F , compare the sets Yield (L ∩ T (F , R)) and Yield (L) ∩ Yield (T (F , R)). As a consequence of the results obtained in the present exercise, what could be said about the intersection of a context free word language and of a regular word language?

Bibliographic notes

This chapter only scratches the topic of tree grammars and related topics. A useful reference on algebraic aspects of regular tree language is [GS84] which contains a lot of classical results on these features. There is a huge litterature on tree grammars and related topics, which is also relevant for the chapter on tree transducers, see the references given in this chapter. Systems of equations can be generalized to formal tree series with similar results [BR82, Boz99, Boz01, Kui99, Kui01]. The notion of pushdown tree automaton has been introduced by Guessarian [Gue83] and generalized to formal tree series by Kuich [START_REF] Kuich | Pushdown tree automata, algebraic tree systems, and algebraic tree series[END_REF] The reader may consult [START_REF] Engelfriet | Three hierarchies of transducers[END_REF][START_REF] Engelfriet | IO and OI II[END_REF] for IO and OI grammars. The connection between recursive program scheme and formalisms for regular tree languages is also well-known, see [START_REF] Courcelle | Equivalences and transformations of regular systemsapplications to recursive program schemes and grammars[END_REF] for instance. We should mention that some open problems like equivalence of deterministic tree grammars are now solved using the result of Senizergues on the equivalence of deterministic pushdown word automata [START_REF] Sénizergues | The equivalence problem for deterministic pushdown automata is decidable[END_REF].

Chapter 3

Logic, Automata and Relations

Introduction

As early as in the 50s, automata, and in particular tree automata, played an important role in the development of verification. Several well-known logicians, such as A. Church, J.R. Büchi, Elgott, MacNaughton, M. Rabin and others contributed to what is called "the trinity" by Trakhtenbrot: Logic, Automata and Verification (of Boolean circuits). The idea is simple: given a formula φ with free variables x 1 , . . . , x n and a domain of interpretation D, φ defines the subset of D n containing all assignments of the free variables x 1 , . . . , x n that satisfy φ. Hence formulas in this case are just a way of defining subsets of D n (also called n-ary relations on D). In case n = 1 (and, as we will see, also for n > 1), finite automata provide another way of defining subsets of D n . In 1960, Büchi realized that these two ways of defining relations over the free monoid {0, . . . , n} * coincide when the logic is the sequential calculus, also called weak second-order monadic logic with one successor, WS1S. This result was extended to tree automata: Doner, Thatcher and Wright showed that the definability in the weak second-order monadic logic with k successors, WSkS coincides with the recognizability by a finite tree automaton. These results imply in particular the decidability of WSkS, following the decision results on tree automata (see chapter 1).

These ideas are the basis of several decision techniques for various logics some of which will be listed in Section 3.4. In order to illustrate this correspondence, consider Presburger's arithmetic: the atomic formulas are equalities and inequalities s = t or s ≥ t where s, t are sums of variables and constants. For instance x+y+y = z+z+z+1+1, also written x+2y = 3z+2, is an atomic formula. In other words, atomic formulas are linear Diophantine (in)equations. Then atomic formulas can be combined using any logical connectives among ∧, ∨, ¬ and quantifications ∀, ∃. For instance ∀x.(∀y.¬(x = 2y)) ⇒ (∃y.x = 2y + 1) is a (true) formula of Presburger's arithmetic. Formulas are interpreted in the natural numbers (non-negative integers), each symbol having its expected meaning. A solution of a formula φ(x) whose only free variable is x, is an assignment of x to a natural number n such that φ(n) holds true in the interpretation. For

1 2 0 1 1 1 0 0 0 1 1 0 0 1 0 1 0 0 0 1 1 0 1 0 1 1 Figure 3.1:
The automaton which accepts the solutions of x = y + z instance, if φ(x) is the formula ∃y.x = 2y, its solutions are the even numbers.

Writing integers in base 2, they can be viewed as elements of the free monoid {0, 1} * , i.e. words of 0s and 1s. The representation of a natural number is not unique as 01 = 1, for instance. Tuples of natural numbers are displayed by stacking their representations in base 2 and aligning on the right, then completing with some 0s on the left in order to get a rectangle of bits. For instance the pair (13,6) is represented as

1 0 1 1 0 1 1 0 (or 0 0 1 0 1 1 0 1 1 0 as well).
Hence, we can see the solutions of a formula as a subset of ({0, 1} n ) * where n is the number of free variables of the formula.

It is not difficult to see that the set of solutions of any atomic formula is recognized by a finite word automaton working on the alphabet {0, 1} n . For instance, the solutions of x = y + z are recognized by the automaton of Figure 3.1.

Then, and that is probably one of the key ideas, each logical connective corresponds to a basic operation on automata (here word automata): ∨ is a union, ∧ and intersection, ¬ a complement, ∃x a projection (an operation which will be defined in Section 3.2.4). It follows that the set of solutions of any Presburger formula is recognized by a finite automaton.

In particular, a closed formula (without free variable), holds true in the interpretation if the initial state of the automaton is also final. It holds false otherwise. Therefore, this gives both a decision technique for Presburger formulas by computing automata and an effective representation of the set of solutions for open formulas.

The example of Presburger's arithmetic we just sketched is not isolated. That is one of the purposes of this chapter to show how to relate finite tree automata and formulas.

In general, the problem with these techniques is to design an appropriate notion of automaton, which is able to recognize the solutions of atomic formulas and which has the desired closure and decision properties. We have to cite here the famous Rabin automata which work on infinite trees and which have indeed the closure and decidability properties, allowing to decide the full second-order monadic logic with k successors (a result due to M. [START_REF] Rabin | Decidability of Second-Order Theories and Automata on Infinite Trees[END_REF]. It is however out of the scope of this book to survey automata techniques in logic and computer science. We restrict our attention to finite automata on finite trees and refer to the excellent surveys [START_REF] Rabin | Handbook of Mathematical Logic, chapter Decidable theories[END_REF][START_REF] Thomas | Handbook of Theoretical Computer Science, volume B, chapter Automata on Infinite Objects[END_REF] for more details on other applications of automata to logic.

We start this chapter by reviewing some possible definitions of automata on pairs (or, more generally, tuples) of finite trees in Section 3.2. We define in this way several notions of recognizability for relations, which are not necessary unary, extending the frame of chapter 1. This extension is necessary since, automata recognizing the solutions of formulas actually recognize n-tuples of solutions, if there are n free variables in the formula.

The most natural way of defining a notion of recognizability on tuples is to consider products of recognizable sets. Though this happens to be sometimes sufficient, this notion is often too weak. For instance the example of Figure 3.1 could not be defined as a product of recognizable sets. Rather, we stacked the words and recognized these codings. Such a construction can be generalized to trees (we have to overlap instead of stacking) and gives rise to a second notion of recognizability. We will also introduce a third class called "Ground Tree Transducers" which is weaker than the second class above but enjoys stronger closure properties, for instance by iteration. Its usefulness will become evident in Section 3.4.

Next, in Section 3.3, we introduce the weak second-order monadic logic with k successor and show Thatcher and Wright's theorem which relates this logic with finite tree automata. This is a modest insight into the relations between logic and automata.

Finally in Section 3.4 we survey a number of applications, mostly issued from Term Rewriting or Constraint Solving. We do not detail this part (we give references instead). The goal is to show how the simple techniques developed before can be applied to various questions, with a special emphasis on decision problems. We consider the theories of sort constraints in Section 3.4.1, the theory of linear encompassment in Section 3.4.2, the theory of ground term rewriting in Section 3.4.3 and reduction strategies in orthogonal term rewriting in Section 3.4.4. Other examples are given as exercises in Section 3.5 or considered in chapters 4 and 5.

Automata on Tuples of Finite Trees

Three Notions of Recognizability

Let Rec × be the subset of n-ary relations on T (F) which are finite unions of products S 1 × • • • × S n where S 1 , . . . , S n are recognizable subsets of T (F). This notion of recognizability of pairs is the simplest one can imagine. Automata for such relations consist of pairs of tree automata which work independently. This notion is however quite weak, as e.g. the diagonal

∆ = {(t, t) | t ∈ T (F)} does not belong to Rec × . Actually a relation R ∈ Rec × does not really relate its components!
The second notion of recognizability is used in the correspondence with WSkS and is strictly stronger than the above one. Roughly, it consists in overlapping the components of a n-tuple, yielding a term on a product alphabet. Then define Rec as the set of sets of pairs of terms whose overlapping coding is recognized by a tree automaton on the product alphabet. Let us first define more precisely the notion of "coding". (This is illustrated by an example on Figure 3.2). We let F ′ = (F ∪{⊥}) n , where ⊥ is a new symbol. This is the idea of "stacking" the symbols, as in the introductory example of Presburger's arithmetic. Let k be the maximal arity of a function symbol in F. Assuming ⊥ has arity 0, the arities of function symbols in

F ′ are defined by a(f 1 . . . f n ) = max(a(f 1 ), . . . , a(f n )).
The coding of two terms t 1 , t 2 ∈ T (F) is defined by induction:

[f (t1, . . . , tn), g(u1, . . . , um)] def = f g([t1, u1], . . . [tm, um], [tm+1, ⊥], . . . , [tn, ⊥]) if n ≥ m and [f (t1, . . . , tn), g(u1, . . . , um)] def = f g([t1, u1], . . . [tn, un], [⊥, un+1], . . . , [⊥, um]) if m ≥ n. More generally, the coding of n terms f 1 (t 1 1 , . . . , t k1 1 ), . . . , f n (t n 1 , . . . , t kn n ) is defined as f 1 . . . f n ([t 1 1 , . . . , t 1 n ], . . . , [t m 1 , . . . , t m n ]
) where m is the maximal arity of f 1 , . . . , f n ∈ F and t j i is, by convention, ⊥ when j > k i .

Definition 3.2.1. Rec is the set of relations R ⊆ T (F) n such that {[t 1 , . . . , t n ] | (t 1 , . . . , t n ) ∈ R}
is recognized by a finite tree automaton on the alphabet

F ′ = (F ∪ {⊥}) n .
For example, consider the diagonal ∆, it is in Rec since its coding is recognized by the bottom-up tree automaton whose only state is q (also a final state) and transitions are the rules f f (q, . . . , q) → q for all symbols f ∈ F.

One drawback of this second notion of recognizability is that it is not closed under iteration. More precisely, there is a binary relation R which belongs to Rec and whose transitive closure is not in Rec (see Section 3.5). For this reason, a third class of recognizable sets of pairs of trees was introduced: the Ground Tree Transducers (GTT for short).

Definition 3.2.2. A GTT is a pair of bottom-up tree automata (A 1 , A 2 ) working on the same alphabet. Their sets of states may share some symbols (the synchronization states).

A pair

(t, t ′ ) is recognized by a GTT (A 1 , A 2 ) if there is a context C ∈ C n (F) such that t = C[t 1 , . . . , t n ], t ′ = C[t ′ 1 , . . . , t ′ n ]
and there are states q 1 , . . . , q n of both automata such that, for all i, t i *

--→ A1 q i and t ′ i * --→ A2 q i . We write L(A 1 , A 2 )
the language accepted by the GTT (A 1 , A 2 ), i.e. the set of pairs of terms which are recognized.

t = A t 1 • • • t n t ′ = A t ′ 1 • • • t ′ n A q 1 t 1 • • • t n • • • q n t ′ 1 • • • t ′ n Figure 3.3: GTT acceptance
The recognizability by a GTT is depicted on Figure 3.3. For instance, ∆ is accepted by a GTT. Another typical example is the binary relation "one step parallel rewriting" for term rewriting system whose left members are linear and whose right hand sides are ground (see Section 3.4.3).

Examples of The Three Notions of Recognizability

The first example illustrates Rec × . It will be developed in a more general framework in Section 3.4.2.

Example 3.2.3. Consider the alphabet F = {f (, ), g(), a} where f is binary, g is unary and a is a constant. Let P be the predicate which is true on t if there are terms t 1 , t 2 such that f (g(t 1 ), t 2 ) is a subterm of t. Then the solutions of P (x) ∧ P (y) define a relation in Rec × , using twice the following automaton:

Q = {q f , q g , q ⊤ } Q f = {q f } T = { a → q ⊤ f (q ⊤ , q ⊤ ) → q ⊤ g(q ⊤ ) → q ⊤ f (q f , q ⊤ ) → q f g(q f ) → q f f (q g , q ⊤ ) → q f g(q ⊤ ) → q g f (q ⊤ , q f ) → q f }
For instance the pair (g(f (g(a), g(a))), f (g(g(a)), a)) is accepted by the pair of automata.

The second example illustrates Rec. Again, it is a first account of the developments of Section 3.4.4.

Example 3.2.4. Let F = {f (, ), g(), a, Ω} where f is binary, g is unary, a and Ω are constants. Let R be the set of terms (t, u) such that u can be obtained from t by replacing each occurrence of Ω by some term in T (F) (each occurrence of Ω needs not to be replaced with the same term). Using the notations of Chapter 2

R(t, u) ⇐⇒ u ∈ t. Ω T (F)
R is recognized by the following automaton (on codings of pairs):

Q = {q, q ′ } Q f = {q ′ } T = { ⊥ a → q ⊥ f (q, q) → q ⊥ g(q) → q Ωf (q, q) → q ′ ⊥ Ω → q f f (q ′ , q ′ ) → q ′ aa → q ′ gg(q ′ ) → q ′ ΩΩ → q ′ Ωg(q) → q ′ Ωa → q ′ }
For instance, the pair (f (g(Ω), g(Ω)), f (g(g(a)), g(Ω))) is accepted by the automaton: the overlap of the two terms yields

[tu] = f f (gg(Ωg(⊥ a)), gg(ΩΩ))
And the reduction:

[tu] * -→ f f (gg(Ωg(q)), gg(q ′ )) * -→ f f (gg(q ′ ), q ′ ) → f f (q ′ , q ′ ) → q ′
The last example illustrates the recognition by a GTT. It comes from the theory of rewriting; further developments and explanations on this theory are given in Section 3.4.3.

Example 3.2.5. Let F = {×, +, 0, 1}. Let R be the rewrite system 0 × x → 0. The many-steps reduction relation defined by R: * -→ R is recognized by the GTT(A 1 , A 2 ) defined as follows (+ and × are used in infix notation to meet their usual reading):

T 1 = { 0 → q ⊤ q ⊤ + q ⊤ → q ⊤ 1 → q ⊤ q ⊤ × q ⊤ → q ⊤ 0 → q 0 q 0 × q ⊤ → q 0 } T 2 = { 0 → q 0 } Then, for instance, the pair (1 + ((0 × 1) × 1), 1 + 0) is accepted by the GTT since 1 + ((0 × 1) × 1) * --→ A1 1 + (q 0 × q ⊤ ) × q ⊤ --→ A1 1 + (q 0 × q ⊤ ) --→ A1 1 + q 0
on one hand and 1 + 0 --→ A2 1 + q 0 on the other hand.

Comparisons Between the Three Classes

We study here the inclusion relations between the three classes: Rec × , Rec, GT T . Proposition 3.2.6. Rec × ⊂ Rec and the inclusion is strict.

Rec

• • GTT Rec × • • R c ∆ T (F ) 2 {a, f (a)} 2
A 1 = (Q 1 , F, Q f 1 , R 1 ), A 2 = (F, Q 2 , Q f 2 , R 2 )
an automaton which recognizes the overlaps of the terms in the languages. We define such an automaton

A = (Q, (F ∪ {⊥}) 2 , Q f , R) by: Q = (Q 1 ∪ {q ⊥ }) × (Q 2 ∪ {q ⊥ }), Q f = Q f 1 × Q f 2 and R is the set of rules: • f ⊥ ((q 1 , q ⊥ ), . . . , (q n , q ⊥ )) -→ (q, q ⊥ ) if f (q 1 , . . . , q n ) → q ∈ R 1 • ⊥ f ((q ⊥ , q 1 ), . . . , (q ⊥ , q n )) -→ (q ⊥ , q) if f (q 1 , . . . , q n ) → q ∈ R 2 • f g((q 1 , q ′ 1 ), . . . , (q m , q ′ m ), (q m+1 , q ⊥ ), . . . , (q n , q ⊥ )) → (q, q ′ ) if f (q 1 , . . . , q n ) → q ∈ R 1 and g(q ′ 1 , . . . , q ′ m ) → q ′ ∈ R 2 and n ≥ m
• f g((q 1 , q ′ 1 ), . . . , (q n , q ′ n ), (q ⊥ , q n+1 ), . . . , (q ⊥ , q m )) → (q, q ′ ) if f (q 1 , . . . , q n ) → q ∈ R 1 and g(q ′ 1 , . . . , q ′ m ) → q ′ ∈ R 2 and m ≥ n

The proof that A indeed accepts L(A 1 ) × L(A 2 ) is left to the reader. Now, the inclusion is strict since e.g. ∆ ∈ Rec \ Rec × .

Proposition 3.2.7. GTT ⊂ Rec and the inclusion is strict.

Proof. Let (A 1 , A 2 ) be a GTT accepting R. We have to construct an automaton A which accepts the codings of pairs in R.

Let A 0 = (Q 0 , F, Q f 0 , T 0 ) be the automaton constructed in the proof of Proposition 3.2.6. [t, u] * --→ A0 (q 1 , q 2 ) if and only if t * --→ A1 q 1 and u * --→ A2 q 2 . Now we let A = (Q 0 ∪ {q f }, F, Q f = {q f }, T ). T consists of T 0 plus the following rules: (q, q) → q f f f (q f , . . . , q f ) → q f
For every symbol f ∈ F and every state q

∈ Q 0 . If (t, u) is accepted by the GTT, then t * --→ A1 C[q 1 , . . . , q n ] p1,...,pn * ← -- A2 u. Then [t, u] * --→ A0 [C, C][(q 1 , q 1 ), . . . , (q n , q n )] p1,...,pn * -→ A [C, C][q f , . . . , q f ] p1,...,pn * -→ A q f
Logic, Automata and Relations

Conversely, if [t, u] is accepted by A then [t, u] * -→ A q f
. By definition of A, there should be a sequence:

[t, u] * -→ A C[(q 1 , q 1 ), . . . , (q n , q n )] p1,...,pn * -→ A C[q f , . . . , q f ] p1,...,pn * -→ A q f
Indeed, we let p i be the positions at which one of the ǫ-transitions steps (q, q) → q f is applied. (n ≥ 0). Now, C[q f , . . . , q f ] p1,...,pm q f if and only if C can be written [C 1 , C 1 ] (the proof is left to the reader).

Concerning the strictness of the inclusion, it will be a consequence of Propositions 3.2.6 and 3.2.8.

Proposition 3.2.8. GTT ⊆ Rec × and Rec × ⊆ GTT.
Proof. ∆ is accepted by a GTT (with no state and no transition) but it does not belong to Rec × . On the other hand, if F = {f, a}, then {a, f (a)} 2 is in Rec × (it is the product of two finite languages) but it is not accepted by any GTT since any GTT accepts at least ∆.

Finally, there is an example of a relation R c which is in Rec and not in the union Rec × ∪ GTT; consider for instance the alphabet {a(), b(), 0} and the one step reduction relation associated with the rewrite system a(x) → x. In other words,

(u, v) ∈ R c ⇐⇒ ∃C ∈ C(F), ∃t ∈ T (F), u = C[a(t)] ∧ v = C[t]
It is left as an exercise to prove that R c ∈ Rec \ (Rec × ∪ GTT).

Closure Properties for Rec × and Rec; Cylindrification and Projection

Let us start with the classical closure properties.

Proposition 3.2.9. Rec × and Rec are closed under Boolean operations.

The proof of this proposition is straightforward and left as an exercise. These relations are also closed under cylindrification and projection. Let us first define these operations which are specific to automata on tuples:

Definition 3.2.10. If R ⊆ T (F) n (n ≥ 1) and 1 ≤ i ≤ n then the ith projection of R is the relation R i ⊆ T (F) n-1 defined by R i (t 1 , . . . , t n-1 ) ⇔ ∃t ∈ T (F) R(t 1 , . . . , t i-1 , t, t i , . . . , t n-1 ) When n = 1, T (F) n-1 is by convention a singleton set {⊤} (so as to keep the property that T (F) n+1 = T (F) × T (F) n ). {⊤} is assumed to be a neutral element w.r.t. Cartesian product. In such a situation, a relation R ⊆ T (F) 0 is either ∅ or {⊤} (it is a propositional variable). Definition 3.2.11. If R ⊆ T (F) n (n ≥ 0) and 1 ≤ i ≤ n + 1, then the ith cylindrification of R is the relation R i ⊆ T (F) n+1 defined by R i (t 1 , . . . , t i-1 , t, t i , . . . , t n ) ⇔ R(t 1 , . . . , t i-1 , t i , . . . , t n )
Proposition 3.2.12. Rec × and Rec are effectively closed under projection and cylindrification. Actually, ith projection can be computed in linear time and the ith cylindrification of A can be computed in linear time (assuming that the size of the alphabet is constant).

Proof. For Rec × , this property is easy: projection on the ith component simply amounts to remove the ith automaton. Cylindrification on the ith component simply amounts to insert as a ith automaton, an automaton accepting all terms.

Assume that R ∈ Rec. The ith projection of R is simply its image by the following linear tree homomorphism:

h i ([f 1 , . . . , f n ](t 1 , . . . , t k )) def = [f 1 . . . f i-1 f i+1 . . . f n ](h i (t 1 ), . . . , h i (t m )) in which m is the arity of [f 1 . . . f i-1 f i+1 . . . f n ] (which is smaller or equal to k).
Hence, by Theorem 1.4.3, the ith projection of R is recognizable (and we can extract from the proof a linear construction of the automaton).

Similarly, the ith cylindrification is obtained as an inverse homomorphic image, hence is recognizable thanks to Theorem 1.4.4.

Note that using the above construction, the projection of a deterministic automaton may be non-deterministic (see exercises) Example 3.2.13. Let F = {f, g, a} where f is binary, g is unary and a is a constant. Consider the following automaton A on F ′ = (F ∪ {⊥})2 : The set of states is {q 1 , q 2 , q 3 , q 4 , q 5 } and the set of final states is {q 3 }1 a ⊥ → q 1 f ⊥ (q 1 , q 1 ) → q 1 g ⊥ (q 1 ) → q 1 f g(q 2 , q 1 ) → q 3 ga(q 1 ) → q 2 f ⊥ (q 4 , q 1 ) → q 4 g ⊥ (q 1 ) → q 4 f a(q 4 , q 1 ) → q 2 gg(q 3 ) → q 3 f f (q 3 , q 3 ) → q 3 aa → q 5 f f (q 3 , q 5 ) → q 3 gg(q 5 ) → q 5 f f (q 5 , q 3 ) → q 3 f f (q 5 , q 5 ) → q 5

The first projection of this automaton gives: a → q 2 g(q 3 ) → q 3 a → q 5 g(q 5 ) → q 5 g(q 2 ) → q 3 f (q 3 , q 3 ) → q 3 f (q 3 , q 5 ) → q 3 f (q 5 , q 5 ) → q 5 f (q 5 , q 3 ) → q 3 Which accepts the terms containing g(a) as a subterm 2 .

C • • • q • • • C q 1 . . . q n A 1 q ′ 1 . . . q ′ n A 2 . . . A 2 A 2 . . . A 2 A 2 A 1 A 1 C ′ = C t = C v = C . . . u = C . . .

Closure of GTT by Composition and Iteration

Theorem 3.2.14. If R ⊆ T (F) 2 is recognized by a GTT, then its transitive closure R * is also recognized by a GTT.

The detailed proof is technical, so let us show it on a picture and explain it informally.

We consider two terms (t, v) and (v, u) which are both accepted by the GTT and we wish that (t, u) is also accepted. For simplicity, consider only one state q

such that t * --→ A1 C[q] * ← -- A2 v and v * --→ A1 C ′ [q 1 , . . . , q n ] * ← -- A2 u.
There are actually two cases: C can be "bigger" than C ′ or "smaller". Assume it is smaller. Then q is reached at a position inside

C ′ : C ′ = C[C ′′ ] p .
The situation is depicted on Figure 3.5. Along the reduction of v to q by A 2 , we enter a configuration

C ′′ [q ′ 1 , . . . , q ′ n ]
. The idea now is to add to A 2 ǫ-transitions from q i to q ′ i . In this way, as can easily be seen on Figure 3.5, we get a reduction from u to C[q], hence the pair (t, u) is accepted.

Proof. Let A 1 and A 2 be the pair of automata defining the GTT which accepts R. We compute by induction the automata

A n 1 , A n 2 . A 0 i = A i and A n+1
i is obtained by adding new transitions to A n i : Let Q i be the set of states of A i (and also the set of states of A n i ).

• If L A n 2 (q) ∩ L A n 1 (q ′ ) = ∅, q ∈ Q 1 ∩ Q 2 and q * --→ A n 1 q ′ , then A n+1 1 is obtained from A n 1 by adding the ǫ-transition q → q ′ and A n+1 2 = A n 2 . • If L A n 1 (q) ∩ L A n 2 (q ′ ) = ∅, q ∈ Q 1 ∩ Q 2 and q * --→ A n 2 q ′ , then A n+1 2 is obtained from A n
2 by adding the ǫ-transition q → q ′ and A n+1

1 = A n 1 .
If there are several ways of obtaining A n+1 i from A n i using these rules, we don't care which of these ways is used.

First, these completion rules are decidable by the decision properties of chapter 1. Their application also terminates as at each application strictly decreases

k 1 (n) + k 2 (n) where k i (n) is the number of pairs of states (q, q ′ ) ∈ (Q 1 ∪ Q 2 ) × (Q 1 ∪ Q 2 ) such that there is no ǫ-transition in A n
i from q to q ′ . We let A * i be a fixed point of this computation. We show that (A * 1 , A * 2 ) defines a GTT accepting R * .

• Each pair of terms accepted by the GTT (A * 1 , A * 2 ) is in R * : we show by induction on n that each pair of terms accepted by the GTT (A n 1 , A n 2 ) is in R * . For n = 0, this follows from the hypothesis. Let us now assume that A n+1 1 is obtained by adding q → q ′ to the transitions of A n 1 (The other case is symmetric). Let (t, u) be accepted by the GTT

(A n+1 1 , A n+1 2 ). By definition, there is a context C and positions p 1 , . . . , p k such that t = C[t 1 , . . . , t k ] p1,...,p k , u = C[u 1 , . . . , u k ] p1,...,p k and there are states q 1 , . . . , q k ∈ Q 1 ∩ Q 2 such that, for all i, t i * ---→ A n+1 1 q i and u i * --→ A n 2 q i .
We prove the result by induction on the number m of times q → q ′ is applied in the reductions

t i * ---→ A n+1 1 q i . If m = 0.
Then this is the first induction hypothesis: (t, u) is accepted by (A n 1 , A n 2 ), hence (t, u) ∈ R * . Now, assume that, for some i,

t i * ---→ A n+1 1 t ′ i [q] p * ---→ q→q ′ t ′ i [q ′ ] p * --→ A n 1 q i By definition, there is a term v such that v * --→ A n 2 q and v * --→ A n 1 q ′ . Hence t i [v] p * ---→ A n+1 1 q i
And the number of reduction steps using q → q ′ is strictly smaller here than in the reduction from t i to q i . Hence, by induction hypothesis,

(t[v] pip , u) ∈ R * . On the other hand, (t, t[v] pip ) is accepted by the GTT (A n+1 1 , A n 2 ) since t| pip * ---→ A n+1 1 q and v * --→ A n 2 q.
Moreover, by construction, the first sequence of reductions uses strictly less than m times the transition q → q ′ . Then, by induction hypothesis, (t,

t[v] pip ) ∈ R * . Now from (t, t[v] pip ) ∈ R * and (t[v] pip , u) ∈ R * , we conclude (t, u) ∈ R * . • If (t, u) ∈ R * , then (t, u) is accepted by the GTT (A * 1 , A * 2 ).
Let us prove the following intermediate result:

Lemma 3.2.15. If                  t * --→ A * 1 q v * --→ A * 2 q v * --→ A * 1 C[q 1 , . . . , q k ] p1,...,p k u * --→ A * 2 C[q 1 , . . . , q k ] p1,...,p k                  then u * --→ A * 2 q
and hence (t, u) is accepted by the GTT.

Let v * --→ A * 2 C[q ′ 1 , . . . , q ′ k ] p1,...,p k * --→ A * 2 q. For each i, v| pi ∈ L A * 2 (q ′ i )∩L A * 1 (q i ) and q i ∈ Q 1 ∩ Q 2 . Hence, by construction, q i --→ A * 2 q ′ i . It follows that u * --→ A * 2 C[q 1 , . . . q k ] p1,...,p k * --→ A * 2 C[q ′ 1 , . . . , q ′ k ] p1,...,p k * --→ A * 2 q
Which proves our lemma.

Symmetrically, if t * --→ A * 1 C[q 1 , . . . , q k ] p1,...,p k , v * --→ A * 2 C[q 1 , . . . , q k ] p1,...,p k , v * --→ A * 1 q and u * --→ A * 2 q, then t * --→ A * 1 q Now, let (t, u) ∈ R n : we prove that (t, u) is accepted by the GTT (A * 1 , A * 2 ) by induction on n. If n = 1, then the result follows from the inclu- sion of L(A 1 , A 2 ) in L(A * 1 , A * 2 ). Now, let v be such that (t, v) ∈ R and (v, u) ∈ R n-1
. By induction hypothesis, both (t, v) and (v, u) are accepted by the GTT (A * 1 , A * 2 ): there are context C and C ′ and positions

p 1 , . . . , p k , p ′ 1 , . . . , p ′ m such that t = C[t 1 , . . . , t k ] p1,...,p k , v = C[v 1 , . . . , v k ] p1,...,p k v = C ′ [v ′ 1 , . . . , v ′ m ] p ′ 1 ,...,p ′ m , u = C ′ [u 1 , . . . , u m ] and states q 1 , . . . , q k , q ′ 1 , . . . , q ′ m ∈ Q 1 ∩ Q 2 such that for all i, j, t i * --→ A * 1 q i , v i * --→ A * 2 q i , v ′ j * --→ A * 1 q ′ j , u j * --→ A * 2 q ′ j .
Let C ′′ be the largest context more general than C and C ′ ; the positions of C ′′ are the positions of both C[q 1 , . . . , q n ] p1,...,pn and C

′ [q ′ 1 , . . . , q ′ m ] p ′ 1 ,...,p ′ m . C ′′ , p ′′ 1 , . . . , p ′′ l are such that: -For each 1 ≤ i ≤ l, there is a j such that either p j = p ′′ i or p ′ j = p ′′ i -For all 1 ≤ i ≤ n there is a j such that p i ≥ p ′′ j -For all 1 ≤ i ≤ m there is a j such that p ′ i ≥ p ′′ j
the positions p ′′ j are pairwise incomparable w.r.t. the prefix ordering. Let us fix a j ∈ [1..l]. Assume that p ′′ j = p i (the other case is symmetric). We can apply our lemma to

t j = t| p ′′ j (in place of t), v j = v| p ′′ j (in place of v) and u| p ′′ j (in place of u), showing that u| p ′′ j * --→ A * 2 q i . If we let now q ′′ j = q i when p ′′ j = p i and q ′′ j = q ′ i when p ′′ j = p ′ i , we get t * --→ A * 1 C ′′ [q ′′ 1 , . . . , q ′′ l ] p ′′ 1 ,...,p ′′ l * ← -- A * 2 u C C ′ q 1 q n q k q ′ m q ′ l q ′ 1 u w v Figure 3.6: The proof of Proposition 3.2.16
which completes the proof.

Proposition 3.2.16. If R and R ′ are in GTT then their composition R • R ′ is also in GTT. Proof. Let (A 1 , A 2 ) and (A ′ 1 , A ′
2 ) be the two pairs of automata which recognize R and R ′ respectively. We assume without loss of generality that the sets of states are disjoint:

(

Q 1 ∪ Q 2 ) ∩ (Q ′ 1 ∪ Q ′ 2 ) = ∅ We define the automaton A *
1 as follows: the set of states is Q 1 ∪ Q ′ 1 and the transitions are the union of:

• the transitions of A 1 • the transitions of A ′ 1 • the ǫ-transitions q -→ q ′ if q ∈ Q 1 ∩ Q 2 , q ′ ∈ Q ′ 1 and L A2 (q) ∩ L A ′ 1 (q ′ ) = ∅ Symmetrically, the automaton A *
2 is defined by: its states are Q 2 ∪ Q ′ 2 and the transitions are:

• the transitions of A 2 • the transitions of A ′ 2 • the ǫ-transitions q ′ -→ q if q ′ ∈ Q ′ 1 ∩ Q ′ 2 , q ∈ Q 2 and L A ′ 1 (q ′ ) ∩ L A2 (q) = ∅ We prove below that (A * 1 , A * 2 ) is a GTT recognizing R • R ′ . See also the figure 3.6. • Assume first that (u, v) ∈ R • R ′ . Then there is a term w such that (u, w) ∈ R and (w, v) ∈ R ′ : u = C[u 1 , . . . , u k ] p1,...,p k , w = C[w 1 , . . . , w k ] p1,...,p k w = C ′ [w ′ 1 , . . . , w ′ m ] p ′ 1 ,...,p ′ m , v = C ′ [v 1 , . . . , v m ] p ′ 1 ,...,p ′ m and, for every i ∈ {1, . . . , k}, u i * --→ A1 q i , w i * --→ A2 q i , for every i ∈ {1, . . . , m}, w ′ i * --→ A ′ 1 q ′ i , v i * --→ A ′ 2 q ′ i . Let p ′′ 1 , .
. . , p ′′ l be the minimal elements (w.r.t. the prefix ordering) of the set {p 1 , . . . , p k } ∪ {p ′ 1 , . . . , p ′ m }. Each p ′′ i is either some p j or some p ′ j . Assume first p ′′ i = p j . Then p j is a position in C ′ and

C ′ [q ′ 1 , . . . , q ′ m ] p ′ 1 ,...,p ′ m | pj = C j [q ′ mj , . . . , q ′ mj +kj ] p ′ m j ,...,p ′ m j +k j Now, w j * --→ A2 q j and w j = C j [w ′ mj , . . . , w ′ mj +kj ] p ′ m j ,...,p ′ m j +k j with w ′ mj +i * --→ A ′ 1
q ′ mj +i for every i ∈ {1, . . . , k j }. For i ∈ {1, . . . , k j }, let q j,i be such that:

   w ′ mj +i = w j | p ′ m j +i * --→ A2 q j,i C j [q j,1 , . . . , q j,kj ] p ′ m j ,...,p ′ m j +k j * --→ A2 q j For every i, w ′ mj +i ∈ L A2 (q j,i ) ∩ L A ′ 1 (q ′ mj +i ) and q ′ mj +i ∈ Q ′ 1 ∩ Q ′ 2 .
Then, by definition, there is a transition q ′ mj +i --→

A * 2 q j,i . Therefore,

C j [q ′ mj , . . . , q ′ mj +kj ] * --→ A * 2 q j and then v| pj * --→ A * 2 q j . Now, if p ′′ i = p ′ j , we get, in a similar way, u| p ′ j * --→ A * 1 q ′ j . Altogether: u * --→ A * 1 C ′′ [q ′′ 1 , . . . , q ′′ l ] p ′′ 1 ,...,p ′′ l * ← -- A * 2 v where q ′′ i = q j if p ′′ i = p j and q ′′ j = q ′ j if p ′′ i = p ′ j . • Conversely, assume that (u, v) is accepted by (A * 1 , A * 2 ). Then u * --→ A * 1 C[q ′′ 1 , . . . , q ′′ l ] p ′′ 1 ,...,p ′′ l * ← -- A * 2 v
and, for every i, either

q ′′ i ∈ Q 1 ∩ Q 2 or q ′′ i ∈ Q ′ 1 ∩ Q ′ 2 (by the disjointness hypothesis). Assume for instance that q ′′ i ∈ Q ′ 1 ∩ Q ′ 2 and consider the computation of A * 1 : u| p ′′ i * --→ A * 1 q ′′ i . By definition, u| p ′′ i = C i [u 1 , . . . , u ki ] with u j * --→ A1 q j --→ A * 1 q ′ j for every j = 1, . . . , k i and C i [q ′ 1 , . . . , q ′ ki ] * --→ A ′ 1 q ′′ i . By construction, q j ∈ Q 1 ∩ Q 2 and L A2 (q j ) ∩ L A ′ 1 (q ′ j ) = ∅.
Let w i,j be a term in this intersection and

w i = C i [w i,1 , . . . , w i,ki ]. Then                w i * --→ A2 C i [q 1 , . . . , q ki ] u| p ′′ i * --→ A1 C i [q 1 , . . . , q ki ] w i * --→ A ′ 1 q ′′ i v| p ′′ i * --→ A ′ 2 q ′′ i
The last property comes from the fact that v|

p ′′ i * --→ A * 2 q ′′ i and, since q ′′ i ∈ Q ′ 2 , there can be only transition steps from A ′ 2 in this reduction. Symmetrically, if q ′′ i ∈ Q 1 ∩ Q 2 , then we define w i and the contexts C i such that                w i * --→ A2 q ′′ i u| p ′′ i * --→ A1 q ′′ i w i * --→ A ′ 1 C i [q ′ 1 , . . . , q ′ ki ] v| p ′′ i * --→ A ′ 2 C i [q ′ 1 , . . . , q ′ ki ] Finally, letting w = C[w 1 , . . . , w l ], we have (u, w) ∈ R and (w, v) ∈ R ′ .
GTTs do not have many other good closure properties (see the exercises).

The Logic WSkS

Syntax

Terms of WSkS are formed out of the constant ǫ, first-order variable symbols (typically written with lower-case letters x, y, z, x ′ , x 1 , . . . ) and unary symbols 1, . . . , n written in postfix notation. For instance x1123, ǫ2111 are terms. The latter will be often written omitting ǫ (e.g. 2111 instead of ǫ2111). Atomic formulas are either equalities s = t between terms, inequalities s ≤ t or s ≥ t between terms, or membership constraints t ∈ X where t is a term and X is a second-order variable symbol. Second-order variables will be typically denoted using upper-case letters.

Formulas are built from the atomic formulas using the logical connectives ∧, ∨, ¬, ⇒, ⇐, ⇔ and the quantifiers ∃x, ∀x(quantification on individuals)∃X, ∀X (quantification on sets); we may quantify both first-order and second-order variables.

As usual, we do not need all this artillery: we may stick to a subset of logical connectives (and even a subset of atomic formulas as will be discussed in Section 3.3.4). For instance φ ⇔ ψ is an abbreviation for (φ ⇒ ψ) ∧ (ψ ⇒ φ), φ ⇒ ψ is another way of writing ψ ⇐ φ, φ ⇒ ψ is an abbreviation for (¬φ) ∨ ψ, ∀x.φ stands for ¬∃x.¬φ etc. We will use the extended syntax for convenience, but we will restrict ourselves to the atomic formulas s = t, s ≤ t, t ∈ X and the logical connectives ∨, ¬, ∃x, ∃X in the proofs.

The set of free variables of a formula φ is defined as usual.

Semantics

We consider the particular interpretation where terms are strings belonging to {1, . . . , k} * , = is the equality of strings, and ≤ is interpreted as the prefix ordering. Second order variables are interpreted as finite subsets of {1, . . . , k} * , so ∈ is then the membership predicate. Let t 1 , . . . , t n ∈ {1, . . . , k} * and S 1 , . . . , S n be finite subsets of {1, . . . , k} * . Given a formula φ(x 1 , . . . , x n , X 1 , . . . , X m ) with free variables x 1 , . . . , x n , X 1 , . . . , X m , the assignment σ = {x 1 → t 1 , . . . , x n → t n , X 1 → S 1 , . . . , X m → S m } satisfies φ, which is written σ |= φ (or also t 1 , . . . , t n , S 1 , . . . , S m |= φ) if replacing the variables with their corresponding value, the formula holds in the above model. Remark: the logic SkS is defined as above, except that set variables may be interpreted as infinite sets.

Examples

We list below a number of formulas defining predicates on sets and singletons.

After these examples, we may use the below-defined abbreviations as if they were primitives of the logic.

X is a subset of Y :

X ⊆ Y def = ∀x.(x ∈ X ⇒ x ∈ Y ) Finite union: X = n i=1 X i def = n i=1 X i ⊆ X ∧ ∀x.(x ∈ X ⇒ n i=1 x ∈ X i ) Intersection: X ∩ Y = Z def = ∀x.x ∈ Z ⇔ (x ∈ X ∧ x ∈ Y ) Partition: Partition(X, X 1 , . . . , X n ) def = X = n i=1 X i ∧ n-1 i=1 n j=i+1 X i ∩ X j = ∅
The prefix ordering:

x ≤ y def = ∀X.(y ∈ X ∧ (∀z.( k i=1 zi ∈ X) ⇒ z ∈ X)) ⇒ x ∈ X
"every set containing y and closed by predecessor contains x"

This shows that ≤ can be removed from the syntax of WSkS formulas without decreasing the expressive power of the logic.

X is closed under prefix:

PrefixClosed(X) def = ∀z.∀y.(z ∈ X ∧ y ≤ z) ⇒ y ∈ X Set equality: Y = X def = Y ⊆ X ∧ X ⊆ Y Emptiness: X = ∅ def = ∀Y.(Y ⊆ X ⇒ Y = X)
X is a Singleton:

Sing(X) def = X = ∅ ∧ ∀Y (Y ⊆ X ⇒ (Y = X ∨ Y = ∅)
Coding of trees: assume that k is the maximal arity of a function symbol in F. For t ∈ T (F), C(t) is the tuple of sets (S, S f1 , . . . , S fn ), where

F = {f 1 , . . . , f n }, S = n i=1
S fi and S fi is the set of positions in t which are labeled with f i .

For instance C(f (g(a), f (a, b))) is the tuple S = {ε, 1, 11, 2, 21, 22}, S f = {ε, 2}, S g = {1}, S a = {11, 21}, S b = {22}.
(S, S f1 , . . . , S fn ) is the coding of some t ∈ T (F) defined by:

Term(X, X 1 , . . . , X n ) def = X = ∅ ∧ Partition(X, X 1 , . . . , X n ) ∧ PrefixClosed(X) ∧ k i=1 a(fj )=i i l=1 ∀x.(x ∈ X fj ⇒ xl ∈ X ∧ k l=i+1 ∀y.(y ∈ X fj ⇒ yl / ∈ X))

Restricting the Syntax

If we consider that a first-order variable is a singleton set, it is possible to transform any formula into an equivalent one which does not contain any firstorder variable. More precisely, we consider now that formulas are built upon the atomic formulas:

X ⊆ Y, Sing(X), X = Y i, X = ǫ
using the logical connectives and second-order quantification only. Let us call this new syntax the restricted syntax.

These formulas are interpreted as expected. In particular Sing(X) holds true when X is a singleton set and X = Y i holds true when X and Y are singleton sets {s} and {t} respectively and s = ti. Let us write |= 2 the satisfaction relation for this new logic. Proposition 3.3.1. There is a translation T from WSkS formulas to the restricted syntax such that s 1 , . . . , s n , S 1 , . . . , S m |= φ(x 1 , . . . , x n , X 1 , . . . , X m ) if and only if

{s 1 }, . . . , {s n }, S 1 , . . . , S m |= 2 T (φ)(X x1 , . . . , X xn , X 1 , . . . , X m )
Conversely, there is a translation T ′ from the restricted syntax to WSkS such that

S 1 , . . . , S m |= T ′ (φ)(X 1 , . . . , X m ) if and only if S 1 , . . . , S m |= 2 φ(X 1 , . . . , X m ))
Proof. First, according to the previous section, we can restrict our attention to formulas built upon the only atomic formulas t ∈ X and s = t. Then, each atomic formula is flattened according to the rules:

ti ∈ X → ∃y.y = ti ∧ y ∈ X xi = yj → ∃z.z = xi ∧ z = yj ti = s → ∃z.z = t ∧ zi = s
The last rule assumes that t is not a variable. Next, we associate a second-order variable X y to each first-order variable y and transform the flat atomic formulas:

T (y ∈ X) def = X y ⊆ X T (y = xi) def = X y = X x i T (x = ǫ) def = X x = ǫ T (x = y) def = X x = X y
The translation of other flat atomic formulas can be derived from these ones, in particular when exchanging the arguments of =. Now, T (φ ∨ ψ)

def = T (φ) ∨ T (ψ), T (¬(φ)) def = ¬T (φ), T (∃X.φ) def = ∃X.T (φ), T (∃y.φ) def = ∃X y .
Sing(X y )∧T (φ). Finally, we add Sing(X x ) for each free variable x.

For the converse, the translation T ′ has been given in the previous section, except for the atomic formulas X = Y i (which becomes Sing(X) ∧ Sing(Y ) ∧ ∃x∃y.x ∈ X ∧ y ∈ Y ∧ x = yi) and X = ǫ (which becomes Sing(X) ∧ ∀x.x ∈ X ⇒ x = ǫ).

Definable Sets are Recognizable Sets

Definition 3.3.2. A set L of tuples of finite sets of words is definable in WSkS if there is a formula φ of WSkS with free variables X 1 , . . . , X n such that

(S 1 , . . . , S n ) ∈ L if and only if S 1 , . . . , S n |= φ.
Each tuple of finite sets of words S 1 , . . . , S n ⊆ {1, . . . , k} * is identified to a finite tree (S 1 , . . . , S n ) ∼ over the alphabet {0, 1, ⊥} n where any string containing a 0 or a 1 is k-ary and ⊥ n is a constant symbol, in the following way3 : is the set of prefixes of words in some S i . The symbol at position p:

Pos((S 1 , . . . , S n ) ∼ ) def = {ǫ} ∪ {pi | ∃p ′ ∈ n j=1 S j , p ≤ p ′ , i ∈ {1, . . . , k}}
(S 1 , . . . , S n ) ∼ (p) = α 1 . . . α n
is defined as follows: Proof. By Proposition 3.3.1, if L is definable in WSkS, it is also definable with the restricted syntax. We are now going to prove the lemma by induction on the structure of the formula φ which defines L. We assume that all variables in φ are bound at most once in the formula and we also assume a fixed total ordering ≤ on the variables. If ψ is a subformula of φ with free variables

• α i = 1 if and only if p ∈ S i • α i = 0 if and only if p / ∈ S i and ∃p ′ ∈ S i and ∃p ′′ .p • p ′′ = p ′ • α i =⊥ otherwise.
Y 1 < • • • < Y n , we construct an automaton A ψ working on the alphabet {0, 1, ⊥} n such that (S 1 , . . . , S n ) |= 2 ψ if and only if (S 1 , . . . , S n ) ∼ ∈ L(A ψ ).
The base case consists in constructing an automaton for each atomic formula. (We assume here that k = 2 for simplicity, but this works of course for arbitrary k).

The automaton A Sing(X) is depicted on Figure 3.8. The only final state is q ′ . The automaton A X⊆Y (with X < Y ) is depicted on Figure 3.9. The only state (which is also final) is q.

The automaton A X=Y 1 is depicted on Figure 3.10. The only final state is q ′′ . An automaton for X = Y 2 is obtained in a similar way.

The automaton for X = ǫ is depicted on Figure 3.11 (the final state is q ′ ). Now, for the induction step, we have several cases to investigate:

⊥ → q 0 q q ′ → q ′ 1 q q → q ′ 0 q ′ q → q ′ Figure 3.8:
The automaton for Sing(X)

⊥⊥ → q 01 q q → q 00 q q → q 11 q q → q ⊥0 q q → q ⊥1 q q → q Figure 3.9: The automaton for X ⊆ Y ⊥⊥ → q 01 q ′ q → q ′′ 1⊥ q q → q ′ 00 q ′′ q → q ′′ 00 q q ′′ → q ′′ Figure 3.10: The automaton for X = Y 1 ⊥ → q 1 q q → q ′ Figure 3.11: The automaton for X = ǫ • If φ is a disjunction φ 1 ∨ φ 2
, where X i is the set of free variables of φ i respectively. Then we first cylindrify the automata for φ 1 and φ 2 in such a way that they recognize the solutions of φ 1 and φ 2 , with free variables X 1 ∪ X 2 . (See Proposition 3.2.12.) More precisely, let

X 1 ∪ X 2 = {Y 1 , . . . , Y n } with Y 1 < . . . < Y n .
Then we successively apply the ith cylindrification to the automaton of φ 1 (resp. φ 2 ) for the variables Y i which are not free in φ 1 (resp. φ 2 ). Then the automaton A φ is obtained as the union of these automata. (Rec is closed under union by Proposition 3.2.9).

• If φ is a formula ¬φ 1 then A φ is the automaton accepting the complement of A φ1 . (See Theorem 1.3.1)

• If φ is a formula ∃X.φ 1 , assume that X corresponds to the ith component. Then A φ is the i th projection of A φ1 (see Proposition 3.2.12).

Example 3.3.5. Consider the following formula, with free variables X, Y :

∀x, y.(x ∈ X ∧ y ∈ Y ) ⇒ ¬(x ≥ y)
We want to compute an automaton which accepts the assignments to X, Y satisfying the formula. First, write the formula as

¬∃X 1 , Y 1 .X 1 ⊆ X ∧ Y 1 ⊆ Y ∧ G(X 1 , Y 1 )
where G(X 1 , Y 1 ) expresses that X 1 is a singleton x, Y 1 is a singleton y and x ≥ y. We can use the definition of ≥ as a WS2S formula, or compute directly the automaton, yielding ⊥⊥ → q 11(q, q) → q 2 1 ⊥ (q, q) → q 1 0 ⊥ (q, q 1 ) → q 1 0 ⊥ (q 1 , q) → q 1 01(q 1 , q) → q 2 01(q, q 2 ) → q 2 00(q 2 , q) → q 2 00(q, q 2 ) → q 2 where q 2 is the only final state. Now, using cylindrification, intersection, projection and negation we get the following automaton (intermediate steps yield large automata which would require a full page to be displayed):

⊥⊥ → q 0 ⊥ 1(q 0 , q 0 ) → q 1 1 ⊥ (q 0 , q 0 ) → q 2 ⊥ 0(q 0 , q 1 ) → q 1 ⊥ 0(q 1 , q 0 ) → q 1 ⊥ 0(q 1 , q 1 ) → q 1 0 ⊥ (q 0 , q 2 ) → q 2 0 ⊥ (q 2 , q 0 ) → q 2 0 ⊥ (q 2 , q 2 ) → q 2 ⊥ 1(q 0 , q 1 ) → q 1 ⊥ 1(q 1 , q 0 ) → q 1 ⊥ 1(q 1 , q 1 ) → q 1 1 ⊥ (q 0 , q 2 ) → q 2
1 ⊥ (q 2 , q 0 ) → q 2 1 ⊥ (q 2 , q 2 ) → q 2 10(q 1 , q 0 ) → q 3 10(q 0 , q 1 ) → q 3 10(q 1 , q 1 ) → q 3 10(q 1 , q 2 ) → q 3 10(q 2 , q 1 ) → q 3 10(q i , q 3 ) → q 3 10(q 3 , q i ) → q 3 00(q i , q 3 ) → q 3 00(q 3 , q i ) → q 3

where i ranges over {0, 1, 2, 3} and q 3 is the only final state.

Recognizable Sets are Definable

We have seen in section 3.

∃Y q1 , . . . , ∃Y q l . Term(X, X f1 , . . . , X fm ) ∧ Partition(X, Y q1 , . . . , Y q l ) ∧ q∈Q f ǫ ∈ Y q ∧ ∀x. f ∈F ′ q∈Q (x ∈ X f ∧ x ∈ Y q ⇒ f (q1,...,qs)→q∈T s i=1 xi ∈ Y qi
This formula basically expresses that there is a successful run of the automaton on [t 1 , . . . , t n ]: the variables Y qi correspond to sets of positions which are labeled with q i by the run. They should be a partition of the set of positions. The root has to be labeled with a final state (the run is successful). Finally, the last line expresses local properties that have to be satisfied by the run: if the sons xi of a position x are labeled with q 1 , . . . , q n respectively and x is labeled with symbol f and state q, then there should be a transition f (q 1 , . . . , q n ) → q in the set of transitions.

We have to prove two inclusions. First assume that (S, S 1 , . . . , S m ) |= 2 φ. Then (S, S 1 , . . . , S m ) |= Term(X, X f1 , . . . , X fm ), hence there is a term u ∈ T (F ′ ) whose set of position is S and such that for all i, S i is the set of positions labeled with f i . Now, there is a partition E q1 , . . . , E q l of S which satisfies

S, S 1 , . . . , S m , E q1 , . . . , E q l |= ∀x. f ∈F ′ q∈Q (x ∈ X f ∧ x ∈ Y q ) ⇒ f (q1,...,qs)→q∈T s i=1 xi ∈ Y qi
This implies that the labeling E q1 , . . . , E q l is compatible with the transition rules: it defines a run of the automaton. Finally, the condition that the root ε belongs to E q f for some final state q f implies that the run is successful, hence that u is accepted by the automaton.

Conversely, if u is accepted by the automaton, then there is a successful run of A on u and we can label its positions with states in such a way that this labeling is compatible with the transition rules in A.

Putting together Lemmas 3.3.4 and 3.3.6, we can state the following slogan (which is not very precise; the precise statements are given by the lemmas):

Theorem 3.3.7. L is definable if and only if L is in Rec.
And, as a consequence:

Theorem 3.3.8 ([TW68]). WSkS is decidable.
Proof. Given a formula φ of WSkS, by Lemma 3.3.4, we can compute a finite tree automaton which has the same solutions as φ. Now, assume that φ has no free variable. Then the alphabet of the automaton is empty (or, more precisely, it contains the only constant ⊤ according to what we explained in Section 3.2.4). Finally, the formula is valid iff the constant ⊤ is in the language, i.e. iff there is a rule ⊤ -→ q f for some q f ∈ Q f .

Complexity Issues

We have seen in chapter 1 that, for finite tree automata, emptiness can be decided in linear time (and is PTIME-complete) and that inclusion is EXPTIMEcomplete. Considering WSkS formulas with a fixed number of quantifier alternations N , the decision method sketched in the previous section will work in time which is a tower of exponentials, the height of the tower being O(N ). This is so because each time we encounter a sequence ∀X, ∃Y , the existential quantification corresponds to a projection, which may yield a non-deterministic automaton, even if the input automaton was deterministic. Then the elimination of ∀X requires a determinization (because we have to compute a complement automaton) which requires in general exponential time and exponential space.

Actually, it is not really possible to do much better since, even when k = 1, deciding a formula of WSkS requires non-elementary time, as shown in [START_REF] Stockmeyer | Word problems requiring exponential time[END_REF].

Extensions

There are several extensions of the logic, which we already mentioned: though quantification is restricted to finite sets, we may consider infinite sets as models (this is what is often called weak second-order monadic logic with k successors and also written WSkS), or consider quantifications on arbitrary sets (this is the full SkS).

These logics require more sophisticated automata which recognize sets of infinite terms. The proof of Theorem 3.3.8 carries over these extensions, with the provision that the devices enjoy the required closure and decidability properties. But this becomes much more intricate in the case of infinite terms. Indeed, for infinite terms, it is not possible to design bottom-up tree automata. We have to use a top-down device. But then, as mentioned in chapter 1, we cannot expect to reduce the non-determinism. Now, the closure by complement becomes problematic because the usual way of computing the complement uses reduction of non-determinism as a first step.

It is out of the scope of this book to define and study automata on infinite objects (see [START_REF] Thomas | Handbook of Theoretical Computer Science, volume B, chapter Automata on Infinite Objects[END_REF] instead). Let us simply mention that the closure under complement for Rabin automata which work on infinite trees (this result is known as Rabin's Theorem) is one of the most difficult results in the field.

Examples of Applications

Terms and Sorts

The most basic example is what is known in the algebraic specification community as order-sorted signatures. These signatures are exactly what we called bottom-up tree automata. There are only differences in the syntax. For instance, the following signature:

SORTS:Nat, int SUBSORTS : Nat ≤ int FUNCTION DECLARATIONS: 0 : → Nat + : Nat × Nat → Nat s : Nat → Nat p : Nat → int + : int × int → int abs : int → Nat f act : Nat → Nat . . .
is an automaton whose states are Nat, int with an ǫ-transition from Nat to int and each function declaration corresponds to a transition of the automaton. For example +(Nat, Nat) → Nat. The set of well-formed terms (as in the algebraic specification terminology) is the set of terms recognized by the automaton in any state.

More general typing systems also correspond to more general automata (as will be seen e.g. in the next chapter). This correspondence is not surprising; types and sorts are introduced in order to prevent run-time errors by some "abstract interpretation" of the inputs. Tree automata and tree grammars also provide such a symbolic evaluation mechanism. For other applications of tree automata in this direction, see e.g. chapter 5.

From what we have seen in this chapter, we can go beyond simply recognizing the set of well-formed terms. Consider the following sort constraints (the alphabet F of function symbols is given):

The set of sort expressions SE is the least set such that

• SE contains a finite set of sort symbols S, including the two particular symbols ⊤ S and ⊥ S . The atomic formulas are expressions t ∈ s where t ∈ T (F, X ) and s ∈ SE. The formulas are arbitrary first-order formulas built on these atomic formulas.

• If s 1 , s 2 ∈ SE, then s 1 ∨ s 2 , s 1 ∧ s 2 , ¬s 1 are in SE • If s 1 , . . . ,
These formulas are interpreted as follows: we are giving an order-sorted signature (or a tree automaton) whose set of sorts is S. We define the interpretation [[•]] S of sort expressions as follows:

• if s ∈ S, [[s]] S is the set of terms in T (F) that are accepted in state s. • [[⊤ S ]] S = T (F) and [[⊥ S ]] S = ∅ • [[s 1 ∨ s 2 ]] S = [[s 1 ]] S ∪ [[s 2 ]] S , [[s 1 ∧ s 2 ]] S = [[s 1 ]] S ∩ [[s 2 ]] S , [[¬s]] S = T (F) \ [[s]] S • [[f (s 1 , . . . , s n )]] S = {f (t 1 , . . . , t n ) | t 1 ∈ [[s 1 ]] S , . . . t n ∈ [[s n ]] S }
An assignment σ, mapping variables to terms in T (F), satisfies t ∈ s (we also say that σ is a solution of t ∈ s) if tσ ∈ [[s]] S . Solutions of arbitrary formulas are defined as expected. Then Theorem 3.4.1. Sort constraints are decidable.

The decision technique is based on automata computations, following the closure properties of Rec × and a decomposition lemma for constraints of the form f (t 1 , . . . , t n ) ∈ s.

More results and applications of sort constraints are discussed in the bibliographic notes.

The Encompassment Theory for Linear Terms

Definition 3.4.2. If t ∈ T (F, X ) and u ∈ T (F), u encompasses t if there is a substitution σ such that tσ is a subterm of u. (See Figure 3.12.) This binary relation is denoted t • ¢u or, seen as a unary relation on ground terms parametrized by t:

• ¢ t (u).
Encompassment plays an important role in rewriting: a term t is reducible by a term rewriting system R if and only if t encompasses at least one left hand side of a rule.

The relationship with tree automata is given by the proposition:

Proposition 3.4.3. If t is linear, then the set of terms that encompass t is recognized by a NFTA of size O(|t|).

Proof. To each non-variable subterm v of t we associate a state q v . In addition we have a state q ⊤ . The only final state is q t . The transition rules are:

• f (q ⊤ , . . . , q ⊤ ) → q ⊤ for all function symbols.

• f (q t1 , . . . , q tn ) → q f (t1,...,tn) if f (t 1 , . . . , t n ) is a subterm of t and q ti is actually q ⊤ is t i is a variable.

• f (q ⊤ . . . , q ⊤ , q t , q ⊤ , . . . , q ⊤ ) → q t for all function symbols f whose arity is at least 1.

The proof that this automaton indeed recognizes the set of terms that encompass t is left to the reader.

Note that the automaton may be non deterministic. With a slight modification, if u is a linear term, we can construct in linear time an automaton which accepts the set of instances of u (this is also left as an exercise in chapter 1, exercise 1.9). Corollary 3.4.4. If R is a term rewriting system whose all left members are linear, then the set of reducible terms in T (F), as well as the set N F of irreducible terms in T (F) are recognized by a finite tree automaton.

Proof. This is a consequence of Theorem 1.3.1.

The theory of reducibility associated with a set of term S ⊆ T (F, X ) is the set of first-order formulas built on the unary predicate symbols E t , t ∈ S and interpreted as the set of terms encompassing t.

Theorem 3.4.5. The reducibility theory associated with a set of linear terms is decidable.

Proof. By proposition 3.4.3, the set of solutions of an atomic formula is recognizable, hence definable in WSkS by Lemma 3.3.6. Hence, any first-order formula built on these atomic predicate symbols can be translated into a (second-order) formula of WSkS which has the same models (up to the coding of terms into tuples of sets). Then, by Theorem 3.3.8, the reducibility theory associated with a set of linear terms is decidable.

Note however that we do not use here the full power of WSkS. Actually, the solutions of a Boolean combination of atomic formulas are in Rec × . So, we cannot apply the complexity results for WSkS here. (In fact, the complexity of the reducibility theory is unknown so far).

Let us simply show an example of an interesting property of rewrite systems which can be expressed in this theory. Definition 3.4.6. Given a term rewriting system R, a term t is ground reducible if, for every ground substitution σ, tσ is reducible by R.

Note that a term might be irreducible and still ground reducible. For instance consider the alphabet F = {0, s} and the rewrite system R = {s(s(0)) → 0}. Then the term s(s(x)) is irreducible by R, but all its ground instances are reducible.

It turns out that ground reducibility of t is expressible in the encompassment theory by the formula:

∀x.( • ¢ t (x) ⇒ n i=1 • ¢ li (x))
Where l 1 , . . . , l n are the left hand sides of the rewrite system. By Theorem 3.4.5, if t, l 1 , . . . , l n are linear, then ground reducibility is decidable. Actually, it has been shown that this problem is EXPTIME-complete, but is beyond the scope of this book to give the proof.

The First-order Theory of a Reduction Relation: the

Case Where no Variables are Shared

We consider again an application of tree automata to a decision problem in logic and term rewriting. Consider the following logical theory. Let L be the set of all first-order formulas using no function symbols and a single binary predicate symbol →.

Given a rewrite system R, interpreting → as -→ R , yields the theory of one step rewriting; interpreting → as * -→ R yields the theory of rewriting.

Both theories are undecidable for arbitrary R. They become however decidable if we restrict our attention to term rewriting systems in which each variable occurs at most once. Basically, the reason is given by the following: Proposition 3.4.7. If R is a linear rewrite system such that left and right members of the rules do not share variables, then * -→ R is recognized by a GTT.

Proof. As in the proof of Proposition 3.4.3, we can construct in linear time a (non-deterministic) automaton which accepts the set of instances of a linear term. For each rule l i → r i we can construct a pair (A i , A ′ i ) of automata which respectively recognize the set of instances of l i and the set of instances of r i . Assume that the sets of states of the A i s are pairwise disjoint and that each A i has a single final state q i f . We may assume a similar property for the A ′ i s: they do not share states and for each i, the only common state between A i and A ′ i is q i f (the final state for both of them). Then A (resp. A ′ ) is the union of the A i s: the states are the union of all sets of states of the A i s (resp. A ′ i s), transitions and final states are also unions of the transitions and final states of each individual automaton.

We claim that (A, A ′ ) defines a GTT whose closure by iteration (A * , A ′ * ) (which is again a GTT according to Theorem 3.2.14

) accepting * -→ R . For, assume first that u p ----→ li→ri v. Then u| p is an instance l i σ of l i , hence is accepted in state q i f . v| p is an instance r i θ of r i , hence accepted in state q i f . Now, v = u[r i θ] p , hence (u, v) is accepted by the GTT (A, A ′ ). It follows that if u * -→ R v, (u, v) is accepted by (A * , A ′ * ). Conversely, assume that (u, v) is accepted by (A, A ′ ), then u * -→ A C[q 1 , . . . , q n ] p1,...,pn * ← -- A ′ v
Moreover, each q i is some state q j f , which, by definition, implies that u| pi is an instance of l j and v| pi is an instance of r j . Now, since l j and r j do not share variables, for each i, u| pi -→

R v| pi . Which implies that u * -→ R v. Now, if (u, v) is accepted by (A * , A ′ * ), u can be rewritten in v by the transitive closure of * -→ R , which is * -→ R itself.
Theorem

Reduction Strategies

So far, we gave examples of first-order theories (or constraint systems) which can be decided using tree automata techniques. Other examples will be given in the next two chapters. We give here another example of application in a different spirit: we are going to show how to decide the existence (and compute) "optimal reduction strategies" in term rewriting systems. Informally, a reduction sequence is optimal when every redex which is contracted along this sequence has to be contracted in any reduction sequence yielding a normal form.

For example, if we consider the rewrite system {x ∨ ⊤ → ⊤; ⊤ ∨ x → ⊤}, there is no optimal sequential reduction strategy in the above sense since, given an expression e 1 ∨ e 2 , where e 1 and e 2 are unevaluated, the strategy should specify which of e 1 or e 2 has to be evaluated first. However, if we start with e 1 , then maybe e 2 will reduce to ⊤ and the evaluation step on e 1 was unnecessary. Symmetrically, evaluating e 2 first may lead to unnecessary computations. An interesting question is to give sufficient criteria for a rewrite system to admit optimal strategies and, in case there is such a strategy, give it explicitly. The formalization of these notions was given by Huet and Lévy in [HL91] who introduce the notion of sequentiality. We give briefly a summary of (part of) their definitions.

F is a fixed alphabet of function symbols and F Ω = F ∪ {Ω} is the alphabet F enriched with a new constant Ω (whose intended meaning is "unevaluated term").

We define on T (F Ω ) the relation "less evaluated than" as:

u ⊑ v if and only if either u = Ω or else u = f (u 1 , . . . , u n ), v = f (v 1 , . . . , v n ) and for all i, u i ⊑ v i Definition 3.4.9. A predicate P on T (F Ω ) is monotonic if u ∈ P and u ⊑ v implies v ∈ P .
For example, a monotonic predicate of interest for rewriting is the predicate N R : t ∈ N R if and only if there is a term u ∈ T (F) such that u is irreducible by R and t * -→ R u.

Definition 3.4.10. Let P be a monotonic predicate on T (F Ω ). If R is a term rewriting system and t ∈ T (F Ω ), a position p of Ω in t is an index for P if for all terms u ∈ T (F Ω ) such that t ⊑ u and u ∈ P , then u| p = Ω In other words: it is necessary to evaluate t at position p in order to have the predicate P satisfied.

Example 3.4.11. Let R = {f (g(x), y) → g(f (x, y)); f (a, x) → a; b → g(b)}.
Then 1 is an index of f (Ω, Ω) for N R : any reduction yielding a normal form without Ω will have to evaluate the term at position 1. More formally, every term f (t 1 , t 2 ) which can be reduced to a term in T (F) in normal form satisfies t 1 = Ω. On the contrary, 2 is not an index of

f (Ω, Ω) since f (a, Ω) * -→ R a.
Definition 3.4.12. A monotonic predicate P is sequential if every term t such that:

• t / ∈ P
• there is u ∈ T (F), t ⊑ u and u ∈ P has an index for P .

If N R is sequential, the reduction strategy consisting of reducing an index is optimal for non-overlapping and left linear rewrite systems. Now, the relationship with tree automata is given by the following result:

Theorem 3.4.13. If P is definable in WSkS, then the sequentiality of P is expressible as a WSkS formula.

The proof of this result is quite easy: it suffices to translate directly the definitions.

For instance, if R is a rewrite system whose left and right members do not share variables, then N R is recognizable (by Propositions 3.4.7 and 3.2.7), hence definable in WSkS by Lemma 3.3.6 and the sequentiality of N R is decidable by Theorem 3.4.13.

In general, the sequentiality of N R is undecidable. However, one can notice that, if R and R ′ are two rewrite systems such that -→ R ⊆ --→ R ′ , then a position p which is an index for R ′ is also an index for R. (And thus, R is sequential whenever R ′ is sequential).

For instance, we may approximate the term rewriting system, replacing all right hand sides by a new variable which does not occur in the corresponding left member. Let R? be this approximation and N ? be the predicate N R? . (This is the approximation considered by Huet and Lévy).

Another, refined, approximation consists in renaming all variables of the right hand sides of the rules in such a way that all right hand sides become linear and do not share variables with their left hand sides. Let R ′ be such an approximation of R. The predicate N R ′ is written N V . are recognized by GTTs. On the other hand, the set of terms in normal form for a left linear rewrite system is recognized by a finite tree automaton (see Corollary 3.4.4). By Proposition 3.2.7 and Lemma 3.3.6, all these predicates are definable in WSkS. Then N ? and N V are also definable in WSkS. For instance for NV:

N V (t) def = ∃u.t * --→ R ′ u ∧ u ∈ N F
Then, by Theorem 3.4.13, the sequentiality of N ? and N V are definable in WSkS and by Theorem 3.3.8 they are decidable.

Application to Rigid E-unification

Given a finite (universally quantified) set of equations E, the classical problem of E-unification is, given an equation s = t, find substitutions σ such that E |= sσ = tσ. The associated decision problem is to decide whether such a substitution exists. This problem is in general unsolvable: there are decision procedures for restricted classes of axioms E.

The simultaneous rigid E-unification problem is slightly different: we are still giving E and a finite set of equations s i = t i and the question is to find a substitution σ such that

|= ( e∈E eσ) ⇒ ( n i=1 s i σ = t i σ)
The associated decision problem is to decide the existence of such a substitution.

The relevance of such questions to automated deduction is very briefly described in the bibliographic notes. We want here to show how tree automata help in this decision problem.

Simultaneous rigid E-unification is undecidable in general. However, for the one variable case, we have: Theorem 3.4.15. The simultaneous rigid E-unification problem with one variable is EXPTIME-complete.

The EXPTIME membership is a direct consequence of the following lemma, together with closure and decision properties for recognizable tree languages. The EXPTIME-hardness is obtained by reduction the intersection non-emptiness problem, see Theorem 1.7.5).

Lemma 3.4.16. The solutions of a rigid E-unification problem with one variable are recognizable by a finite tree automaton.

Proof. (sketch) Assume that we have a single equation s = t. Let x be the only variable occurring in E, s = t and Ê be the set E in which x is considered as a constant. Let R be a canonical ground rewrite system (see e.g. [START_REF] Dershowitz | Handbook of Theoretical Computer Science, volume B, chapter Rewrite Systems[END_REF]) associated with Ê (and for which x is minimal). We define v as x if s and t have the same normal form w.r.t. R and as the normal form of xσ w.r.t. R otherwise.

Assume Eσ |= sσ = tσ. If v ≡ x, we have Ê ∪ {x = v} |= x = xσ. Hence Ê ∪ {x = v} |= s = t in any case. Conversely, assume that Ê ∪ {x = v} |= s = t. Then Ê ∪ {x = xσ} |= s = t, hence Eσ |= sσ = tσ.
Now, assume v ≡ x. Then either there is a subterm u of an equation in Ê such that Ê |= u = v or else R 1 = R ∪ {v → x} is canonical. In this case, from Ê ∪ {v = x} |= s = t, we deduce that either Ê |= s = t (and v ≡ x) or there is a subterm u of s, t such that Ê |= v = u. we can conclude that, in all cases, there is a subterm

u of E ∪ {s = t} such that Ê |= u = v.
To summarize, σ is such that

Eσ |= sσ = tσ iff there is a subterm u of E ∪ {s = t} such that Ê |= u = xσ and Ê ∪ {u = x} |= s = t.
If we let T be the set of subterms u of E ∪ {s = t} such that Ê ∪ {u = x} |= s = t, then T is finite (and computable in polynomial time). The set of solutions is then * ---→ R -1 (T ), which is a recognizable set of trees, thanks to Proposition 3.4.7.

Further comments and references are given in the bibliographic notes.

Application to Higher-order Matching

We give here a last application (but the list is not closed!), in the typed lambdacalculus.

To be self-contained, let us first recall some basic definitions in typed lambda calculus.

The set of types of the simply typed lambda calculus is the least set containing the constant o (basic type) and such that τ → τ ′ is a type whenever τ and τ ′ are types.

Using the so-called Curryfication, any type τ → (τ ′ → τ ′′ ) is written τ, τ ′ → τ ′′ . In this way all non-basic types are of the form τ 1 , . . . , τ n → o with intuitive meaning that this is the type of functions taking n arguments of respective types τ 1 , . . . , τ n and whose result is a basic type o.

The order of a type τ is defined by:

• O(o) = 1 • O(τ 1 , . . . , τ n → o) = 1 + max{O(τ 1 ), . . . , O(τ n )}
Given, for each type τ a set of variables X τ of type τ and a set C τ of constants of type τ , the set of terms (of the simply typed lambda calculus) is the least set Λ such that: The order of a term t is the order of its type τ (t). The set of free variables Var (t) of a term t is defined by:

• x ∈ X τ is a term of type τ • c ∈ C τ is a term of type τ • If x 1 ∈ X τ1 , . . . ,
• Var (x) = {x} if x is a variable • Var (c) = ∅ if c is a constant • Var (λx 1 , . . . , x n : t) = Var (t) \ {x 1 , . . . , x n } • Var (t(u 1 , . . . , u n )) = Var (t) ∪ Var (u 1 ) ∪ . . . ∪ Var (u n )
Terms are always assumed to be in η-long form, i.e. they are assumed to be in normal form with respect to the rule:

(η) t → λx 1 , . . . , x n .t(x 1 , . . . , x n ) if τ (t) = τ 1 , . . . τ n → τ and x i ∈ X τi \ Var (t) for all i
We define the α-equivalence = α on Λ as the least congruence relation such that: λx 1 , . . . , x n : t = α λx ′ 1 . . . , x ′ n : t ′ when • t ′ is the term obtained from t by substituting for every index i, every free occurrence of x i with x ′ i . • There is no subterm of t in which, for some index i, both x i and x ′ i occur free.

In the following, we consider only lambda terms modulo α-equivalence. Then we may assume that, in any term, any variable is bounded at most once and free variables do not have bounded occurrences.

The β-reduction is defined on Λ as the least binary relation -→

β such that • λx 1 , . . . , x n : t(t 1 , . . . , t n ) -→ β t{x 1 ←t 1 , . . . , x n ←t n } • for every context C, C[t] -→ β C[u] whenever t -→ β u
It is well-known that βη-reduction is terminating and confluent on Λ and, for every term t ∈ Λ, we let t ↓ be the unique normal form of t.

A matching problem is an equation s = t where s, t ∈ Λ and Var (t) = ∅. A solution of a matching problem is a substitution σ of the free variables of t such that sσ ↓= t ↓.

Whether or not the matching problem is decidable is an open question at the time we write this book. However, it can be decided when every free variable occurring in s is of order less or equal to 4. We sketch here how tree automata may help in this matter. We will consider only two special cases here, leaving the general case as well as details of the proofs as exercises (see also bibliographic notes).

First consider a problem

(1)

x(s 1 , . . . , s n ) = t
where x is a third order variable and s 1 , . . . , s n , t are terms without free variables.

The first result states that the set of solutions is recognizable by a Pautomaton. P-automata are a slight extension of finite tree automata: we assume here that the alphabet contains a special symbol P. Then a term u is accepted by a P-automaton A if and only if there is a term v which is accepted (in the usual sense) by A and such that u is obtained from v by replacing each occurrence of the symbol P with a term (of appropriate type). Note that two distinct occurrences of P need not to be replaced with the same term.

We consider the automaton A s1,...,sn,t defined by: F consists of all symbols occurring in t plus the variable symbols x 1 , . . . , x n whose types are respectively the types of s 1 , . . . , s n and the constant P.

The set of states Q consists of all subterms of t, which we write q u (instead of u) and a state q 2 . In addition, we have the final state q f . The transition rules ∆ consist in

• The rules f (q t1 , . . . , q tn ) → q f (t1,...,tn)

each time q f (t1,...,tn) ∈ Q

• For i = 1, . . . , n, the rules

x i (q t1 , . . . , q tn ) → q u
where u is a subterm of t such that s i (t 1 , . . . , t n ) ↓= u and t j = P whenever s i (t 1 , . . . , t j-1 , P, t j+1 , . . . , t n ) ↓= u.

• the rule λx 1 , . . . , λx n .q t → q f Theorem 3.4.17. The set of solutions of (1) (up to α-conversion) is accepted by the P-automaton A s1,...,sn,t .

More about this result, its proof and its extension to fourth order will be given in the exercises (see also bibliographic notes). Let us simply give an example.

Example 3.4.18. Let us consider the interpolation equation x(λy 1 λy 2 .y 1 , λy 3 .f (y 3 , y 3 )) = f (a, a)

where y 1 , y 2 are assumed to be of base type o. Then F = {a, f, x 1 , x 2 , P o }. Q = {q a , q f (a,a) , q 2o , q f } and the rules of the automaton are: a → q a f (q a , q a ) → q f (a,a) P o → q 2o

x 1 (q a , q 2o ) → q a x 1 (q f (a,a) , q 2o ) → q f (a,a)

x 2 (q a ) → q f (a,a) λx 1 λx 2 .q f (a,a) → q f For instance the term λx 1 λx 2 .x 1 (x 2 (x 1 (x 1 (a, P o ), P o )), P o ) is accepted by the automaton:

λx 1 λx 2 .x 1 (x 2 (x 1 (x 1 (a, P o ), P o )), P o ) * -→ A λx 1 λx 2 .x 1 (x 2 (x 1 (x 1 (q a , q 2o ), q 2o )), q 2o ) -→ A λx 1 λx 2 .x 1 (x 2 (x 1 (q a , q 2o )), q 2o ) -→ A λx 1 λx 2 .x 1 (x 2 (q a ), q 2o ) -→ A λx 1 λx 2 .x 1 (q f (a,a) , q 2o ) -→ A λx 1 λx 2 .q f (a,a) -→ A q f
And indeed, for every terms t 1 , t 2 , t 3 , λx 1 λx 2 .x 1 (x 2 (x 1 (x 1 (a, t 1 ), t 2 )), t 3 ) is a solution of the interpolation problem.

Exercises

Exercise 3.1. Let F be the alphabet consisting of finitely many unary function symbols a1, . . . , an and a constant 0.

1. Show that the set S of pairs (of words) {(a n 1 (a1(a2(a p 2 (0)))), a n 1 (a p 2 (0))) | n, p ∈ N} is in Rec. Show that S * is not in Rec, hence that Rec is not closed under transitive closure.

2. More generally, show that, for any finite rewrite system R (on the alphabet F !), the reduction relation -→ R is in Rec.

3. Is there any hope to design a class of tree languages which contains Rec, which is closed by all Boolean operations and by transitive closure and for which emptiness is decidable? Why?

Exercise 3.2. Show that the set of pairs

{(t, f (t, t ′ )) | t, t ′ ∈ T (F )} is not in Rec.
Exercise 3.3. Show that if a binary relation is recognized by a GTT, then its inverse is also recognized by a GTT.

Exercise 3.4. Give an example of two relations that are recognized by GTTs and whose union is not recognized by any GTT.

Similarly, show that the class of relations recognized by a GTT is not closed by complement. Is the class closed by intersection? Exercise 3.5. Give an example of a n-ary relation such that its ith projection followed by its ith cylindrification does not give back the original relation. On the contrary, show that ith cylindrification followed by ith projection gives back the original relation.

A • B def = {(u, v)/∃(u1, v1) ∈ A, (u2, v2) ∈ Bu = u1.u2, v = v1.v2}
Similarly, we write (in this exercise!)

A * = {(u, v)/∃(u1, v1) ∈ A, . . . , (un, vn) ∈ A, u = u1 . . . un, v = v1 . . . vn} 1. Given A, B ∈ Rec, is A • B necessary in Rec? is A * necessary in Rec? Why?
2. Show that if A ∈ Rec preserves the length, then A * ∈ Rec.

Show that if

A, B ∈ Rec and A is of bounded delay, then A • B ∈ Rec.
4. The family of rational relations is the smallest set of subsets of T (F ) 2 which contains the finite subsets of T (F ) 2 and which is closed under union, concatenation (•) and * . Show that, if A is a bounded delay rational relation, then A ∈ Rec. Is the converse true?

Exercise 3.7. Let R0 be the rewrite system {x×0 → 0; 0×x → 0} and F = {0, 1, s, ×}

1. Construct explicitly the GTT accepting * --→ R 0 . 2. Let R1 = R0 ∪ {x × 1 → x}. Show that * --→ R 1
is is not recognized by a GTT.

3. Let R2 = R1 ∪ {1 × x → x × 1}. Using a construction similar to the transitive closure of GTTs, show that the set {t ∈ T (F )

| ∃u ∈ T (F ), t * --→ R 2 u, u ∈ N F }
where N F is the set of terms in normal form for R2 is recognized by a finite tree automaton.

Exercise 3.8. (*) More generally, prove that given any rewrite system {li → ri | 1 ≤ i ≤ n} such that 1. for all i, li and ri are linear 2. for all i, if x ∈ Var (li) ∩ Var (ri), then x occurs at depth at most one in li.

the set {t ∈ T (F ) | ∃u ∈ N F, t * -→ R
u} is recognized by finite tree automaton.

What are the consequences of this result? (See [START_REF] Jacquemard | Decidable approximations of term rewriting systems[END_REF] for details about this results and its applications. Also compare with Exercise 1.17, question 4.) Exercise 3.9. Show that the set of pairs {(f (t, t ′ ), t) | t, t ′ ∈ T (F )} is not definable in WSkS. (See also Exercise 3.2) Exercise 3.10. Show that the set of pairs of words {(w, w ′ ) | l(w) = l(w ′ )}, where l(x) is the length of x, is not definable in WSkS.

Exercise 3.11. Let F = {a1, . . . , an, 0} where each ai is unary and 0 is a constant. Consider the following constraint system: terms are built on F , the binary symbols ∩, ∪, the unary symbol ¬ and set variables. Formulas are conjunctions of inclusion constraints t ⊆ t ′ . The formulas are interpreted by assigning to variables finite subsets of T (F ), with the expected meaning for other symbols.

Show that the set of solutions of such constraints is in Rec2. What can we conclude? (*) What happens if we remove the condition on the ai's to be unary?

Exercise 3.12. Complete the proof of Proposition 3.2.16.

Exercise 3.13. Show that the subterm relation is not definable in WSkS. Given a term t Write a WSkS formula φt such that a term u |= φt if and only if t is a subterm of u.

Exercise 3.14. Define in SkS "X is finite". (Hint: express that every totally ordered subset of X has an upper bound and use König's lemma) Exercise 3.15. A tuple (t1, . . . , tn) ∈ T (F ) n can be represented in several ways as a finite sequence of finite sets. The first one is the encoding given in Section 3.3.6, overlapping the terms and considering one set for each tuple of symbols. A second one consists in having a tuple of sets for each component: one for each function symbol.

Compare the number of free variables which result from both codings when defining an n-ary relation on terms in WSkS. Compare also the definitions of the diagonal ∆ using both encodings. How is it possible to translate an encoding into the other one? Exercise 3.16. (*) Let R be a finite rewrite system whose all left and right members are ground.

1. Let Termination(x) be the predicate on T (F ) which holds true on t when there is no infinite sequence of reductions starting from t. Show that adding this predicate as an atomic formula in the first-order theory of rewriting, this theory remains decidable for ground rewrite systems.

2. Generalize these results to the case where the left members of R are linear and the right members are ground.

Exercise 3.17. The complexity of automata recognizing the set of irreducible ground terms.

1. For each n ∈ N, give a linear rewrite system Rn whose size is O(n) and such that the minimal automaton accepting the set of irreducible ground terms has a size O(2 n ).

2. Assume that for any two strict subterms s, t of left hand side(s) of R, if s and t are unifiable, then s is an instance of t or t is an instance of s. Show that there is a NFTA A whose size is linear in R and which accepts the set of irreducible ground terms.

Exercise 3.18. Prove Theorem 3.4.13.

Exercise 3.19. The Propositional Linear-time Temporal Logic. The logic PTL is defined as follows:

Syntax P is a finite set of propositional variables. Each symbol of P is a formula (an atomic formula). If φ and ψ are formulas, then the following are formulas:

φ ∧ ψ, φ ∨ ψ, φ → ψ, ¬φ, φUψ, Nφ, Lφ
Semantics Let P * be the set of words over the alphabet P . A word w ∈ P * is identified with the sequence of letters w(0)w(1) . . . w(|w| -1). w(i..j) is the word w(i) . . . w(j). The satisfaction relation is defined by: Let us recall that the language defined by a formula φ is the set of words w such that w |= φ.

• if p ∈ P ,
1. What it is the language defined by N(p1Up2) (with p1, p2 ∈ P )? 2. Give PTL formulas defining respectively P * p1P * , p * 1 , (p1p2) * . 3. Give a first-order WS1S formula (i.e. without second-order quantification and containing only one free second-order variable) which defines the same language as N(p1Up2)

4. For any PTL formula, give a first-order WS1S formula which defines the same language.

5. Conversely, show that any language defined by a first-order WS1S formula is definable by a PTL formula.

Exercise 3.20. About 3rd-order interpolation problems 1. Prove Theorem 3.4.17.

Show that the size of the automaton

Bibliographic Notes

The following bibliographic notes only concern the applications of the usual finite tree automata on finite trees (as defined at this stage of the book). We are pretty sure that there are many missing references and we are pleased to receive more pointers to the litterature.

GTT

GTT were introduced in [START_REF] Dauchet | Decidability of the confluence of ground term rewriting systems[END_REF] where they were used for the decidability of confluence of ground rewrite systems.

Automata and Logic

The development of automata in relation with logic and verification (in the sixties) is reported in [START_REF] Trakhtenbrot | Origins and metamorphoses of the trinity: Logic, nets, automata[END_REF]. This research program was explained by A.

Church himself in 1962 [START_REF] Church | Logic, arithmetic, automata[END_REF].

Milestones of the decidability of monadic second-order logic are the papers [Büc60] [START_REF] Rabin | Decidability of Second-Order Theories and Automata on Infinite Trees[END_REF]. Theorem 3.3.8 is proved in [START_REF] Thatcher | Generalized finite automata with an application to a decision problem of second-order logic[END_REF].

Surveys

There are numerous surveys on automata and logic. Let us mention some of them: M.O. Rabin [START_REF] Rabin | Handbook of Mathematical Logic, chapter Decidable theories[END_REF] surveys the decidable theories; W. Thomas [START_REF] Thomas | Handbook of Theoretical Computer Science, volume B, chapter Automata on Infinite Objects[END_REF][START_REF] Thomas | Languages, automata and logic[END_REF] provides an excellent survey of relationships between automata and logic.

Applications of tree automata to constraint solving

Concerning applications of tree automata, the reader is also referred to [START_REF] Dauchet | Rewriting and tree automata[END_REF] which reviews a number of applications of Tree automata to rewriting and constraints.

The relation between sorts and tree automata is pointed out in [START_REF] Comon | Inductive proofs by specification transformations[END_REF]. The decidability of arbitrary first-order sort constraints (and actually the first order theory of finite trees with equality and sort constraints) is proved in [START_REF] Comon | Equational formulae with membership constraints[END_REF].

More general sort constraints involving some second-order terms are studied in [START_REF] Comon | Completion of rewrite systems with membership constraints. Part II: Constraint solving[END_REF] with applications to a sort constrained equational logic [START_REF] Comon | Completion of rewrite systems with membership constraints. Part I: deduction rules[END_REF].

Sort constraints are also applied to specifications and automated inductive proofs in [START_REF] Bouhoula | Automata-driven automated induction[END_REF] where tree automata are used to represent some normal forms sets. They are used in logic programming and automated reasoning [START_REF] Frühwirth | Logic programs as types for logic programs[END_REF][START_REF] Ganzinger | Soft typing for ordered resolution[END_REF], in order to get more efficient procedures for fragments which fall into the scope of tree automata techniques. They are also used in automated deduction in order to increase the expressivity of (counter-)model constructions [START_REF] Peltier | Tree automata and automated model building[END_REF].

Concerning encompassment, M. Dauchet et al gave a more general result (dropping the linearity requirement) in [START_REF] Dauchet | Reduction properties and automata with constraints[END_REF]. We will come back to this result in the next chapter.

Application of tree automata to semantic unification

Rigid unification was originally considered by J. Gallier et al. [START_REF] Gallier | Theorem proving using rigid E-unification: Equational matings[END_REF] who showed that this is a key notion in extending the matings method to a logic with equality. Several authors worked on this problem and it is out of the scope of this book to give a list of references. Let us simply mention that the result of Section 3.4.5 can be found in [START_REF] Veanes | On simultaneous rigid E-unification[END_REF]. Further results on application of tree automata to rigid unification can be found in [DGN + 98], [START_REF] Ganzinger | Rigid reachability[END_REF].

Tree automata are also used in solving classical semantic unification problems. See e.g. [START_REF] Lugiez | Complement problems and tree automata in AC-like theories[END_REF] [KFK97] [Uri92]. For instance, in [START_REF] Kaji | Solving a unification problem under constrained substitutions using tree automata[END_REF], the idea is to capture some loops in the narrowing procedure using tree automata.

Application of tree automata to decision problems in term rewriting

Some of the applications of tree automata to term rewriting follow from the results on encompassment theory. Early works in this area are also mentioned in the bibliographic notes of Chapter 1. The reader is also referred to the survey [START_REF] Gilleron | Regular tree languages and rewrite systems[END_REF].

The first-order theory of the binary (many-steps) reduction relation w.r.t. a ground rewrite system has been shown decidable by. M. Dauchet and S. Tison [START_REF] Dauchet | The theory of ground rewrite systems is decidable[END_REF]. Extensions of the theory, including some function symbols, or other predicate symbols like the parallel rewriting or the termination predicate (Terminate(t) holds if there is no infinite reduction sequence starting from t), or fair termination etc... remain decidable [START_REF] Tison | Fair termination is decidable for ground systems[END_REF]. See also the exercises.

Both the theory of one step and the theory of many steps rewriting are undecidable for arbitrary R [START_REF] Treinen | The first-order theory of one-step rewriting is undecidable[END_REF].

Reduction strategies for term rewriting have been first studied by Huet and Lévy in 1978 [START_REF] Huet | Computations in orthogonal rewriting systems I[END_REF]. They show here the decidability of strong sequentiality for orthogonal rewrite systems. This is based on an approximation of the rewrite system which, roughly, only considers the left sides of the rules. Better approximation, yielding refined criteria were further proposed in [START_REF] Oyamaguchi | NV-sequentiality: a decidable condition for callby-need computations in term rewriting systems[END_REF], [START_REF] Comon | Sequentiality, second-order monadic logic and tree automata[END_REF], [START_REF] Jacquemard | Decidable approximations of term rewriting systems[END_REF]. The orthogonality requirement has also been replaced with the weaker condition of left linearity. The first relation between tree automata, WSkS and reduction strategies is pointed out in [START_REF] Comon | Sequentiality, second-order monadic logic and tree automata[END_REF]. Further studies of call-by-need strategies, which are still based on tree automata, but do not use a detour through monadic second-order logic can be found in [START_REF] Durand | Decidable call by need computations in term rewriting[END_REF]. For all these works, a key property is the preservation of regularity by (many-steps) rewriting, which was shown for ground systems in [START_REF] Brainerd | Tree generating regular systems[END_REF], for linear systems which do not share variables in [START_REF] Dauchet | The theory of ground rewrite systems is decidable[END_REF], for shallow systems in [START_REF] Comon | Sequentiality, second-order monadic logic and tree automata[END_REF], for right linear monadic rewrite systems [START_REF] Salomaa | Deterministic tree pushdown automata and monadic tree rewriting systems[END_REF], for linear semi-monadic rewrite systems [START_REF] Coquidé | Proofs and reachability problem for ground rewrite systems[END_REF], also called (with slight differences) growing systems in [START_REF] Jacquemard | Decidable approximations of term rewriting systems[END_REF]. Growing systems are the currently most general class for which the preservation of recognizability is known.

As already pointed out, the decidability of the encompassment theory implies the decidability of ground reducibility. There are several papers written along these lines which will be explained in the next chapter.

Finally, approximations of the reachable terms are computed in [Gen97] using tree automata techniques, which implies the decision of some safety properties.

Other applications

The relationship between finite tree automata and higher-order matching is studied in [START_REF] Comon | Higher-order matching and tree automata[END_REF].

Finite tree automata are also used in logic programming [START_REF] Frühwirth | Logic programs as types for logic programs[END_REF], type reconstruction [START_REF] Tiuryn | Subtype inequalities[END_REF] and automated deduction [START_REF] Ganzinger | Soft typing for ordered resolution[END_REF].

For further applications of tree automata in the direction of program verification, see e.g. chapter 5 of this book or e.g. [START_REF] Jones | Abstract interpretation of declarative languages, chapter Flow analysis of lazy higher-order functional programs[END_REF].

Chapter 4

Automata with Constraints

Introduction

A typical example of a language which is not recognized by a finite tree automaton is the set of terms {f (t, t) | t ∈ T (F)}, i.e. the set of ground instances of the term f (x, x). The reason is that the two sons of the root are recognized independently and only a fixed finite amount of information can be carried up to the root position, whereas t may be arbitrarily large. Therefore, as seen in the application section of the previous chapter, this imposes some linearity conditions, typically when automata techniques are applied to rewrite systems or to sort constraints. The shift from linear to non linear situations can also be seen as a generalization from tree automata to DAG (directed acyclic graphs) automata. This is the purpose of the present chapter: how is it possible to extend the definitions of tree automata in order to carry over the applications of the previous chapter to (some) non-linear situations?

Such an extension has been studied in the early 80's by M. Dauchet and J. Mongy. They define a class of automata which (when working in a top-down fashion) allow duplications. Considering bottom-up automata, this amounts to check equalities between subtrees. This yields the RATEG class. This class is not closed under complement. If we consider its closure, we get the class of automata with equality and disequality constraints. This class is studied in Section 4.2.

Unfortunately, the emptiness problem is undecidable for the class RATEG (and hence for automata with equality and disequality constraints). Several decidable subclasses have been studied in the literature. The most remarkable ones are:

• The class of automata with constraints between brothers which, roughly, allows equality (or disequality) tests only between positions with the same ancestors. For instance, the above set of terms f (t, t) is recognized by such an automaton. This class is interesting because most important properties of tree automata (Boolean closure and decision results) carry over this extension and hence most of the applications of tree automata can be extended, replacing linearity conditions with corresponding restrictions on non-linearities.

We study this class in Section 4.3.

• The class of reduction automata which, roughly, allows arbitrary disequality constraints but only a fixed finite amount of equality constraints on each run of the automaton. For instance the above set of terms f (t, t) also belongs to this class, since recognizing the terms of this set requires only one equality test, performed at the top position. Though closure properties have to be handled with care (with the definition sketched above, the closure by complement is unknown for this class), reduction automata are interesting because for example the set of irreducible terms (w.r.t. an arbitrary, possibly non-linear rewrite system) is recognized by a reduction automaton. Then the decidability of ground reducibility is a direct consequence of emptiness decidability for deterministic reduction automata.

There is also a logical counterpart: the reducibility theory which is presented in the linear case in the previous chapter and which can be shown decidable in the general case using a similar technique.

Reduction automata are studied in Section 4.4.

Automata with Equality and Disequality Constraints 4.2.1 The Most General Class

An equality constraint (resp. a disequality constraint) is a predicate on T (F) written π = π ′ (resp. π = π ′ ) where π, π ′ ∈ {1, . . . , k} * . Such a predicate is satisfied on a term t, which we write

t |= π = π ′ , if π, π ′ ∈ Pos(t) and t| π = t| π ′ (resp. π = π ′ is satisfied on t if π = π ′ is not satisfied on t).
The satisfaction relation |= is extended as usual to any Boolean combination of equality and disequality constraints. The empty conjunction and disjunction are respectively written ⊤ (true) and ⊥ (false). An automaton with equality and disequality constraints [is a tuple (Q, F, Q f , ∆) where F is a finite ranked alphabet, Q is a finite set of states, Q f is a subset of Q of final states and ∆ is a set of transition rules of of the form:

f (q 1 , . . . , q n ) c -→ q
where f ∈ F, q 1 , . . . , q n , q ∈ Q, and c is a Boolean combination of equality (and disequality) constraints. The state q is called target state in the above transition rule. We write for short AWEDC the class of automata with equality and disequality constraints.

Let A = (Q, F, Q f , ∆) ∈ AWEDC. The move relation → A is defined using the satisfaction of equality and disequality constraints: let t, t ′ ∈ T (F ∪ Q), then t → A t ′ if and only there is a context C ∈ C(F ∪ Q), some terms u 1 , . . . , u n ∈ T (F), and a transition rule f (q 1 , . . . , q n ) c -→ q ∈ ∆, such that

t = C[f (q 1 (u 1 ), . . . , q n (u n )], t ′ = C[q(f (u 1 , . . . , u n ))] and f (u 1 , . . . , u n ) |= c.
We denote * → A the reflexive and transitive closure of → A . As in Chapter 1, we usually write t * → A q instead of t * → A q(t). An automaton A ∈ AWEDC accepts (or recognizes) a ground term t ∈ T (F) if t * → A q for some state q ∈ Q f . More generally, we also say that A accepts t in state q iff t * → A q (acceptance by A is the particular case of acceptance by A in a final state).

The language accepted, or recognized, by an automaton A ∈ AWEDC is the set L(A) of terms t ∈ T (F) that are accepted by A. The set of terms t ∈ T (F) that are accepted by A in state q is denoted L(A, q).

A run is a mapping ρ from Pos(t) into ∆ such that if t(p) = f and the target state of ρ(p) is q, then there is a transition rule f (q 1 , . . . , q n ) c -→ q in ∆ such that for all 1 ≤ i ≤ n, the target state of ρ(pi) is q i and t| p |= c.

Note that we do not have here exactly the same definition of a run as in Chapter 1: instead of the state, we keep also the rule which yielded this state. This will be useful in the design of an emptiness decision algorithm for tree automata with equality and disequality constraints.

Example 4.2.2. Balanced complete binary trees over the alphabet f (binary) and a (constant) are recognized by the AWEDC ({q}, {f, a}, {q}, ∆) where ∆ consists of the following rules:

r 1 : a → q r 2 : f (q, q) 1=2 --→ q
For example, t = f (f (a, a), f (a, a)) is accepted. The mapping which associates r 1 to every position p of t such that t(p) = a and which associates r 2 to every position p of t such that t(p) = f is indeed a successful run: for every position

p of t such that t(p) = f , t| p•1 = t p•2 , hence t| p |= 1 = 2.
Example 4.2.3. Consider the following AWEDC: (Q, F, Q f , ∆) with F = {0, s, f } where 0 is a constant, s is unary and f has arity 4, Q = {q n , q 0 , q f }, Q f = {q f }, and ∆ consists of the following rules:

0 → q 0 s(q 0 ) → q n s(q n ) → q n f (q 0 , q 0 , q n , q n ) 3=4 --→ q f f (q 0 , q 0 , q 0 , q 0 ) → q f f (q 0 , q n , q 0 , q n ) 2=4 --→ q f f (q f , q n , q n , q n ) 14=4∧21=12∧131=3 -------------→ q f
This automaton computes the sum of two natural numbers written in base one in the following sense: if t is accepted by A then 1 t = f (t 1 , s n (0), s m (0), s n+m (0)) for some t 1 and n, m ≥ 0. Conversely, for each n, m ≥ 0, there is a term f (t 1 , s n (0), s m (0), s n+m (0)) which is accepted by the automaton.

For instance the term depicted on

Complexity Measures

In order to evaluate the complexity of operations on automata of the class AWEDC, we need to precise a representation of the automata and estimate the space which is necessary for this representation.

The size of a Boolean combination of equality and disequality constraints is defined by induction:

• π = π ′ def = π = π ′ def = |π| + |π ′ | (|π| is the length of π) • c ∧ c ′ def = c ∨ c ′ def = c + c ′ + 1 • ¬c def = c
Now, the complexity of deciding whether t |= c depends on the representation of t. If t is represented as a directed acyclic graph (a DAG) with maximal sharing, then this can be decided in O( c ) on a RAM. Otherwise, it requires to compute first this representation of t, and hence can be computed in time at most O( t log t + c ).

From now on, we assume, for complexity analysis, that the terms are represented with maximal sharing in such a way that checking an equality or a disequality constraint on t can be completed in a time which is independent of t .

The size of an automaton A ∈ AWEDC is

A def = |Q| + f (q1,...,qn) c -→ q∈∆ n + 2 + c Determinism An automaton A in AWEDC is deterministic if for every t ∈ T (F), there is at most one state q such that t * -→ A q. It is complete if for every t ∈ T (F)
there is at least one state q such that t * -→ A q.

When every constraint is a tautology, then our definition of automata reduces to the definition of Chapter 1. However, in such a case, the notions of determinacy do not fully coincide, as noticed in Chapter 1, page 23.

Reducing Non-determinism and Closure Properties

Proposition 4.2.4. For every automaton A ∈ AWEDC, there is a complete automaton A ′ which accepts the same language as A. The size A ′ is polynomial in A and the computation of A ′ can be performed in polynomial time (for a fixed alphabet). If A is deterministic, then A ′ is deterministic.

Proof. The proof is similar as for Theorem 1.1.7: we add a trash state q ⊥ and every appropriate transition to the trash state. However, we need to be careful concerning the constraints of the computed transitions in order to preserve the determinism.

The additional transitions are computed as follows: for each function symbol f ∈ F and each tuple of states (including the trash state) q 1 , . . . , q n , if there is no transition f (q 1 , . . . , q n ) c -→ q ∈ ∆, then we simply add the rule f (q 1 , . . . , q n ) → q ⊥ to ∆. Otherwise, let f (q 1 , . . . , q n ) ci -→ s i (i = 1, . . . , m) be all rules in ∆ whose left member is f (q 1 , . . . , q n ). We add the rule f (q 1 , . . . , q n )

c ′ -→ q ⊥ to ∆, where c ′ def = ¬ m i=1 c i .
Example 4.2.5. In order to complete the AWEDC of Example 4.2.2, we add the following transitions:

f (q, q) 1 =2 --→ q ⊥ f (q ⊥ , q) → q ⊥ f (q, q ⊥ ) → q ⊥ f (q ⊥ , q ⊥ ) → q ⊥
Note that the AWEDC obtained is deterministic.

Proposition 4.2.6. For every automaton A ∈ AWEDC, there is a deterministic automaton A ′ which accepts the same language as A. The size A ′ is exponential in A and A ′ can be computed in exponential time. If A is complete, then A ′ is complete.

Proof. The construction is the same as in Theorem 1.1.9: states of A ′ are sets of states of A. Final states of A ′ are those sets which contain at least one final state of A. The construction time complexity as well as the size A ′ are also of the same magnitude as in Theorem 1.1.9. The only difference is the computation of the constraints in transition rules: if S 1 , . . . , S n , S are sets of states, in the deterministic automaton, the rule f (S 1 , . . . , S n ) c -→ S is labeled by a constraint c defined by:

c def = q∈S f (q1,...,qn) cr -→ q∈∆ qi∈Si, i≤n c r ∧ q / ∈S f (q1,...,qn) cr -→ q∈∆ qi∈Si, i≤n ¬c r
Let us prove that a term t is accepted by A in states q 1 , . . . , q k (and no other states) if and only if t is accepted by A ′ in the state {q 1 , . . . , q k }:

Direction ⇒. Assume that t ni -→ A q i (i.e. t * -→ A q i in n i steps), for i = 1, . . . , k.
We prove, by induction on n = max(n 1 , . . . , n k ), that

t n --→ A ′ {q 1 , . . . , q k }. If n = 1, then t is a constant and t → S is a rule of A ′ where S = {q | a -→ A q}. Assume now that n > 1. Let, for each i = 1, . . . , k, t = f (t 1 , . . . , t p ) mi --→ A f (q i 1 , . . . , q i p ) -→ A q i
and let f (q i 1 , . . . , q i p )

ci -→ q i be a rule of A such that t |= c i . By induction hypothesis, each term t j is accepted by A ′ in the states of a set S j ⊇ {q 1 j , . . . , q k j }. Moreover, by definition of S = {q 1 , . . . , q k }, if t * -→ A q ′ then q ′ ∈ S. Therefore, for every transition rule of A f (q ′ 1 , . . . , q ′ p )

c ′ -→ q ′ such that q ′ / ∈ S and q j ∈ S j for every j ≤ p, we have t |= c ′ . Then t satisfies the above defined constraint c.

Direction ⇐. Assume that t n --→ A ′ S. We prove by induction on n that, for every q ∈ S, and for no other state of A, t n -→ A q.

If n = 1, then S is the set of states q such that t -→ A q, hence the property.

Assume now that:

t = f (t 1 , . . . , t p ) n --→ A ′ f (S 1 , . . . , S p ) --→ A ′ S.
Let f (S 1 , . . . , S p ) c -→ S be the last rule used in this reduction. Then t |= c and, by definition of c, for every state q ∈ S, there is a rule f (q 1 , . . . , q n ) cr -→ q of A such that q i ∈ S i for every i ≤ n and t |= c r . By induction hypothesis, for each i, t i mi

--→ A ′ S i implies t i mi --→ A q i (for some m i < n) and hence t n -→ A f (q 1 , . . . , q p ) -→ A q.
Let q / ∈ S and assume that t * -→ A q and that the last step in this reduction uses the transition rule f (q 1 , . . . , q n ) cr -→ q. By induction hypothesis, every

q i ∈ S i (for i ≤ n).
Hence, by definition of the constraint c, t |= c, and it contradicts t * --→ A ′ S.

Thus, by construction of the final states set, a ground term t is accepted by A ′ iff t is accepted by A. Now, we have to prove that A ′ is deterministic indeed. Assume that t * --→ A ′ S and t * --→ A ′ S ′ . Assume moreover that S = S ′ and that t is the smallest term (in size) recognized in two different states. Then there exists S 1 , . . . , S n such that

t * --→ A ′ f (S 1 , . . . , S n ) and such that f (S 1 , . . . , S n ) c -→ S and f (S 1 , . . . , S n ) c ′ -→ S ′
are transition rules of A ′ , with t |= c and t |= c ′ . By symmetry, we may assume that there is a state q ∈ S such that q / ∈ S ′ . Then, by construction of A ′ , there are some states q i ∈ S i , for every i ≤ n, and a rule f (q 1 , . . . , q n ) cr -→ q of A where c r occurs positively in c, and is therefore satisfied by t, t |= c r . By construction of the constraint of A ′ , c r must occur negatively in the second part of (the conjunction) c ′ . Therefore, t |= c ′ contradicts t |= c r .

Example 4.2.7. Consider the following automaton on the alphabet F = {a, f } where a is a constant and f is a binary symbol: Q = {q, q ⊥ }, Q f = {q} and ∆ contains the following rules:

a → q f (q, q) 1=2 --→ q f (q, q) → q ⊥ f (q ⊥ , q) → q ⊥ f (q, q ⊥ ) → q ⊥ f (q ⊥ , q ⊥ ) → q ⊥
This complete (and non-deterministic) automaton accepts the same languages as the automaton of Example 4.2.2. Then the deterministic automaton computed as in the previous proposition is given by:

a → {q} f ({q}, {q}) 1=2∧⊥ -----→ {q} f ({q}, {q}) 1=2 --→ {q, q ⊥ } f ({q}, {q}) 1 =2 --→ {q ⊥ } f ({q}, {q ⊥ }) → {q ⊥ } f ({q ⊥ }, {q}) → {q ⊥ } f ({q ⊥ }, {q ⊥ }) → {q ⊥ } f ({q, q ⊥ }, {q}) 1=2∧⊥ -----→ {q} f ({q, q ⊥ }, {q}) 1=2 --→ {q, q ⊥ } f ({q, q ⊥ }, {q ⊥ }) -→ {q ⊥ } f ({q, q ⊥ }, {q, q ⊥ }) 1=2 --→ {q, q ⊥ } f ({q, q ⊥ }, {q}) 1 =2 --→ {q ⊥ } f ({q}, {q, q ⊥ }) 1=2 --→ {q, q ⊥ } f ({q}, {q, q ⊥ }) 1 =2 --→ {q ⊥ } f ({q, q ⊥ }, {q}) 1 =2 --→ {q ⊥ } f ({q}, {q, q ⊥ }) 1=2∧⊥ -----→ {q} f ({q, q ⊥ }, {q, q ⊥ }) 1=2∧⊥ -----→ {q} f ({q ⊥ }, {q, q ⊥ }) -→ {q ⊥ }
For instance, the constraint 1=2∧⊥ is obtained by the conjunction of the label of f (q, q) 1=2 --→ q and the negation of the constraint labelling f (q, q) -→ q ⊥ , (which is ⊤). Some of the constraints, such as 1=2∧⊥ are unsatisfiable, hence the corresponding rules can be removed. If we finally rename the two accepting states {q} and {q, q ⊥ } into a single state q f (this is possible since by replacing one of these states by the other in any left hand side of a transition rule, we get another transition rule), then we get a simplified version of the deterministic automaton: Proof. The proof of this proposition can be obtained from the proof of Theorem 1.3.1 (Chapter 1, pages 30-31) with straightforward modifications. The only difference lies in the product automaton for the intersection: we have to consider conjunctions of constraints. More precisely, if we have two AWEDC

a → q f f (q ⊥ , q f ) → q ⊥ f (q f , q f ) 1=2 --→ q f f (q f , q ⊥ ) → q ⊥ f (q f , q f ) 1 =2 --→ q ⊥ f (q ⊥ , q ⊥ ) → q ⊥ Proposition 4.
A 1 = (Q 1 , F, Q f 1 , ∆ 1 ) and A 1 = (Q 2 , F, Q f 2 , ∆ 2 ), we construct an AWEDC A = (Q 1 × Q 2 , F, Q f 1 × Q f 2 , ∆) such that if f (q 1 , . . . , q n ) c -→ q ∈ ∆ 1 and f (q ′ 1 , . . . , q ′ n ) c ′ -→ q ′ ∈ ∆ 2 , then f ((q 1 , q ′ 1 ), . . . , (q n , q ′ n )) c∧c ′ ---→ (q, q ′ ) ∈ ∆. The AWEDC A recognizes L(A 1 ) ∩ L(A 2 ).

Decision Problems

Membership Proposition 4.2.9. Given t ∈ T (F) and A ∈AWEDC, deciding whether t is accepted by A can be completed in polynomial time (linear time for a deterministic automaton).

Proof. Because of the DAG representation of t, the satisfaction of a constraint π = π ′ on t can be completed in time O(|π| + |π ′ |). Thus, if A is deterministic, the membership test can be performed in time O( t + A + MC ) where M C = max( c c is a constraint of a rule of A). If A is nondeterministic, the complexity of the algorithm will be O( t × A × MC ).

Undecidability of Emptiness

Theorem 4.2.10. The emptiness problem for AWEDC is undecidable.

Proof. We reduce the Post Correspondence Problem (PCP). If w 1 , . . . , w n and w ′ 1 , . . . , w ′ n are the word sequences of the PCP problem over the alphabet {a, b}, we let F contain h (ternary), a, b (unary) and 0 (constant). Lets recall that the answer for the above instance of the PCP is a sequence i 1 , . . . , i p (which may contain some repetitions) such that w i1 . . . w ip = w ′ i1 . . . w ′ ip . If w ∈ {a, b} * , w = a 1 . . . a k and t ∈ T (F), we write w(t) the term a 1 (. . . (a k (t)) . . .) ∈ T (F). Now, we construct A = (Q, F, Q f , ∆) ∈ AWEDC as follows:

• Q contains a state q v for each prefix v of one of the words w i , w ′ i (including q wi and q w ′ i as well as 3 extra states: q 0 , q and q f . We assume that a and b are both prefix of at least one of the words

w i , w ′ i . Q f = {q f }. h w h h w i v h v h h 0 0 0 v ′ w ′ i v ′ w Figure 4
.2: An automaton in AWEDC accepting the solutions of PCP

• ∆ contains the following rules:

a(q 0 ) → q a b(q 0 ) → q b a(q v ) → q a•v if q v , q a•v ∈ Q b(q v ) → q b•v if q v , q b•v ∈ Q a(q wi ) → q a b(q wi ) → q b a(q w ′ i ) → q a b(q w ′ i ) → q b
∆ also contains the rules: 0 → q 0 h(q 0 , q 0 , q 0 ) → q h(q wi , q, q w ′ i )

1•1 |w i | =2•1∧3•1 |w ′ i | =2•3 ---------------→ q h(q wi , q, q w ′ i ) 1•1 |w i | =2•1∧3•1 |w ′ i | =2•3∧1=3 -------------------→ q f
The rule with left member h(q 0 , q 0 , q 0 ) recognizes the beginning of a Post sequence. The rules with left members h(q wi , q, q w ′ i ) ensure that we are really in presence of a successor in the PCP sequences: the constraint expresses that the subterm at position 1 is obtained by concatenating some w i with the term at position 2 • 1 and that the subterm at position 3 is obtained by concatenating w ′ i (with the same index i) with the subterm at position 2 • 3. Finally, entering the final state is subject to the additional constraint 1 = 3. This last constraint expresses that we went through two identical words with the w i sequences and the w ′ i sequences respectively. (See Figure 4.2). The details that this automaton indeed accepts the solutions of the PCP are left to the reader.

Then the language accepted by A is empty if and only if the PCP has a solution. Since PCP is undecidable, emptiness of A is also undecidable.

Automata with Constraints Between Brothers

The undecidability result of the previous section led to look for subclasses which have the desired closure properties, contain (properly) the classical tree automata and still keep the decidability of emptiness. This is the purpose of the class AWCBB.

Definition

An automaton A ∈ AWEDC is an automaton with constraints between brothers if every equality (resp. disequality) constraint has the form i = j (resp. i = j) where i, j ∈ N + . AWCBB is the set of automata with constraints between brothers.

Example Recall that the time complexity of each such construction is the same in AWEDC and in the unconstrained case: union and intersection are polynomial, complementation requires determinization and is exponential.

Emptiness Decision

To decide emptiness we would like to design a marking algorithm like the reduction algorithm of Section 1.1. Here the constraints in the transition rules cause additional difficulties. For instance consider the following example.

Example 4.3.3. Let us consider the AWCBB A which contains two states q and q 1 and the rules:

a → q f (q, q) 1 =2 --→ q 1 b → q
With the reduction algorithm of Section 1.1, we mark the state q, meaning that this state is inhabited by at least one term (for instance a). However, this information is not sufficient to ensure that one term is accepted in q 1 . Indeed, in order to use the rule f (q, q)

that two terms are accepted in q, we can deduce that at least two terms will be accepted in q 1 (for instance f (a, b) and f (b, a)).

The basic idea for the marking algorithm below is that one can bound the number of "marks" (terms) needed for each state. More precisely, if we have enough distinct terms accepted in states q 1 , . . . , q n , and the the transition f (q 1 , . . . , q n ) c -→ q is possible using some of these terms, then we know that we have enough terms accepted in state q. In the above example, we see that the bound is 2. We show in the next lemma that it is actually he maximal arity of a function symbol of the signature. Let us denote maxar (F)

def = max{ar (f ) | f ∈ F}.
Lemma 4.3.4. Let A be a deterministic AWCBB on F, let f (q 1 , . . . , q n ) c -→ q be a transition rule of A and assume a subset L i ⊆ L(A, q i ) for each i ≤ n. If there exists i ≤ n such that |L i | ≥ maxar (F) and there exists at least one term t = f (t 1 , . . . , t n ) with t i ∈ L i for each i ≤ n and t |= c, then then |L(A, q)| ≥ maxar (F).

Proof. We assume without loss of generality that c is in disjunctive normal form, and let c ′ be a conjunction in c of constraints j = j ′ or j = j ′ such that t |= c ′ for one t like in the lemma. Let L i = {s 1 , . . . , s a , . . .} (with a = maxar (F)) and let k be the number of occurrences of q i in q 1 , . . . , q n . For the sake of simplicity, we assume below that the k occurrence of q i are q 1 , . . . , q k .

If k = 1, we have f (s j , t 2 , . . . , t n ) |= c ′ for each j ≤ a, hence f (s j , t 2 , . . . , t n ) ∈ L(A, q) for each j ≤ a. Indeed, since A is deterministic, terms in different states are distinct. Hence, c ′ cannot contain an equality 1 = j with j > 1 (otherwise it would contradict t |= c ′ ) and every disequality 1 = j in c ′ with j > 1 is still satisfied by every f (s j , t 2 , . . . , t n ). Moreover, it is clear that by hypothesis every constraint of the form j = j ′ or j = j ′ with j ′ > j > 1 is still satisfied by every f (s j , t 2 , . . . , t n ).

If k > 1, as above, there are no equalities j = j ′ with 1 ≤ j ≤ k < j ′ ≤ n in c ′ and every disequality j = j ′ (1 ≤ j ≤ k < j ′ ≤ n) is still satisfied by any term of the form f (s i1 , . . . , s i k , t k+1 , . . . t n ) with i 1 , . . . , i k ≤ a. It remains to study the constraints of the form j = j ′ or j = j ′ with 1 ≤ j < j ′ ≤ k. Assume that there are d such disequality constraints. Then there are a! (a-d+1)! combinations of the form f (s i1 , . . . , s i k , t k+1 , . . . t n ) which satisfy c ′ . Since d ≤ k ≤ a, it follows that L(A, q) contains at least a terms of this form. Now, the marking algorithm for emptiness decision is the following:

input: AWCBB A = (Q, F, Q f , ∆) begin
-Marked is a mapping which associates each state with a set of terms accepted in that state. Set Marked to the function which maps each state to the ∅ repeat Set Marked (q) to Marked (q) ∪ {t} where f ∈ F n , t 1 ∈ Marked (q 1 ), . . . , t n ∈ Marked (q n ),

f (q 1 , . . . , q n ) c -→ q ∈ ∆, t = f (t 1 , . . . , t n ) and t |= c, |Marked (q)
| ≤ maxar (F) -1, until no term can be added to any Marked (q) output: true if, for every state q f ∈ Q f , Marked (q f ) = ∅. end Theorem 4.3.5. Emptiness can be decided in polynomial time for deterministic automata in AWCBB.

Proof. We use the above algorithm. Lemma 4.3.4 and the determinacy hypothesis ensures that it is sufficient to keep at most maxar (F) terms in each state.

Theorem 4.3.6. The emptiness problem is EXPTIME-complete for (non-deterministic) automata in AWCBB.

Proof. For non-deterministic automata, an exponential time algorithm is derived from Proposition 4.2.6 (determinization) and Theorem 4.3.5.

For the EXPTIME-hardness, we may reduce to non-emptiness decision for non-deterministic AWCBB the problem of intersection non-emptiness (for standard tree automata), which is known to be EXPTIME-complete, see Section 1.7.

Let A 1 ,. . . ,A n be tree automata over F. We want to decide whether L(A 1 )∩ . . . ∩ L(A n ) is empty or not.

We may assume without loss of generality that the states sets of A 1 ,. . . ,A n (called respectively Q 1 ,. . . ,Q n ) are pairwise disjoint, and that every A i has a single final state called q f i . We also assume that n = 2 k for some integer k. If this is not the case, let k be the smallest integer i such that n < 2 i and let n ′ = 2 k . We consider a second instance of the above problem: A ′ 1 ,. . . ,A ′ n ′ where

A ′ i = A i for each i ≤ n.
A ′ i = ({q}, F, {q}, {f (q, . . . , q) → q f ∈ F}) for each n < i ≤ n ′ .

Note that the tree automaton in the second case is universal, i.e. it accepts every term of T (F). Hence, the answer is "yes" for A ′ 1 ,. . . ,A ′ n ′ iff it is "yes" for A 1 ,. . . ,A n . Now, we add a single new binary symbol g to F, getting F ′ , and consider an AWCBB A whose language is empty iff L(A 1 ) ∩ . . . ∩ L(A n ) = ∅. The idea is that, while reading a term t bottom-up, A will simulate the computation of each A i in several subterms t 1 , . . . , t n of t and will test later on (with equality constraints) that these terms t i are all equal. For instance, for n = 4, A accepts g(g(t 1 , t 2 ), g(t 3 , t 4 )) iff for all i = 1..4, A i accepts t i and moreover t 1 = t 2 and g(t 1 , t 2 ) = g(t 3 , t 4 ) (hence t 1 = t 3 = t 4 ).

A = ( n i=1 Q i ⊎ {q 1 , . . . , q n 2 }, F ′ , {q 1 }, ∆)
where q 1 ,. . . ,q n 2 are new states, and the transition of ∆ are:

• every transition rule of A 1 , . . . , A n • for each i, 1 ≤ i ≤ n 2 , g(q 2i , q 2i+1 ) 1=2 --→ q i , • for each i, 1 ≤ i ≤ n 2 , g(q f 2i , q f 2i+1 ) 1=2 --→ q i .
Note that A is non-deterministic, even if every A i is deterministic.

We can show by induction on k (n = 2 k ) that the answer to the intersection non-emptiness problem is "yes" iff the language recognized by A is not empty. Moreover, the size of A is linear in the size of the initial problem and A is constructed in a time which is linear in its size. This proves the EXPTIMEhardness of emptiness decision for AWCBB.

Applications

The main difference between AWCBB and NFTA is the non-closure of AWCBB under projection and cylindrification. Actually, the shift from automata on trees to automata on tuples of trees cannot be extended to the class AWCBB. For instance, choosing {0, 1} 2 for a signature, we have 00(00, 01) |= 1 = 2, but this constraint is no more valid after projection of this term on the first component.

As long as we are interested in automata recognizing sets of trees, all results on NFTA (and all applications) can be extended to the class AWCBB (with a bigger complexity). For instance, Theorem 3.4.1 (sort constraints) can be extended to interpretations of sorts as languages accepted by AWCBB. Proposition 3.4.3 (encompassment) can be easily generalized to the case of non-linear terms in which non-linearities only occur between brother positions, provided that we replace NFTA with AWCBB. Theorem 3.4.5 can also be generalized to the reducibility theory with predicates • ¢ t where t is non-linear terms, provided that non-linearities in t only occur between brother positions. However, we can no longer invoke an embedding into WSkS. The important point is that the reductibility theory only requires the weak notion of recognizability on tuples (Rec × ). Hence we do not need automata on tuples, but only tuples of automata. As an example of application, we get a decision algorithm for ground reducibility of a term t w.r.t. left hand sides l 1 , . . . , l n , provided that all non-linearities in t, l 1 , . . . , l n occur at brother positions: simply compute the automata A i accepting the terms that encompass l i and check that L(A) ⊆ L(A 1 )∪. . .∪L(A n ).

Finally, the application on reduction strategies does not carry over to the case of non-linear terms because it really needs automata on tuples.

Reduction Automata

As we have seen above, the first-order theory of finitely many unary encompassment predicates • ¢ t1 , . . . , • ¢ tn (reducibility theory) is decidable when nonlinearities in the terms t i are restricted to brother positions. What happens when we drop the restrictions and consider arbitrary terms t 1 , . . . , t n ? It turns out that the theory remains decidable, as we will see. Intuitively, we make impossible counter examples like the one in the proof of Theorem 4.2.10 (stating undecidability of the emptiness problem for AWEDC) with an additional condition that using the automaton which accepts the set of terms encompassing t, we may only check for a bounded number of equalities along each branch. That is the idea of the next definitions of reduction automata.

Definition

A reduction automaton A is a member of AWEDC such that there is an ordering on the states of A such that, for each rule f (q 1 , . . . , q n ) c -→ q, q is an upper bound of q 1 , . . . , q n and it is moreover a strict upper bound if c contains an equality constraint.

In case of an automaton with ǫ-transitions q → q ′ we also require q ′ to be not larger than q.

Example 4.4.1. Consider the set of terms on the alphabet F = {a, g} encompassing g(g(x, y), x). It is accepted by the following reduction automaton, the final state of which is q f and q f is minimal in the ordering on states. a → q ⊤ g(q ⊤ , q ⊤ ) → q g(x,y) g(q ⊤ , q g(x,y) ) → q g(x,y) g(q g(x,y) , q ⊤ ) 11=2 ---→ q f g(q g(x,y) , q ⊤ ) 11 =2

---→ q g(x,y) g(q g(x,y) , q g(x,y) )

11=2 ---→ q f g(q g(x,y) , q g(x,y) )

11 =2

---→ q g(x,y) g(q, q f ) → q f g(q f , q) → q f where q ∈ {q ⊤ , q g(x,y) , q f } This construction can be generalized, along the lines of the proof of Proposition 3.4.3 (page 97): Proposition 4.4.2. The set of terms encompassing a term t is accepted by a deterministic and complete reduction automaton. The size of this automaton is polynomial in t as well as the time complexity for its construction.

Closure Properties

As usual, we are now interested in closure properties: Proposition 4.4.3. The class of reduction automata is closed under union and intersection.

Proof. The constructions for union and intersection are the same as in the proof of Proposition 4.2.8, and therefore, the respective time complexity and sizes are the same. The proof that the class of reduction automata is closed under these constructions is left as an exercise.

It is still unknown whether the class of reduction automata is closed under complementation or not. As we shall see below, it is not possible to reduce the non-determinism for reduction automata.

However, we have a weak version of stability:

Proposition 4.4.4.

• With each reduction automaton, we can associate a complete reduction automaton which accepts the same language. Moreover, this construction preserves the determinism.

• The class of complete deterministic reduction automata is closed under complement.

Emptiness Decision

Theorem 4.4.5. Emptiness is decidable for the class of complete and deterministic reduction automata.

The proof of this result is quite complicated and gives quite high upper bounds on the complexity (a tower of several exponentials). Hence, we are not going to reproduce it here. Let us only sketch how it works.

The idea is to use a pumping lemma in order to show that if there exists a term recognized by a given reduction automaton A, there exists one recognized term smaller in size than a certain bound (which depends on A). Hence, we need to show that every term bigger than the bound can be reduced by pumping. The equality and disequality constraints cause additional difficulties in the design of a pumping lemma. For instance consider the following example.

Example 4.4.6. Let us consider a reduction automaton A with the rules:

a → q, b → q, f (q, q) 1 =2 --→ q
Now consider the term t = f (f (a, b), b) which is accepted by the automaton. The terms f (a, b) and b yield the same state q. Hence, if there was no disequality constraints in A (i.e. if A were a classical finite tree automaton), we may replace f (a, b) with b in t and get a smaller term f (b, b) which is still accepted by A. However, this is not the case here since f (b, b) which is not accepted because f (b, b) |= 1 = 2. The reason of this phenomenon is easy to understand: some constraint which was satisfied before the pumping is no longer valid after the pumping.

Consider some term t bigger than the bound, and accepted by A with a run r. We want to perform a pumping in r giving a successful run r ′ on a term t ′ strictly smaller than t. Here the problem is to preserve the satisfaction of equality and disequality constraints along term replacements.

Preserving the equality constraints. Concerning equality constraints, we define an equivalence relation between positions (of equal subtrees). It depends on the run r considered. We have the following properties for the equivalence classes: first, their cardinality can be bounded by a number which only depends on the automaton, because of the condition with the ordering on states (this is actually not true for the class AWCBB).

second, we can compute a bound b 2 (which only depends on the automaton) such that the difference of the lengths of two equivalent positions is smaller than b 2 . Nevertheless, equalities are not a real problem, as soon as the automaton is deterministic. Indeed, pumping can then be defined on equivalence classes of positions.

If the automaton is not deterministic, we cannot anymore guarantee that we reach the same state at two equivalent positions. Actually, defining a pumping for non deterministic reduction automata is not possible, according to Theorem 4.4.7 below.

Preserving the disequality constraints. Handling disequalities requires more care; the number of distinct subterms in a minimal accepted term cannot be bounded (in contrast, this number can be bounded by |Q| × N , where N is the maximal arity of a function symbol, for AWCBB).

The problem is the possible "overlap" of disequalities checked by the automaton. As in Example 4.4.6, a pumping may yield a term which is no longer accepted, since a disequality checked somewhere in the term is no longer satisfied. In such a case, we say that the pumping creates an equality. Then, we distinguish two kinds of equalities created by a pumping: the close equalities and the remote equalities. Roughly, an equality created by a pump-

ing (t[v(u)] p , t[u] p ) is a pair of positions (π • π 1 , π • π 2 ) of t[v(u)] p
which was checked for disequality by the run ρ at position π on t[v(u)] p and such that t

[u] p | π•π1 = t[u] p | π•π2
(π is the longest common prefix to both members of the pair). This equality (π One possible proof sketch is

• π 1 , π • π 2 ) is a close equality if π ≤ p < π • π 1 or π ≤ p < π • π 2 . Otherwise (p ≥ π • π 1 or p ≥ π • π 2 ),
• First show that it is sufficient to consider equalities that are created at positions around which the states are incomparable w.r.t. >

• Next, show that, for a deep enough path, there is at least one pumping • For remote equalities, pumping is not sufficient. However, if some pumping creates a remote equality anyway, this means that there are "big"equal terms in t. Then we switch to another branch of the tree, combining pumping in both subtrees to find one (again using a combinatorial argument) such that no equality is created.

Of course, this is a very sketchy proof. The reader is referred to the bibliography for more information about the proof.

Theorem 4.4.7. Emptiness is not decidable for (non deterministic) reduction automata.

Proof. We reduce the halting problem for 2-counters machines. Let us consider a 2-counters machine with states p 0 (initial), p 1 , . . . , p k (p k is the unique final state, and we assume wlog that it cannot be reentered by M). The transitions of M have the form:

p(x 1 , x 2 ) c -→ p ′ (x ′ 1 , x ′
2 ) where p, p ′ are states of M and x 1 , x 2 , x ′ 1 , x ′ 2 are the respective contents of the 2 counters, where x ′ i is x i + 1 or x i -1 or x i . The condition c is a combination of x i = 0 and x i = 0 (i = 1, 2). The problem is to decide whether p 0 (0, 0) * --→ M p k (0, 0). We reduce it to the emptiness problem for a reduction automaton which recognizes the term representations of successful computations of M.

We consider a term representation of computations of M with some redundancy. For this purpose, we use the following signature: F = {0 : 0, # : 0, s : 1, p 0 , . . . , p k : 2, g : 2, h : 2, h ′ : 2} A configuration p(n, m) of M is represented by the term p(s n (0), s m (0)).

A transition of M between a configuration c and a configuration c ′ is represented by a term g(c, h(g(c ′ , y), y)), where y represents the rest of a computation of M. Some examples of transitions are given in Figure 4.5.

The term in Figure 4.6 represents a computation sequence of configurations c 0 , . . . , c n , with c 0 = p 0 (0, 0) and c n = p k (0, 0) and the transition of M between c i and c i+1 is denoted T i . In Figure 4.6, the nodes are decorated with the states of A in which they are accepted. We describe below these states and the transitions of A which permit the recognition of such a term.

The states of A are q # (for #), q 0 (for 0) and q 1 (for strictly positive integers), a universal state q ∀ (in which any term is accepted), and, for every transition T : ℓ → r of M, some states q ℓ , q r , q gr , q hr , and q T . Finally, A contains also a state q for chaining the transitions of M and a final state q f . The transitions for recognizing integers are simply: 0 → q 0 , s(q 0 ) → q 1 , s(q 1 ) → q 1

We have also some transitions ensuring that every term is accepted in the universal state q ∀ : 0 → q ∀ , # → q ∀ , s(q ∀ ) → q ∀ , p 0 (q ∀ , q ∀ ) → q ∀ ,. . . We associate five transitions of A to every transition T of M. Let us describe below three examples of this construction (the other cases are similar). For the first transition T 1 = ℓ 1 → r 1 in Figure 4.5 (with ℓ 1 = p(x 1 , x 2 ) and r 1 = p ′ (x 1 + 1, x 2 )), we have the following transitions of the reduction automata A (q 01 is an abbreviation for q 0 or q 1 ): p(q 01 , q 01 ) → q ℓ1 p ′ (q 1 , q 01 ) → q r1 g(q r1 , q ∀ ) → q gr1 h(q gr1 , q ∀ ) → q hr1 g(q ℓ1 , q hr1 ) 11=21111∧12=2112∧22=212 ------------------→ q T1

p(x 1 , x 2 ) → p ′ (x 1 + 1, x 2 ) p(x 1 , x 2 ) x1 =0 ---→ p ′ (x 1 -1, x 2 ) p(x 1 , x 2 ) x1=0 ---→ p ′ (x 1 , x 2 ) g p x 1 x 2 h g p ′
These transitions permit the recognition by A of a term of the form described in Figure 4.5. Note that both occurrences of y in this figure are recognized in the universal state q ∀ . It means that nothing is checked in these subterms. The constraints in the last transition above guaranty the equality between the two occurrences of x 1 , x 2 and y, respectively.

The transition T 2 = ℓ 2 → r 2 in Figure 4.5 (with ℓ 2 = p(x 1 , x 2 ) and r 2 = p ′ (x 1 -1, x 2 )) is characterized by the following transitions of A: p(q 1 , q 01 ) → q ℓ2 p ′ (q 01 , q 01 ) → q r2 g(q r2 , q ∀ ) → q gr2 h(q gr2 , q ∀ ) → q hr2 g(q ℓ2 , q hr2 ) 111=2111∧12=2112∧22=212 ------------------→ q T2

For the last the transition T 3 = ℓ 3 → r 3 in Figure 4.5 (with ℓ 3 = p(0, x 2 ) and r 3 = p ′ (0, x 2 )) we have the following transitions of A: p(q 0 , q 01 ) → q ℓ3 p ′ (q 0 , q 01 ) → q r3 g(q r3 , q ∀ ) → q gr3 h(q gr3 , q ∀ ) → q hr3 g(q ℓ3 , q hr3 )

12=2112∧22=212 -----------→ q T3 k q f g q T0 c 0 q c0 y 1 q hc1 y 1 = h q g q T1 c 1 q c1 y 2 q hc2 y 2 = h q g q T2 c 2 q c2 y 3 q hc3 y 3 = h q h q g p k 0 0 # # Figure 4.6: A computation of A
In order to recognize with A the chaining of transitions depicted in Figure 4.6, we use the state q and, for each transition T of M, following unconstrained transition: h(q T , q) → q

We have in A a special constrained transition starting from q T0 , where T 0 is the unique transition of M starting from the initial configuration c 0 = p 0 (0, 0), (M is assumed deterministic). Note that in this transition we have a symbol h ′ in the head, instead of a h:

h ′ (q T0 , q) 12=2 ---→ q f
Note that the equality constraint 12 = 2, together with the above constraints 22 = 212 in the rules leading to states q T (corresponding to the equality of both y in Figure 4.5) ensure, by transitivity, the equality of the two subterms denoted y 1 (and y 2 etc) in Figure 4.6.

Finally, we have four unconstrained transitions of A whose purpose is to initiate the bottom-up computation of the automaton with the final configuration

c k = p k (0, 0) of M. # → q # p k (q 0 , q 0 ) → q c k g(q c k , q # ) → q gc k h(q gc k , q # ) → q
Note that the equality tests are performed only at nodes labelled with the symbol g or h ′ , hence the number of such tests is at most 2 on any path of the tree in Figure 4.6. We let q f > q T0 , q f > q and q T > q ℓ , q T > q hr for every transition T = ℓ → r of M and every associated states q T , q ℓ , q hr . This way, we have defined above a reduction automata A. It is non-deterministic: the term y 1 in Figure 4.6 is recognized in both states q hc1 and q.

To conclude, it can be shown that M halts on p f (0, 0) starting from p 0 (0, 0) iff L(A, q f ) = ∅.

Finiteness Decision

The following result is quite difficult to establish. We only mention it for sake of completeness.

Theorem 4.4.9. Finiteness of the language is decidable for the class of reduction automata.

Term Rewriting Systems

There is a strong relationship between reduction automata and term rewriting. We mention them for readers interested in that topic.

Proposition 4.4.10. Given a term rewriting system R, the set of ground Rnormal forms is recognizable by a reduction automaton, the size of which is exponential in the size of R. The time complexity of the construction is exponential.

Proof. The set of R-reducible ground terms can be defined as the union of sets of ground terms encompassing the left members of rules of R. Thus, by Propositions 4.4.2 and 4.4.3 the set of R-reducible ground terms is accepted by a deterministic and complete reduction automaton. For the union, we use the product construction, preserving determinism (see the proof of Theorem 1.3.1, Chapter 1) with the price of an exponential blowup. The set of ground Rnormal forms is the complement of the set of ground R-reducible terms, and it is therefore accepted by a reduction automaton, according to Proposition 4.4.4. Thus, we have the following consequence of Theorems 4.4.9 and 4.4.5.

Corollary 4.4.11. Emptiness and finiteness of the language of ground Rnormal forms is decidable for every term rewriting system R.

Let us cite another important result concerning recognizability of sets normal forms.

Theorem 4.4.12. Given a term rewriting system, it is decidable whether its set of ground normal forms is a recognizable tree language.

Application to the Reducibility Theory

Consider the reducibility theory of Section 3.4.2: there are unary predicate symbols • ¢ t which are interpreted as the set of terms which encompass t. Let us accept now non-linear terms t as indices.

Propositions 4.4.2, and 4.4.3, and 4.4.4 and Theorem 4.4.5 yield the following result:

Theorem 4.4.13. The reducibility theory associated with any sets of terms is decidable.

And, as in the previous chapter, we have, as an immediate corollary: Corollary 4.4.14. Ground reducibility is decidable.

Other Decidable Subclasses

Complexity issues and restricted classes. There are two classes of automata with equality and disequality constraints for which tighter complexity results are known:

• For the class of automata containing only disequality constraints, emptiness can be decided in deterministic exponential time. For any term rewriting system R, the set of ground R-normal forms is still recognizable by an automaton of this subclass of reduction automata.

• For the class of deterministic reduction automata for which the constraints "cannot overlap", emptiness can be decided in polynomial time.

Combination of AWCBB and reduction automata. If you relax the condition on equality constraints in the transition rules of reduction automata so as to allow constraints between brothers, you obtain the biggest known subclass of AWEDC with a decidable emptiness problem. Formally, these automata, called generalized reduction automata, are members of AWEDC such that there is an ordering on the states set such that for each rule f (q 1 , . . . , q n ) c -→ q, q is an upper bound of q 1 , . . . , q n and it is moreover a strict upper bound if c contains an equality constraint

π 1 = π 2 with |π 1 | > 1 or |π 2 | > 1.
The closure and decidability results for reduction automata may be transposed to generalized reduction automata, with though a longer proof for the emptiness decision. Generalized reduction automata can thus be used for the decision of reducibility theory extended by some restricted sort declarations. In this extension, additionally to encompassment predicates • ¢ t , we allow a family of unary sort predicates . ∈ S, where S is a sort symbol. But, sort declarations are limited to atoms of the form t ∈ S where where non linear variables in t only occur at brother positions. This fragment is decidable by an analog of Theorem 4.4.13 for generalized reduction automata.

Exercises

Exercise 4.1.

1. Show that the automaton A+ of Example 4.2.3 accepts only terms of the form f (t1, s n (0), s m (0), s n+m (0)) 2. Conversely, show that, for every pair of natural numbers (n, m), there exists a term t1 such that f (t1, s n (0), s m (0), s n+m (0)) is accepted by A+.

3. Construct an automaton A× of the class AWEDC which has the same properties as above, replacing + with × 4. Give a proof that emptiness is undecidable for the class AWEDC, reducing Hilbert's tenth problem.

Exercise 4.2. Give an automaton of the class AWCBB which accepts the set of terms t (over the alphabet {a(0), b(0), f (2)}) having a subterm of the form f (u, u). (i.e. the set of terms that are reducible by a rule f (x, x) → v).

Exercise 4.3. Show that the class AWCBB is not closed under linear tree homomorphisms. Is it closed under inverse image of such morphisms?

Exercise 4.4. Give an example of two automata in AWCBB such that the set of pairs of terms recognized respectively by the automata is not itself a member of AWCBB.

Exercise 4.5. (Proposition 4.4.3) Show that the class of (languages recognized by) reduction automata is closed under intersection and union.

Exercise 4.6. Show that the set of balanced term on alphabet {a, f } as well as its complement are both recognizable by reduction automata.

Exercise 4.7. Show that the class of languages recognized by reduction automata is preserved under linear tree homomorphisms. Show however that this is no longer true for arbitrary tree homomorphisms.

Exercise 4.8. Let A be a reduction automaton. We define a ternary relation q

w -→ q ′ contained in Q × N * × Q as follows:
• for i ∈ N, q i -→ q ′ if and only if there is a rule f (q1, . . . , qn)

c -→ A q ′ with qi = q • q i•w
--→ q ′ if and only if there is a state q ′′ such that q i -→ q ′′ and q ′′ w -→ q ′ . Moreover, we say that a state q ∈ Q is a constrained state if there is a rule f (q1, . . . , qn)

c -→ A q
in A such that c is not a valid constraint. We say that the the constraints of A cannot overlap if, for each rule f (q1, . . . , qn) c -→ q and for each equality (resp. disequality) π = π ′ of c, there is no strict prefix p of π and no constrained state q ′ such that q ′ p -→ q.

1. Consider the rewrite system on the alphabet {f (2), g(1), a(0)} whose left members are f (x, g(x)), g(g(x)), f (a, a). Compute a reduction automaton, whose constraints do not overlap and which accepts the set of irreducible ground terms.

2. Show that emptiness can be decided in polynomial time for reduction automata whose constraints do not overlap. (Hint: it is similar to the proof of Theorem 4.3.5.)

3. Show that any language recognized by a reduction automaton whose constraints do not overlap is an homomorphic image of a language in the class AWCBB.

Give an example showing that the converse is false.

Exercise 4.9. Prove the Proposition 4.4.2 along the lines of Proposition 3.4.3.

Exercise 4.10. The purpose of this exercise is to give a construction of an automaton with disequality constraints (no equality constraints) whose emptiness is equivalent to the ground reducibility of a given term t with respect to a given term rewriting system R.

Give a direct construction of an automaton with disequality constraints A NF(R)

which accepts the set of irreducible ground terms 2. Show that the class of languages recognized by automata with disequality constraints is closed under intersection. Hence the set of irreducible ground instances of a linear term is recognized by an automaton with disequality constraints.

3. Let A NF(R) = (QNF, F , Q f NF , ∆NF). We compute ANF,t def = (QNF,t, F , Q f NF,t , ∆NF,t) as follows:

• QNF,t def = {tσ|p | p ∈ P os(t)}×QNF where σ ranges over substitutions from N LV (t) (the set of variables occurring at least twice in t) into Q f NF . • For all f (q1, . . . , qn) c -→ q ∈ ∆NF, and all u1, . . . , un ∈ {tσ|p | p ∈ P os(t)}, ∆NF,t contains the following rules:

-f ([qu 1 , q1], . . . , [qu n , qn]) c∧c ′ ---→ [q f (u 1 ,...,un) , q] if f (u1, . . . , un) = tσ0 and c ′ is constructed as sketched below. -f ([qu 1 , q1], . . . , [qu n , qn]) c -→ [q f (u 1 ,...,un) , q] if [q f (u 1 ,...,un) , q] ∈ QNF,t
and we are not in the first case.

f ([qu 1 , q1], . . . , [qu n , qn]) c -→ [qq, q] in all other cases c ′ is constructed as follows. From f (u1, . . . , un) we can retrieve the rules applied at position p in t. Assume that the rule at p checks π1 = π2. This amounts to check pπ1 = pπ2 at the root position of t. Let D be all disequalities pπ1 = pπ2 obtained in this way. The non linearity of t implies some equalities: let E be the set of equalities p1 = p2, for all positions p1, p2 such that t|p 1 = t|p 2 is a variable. Now, c ′ is the set of disequalities π = π ′ which are not in D and that can be inferred from D, E using the rules

pp1 = p2, p = p ′ ⊢ p ′ p1 = p2 p = p ′ , pp1 = p2 ⊢ p ′ p1 = p2
For instance, let t = f (x, f (x, y)) and assume that the automaton ANF contains a rule f (q, q) 1 =2

--→ q. Then the automaton ANF,t will contain the rule f ([qq, q], [q f (q,q) , q])

1 =2∧1 =22 -------→ q.
The final states are [qu, q f ] where q f ∈ Q f NF and u is an instance of t. Prove that ANF,t accepts at least one term if and only if t is not ground reducible by R.

Exercise 4.11. Prove Theorem 4.4.13 along the lines of the proof of Theorem 3.4.5.

Exercise 4.12. Show that the algorithm for deciding emptiness of deterministic complete flat tree automaton works for non-deterministic flat tree automata such that for each state q the number of non-equivalent terms reaching q is 0 or greater than or equal to 2.

Bibliographic notes

RATEG appeared in Mongy's thesis [START_REF] Mongy | Transformation de noyaux reconnaissables d'arbres[END_REF]. Unfortunately, as shown in [START_REF] Mongy | Transformation de noyaux reconnaissables d'arbres[END_REF] the emptiness problem is undecidable for the class RATEG (and hence for AWEDC). The undecidability can be even shown for a more restricted class of automata with equality tests between cousins (see [START_REF] Tommasi | Automates d'arbres avec tests d'égalité entre cousins germains[END_REF]).

The remarkable subclass AWCBB is defined in [START_REF] Bogaert | Equality and disequality constraints on direct subterms in tree automata[END_REF]. This paper presents the results cited in Section 4.3, especially Theorem 4.3.5. Concerning complexity, the result used in Section 4.3.3 (EXPTIME-completeness of the emptiness of the intersection of n recognizable tree languages) may be found in [START_REF] Frühwirth | Logic programs as types for logic programs[END_REF][START_REF] Seidl | Haskell overloading is DEXPTIME-complete[END_REF]. [START_REF] Dauchet | Reduction properties and automata with constraints[END_REF] is concerned with reduction automata and their use as a tool for the decision of the encompassment theory in the general case. The first decidability proof for ground reducibility is due to [START_REF] Plaisted | Semantic confluence tests and completion method[END_REF]. In [START_REF] Comon | Ground reducibility is EXPTIMEcomplete[END_REF], ground reducibility decision is shown EXPTIME-complete. In this work, an EXPTIME algorithm for emptiness decision for AWEDC with only disequality constrained The result mentioned in Section 4.5. The class of generalized reduction automata is introduced in [CCC + 94]. In this paper, a efficient cleaning algorithm is given for emptiness decision.

Chapter 5

Tree Set Automata

This chapter introduces a class of automata for sets of terms called Generalized Tree Set Automata. Languages associated with such automata are sets of sets of terms. The class of languages recognized by Generalized Tree Set Automata fulfills properties that suffices to build automata-based procedures for solving problems involving sets of terms, for instance, for solving systems of set constraints.

Introduction "The notion of type expresses the fact that one just cannot apply any operator to any value. Inferring and checking a program's type is then a proof of partial correction" quoting Marie-Claude Gaudel. "The main problem in this field is to be flexible while remaining rigorous, that is to allow polymorphism (a value can have more than one type) in order to avoid repetitions and write very general programs while preserving decidability of their correction with respect to types."

On that score, the set constraints formalism is a compromise between power of expression and decidability. This has been the object of active research for a few years.

Set constraints are relations between sets of terms. For instance, let us define the natural numbers with 0 and the successor relation denoted by s. Thus, the constraint Nat = 0 ∪ s(Nat) (5.1) corresponds to this definition. Let us consider the following system:

Nat = 0 ∪ s(Nat) List = cons(Nat, List) ∪ nil List + ⊆ List car(List + ) ⊆ s(Nat) (5.2)
The first constraint defines natural numbers. The second constraint codes the set of LISP-like lists of natural numbers. The empty list is nil and other lists are obtained using the constructor symbol cons. The last two constraints represent the set of lists with a non zero first element. Symbol car has the usual interpretation: the head of a list. Here car(List + ) can be interpreted as the set of all terms at first position in List + , that is all terms t such that there exists u with cons(t, u) ∈ List + . In the set constraint framework such an operator car is often written cons -1 1 . Set constraints are the essence of Set Based Analysis. The basic idea is to reason about program variables as sets of possible values. Set Based Analysis involves first writing set constraints expressing relationships between sets of program values, and then solving the system of set constraints. A single approximation is: all dependencies between the values of program variables are ignored. Techniques developed for Set Based Analysis have been successfully applied in program analysis and type inference and the technique can be combined with others [START_REF] Heintze | An engine for logic program analysis[END_REF].

Set constraints have also been used to define a constraint logic programming language over sets of ground terms that generalizes ordinary logic programming over an Herbrand domain [START_REF] Kozen | Set constraints and logic programming[END_REF].

In a more general way, a system of set constraints is a conjunction of positive constraints of the form exp ⊆ exp ′1 and negative constraints of the form exp ⊆ exp ′ . Right hand side and left hand side of these inequalities are set expressions, which are built with

• function symbols: in our example 0, s, cons, nil are function symbols.

• operators: union ∪, intersection ∩, complement ∼ • projection symbols: for instance, in the last equation of system (5.2) car denotes the first component of cons. In the set constraints syntax, this is written cons -1 (1) .

• set variables like Nat or List.

An interpretation assigns to each set variable a set of terms only built with function symbols. A solution is an interpretation which satisfies the system. For example, {0, s(0), s(s(0)), . . . } is a solution of Equation (5.1).

In the set constraint formalism, set inclusion and set union express in a natural way parametric polymorphism: List ⊆ nil ∪ cons(X, List).

In logic or functional programming, one often use dynamic procedures to deal with type. In other words, a run-time procedure checks whether or not an expression is well-typed. This permits maximum programming flexibility at the potential cost of efficiency and security. Static analysis partially avoids these drawbacks with the help of type inference and type checking procedures. The information extracted at compile time is also used for optimization.

Basically, program sources are analyzed at compile time and an ad hoc formalism is used to represent the result of the analysis. For types considered as sets of values, the set constraints formalism is well suited to represent them and to express their relations. Numerous inference and type checking algorithms in logic, functional and imperative programming are based on a resolution procedure for set constraints.

Most of the earliest algorithms consider systems of set constraints with weak power of expression. More often than not, these set constraints always have a least solution -w.r.t. inclusion -which corresponds to a (tuple of) regular set of terms. In this case, types are usual sorts. A sort signature defines a tree automaton (see Section 3.4.1 for the correspondence between automata and sorts). For instance, regular equations iontroduced in Section 2.3 such a subclass of set constraints. Therefore, these methods are closely related finite tree automata and use classical algorithms on these recognizers, like the ones presented in Chapter 1.

In order to obtain a more precise information with set constraints in static analysis, one way is to enrich the set constraints vocabulary. In one hand, with a large vocabulary an analysis can be accurate and relevant, but on the other hand, solutions are difficult to obtain.

Nonetheless, an essential property must be preserved: the decidability of satisfiability. There must exists a procedure which determines whether or not a system of set constraints has solutions. In other words, extracted information must be sufficient to say whether the objects of an analyzed program have a type. It is crucial, therefore, to know which classes of set constraints are decidable, and identifying the complexity of set constraints is of paramount importance.

A second important characteristic to preserve is to represent solutions in a convenient way. We want to obtain a kind of solved form from which one can decide whether a system has solutions and one can "compute" them.

In this chapter, we present an automata-based algorithm for solving systems of positive and negative set constraints where no projection symbols occurs. We define a new class of automata recognizing sets of (codes of) n-tuples of tree languages. Given a system of set constraints, there exists an automaton of this class which recognizes the set of solutions of the system. Therefore properties of our class of automata directly translate to set constraints.

In order to introduce our automata, we discuss the case of unary symbols, i.e. the case of strings over finite alphabet. For instance, let us consider the following constraints over the alphabet composed of two unary symbols a and b and a constant 0:

Xaa ∪ Xbb ⊆ X (5.3) Y ⊆ X
This system of set constraints can be encoded in a formula of the monadic second order theory of 2 successors named a and b:

∀u (u ∈ X ⇒ (uaa ∈ X ∧ ubb ∈ X))∧ ∀u u ∈ Y ⇒ u ∈ X
We have depicted in Fig 5 .1 (a beginning of) an infinite tree which is a model of the formula. Each node corresponds to a string over a and b. The root is associated with the empty string; going down to the left concatenates a a; going down to the right concatenates a b. Each node of the tree is labelled with a couple of points. The two components correspond to sets X and Y . A black point in the first component means that the current node belongs to X. Conversely, a white point in the first component means that the current node does not belong to X. Here we have X = {ε, aa, bb, . . . } and Y = {ε, bb, . . . }. A tree language that encodes solutions of Eq. 5.3 is Rabin-recognizable by a tree automaton which must avoid the three forbidden patterns depicted in Figure 5.2.

•?

??

•?

•? ??

•? •• Figure 5.2:
The set of three forbidden patterns. ' ?' stands for black or white dot. The tree depicted in Fig. 5.1 exclude these three patterns.

Given a ranked alphabet of unary symbols and one constant and a system of set constraints over {X 1 , . . . , X n }, one can encode a solution with a {0, 1} nvalued infinite tree and the set of solutions is recognized by an infinite tree automaton. Therefore, decidability of satisfiability of systems of set constraints can easily be derived from Rabin's Tree Theorem [START_REF] Rabin | Decidability of Second-Order Theories and Automata on Infinite Trees[END_REF] because infinite tree automata can be considered as an acceptor model for n-tuples of word languages over finite alphabet2 .

We extend this method to set constraints with symbols of arbitrary arity. Therefore, we define an acceptor model for mappings from T (F), where F is a ranked alphabet, into a set E = {0, 1} n of labels. Our automata can be viewed as an extension of infinite tree automata, but we will use weaker acceptance condition. The acceptance condition is: the range of a successful run is in a specified set of accepting set of states. We will prove that we can design an automaton which recognizes the set of solutions of a system of both positive and negative set constraints. For instance, let us consider the following system:

Y ⊆ ⊥ (5.4) X ⊆ f (Y, ∼ X) ∪ a (5.5)
where ⊥ stands for the empty set and ∼ stands for the complement symbol. The underlying structure is different than in the previous example since it is now the whole set of terms on the alphabet composed of a binary symbol f and a constant a. Having a representation of this structure in mind is not trivial. One can imagine a directed graph whose vertices are terms and such that there exists an edge between each couple of terms in the direct subterm relation (see figure 5.3). An automaton have to associate a state with each node following a finite set of rules. In the case of the example above, states are also couples of • or •.

Each vertex is of infinite out-degree, nonetheless one can define as in the word case forbidden patterns for incoming vertices which such an automaton have to avoid in order to satisfy Eq. (5.5) (see Fig. 5.4, Pattern ? stands for • or •). The acceptance condition is illustrated using Eq. (5.4). Indeed, to describe a solution of the system of set constraints, the pattern ?• must occur somewhere in a successful "run" of the automaton. ?• ??

•? f ??

•?

•?

f Consequently, decidability of systems of set constraints is a consequence of decidability of emptiness in our class of automata. Emptiness decidability is easy for automata without acceptance conditions (it corresponds to the case of positive set constraints only). The proof is more difficult and technical in the general case and is not presented here. Moreover, and this is the main advantage of an automaton-based method, properties of recognizable sets directly translate to sets of solutions of systems of set constraints. Therefore, we are able to prove nice properties. For instance, we can prove that a non empty set of solutions always contain a regular solution. Moreover we can prove the decidability of existence of finite solutions.

Definitions and Examples

Infinite tree automata are an acceptor model for infinite trees, i.e. for mappings from A * into E where A is a finite alphabet and E is a finite set of labels. We define and study F-generalized tree set automata which are an acceptor model for mappings from T (F) into E where F is a finite ranked alphabet and E is a finite set of labels.

Generalized Tree Sets

Let F be a ranked alphabet and E be a finite set. An E-valued F-generalized tree set g is a mapping from T (F) into E. We denote by G E the set of E-valued F-generalized tree sets.

For the sake of brevity, we do not mention the signature F which strictly speaking is in order in generalized tree sets. We also use the abbreviation GTS for generalized tree sets.

Throughout the chapter, if c ∈ {0, 1} n , then c i denotes the i th component of the tuple c. If we consider the set E = {0, 1} n for some n, a generalized tree set g in G {0,1} n can be considered as a n-tuple (L 1 , . . . , L n ) of tree languages over the ranked alphabet F where L i = {t ∈ T (F) | g(t) i = 1}.

We will need in the chapter the following operations on generalized tree sets. Let g (resp. g ′ ) be a generalized tree set in G E (resp. G E ′ ). The generalized tree set g ↑ g ′ ∈ G E×E ′ is defined by g ↑ g ′ (t) = (g(t), g ′ (t)), for each term t in T (F). Conversely let g be a generalized tree set in G E×E ′ and consider the projection π from E × E ′ into the E-component then π(g) is the generalized tree set in G E defined by π(g

)(t) = π(g(t)). Let G ⊆ G E×E ′ and G ′ ⊆ G E , then π(G) = {π(g) | g ∈ G} and π -1 (G ′ ) = {g ∈ G E×E ′ | π(g) ∈ G ′ }.

Tree Set Automata

A generalized tree set automaton A = (Q, ∆, Ω) (GTSA) over a finite set E consist of a finite state set Q, a transition relation ∆ ⊆ p Q p × F p × E × Q and a set Ω ⊆ 2 Q of accepting sets of states.
A run of A (or A-run) on a generalized tree set g ∈ G E is a mapping r : T (F) → Q with:

(r(t 1 ), . . . , r(t p ), f, g(f (t 1 , . . . , t p )), r(f (t 1 , . . . , t p ))) ∈ ∆ for t 1 , . . . , t p ∈ T (F) and f ∈ F p . The run r is successful if the range of r is in Ω i.e. r(T (F)) ∈ Ω.

A generalized tree set g ∈ G E is accepted by the automaton A if some run r of A on g is successful. We denote by L(A) the set of E-valued generalized tree sets accepted by a generalized tree set automaton A over E. A set G ⊆ G E is recognizable if G = L(A) for some generalized tree set automaton A.

In the following, a rule (q 1 , . . . , q p , f, l, q) is also denoted by f (q 1 , . . . , q p ) l → q. Consider a term t = f (t 1 , . . . , t p ) and a rule f (q 1 , . . . , q p ) l → q, this rule can be applied in a run r on a generalized tree set g for the term t if r(t 1 ) = q 1 ,. . . ,r(t p ) = q p , t is labeled by l, i.e. g(t) = l. If the rule is applied, then r(t) = q.

A generalized tree set automaton A = (Q, ∆, Ω) over E is

• deterministic if for each tuple (q 1 , . . . , q p , f, l) ∈ Q p × F p × E there is at most one state q ∈ Q such that (q 1 , . . . , q p , f, l, q) ∈ ∆.

• strongly deterministic if for each tuple (q 1 , . . . , q p , f ) ∈ Q p × F p there is at most one pair (l, q) ∈ E × Q such that (q 1 , . . . , q p , f, l, q) ∈ ∆.

• complete if for each tuple (q 1 , . . . , q p , f, l) ∈ Q p × F p × E there is at least one state q ∈ Q such that (q 1 , . . . , q p , f, l, q) ∈ ∆.

• simple if Ω is "subset-closed", that is ω ∈ Ω ⇒ (∀ω ′ ⊆ ω ω ′ ∈ Ω).
Successfulness for simple automata just implies some states are not assumed along a run. For instance, if the accepting set of a GTSA A is Ω = 2 Q then A is simple and any run is successful. But, if Ω = {Q}, then A is not simple and each state must be assumed at least once in a successful run. The definition of simple automata will be clearer with the relationships with set constraints and the emptiness property (see Section 5.4). Briefly, positive set constraints are related to simple GTSA for which the proof of emptiness decision is straightforward. Another and equivalent definition for simple GTSA relies on the acceptance condition: a run r is successful if and only if r(T (F)) ⊆ ω ∈ Ω.

There is in general an infinite number of runs -and hence an infinite number of GTS recognized -even in the case of deterministic generalized tree set automata (see example 5.2.1.2). Nonetheless, given a GTS g, there is at most one run on g for a deterministic generalized tree set automata. But, in the case of strongly deterministic generalized tree set automata, there is at most one run (see example 5.2.1.1) and therefore there is at most one GTS recognized.

Example 5.2.1.

Ex. 5.2.1.1

Let E = {0, 1}, F = {cons(, ), s(), nil, 0}. Let A = (Q, ∆, Ω) be defined by Q = {Nat, List, Term}, Ω = 2 Q , and ∆ is the following set of rules:

0 0 → Nat ; s(Nat) 0 → Nat ; nil 1 → List ; cons(Nat, List) 1 → List ; cons(q, q ′ ) 0 → Term ∀(q, q ′ ) = (Nat, List) ; s(q) 0 → Term ∀q = Nat .
A is strongly deterministic, simple, and not complete. L(A) is a singleton set. Indeed, there is a unique run r on a unique generalized tree set g ∈ G {0,1} n . The run r maps every natural number on state Nat, every list on state List and the other terms on state Term. Therefore g maps a natural number on 0, a list on 1 and the other terms on 0. Hence, we say that L(A) is the regular tree language L of Lisp-like lists of natural numbers.

Ex. 5.2.1.2 Let E = {0, 1}, F = {cons(, ), s(), nil, 0}, and let

A ′ = (Q ′ , ∆ ′ , Ω ′ ) be defined by Q ′ = Q, Ω ′ = Ω, and ∆ ′ = ∆ ∪ {cons(Nat, List) 0 → List, nil 0 → List}.
A ′ is deterministic (but not strongly), simple, and not complete, and L(A ′ ) is the set of all subsets of the regular tree language L of Lisp-like lists of natural numbers. Indeed, successful runs can now be defined on generalized tree sets g such that a term in L is labeled by 0 or 1.

Ex. 5.2.1.3

Let E = {0, 1} 2 , F = {cons(, ), s(), nil, 0}, and let A = (Q, ∆, Ω) be defined by Q = {Nat, Nat ′ , List, Term}, Ω = 2 Q , and ∆ is the following set of rules:

0 (0,0) → Nat ; 0 (1,0) → Nat ′ ; s(Nat) (0,0) → Nat s(Nat) (1,0) → Nat ′ ; s(Nat ′ ) (0,0) → Nat ; s(Nat ′ ) (1,0) → Nat ′ nil (0,1) → List ; cons(Nat ′ , List) (0,1) → List ; s(q) (0,0) → Term ∀q = Nat cons(q, q ′ ) (0,0) → Term ∀(q, q ′ ) = (Nat ′ , List)
A is deterministic, simple, and not complete, and L(A) is the set of 2-tuples of tree languages (N ′ , L ′ ) where N ′ is a subset of the regular tree language of natural numbers and L ′ is the set of Lisp-like lists of natural numbers over N ′ .

Let us remark that the set N ′ may be non-regular. For instance, one can define a run on a characteristic generalized tree set g p of Lisp-like lists of prime numbers. The generalized tree set g p is such that g p (t) = (1, 0) when t is a (code of a) prime number.

In the previous examples, we only consider simple generalized tree set automata. Moreover all runs are successful runs. The following examples are non-simple generalized tree set automata in order to make clear the interest of acceptance conditions. For this, compare the sets of generalized tree sets obtained in examples 5.2.1.3 and 5.2.2 and note that with acceptance conditions, we can express that a set is non empty.

Example 5.2.2. Example 5.2.1.3 continued

Let E = {0, 1} 2 , F = {cons(, ), nil, s(), 0}, and let

A ′ = (Q ′ , ∆ ′ , Ω ′ ) be defined by Q ′ = Q, ∆ ′ = ∆, and Ω ′ = {ω ∈ 2 Q | Nat ′ ∈ ω}. A ′ is
deterministic, not simple, and not complete, and L(A ′ ) is the set of 2-tuples of tree languages (N ′ , L ′ ) where N ′ is a subset of the regular tree language of natural numbers and L ′ is the set of Lisp-like lists of natural numbers over N ′ , and N ′ = ∅. Indeed, for a successful r on g, there must be a term t such that r(t) = Nat ′ therefore, there must be a term t labelled by (1, 0), henceforth N ′ = ∅.

Hierarchy of GTSA-recognizable Languages

Let us define:

• R GTS , the class of languages recognizable by GTSA,

• R DGTS , the class of languages recognizable by deterministic GTSA,

• R SGTS , the class of languages recognizable by Simple GTSA.

The three classes defined above are proved to be different. They are also closely related to classes of languages defined from the set constraint theory point of view.

R GTS R SGTS R DGTS Figure 5.5: Classes of GTSA-recognizable languages
Classes of GTSA-recognizable languages have also different closure properties. We will prove in Section 5.3.1 that R SGTS and the entire class R GTS are closed under union, intersection, projection and cylindrification; R DGTS is closed under complementation and intersection.

We propose three examples that illustrate the differences between the three classes. First, R DGTS is not a subset of R SGTS .

Example 5.2.3. Let E = {0, 1}, F = {f, a} where a is a constant and f is unary. Let us consider the deterministic but non-simple GTSA A 1 = ({q 0 , q 1 }, ∆ 1 , Ω 1 ) where ∆ 1 is:

a 0 → q 0 , a 1 → q 1 , f (q 0 ) 0 → q 0 , f (q 1 ) 0 → q 0 , f (q 0 ) 1 → q 1 , f (q 1 ) 1 → q 0 .
and Ω 1 = {{q 0 , q 1 }, {q 1 }}. Let us prove that

L(A 1 ) = {L | L = ∅} is not in R SGTS .
Assume that there exists a simple GTSA A s with n states such that L(A 1 ) = L(A s ). Hence, A s recognizes also each one of the singleton sets {f i (a)} for i > 0. Let us consider some i greater than n + 1, we can deduce that a run r on the GTS g associated with {f i (a)} maps two terms f k (a) and f l (a), k < l < i to the same state. We have g(t) = 0 for every term t ¢ f l (a) and r "loops" between f k (a) and f l (a). Therefore, one can build another run r 0 on a GTS g 0 such that g 0 (t) = 0 for each t ∈ T (F). Since A s is simple, and since the range of r 0 is a subset of the range of r, g 0 is recognized, hence the empty set is recognized which contradicts the hypothesis.

Basically, using simple GTSA it is not possible to enforce a state to be assumed somewhere by every run. Consequently, it is not possible to express global properties of generalized tree languages such as non-emptiness.

Second, R SGTS is not a subset of R DGTS .

Example 5.2.4. Let us consider the non-deterministic but simple GTSA A 2 = ({q f , q h }, ∆ 2 , Ω 2 ) where ∆ 2 is:

a 0 → q f | q h , a 1 → q f | q h , f (q f ) 1 → q f | q h , h(q h ) 1 → q f | q h , f (q h ) 0 → q f | q h , h(q f ) 0 → q f | q h ,
and

Ω 2 = 2 {q f ,q h } . It is easy to prove that L(A 2 ) = {L | ∀t f (t) ∈ L ⇔ h(t) ∈ L}.
The proof that no deterministic GTSA recognizes L(A 2 ) is left to the reader. We terminate with an example of a non-deterministic and non-simple generalized tree set automaton. This example will be used in the proof of Proposition 5.3.2.

Example 5.2.5. Let A = (Q, ∆, Ω) be defined by Q = {q, q ′ }, Ω = {Q}, and ∆ is the following set of rules:

a 1 → q ; a 1 → q ′ ; a 0 → q ′ ; f (q) 1 → q ; f (q ′ ) 0 → q ′ ; f (q ′ ) 1 → q ′ ; f (q ′ ) 1 → q ;
The proof that A is not deterministic, not simple, and not complete, and

L(A) = {L ⊆ T (F) | ∃t ∈ T (F) ((t ∈ L) ∧ (∀t ′ ∈ T (F) (t ¢ t ′ ) ⇒ (t ′ ∈ L)))
} is left as an exercise to the reader.

Regular Generalized Tree Sets, Regular Runs

As we mentioned it in Example 5.2.1.3, the set recognized by a GTSA may contain GTS corresponding to non-regular languages. But regularity is of major interest for practical reasons because it implies a GTS or a language to be finitely defined.

A generalized tree set g ∈ G E is regular if there exist a finite set R, a mapping α : T (F) → R, and a mapping β : R → E satisfying the following two properties.

1. g = αβ (i.e. g = β • α), 2. α is closed under contexts, i.e. for all context c and terms t 1 , t 2 , we have

(α(t 1 ) = α(t 2 )) ⇒ (α(c[t 1 ]) = α(c[t 2 ]))
In the case E = {0, 1} n , regular generalized tree sets correspond to n-tuples of regular tree languages.

Although the definition of regularity could lead to the definition of regular run -because a run can be considered as a generalized tree set in G Q , we use stronger conditions for a run to be regular. Indeed, if we define regular runs as regular generalized tree sets in G Q , regularity of generalized tree sets and regularity of runs do not correspond in general. For instance, one could define regular runs on non-regular generalized tree sets in the case of non-strongly deterministic generalized tree set automata, and one could define non-regular runs on regular generalized tree sets in the case of non-deterministic generalized tree set automata. Therefore, we only consider regular runs on regular generalized tree sets:

A run r on a generalized tree set g is regular if r ↑ g ∈ G E×Q is regular. Consequently, r and g are regular generalized tree sets. Proposition 5.2.6. Let A be a generalized tree set automaton, if g is a regular generalized tree set in L(A) then there exists a regular A-run on g.

Proof. Consider a generalized tree set automaton A = (Q, ∆, Ω) over E and a regular generalized tree set g in L(A) and let r be a successful run on g. Let L be a finite tree language closed under the subterm relation and such that F 0 ⊆ L and r(L) = r(T (F)). The generalized tree set g is regular, therefore there exist a finite set R, a mapping α : T (F) → R closed under context and a mapping β : R → E such that g = αβ. We now define a regular run r ′ on g.

Let L ⋆ = L∪{⋆} where ⋆ is a new constant symbol and let φ be the mapping from

T (F) into Q × R × L ⋆ defined by φ(t) = (r(t), α(t), u) where u = t if t ∈ L and u = ⋆ otherwise. Hence R ′ = φ(T (F)) is a finite set because R ′ ⊆ Q×R×L ⋆ . For each ρ in R ′ , let us fix t ρ ∈ T (F) such that φ(t ρ ) = ρ.
The run r ′ is now (regularly) defined via two mappings α ′ and β ′ . Let β ′ be the projection from Q × R × L ⋆ into Q and let α ′ : T (F) → R ′ be inductively defined by: ∀a ∈ F 0 α ′ (a) = φ(a);

and ∀f ∈ F p ∀t 1 , . . . , t p ∈ T (F) α ′ (f (t 1 , . . . , t p )) = φ(f (t α ′ (t1) , . . . , t α ′ (tp) )).
Let r ′ = α ′ β ′ . First we can easily prove by induction that ∀t ∈ L α ′ (t) = φ(t) and deduce that ∀t ∈ L r ′ (t) = r(t). Thus r ′ and r coincide on L. It remains to prove that (1) the mapping α ′ is closed under context, (2) r ′ is a run on g and (3) r ′ is a successful run.

(1) From the definition of α ′ we can easily derive that the mapping α ′ is closed under context.

(2) We prove that the mapping r ′ = α ′ β ′ is a run on g, that is if t = f (t 1 , . . . , t p ) then (r ′ (t 1 ), . . . , r ′ (t p ), f, g(t), r ′ (t)) ∈ ∆.

Let us consider a term t = f (t 1 , . . . , t p ). From the definitions of α ′ , β ′ , and r ′ , we get r ′ (t) = r(t ′ ) with t ′ = f (t α ′ (t1) , . . . , t α ′ (tp) ). The mapping r is a run on g, hence (r(t α ′ (t1) ), . . . , r(t α ′ (tp) ), f, g(t ′ ), r(t ′ )) ∈ ∆, and thus it suffices to prove that g(t) = g(t ′ ) and, for all i, r ′ (t i ) = r(t α ′ (ti) ).

Let i ∈ {1, . . . , p}, r

′ (t i ) = β ′ (α ′ (t i )) by definition of r ′ . By definition of t α ′ (ti) , α ′ (t i ) = φ(t α ′ (ti) ), therefore r ′ (t i ) = β ′ (φ(t α ′ (ti) )
). Now, using the definitions of φ and β ′ , we get r ′ (t i ) = r(t α ′ (ti) ).

In order to prove that g(t) = g(t ′ ), we prove that α(t) = α(t ′ ). Let π be the projection from R ′ into R. We have α(t ′ ) = π(φ(t ′ )) by definition of φ and π. We have α(t ′ ) = π(α ′ (t)) using definitions of t ′ and α ′ . Now

α(t ′ ) = π(φ(t α ′ (t) )) because φ(t α ′ (t) ) = α ′ (t) by definition of t α ′ (t) . And then α(t ′ ) = α(t α ′ (t)
) by definition of π and φ. Therefore it remains to prove that α(t α ′ (t) ) = α(t). The proof is by induction on the structure of terms.

If t ∈ F 0 then t α ′ (t) = t, so the property holds (note that this property holds for all t ∈ L). Let us suppose that t = f (t 1 , . . . , t p ) and α(t α ′ (ti) ) = α(t i ) ∀i ∈ {1, . . . , p}. First, using induction hypothesis and closure under context of α, we get

α(f (t 1 , . . . , t p )) = α(f (t α ′ (t1) , . . . , t α ′ (tp) ))
Therefore,

α(f (t 1 , . . . , t p )) = α(f (t α ′ (t1) , . . . , t α ′ (tp) )) = π(φ(f (t α ′ (t1) , . . . , t α ′ (tp) ))) ( def. of φ and π) = π(α ′ (f (t 1 , . . . , t p ))) ( def. of α ′ ) = π(φ(t α ′ (f (t1,...,tp))
)) ( def. of t α ′ (f (t1,...,tp)) ) = α(t α ′ (f (t1,...,tp)) ) ( def. of φ and π).

(3) We have r ′ (T (F)) = r ′ (L) = r(L) = r(T (F)) using the definition of r ′ , the definition of L, and the equality r ′ (L) = r(L). The run r is a successful run. Consequently r ′ is a successful run.

Proposition 5.2.7. A non-empty recognizable set of generalized tree sets contains a regular generalized tree set.

Proof. Let us consider a generalized tree set automaton A and a successful run r on a generalized tree set g. There exists a tree language closed under the subterm relation F such that r(F ) = r(T (F)). We define a regular run rr on a regular generalized tree set gg in the following way.

The run rr coincides with r on F : ∀t ∈ F , rr(t) = r(t) and gg(t) = g(t). The runs rr and gg are inductively defined on T (F) \ F : given q 1 , . . . , q p in r(T (F)), let us fix a rule f (q 1 , . . . , q p ) l → q such that q ∈ r(T (F)). The rule exists since r is a run. Therefore, ∀t = f (t 1 , . . . , t p ) ∈ F such that rr(t i ) = q i for all i ≤ p, we define rr(t) = q and gg(t) = l, following the fixed rule f (q 1 , . . . , q p ) l → q.

From the preceding, we can also deduce that a finite and recognizable set of generalized tree sets only contains regular generalized tree sets.

Proof. (a) Let A = (Q, ∆, Ω) be a generalized tree set automaton over E and let q ′ be a new state, i.e. q ′ ∈ Q.

Let A c = (Q c , ∆ c , Ω c ) be defined by Q c = Q∪{q ′ }, Ω c = Ω, and ∆ c = ∆ ∪ {(q 1 , . . . , q p , f, l, q ′ ) | {(q 1 , . . . , q p , f, l)} × Q ∩ ∆ = ∅; q 1 , . . . , q p ∈ Q c , f ∈ F p , l ∈ E}.
A c is complete and

L(A) = L(A c ). Note that A c is simple if A is simple. (b) A cd = (Q, ∆
, Ω) be a deterministic and complete generalized tree set automaton over E. The automaton

A ′ = (Q ′ , ∆ ′ , Ω ′ ) with Q ′ = Q, ∆ ′ = ∆, and Ω ′ = 2 Q -Ω recognizes the set G E -L(A cd ). (c) E = {0, 1}, F = {c, a} where a is a constant and c is of arity 1. Let G = {g ∈ G {0,1} n | ∃t ∈ T (F) ((g(t) = 1) ∧ (∀t ′ ∈ T (F) (t ¢ t ′ ) ⇒ (g(t ′ ) = 1)))}. Clearly, G is recognizable by a non deterministic GTSA (see Example 5.2.5). Let G = G {0,1} n -G, we have G = {g ∈ G {0,1} n | ∀t ∈ T (F) ∃t ′ ∈ T (F) (t ¢ t ′ ) ∧ (g(t ′ ) = 0)}
and G is not recognizable. Let us suppose that G is recognized by an automaton A = (Q, ∆, Ω) with Card(Q) = k -2 and let us consider the generalized tree set g defined by: g(c i (a)) = 0 if i = k × z for some integer z, and g(c i (a)) = 1 otherwise. The generalized tree set g is in G and we consider a successful run r on g. We have r(T (F)) = ω ∈ Ω therefore there exists some integer n such that r({g(c i (a)) | i ≤ n}) = ω. Moreover we can suppose that n is a multiple of k. As Card(Q) = k -2 there are two terms u and v in the set {c i (a) | n+1 ≤ i ≤ n+k-1} such that r(u) = r(v). Note that by hypothesis, for all i such that n+1 ≤ i ≤ n+k +1, g(c i (a)) = 1. Consequently, a successful run g ′ could be defined from g on the generalized tree set g ′ defined by g ′ (t) = g(t) if t = c i (a) when i ≤ n, and g ′ (t) = 1 otherwise. This leads to a contradiction because g ′ ∈ G.

(d) This result is a consequence of (b) and (c).

We will now prove the closure under projection and cylindrification. We will first prove a stronger lemma.

Lemma 5.3.3. Let G ⊆ G E1 be a GTSA-recognizable language and let R ⊆ E 1 × E 2 . The set R(G) = {g ′ ∈ G E2 | ∃g ∈ G ∀t ∈ T (F) (g(t), g ′ (t)) ∈ R} is recognizable. Proof. Let A = (Q, ∆, Ω) such that L(A) = G. Let A ′ = (Q ′ , ∆ ′ , Ω ′ ) where Q ′ = Q, ∆ ′ = {f (q 1 , . . . , q p ) l ′ → q | ∃l ∈ E 1 f (q 1 , . . . , q p ) l → q ∈ ∆ and (l, l ′ ) ∈ R} and Ω ′ = Ω. We prove that R(G) = L(A ′ ).
⊇ Let g ′ ∈ L(A ′ ) and let r ′ be a successful run on g ′ . We construct a generalized tree set g such that for all t ∈ T (F), (g(t), g ′ (t)) ∈ R and such that r ′ is also a successful A-run on g.

Let a be a constant. According to the definition of ∆ ′ , a g ′ (a) → r ′ (a) ∈ ∆ ′ implies that there exists l a such that (l a , g ′ (a)) ∈ R and a la → r ′ (a) ∈ ∆. So let g(a) = l a .

Let t = f (t 1 , . . . , t p ) with ∀i r ′ (t i ) = q i . There exists a rule f (q 1 , . . . , q p ) g ′ (t) → r ′ (t) in ∆ ′ because r ′ is a run on g ′ and again, from the definition of ∆ ′ , there exists l t ∈ E 1 such that f (q 1 , . . . , q p ) lt → r ′ (t) in ∆ with (l t (t), g ′ (t)) ∈ R. So, we define g(t) = l t . Clearly, g is a generalized tree set and r ′ is a successful run on g and for all t ∈ T (F), (g(t), g ′ (t)) ∈ R by construction.

⊆ Let g ′ ∈ R(G) and let g ∈ G such that ∀t ∈ T (F) (g(t), g ′ (t)) ∈ R. One can easily prove that any successful A-run on g is also a successful A ′ -run on g ′ .

Let us recall that if g is a generalized tree set in

G E1ו••×En , the ith projection of g (on the E i -component, 1 ≤ i ≤ n) is the GTS π i (g) defined by: let π from E 1 × • • • × E n into E i , such that π(l 1 , . . . , l n ) = l i and let π i (g)(t) = π(g(t)
) for every term t. Conversely, the ith cylindrification of a GTS g denoted by π -1 i (g) is the set of GTS g ′ such that π i (g ′ ) = g. Projection and cylindrification are usually extended to sets of GTS.

Corollary 5.3.4. (a) The class of GTSA-recognizable languages is closed un-

der projection and cylindrification.

(b) Let G ⊆ G E and G ′ ⊆ G E ′ be two GTSA-recognizable languages. The set G ↑ G ′ = {g ↑ g ′ | g ∈ G, g ′ ∈ G ′ } is a GTSA-recognizable language in G E×E ′ .
Proof. (a) The case of projection is an immediate consequence of Lemma 5.3.3 using

E 1 = E × E ′ , E 2 = E,
G ↑ G ′ = π -1 1 (G) ∩ π -1 2 (G ′ ) where π -1 1 (respectively π -1 2 ) is the inverse projection from E to E × E ′ (respectively from E ′ to E × E ′ ).
Let us remark that the construction preserves simplicity, so R SGTS is closed under projection and cylindrification.

We now consider the case E = {0, 1} n and we give two propositions without proof. Proposition 5.3.5 can easily be deduced from Corollary 5.3.4. The proof of Proposition 5.3.6 is an extension of the constructions made in Examples 5.2.1.1 and 5.2.1.2. Proposition 5.3.5. Let A and A ′ be two generalized tree set automata over

{0, 1} n . (a) {(L 1 ∪ L ′ 1 , . . . , L n ∪ L ′ n ) | (L 1 , . . . , L n ) ∈ L(A) and (L ′ 1 , . . . , L ′ n ) ∈ L(A ′ )} is recognizable. (b) {(L 1 ∩ L ′ 1 , . . . , L n ∩ L ′ n ) | (L 1 , . . . , L n ) ∈ L(A) and (L ′ 1 , . . . , L ′ n ) ∈ L(A ′ )} is recognizable. (c) {(L 1 , . . . , L n ) | (L 1 , . . . , L n ) ∈ L(A)} is recognizable, where L i = T (F) - L i , ∀i.
Proposition 5.3.6. Let E = {0, 1} n and let (F 1 , . . . , F n ) be a n-tuple of regular tree languages. There exist deterministic simple generalized tree set automata A , A ′ , and A ′′ such that

• L(A) = {(F 1 , . . . , F n )}; • L(A ′ ) = {(L 1 , . . . , L n ) | L 1 ⊆ F 1 , . . . , L n ⊆ F n }; • L(A ′′ ) = {(L 1 , . . . , L n ) | F 1 ⊆ L 1 , . . . , F n ⊆ L n }.

Emptiness Property

Theorem 5.3.7. The emptiness property is decidable in the class of generalized tree set automata. Given a generalized tree set automaton A, it is decidable whether

L(A) = ∅.
Labels of the generalized tree sets are meaningless for the emptiness decision thus we consider "label-free" generalized tree set automata. Briefly, the transition relation of a "label-free" generalized tree set automata is a relation

∆ ⊆ ∪ p Q p × F p × Q.
The emptiness decision algorithm for simple generalized tree set automata is straightforward. Indeed, Let ω be a subset of Q and let COND(ω) be the following condition: ∀p ∀f ∈ F p ∀q 1 , . . . , q p ∈ ω ∃q ∈ ω (q 1 , . . . , q p , f, q) ∈ ∆ We easily prove that there exists a set ω satisfying COND(ω) if and only if there exists an A-run. Therefore, the emptiness problem for simple generalized tree set automata is decidable because 2 Q is finite and COND(ω) is decidable. Decidability of the emptiness problem for simple generalized tree set automata is NP-complete (see Prop. 5.3.9).

The proof is more intricate in the general case, and it is not given in this book. Without the property of simple GTSA, we have to deal with a reachability problem of a set of states since we have to check that there exists ω ∈ Ω and a run r such that r assumes exactly all the states in ω.

We conclude this section with a complexity result of the emptiness problem in the class of generalized tree set automata.

Let us remark that a finite initial fragment of a "label-free" generalized tree set corresponds to a finite set of terms that is closed under the subterm relation. The size or the number of nodes in such an initial fragment is the number of different terms in the subterm-closed set of terms (the cardinality of the set of terms). The size of a GTSA is given by:

A = |Q| + f (q1,...,qp) l → q∈∆ (arity(f ) + 3) + ω∈Ω |ω|.
Let us consider a GTSA A with n states. The proof shows that one must consider at most all initial fragments of runs -hence corresponding to finite tree languages closed under the subterm relation-of size smaller than B(A), a polynomial in n, in order to decide emptiness for A. Let us remark that the polynomial bound B(A) can be computed. The emptiness proofs relies on the following lemma: Lemma 5.3.8. There exists a polynomial function f of degree 4 such that:

Let A = (Q, ∆, Ω) be a GTSA. There exists a successful run r s such that r s (T (F)) = ω ∈ Ω if and only if there exists a run r m and a closed tree language F such that:

• r m (T (F)) = r m (F ) = ω; • Card(F ) ≤ f (n)
where n is the number of states in ω.

Proposition 5.3.9. The emptiness problem in the class of (simple) generalized tree set automata is NP-complete.

Proof. Let A = (Q, ∆, Ω) be a generalized tree set automaton over E. Let n = Card(Q).

We first give a non-deterministic and polynomial algorithm for deciding emptiness: (1) take a tree language F closed under the subterm relation such that the number of different terms in it is smaller than B(A); (2) take a run r on F ; (3) compute r(F ); (4) check whether r(F ) = ω is a member of Ω; (5) check whether ω satisfies COND(ω).

From Theorem 5.3.7, this algorithm is correct and complete. Moreover, this algorithm is polynomial in n since (1) the size of F is polynomial in n: step (2) consists in labeling the nodes of F with states following the rules of the automaton -so there is a polynomial number of states, step (3) consists in collecting the states; step (4) is polynomial and non-deterministic and finally, step (5) is polynomial.

We reduce the satisfiability problem of boolean expressions into the emptiness problem for generalized tree set automata. We first build a generalized tree set automaton A such that L(A) is the set of (codes of) satisfiable boolean expressions over n variables {x 1 , . . . , x n }.

Let F = F 0 ∪ F 1 ∪ F 2 where F 0 = {x 1 , . . . , x n }, F 1 = {¬}, and F 2 = {∧, ∨}. A boolean expression is a term of T (F). Let Bool = {0, 1} be the set of boolean values. Let A = (Q, ∆, Ω), be a generalized tree set automaton such that Q = {q 0 , q 1 }, Ω = 2 Q and ∆ is the following set of rules:

x j i
→ q i where j ∈ {1, . . . , n} and i ∈ Bool ¬(q i ) ¬i → q ¬i where i ∈ Bool ∨(q i1 , q i2 ) i1∨i2

→ q i1∨i2 where i 1 , i 2 ∈ Bool ∧(q i1 , q i2 ) i1∧i2

→ q i1∧i2 where i 1 , i 2 ∈ Bool One can easily prove that L(A) = {L v | v is a valuation of {x 1 , . . . , x n }} where L v = {t | t is a boolean expression which is true under v}. L v corresponds to a run r v on a GTS g v and g v labels each x j either by 0 or 1. Hence, g v can be considered as a valuation v of x 1 , . . . , x n . This valuation is extended in g v to every node, that is to say that every term (representing a boolean expression) is labeled either by 0 or 1 accordingly to the usual interpretation of ¬, ∧, ∨. A given boolean expression is hence labeled by 1 if and only if it is true under the valuation v. Now, we can derive an algorithm for the satisfiability of any boolean expression e: build A e a generalized tree set automaton such that L(A) is the set of all tree languages containing e: {L | e ∈ L}; build A e ∩ A and decide emptiness.

We get then the reduction because A e ∩ A is empty if and only if e is not satisfiable. Now, it remains to prove that the reduction is polynomial. The size of A is 2 * n + 10. The size of A e is the length of e plus a constant. So we get the result.

Other Decision Results

Proposition 5.3.10. The inclusion problem and the equivalence problem for deterministic generalized tree set automata are decidable.

Proof. These results are a consequence of the closure properties under intersection and complementation (Propositions 5.3.1, 5.3.2), and the decidability of the emptiness property (Theorem 5.3.7).

Proposition 5.3.11. Let A be a generalized tree set automaton. It is decidable whether or not L(A) is a singleton set.

Proof. Let A be a generalized tree set automaton. First it is decidable whether L(A) is empty or not (Theorem 5.3.7). Second if L(A) is non empty then a regular generalized tree set g in L(A) can be constructed (see the proof of Theorem 5.3.7). Construct the strongly deterministic generalized tree set automaton A ′ such that L(A ′ ) is a singleton set reduced to the generalized tree set g. Finally, build A ∩ A ′ to decide the equivalence of A and A ′ . Note that we can build A ′ , since A ′ is deterministic (see Proposition 5.3.2).

Proposition 5.3.12. Let L = (L 1 , . . . , L n ) be a tuple of regular tree language and let A be a generalized tree set automaton over {0, 1} n . It is decidable whether

L ∈ L(A).
Proof. This result just follows from closure under intersection and emptiness decidability.

First construct a (strongly deterministic) generalized tree set automaton A L such that L(A) is reduced to the singleton set {L}. Second, construct A ∩ A L and decide whether L(A ∩ A L ) is empty or not.

Proposition 5.3.13. Given a generalized tree set automaton over E = {0, 1, } n and I ⊆ {1, . . . , n}. The following two problems are decidable: 1. It is decidable whether or not there exists (L 1 , . . . , L n ) in L(A) such that all the L i are finite for i ∈ I.

2. Let x 1 . . . , x n be natural numbers. It is decidable whether or not there exists

(L 1 , . . . , L n ) in L(A) such that Card(L i ) = x i for each i ∈ I.
The proof is technical and not given in this book. It relies on Lemma 5.3.8 of the emptiness decision proof.

Applications to Set Constraints

In this section, we consider the satisfiability problem for systems of set constraints. We show a decision algorithm using generalized tree set automata.

Definitions

Let F be a finite and non-empty set of function symbols. Let X be a set of variables. We consider special symbols ⊤, ⊥, ∼, ∪, ∩ of respective arities 0, 0, 1, 2, 2. A set expression is a term in T F ′ (X ) where F ′ = F ∪ {⊤, ⊥, ∼, ∪, ∩}.

A set constraint is either a positive set constraint of the form e ⊆ e ′ or a negative set constraint of the form e ⊆ e ′ (or ¬(e ⊆ e ′ )) where e and e ′ are set expressions, and a system of set constraints is defined by k i=1 SC i where the SC i are set constraints.

An interpretation I is a mapping from X into 2 T (F ) . It can immediately be extended to set expressions in the following way: We deduce an interpretation of set constraints in Bool = {0, 1}, the Boolean values. For a system of set constraints SC, all the interpretations I such that I(SC) = 1 are called solutions of SC. In the remainder, we will consider systems of set constraints of n variables X 1 , . . . , X n . We will make no distinction between a solution I of a system of set constraints and a n-tuple of tree languages (I(X 1 ), . . . , I(X n )). We denote by SOL(SC) the set of all solutions of a system of set constraints SC.

I(⊤) = T (F); I(⊥) = ∅; I(f (

Set Constraints and Automata

Proposition 5.4.1. Let SC be a system of set constraints (respectively of positive set constraints) of n variables X 1 , . . . , X n . There exists a deterministic (respectively deterministic and simple) generalized tree set automaton A over {0, 1} n such that L(A) is the set of characteristic generalized tree sets of the n-tuples (L 1 , . . . , L n ) of solutions of SC.

Proof. First we reduce the problem to a single set constraint. Let SC = C 1 ∧ . . . ∧ C k be a system of set constraints. A solution of SC satisfies all the constraints C i . Let us suppose that, for every i, there exists a deterministic generalized tree set automaton A i such that SOL(C i ) = L(A). As all variables in {X 1 , . . . , X n } do not necessarily occur in C i , using Corollary 5.3.4, we can construct a deterministic generalized tree set automaton A n i over {0, 1} n satisfying: L(A n i ) is the set of (L 1 , . . . , L n ) which corresponds to solutions of C i when restricted to the variables of C i . Using closure under intersection (Proposition 5.3.1), we can construct a deterministic generalized tree set automaton A over {0, 1} n such that SOL(SC) = L(A).

Therefore we prove the result for a set constraint SC of n variables X 1 , . . . , X n . Let E(exp) be the set of set variables and of set expression exp with a root symbol in F which occur in the set expression exp:

E(exp) = exp ′ ∈ T F ′ (X ) | exp ′ ¢ exp and such that either Head (exp ′ ) ∈ F or exp ′ ∈ X . If SC ≡ exp 1 ⊆ exp 2 or SC ≡ exp 1 ⊆ exp 2 then E(SC) = E(exp 1 )∪E(exp 2 ).
Let us consider a set constraint SC and let ϕ be a mapping ϕ from E(SC) into Bool. Such a mapping is easily extended first to any set expression occurring in SC and second to the set constraint SC. The symbols ∪, ∩, ∼, ⊆ and ⊆ are respectively interpreted as ∨, ∧, ¬, ⇒ and ¬ ⇒.

We now define the generalized tree set automaton

A = (Q, ∆, Ω) over E = {0, 1} n . • The set of states is Q is the set {ϕ | ϕ : E(SC) → Bool}.
• The transition relation is defined as follows:

f (ϕ 1 , . . . , ϕ p ) l → ϕ ∈ ∆ where ϕ 1 , . . . , ϕ p ∈ Q, f ∈ F p , l = (l 1 , . . . , l n ) ∈ {0, 1} n , and ϕ ∈ Q satisfies: ∀i ∈ {1, . . . , n} ϕ(X i ) = l i (5.6)
∀e ∈ E(SC) \ X (ϕ(e) = 1) ⇔ e = f (e 1 , . . . , e p ) ∀i 1 ≤ i ≤ p ϕ i (e i ) = 1 (5.7)

• The set of accepting sets of states Ω is defined depending on the case of a positive or a negative set constraint.

-

If SC is positive, Ω = {ω ∈ 2 Q | ∀ϕ ∈ ω ϕ(SC) = 1}; -If SC is negative, Ω = {ω ∈ 2 Q | ∃ϕ ∈ ω ϕ(SC) = 1}.
In the case of a positive set constraint, we can choose the state set Q = {ϕ | ϕ(SC) = 1} and Ω = 2 Q . Consequently, A is deterministic and simple.

The correctness of this construction is easy to prove and is left to the reader.

Decidability Results for Set Constraints

We now summarize results on set constraints. These results are immediate consequences of the results of Section 5.4.2. We use Proposition 5.4.1 to encode sets of solutions of systems of set constraints with generalized tree set automata and then, each point is deduced from Theorem 5.3.7, or Propositions 5.3.6, 5.3.13, 5.3.10, 5.3.11.

Properties on sets of solutions

Satisfiability The satisfiability problem for systems of set constraints is decidable.

Regular solution There exists a regular solution, that is a tuple of regular tree languages, in any non-empty set of solutions.

Inclusion, Equivalence Given two systems of set constraints SC and SC ′ , it is decidable whether or not SOL(SC) ⊆ SOL(SC ′ ).

Unicity Given a system SC of set constraints, it is decidable whether or not there is a unique solution in SOL(SC).

Properties on solutions fixed cardinalities, singletons Given a system SC of set constraints over (X 1 , . . . , X n ), I ⊆ {1, . . . , n}, and x 1 . . . , x n natural numbers;

• it is decidable whether or not there is a solution (L 1 , . . . , L n ) ∈ SOL(SC) such that Card(L i ) = x i for each i ∈ I.

• it is decidable whether or not all the L i are finite for i ∈ I.

In both cases, proofs are constructive and exhibits a solution.

Membership Given SC a system of set constraints over (X 1 , . . . , X n ) and a n-tuple (L 1 , . . . , L n ) of regular tree languages, it is decidable whether or not (L 1 , . . . , L n ) ∈ SOL(SC).

Proposition 5.4.2. Let SC be a system of positive set constraints, it is decidable whether or not there is a least solution in SOL(SC).

Proof. Let SC be a system of positive set constraints. Let A be the deterministic, simple generalized tree set automaton over {0, 1} n such that L(A) = SOL(SC) (see Proposition 5.4.1). We define a partial ordering on G {0,1} n by:

∀l, l ′ ∈ {0, 1} n l l ′ ⇔ (∀i l(i) ≤ l ′ (i)) ∀g, g ′ ∈ G {0,1} n g g ′ ⇔ (∀t ∈ T (F) g(t) g ′ (t))
The problem we want to deal with is to decide whether or not there exists a least generalized tree set w.r.t. in L(A). To this aim, we first build a minimal solution if it exists, and second, we verify that this solution is unique.

Let ω be a subset of states such that COND(ω) (see the sketch of proof page 152). Let A ω = (ω, ∆ ω , 2 ω ) be the generalized tree set automaton A restricted to state set ω. Now let ∆ ω min defined by: for each (q 1 , . . . , q p , f ) ∈ ω p × F p , choose in the set ∆ ω one rule (q 1 , . . . , q p , f, l, q) such that l is minimal w.r.t. . Let A ω min = (ω, ∆ ω min , 2 ω ). Consequently, 1. There exists only one run r ω on a unique generalized tree set g ω in A ω min because for all q 1 , . . . , q p ∈ ω and f ∈ F p there is only one rule (q 1 , . . . , q p , f, l, q) in ∆ ω min ;

2. the run r ω on g ω is regular;

3. the generalized tree set g ω is minimal w.r.t. in L(A ω ).

Points 1 and 2 are straightforward. The third point follows from the fact that A is deterministic. Indeed, let us suppose that there exists a run r ′ on a generalized tree set g ′ such that g ′ ≺ g ω . Therefore, ∀t g ′ (t) g ω (t), and there exists (w.l.o.g.) a minimal term u = f (u 1 , . . . , u p ) w.r.t. the subterm ordering such that g ′ (u) ≺ g ω (u). Since A is deterministic and ∀v ¡ u g ω (v) = g ′ (v), we have r ω (u i ) = r ′ (u i ). Hence, the rule (r ω (u 1 ), . . . , r ω (u p ), f, g ω (u), r ω (u)) is not such that g ω (u) is minimal in ∆ ω , which contradicts the hypothesis.

Consider the generalized tree sets g ω for all subsets of states ω satisfying COND(ω). If there is no such g ω , then there is no least generalized tree set g in L(A). Otherwise, each generalized tree set defines a n-tuple of regular tree languages and inclusion is decidable for regular tree languages. Hence we can identify a minimal generalized tree set g among all g ω . This GTS g defines a n-tuple (F 1 , . . . , F n ) of regular tree languages. Let us remark this construction does not ensure that (F 1 , . .

. , F n ) is minimal in L(A).

There is a deterministic, simple generalized tree set automaton A ′ such that L(A ′ ) is the set of characteristic generalized tree sets of all (L 1 , . . . , L n ) satisfying F 1 ⊆ L 1 , . . . , F n ⊆ L n (see Proposition 5.3.6). Let A ′′ be the deterministic generalized tree set automaton such that L(A ′′ ) = L(A) ∩ L(A ′ ) (see Proposition 5.3.1). There exists a least generalized tree set w.r.t. in L(A) if and only if the generalized tree set automata A and A ′′ are equivalent. Since equivalence of generalized tree set automata is decidable (see Proposition 5.3.10) we get the result.

Bibliographical Notes

We now survey decidability results for satisfiability of set constraints and some complexity issues.

Decision procedures for solving set constraints arise with [START_REF] Reynolds | Automatic Computation of Data Set Definition[END_REF], and Mishra [START_REF] Mishra | Towards a Theory of Types in PROLOG[END_REF]. The aim of these works was to obtain new tools for type inference and type checking [START_REF] Aiken | Implementing regular tree expressions[END_REF][START_REF] Heintze | Set Based Program Analysis[END_REF][START_REF] Heintze | A finite presentation theorem for approximating logic programs[END_REF][START_REF] Jones | Flow Analysis and Optimization of LISP-like Structures[END_REF][START_REF] Mishra | Towards a Theory of Types in PROLOG[END_REF][START_REF] Reynolds | Automatic Computation of Data Set Definition[END_REF].

First consider systems of set constraints of the form:

X 1 = exp 1 , . . . , X n = exp n (5.8)
where the X i are distinct variables and the exp i are disjunctions of set expressions of the form f (X i1 , . . . , X ip ) with f ∈ F p . These systems of set constraints are essentially tree automata, therefore they have a unique solution and each X i is interpreted as a regular tree language. Suppose now that the exp i are set expressions without complement symbols. Such systems are always satisfiable and have a least solution which is regular. For example, the system

Nat = s(Nat) ∪ 0 X = X ∩ Nat List = cons(X, List) ∪ nil has a least solution Nat = {s i (0) | i ≥ 0} , X = ∅ , List = {nil}.
[HJ90a] investigate the class of definite set constraints which are of the form exp ⊆ exp ′ , where no complement symbol occurs and exp ′ contains no set operation. Definite set constraints have a least solution whenever they have a solution. The algorithm presented in [START_REF] Heintze | A Decision Procedure for a Class of Set Constraints[END_REF] provides a specific set of transformation rules and, when there exists a solution, the result is a regular presentation of the least solution, in other words a system of the form (5.8).

Solving definite set constraints is EXPTIME-complete [START_REF] Charatonik | Set Constraints with Intersection[END_REF]. Many developments or improvements of Heinzte and Jaffar's method have been proposed and some are based on tree automata [START_REF] Devienne | Solving classes of set constraints with tree automata[END_REF].

The class of positive set constraints is the class of systems of set constraints of the form exp ⊆ exp ′ , where no projection symbol occur. In this case, when a solution exists, set constraints do not necessarily have a least solution. Several algorithms for solving systems in this class were proposed, [START_REF] Aiken | Solving Systems of Set Constraints[END_REF] generalize the method of [START_REF] Heintze | A Decision Procedure for a Class of Set Constraints[END_REF], [START_REF] Gilleron | Solving systems of set constraints with negated subset relationships[END_REF][START_REF] Gilleron | Set constraints and automata[END_REF] give an automata-based algorithm, and [START_REF] Bachmair | Set constraints are the monadic class[END_REF] use the decision procedure for the first order theory of monadic predicates. Results on the computational complexity of solving systems of set constraints are presented in a paper of [START_REF] Aiken | The complexity of set constraints[END_REF]. The systems form a natural complexity hierarchy depending on the number of elements of F of each arity. The problem of existence of a solution of a system of positive set constraints is NEXPTIME-complete.

The class of positive and negative set constraints is the class of systems of set constraints of the form exp ⊆ exp ′ or exp ⊆ exp ′ , where no projection symbol occur. In this case, when a solution exists, set constraints do not necessarily have, neither a minimal solution, nor a maximal solution. Let F = {a, b()}. Consider the system (b(X) ⊆ X) ∧ (X ⊆ ⊥), this system has no minimal solution. Consider the system (X ⊆ b(X) ∪ a) ∧ (⊤ ⊆ X), this system has no maximal solution. The satisfiability problem in this class turned out to be much more difficult than the positive case. [START_REF] Aiken | Decidability of systems of set constraints with negative constraints[END_REF] give a proof based on a reachability problem involving Diophantine inequalities. NEXPTIMEcompleteness was proved by [START_REF] Stefansson | Systems of set constraints with negative constraints are nexptime-complete[END_REF]. [START_REF] Charatonik | Negative set constraints with equality[END_REF] gives a proof based on the ideas of [START_REF] Bachmair | Set constraints are the monadic class[END_REF].

The class of positive set constraints with projections is the class of systems of set constraints of the form exp ⊆ exp ′ with projection symbols. Set constraints of the form f -1 i (X) ⊆ Y can easily be solved, but the case of set constraints of the form X ⊆ f -1 i (Y ) is more intricate. The problem was proved decidable by [START_REF] Charatonik | Set constraints with projections are in NEXPTIME[END_REF].

The expressive power of these classes of set constraints have been studied and have been proved to be different [START_REF] Seynhaeve | Contraintes ensemblistes[END_REF]. In [START_REF] Cheng | A complete Gentzen-style axiomatization for set constraints[END_REF][START_REF] Kozen | Logical aspects of set constraints[END_REF], an axiomatization is proposed which enlightens the reader on relationships between many approaches on set constraints.

Furthermore, set constraints have been studied in a logical and topological point of view [START_REF] Kozen | Rational spaces and set constraints[END_REF][START_REF] Mcallester | Tarskian set constraints[END_REF]. This last paper combine set constraints with Tarskian set constraints, a more general framework for which many complexity results are proved or recalled. Tarskian set constraints involve variables, relation and function symbols interpreted relative to a first order structure.

Topological characterizations of classes of GTSA recognizable sets, have also been studied in [START_REF] Tommasi | Automates et contraintes ensemblistes[END_REF][START_REF] Seynhaeve | Contraintes ensemblistes[END_REF]. Every set in R SGTS is a compact set and every set in R GTS is the intersection between a compact set and an open set. These remarks give also characterizations for the different classes of set constraints.

Chapter 6

Tree Transducers

Introduction

Finite state transformations of words, also called a-transducers or rational transducers in the literature, model many kinds of processes, such as coffee machines or lexical translators. But these transformations are not powerful enough to model syntax directed transformations, and compiler theory is an important motivation to the study of finite state transformations of trees. Indeed, translation of natural or computing languages is directed by syntactical trees, and a translator from L A T E X into HTML is a tree transducer. Unfortunately, from a theoretical point of view, tree transducers do not inherit nice properties of word transducers, and the classification is very intricate. So, in the present chapter we focus on some aspects. In Sections 6.2 and 6.3, toy examples introduce in an intuitive way different kinds of transducers. In Section 6.2, we summarize main results in the word case. Indeed, this book is mainly concerned with trees, but the word case is useful to understand the tree case and its difficulties. The bimorphism characterization is the ideal illustration of the link between the "machine" point of view and the "homomorphic" one. In Section 6.3, we motivate and illustrate bottom-up and top-down tree transducers, using compilation as leitmotiv. We precisely define and present the main classes of tree transducers and their properties in Section 6.4, where we observe that general classes are not closed under composition, mainly because of alternation of copying and nondeterministic processing. Nevertheless most useful classes, as those used in Section 6.3, have closure properties. In Section 6.5 we present the homomorphic point of view.

Most of the proofs are tedious and are omitted. This chapter is a very incomplete introduction to tree transducers. Tree transducers are extensively studied for themselves and for various applications. But as they are somewhat complicated objects, we focus here on the definitions and main general properties. It is useful for every theoretical computer scientist to know main notions about tree transducers, because they are the main model of syntax directed manipulations, and that the heart of software manipulations and interfaces are syntax directed. Tree transducers are an essential frame to develop practical modular syntax directed algorithms, thought an effort of algorithmic engineering remains to do. Tree transducers theory can be fertilized by other area or can be useful for other areas (example: Ground tree transducers for decidability of the first order theory of ground rewriting). We will be happy if after reading this chapter, the reader wants for further lectures, as monograph of Z. Fülöp and H. Vögler (December 1998 [START_REF] Fülöp | Formal Models Based on Tree Transducers[END_REF]).

The Word Case

Introduction to Rational Transducers

We assume that the reader roughly knows popular notions of language theory: homomorphisms on words, finite automata, rational expressions, regular grammars. See for example the recent survey of A. Mateescu and A. Salomaa [START_REF] Mateescu | Aspects of classical language theory[END_REF]. A rational transducer is a finite word automaton W with output. In a word automaton, a transition rule f (q) → q ′ (f ) means "if W is in some state q, if it reads the input symbol f , then it enters state q ′ and moves its head one symbol to the right". For defining a rational transducer, it suffices to add an output, and a transition rule f (q) → q ′ (m) means "if the transducer is in some state q, if it reads the input symbol f , then it enters state q ′ , writes the word m on the output tape, and moves its head one symbol to the right". Remark that with these notations, we identify a finite automaton with a rational transducer which writes what it reads. Note that m is not necessarily a symbol but can be a word, including the empty word. Furthermore, we assume that it is not necessary to read an input symbol, i.e. we accept transition rules of the form ε(q) → q ′ (m) (ε denotes the empty word).

Graph presentations of finite automata are popular and convenient. So it is for rational transducers. The rule f (q) → q ′ (m) will be drawn

q q ′ f /m
Example 6.2.1. (Language L 1 ) Let F = { , , ; , 0, 1, A, ..., Z}. In the following, we will consider the language L 1 defined on F by the regular grammar (the

axiom is program): program → instruct instruct → LOAD register | STORE register | MULT register → | ADD register register → 1tailregister tailregister → 0tailregister | 1tailregister | ; instruct |
( a → b|c is an abbreviation for the set of rules {a → b, a → c}) L 1 is recognized by deterministic automaton A 1 of Figure 6.1. Semantic of L 1 is well known: LOAD i loads the content of register i in the accumulator; STORE i stores the content of the accumulator in register i; ADD i adds in the accumulator the content of the accumulator and the content of register i; MULT i multiplies in the accumulator the content of the accumulator and the content of register i.

Begin Instruct register

Tail Register end

L O A D S T O R E M U L T A D D ; 0,1 1 Figure 6.1: A recognizer of L 1 A rational transducer is a tuple R = (Q, F, F ′ , Q i , Q f , ∆)
where Q is a set of states, F and F ′ are finite nonempty sets of input letters and output letters, Q i , Q f ⊆ Q are sets of initial and final states and ∆ is a set of transduction rules of the following type:

f (q) → q ′ (m), where f ∈ F ∪ {ε} , m ∈ F ′ * , q, q ′ ∈ Q. R is ε-free if there is no rule f (q) → q ′ (m) with f = ε in ∆. The move relation → R is defined by: let t, t ′ ∈ F * , u ∈ F ′ * , q, q ′ ∈ Q, f ∈ F, m ∈ F ′ * , (tqf t ′ , u) → R (tf q ′ t ′ , um) ⇔ f (q) → q ′ (m) ∈ ∆,
and → * R is the reflexive and transitive closure of → R . A (partial) transduction of R on tt ′ t ′′ is a sequence of move steps of the form (tqt

′ t ′′ , u) → * R (tt ′ q ′ t ′′ , uu ′ ). A transduction of R from t ∈ F * into u ∈ F ′ * is a transduction of the form (qt, ε) → * R (tq ′ , u) with q ∈ Q i and q ′ ∈ Q f .
The relation T R induced by R can now be formally defined by:

T R = {(t, u) | (qt, ε) * → R (tq ′ , u) with t ∈ F * , u ∈ F ′ * , q ∈ Q i , q ′ ∈ Q f }.
A relation in F * × F ′ * is a rational transduction if and only if it is induced by some rational transducer. We also need the following definitions:

let t ∈ F * , T R (t) = {u | (t, u) ∈ T R }. The translated of a language L is the language defined by T R (L) = {u | ∃t ∈ L, u ∈ T R (t)}.
Example 6.2.2. Ex. 6.2.2.1

Let us name French-L 1 the translation of L 1 in French (LOAD is translated into CHARGER and STORE into STOCKER). Transducer of Figure 6.2 achieves this translation. This example illustrates the use of rational transducers as lexical transducers.

Ex. 6.2.2.2

Let us consider the rational transducer Diff defined by Q = {q i , q s , q l , q d }, F = F ′ = {a, b}, Q i = {q i }, Q f = {q s , q l , q d }, and ∆ is the set of rules:

type i(dentical) a(q i ) → q i (a), b(q i ) → q i (b) type s(horter) ε(q i ) → q s (a), ε(q i ) → q s (b), ε(q s ) → q s (a), ε(q s ) → q s (b) type l(onger) a(q i ) → q l (ε), b(q i ) → q l (ε), a(q l ) → q l (ε), b(q l ) → q l (ε) type d(ifferent) a(q i ) → q d (b), b(q i ) → q d (a), a(q d ) → q d (ε), b(q d ) → q d (ε), ε(q d ) → q d (a), ε(q d ) → q d (b). It is easy to prove that T Diff = {(m, m ′ ) | m = m ′ , m, m ′ ∈ {a, b} * }.
We give without proofs some properties of rational transducers. For more details, see [START_REF] Salomaa | Formal Languages[END_REF] or [START_REF] Mateescu | Aspects of classical language theory[END_REF] and Exercises 6.1, 6.2, 6.4 for 1, 4 and 5. The homomorphic approach presented in the next section can be used as an elegant way to prove 2 and 3 (Exercise 6.6).

Begin Instruct register

Tail Register end

/ L/ε O/ε A/ε D / C H A R G E R S/ε T/ε O/ε R/ε E/STOCKER M/ε U/ε L/ε T / M U L T A/ε D/ε D / A J O U T E R ;/; 0/0 1/1 1/1 / Figure 6.2: A rational transducer from L 1 into French-L 1 .
Proposition 6.2.3 (Main properties of rational transducers).

1. The class of rational transductions is closed under union but not closed under intersection.

2. The class of rational transductions is closed under composition.

3. Regular languages and context-free languages are closed under rational transduction.

4. Equivalence of rational transductions is undecidable.

5. Equivalence of deterministic rational transductions is decidable.

The Homomorphic Approach

A bimorphism is defined as a triple B = (Φ, L, Ψ) where L is a recognizable language and Φ and Ψ are homomorphisms. The relation induced by B (also denoted by B) is defined by

B = {(Φ(t), Ψ(t)) | t ∈ L}. Bimorphism (Φ, L, Ψ) is ε-free if Φ is ε-free (an homomorphism is ε-free if the
image of a letter is never reduced to ε). Two bimorphisms are equivalent if they induce the same relation.

We can state the following theorem, generally known as Nivat Theorem [Niv68] (see Exercises 6.5 and 6.6 for a sketch of proof). Theorem 6.2.4 (Bimorphism theorem). Given a rational transducer, an equivalent bimorphism can be constructed. Conversely, any bimorphism defines a rational transduction. Construction preserves ε-freeness. Example 6.2.5. Ex. 6.2.5.1

The relation {(a(ba

) n , a n ) | n ∈ N} ∪ {((ab) n , b 3n ) | n ∈ N} is processed by transducer R and bimorphism B of Figure 6.3 a/ε a/ε a/ε b/ε b/bbb a/ε b/bbb Φ(A) = a Ψ(A) = ε Φ(B) = ba Ψ(B) = a Φ(C) = ab Ψ(C) = bbb A C B C Φ Ψ Figure 6.3: Transducer R and an equivalent bimorphism B = {(Φ(t), Ψ(t)) | t ∈ ǫ + AB * + CC * }.
Ex. 6.2.5.2 Automaton L of Figure 6.4 and morphisms Φ and Ψ below define a bimorphism equivalent to the transducer in Figure 6 Nivat characterization of rational transducers makes intuitive sense. Automaton L can be seen as a control of the actions, morphism Ψ can be seen as output function and Φ -1 as an input function. Φ -1 analyses the input -it is a kind of part of lexical analyzer -and it generates symbolic names; regular grammatical structure on theses symbolic names is controlled by L. Examples 6.2.5.1 and 6.2.5.2 are an obvious illustration. L is the common structure to English and French versions, Φ generates the English version and Ψ generates the French one. This idea is the major idea of compilation, but compilation of computing languages or translation of natural languages are directed by syntax, that is to say by syntactical trees. This is the motivation for the sequel of the chapter. But unfortunately, from a formal point of view, we will loose most of the nice properties obtained in the word case. Expressivity of non-linear tree transducers will explain in part this complication, but, even in the linear case, there is a new phenomenon in trees, the understanding of which can be introduced by the "problem of homomorphism inversion" that we describe in Exercise 6.7.

.2 Φ(β) = Φ(λ) = LOAD Φ(σ) = STORE Φ(µ) = MULT Φ(α) = ADD Φ(ρ) =; Φ(ω) = 1 Φ(ζ) = 0 Φ(θ) = Ψ(β) = Ψ(λ) = CHARGER Ψ(σ) = STOCKER Ψ(µ) = MULT Ψ(α) = ADD Ψ(ρ) =; Ψ(ω) = 1 Ψ(ζ) = 0 Ψ(θ) =

Introduction to Tree Transducers

Tree transducers and their generalizations model many syntax directed transformations (see exercises). We use here a toy example of compiler to illustrate how usual tree transducers can be considered as modules of compilers.

We consider a simple class of arithmetic expressions (with usual syntax) as source language. We assume that this language is analyzed by a LL(1) parser.

We consider two target languages: L 1 defined in Example 6.2.1 and an other language L 2 . A transducer A translates syntactical trees in abstract trees (Figure 6.5). A second tree transducer R illustrates how tree transducers can be seen as part of compilers which compute attributes over abstract trees. It decorates abstract trees with numbers of registers (Figure 6.7). Thus R translates abstract trees into attributed abstract trees. After that, tree transducers T 1 and T 2 generate target programs in L 1 and L 2 , respectively, starting from attributed abstract trees (Figures 6.7 and 6.8). This is an example of nonlinear transducer. Target programs are yields of generated trees. So composition of transducers model succession of compilation passes, and when a class of transducers is closed by composition (see section 6.4), we get universal constructions to reduce the number of compiler passes and to meta-optimize compilers.

We now define the source language. Let us consider the terminal alphabet {(, ), +, ×, a, b, . . . , z}. First, the context-free word grammar G 1 is defined by rules (E is the axiom):

E → M | M + E M → F | F × M F → I | (E) I → a | b | • • • | z
Another context-free word grammar G 2 is defined by (E is the axiom):

E → M E ′ E ′ → +E | ε M → F M ′ M ′ → ×M | ε F → I | (E) I → a | b | • • • | z
It is easy to prove that G 1 and G 2 are equivalent, i.e. they define the same source language. On the one hand, G 1 is more natural, on the other hand G 2 could be preferred for syntactical analysis reason, because G 2 is LL(1) and G 1 is not LL. We consider syntactical trees as derivation trees for the tree grammar G 2 .

Let us consider word u = (a + b) × c of the source language. We define the abstract tree associated with u as the tree ×(+(a, b), c) defined over F = {+(, ), ×(, ), a, b, c}. Abstract trees are ground terms over F. The following transformation associates with a syntactical tree t its corresponding abstract tree A(t).

I(x) → x F (x) → x M (x, M ′ (ε)) → x E(x, E ′ (ε)) → x M (x, M ′ (×, y)) → ×(x, y) E(x, E ′ (+, y)) → +(x, y) F ((, x, )) → x
We have not precisely defined the use of the arrow →, but it is intuitive. Likewise we introduce examples before definitions of different kinds of tree transducers (section 6.4 supplies a formal frame).

To illustrate nondeterminism, let us introduce two new transducers A and A ′ . Some brackets are optional in the source language, hence A ′ is nondeterministic. Note that A works from frontier to root and A ′ works from root to frontier.

A: an Example of Bottom-up Tree Transducer

The following linear deterministic bottom-up tree transducer A carries out transformation of derivation trees for G 2 , i.e. syntactical trees, into their corresponding abstract trees. Empty word ε is identified as a constant symbol in syntactical trees. States of A are q, q ε , q I , q F , q M ′ ε , q E ′ ε , q E , q × , q M ′ × , q + , q E ′ + , q ( , and q ) . Final state is q E . The set of transduction rules is:

a → q(a) b → q(b) c → q(c) ε → q ε (ε) ) → q ) ()) ( → q ( (() + → q + (+) × → q × (×) I(q(x)) → q I (x) F (q I (x)) → q F (x) M ′ (q ε (x)) → q M ′ ε (x) E ′ (q ε (x)) → q E ′ ε (x) M (q F (x), q M ′ ε(y) ) → q M (x) E(q M (x), q E ′ ε (y)) → q E (x) M ′ (q × (x), q M (y)) → q M ′ × (y) M (q F (x), q M ′ × (y)) → q M (×(x, y)) E ′ (q + (x), q E (y)) → q E ′ + (y) E(q M (x), q E ′ + (y)) → q E (+(x, y)) F (q ( (x), q E (y), q ) (z)) → q F (y)
The notion of (successful) run is an intuitive generalization of the notion of run for finite tree automata. The reader should note that FTAs can be considered as a special case of bottom-up tree transducers whose output is equal to the input. We give in Figure 6.5 a run of A which translates the derivation tree t of (a + b) × c w.r.t. G 2 into the corresponding abstract tree ×(+(a, b), c).

t → * A ( q ( a q M b q E ′ + E ) q ) F c q M ′ × M ε q E ′ ε E → * A a b + q F c q M ′ × M ε q E ′ ε E → * A a b + c × q E Figure 6.5: Example of run of A A ′ :

an Example of Top-down Tree Transducer

The inverse transformation A -1 , which computes the set of syntactical trees associated with an abstract tree, is computed by a nondeterministic top-down tree transducer A ′ . The states of A ′ are q E , q F , q M . The initial state is q E . The set of transduction rules is:

q E (x) → E(q M (x), E ′ (ε)) q E (+(x, y)) → E(q M (x), E ′ (+, q E (y))) q M (x) → M (q F (x), M ′ (ε)) q M (×(x, y)) → M (q F (x), M ′ (×, q M (y))) q F (x) → F ((, q E (x), )) q F (a) → F (I(a)) q F (b) → F (I(b)) q F (c) → F (I(c))
Transducer A ′ is nondeterministic because there are ε-rules like q E (x) → E(q M (x), E ′ (ε)). We give in Figure 6.6 a run of A ′ which transforms the abstract tree +(a, ×(b, c)) into a syntactical tree t ′ of the word a

+ b × c. a b c × + q E → A ′ a q M + b c × q E E ′ E → * A ′ a I F ε M ′ M + b c × q E E ′ E → * A ′ t ′ Figure 6.6: Example of run of A ′

Compilation

The compiler now transforms abstract trees into programs for some target languages. We consider two target languages. The first one is L 1 of Example 6.2.1.

To simplify, we omit ";", because they are not necessary -we introduced semicolons in Section 6.2 to avoid ε-rules, but this is a technical detail, because word (and tree) automata with ε-rules are equivalent to usual ones. The second target language is an other very simple language L 2 , namely sequences of two instructions +(i, j, k) (put the sum of contents of registers i and j in the register k) and ×(i, j, k). In a first pass, we attribute to each node of the abstract tree the minimal number of registers necessary to compute the corresponding sub-expression in the target language. The second pass generates target programs.

First pass: computation of register numbers by a deterministic linear bottomup transducer R.

States of a tree automaton can be considered as values of (finitely valued) attributes, but formalism of tree automata does not allow decorating nodes of trees with the corresponding values. On the other hand, this decoration is easy with a transducer. Computation of finitely valued inherited (respectively synthesized) attributes is modeled by top-down (respectively bottom-up) tree transducers. Here, we use a bottom-up tree transducer R. States of R are q 0 , . . . , q n . All states are final states. The set of rules is:

a → q 0 (a) b → q 0 (b) c → q 0 (c) +(q i (x), q i (y)) → q i+1 ( + i+1 (x, y)) ×(q i (x), q i (y)) → q i+1 ( × i+1 (x, y)) if i > j +(q i (x), q j (y)) → q i ( + i (x, y)
×(q i (x), q j (y)) → q i ( × i (x, y)) if i < j, we permute the order of subtrees +(q i (x), q j (y)) → q j ( + j (y, x)) ×(q i (x), q j (y)) → q j ( × j (y, x))

A run t → * R q i (u) means that i registers are necessary to evaluate t. Root of t is then relabelled in u by symbol + i or × i .

Second pass: generation of target programs in L 1 or L 2 , by top-down deterministic transducers T 1 and T 2 . T 1 contains only one state q. Set of rules of T 1 is:

q( + i (x, y)) → ⋄(q(x), STOREi, q(y), ADDi, STOREi) q( × i (x, y)) → ⋄(q(x), STOREi, q(y), MULTi, STOREi) q(a) → ⋄(LOAD, a) q(b) → ⋄(LOAD, b) q(c) → ⋄(LOAD, c)
where ⋄(, , , , ) and ⋄(, ) are new symbols.

State set of T 2 is {q, q ′ } where q is the initial state. Set of rules of T 2 is: q( + i (x, y)) → #(q(x), q(y), +, (, q ′ (x), q ′ (y), i, )) q ′ ( + i (x, y)) → i q( × i (x, y)) → #(q(x), q(y), ×, (, q ′ (x), q ′ (y), i,

)) q ′ ( × i (x, y)) → i q(a) → ε q ′ (a) → a q(b) → ε q ′ (b) → b q(c) → ε q ′ (c) → c
where # is a new symbol of arity 8.

The reader should note that target programs are words formed with leaves of trees, i.e. yields of trees. Examples of transductions computed by T 1 and T 2 are given in Figures 6.7 and 6.8. The reader should also note that T 1 is an homomorphism. Indeed, an homomorphism can be considered as a particular case of deterministic transducer, namely a transducer with only one state (we can consider it as bottom-up as well as top-down). The reader should also note that T 2 is deterministic but not linear.

Properties of Tree Transducers

Bottom-up Tree Transducers

We now give formal definitions. In this section, we consider academic examples, without intuitive semantic, to illustrate phenomena and properties. Tree transducers are both generalization of word transducers and tree automata. We first a b c

+ d × + → * R b c + 1 d × 1 a + 1 q 1 = q 1 (u). q(u) → * T1 L b ⋄ S1 L c ⋄ A1 S1 ⋄ S1 L d ⋄ M1 S1 ⋄ S1 L a ⋄ A1 S1
⋄ where L stands for LOAD, S stands for STORE, A stands for ADD, M stands for MULT.

The corresponding program is the yield of this tree:

LOADb STORE1 LOADc ADD1 STORE1 STORE1 LOADd MULT1 STORE1 STORE1 LOADa ADD1 STORE1
Figure 6.7: Decoration with synthesized attributes of an abstract tree, and translation into a target program of L 1 .

q(u) → * T2 ε ε + ( b c 1 ) ♯ ε × ( 1 d 1 ) ♯ ε + ( 1 a 1 )

♯

The corresponding program is the yield of this tree: +(bc1) × (1d1) + (1a1) Figure 6.8: Translation of an abstract tree into a target program of L 2 consider bottom-up tree transducers. A transition rule of a NFTA is of the type f (q 1 (x 1 ), . . . , q n (x n )) → q(f (x 1 , . . . , x n )). Here we extend the definition (as we did in the word case), accepting to change symbol f into any term.

A bottom-up Tree Transducer (NUTT) is a tuple U = (Q, F, F ′ , Q f , ∆) where Q is a set of (unary) states, F and F ′ are finite nonempty sets of input symbols and output symbols, Q f ⊆ Q is a set of final states and ∆ is a set of transduction rules of the following two types:

f (q 1 (x 1 ), . . . , q n (x n )) → q(u) , where f ∈ F n , u ∈ T (F ′ , X n ), q, q 1 , . . . , q n ∈ Q , or q(x 1 ) → q ′ (u) (ε-rule),
where u ∈ T (F ′ , X 1 ), q, q ′ ∈ Q.

As for NFTA, there is no initial state, because when a symbol is a leave a (i.e. a constant symbol), transduction rules are of the form a → q(u), where u is a ground term. These rules can be considered as "initial rules". Let

t, t ′ ∈ T (F ∪ F ′ ∪ Q). The move relation → U is defined by: t → U t ′ ⇔            ∃f (q 1 (x 1 ), . . . , q n (x n )) → q(u) ∈ ∆ ∃C ∈ C(F ∪ F ′ ∪ Q) ∃u 1 , . . . , u n ∈ T (F ′ ) t = C[f (q 1 (u 1 ), . . . , q n (u n ))] t ′ = C[q(u{x 1 ←u 1 , . . . , x n ←u n })]
This definition includes the case of ε-rule as a particular case. The reflexive and transitive closure of → U is → * U . A transduction of U from a ground term t ∈ T (F) to a ground term t ′ ∈ T (F ′ ) is a sequence of move steps of the form t → * U q(t ′ ), such that q is a final state. The relation induced by U is the relation (also denoted by U ) defined by:

U = {(t, t ′ ) | t * → U q(t ′ ), t ∈ T (F), t ′ ∈ T (F ′ ), q ∈ Q f }. The domain of U is the set {t ∈ T (F) | (t, t ′ ) ∈ U }. The image by U of a set of ground terms L is the set U (L) = {t ′ ∈ T (F ′ ) | ∃t ∈ L, (t, t ′ ) ∈ U }.
A transducer is ε-free if it contains no ε-rule. It is linear if all transition rules are linear (no variable occurs twice in the right-hand side). It is non-erasing if, for every rule, at least one symbol of F ′ occurs in the right-hand side. It is said to be complete (or non-deleting) if, for every rule f (q 1 (x 1 ), . . . , q n (x n )) → q(u) , for every x i (1 ≤ i ≤ n), x i occurs at least once in u. It is deterministic (DUTT) if it is ε-free and there is no two rules with the same left-hand side.

Example 6.4.1. Ex. 6.4.1.1

Tree transducer A defined in Section 6.3 is a linear DUTT. Tree transducer R in Section 6.3 is a linear and complete DUTT.

Ex. 6.4.1.2

States of U 1 are q, q ′ ; F = {f (), a}; F ′ = {g(, ), f (), f ′ (), a}; q ′ is the final state; the set of transduction rules is:

a → q(a) f (q(x)) → q(f (x)) | q(f ′ (x)) | q ′ (g(x, x))
U 1 is a complete, non linear NUTT. We now give the transductions of the ground term f (f (f (a))). For the sake of simplicity, f f f a stands for f (f (f (a))). We have:

U 1 ({f f f a}) = {g(f f a, f f a), g(f f ′ a, f f ′ a), g(f ′ f a, f ′ f a), g(f ′ f ′ a, f ′ f ′ a)}.
U 1 illustrates an ability of NUTT, that we describe following Gécseg and Steinby:

B1-"Nprocess and copy" A NUTT can first process an input subtree nondeterministically and then make copies of the resulting output tree.

Ex. 6.4.1.3

States of U 2 are q, q ′ , q f ; F = {f (, ), g(), a}; F = F ′ ∪ {f ′ ()}; q f is the final state; the set of transduction rules is defined by:

a → q(a) | q ′ (a) g(q(x)) → q(g(x)) g(q ′ (x)) → q ′ (g(x)) f (q ′ (x), q ′ (y)) → q ′ (f (x, y)) f (q ′ (x), q(y)) → q f (f ′ (x)) U 2 is a non complete NUTT. The tree transformation induced by U 2 is {(f (t 1 , t 2 ), f ′ (t 1 )) | t 2 = g m (
a) for some m}. It illustrates an ability of NUTT, that we describe following Gécseg and Steinby:

B2-"check and delete" A NUTT can first check regular constraints on input subterms and delete these subterms afterwards.

Bottom-up tree transducers translate the input trees from leaves to root, so bottom-up tree transducers are also called frontier-to-root transducers. Topdown tree transducers work in opposite direction.

Top-down Tree Transducers

A top-down Tree Transducer (NDTT) is a tuple D = (Q, F, F ′ , Q i , ∆) where Q is a set of (unary) states, F and F ′ are finite nonempty sets of input symbols and output symbols, Q i ⊆ Q is a set of initial states and ∆ is a set of transduction rules of the following two types:

q(f (x 1 , . . . , x n )) → u[q 1 (x i1 ), . . . , q p (x ip )] ,
where f ∈ F n , u ∈ C p (F ′ ), q, q 1 , . . . , q p ∈ Q, , x i1 , . . . , x ip ∈ X n , or q(x) → u[q 1 (x), . . . , q p (x)] (ε-rule), where u ∈ C p (F ′ ), q, q 1 , . . . , q p ∈ Q, x ∈ X .

As for top-down NFTA, there is no final state, because when a symbol is a leave a (i.e. a constant symbol), transduction rules are of the form q(a) → u, where u is a ground term. These rules can be considered as "final rules". Let t, t ′ ∈ T (F ∪ F ′ ∪ Q). The move relation → D is defined by:

t → D t ′ ⇔            ∃q(f (x 1 , . . . , x n )) → u[q 1 (x i1 ), . . . , q p (x ip )] ∈ ∆ ∃C ∈ C(F ∪ F ′ ∪ Q) ∃u 1 , . . . , u n ∈ T (F) t = C[q(f (u 1 , . . . , u n ))] t ′ = C[u[q 1 (v 1 ), . . . , q p (v p )])] where v j = u k if x ij = x k
This definition includes the case of ε-rule as a particular case. → * D is the reflexive and transitive closure of → D . A transduction of D from a ground term t ∈ T (F) to a ground term t ′ ∈ T (F ′ ) is a sequence of move steps of the form q(t) → * D t ′ , where q is an initial state. The transformation induced by D is the relation (also denoted by D) defined by:

D = {(t, t ′ ) | q(t) * → D t ′ , t ∈ T (F), t ′ ∈ T (F ′ ), q ∈ Q i }. The domain of D is the set {t ∈ T (F) | (t, t ′ ) ∈ D}. The image of a set of ground terms L by D is the set D(L) = {t ′ ∈ T (F ′ ) | ∃t ∈ L, (t, t ′ ) ∈ D}.
ε-free, linear, non-erasing, complete (or non-deleting), deterministic top-down tree transducers are defined as in the bottom-up case.

Example 6.4.2. Ex. 6.4.2.1

Tree transducers A ′ , T 1 , T 2 defined in Section 6.3 are examples of NDTT.

Ex. 6.4.2.2

Let us now define a non-deterministic and non linear NDTT D 1 . States of D 1 are q, q ′ . The set of input symbols is F = {f (), a}. The set of output symbols is F ′ = {g(, ), f (), f ′ (), a}. The initial state is q. The set of transduction rules is:

q(f (x)) → g(q ′ (x), q ′ (x)) (copying rule) q ′ (f (x)) → f (q ′ (x)) | f ′ (q ′ (x)) (non deterministic relabeling) q ′ (a) → a D 1 transduces f (f (f (a))) (or briefly f f f a) into the set of 16 trees: {g(f f a, f f a), g(f f a, f f ′ a), g(f f a, f ′ f a), . . . , g(f ′ f ′ a, f ′ f a), g(f ′ f ′ a, f ′ f ′ a)}.
D 1 illustrates a new property.

D-"copy and

Nprocess" A NDTT can first make copies of an input subtree and then process different copies independently and nondeterministically .

Structural Properties

In this section, we use tree transducers U 1 , U 2 and D 1 of the previous section in order to point out differences between top-down and bottom-up tree transducers. Theorem 6.4.3 (Comparison Theorem).

1. There is no top-down tree transducer equivalent to U 1 or to U 2 .

2. There is no bottom-up tree transducer equivalent to D 1 .

Any linear top-down tree transducer is equivalent to a linear bottom-up tree

transducer. In the linear complete case, classes of bottom-up and top-down tree transducers are equal.

It is not hard to verify that neither NUTT nor NDTT are closed under composition. Therefore, comparison of D-property "copy and Nprocess" and U -property "Nprocess and copy" suggests an important question:

does alternation of copying and non-determinism induces an infinite hierarchy of transformations?

The answer is affirmative [START_REF] Engelfriet | A hierarchy of tree transducers[END_REF][START_REF] Engelfriet | Three hierarchies of transducers[END_REF], but it was a relatively long-standing open problem. The fact that top-down transducers copy before non-deterministic processes, and bottom-up transducers copy after non-deterministic processes (see Exercise 6.11) suggests too that we get by composition two intricate infinite hierarchies of transformation. The following theorem summarizes results. Theorem 6.4.4 (Hierarchy theorem). By composition of NUTT, we get an infinite hierarchy of transformations. Any composition of n NUTT can be processed by composition of n+1 NDTT, and conversely (i.e. any composition of n NDTT can be processed by composition of n + 1 NUTT).

Transducer A ′ of Section 6.3 shows that it can be useful to consider ε-rules, but usual definitions of tree transducers in literature exclude this case of non determinism. This does not matter, because it is easy to check that all important results of closure or non-closure hold simultaneously for general classes and εfree classes. Deleting is also a minor phenomenon. Indeed, it gives rise to the "check and delete" property, which is specific to bottom-up transducers, but it does not matter for hierarchy theorem, which remains true if we consider complete transducers. Section 6.3 suggests that for practical use, non-determinism and non-linearity are rare. Therefore, it is important to note that if we assume linearity or determinism, hierarchy of Theorem 6.4.5 collapses. Following results supply algorithms to compose or simplify transducers. Theorem 6.4.5 (Composition Theorem).

The class of linear bottom-up transductions is closed under composition.

2. The class of deterministic bottom-up transductions is closed under composition.

Any composition of deterministic top-down transductions is equivalent to a deterministic complete top-down transduction composed with a linear homomorphism.

The reader should note that bottom-up determinism and top-down determinism are incomparable (see Exercise 6.8).

Recognizable tree languages play a crucial role because derivation tree languages for context-free word grammars are recognizable. Fortunately, we get: Theorem 6.4.6 (Recognizability Theorem). The domain of a tree transducer is a recognizable tree language. The image of a recognizable tree language by a linear tree transducer is recognizable.

Complexity Properties

We present now some decidability and complexity results. As for structural properties, the situation is more complicated than in the word case, especially for top-down tree transducers. Most of problems are untractable in the worst case, but empirically "not so much complex" in real cases, though there is a lack of "algorithmic engineering" to get efficient algorithms. As in the word case, emptiness is decidable, and equivalence is undecidable in the general case but is decidable in the k-valued case (a transducer is k-valued if there is no tree which is transduced in more than k different terms; so a deterministic transducer is a particular case of 1-valued transducer). Theorem 6.4.7 (Decidability and complexity). Emptiness of tree transductions is decidable. Equivalence of k-valued tree transducers is decidable.

Emptiness for bottom-up transducers is essentially the same as emptiness for tree automata and therefore PTIME complete. Emptiness for top-down automata, however, is essentially the same as emptiness for alternating top-down tree automata, giving DEXPTIME completeness for emptiness. The complexity PTIME for testing single-valuedness in the bottom-up case is contained in Seidl [START_REF] Seidl | Single-valuedness of tree transducers is decidable in polynomial time[END_REF]. Ramsey theory gives combinatorial properties onto which equivalence tests for k-valued tree transducers [START_REF] Seidl | Equivalence of finite-valued tree transducers is decidable[END_REF]. Theorem 6.4.8 (Equivalence Theorem). Equivalence of deterministic tree transducers is decidable.

Homomorphisms and Tree Transducers

Exercise 6.10 illustrates how decomposition of transducers using homomorphisms can help to get composition results, but we are far from the nice bimorphism theorem of the word case, and in the tree case, there is no illuminating theorem, but many complicated partial statements. Seminal paper of Engelfriet [START_REF] Engelfriet | Bottom-up and top-down tree transformations. a comparision[END_REF] contains a lot of decomposition and composition theorems. Here, we only present the most significant results.

A delabeling is a linear, complete, and symbol-to-symbol tree homomorphism (see Section 1.4). This very special kind of homomorphism changes only the label of the input letter and possibly order of subtrees. Definition of tree bimorphisms is not necessary, it is the same as in the word case. We get the following characterization theorem. We say that a bimorphism is linear, (respectively complete, etc) if the two morphisms are linear, (respectively complete, etc). Theorem 6.5.1. The class of bottom-up tree transductions is equivalent to the class of bimorphisms (Φ, L, Ψ) where Φ is a delabeling.

Relation defined by (Φ, L, Ψ) is computed by a transduction which is linear (respectively complete, ε-free) if Ψ is linear (respectively complete, ε-free).

Remark that Nivat Theorem illuminates the symmetry of word transductions: the inverse relation of a rational transduction is a rational transduction. In the tree case, non-linearity obviously breaks this symmetry, because a tree transducer can copy an input tree and process several copies, but it can never check equality of subtrees of an input tree. If we want to consider symmetric relations, we have two main situations. In the non-linear case, it is easy to prove that composition of two bimorphisms simulates a Turing machine. In the linear and the linear complete cases, we get the following results. Theorem 6.5.2 (Tree Bimorphisms). . 1. The class LCFB of linear complete ε-free tree bimorphisms satisfies LCFB ⊂ LCFB 2 = LCFB 3 .

The class LB of linear tree bimorphisms satisfies

LB ⊂ LB 2 ⊂ LB 3 ⊂ LB 4 = LB 5 .
Proof of LCFB 2 = LCFB 3 requires many refinements and we omit it.

To prove LCFB ⊂ LCFB 2 we use twice the same homomorphism Φ

(a) = a, Φ(f (x)) = f (x), Φ(g(x, y)) = g(x, y), Φ(h(x, y, z)) = g(x, g(y, z)).
For any subterms (t 1 , . . . , t 2p+2 ) , let We get t ′ ∈ (Φ • Φ -1 )(t). Assume that Φ • Φ -1 can be processed by some Ψ -1 • Ψ ′ . Consider for simplicity subterms t i of kind f ni (a). Roughly, if lengths of t i are different enough, Ψ and Ψ ′ must be supposed linear complete. Suppose that for some u we have Ψ(u) = t and Ψ ′ (u) = t ′ , then for any context u ′ of u, Ψ(u ′ ) is a context of t with an odd number of variables, and Ψ ′ (u ′ ) is a context of t ′ with an even number of variables. That is impossible because homomorphisms are linear complete. Point 2 is a refinement of point 1 (see Exercise 6.15). This example shows a stronger fact: the relation cannot be processed by any bimorphism, even non-linear, nor by any bottom-up transducer A direct characterization of these transformations is given in [START_REF] Arnold | Morphismes et bimorphismes d'arbres[END_REF] by a special class of top-down tree transducers, which are not linear but are "globally" linear, and which are used to prove LCFB 2 = LCFB 3 .

t = h(

Exercises

Exercises 6.1 to 6.7 are devoted to the word case, which is out of scope of this book. For this reason, we give precise hints for them.

Exercise 6.1. The class of rational transductions is closed under rational operations. Hint: for closure under union, connect a new initial state to initial state with (ε, ε)rules (parallel composition). For concatenation, connect by the same way final states of the first transducer to initial states of the second (serial composition). For iteration, connect final states to initial states (loop operation).

Exercise 6.2. The class of rational transductions is not closed under intersection. Hint: consider rational transductions {(a n b p , a n ) | n, p ∈ N} and {(a n b p , a p ) | n, p ∈ N}.

Exercise 6.3. Equivalence of rational transductions is undecidable. Hint: Associate the transduction

TP = {(f (u), g(u)) | u ∈ Σ + } with each instance P = (f, g) of the Post correspondance Problem such that TP defines {(Φ(m), Ψ(m)) | m ∈ Σ * }.
Consider Diff of example 6.2.2.2. Diff = Diff ∪ TP if and only if P satisfies Post property.

Exercise 6.4. Equivalence of deterministic rational transductions is decidable. Hint: design a pumping lemma to reduce the problem to a bounded one by suppression of loops (if difference of lengths between two transduced subwords is not bounded, two transducers cannot be equivalent). Exercise 6.5. Build a rational transducer equivalent to a bimorphism. Hint: let f (q) → q ′ (f ) a transition rule of L. If Φ(f ) = ε, introduce transduction rule ε(q) → q ′ (Ψ(f )). If Φ(f ) = a0 . . . an, introduce new states q1, . . . , qn and transduction rules a0(q) → q1(ε), . . . ai(qi) → qi+1(ε), . . . an(qn) → q ′ (Ψ(f )). Exercise 6.6. Build a bimorphism equivalent to a rational transducer. Hint: consider the set ∆ of transition rules as a new alphabet. We may speak of the first state q and the second state q ′ in a letter "f (q) → q ′ (m)". The control language L is the set of words over this alphabet, such that (i) the first state of the first letter is initial (ii) the second state of the last letter is final (iii) in every two consecutive letters of a word, the first state of the second equals the second state of the first. We define Φ and Ψ by Φ(f (q)-> q ′ (m)) = f and Ψ(f (q)-> q ′ (m)) = m. Exercise 6.7. Homomorphism inversion and applications. An homomorphism Φ is non-increasing if for every symbol a, Φ(a) is the empty word or a symbol. 1. For any morphism Φ, find a bimorphism (Φ ′ , L, Ψ) equivalent to Φ -1 , with Φ ′ non-increasing, and such that furthermore Φ ′ is ε-free if Φ is ε-free. Hint: Φ -1 is equivalent to a transducer R (Exercise 6.5), and the output homomorphism Φ ′ associated to R as in Exercise 6.6 is non-increasing. Furthermore, if Φ is ε-free, R and Φ ′ are ε-free.

2. Let Φ and Ψ two homomorphisms. If Φ is non-increasing, build a transducer equivalent to Ψ • Φ -1 (recall that this notation means that we apply Ψ before Φ -1 ). Hint and remark: as Φ is non-increasing, Φ -1 satisfies the inverse homomorphism property Φ -1 (M M ′ ) = Φ -1 (M )Φ -1 (M ′ ) (for any pair of words or languages M and M ′ ). This property can be used to do constructions "symbol by symbol". Here, it suffices that the transducer associates Φ -1 (Ψ(a)) with a, for every symbol a of the domain of Ψ.

3. Application: prove that classes of regular and context-free languages are closed under bimorphisms (we admit that intersection of a regular language with a regular or context-free language, is respectively regular or context-free).

4. Other application: prove that bimorphisms are closed under composition. Hint: remark that for any application f and set E,

{(x, f (x)) | f (x) ∈ E} = {(x, f (x)) | x ∈ f -1 (E)}. 2. H • Delabeling -1 ⊆ Delabeling -1 • H 3. H ⊆ LCFB 2
4. Conclude. Compare with Exercise 6.7

Exercise 6.17. Prove that the image of a recognizable tree language by a linear tree transducer is recognizable.

Bibliographic notes

First of all, let us precise that several surveys have been devoted (at least in part) to tree transducers for 25 years. J.W. Thatcher [START_REF] Thatcher | Tree automata: an informal survey[END_REF], one of the main pioneer, did the first one in 1973, and F. Gécseg and M. Steinby the last one in 1996 [START_REF] Gécseg | Tree languages[END_REF]. Transducers are formally studied too in the book of F. Gécseg and M. Steinby [START_REF] Gécseg | Tree Automata[END_REF] and in the survey of J.-C. Raoult [START_REF] Raoult | A survey of tree transductions[END_REF]. Survey of M. Dauchet and S. Tison [START_REF] Dauchet | Structural complexity of classes of tree languages[END_REF] develops links with homomorphisms. In section 6.2, some examples are inspired by the old survey of Thatcher, because seminal motivation remain, namely modelization of compilers or, more generally, of syntax directed transformations as interfacing softwares, which are always up to date. Among main precursors, we can distinguish Thatcher [START_REF] Thatcher | Tree automata: an informal survey[END_REF], W.S. Brainerd [START_REF] Brainerd | Tree generating regular systems[END_REF], A. Aho, J.D. Ullman [AU71], M. A. Arbib, E. G. Manes [START_REF] Arbib | Tree transformations and semantics of loop-free programs[END_REF]. First approaches where very linked to practice of compilation, and in some way, present tree transducers are evolutions of generalized syntax directed translations (B.S. Backer [START_REF] Baker | Generalized syntax directed translation, tree transducers, and linear space[END_REF] for example), which translate trees into strings. But crucial role of tree structure have increased later.

Many generalizations have been introduced, for example generalized finite state transformations which generalize both the top-down and the bottom-up tree transducers (J. Engelfriet [START_REF] Engelfriet | Top-down tree transducers with regular look-ahead[END_REF]); modular tree transducers (H. Vogler [START_REF] Engelfriet | Modular tree transducers[END_REF]); synchronized tree automata (K. Salomaa [START_REF] Salomaa | Synchronized tree automata[END_REF]); alternating tree automata (G.Slutzki [START_REF] Slutzki | Alternating tree automata[END_REF]); deterministic top-down tree transducers with iterated look-ahead (G. Slutzki, S. Vàgvölgyi [START_REF] Slutzki | Deterministic top-down tree transducers with iterated look-ahead[END_REF]). Ground tree transducers GTT are studied in Chapter 3 of this book. The first and the most natural generalization was introduction of top-down tree transducers with look-ahead. We have seen that "check and delete" property is specific to bottom-up tree transducers, and that missing of this property in the non-complete top-down case induces non closure under composition, even in the linear case (see Composition Theorem). Top-down transducers with regular look-ahead are able to recognize before the application of a rule at a node of an input tree whether the subtree at a son of this node belongs to a given recognizable tree language. This definition remains simple and gives to top-down transducers a property equivalent to "check and delete".

Contribution of Engelfriet to the theory of tree transducers is important, especially for composition, decomposition and hierarchy main results ([Eng75, Eng78, Eng82]).

We did not many discuss complexity and decidability in this chapter, because the situation is classical. Since many problems are undecidable in the word case, they are obviously undecidable in the tree case. Equivalence decidability holds as in the word case for deterministic or finite-valued tree transducers (Z. Zachar [START_REF] Zachar | The solvability of the equivalence problem for deterministic frontier-to-root tree transducers[END_REF], Z. Esik [START_REF] Esik | Decidability results concerning tree transducers[END_REF], H. Seidl [START_REF] Seidl | Single-valuedness of tree transducers is decidable in polynomial time[END_REF][START_REF] Seidl | Equivalence of finite-valued tree transducers is decidable[END_REF]).

Chapter 7

Alternating Tree Automata

Introduction

Complementation of non-deterministic tree (or word) automata requires a determinization step. This is due to an asymmetry in the definition. Two transition rules with the same left hand side can be seen as a single rule with a disjunctive right side. A run of the automaton on a given tree has to choose some member of the disjunction. Basically, determinization gathers the disjuncts in a single state.

Alternating automata restore some symmetry, allowing both disjunctions and conjunctions in the right hand sides. Then complementation is much easier: it is sufficient to exchange the conjunctions and the disjunction signs, as well as final and non-final states. In particular, nothing similar to determinization is needed.

This nice formalism is more concise. The counterpart is that decision problems are more complex, as we will see in Section 7.5.

There are other nice features: for instance, if we see a tree automaton as a finite set of monadic Horn clauses, then moving from non-deterministic to alternating tree automata consists in removing a very simple assumption on the clauses. This is explained in Section 7.6. In the same vein, removing another simple assumption yields two-way alternating tree automata, a more powerful device (yet not more expressive), as described in Section 7.6.3.

Finally, we also show in Section 7.2.3 that, as far as emptiness is concerned, tree automata correspond to alternating word automata on a single-letter alphabet, which shows the relationship between computations (runs) of a word alternating automaton and computations of a tree automaton.

Definitions and Examples

Alternating Word Automata

Let us start first with alternating word automata.

If Q is a finite set of states, B + (Q) is the set of positive propositional formulas over the set of propositional variables Q. For instance, q 1 ∧ (q 2 ∨ q 3 ) ∧ (q 2 ∨ q 4 ) ∈ B + ({q 1 , q 2 , q 3 , q 4 }).

Alternating word automata are defined as deterministic word automata, except that the transition function is a mapping from Q × A to B + (Q) instead of being a mapping from Q × A to Q. We assume a subset Q 0 of Q of initial states and a subset Q f of Q of final states.

Example 7.2.1. Assume that the alphabet is {0, 1} and the set of states is {q 0 , q 1 , q 2 , q 3 , q 4 , q ′ 1 , q ′ 2 }, Q 0 = {q 0 }, Q f = {q 0 , q 1 , q 2 , q 3 , q 4 } and the transitions are: q 0 0 → (q 0 ∧ q 1 ) ∨ q ′ 1 q 0 1 → q 0 q 1 0 → q 2 q 1 1 → true q 2 0 → q 3 q 2 1 → q 3 q 3 0 → q 4 q 3 1 → q 4 q 4 0 → true

q 4 1 → true q ′ 1 0 → q ′ 1 q ′ 1 1 → q ′ 2 q ′ 2 0 → q ′ 2 q ′ 2 1 → q ′ 1
A run of an alternating word automaton A on a word w is a finite tree ρ labeled with Q × N such that:

• The root of ρ is labeled by some pair (q, 0).

• If ρ(p) = (q, i) and i is strictly smaller than the length of w, w(i + 1) = a, δ(q, a) = φ, then there is a set S = {q 1 , . . . , q n } of states such that S |= φ, positions p1, . . . , pn are the successor positions of p in ρ and ρ(pj) = (q j , i + 1) for every j = 1, ...n.

The notion of satisfaction used here is the usual one in propositional calculus: the set S is the set of propositions assigned to true, while the propositions not belonging to S are assumed to be assigned to false. Therefore, we have the following:

• there is no run on w such that w(i + 1) = a for some i, ρ(p) = (q, i) and δ(q, i) = false

• if δ(q, w(i + 1)) = true and ρ(p) = (q, i), then p can be a leaf node, in which case it is called a success node.

• All leaf nodes are either success nodes as above or labeled with some (q, n) such that n is the length of w.

A run of an alternating automaton is successful on w if and only if

• all leaf nodes are either success nodes or labeled with some (q, n), where n is the length of w, such that q ∈ Q f .

• the root node ρ(ǫ) = (q 0 , 0) with q 0 ∈ Q 0 .

Example 7.2.2. Let us come back to Example 7.2.1. We show on Figure 7.1 two runs on the word 00101, one of which is successful. Note that non-deterministic automata are the particular case of alternating automata in which only disjunctions (no conjunctions) occur in the transition relation. In such a case, if there is a succesful run on w, then there is also a successful run, which is a string.

0 0 1 1 0 q0, 2 q1, 2 q'2 q ′ 2 , 5 q0, 3 q0, 5 q0, 1 q2, 2 q3, 3 q4, 4 q1, 1 q0, 1 q0, 2 q1, 2 q2, 2 q3, 3 q4, 4 q0, 4 q1, 4 q1, 1 q0, 3 q ′ 1 , 4 q0
Note also that, in the definition of a run, we can always choose the set S to be a minimal satisfaction set: if there is a successful run of the automaton, then there is a successful one in which we always choose a minimal set S of states.

Alternating Tree Automata

Now, let us switch to alternating tree automata: the definitions are simple adaptations of the previous ones. Definition 7.2.3. An alternating tree automaton over F is a tuple A = (Q, F, I, ∆) where Q is a set of states, I ⊆ Q is a set of initial states and ∆ is a mapping from Q×F to B + (Q×N) such that ∆(q, f ) ∈ B + (Q×{1, . . . , Arity(f )}) where Arity(f ) is the arity of f . Note that this definition corresponds to a top-down automaton, which is more convenient in the alternating case. Definition 7.2.4. Given a term t ∈ T (F) and an alternating tree automaton A on F, a run of A on t is a tree ρ on Q × N * such that ρ(ε) = (q, ε) for some state q and if ρ(π) = (q, p), t(p) = f and δ(q, f ) = φ, then there is a subset S = {(q 1 , i 1 ), . . . , (q n , i n )} of Q × {1, . . . , Arity(f )} such that S |= φ, the successor positions of π in ρ are {π1, . . . , πn} and ρ(π •j) = (q j , p•i j ) for every j = 1..n.

A run ρ is successful if ρ(ε) = (q, ε) for some initial state q ∈ I. q 2 ,ε q 2 ,1 q 4 ,1 q 1 ,2 q 1 ,11 q 2 ,12 q 4 ,11 q 3 ,11 q 3 ,12 q 4 ,121 q 2 ,121 q 1 ,122 q 5 ,121 q 4 ,121 q 1 ,122

Figure 7.2: A run of an alternating tree automaton Note that (completely specified) non-deterministic top-down tree automata are the particular case of alternating tree automata. For a set of non-deterministic rules q(f (x 1 , . . . , x n )) → f (q 1 (x 1 ), . . . , q n (x n )), Delta(q, f ) is defined by: ∆(q, f ) = (q1,...,qn)∈S

Arity(f ) i=1 (q i , i)
Example 7.2.5. Consider the automaton on the alphabet {f (, ), a, b} whose transition relation is defined by: ∆ f a b q 2 [((q 1 , 1) ∧ (q 2 , 2)) ∨ ((q 1 , 2) ∧ (q 2 , 1))] ∧ (q 4 , 1) true false q 1 ((q 2 , 1) ∧ (q 2 , 2)) ∨ ((q 1 , 2) ∧ (q 1 , 1)) false true q 4 ((q 3 , 1) ∧ (q 3 , 2)) ∨ ((q 4 , 1) ∧ (q 4 , 2)) true true q 3 ((q 3 , 1) ∧ (q 2 , 2)) ∨ ((q 4 , 1) ∧ (q 1 , 2)) ∧ (q 5 , 1)) false true q 5 false true false Assume I = {q 2 }. A run of the automaton on the term t = f (f (b, f (a, b)), b). is depicted on Figure 7.2.

In the case of a non-deterministic top-down tree automaton, the different notions of a run coincide as, in such a case, the run obtained from Definition 7.2.4 on a tree t is a tree whose set of positions is the set of positions of t, possibly changing the ordering of sons.

Words over an alphabet A can be seen as trees over the set of unary function symbols A and an additional constant #. For convenience, we read the words from right to left. For instance, aaba is translate into the tree a(b(a(a(#)))). Then an alternating word automaton A can be seen as an alternating tree automaton whose initial states are the final states of A, the transitions are the same and there is additional rules δ(q 0 , #) = true for the initial state q 0 of A and δ(q, #) = false for other states.

Tree Automata versus Alternating Word Automata

It is interesting to remark that, guessing the input tree, it is possible to reduce the emptiness problem for (non-deterministic, bottom-up) tree automata to the emptiness problem for an alternating word automaton on a single letter alphabet: assume that A = (Q, F, Q f , ∆) is a non-deterministic tree automaton, then construct the alternating word automaton on a one letter alphabet {a} as follows: the states are Q × F, the initial states are Q f × F and the transition rules:

δ((q, f ), a) = f (q1,...,qn)→q∈∆ n i=1 fj ∈F ((q i , f j ), i)
Conversely, it is also possible to reduce the emptiness problem for an alternating word automaton over a one letter alphabet {a} to the emptiness problem of non-deterministic tree automata, introducing a new function symbol for each conjunction; assume the formulas in disjunctive normal form (this can be assumed w.l.o.g, see Exercise 7.1), then replace each transition δ(q, a) = n i=1 ki j=1 (q i,j , i) with f i (q i,1 , . . . , q i,ki ) → q.

Closure Properties

One nice feature of alternating automata is that it is very easy to perform the Boolean operations (for short, we confuse here the automaton and the language recognized by the automaton). First, we show that we can consider automata with only one initial state, without loss of generality.

Lemma 7.3.1. Given an alternating tree automaton A, we can compute in linear time an automaton A ′ with only one initial state and which accepts the same language as A.

Proof. Add one state q 0 to A, which will become the only initial state, and the transitions:

δ(q 0 , f ) = q∈I δ(q, f ) Proposition 7.3.2. Union, intersection and complement of alternating tree automata can be performed in linear time.

A term t is accepted by A ′ in state S iff t is accepted by A in all states q ∈ S. This is proved by induction on the size of t: if t is a constant, then t is accepted in all states q such that ∆(q, t) = true. Now, if t = f (t 1 , . . . , t n ) we let S 1 , . . . , S n are the set of states in which t 1 , . . . , t n are respectively accepted by A. t is accepted by A in a state q iff there is S 0 ⊆ Q×{1, . . . , n} such that S 0 |= ∆(q, f ) and, for every pair (q i , j) ∈ S 0 , t j is accepted in q i . In other words, t is accepted by A in state q iff there is an S 0 ⊆ S 1 ×{1}∪. . .∪S n ×{n} such that S 0 |= ∆(q, f ), which is in turn equivalent to S 1 × {1} ∪ . . . ∪ S n × {n} |= ∆(q, f ). We conclude by an application of the induction hypothesis.

Unfortunately the exponential blow-up is unavoidable, as a consequence of Proposition 7.3.2 and Theorems 1.7.7 and 1.7.4. The DEXPTIME-hardness is a consequence of Proposition 7.3.2 and Theorem 1.7.7.

Decision Problems and Complexity Issues

The membership problem (given t and A, is t accepted by A ?) can be decided in polynomial time. This is left as an exercise.

7.6 Horn Logic, Set Constraints and Alternating Automata

The Clausal Formalism

Viewing every state q as a unary predicate symbol P q , tree automata can be translated into Horn clauses in such a way that the language recognized in state q is exactly the interpretation of P q in the least Herbrand model of the set of clauses.

There are several advantages of this point of view:

• Since the logical setting is declarative, we don't have to distinguish between top-down and bottom-up automata. In particular, we have a definition of bottom-up alternating automata for free.

• Alternation can be expressed in a simple way, as well as push and pop operations, as described in the next section.

• There is no need to define a run (which would correspond to a proof in the logical setting)

• Several decision properties can be translated into decidability problems for such clauses. Typically, since all clauses belong to the monadic fragment, there are decision procedures e.g. relying on ordered resolution strategies.

There are also weaknesses: complexity issues are harder to study in this setting. Many constructive proofs, and complexity results have been obtained with tree automata techniques.

Tree automata can be translated into Horn clauses. With a tree automaton A = (Q, F, Q f , ∆) is associated the following set of Horn clauses: P q (f (x 1 , . . . , x n )) ← P q1 (x 1 ), . . . , P qn (x n ) if f (q 1 , . . . , q n ) → q ∈ ∆. The language accepted by the automaton is the union of interpretations of P q , for q ∈ Q f , in the least Herbrand model of clauses.

Also, alternating tree automata can be translated into Horn clauses. Alternation can be expressed by variable sharing in the body of the clause. Consider an alternating tree automaton (Q, F, I, ∆). Assume that the transitions are in disjunctive normal form (see Exercise 7.1). With a transition ∆(q, f ) = m i=1 ki j=1 (q j , i j ) is associated the clauses

P q (f (x 1 , . . . , x n )) ← ki j=1 P qj (x ij )
We can also add ǫ-transitions, by allowing clauses

P (x) ← Q(x)
In such a setting, automata with equality constraints between brothers, which are studied in Section 4.3, are simply an extension of the above class of Horn clauses, in which we allow repeated variables in the head of the clause.

Allowing variable repetition in an arbitrary way, we get alternating automata with contraints between brothers, a class of automata for which emptiness is decidable in deterministic exponential time. (It is expressible in Löwenheim's class with equality, also called sometimes the monadic class).

Still, for tight complexity bounds, for closure properties (typically by complementation) of automata with equality tests between brothers, we refer to Section 4.3. Note that it is not easy to derive the complexity results obtained with tree automata techniques in a logical framework.

The Set Constraints Formalism

We introduced and studied general set constraints in Chapter 5. Set constraints and, more precisely, definite set constraints provide with an alternative description of tree automata.

Definite set constraints are conjunctions of inclusions e ⊆ t where e is a set expression built using function application, intersection and variables and t is a term set expression, constructed using function application and variables only.

Given an assignment σ of variables to subsets of T (F), we can interpret the set expressions as follows:

[[f (e 1 , . . . , e n )]] σ def = {f (t 1 , . . . , t n ) | t i ∈ [[e i ]] σ } [[e 1 ∩ e 2 ]] σ def = [[e 1 ]] σ ∩ [[e 2 ]] σ [[X]] σ def = Xσ
Then σ is a solution of a set constraint if inclusions hold for the corresponding interpretation of expressions.

When we restrict the left members of inclusions to variables, we get another formalism for alternating tree automata: such set constraints have always a least solution, which is accepted by an alternating tree automaton. More precisely, we can use the following translation from the alternating automaton A = (Q, F, I, ∆): assume again that the transitions are in disjunctive normal form (see Exercise 7.1) and construct, the inclusion constraints f (X 1,f,q,d , . . . , X n,f,q,d ) ⊆ X q (q ′ ,j)∈d X q ′ ⊆ X j,f,q,d for every (q, f ) ∈ Q × F and d a disjunct of ∆(q, f ). (An intersection over an empty set has to be understood as the set of all trees).

Then, the language recognized by the alternating tree automaton is the union, for q ∈ I, of X q σ where σ is the least solution of the constraint.

Actually, we are constructing the constraint in exactly the same way as we constructed the clauses in the previous section. When there is no alternation, we get an alternative definition of non-deterministic automata, which corresponds to the algebraic characterization of Chapter 2.

Conversely, if all right members of the definite set constraint are variables, it is not difficult to construct an alternating tree automaton which accepts the least solution of the constraint (see Exercise 7.4).

Two Way Alternating Tree Automata

Definite set constraints look more expressive than alternating tree automata, because inclusions X ⊆ f (Y, Z) cannot be directly translated into automata rules.

We define here two-way tree automata which will easily correspond to definite set constraints on one hand and allow to simulate, e.g., the behavior of standard pushdown word automata.

It is convenient here to use the clausal formalism in order to define such automata. A clause P (u) ← P 1 (x 1 ), . . . , P n (x n )

where u is a linear, non-variable term and x 1 , . . . , x n are (not necessarily distinct) variables occurring in u, is called a push clause. A clause

P (x) ← Q(t)
where x is a variable and t is a linear term, is called a pop clause. A clause

P (x) ← P 1 (x), . . . , P n (x)
is called an alternating clause (or an intersection clause).

Definition 7.6.1. An alternating two-way tree automaton is a tuple

(Q, Q f , F, C)
where Q is a finite set of unary function symbols, Q f is a subset of Q and C is a finite set of clauses each of which is a push clause, a pop clause or an alternating clause.

Such an automaton accepts a tree t if t belongs to the interpretation of some P ∈ Q f in the least Herbrand model of the clauses.

Example 7.6.2. Consider the following alternating two-way automaton on the alphabet F = {a, f (, )}:

1. P 1 (f (f (x 1 , x 2 ), x 3 )) ← P 2 (x 1 ), P 2 (x 2 ), P 2 (x 3 ) 2.

P 2 (a) 3.

P 1 (f (a, x)) ← P 2 (x) 4.

P 3 (f (x, y)) ← P 1 (x), P 2 (y) 5.

P 4 (x) ← P 3 (x), P 1 (x) 6.

P 2 (x) ← P 4 (f (x, y)) 7.

P 1 (y) ← P 4 (f (x, y))

The clauses 1,2,3,4 are push clauses. Clause 5 is an alternating clause and clauses 6,7 are pop clauses.

If we compute the least Herbrand model, we successively get for the five first steps:

step 1 2 3 4 5 P1 f (a, a), f (f (a, a), a) a P2 a f (a, a) P3 f (f (a, a), a), f (f (f (a, a), a), a) P4 f (f (a, a), a)
These automata are often convenient in expressing some problems (see the exercises and bibliographic notes). However they do not increase the expressive power of (alternating) tree automata: Theorem 7.6.3. For every alternating two-way tree automaton, it is possible to compute in deterministic exponential time a tree automaton which accepts the same language.

We do not prove the result here (see the bibliographic notes instead). A simple way to compute the equivalent tree automaton is as follows: first flatten the clauses, introducing new predicate symbols. Then saturate the set of clauses, using ordered resolution (w.r.t. subterm ordering) and keeping only non-subsumed clauses. The saturation process terminates in exponential time. The desired automaton is obtained by simply keeping only the push clauses of this resulting set of clauses.

Example 7.6.4. Let us come back to Example 7.6.2 and show how we get an equivalent finite tree automaton.

First flatten the clauses: Clause 1 becomes 1. P 1 (f (x, y)) ← P 5 (x), P 2 (y) 8. P 5 (f (x, y)) ← P 2 (x), P 2 (y)

Now we start applying resolution;

From 4 + 5: 9. P 4 (f (x, y)) ← P 1 (x), P 2 (y), P 1 (f (x, y)) Form 9 + 6: 10. P 2 (x) ← P 1 (x), P 2 (y) From 10 + 2: 11.

P 2 (x) ← P 1 (x)

1. P 1 (f (x, y)) ← P 5 (x), P 2 (y) 2.

P 1 (a) 3.

P 1 (f (a, x)) ← P 1 (x) 4.

P 3 (f (x, y)) ← P 1 (x), P 1 (y) 8.

P 5 (f (x, y)) ← P 1 (x), P 1 (y) 11.

P 1 (x) ← P 1 (y) 15.

P 2 (x) ← P 1 (x) 21. P 4 (f (a, x)) ← P 1 (x) Of course, this automaton can be simplified: P 1 and P 2 accept all terms in T (F).

It follows from Theorems 7.6.3, 7.5.1 and 1.7.4 that the emptiness problem (resp. universality problems) are DEXPTIME-complete for two-way alternating automata.

Two Way Automata and Definite Set Constraints

There is a simple reduction of two-way automata to definite set constraints:

A push clause P (f (x 1 , . . . , x n )) ← P 1 (x i1 ), . . . , P n (x in ) corresponds to an inclusion constraint f (e 1 , . . . , e n ) ⊆ X P

where each e j is the intersection, for i k = j of the variables X P k . A (conditional) pop clause P (x i ) ← Q(f (x 1 , . . . , x n )), P 1 (x 1 ), . . . P k (x k ) corresponds to f (e 1 , . . . , e n ) ∩ X Q ⊆ f (⊤, . . . , X P , ⊤, . . .)

where, again, each e j is the intersection, for i k = j of the variables X P k and ⊤ is a variable containing all term expressions. Intersection clauses

P (x) ← Q(x), R(x) correspond to constraints X Q ∩ X R ⊆ X P
Conversely, we can translate the definite set constraints into two-way automata, with additional restrictions on some states. We cannot do better since a definite set constraint could be unsatisfiable.

Introducing auxiliary variables, we only have to consider constraints:

1. f (X 1 , . . . , X n ) ⊆ X, 2. X 1 ∩ . . . ∩ X n ⊆ X, 3. X ⊆ f (X 1 , . . . , X n ).
The first constraints are translated to push clauses, the second kind of constraints is translated to intersection clauses. Consider the last constraints. It can be translated into the pop clauses:

P Xi (x i ) ← P X (f (x 1 , . . . , x n ))
with the provision that all terms in P X are headed with f . Then the procedure which solves definite set constraints is essentially the same as the one we sketched for the proof of Theorem 7.6.3, except that we have to add unit negative clauses which may yield failure rules Example 7.6.5. Consider the definite set constraint

f (X, Y ) ∩ X ⊆ f (Y, X), f (a, Y ) ⊆ X, a ⊆ Y, f (f (Y, Y ), Y ) ⊆ X
Starting from this constraint, we get the clauses of Example 7.6.2, with the additional restriction 26. ¬P 4 (a)

since every term accepted in P 4 has to be headed with f . If we saturate this constraint as in Example 7.6.4, we get the same clauses, of course, but also negative clauses resulting from the new negative clause:

From 26 + 18 27. ¬P 3 (a)

And that is all: the constraint is satisfiable, with a minimal solution described by the automaton resulting from the computation of Example 7.6.4.

the form δ(q, f ) = m _ i=1 k i ĵ=1
(qj, lj)

Exercise 7.2. Show that the membership problem for alternating tree automata can be decided in polynomial time.

Exercise 7.3. An alternating automaton is weak if there is an ordering on the set of states such that, for every state q and every function symbol f , every state q ′ occurring in δ(q, f ) satisfies q ′ ≤ q.

Prove that the emptiness of weak alternating tree automata is in PTIME.

Exercise 7.4. Given a definite set constraint whose all right hand sides are variables, show how to construct (in polynomial time) k alternating tree automata which accept respectively X1σ, . . . , X k σ where σ is the least solution of the constraint.

Exercise 7.5. A pushdown automaton on words is a tuple (Q, Q f , A, Γ, δ) where Q is a finite set of states, Q f ⊆ Q, A is a finite alphabet of input symbols, Γ is a finite alphabet of stack symbols and δ is a transition relation defined by rules: qa w -→ q ′ and qa

w -1 ---→ q ′ where q, q ′ ∈ Q, a ∈ A and w, w ′ ∈ Γ * .

A configuration is a pair of a state and a word γ ∈ Γ * . The automaton may move when reading a, from (q, γ) to (q ′ , γ ′ ) if either there is a transition qa w -→ q ′ and γ ′ = w • γ or there is a transition qa

w -1 ---→ q ′ and γ = w • γ ′ .
1. Show how to compute (in polynomial time) a two-way automaton which accepts w in state q iff the configuration (q, w) is reachable.

2. This can be slightly generalized considering alternating pushdown automata: now assume that the transitions are of the form: qa w -→ φ and qa

w -1 ---→ φ
where φ ∈ B + (Q). Give a definition of a run and of an accepted word, which is consistent with both the definition of a pushdown automaton and the definition of an alternating automaton.

3. Generalize the result of the first question to alternating pushdown automata.

4. Generalize previous questions to tree automata.

Exercise 7.6. Given a finite tree automaton A over the alphabet {a, { } , < , >}, construct a two-way tree automaton which accepts the set of terms t which can be deduced by the rule of Figure 7.3 and the rule t If t is accepted by A

Bibliographic Notes

Alternation has been considered for a long time as a computation model, e.g. for Turing machines. The seminal work in this area is [CKS81], in which the relationship between complexity classes defined using (non)-deterministic machines and alternating machines is studied. Concerning tree automata, alternation has been mainly considered in the case of infinite trees. This is especially useful to keep small representations of automata associated with temporal logic formulas, yielding optimal modelchecking algorithms [START_REF] Kupferman | An automata-theoretic approach to branching time model-checking[END_REF]. Two-way automata and their relationship with clauses have been first considered in [START_REF] Frühwirth | Logic programs as types for logic programs[END_REF] for the analysis of logic programs. They also occur naturally in the context of definite set constraints, as we have seen (the completion mechanisms are presented in, e.g., [START_REF] Heintze | A Decision Procedure for a Class of Set Constraints[END_REF][START_REF] Charatonik | Set Constraints with Intersection[END_REF]), and in the analysis of cryptographic protocols [START_REF] Goubault-Larrecq | A method for automatic cryptographic protocol verification[END_REF].

There several other definitions of two-way tree automata. We can distinguish between two-way automata which have the same expressive power as regular languages and what we refer here to pushdown automata, whose expressive power is beyond regularity.

Decision procedures based on ordered resolution strategies could be found in [Jr.76].

Alternating automata with contraints between brothers define a class of languages expressible in Löwenheim's class with equality, also called sometimes the monadic class. See for instance [START_REF] Börger | The Classical Decision Problem[END_REF].

Chapter 8

Automata for Unranked Trees 8.1 Introduction

Finite ordered unranked trees have attracted attention as a formal model for semi-structured data represented by XML documents. Consider for example the (incomplete) HTML document on the left-hand side of Figure 8.1. The use of opening and closing tags surrounding things like the whole document, the head and body of the document, headings, tables, etc. gives a natural tree structure to the document that is shown on the right-hand side of Figure 8.1.

This structure is common to all XML documents and while sometimes the order of the stored data (e.g. the order of the rows in a table) might not be important, its representation as a document naturally enforces an order which has to be taken into account. So we can view unordered unranked trees as a way to model semi-structured data, whereas ordered unranked trees are used to model the documents.

Specifying a class of documents having a desired structure, e.g. the the class of valid HTML documents, corresponds to identifying a set of trees. For example, expressing that a table consists of rows which themselves contain cells, means that we require for the trees that a node labeled table has a sequence of successors labeled tr and nodes labeled tr have a sequence of successors labeled td.

There are several formalisms allowing to specify such requirements, e.g. Document Type Definitions (DTDs) and XML schema. To provide a formal background a theory of finite automata on ordered unranked trees has been developed. Actually, such automata models have already appeared in early works on tree automata, e.g. by Thatcher in the late 1960s, but later the focus has been on automata for ranked trees.

The research was reanimated in the 1990s and since then there has been a lot of work in this area. In this chapter we present the basic theory that has been developed for automata on ordered and unranked trees. In the following we simply speak of unranked trees.

We center our presentation around the model of hedge automaton, which is accepted as a natural and fundamental model for automata on unranked

• • • • • • • • • Figure 8
.1: An HTML document and its representation as a tree trees. As we will see, many results can be obtained by encoding unranked trees into ranked ones and then applying the theory of ranked tree automata. Nevertheless, the use of hedge automata as an automaton model directly working on unranked trees is justified because, first of all, the choice of the particular encoding using ranked trees depends on the application, and second, the use of encodings blurs the separation between the two unboundedness aspects (the height of trees is unbounded but also the length of the successor sequences for each node). For example, in the formalism of DTDs there is only a restricted way to specify allowed successor sequences of nodes with a certain label. To reflect such restrictions in an automaton model working on encodings by ranked trees requires a careful choice of the encoding, whereas it directly transfers to hedge automata.

The chapter is structured as follows. In Section 8.2 we give basic definitions and introduce the model of hedge automaton. How to encode unranked trees by ranked ones is discussed in Section 8.3. Section 8.4 presents the equivalence between weak monadic second-order logic and hedge automata, similar to the results in Section 3.3. In Section 8.5 we consider decision problems for hedge automata and Section 8.6 deals with the minimization problem. Finally, we present several formalisms for specifying classes of XML documents, compare their expressive power, and relate them to the model of hedge automata in Section 8.7.

Definitions and Examples

Unranked Trees and Hedges

In the Preliminaries, finite ordered trees t over some set of labels have been defined as mappings from a finite prefix-closed set Pos(t) ⊆ N * to the set of labels. Ranked trees are trees where the set of labels is a ranked alphabet and the mapping obeys the restrictions imposed by the ranks of the symbols.

In this chapter we drop this restriction, i.e. we consider a set U of unranked labels and allow each position in the domain of the tree to have an arbitrary (but finite) number of successors.

A more general definition allows to combine ranked and unranked symbols. For this purpose we consider an alphabet Σ = U ∪ n i=0 F i , where F is a ranked alphabet as usual.

A finite (ordered) tree t over Σ is defined as a partial function t : N * → Σ with domain written Pos(t) satisfying the following properties:

1. Pos(t) is finite, nonempty, and prefix-closed.

∀p ∈ Pos(t),

• if t(p) ∈ F n , then {j | pj ∈ Pos(t)} = {1, . . . , n},

• if t(p) ∈ U, then {j | pj ∈ Pos(t)} = {1, . . . , k} for some k ≥ 0.
This means that the number of children of a node labeled with a symbol from U is not determined by this symbol.

For simplicity, we only consider the case that F is empty, i.e. that Σ only contains unranked symbols. In this case, we call a tree t over Σ an unranked tree. The set of all unranked trees over Σ is denoted by T (Σ).

Many definitions that have been given for ranked trees and that do not make use of the ranked nature of the tree, such as height or subtree, directly carry over to unranked trees.

A tree with root symbol a and subtrees t 1 , . . . , t n directly below the root is written as a(t 1 • • • t n ). The sequence t 1 • • • t n of unranked trees is also called a hedge. The notion of hedge can be used to give an inductive definition of unranked trees:

• A sequence of unranked trees is a hedge (including the empty sequence ε).

• If h is a hedge and a ∈ Σ is a label, then a(h) is an unranked tree.

If h is the empty hedge (i.e. the empty sequence), then we write a instead of a(). The set of all hedges over Σ is denoted by H(Σ). The subtree at position 3 is t| 3 = d(ab).

Hedge Automata

We want to define a model of finite automaton for unranked trees that is as robust and has similar properties as the model for ranked trees. Recall that a finite tree automaton for ranked trees, as defined in Section 1.1, is specified by a set of transition rules of the form f (q 1 (x 1 ), . . . , q n (x n )) → q(f (x 1 , . . . , x n )), also written as f (q 1 , . . . , q n ) → q, where n is the arity of the symbol f . An input tree is processed in a bottom-up fashion, starting at the leaves and working toward the root using the transition rules.

In unranked trees the number of successors of a position p in a tree t is not determined by its label, and furthermore there is no upper bound on the number of successors that a position can have. Therefore automata for unranked trees cannot be defined by explicitly listing all transition rules in the same style as for ranked tree automata.

To deal with the unbounded branching of unranked trees we have to find a way to symbolically represent an infinite number of transitions.

Example 8.2.2. Assume we want to define an automaton accepting all unranked trees of height 1 over the alphabet Σ = {a, b} that have an even number of leaves, all leaves are labeled by b, and the root is labeled by a, i.e. the trees a, a(bb), a(bbbb), • • • .

For this purpose, we could use the two states q b and q. The first transition rule b → q b ensures that the leaves can be labeled by q b . To capture all the trees listed above we need the infinite set of rules a → q, a(q b q b ) → q, a(q b q b q b q b ) → q, • • • This set can be represented by a single rule a((q b q b ) * ) → q using a regular expression for describing the sequences of states below the position with label a that enable the automaton to proceed to state q.

In the previous example we have used a regular expression to represent an infinite number of transition rules. In general, this leads to transition rules of the form a(R) → q, where R ⊆ Q * is a regular language over the states of the unranked tree automaton.

Of course it would be possible to allow R to be from a bigger class of languages, e.g. the context-free languages. But as we are interested in defining finite automata for unranked trees, i.e. automata using memory of bounded size, we should choose R such that it can be represented by an automaton using only bounded memory. Thus, the class of regular languages is a natural choice in this context.

A nondeterministic finite hedge automaton (NFHA) over Σ is a tuple A = (Q, Σ, Q f , ∆) where Q is a finite set of states, Q f ⊆ Q is a set of final states, and ∆ is a finite set of transition rules of the following type:

a(R) → q
where R ⊆ Q * is a regular language over Q. These languages R occurring in the transition rules are called horizontal languages.

A run of A on a tree t ∈ T (Σ) is a tree r ∈ T (Q) with the same domain as t such that for each node p ∈ Pos(r) with a = t(p) and q = r(p) there is a transition rule a(R) → q of A with r(p1) • • • r(pn) ∈ R, where n denotes the number of successors of p. In particular, to apply a rule at a leaf, the empty word ε has to be in the horizontal language of the rule.

An unranked tree t is accepted by A if there is a run r of A on t whose root is labeled by a final state, i.e. with r(ε) ∈ Q f . The language L(A) of A is the set of all unranked trees accepted by A.

These automata can be seen as working bottom-up, starting at the leaves and ending at the root. For nondeterministic automata this is just a matter of taste, except that in the top-down view one would rather call the set of final states the set of initial states and write the transitions as q(a) → R instead of a(R) → q. For deterministic automata there is a difference because one has to specify in which direction the automaton should be deterministic. In Section 8.2.3 we consider deterministic bottom-up automata.

As for ranked trees we call two NFHAs equivalent if they accept the same language, and if t is accepted by A with a run whose root is labeled q, then we also write t * -→ A q.

In the following examples we give the horizontal languages using regular expressions. For the specification of transitions we can use any formalism defining regular languages, for example nondeterministic finite automata (NFAs). But of course the choice of the formalism is important when considering algorithms for NFHAs. This issue is discussed in Section 8.5.

Example 8.2.3. Let Σ = {a, b, c} and L ⊆ T (Σ) be the language of all trees t for which there are two nodes labeled b whose greatest common ancestor is labeled c. More formally, we consider all trees for which there exist nodes p 1 , p 2 ∈ Pos(t) with t(p 1 ) = t(p 2 ) = b such that t(p) = c for the greatest common ancestor (the longest common prefix) of p 1 and p 2 .

A tree satisfying this condition is shown in Figure 8.2. The corresponding nodes are p 1 = 12, p 2 = 132, and p = 1.

To accept this language, the following NFHA labels b-nodes with q b , as long as it has not yet verified the required condition in a subtree, passes this q b upward, and checks if there is a c-node with two successors labeled q b . This node is then labeled with the final state q c that is passed up to the root.

Let A = (Q, Σ, Q f , ∆) with Q = {q, q b , q c }, Q f = {q c }, and ∆ given by the following rules:

a(Q * ) → q a(Q * q b Q * ) → q b a(Q * q c Q * ) → q c b(Q * ) → q b c(Q * q b Q * ) → q b b(Q * q c Q * ) → q c c(Q * ) → q c(Q * q b Q * q b Q * ) → q c c(Q * q c Q * ) → q c
The right-hand side of Figure 8.2 shows a run of A. Consider, for example, node 1. It is labeled c in the input tree. In the run, the sequence of its successor labels is the word qq b q b . This means that we can apply the rule c(Q * q b Q * q b Q * ) → q c and hence obtain q c at node 1 in the run. q c q b q q b q b q q q q q b Figure 8.2: A run of the NFHA from Example 8.2.3 with Q = {q 0 , q 1 }, Q f = {q 1 }, and ∆ given by the following rules:

0(ε) → q 0 or(Q * q 1 Q * ) → q 1 1(ε) → q 1
or(q 0 q * 0 ) → q 0 not(q 0 ) → q 1 and(Q * q 0 Q * ) → q 0 not(q 1 ) → q 0 and(q 1 q * 1 ) → q 1

This automaton accepts all trees that form Boolean expressions evaluating to true. The expressions have to be correct in the sense that the leaves are labeled by 0 or 1 and the nodes labeled not have exactly one successor.

We call a language L ⊆ T (Σ) of unranked trees hedge recognizable if there is an NFHA accepting this language.

We now discuss some basic properties of NFHAs similar to the ones for NFTAs in Section 1.1.

An NFHA A is complete if for each t ∈ T (Σ) there is at least one state q such that t * -→ A q. The automaton from Example 8.2.3 is complete because for each label and for each sequence of states, one of the three rules a(Q * ) → q, b(Q * ) → q b , c(Q * ) → q can be applied. The automaton from Example 8.2.4 is not complete because, for example, there is no transition rule that can be applied if the label 0 appears at an inner node of the tree.

Due to the closure properties of regular word languages, it is easy to see that each NFHA can be completed by adding a sink state.

Remark 8.2.5. For each NFHA one can compute a complete NFHA with at most one state more that accepts the same language.

Proof. Let A = (Q, Σ, Q f , ∆) be an NFHA. Let q ⊥ be a new state that is not in Q. For a ∈ Σ let a(R 1 ) → q, . . . , a(R n ) → q n be all rules for a. We complete A by adding the rule a

(R ⊥ ) → q ⊥ with R ⊥ = (Q ∪ {q ⊥ }) * \ (R 1 ∪ • • • ∪ R n ).
In Section 8.5 we discuss the complexity of deciding whether a given NFHA is complete.

We call A reduced if each state of A is reachable, i.e. for each state q there is a tree t with t * -→ A q. The algorithm for computing the set of reachable states is presented in Section 8.5 for solving the emptiness problem. From that we can conclude that for a given NFHA we can compute a reduced one accepting the same language.

Another thing that one might notice in the representation of NFHAs is that it is not necessary to have different rules a(R 1 ) → q and a(R 2 ) → q because a single rule a(R 1 ∪ R 2 ) → q allows the same transitions (and the class of regular languages is closed under union). We call an NFHA A = (Q, Σ, Q f , ∆) normalized if for each a ∈ Σ and q ∈ Q there is at most one transition rule of the form a(R) → q. The NFHA from Example 8.2.3 is not normalized because it has two transitions for c and q c , whereas the NFHA from Example 8.2.4 is normalized.

As mentioned above this property can always be obtained easily.

Remark 8.2.6. Each NFHA is equivalent to a normalized NFHA.

As for NFTAs we can allow ǫ-rules. These ǫ-rules can be removed using a construction similar to the one for NFTAs (see Exercise 8.2).

In Section 1.3 it is shown that the class of recognizable languages of ranked trees is closed under set operations like union, intersection, and complement. It is not difficult to adapt the proofs from the case of ranked trees to the unranked setting (see Exercises). But instead of redoing the constructions in the new setting we show in Section 8.3 how to encode unranked trees by ranked ones. This enables us to reuse the results from Section 1.3.

Deterministic Automata

In this section we consider deterministic bottom-up automata. In the case of ranked tree automata, deterministic (bottom-up) automata (DFTAs) are those that do not have two rules with the same left-hand side (compare Section 1.1). This immediately implies that for each ground term t there is at most one state q of the automaton such that t * -→ q.

To transfer this property to unranked trees we have to ensure that the state at a node p in the run of a deterministic automaton should be determined uniquely by the label of p and the states at the successors of p.

We obtain the following definition. A deterministic finite hedge automaton (DFHA) is a finite hedge automaton A = (Q, Σ, Q f , ∆) such that for all rules a(R 1 ) → q 1 and a(R 2 ) → q 2 either R 1 ∩ R 2 = ∅ or q 1 = q 2 . Example 8.2.7. The NFHA from Example 8.2.3 is not deterministic because it contains, e.g., the two transitions a(Q * ) → q and a(Q * q b Q * ) → q b . The NFHA from Example 8.2.4 is deterministic.

By using a standard subset construction as for ranked tree automata, it is not difficult to see that every NFHA can be transformed into a deterministic one.

Theorem 8.2.8. For every NFHA A there is a DFHA A d accepting the same language. The number of states of A d is exponential in the number of states of A.

Proof. The construction is very similar to the one for proving Theorem 1.1.9. The states of A d are sets of states of A. For the transitions we have to compute, given a letter a and a sequence s 1 • • • s n of sets of states, all possible states of A that can be reached on an a-labeled node whose successors are labeled by a state sequence composed from elements of the sets s 1 , . . . , s n .

Formally, let A = (Q, Σ, Q f , ∆) and define

A d = (Q d , Σ, Q df , ∆ d ) by Q d = 2 Q , Q df = {s ∈ Q d | s∩Q f = ∅},
and ∆ d containing all the transitions a(R) → s such that

s 1 • • • s n ∈ R iff s = {q ∈ Q | ∃q 1 ∈ s 1 , . . . , q n ∈ s n , a(R ′ ) → q ∈ ∆ with q 1 • • • q n ∈ R ′ }.
This automaton is obviously deterministic because for each a and each s there is only one transition having s as target. But we have to show that the sets R defined as above are regular. For this purpose, assume that A is normalized and let R a,q be the language with a(R a,q ) → q ∈ ∆ for all a ∈ Σ and q ∈ Q. The language

S a,q = {s 1 • • • s n ∈ Q * d | ∃q 1 ∈ s 1 , . . . , q n ∈ s n with q 1 • • • q n ∈ R a,q }
is regular because it is the set of all words obtained from words of R a,q by substituting at each position of the word a set of states containing the respective state at this position. In general, such an operation is called substitution in the context of regular word languages, and the class of regular word languages is closed under substitution.

With this definition we can write the language R with a

(R) → s ∈ ∆ d as R = ( q∈s S a,q ) \ ( q / ∈s S a,q )
showing that it is regular. For the correctness of the construction one easily shows by induction on the height of the trees that

t * --→ A d s iff s = {q ∈ Q | t * -→ A q}.
We omit the details of this straightforward induction.

Encodings and Closure Properties

In this section we present two ways of encoding unranked trees by ranked ones:

• the first-child-next-sibling (FCNS) encoding, and

• the extension encoding.

The first one (FCNS) arises when unranked trees have to be represented by data structures using pointers and lists. As for each node the number of children is unbounded, a natural way to represent this is to have for each node a pointer to the list of its successors. The successors are naturally ordered from left to right. Following this scheme, one ends up with a representation in which each node has a pointer to its first child and to its right sibling. This can be viewed as a binary tree that is known as the FCNS encoding of an unranked tree.

The second encoding takes a more algebraic view and the general idea behind it is not specific to unranked trees: Assume we are dealing with a set O of objects, and that there is a finite set of operations and a finite set of basic objects such that each element of O can be constructed by using these operations starting from the basic objects. Then we can represent each element of O by a (not necessarily unique) finite term that can be used to construct this element. Many structures used in computer science can be represented this way (for example natural numbers using 1 as basic object and the addition as operation, or lists using lists of length one and concatenation).

The extension encoding is of this kind. It uses a single operation that allows to construct all unranked trees from the set of trees of height 0.

Once we have given an encoding we can analyze the notion of recognizability using ranked tree automata on the encodings and how it transfers to the unranked trees (by looking at the pre-images of all recognizable sets of encodings). It turns out that the notion of recognizability using hedge automata is the same as the notion of recognizability obtained from both encodings. This shows that hedge automata provide a robust notion of recognizability and it furthermore allows us to easily transfer several closure properties from the ranked to the unranked setting.

First-Child-Next-Sibling Encoding

The idea for the first-child-next-sibling (FCNS) encoding has already been explained in the introduction of this section. It can be viewed as the binary tree obtained from the unranked tree by representing it using two pointers for each node, one to its first child and the second to its right sibling.

In the terminology of ranked trees, all symbols from the unranked alphabet become binary symbols and an additional constant # is introduced (corresponding to the empty list). For a node of the unranked tree we proceed as follows: As left successor we put its first child from the unranked tree, as right successor we put its right sibling from the unranked tree. Whenever the corresponding node does not exist, then we put # in the encoding. Formally, let F Σ FCNS = {a(, ) | a ∈ Σ} ∪ {#} for an unranked alphabet Σ. Recall that the notation a(, ) means that a is a binary symbol. We define the encoding not only for trees but also for hedges. The following inductive definition of the function fcns : H(Σ) → T (F Σ FCNS ) corresponds to the encoding idea described above. Recall that t[t ′ ] p denotes the tree obtained from t by replacing the subtree at position p by t ′ .

c # b c # # # d b # # b # # Figure 8
.3: An unranked tree, its representation using lists, and its FCNS encoding

• For a ∈ Σ: fcns(a) = a(#, #) • For a tree t = a(t 1 • • • t n ): fcns(t) = a(fcns(t 1 • • • t n ), #) • For a hedge h = t 1 • • • t n with n ≥ 2: fcns(h) = fcns(t 1 )[fcns(t 2 • • • t n )] 2
The last item from the definition corresponds to the following situation: To define the encoding of a hedge we take the encoding of its first tree, and let the pointer for the right sibling point to the encoding of the remaining hedge. We extend this mapping to sets of trees in the usual way:

fcns(L) = {fcns(t) | t ∈ L}.
It is rather easy to see that the function fcns : H(Σ) → T (F Σ FCNS ) is a bijection, i.e. we can use the inverse function fcns -1 .

From the definition one can directly conclude that applying fcns -1 to a tree t ∈ T (F Σ FCNS ) yields an unranked tree (rather than just a hedge) iff t(2) = #. As this property can be checked by an NFTA, a simple consequence is that the image fcns(T (Σ)) of all unranked trees is a recognizable set. This can easily be generalized:

Proposition 8.3.2. If L ⊆ T (Σ) is hedge recognizable, then fcns(L) is recog- nizable.
Proof. We show how to construct an NFTA for fcns(L). We start from an NFHA A = (Q, Σ, Q f , ∆) for L and assume that it is normalized, with the horizontal languages accepted by NFAs B a,q with state set P a,q , final states F a,q , transition relation ∆ a,q , and initial state p 0 a,q . The idea for the transformation to an NFTA on the FCNS encoding is rather simple: On the branches to the right we simulate 8.4: Illustration of the construction from Proposition 8.3.2 the NFAs. At the #-symbols a final state of the NFA has to be reached, showing that the successor word is accepted by the NFA.

q a q 1 b 1 q 2 b 2 q 3 b 3 p 0 a,q p1 p2 p3 p 0 b 1 ,q 1 p 0 b 2 ,q 2 p 0 b 3 ,q 3 q f a p 0 a,q b 1 q # # p 0 b1,q1 # p 1 b 2 p 0 b2,q2 # p 2 b 3 p 0 b3,q3 # p 3 # Figure
We define

A ′ = (Q ′ , F Σ FCNS , Q ′ f , ∆ ′ )
as follows, where P = a∈Σ,q∈Q P a,q and F = a∈Σ,q∈Q F a,q :

• Q ′ = {q f , q # } ∪ P for two new states q f and q # .

• Q ′ f = {q f }. • ∆ ′ contains the following transitions: -# → p for all p ∈ F -# → q # .
This rule is used to identify the right leaf below the root, which has to exist in a correct coding of an unranked tree.

b(p ′ , p ′′ ) → p for all p ′ , p ′′ , p ∈ P such that there is a ∈ Σ and q, q ′ ∈ Q with p ′ = p 0 b,q ′ , and (p, q ′ , p ′′ ) ∈ ∆ a,q . -a(p, q # ) → q f if p = p 0 a,q for some q ∈ Q f . This rule is intended to be used only at the root (there are no further transitions using q f ).

Figure 8.4 illustrates how a run on the unranked tree is transferred to the FCNS encoding. On the left-hand side a run of a hedge automaton on an unranked tree is shown. Additionally the runs of the automata B a,q are shown because this is what is transferred to the FCNS encoding, as depicted on the right-hand side of the figure. Note that the states p 0 b1,q1 , p 0 b2,q2 , p 0 b3,q3 and p 3 are final states of the corresponding NFAs.

For the correctness of this construction one can verify the following property: Consider a hedge t 1 • • • t n with t i → * A q i for all i ∈ {1, . . . , n} and assume that q 1 • • • q n is accepted by some B a,q with a run starting in some state p ∈ P a,q . This is the case if and only if fcns

(t 1 • • • t n ) → * A ′ p.
This can be shown by structural induction on the hedge under consideration. We omit the details of this proof.

For a similar statement in the other direction we remove the hedges by intersecting with the set of all unranked trees after applying the inverse of the FCNS encoding.

Proposition 8.3.3. If L ⊆ T (F Σ FCNS ) is recognizable, then fcns -1 (L) ∩ T (Σ) is hedge recognizable.
Proof. From an NFTA for L ⊆ T (F Σ FCNS ) one can construct a NFHA accepting the desired language. The details of this construction are left as an exercise.

These propositions allow to transfer closure properties from ranked tree automata to hedge automata. Before we do this in detail we first introduce another encoding.

Extension Operator

As mentioned in the introduction to this section, we now consider an encoding using an operation for building unranked trees. In this setting, an unranked tree t is represented by the term that evaluates to this tree t.

The encoding is based on the extension operator @. This operator connects two trees by adding the second tree as the right-most subtree below the root of the first tree. More formally, for two trees t, t

′ ∈ T (Σ) with t = a(t 1 • • • t n ) we let t @ t ′ = a(t 1 • • • t n t ′ ).
If t has height 0, i.e. if n = 0, then we get that a @ t ′ = a(t ′ ). Every unranked tree can be built in a unique way from the symbols of Σ, i.e. the trees of height 0, by applying the extension operator.

Example 8.3.4. The unranked tree a(bc) can be built by starting with the tree a, then adding b as subtree using the extension operator, and then adding c as right-most subtree by using the extension operator again. So we get that a(bc) = (a @ b) @ c.

As @ is a binary operator, we can use it to code unranked trees by ranked ones. We use the symbols from Σ as constants and @ as the only binary symbol: for an unranked alphabet Σ let F Σ ext = {@(, )} ∪ {a | a ∈ Σ}. The extension encoding ext : T (Σ) → T (F Σ ext ) is inductively defined as follows:

• For a ∈ Σ let ext(a) = a.

• For t = a(t 1 • • • t n ) with n ≥ 1 let ext(t) = @(ext(a(t 1 • • • t n-1 )), ext(t n )).
Another way of stating the second rule is: If t is not of height 0, then it is of the form t = t ′ @ t ′′ and we let ext(t) = @(ext(t ′ ), ext(t ′′ ))).

As before, we apply the encoding also to sets and let In each further step of the encoding one more subtree is removed until only the symbol at the root is left. So the a at the left-most leaf in the encoding corresponds to the a at the root of the unranked tree. Although this encoding is less intuitive than the FCNS encoding, it has some advantages. First of all, each tree over the alphabet F Σ ext corresponds to a tree (and not only to a hedge as for the FCNS encoding). Proposition 8.3.6. The extension encoding ext : T (Σ) → T (F Σ ext ) is a bijection. Similar to the FCNS encoding, recognizability is preserved by the extension encoding in both directions.

ext(L) = {ext(t) | t ∈ L}.
Theorem 8.3.7. A language L ⊆ T (Σ) is hedge recognizable if, and only if, ext(L) is recognizable.

We omit the proof because in Subsection 8.6.3 we present the tight relation between deterministic hedge automata and deterministic bottom-up automata on the extension encoding. The same ideas can be used to make the translation for nondeterministic automata. It turns out that one can almost directly transfer the transition relation of the horizontal automata of a hedge automaton to transitions on the extension encoding.

Closure Properties

We have seen that we obtain the same notion of recognizability when using hedge automata or automata on encodings. Therefore, we call languages L ⊆ T (Σ) that are recognizable in one of the formalisms (and thus in all) simply recognizable. Using the closure properties that have been shown in Section 1.3 for ranked tree automata, we can easily conclude that recognizable sets of unranked trees have similar properties.

Theorem 8.3.8. The class of recognizable unranked tree languages is closed under union, under intersection, and under complementation.

Proof. Let L 1 , L 2 ⊆ T (Σ) be recognizable. From Theorem 8.3.7 we conclude that ext(L 1 ) and ext(L 2 ) are recognizable. The class of recognizable languages of ranked trees is closed under union (Theorem 1.3.1) and we have ext(

L 1 ) ∪ ext(L 2 ) = ext(L 1 ∪L 2 ). Thus, ext(L 1 ∪L 2 ) and therefore L 1 ∪L 2 = ext -1 (ext(L 1 ∪ L 2 )) are recognizable.
The same arguments can be used for intersection and complementation.

The concept of homomorphisms, introduced in Section 1.4, relies on the fact that every symbol has a fixed rank. We only adapt the notion of alphabetic homomorphism, which we also call projection in this context. Using these relations it is possible to specify a formula Domain(X) stating that the set X codes a tree domain: ∀x, y.(y ∈ X ∧ (descendant(x, y) ∨ right-sibling(x, y) ⇒ x ∈ X) Note that we do not have to explicitly require that this set is finite because set variables are interpreted by finite sets by definition.

In the same way as for WSkS we can use WMSO to define sets of unranked trees by using formulas of the form ϕ(X, X 1 , . . . , X n ), where X codes the domain of the tree and X 1 , . . . , X n the labeling. A set X i codes the positions in the tree labeled by a i if the alphabet is Σ = {a 1 , . . . , a n }. We can describe correct codings of trees by using the formula Domain(X) and by requiring that X 1 , . . . , X n form a partition of X.

We skip the formal definitions as they are completely analogous to the ones from Section 3.3. We call a language L ⊆ T (Σ) definable if there exists a WMSO-formula defining it.

It turns out that definability and recognizability are the same as in the case of ranked trees. This is not a surprising result as the relations used in WMSO for unranked trees provide a direct link to the FCNS encoding.

Theorem 8.4.2. A language L ⊆ T (Σ) is definable in WMSO if and only if it is recognizable.

Proof. Assume that L is definable in WMSO. It is straightforward to translate a defining WMSO-formula ϕ(X, X 1 , . . . , X n ) into a formula ϕ ′ (X, X 1 , . . . , X n , X # ) of WS2S such that ϕ ′ defines the language fcns(L). Here, the set X # encodes the positions labeled # in the encoding. The formula ϕ ′ is obtained by • requiring that the sets X, X 1 , . . . , X n , X # indeed represent a term (as described in Section 3.3),

• this term codes an unranked tree (not a hedge), and

• replacing atomic formulas in ϕ according to the following table

x ∈ X Y x ∈ X ∧ x / ∈ X # child(x, y) Y y ∈ x12 * next-sibling(x, y) Y y = x2
where x12 * is a short notation for the set of elements z satisfying the formula descendant

(x1, z) ∧ ∀x ′ .(descendant(x, x ′ ) ∧ descendant(x ′ 1, z) ⇒ x = x ′ ).
From this we obtain that L being definable implies that L is recognizable: Transform the defining formula into a WS2S-formula defining fcns(L) as described above. Then fcns(L) is recognizable according to Theorem 3.3.7 from Section 3.3 and hence L is recognizable (Proposition 8.3.3).

For the other direction, the approach of transferring a WS2S-formula for fcns(L) into a WMSO-formula for L is more technical because one has to take care of the elements of the form 2{1, 2} * , which are not used in the FCNS encoding and hence have no counterpart in the unranked tree.

So in fact, it is easier to construct a WMSO-formula that describes the existence of an accepting run of a hedge automaton for L. We omit the details because the construction of the formula is similar to the one from Lemma 3.3.6 from Section 3.3.

Decision Problems and Complexity

In this section we study various decision problems for recognizable languages of unranked trees. We have already seen that choosing appropriate encodings by ranked trees allows to reduce many problems to the well-studied ranked setting. This is certainly also true to some extent for decision problems. Consider for example the emptiness problem: "Given a hedge automaton A, is L(A) empty?"

We can use the construction from Theorem 8.3.7 to construct a ranked tree automaton for the extension encoding of L(A). Then we apply the results from Section 1.7 and conclude that the problem is decidable. This approach has the advantage that we can reuse existing algorithms. A disadvantage of this approach is that it does not take into account the representation of the horizontal languages while languages of unranked trees are commonly defined by schemas using horizontal languages. If the representation of the horizontal languages uses a rather complex formalism, then hedge automata cannot be transfered to automata on the encodings as easily as in Theorems 8.3.7 and 8.3.2. So going through encodings might result in higher complexities in these situations.

From this point of view it is worth developing generic algorithms that directly work with hedge automata and using, whenever possible, required decision procedures for the horizontal level as a black box. In this section we first discuss some representations for the horizontal languages and then consider several decision problems.

To estimate the complexity of algorithms we use as size of the automata the size of their representation. This of course depends on how the horizontal languages are specified, but for these representations we use size definitions which are standard as, e.g., the length of regular expressions or the number of states plus number of transitions for NFAs.

Representations of Horizontal Languages

In Section 8.2 we have specified some example hedge automata using regular expressions for the horizontal languages. We also mentioned that w.r.t. expressive power we can use in principle any formalism for defining regular word languages. Here we present some of such representations and introduce some notations that will be used in the later subsections to illustrate the differences between direct algorithms for hedge automata and the approach via encodings.

The most common way of specifying hedge automata is to use regular expressions or NFAs for the horizontal languages. This might result in rather large automata for simple properties because these formalisms do not allow to easily specify conjunctions of properties or the absence of certain patterns. Consider the following simple example. We are given some trees t 1 , . . . , t n ∈ T (Σ) and a label a ∈ Σ and want to construct a hedge automaton that recognizes the trees with the property that each node with label a has each tree from t 1 , . . . , t n as subtree at least once (in any order). A hedge automaton would need states q 1 , . . . , q n where q i signals that the tree t i has been read. A standard regular expression that checks that all states q 1 , . . . , q n occur in a word basically has to explicitly list all possible permutations. A way to bypass this problem is to allow in the representation of the horizontal languages intersections of regular expressions. Then the required horizontal language can simply be defined by n i=1 Q * q i Q * if Q is the state set of the hedge automaton. Note that we do not allow the intersection as an operator in the expressions but only on the outermost level.

We can generalize this by allowing also negations of regular expressions or arbitrary Boolean combinations of regular expressions. An example for a negation of regular expression is ∼ (Q * q 1 q 2 q 3 Q * ) stating that the pattern q 1 q 2 q 3 does not appear. Specifying the absence of such patterns with standard regular expressions is possible but much more involved.

Expressions of this kind can be translated into alternating finite automata (AFA) of size linear in the expression: The regular expressions can first be translated into NFAs, and then the Boolean operations are applied introducing alternation in the transition function but without increasing the size of the state set (compare Chapter 7).

Since Boolean combinations of regular expressions are a rather natural and convenient formalism for specifying languages, and as they easily translate to AFAs, we will also consider AFAs as a formalism for representing horizontal languages.

Proposition 8.5.1. The (uniform) membership problem for AFAs can be solved in polynomial time, and the emptiness problem for AFAs is PSPACE-complete.

Proof. The membership problem is polynomial even for the more general formalism of alternating tree automata (compare Section 7.5). For the emptiness problem see the bibliographic notes.

Another way of extending regular expressions for making them more succinct is the shuffle or interleaving operator . A shuffle of two words u and v is an arbitrary interleaving of the form u 1 v 1 • • • u n v n where the u i and v i are finite words (that may be empty) such that u

= u 1 • • • u n and v = v 1 • • • v n .
Example 8.5.2. For the words ab and cd the possible shuffles are abcd, acbd, acdb, cabd, cadb, cdab.

As usual, the shuffle of two word languages consists of all shuffles of words from these languages:

R 1 R 2 = {w | ∃u ∈ R 1 , v ∈ R 2 : w is a shuffle of u, v }.
This operator is used in the language Relax NG that is presented in Section 8.7. It is easy to see that the shuffle of two regular languages is again a regular language. Hence the expressive power of regular expressions does not increase if we add this operator. We denote the class of regular expressions extended with the operator by RE . This class of regular expressions has an interesting property. For most formalisms the membership problem is not harder (and in many cases easier) than the emptiness problem. For RE the situation is the other way round. The membership problem becomes harder but the complexity of the emptiness problem does not change because one can replace each operator by the standard concatenation while preserving non-emptiness.

Theorem 8.5.3. The uniform membership problem for RE is NP-complete and the emptiness problem for RE is in PTIME.

In the following subsections we have to explicitly refer to the representation used for the horizontal languages in hedge automata. For this we use notations like NFHA(NFA), denoting the class of nondeterministic hedge automata with horizontal languages represented by NFAs. Another example for this notation is DFHA(AFA) for the class of deterministic hedge automata with horizontal languages represented by AFAs.

Determinism and Completeness

To check if a given NFTA is deterministic one can simply compare all left-hand sides of transitions, which can clearly be done in time polynomial in the size of the automaton. For hedge automata the situation is different because we have to compare the intersections of the horizontal languages appearing in the transitions.

Theorem 8.5.4. Checking whether a given NFHA(NFA) is deterministic can be done in polynomial time and is PSPACE-complete for NFHA(AFA).

To check determinism can be interesting because complementing a deterministic automaton is easier than complementing a nondeterministic one. But to achieve complementation just by exchanging final and non-final states, the automaton also has to be complete. It is not difficult to see that testing for completeness is at least as hard as testing universality for the formalism used to represent the horizontal languages. Hence, the following result is not surprising. Theorem 8.5.5. Checking whether a given NFHA(NFA) or NFHA(AFA) is complete is PSPACE-complete.

In the following subsections, when we estimate the complexity for (complete) automata from DFHA(NFA) or DFHA(AFA) one should keep in mind that testing whether the given automaton has the desired properties might increase the complexity.

Membership

The membership problem, i.e. the problem of deciding for a fixed hedge automaton A if a given tree t is accepted by A (compare Section 1.7), can easily be decided in linear time in the size of t: If A is fixed we can assume that it is deterministic and that all of its horizontal languages are given by DFAs. The run of A on t can then be constructed by a single bottom-up pass over the tree.

The problem is more interesting if the automaton is also part of the input. In this case it is called the uniform membership problem. In Figure 8.6 we give If we are working with DFHA, then for each p ∈ Pos(t) there is at most one state in ρ(p). This means that there is at most one sequence q 1 • • • q k to consider. From this observation we easily obtain (2), and also (4) in combination with the fact that the uniform membership problem for AFAs is solvable in polynomial time.

For (1) we just note that the condition in the if-statement can be decided in polynomial time for NFAs: One starts at the initial state of the NFA and then collects all states of the NFA that are reachable by using elements from ρ(p1) as input, and then continues to compute all states reachable from there with inputs from ρ(p2), and so on. If the last set contains a final state of the NFA, then the condition is satisfied.

To prove (3) we do not use the generic algorithm because we have to provide a nondeterministic one for the upper bound. It is rather easy to see that guessing an accepting run of A and then verifying it can be done in polynomial time because the uniform membership problem for AFAs is solvable in polynomial time.

We show the NP-hardness even for horizontal languages represented by intersections of regular expressions instead of the more general formalism of alternating automata. We use a reduction from the satisfiability problem for Boolean formulas.

Let ϕ = c 1 ∧• • •∧c m be such a formula in CNF using the variables x 1 , . . . , x n , where the c i are disjunctions of literals, i.e. variables or their negations. An assignment to the variables is coded as a string of length n over the alphabet {0, 1}, where 1 in position i codes that variable x i is set to true and 0 that it is set to false. A literal x j is now translated to a regular expression describing all strings of length n with 1 in position j. Correspondingly, the literal ¬x j is translated to an expression requiring 0 in position j of the string. A clause c i corresponds to the regular expression e i obtained as the union of the expressions for the literals in c i . The expression e ϕ , finally, corresponds to the intersection of all the e i .

The NFHA A = (Q, Σ, Q f , ∆) uses a singleton alphabet Σ = {a}, three states Q = {0, 1, q} with Q f = {q}, and the transitions a({ε}) → 0, a({ε}) → 1, a(e ϕ ) → q. Now it is rather easy to observe that A accepts the tree a(a • • • a n ) iff ϕ is satisfiable because an accepting run has to code a satisfying assignment for ϕ at the leaves of the tree.

Finally, (5) follows easily from the NP-completeness of the uniform membership problem for RE (see Theorem 8.5.3).

One should note here that the first two items of Theorem 8.5.6 can easily be obtained by using the extension encoding and the results from Section 1.7 on the uniform membership problem for ranked tree automata.

On the other hand, this approach is not optimal for (3) and (4). One might think that hedge automata with horizontal languages represented by alternating word automata can directly be translated to alternating tree automata working on encodings. But (3) from the above theorem indicates that this is not possible unless P=NP because the uniform membership problem for alternating tree automata is solvable in polynomial time (compare Section 7.5). This suggests that for going through encodings one first has to remove alternation from the horizontal languages, that is one has to convert the alternating finite automata into nondeterministic ones, involving an exponential blow-up. So in general, this procedure requires exponential space opposed to NP and polynomial time for (3) and (4). Similarly, a translation from RE expressions to automata involves an exponential blow-up.

Generic Algorithm for Emptiness input

: NFHA A = (Q, Σ, Q f , ∆) begin Set M = ∅ while ∃a(R) → q ∈ ∆ with q / ∈ M and R| M = ∅ M = M ∪ {q} endwhile output: "yes" if M ∩ Q f = ∅, "no" otherwise end
Finally, we note that the case of NFHA(DFA) is polynomial because it is subsumed by NFHA(NFA), but it is not linear because of the nondeterminism in the tree automaton.

Emptiness

The emptiness problem is decidable in polynomial time for NFTAs (Section 1.7) and DEXPTIME-complete for alternating tree automata (Section 7.5). Here we analyze the problem for hedge automata and get, similar to Theorem 8.5.6, different results depending on the representation of the horizontal languages.

Figure 8.7 shows a generic algorithm deciding the emptiness for hedge automata using an oracle for the non-emptiness of (restrictions of) the horizontal languages: the condition in the while-loop uses the expression R| M = ∅, where M is a subset of Q, the alphabet of R, and R| M simply denotes the restriction of R to the subalphabet M , i.e.

R| M = {w ∈ M * | w ∈ R},
where we use the convention R| ∅ = {ε}.

Apart from that, the algorithm works in the same way as the reduction algorithm for NFTAs from Section 1.1. It computes the set of all reachable states and then checks if there is a final state among them.

The complexity mainly depends on how fast the test R| M = ∅ can be realized.

Theorem 8.5.8. The emptiness problem for hedge automata has the following complexity, depending on the type of the given automaton:

(1) For NFHA(NFA) it is in PTIME.

(2) For NFHA(AFA) it is PSPACE-complete.

(3) For NFHA(RE ) it is in PTIME.

Proof. The first two claims follow directly from the corresponding complexity for the test R| M = ∅ in the while loop. For NFAs this can be done in polynomial time and for AFAs it is PSPACE-complete (Proposition 8.5.1). The last claim follows from the fact that replacing in the RE -expressions each -operator by a standard concatenation results in an automaton that accepts the empty language iff the language of the original automaton is empty. Since standard regular expressions can be translated to NFAs in polynomial time, the claim follows from (1).

One should note again that the first result can easily be obtained using the extension encoding, whereas for (2) this is not the case. First converting the alternating automata for the horizontal languages into nondeterministic can require exponential space.

Inclusion

The inclusion problem, given two hedge automata A 1 and A 2 , decide whether L(A 1 ) ⊆ L(A 2 ), can be solved by a very simple generic algorithm using the emptiness test from Section 8.5.4:

L(A 1 ) ⊆ L(A 2 ) iff L(A 1 ) ∩ (T (Σ) \ L(A 2 )) = ∅ .
To solve the inclusion problem according to this scheme, we have to compute the complement, the intersection, and do the emptiness test.

Theorem 8.5.9. The inclusion problem for hedge automata has the following complexity, depending on the type of the given automaton:

(1) For DFHA(DFA) it is in PTIME.

(2) For NFHA(NFA) it is EXPTIME-complete.

(3) For DFHA(AFA) it is PSPACE-complete.

Proof. As a DFHA(DFA) can easily be completed and then complemented by exchanging final and non-final states, we obtain (1).

see errata

The upper bound for (2) follows from (1) and from the fact that a NFHA(NFA) can be turned into a DFHA(DFA) of exponential size. The lower bound follows from the corresponding one for NFTAs from Section 1.7.

Finally, for (3) a DFHA(AFA) A can be made complete as follows. Let a(R 1 ) → q 1 , . . . , a(R n ) → q n be all transitions of A with label a. An AFA for R = Q * \ n i=1 R i can be constructed in polynomial time from the AFAs for the languages R i . Then we add a new rejecting sink state q ⊥ and the transition a(R) → q ⊥ . Proceeding like this for all labels from Σ yields a complete DFHA(AFA) that can be complemented by exchanging final and non-final states. The intersection of two DFHA(AFA) can be built by using a simple product construction. Now the upper bound follows from Theorem 8.5.8.

The lower bound is easily obtained because the emptiness problem for AFAs is PSPACE-complete.

Minimization

In Section 1.5 we have seen that DFTAs have some good properties with respect to minimization: For each recognizable tree language there is a unique minimal DFTA recognizing it, which can be computed efficiently from a given DFTA for the language.

In this section we discuss the minimization problem for hedge automata. We consider the following three approaches:

1. Use encodings and minimization results for ranked tree languages.

2. Use hedge automata while only looking at the number of states and considering transitions a(R) → q as atomic units.

3. Use hedge automata with a definition of size that takes into account the representations of the languages R in transitions a(R) → q.

The first approach certainly strongly depends on the chosen encoding. One way to justify the choice of a specific encoding is to relate the automata on this encoding to a natural model which is interpreted directly on the unranked trees. When we treat the third approach in Section 8.6.2 we see that this is indeed possible for the extension encoding. Before that we consider the second approach and just focus on the number of states.

Minimizing the Number of States

In Section 1.5 we have seen that for a recognizable language L of ranked trees the congruence ≡ L has finite index. The equivalence classes of ≡ L can be used as states in a canonical automaton, which is also the unique minimal DFTA for this language. Recall the definition of t ≡ L t ′ for ranked trees t, t ′ :

∀C ∈ C(F) : C[t] ∈ L ⇔ C[t ′ ] ∈ L.
This definition can easily be adapted to unranked trees. For this purpose, we use C(Σ) to denote the set of unranked trees with exactly one leaf labeled by a variable. For C ∈ C(Σ) and t ∈ T (Σ) we denote by C[t] the unranked tree obtained by substituting t for the variable in C (in the same way as for ranked trees).

Given a language L ⊆ T (Σ), the definition of ≡ L is then exactly the same as for ranked trees:

t ≡ L t ′ iff ∀C ∈ C(Σ) : C[t] ∈ L ⇔ C[t ′ ] ∈ L.
Using the equivalence classes of ≡ L we can construct a minimal DFHA. To ensure that it is unique we have to require that it is normalized because otherwise one can always split a transition into two without changing the behavior of the automaton.

For the formulation of the following theorem we say that two DFHAs A 1 and A 2 are the same up to renaming of states if there is a bijection f between the two sets of states that respects final states and transitions: q is a final state of A 1 iff f (q) is a final state of A 2 , and a(R) → q is a transition of A 1 iff a(f (R)) → f (q) is a transition of A 2 . Theorem 8.6.1. For each recognizable language L ⊆ T (Σ) there is a unique (up to renaming of states) normalized DFHA with a minimal number of states.

Proof. Let L ⊆ T (Σ) be recognizable. For t ∈ T (Σ) we denote the ≡ L -class of t by [t]. We define the components of A min as follows. Let

Q min = {[t] | t ∈ T (Σ)}, Q min f = {[t] | t ∈ L}. The transition relation ∆ min contains the transitions a(R a,[t] ) → [t] with R a,[t] = {[t 1 ] • • • [t n ] | a(t 1 • • • t n ) ≡ L t}.
This transition relation is deterministic because ≡ L is an equivalence relation.

To show that the sets R a,[t] are regular consider a normalized DFHA A = (Q, Σ, Q f , ∆) accepting L with transitions of the form a(R a,q ) → q. For a state q ∈ Q let

[q] = {t ∈ T (Σ) | t * -→ A q}.
From the definition of ≡ L we obtain that all trees from [q] are ≡ L -equivalent, i.e. for each q there exists a t with [q] ⊆ [t]. Then we can write the sets R a,[t] as

R a,[t] = {[t 1 ] • • • [t n ] | ∃q ∈ Q with [q] ⊆ [t] and q 1 • • • q n ∈ R a,q with [q 1 ] ⊆ [t 1 ], . . . , [q n ] ⊆ [t n ]} .
As the sets R a,q are regular we can derive from this description that also the sets R a,[t] are regular.

For the correctness of the construction one can easily show that t * ----→

Amin [t ′ ] iff t ≡ L t ′ .
As mentioned above, if q is a state of a DFHA for L, then [q] ⊆ [t] for some t ∈ T (Σ). From this one can easily derive that A min is indeed unique up to renaming of states.

However, this result is not sufficient for practical purposes because it does not take into account the size for representing the horizontal languages. Furthermore, the complexity of computing the minimal automaton from a given one by merging equivalent states strongly depends on the formalism used to represent the horizontal languages. If the horizontal languages are given by regular expressions, for example, it is easy to code the equivalence problem for regular expressions into the question of deciding whether a given DFHA is minimal. As the former problem is PSPACE-hard, the latter one is also at least PSPACE-hard.

Furthermore, the congruence ≡ L does not yield a Myhill-Nerode-like theorem as presented in Section 1.5. The following example illustrates this by providing a language L that is not recognizable but for which ≡ L is of finite index.

Example 8.6.2. Consider the set L = {a(b n c n ) | n ∈ N } of unranked trees. The number of equivalence classes of ≡ L for this set is 4: the language L forms one class, the trees b and c form classes of size one, respectively, and all the remaining trees the fourth class. But certainly L is not recognizable because b n c n is not a regular language.

The example shows that regularity on the horizontal level is not captured by the congruence ≡ L . One might be tempted to think that it is enough to require for each label a ∈ Σ, that the set of words occurring as successor word below the label a in some tree of the language is regular. Indeed, this would exclude the above example but it is not difficult to find a non-regular language of trees for which ≡ L is of finite index and this additional condition is also met (see Exercises).

At the end of Section 8.6.3 we give a refinement of ≡ L that is sufficient to characterize the recognizable languages.

Problems for Minimizing the Whole Representation

Minimization becomes a more complex task if we also want to consider the size of the representations of the transitions. It might be that adding additional states to the hedge automaton allows splitting transitions such that the representations for the required horizontal languages become smaller.

If we are interested in unique representations while taking into account also the horizontal languages, then we should certainly choose a formalism that allows unique representations for the horizontal languages. Therefore we only consider DFHAs with horizontal languages given by deterministic finite automata in the following.

But even with this assumption it turns out that there are no unique minimal DFHAs for a given recognizable language. An exact statement of this negative result, however, would require a precise definition of the size of DFHAs. There are various reasonable such definitions, and to prove that minimal DFHAs for a given language are not unique in general, it would be necessary to show this for all these definitions.

Here, we restrict ourselves to an explanation of the main reason why DFHAs are problematic with respect to minimization. In Section 8.6.3 we then introduce a model that solves this problem.

Example 8.6.3. We consider the language containing the trees of the form a(b n ) with n mod 2 = 0 or n mod 3 = 0, i.e. trees of height 1 with a at the root and b at all the successors, where the number of successors divides 2 or 3. A DFHA recognizing this language can use two states q a and q b with rules b({ε}) → q b and a(L) → q a with L = {q n b | n mod 2 = 0 or n mod 3 = 0}. The minimal deterministic automaton (over the singleton alphabet {q b }, which is sufficient for the language under consideration) for L has 6 states because it has to count modulo 6 for verifying if one of the condition holds.

It is also possible to split the second transition into two transitions: a(L 2 ) → q a and a(L 3 ) → q a with L 2 = {q n b | n mod 2 = 0} and L 3 = {q n b | n mod 3 = 0}. The two automata for L 2 and L 3 need only 2 and 3 states, respectively. But in exchange the tree automaton has one transition more.

If we take as size of a DFHA the number of states and the number of transitions of the tree automaton plus the number of states used in the horizontal languages, then the two DFHAs from above are both minimal for the given language but they are clearly non-isomorphic. This example illustrates that the proposed model is not fully deterministic. We have chosen the horizontal automata to be deterministic but to know which automaton to apply we have to know the whole successor word.

One should note here that in the example we did not require the automata to be normalized. But even this additional restriction is not sufficient to guarantee unique minimal automata. The interested reader is referred to the bibliographic notes.

Stepwise automata

We have seen that the first model of deterministic automata that we defined is not fully deterministic on the horizontal level because there may be different choices for the horizontal automaton to apply, or we have to know the full successor word to decide which horizontal automaton to use.

We now present a way to overcome this problem. We start from a rather intuitive model that uses deterministic automata with output at the sequence of successors. By applying simple transformations we finally end up with a model that uses only one sort of states and is tightly connected to automata on encoded trees (see Section 8.3).

We start by explaining the models on an intuitive level and give formal definitions in the end.

We start with a model that works as follows:

• Transitions are represented by deterministic automata with output, one automaton H a for each letter a from Σ. We refer to these automata as 'horizontal automata'.

• For a node labeled a, the automaton H a reads the sequence of states at the successor nodes.

• After reading this sequence the automaton outputs an element from Q.

This is illustrated in the following picture.

q a q 1 a 1 q n a n . . . H a output Example 8.6.4. We consider the set of all unranked trees over the alphabet Σ = {a, b, c, d} such that below each a there exists a subtree containing at least two b, and below each d there exist at least two subtrees containing at least one b.

A hedge automaton for this language can be implemented using states q, q b , q bb indicating the number of b in the subtree (all of them are final states), and a rejecting sink state q ⊥ . If a node is found where one of the conditions is not satisfied, then the automaton moves to q ⊥ . Figure 8.8 shows the transition function of the automaton, represented by deterministic automata with output. The arrow pointing to the initial state

A 0 q ⊥ A 1 q bb B 0 q b B 1 q bb C 0 q C 1 q b C 2 q bb D 0 q ⊥ D 1 q ⊥ D 2
q bb q bb q, q b q b , q bb q q b , q bb q q b , q bb q q b q q b , q bb q q, q b , q bb q, q b , q bb q, q b , q bb q, q b , q bb is labeled with a letter from Σ indicating for which nodes in the tree which automaton has to be used. The output at each state is written in the upper right corner. For example, the output at state C 1 is q b . For better readability we did not specify the transitions for q ⊥ . In each of the four automata a sink state has to be added to which the automaton moves as soon as q ⊥ is read. The output at these sink states is q ⊥ . Figure 8.9 shows a run of this automaton on an input tree. Directly above the labels of the tree the state of the tree automaton is written. The states of the horizontal automata are obtained as follows. Consider the bottom left leaf of the tree. It is labeled by b. So we have to use the automaton with the initial arrow marked with b. This automaton now reads the sequence of states below the leaf, i.e. the empty sequence. It starts in its initial state B 0 . As there is nothing to read, it has finished. We take the output q b of B 0 and obtain the state of the hedge automaton at this leaf. Now consider the node above this leaf, it is labeled by c. So we have to start the horizontal automaton with initial state C 0 . It reads the state q b that we have just computed and moves to C 1 . Then it has finished and produces the output q b . In this way we can complete the whole run.

A first thing to note about this model is that there is no reason to keep the automata H a separate. Looking at the example one quickly realizes that the states A 1 , B 1 , C 2 , D 2 are all equivalent in the sense that they produce the same output and behave in the same way for each input. So instead of having four automata we could consider them as one automaton with four initial states. This allows reducing the representation by merging equivalent states.

Next, we can note that this type of automaton uses two different sets of states, those of the hedge automaton and those of the horizontal automaton. But there is a direct relationship between these two different types of states, namely the one given by the output function: each state of the horizontal automaton is mapped to a state of the hedge automaton. If we replace each state q of the hedge automaton by its inverse image under this output function, i.e. by the set of states of the horizontal automaton that produce q as output, then we obtain a model using only one type of states. The result of these operations applied to the example is shown in Figure 8.10. The state BB is obtained by merging A 1 , B 1 , C 2 , D 2 , and C 1 is merged into B 0 . Then the output function is removed. One can think of each state outputting itself. On the transitions, state q is replaced by C 0 , q b by B 0 , q bb by BB, and q ⊥ by A 0 , D 0 , D 1 . The latter means that the transitions to the sink (not shown in the picture) are now labeled by A 0 , D 0 , and D 1 instead of just q ⊥ . The final states are B 0 , BB, C 0 , i.e. all those states that were mapped to a final state of the hedge automaton before.

On the right-hand side of Figure 8.10 it is shown how this new automaton processes a tree. Consider, for example, the front of the right subtree. Both leaves are labeled by b and hence are assigned state B 0 . Now the automaton processes this sequence B 0 B 0 . As the node above is labeled d, it starts in state D 0 . On reading B 0 it moves to state D 1 . On reading the next B 0 it moves to BB. This is the state assigned to the node above in the tree.

Another example on how the state sequence of the successors is processed is directly below the root: scanning the sequence B 0 C 0 BB leads the automaton from A 0 to BB, which is then assigned to the root.

We now give a formal definition of the model we have just derived. It is basically a word automaton that has its own state set as input alphabet and a function assigning to each letter of the tree alphabet an initial state.

A deterministic stepwise hedge automaton (DSHA) is a tuple A = (Q, Σ, δ 0 , Q f , δ), where Q, Σ, and Q f are as usual, δ 0 : Σ → Q is a function assigning to each letter of the alphabet an initial state, and δ : Q × Q → Q is the transition function.

To define how such an automaton works on trees we first define how it reads sequences of its own states. For a ∈ Σ let δ a : Q * → Q be defined inductively by δ a (ε) = δ 0 (a), and δ a (wq) = δ(δ a (w), q). This corresponds to the view of A as a word automaton reading its own states.

For a tree t and a state q of A we define the relation t *

-→

A q as follows.

Let t = a(t 1 • • • t n ) and t i * -→ A q i for each i ∈ {1, . . . , n}. Then t * -→ A q for q = δ a (q 1 • • • q n ). For n = 0 this means q = δ 0 (a). We have given an intuitive explanation on how to obtain a stepwise automaton for a recognizable language. To formally prove that there indeed is a stepwise automaton for each recognizable language we go through the extension encoding from Subsection 8.3.2.

For this purpose we first analyze how the transitions of a DSHA behave with respect to the extension operator. Our aim is to establish the following simple rules to switch between DSHAs and DFTAs on the extension encodings: ranked stepwise a → q δ 0 (a) = q @(q 1 , q 2 ) → q δ(q 1 , q 2 ) = q

The key lemma needed for this is the following. Lemma 8.6.5. Let A = (Q, Σ, δ 0 , Q f , δ) be a DSHA and t, t ′ ∈ T (Σ) with t * -→ A q and t ′ * -→ A q ′ for q, q ′ ∈ Q. Then t @ t ′ * -→ A δ(q, q ′ ).

Proof. Let t = a(t 1 • • • t n ) with t i * -→ A q i . Then t *

-→

A q means that δ a (q 1 • • • q n ) = q. Further, we have t @ t ′ = a(t 1 • • • t n t ′ ) and δ a (q 1 • • • q n q ′ ) = δ(δ a (q 1 • • • q n ), q ′ ) = δ(q, q ′ ).

Hence, we obtain t @ t ′ * -→ A δ(q, q ′ ).

This allows us to view a stepwise automaton as an automaton on the extension encodings and vice versa. If A = (Q, Σ, δ 0 , Q f , δ) is a DSHA, then we refer to the corresponding DFTA on the extension encoding as ext(A), formally defined as ext(A) = (Q, F Σ ext , Q f , ∆) with ∆ defined according to the above table by

• a → q in ∆ if δ 0 (a) = q, and • @(q 1 , q 2 ) → q in ∆ if δ(q 1 , q 2 ) = q.

Using Lemma 8.6.5 it is not difficult to show that this construction indeed transfers the language in the desired way. For trees with only one node this is obvious from the definition: We have a * -→ A q iff δ 0 (a) = q iff a → q is a rule of B iff a * -→ B q.

If t has more than one node, then t = t ′ @ t ′′ for some t ′ , t ′′ . The definition of ext yields that ext(t) = @(ext(t ′ ), ext(t ′′ )).

Applying the induction hypothesis we obtain that t ′ * -→ A q ′ ⇔ ext(t q means that @(q ′ , q ′′ ) → q is a rule of B. So in A we have δ(q ′ , q ′′ ) = q and we conclude t * -→ A q from Lemma 8.6.5.

Example 8.6.7. A simple consequence is that DSHAs are sufficient to accept all recognizable unranked tree languages. But we can furthermore use the tight connection between DFTAs working on extension encodings and stepwise automata that is established in Theorem 8.6.6 to transfer the results on minimization from Section 1.5 to stepwise automata. Theorem 8.6.8. For each recognizable language L ⊆ T (Σ) there is a unique (up to renaming of states) minimal DSHA accepting L.

Proof. Starting from a stepwise automaton A for L we consider the DFTA B := ext(A). Using the results from Section 1.5 we know that there is a unique minimal DFTA B min equivalent to B. We then define A min := ext -1 (B min ). From Theorem 8.6.6 we conclude that A min is the unique minimal DSHA equivalent to A.

In Section 8.6.1 we have introduced the congruence ≡ L to characterize the state-minimal DFHA for the language L. We have also seen that there are non-recognizable languages for which this congruence has finite index.

In the following we show that there is another congruence characterizing recognizable sets of unranked trees as those sets for which this congruence has finite index.

To achieve this we consider congruences w.r.t. the extension operator from Section 8.3. We say that an equivalence relation ≡ on T (Σ) is an @-congruence if the following holds:

t 1 ≡ t 2 and t ′ 1 ≡ t ′ 2 ⇒ t 1 @ t 2 ≡ t ′ 1 @ t ′ 2 .
It is easy to see that an @-congruence on T (Σ) corresponds to a congruence on T (F Σ ext ) via the extension encoding and vice versa. Thus, we directly obtain the following result.

Theorem 8.6.9. A language L ⊆ T (Σ) is recognizable if and only if it is the union of equivalence classes of a finite @-congruence.

For a recognizable language L ⊆ T (Σ), the congruence ≡ ext(L) can be used to characterize the minimal DFTA for ext(L). By the tight connection between DSHAs and DFTAs on the extension encoding, we obtain that the minimal DSHA can be characterized by the @-congruence ≡ @ L defined as t 1 ≡ @ L t 2 iff ext(t 1 ) ≡ ext(L) ext(t 2 ) .

For a direct definition of ≡ @ L see Exercise 8.9.

XML Schema Languages

The nested structure of XML documents can be represented by trees. Assume, for example, that an organizer of a conference would like to store the scientific program of the conference as an XML document to make it available on the web. In Figure 8.12 a possible shape of such a document is shown and in Figure 8.13 the corresponding tree (the tree only reflects the structure without the actual data from the document). Some requirements that one might want impose on the structure of the description of a conference program are:

• The conference might be split into several tracks.

• Each track (or the conference itself if it is not spilt into tracks) is divided in sessions, each consisting of one or more talks.

• For each session there is a session chair announcing the talks and coordinating the discussion.

• A talk might be contributed, in which case the title and the authors of the contribution are listed, or invited, in which case the title and the speaker are listed.

• Between sessions there might be breaks.

These requirements describe a tree language over the alphabet consisting of the tags like conference, track, etc. used in the document. In these considerations the data is usually ignored and only the structure of the document is taken into account. Such a description of a tree language is also called a schema. A document is said to be valid w.r.t. a schema if it (seen as a tree) belongs to the tree language defined by the schema. There are several languages, called XML schema languages, that allow to describe such requirements on XML documents, and in the following we discuss some of them. This should not be considered as a reference for the syntax and semantics of these schema languages but we rather focus on the theoretical aspects and the connections to automata theory. In particular, we are not considering anything connected to the actual data represented in the documents, as e.g. data types, because we are, as already mentioned, only interested in the structure of the documents.

In particular, we are interested in the expressive power of these languages. Furthermore, we consider the decision problems from Section 8.5 because they correspond to natural questions on XML documents.

• The membership problem corresponds to check whether a given document is valid w.r.t. to a fixed schema. For example, checking whether an HTML document conforms to the specification is an instance of such a problem.

• The uniform membership problem corresponds to validation of a document against some given schema. The schema might for example be specified in the header of the document.

• The emptiness problem corresponds to the question whether for a schema there is any tree valid w.r.t. this schema. This can one the one hand be used for sanity checks on schema descriptions but also as subproblem for solving other questions like the inclusion problem.

• The inclusion problem is the question whether all documents that are valid w.r.t. one schema are also valid w.r.t. another schema. This is, e.g., of interest when merging archives of documents that are valid w.r.t. different schemas.

The practical formalisms that we present in the following all have a syntax that is closer to tree grammars than to hedge automata (compare Chapter 2 for ranked tree grammars). But it is convenient to use hedge automata as a reference model for the expressiveness, and to use the results from Section 8.5 to obtain algorithms and complexity results for the different formalisms in a uniform framework. Furthermore, the knowledge on hedge automata (and word automata) has certainly influenced the development of the formalisms presented here.

The languages defined by DTDs are also called local languages because for a tree t the membership of t in L(D) can be decided just by looking all subpatterns of height 1 (compare also Exercise 2.5 in Chapter 2 for local languages of ranked trees).

It is not difficult to see that these local languages form a proper subclass of the recognizable languages. Even the finite language containing the two trees a(b(cd)) and a ′ (b(dc)) cannot be defined by a DTD because every DTD D such that L(D) contains these two trees would also contain the tree a(b(dc)).

Remark 8.7.1. There are recognizable languages of unranked trees that cannot be defined by DTDs. This illustrates the weakness of DTDs compared to hedge automata. But in fact, DTDs are even more restrictive.

Deterministic Content Models

The following quote is taken from the web site of the W3C recommendation for XML:

For Compatibility, it is an error if the content model allows an element to match more than one occurrence of an element type in the content model.

Informally, this means that, for a given word, we can uniquely match each symbol in this word to an occurrence of the same symbol in the content model by a single left to right pass without looking ahead in the input. This rather vague description is formalized using the notion of deterministic regular expression.

Consider the line <!ELEMENT talk ((title,authors)|(title,speaker))> from the example. The content model is a regular expression of the type ab+ac, which is not deterministic because when reading the first a it is not clear to which a in the regular expression it corresponds. This depends on whether the next letter is b or c.

To formally define deterministic regular expressions (also called 1-unambiguous in the literature) we use markings of regular expressions by adding unique subscripts to each occurrence of letters in the expression: the ith occurrence (from left to right) of a in the expression is replaced by a i .

Example 8.7.2. The marking of the expression (a+b) * b(ab) * is (a 1 +b 1 ) * b 2 (a 2 b 3 ) * .

For a regular expression e over the alphabet Γ we denote by e ′ the corresponding marked expression, and the marked alphabet by Γ ′ . As usual, L(e) and L(e ′ ) are the word languages defined by these expressions. Note that L(e ′ ) defines a language over Γ ′ .

A regular expression e over some alphabet Γ is called deterministic if for all words u, v, w over Γ ′ and all symbols x i , y j ∈ Γ ′ with ux i v, uy j w ∈ L(e ′ ) we have that x i = y j implies x = y.

Example 8.7.3. The expression e = ab + ac is not deterministic because a 1 b 1 and a 2 c 1 are in L(e ′ ) and a 1 = a 2 but a = a. On the other hand, the equivalent expression a(b + c) is deterministic.

We call a DTD with deterministic content models a deterministic DTD.

In the following we mention some results on deterministic regular expressions without giving proofs. The corresponding references can be found in the bibliographic notes.

The main interest in having deterministic regular expressions is that they can easily be translated to DFAs. Theorem 8.7.4. For each deterministic regular expression e one can construct in polynomial time a DFA accepting the language L(e).

This implies that we can construct in polynomial time a DFHA(DFA) accepting the language defined by the DTD. Hence, all the decision problems considered in Section 8.5 can be solved in polynomial time.

Proposition 8.7.5. The uniform membership problem, the emptiness problem, and the inclusion problem for deterministic DTDs are solvable in polynomial time.

This raises the question whether deterministic DTDs have the same expressive power as DTDs without this restriction. The following results imply that this is not the case. But it is decidable whether a DTD is equivalent to a deterministic one. Theorem 8.7.6.

1. Not every regular language can be defined by a deterministic regular expression.

2. Given a DFA one can decide in polynomial time if there is a deterministic regular expression denoting the same language. If such an expression exists it can be constructed in exponential time.

Extended DTDs

We have seen that the main restriction for DTDs is that they can only define local languages. Extended DTDs use types to avoid that problem. For this we consider the alphabet Σ = {a (n) | a ∈ Σ, n ∈ N }, which is called alphabet of types.

An extended DTD (EDTD) over Σ is a DTD over (a finite subset of) Σ, the alphabet of types. A tree t ∈ T (Σ) satisfies an EDTD D if there is an assignment of types to the labels of t such that the resulting tree over Σ satisfies D viewed as DTD over Σ.

Example 8.7.7. We modify the conference example from the beginning of this section. We replace the session tag with two new tags, one for invited sessions and one for contributed sessions, and require that invited sessions have exactly one invited talk and contributed sessions have a sequence of contributed talks. But we do not introduce different tags for the different types of talks. An invited talk is still characterized by the fact that it consists of a title and The new requirement cannot be expressed by a DTD anymore because this would require to distinguish two rules (talk → title speaker) and (talk → title authors), depending on whether the talk is below a tag for an invited session or a contributed session. To resolve this problem one would also have to introduce two new tags for distinguishing invited talks and contributed talks.

To capture the modification that invited sessions only contain a single invited talk and that contributed sessions do not contain invited talks, we can define an EDTD using two types for the talks: conference → track + +((invSession+conSession) (break + ε)) + track → ((invSession+conSession) (break + ε)) + invSession → chair talk (1) conSession → chair (talk (2) ) + talk (1) → title speaker talk (2) → title authors

• • •

We have omitted the types for the other tags because only one type is used for them It is not difficult to see that the types can be used to code the states of a hedge automaton. The proof of this statement is left as an exercise.

Proposition 8.7.8. A language L ⊆ T (Σ) with the property that all trees in L have the same root label is recognizable if and only if it can be defined by an EDTD over Σ.

The conversion from EDTDs to NFHA(NFA) is polynomial and hence we obtain the following. Furthermore, in XML schema the content models also have to be deterministic (called "Unique Particle Attribution") as for DTDs, which is not the case in the above code fragment: There is a choice between two elements with name session, corresponding to a regular expression of the type a + a, which is not deterministic.

In the following we focus on the "Element Declarations Consistent" constraint and do not consider the restriction to deterministic content models because this subject has already been discussed in connection with DTDs.

To capture the restriction on different types in a content model we introduce single-type EDTDs. An EDTD is called single-type if there is no regular expression on the right-hand side of a rule using two different types a (i) and a (j) of the same letter.

We have already seen that uniform membership and emptiness are polynomial for unrestricted EDTDs. If we consider single-type EDTDs that are deterministic, then even the inclusion problem becomes tractable because such EDTDs can be complemented in polynomial time.

Theorem 8.7.10. Let D be a deterministic single-type EDTD. One can construct in polynomial time an NFHA accepting T (Σ) \ L(D).

Proof. Let D = (Σ ′ , s (1) , δ) be a deterministic single-type EDTD.

For those trees that do not have the correct symbol s at the root we can easily construct an automaton. So we only consider those trees with s at the root.

We only sketch the idea of the proof. The technical details are left as exercise.

The single-type property of D allows a unique top-down assignment of types to the nodes of a tree t ∈ T (Σ). One starts at the root with the type of the start symbol. For all other nodes the type is determined by the type of their parents: Let p ∈ Pos(t) such that the parent of p is of type a (i) . There is a rule a (i) → e a,i with a deterministic regular expression e a,i that uses at most one type per letter in D. Let b = t(p). If some type of b appears in e a,i , then this defines the type of p. Otherwise, we assign type b (k) to p, where k is bigger than all the types for b used in D.

Note that this assignment of types also works if t is not in L(D).

One can now construct an NFHA that assigns types to the nodes and accepts only if the assignment is correct according to the above definition, and if there is a node of type a (i) such that the sequence of types at its successors is not in the language of e a,i . To check this latter condition, one has to construct automata for the complement of the languages of the e a,i . As the expressions are deterministic, this is possible in polynomial time.

As discussed in Section 8.5 the complementation step is the most difficult one in the inclusion algorithm.

Theorem 8.7.11. The inclusion problem for deterministic single-type EDTDs is solvable in polynomial time.

Given an EDTD it is very easy to check if it is single-type. In case it is not, one can decide if it can be transformed into a single-type EDTD for the same language. See the bibliographic notes for references.

Theorem 8.7.12. Deciding whether an EDTD is equivalent to a single-type EDTD is EXPTIME-complete.

Relax NG

Relax NG is the most expressive of the tree formalisms presented here. It is very close to regular tree grammars (as presented in Chapter 2) adapted to the setting of unranked trees by allowing regular expressions in the rules for capturing the horizontal languages. Consider again the conference example with the last modification discussed in Section 8.7.2: we have invited and contributed sessions but we do not distinguish them with different labels. The following regular tree grammar defines the corresponding language of trees, where nonterminals are written in small capitals like the start symbol Conference below. We do not give the rules for those nonterminals that directly derive to data: We do not precisely define the semantics of such a grammar because it is the straightforward adaption of the semantics for regular tree grammars from Chapter 2. Such grammars can directly be expressed in Relax NG. In Figure 8.15 the above grammar is presented in Relax NG syntax. The start-block defines the start symbol of the grammar, and the define-blocks the rules of the grammar, where

• the name in the define-tag corresponds to the nonterminal on the lefthand side of the rule, and

• the block enclosed by define-tags gives the right-hand side of the rule, where

• names in element tags correspond to terminals.

In contrast to DTDs and XML schema, it is not required that the content models are deterministic. This of course increases the complexity of algorithms dealing with Relax NG schemas. Furthermore, Relax NG allows an operator <interleave> in the definition of the content models that corresponds to the shuffle introduced in Section 8.5. This raises to complexity of checking whether a given document satisfies a given schema to NP (compare Theorem 8.5.6). But without the use of the interleaving operator this problem is still solvable in polynomial time (linear in the size of the document). Checking emptiness for Relax NG schemas remains in polynomial time, even with interleaving (compare Theorem 8.5.8).

Exercises

Exercise 8.1. As for ranked trees we define for an unranked tree t the word obtained by reading the front from left to right, the yield of t, inductively by Yield (a) = a and <start> <ref name="Conference"/> </start> <define name="Conference"> <element name="conference"> <choice> <oneOrMore> <ref name="Track"/> </oneOrMore> <ref name="Sessions"/> </choice> </element> </define> <define name="Track"> <element name="track"> <ref name="Sessions"/> </element> </define> <define name="Sessions"> <oneOrMore> <choice> <ref name="InvSession"/> <ref name="ConSession"/> </choice> <optional> <ref name="Break"/> </optional> </oneOrMore> </define> <define name="InvSession"> <element name="session"> <ref name="Chair"/> <ref name="InvTalk"/> </element> </define> <define name="ConSession"> <element name="session"> <ref name="Chair"/> <oneOrMore> <ref name="ConTalk"/> </oneOrMore> </element> </define> <define name="InvTalk"> <element name="talk"> <ref name="Title"/> <ref name="Speaker"/> </element> </define> <define name="ConTalk"> <element name="talk"> <ref name="Title"/> <ref name="Authors"/> </element> </define> <define name="Chair"> <element name="chair"> <text/> </element> </define> ... Exercise 8.2. An ǫ-NFHA A = (Q, Σ, Q f , ∆) has the same components as an NFHA except that ∆ may contain ǫ-transitions of the form (q, q ′ ). For t ∈ T (Σ) we define inductively the relation t * -→ A q as follows. If t = a(t1

• • • tn) ∈ Σ, then t * -→ A q if
• there is a rule a(R) → q in ∆ with q1 • • • qn ∈ R where ti * -→ A qi for each i ∈ {1, . . . , n} (for n = 0 this means that ǫ ∈ R), or • t * -→ A q ′ and (q ′ , q) ∈ ∆.

We say that an ǫ-NFHA accepts t if t * -→ A q for some q ∈ Q f . Give a construction that transforms an ǫ-NFHA into an NFHA over the same set of states that accepts the same language.

Exercise 8.3. Give direct constructions to show that the class of recognizable unranked tree languages is closed under union and intersection.

Exercise 8.4. Consider a ranked alphabet F and assume that f is a binary associative symbol. The following recursively defined functions A : T (F ) → T (Σ) and A f : T (F ) → H(Σ) turn a term over F into an unranked tree over Σ by gathering all the arguments of nested applications of f below a single node labeled f , where Σ is an unranked alphabet containing the same symbols as F : A(g(t1, . . . , tn)) = g(A(t1) Exercise 8.5. Let A = (Q, Σ, Q f , ∆) be a normalized NFHA over Σ. We call A top-down determinsitic, i.e. a top-down DFHA, if |Q f | = 1 and for all transitions a(R) → q there is for each n at most one word of length n in R.

• • • A(tn)) for g = f A(f (t1, t2)) = f (A f (t1) A f (t2)) A f (f (t1, t2)) = A f (t1) A f (t2) A f (
(a) Give a recognizable language L ⊆ T (Σ) that cannot be recognized by a top-down DFHA.

(b) Give a language L ⊆ T (Σ) that is recognizable by a top-down DFHA such that the two languages fcns(L) and ext(L) cannot be recognized by a top-down DFTA.

Exercise 8.6. Give the proof of Proposition 8.3.3 (page 209).

Exercise 8.7. Let L ⊆ T (Σ) be definable in WMSO and let ϕ(X, X1, . . . , Xn) be a defining formula. Construct a formula ϕ ′ (X, X1, . . . , Xn, X @ ) of WS2S that defines ext(L) (similar to the proof of Theorem 8.4.2 on page 213 where such a formula for fcns(L) is constructed).

Exercise 8.8. Show that the finiteness problem for NFHA(NFA) is solvable in polynomial time. The finiteness problem for ranked tree automata is described in Section 1.7.

Exercise 8.9. Find a non-recognizable language L ⊆ T (Σ) such that ≡L is of finite index and the horizontal language Ra for each label a ∈ Σ, defined as Exercise 8.10. Consider the congruence ≡ @ L defined on page 229. Our aim is to provide a direct definition: For an unranked alphabet Σ the set of special trees is defined to be the set of trees over Σ ∪ {•} that have exactly one node labeled with •. A special tree s is always of the form s = C[•(s1 • • • sn)], where C ∈ C(Σ) and s1, . . . , sn ∈ T (Σ). For t ∈ T (Σ) we define s•t = C[t@s1@• • •@sn], i.e. if t = a(t1

• • • tm), then s • t = C[a(t1 • • • tms1 • • • sn)]. Show that t1 ≡ @ L t2 iff s • t1 ∈ L ⇔ s • t2
∈ L for all special trees s.

Exercise 8.11. Give the proof that recognizable languages of unranked trees with the property that every tree in the language has the same root symbol are exactly those languages definable by EDTDs (compare Proposition 8.7.8 on page 235).

Exercise 8.12. Work out the details for the construction in Theorem 8.7.10 on page 238.

Bibliographic Notes

The first papers considering automata for unranked trees and hedges appeared around the same time as those for ranked trees. In [START_REF] Thatcher | Characterizing derivation trees of context-free grammars through a generalization of finite automata theory[END_REF] several basic results are stated and the connection to derivation trees of context-free grammars with regular expressions in the rules is mentioned. The proofs are not given in the paper but the reader is pointed to technical reports. Approximately at the same time, in [START_REF] Pair | Définition et étude des bilangages réguliers[END_REF] languages of hedges ("bilangages") are studied from an algebraic point of view. A few years later [START_REF] Takahashi | Generalizations of regular sets and their application to a study of context-free languages[END_REF] considers tree languages over alphabets where symbols can have several ranks (even infinitely many). The case of unranked trees is called homogeneous rank. Besides derivation trees of context-free grammars with regular expressions also systems involving horizontal recursion are considered for generating unranked trees.

Later, the theory of tree automata has focused on ranked trees. Unranked trees became interesting again as a formal model for XML documents and the corresponding automata theory was revived by Brüggemman-Klein, Murata, and Wood [START_REF] Murata | Hedge Automata: a Formal Model for XML Schemata[END_REF][START_REF] Brüggemann-Klein | Regular tree and regular hedge languages over unranked alphabets[END_REF]. Before that in [START_REF] Barrero | Unranked tree languages[END_REF] languages of unranked trees have been studied but using automata without regular languages on the horizontal level, i.e. with only finitely many transitions.

The term hedge was coined by Courcelle in [START_REF] Courcelle | A representation of trees by languages I[END_REF][START_REF] Courcelle | On Recognizable Sets and Tree Automata, chapter Resolution of Equations in Algebraic Structures[END_REF] who studied algebraic notions of recognizability. This notion is not standard, in the older papers one finds the notions, ramification [START_REF] Pair | Définition et étude des bilangages réguliers[END_REF], and forest [START_REF] Takahashi | Generalizations of regular sets and their application to a study of context-free languages[END_REF]. Nowadays, the notion hedge is used very often but the term forest also appears.

Encodings of unranked trees by ranked ones have already been considered independently of automata theory: The first-child-next-sibling encoding can be found in the textbook [START_REF] Knuth | The Art of Computer Programming[END_REF]. The extension encoding was presented in [START_REF] Carme | Querying unranked trees with stepwise tree automata[END_REF] but the extension operator for unranked trees was already used in [START_REF] Takahashi | Generalizations of regular sets and their application to a study of context-free languages[END_REF]. There are several other encodings that have been used in the literature. In [START_REF] Milo | Typechecking for XML transformers[END_REF] transformations of unranked trees are studied using an encoding similar to the FCNS encoding. In [START_REF] Courcelle | On Recognizable Sets and Tree Automata, chapter Resolution of Equations in Algebraic Structures[END_REF] an encoding based on operators to build unranked trees is presented, which is similar in spirit to the extension encoding.

We have only briefly presented the connection between logic and hedge automata. For an extensive survey on various kinds of logics for unranked trees we refer the reader to the survey [START_REF] Libkin | Logics for unranked trees: An overview[END_REF].

Many of the results concerning complexities of decision problems can be considered folklore as they are easily obtained using encodings and corresponding results for ranked tree automata. Representations using alternating automata (even two-way) for the horizontal languages are used in [START_REF] Martens | Typechecking top-down uniform unranked tree transducers[END_REF] to obtain complexity bounds for transformations of XML documents. For complexities of decision problems for alternating word automata we refer to [START_REF] Vardi | An automata-theoretic approach to linear temporal logic[END_REF] and references therein. The membership problem for regular expressions with shuffle are treated in [START_REF] Mayer | Word problems -this time with interleaving[END_REF].

The minimization problem for hedge automata is studied in [START_REF] Martens | Minimizing tree automata for unranked trees[END_REF] and [START_REF] Cristau | Deterministic automata on unranked trees[END_REF]. The latter article considers the model introduced at the beginning of Section 8.6.3 and gives a minimization procedure directly working on the unranked tree automaton. The results presented in Section 8.6.3 are from [START_REF] Martens | Minimizing tree automata for unranked trees[END_REF]. There one can also find more results on the problems discussed in Section 8.6.2. The characterization of minimal stepwise automata by congruences is also discussed in [START_REF] Martens | Minimizing tree automata for unranked trees[END_REF] but Theorem 8.6.9 already goes back to [START_REF] Takahashi | Generalizations of regular sets and their application to a study of context-free languages[END_REF].

There is a lot of literature on XML and the connection to automata and we cannot give a comprehensive overview of this very rich field of research. Our presentation is oriented along the lines of [START_REF] Murata | Taxonomy of XML schema languages using formal language theory[END_REF], where the correspondence between DTDs and local languages, XML Schema and single-type EDTDs, and Relax NG and regular tree grammars is illustrated. The results on deterministic regular expressions presented in Section 8.7.1 are from [START_REF] Brüggemann-Klein | One-unambiguous regular languages[END_REF]. Even stronger forms of unambiguity of regular expressions have been studied in [START_REF] Koch | Attribute grammars for scalable query processing on XML streams[END_REF] in the context of transforming streaming XML documents. The inclusion problem for DTDs with other fragments of regular expressions is considered in detail in [START_REF] Martens | Complexity of decision problems for simple regular expressions[END_REF].

The results on single-type EDTDs (Theorems 8.7.11 and 8.7.12) are from [START_REF] Martens | Which XML schemas admit 1-pass preorder typing?[END_REF] (where EDTDs are called specialized DTDs). Single-type EDTDs are close to top-down deterministic automata as defined in [START_REF] Cristau | Deterministic automata on unranked trees[END_REF], where it is shown that it is decidable whether a given NFHA is equivalent to one that is top-down deterministic.

Something that has not been discussed in this chapter are problems for streaming XML documents. In this setting the documents are not accessible in their tree shape but arrive as a stream and can only be parsed once. Problems in this framework have for example been addressed in [START_REF] Segoufin | Validating streaming XML documents[END_REF] and [START_REF] Martens | Which XML schemas admit 1-pass preorder typing?[END_REF][START_REF] Martens | Expressiveness and complexity of XML schema[END_REF].

Another aspect that we did not take into account concerns the data values in the XML documents. In this case one has to deal with automata over infinite alphabets. This is addressed, e.g., in [START_REF] Neven | Finite state machines for strings over infinite alphabets[END_REF] and [BMS + 06, BDM + 06].

Finally, one should certainly mention the survey [START_REF] Neven | Automata, logic, and XML[END_REF], which gives a nice overview of several topics related to XML and automata for unranked trees.

Index

  Languages and Finite Tree Automata 19 1.1 Finite Tree Automata . . . . . . . . . . . . . . . . . . . . . . . . 20 1.2 The Pumping Lemma for Recognizable Tree Languages . . . . . 28 1.3 Closure Properties of Recognizable Tree Languages . . . . . . . . 29 1.4 Tree Homomorphisms . . . . . . . . . . . . . . . . . . . . . . . . 31 1.5 Minimizing Tree Automata . . . . . . . . . . . . . . . . . . . . . 35 1.6 Top Down Tree Automata . . . . . . . . . . . . . . . . . . . . . . 38 1.7 Decision Problems and their Complexity . . . . . . . . . . . . . . 39 1.8 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 1.9 Bibliographic Notes . . . . . . . . . . . . . . . . . . . . . . . . . . 47 2 Regular Grammars and Regular Expressions 51 2.1 Tree Grammar . . . . . . . . . . . . . . . . . . . . . . . . . .

f

  (s 1 , . . . , s n ) → A d s. By induction hypothesis, for each i ∈ {1, . . . , n}, s i = {q ∈ Q | t i * -→ A q}. States s i are in Q d , thus a rule f (s 1 , . . . , s n ) → s ∈ ∆ d isadded in the set ∆ d by the determinization algorithm and s = {q ∈ Q | ∃q 1 ∈ s 1 , .

2.

  Prove that the set L2 = {t ∈ T (F ) | |t|a = |t| b } is not recognizable where |t|a (respectively |t| b ) denotes the number of a (respectively the number of b) in t.

  ) and (a → a 1 . . . a p ) ∈ R where a i ∈ G.The set of derivation treesof G is D(G) = ∪ (S,i)∈G D(G, (S, i)).Example 2.4.2. Let T = {x, +, * } and let G be the context free word grammar with axiom S, non terminal Op, and rulesS → S Op S S → x Op → + Op → *Let the word u = x * x + x, a derivation tree for u with G is d G (u), and the same derivation tree with our notations is D G (u) ∈ D(G,

2.

  Same questions with Yield (L) = {u ∈ F * 0 | |u|a = |u| b } where |u|a (respectively |u| b ) denotes the number of a (respectively the number of b) in u. 3. Let F be a ranked alphabet such that F0 = {a, b, c}, let A1 = {a n b n c p | n, p ≥ 0}, and let A2 = {a n b p c p | n, p ≥ 0}. Find regular tree languages such that Yield (L1) = A1 and Yield (L2) = A2. Does there exist a regular tree language such that Yield (L) = A1 ∩ A2.

Figure 3 . 2 :

 32 Figure 3.2: The overlap of two terms

Figure 3 . 4 :

 34 Figure 3.4: The relations between the three classes

Figure 3 . 5 :

 35 Figure 3.5: The proof of Theorem 3.2.14

Figure 3

 3 Figure 3.7: An example of a tree coding a triple of finite sets of strings

  Example 3.3.3. Consider for instance S 1 = {ǫ, 11}, S 2 = ∅, S 3 = {11, 22} three subsets of {1, 2} * . Then the coding (S 1 , S 2 , S 3 ) ∼ is depicted on Figure 3.7. Lemma 3.3.4. If a set L of tuples of finite subsets of {1, . . . , k} * is definable in WSkS, then L def = {(S 1 , . . . , S n ) ∼ | (S 1 , . . . , S n ) ∈ L} is in Rec.

Figure 3

 3 Figure 3.12: u encompasses t

  Proposition 3.4.14. If R is left linear, then the predicates N ? and N V are definable in WSkS and their sequentiality is decidable.Proof. The approximations R? and R ′ satisfy the hypotheses of Proposition 3.4.7 and hence *

Exercise 3. 6 .

 6 About Rec and bounded delay relations. We assume that F only contains unary function symbols and a constant, i.e. we consider words rather than trees and we write u = a1 . . . an instead of u = a1(. . . (an(0)) . . .). Similarly, u • v corresponds to the usual concatenation of words.A binary relation R on T (F ) is called a bounded delay relation if and only if ∃k/∀(u, v) ∈ R, |u| -|v| ≤ k R preserves the length if and only if ∀(u, v) ∈ R, |u| = |v| If A, B are two binary relations, we write A • B (or simply AB) the relation

  w |= p if and only if w(0) = p • The interpretation of logical connectives is the usual one • w |= Nφ if and only if |w| ≥ 2 and w(1..|w| -1) |= φ • w |= Lφ if and only if |w| = 1 • w |= φUψ if and only if there is an index i ∈ [0..|w|] such that for all j ∈ [0..i], w(j..|w| -1) |= φ and w(i..|w| -1) |= ψ.

  Example 4.2.1. With the above definition, we have: f (a, f (a, b)) |= 1 = 21, and f (a, b) |= 1 = 2.

Figure 4

 4 Figure 4.1: A computation of the sum of two natural numbers

Figure 4

 4 Figure 4.3: A close equality is created

  it is a remote equality. The different situations are depicted on Figures 4.3 and 4.4.

Figure 4

 4 Figure 4.4: A remote equality is created

Figure 4 . 5 :

 45 Figure 4.5: Transitions of the 2-counter machine

  Corollary 4.4.8. Reduction automata cannot be determinized.Proof. By Theorems 4.4.7 and 4.4.5.

Figure 5 . 1 :

 51 Figure 5.1: An infinite tree for the representation of a couple of word languages (X, Y ). Each node is associated with a word. A black dot stands for belongs to. X = {ε, aa, bb, . . . } and Y = {ε, bb, . . . }.

Figure 5

 5 Figure 5.3: The (beginning of the) underlying structure for a two letter alphabet {f (, ), a}.

Figure 5 . 4 :

 54 Figure 5.4: Forbidden patterns for (5.5).

  and R = π where π is the projection from E × E ′ into E. The case of cylindrification is proved in a similar way. (b) Consequence of (a) and of Proposition 5.3.1 because

  e 1 , . . . , e p )) = f (I(e 1 ), . . . , I(e p )); I(∼ e) = T (F) \ I(e); I(e ∪ e ′ ) = I(e) ∪ I(e ′ ); I(e ∩ e ′ ) = I(e) ∩ I(e ′ ).

Figure 6 . 4 :

 64 Figure 6.4: The control automaton L.

, 0 q0, 0 Figure 7

 07 Figure 7.1: Two runs on the word 00101 of the automaton defined in Example 7.2.1. The right one is successful.

  Theorem 7.5.1. The emptiness problem and the universality problem for alternating tree automata are DEXPTIME-complete.Proof. The DEXPTIME membership is a consequence of Theorems 1.7.4 and 7.4.1.

  Example 8.2.1. Consider the unranked tree t = a(c(b)cd(ab)) and its graphical notation together with the corresponding set of positions:

  Example 8.2.4. In Example 1.1.3 on page 22 we have seen an NFTA accepting the set of all true Boolean expressions built from a unary negation symbol and binary conjunction and disjunction symbols. As conjunction and disjunction are associative, we can also view them as operators without fixed arity.Consider the alphabet Σ = {or, and, not, 0, 1} and the NFHA A = (Q, Σ, Q f , ∆)

  Example 8.3.1. The unranked tree a(c(b)cd(bb)) is encoded asa(c(b(#, #), c(#, d(b(#, b(#, #), #))), #).

Figure 8 .

 8 Figure8.3 shows the tree itself, its representation using two pointers (where the solid arrow points to the first child and the dashed arrow to the right sibling), and the FCNS encoding.

Example 8.3. 5 .

 5 Consider the tree t = a(c(b)cd(bb)) depicted on the left-hand side of Figure 8.5. The recursive rule for the encoding tells us that ext(t) = @(ext(a(c(b)c)), ext(d(bb))). So the left subtree in the encoding surrounded by the dashed line corresponds to the part of the unranked tree surrounded by the dashed line.

Figure 8 . 5 :

 85 Figure 8.5: An unranked tree and its extension encoding

Figure 8

 8 Figure 8.7: A generic algorithm for emptiness of hedge automata

Figure 8

 8 Figure 8.8: Transition function of the automaton from Example 8.6.4

Figure 8

 8 Figure 8.9: A run using the transition function from Figure 8.8

Figure 8

 8 Figure 8.10: Model using only one sort of states

  Figure 8.11: A run on the extension encoding corresponding to the run in Figure 8.10

Figure 8 .

 8 11 shows the run on the extension encoding corresponding to the right-hand side of Figure 8.10.

Figure 8

 8 Figure 8.14: An example for a document structure satisfying the XML schema for the extended example

Conference

  → conference(Track + + Sessions) Track → track(Sessions) Sessions → ((InvSession+ConSession) (Break +ε)) + InvSession → session(Chair InvTalk) ConSession → session(Chair ConTalk + ) InvTalk → talk(Title Speaker) ConTalk → talk(Title Authors)

Figure 8 .

 8 Figure 8.15: Relax NG grammar for the conference example with invited and contributed sessions

  g(t1, . . . , tn)) = g(A(t1) • • • A(tn)) for g = f Show the following: (a) There is a recognizable set L ⊆ T (F ) such that {A(t) ∈ T (Σ) | t ∈ L} needs not to be a recognizable set of unranked trees. (b) If L ⊆ T (F ) is recognizable and closed under the congruence defined by the equation f (x, f (y, z)) = f (f (x, y), z), then {A(t) ∈ T (Σ) | t ∈ L} is recognizable.

  * ˛∃t ∈ L, p ∈ Pos(t) such that t(p) = a and w = t(p1) • • • t(pk) for k = max{i | pi ∈ Pos(t)} ff is regular.

  Regular Expressions. Kleene's Theorem for Tree Languages . . . 54 2.2.1 Substitution and Iteration . . . . . . . . . . . . . . . . . . 55 2.2.2 Regular Expressions and Regular Tree Languages . . . . . 57 2.3 Regular Equations . . . . . . . . . . . . . . . . . . . . . . . . . . 61 2.4 Context-free Word Languages and Regular Tree Languages . . . 63 2.5 Beyond Regular Tree Languages: Context-free Tree Languages . 66 2.5.1 Context-free Tree Languages . . . . . . . . . . . . . . . . 66 2.5.2 IO and OI Tree Grammars . . . . . . . . . . . . . . . . . 67 2.6 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 2.7 Bibliographic notes . . . . . . . . . . . . . . . . . . . . . . . . . . 71 3 Logic, Automata and Relations 73 3.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 3.2 Automata on Tuples of Finite Trees . . . . . . . . . . . . . . . . 75 3.2.1 Three Notions of Recognizability . . . . . . . . . . . . . . 75 3.2.2 Examples of The Three Notions of Recognizability . . . . 77 3.2.3 Comparisons Between the Three Classes . . . . . . . . . . 78

. . 51 2.1.1 Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . 51 2.1.2 Regularity and Recognizabilty . . . . . . . . . . . . . . . 54 2.2

  Deciding finiteness of A is direct by Corollary 1.2.3: it suffices to find an accepted term t s.t. |Q| < t ≤ 2 * |Q|. A more efficient way to test finiteness is to check the existence of a loop: the language is infinite if and only if there is a loop on some useful state, i.e. there exist an accessible state q and contexts C and

  3.3 how to represent a term using a tuple of set variables. Now, we use this formula Term on the coding of tuples of terms; for (t 1 , . . . , t n ) ∈ T (F) n , we write [t 1 , . . . , t n ] the (|F| + 1) n + 1-tuple of finite sets which represents it: one set for the positions of [t 1 , . . . , t n ] and one set for each element of the alphabet (F ∪ {⊥}) n . As it has been seen in section 3.3.3, there is a WSkS formula Term([t 1 , . . . , t n ]) which expresses the image of the coding. Lemma 3.3.6. Every relation in Rec is definable. More precisely, if R ∈ Rec there is a formula φ such that, for all terms t 1 , . . . , t n , if (S 1 , . . . , S m ) = [t 1 , . . . , t n ], then (S 1 , . . . , S m ) |= 2 φ if and only if (t 1 , . . . , t

n ) ∈ R

Proof. Let A be the automaton which accepts the set of terms [t 1 , . . . , t n ] for (t 1 , . . . , t n ) ∈ R. The terminal alphabet of A is F ′ = (F ∪{⊥}) n , the set of states Q, the final states Q f and the set of transition rules T . Let F ′ = {f 1 , . . . , f m } and Q = {q 1 , . . . , q l }. The following formula φ A (with m + 1 free variables) defines the set {[t 1 , . . . , t n ] | (t 1 , . . . , t n ) ∈ R}.

  3.4.8. If R is a linear term rewriting system such that left and right members of the rules do not share variables, then the first-order theory of rewriting is decidable.

	Proof. By Proposition 3.4.7,

* -→ R is recognized by a GTT. From Proposition 3.2.7, * -→ R is in Rec. By Lemma 3.3.6, there is a WSkS formula whose solutions are exactly the pairs (s, t) such that s * -→ R t. Finally, by Theorem 3.3.8, the first-order theory of * -→ R is decidable.

  x n ∈ X τn and t is a term of type τ , then λx 1 , . . . x n : t is a term of type τ 1 , . . . , τ n → τ • If t is a term of type τ 1 , . . . , τ n → τ and t 1 , . . . , t n are terms of respective types τ 1 , . . . , τ n , then t(t 1 , . . . , t n ) is a term of type τ .

  As 1 ,...,sn,t is O(n × |t|) 3. Deduce from Exercise 1.20 that the existence of a solution to a system of interpolation equations of the form x(s1, . . . , sn) = t (where x is a third order variable in each equation) is in NP. Exercise 3.21. About general third order matching. 1. How is it possible to modify the construction of As 1 ,...,sn,t so as to forbid some symbols of t to occur in the solutions? 2. Consider a third order matching problem u = t where t is in normal form and does not contain any free variable. Let x1, . . . , xn be the free variables of u and xi(s1, . . . , sm) be the subterm of u at position p. Show that, for every solution σ, either u[2]pσ ↓=α t or else that xiσ(s1σ, . . . , smσ) ↓ is in the set Sp defined as follows: v ∈ Sp if and only if there is a subterm t ′ of t and there are positions p1, . . . , p k of t ′ and variables z1, . . . , z k which are bound above p in u such that v = t ′ [z1, . . . , z k ]p 1 ,...,p k . 3. By guessing the results of xiσ(s1σ, . . . , smσ) and using the previous exercise, show that general third order matching is in NP.

  2.8. The class AWEDC is effectively closed by all Boolean operations. Union requires linear time, intersection requires quadratic time and complement requires exponential time. The respective sizes of the AWEDC ob-tained by these construction are of the same magnitude as the time complexity.

  4.3.1. The set of terms {f (t, t) | t ∈ T (F)} is accepted by an automaton of the class AWCBB, because the automaton of Example 4.2.2 is in AWCBB indeed.

4.3.2 Closure Properties

Proposition 4.3.2. AWCBB is a stable subclass of AWEDC w.r.t. Boolean operations (union, intersection, complementation). Proof. It is sufficient to check that the constructions of Propositions 4.2.4, 4.2.6 and 4.2.8 preserve the property of being a member of AWCBB.

This automaton accepts the set of pairs of terms (u, v) such that u can be rewritten in one or more steps to v by the rewrite system f (g(x), y) → g(a).

i.e. the terms that are obtained by applying at least one rewriting step using f (g(x), y) → g(a)

This is very similar to the coding of Section 3.2.1

=2--→ q 1 , and hence pass the constraint 1 =

2, we need at least two distinct terms in q (for instance a and b). Note that knowing

exp = exp ′ for exp ⊆ exp ′ ∧ exp ′ ⊆ exp.

The entire class of Rabin's tree languages is not captured by solutions of set of words constraints. Set of words constraints define a class of languages which is strictly smaller than Büchi recognizable tree languages.

close equalities, 128 closed, 16 closure, 56 closure properties for Rec × ,Rec, 80 for GTTs, 82 for hedge automata, 211 closure property, 29 complementation, 30 intersection, 30 union, 30 complete, 35, 117 NFHA, 204 complete specification of an automaton with constraints, 117 concatenation, 56 congruence, 35 finite index, 35 for unranked trees, 221, 229 constraint disequality constraint, 114 equality constraint, 114 content model, 232 context, 17 context-free tree grammar, 66 tree languages, 67 word grammar, 64 cryptographic protocols, 195 cylindrification, 80 definable language of unranked trees, 213 set, 90 definite set constraints, 190 delabeling, 35 derivation relation, 52 derivation trees, 64 determinacy

Acknowledgments

Many people gave substantial suggestions to improve the contents of this book. These are, in alphabetic order, Witold Charatonik, Zoltan Fülöp, Werner Kuich, Markus Lohrey, Jun Matsuda, Aart Middeldorp, Hitoshi Ohsaki, P. K. Manivannan, Masahiko Sakai, Helmut Seidl, Stephan Tobies, Ralf Treinen, Thomas Uribe, Sandor Vágvölgyi, Kumar Neeraj Verma, Toshiyuki Yamada.

Closure and Decision Properties

Closure properties

This section is dedicated to the study of classical closure properties on GTSArecognizable languages. For all positive results -union, intersection, projection, cylindrification -the proofs are constructive. We show that the class of recognizable sets of generalized tree sets is not closed under complementation and that non-determinism cannot be reduced for generalized tree set automata.

Set operations on sets of GTS have to be distinguished from set operations on sets of terms. In particular, in the case where E = {0, 1} n , if G 1 and G 2 are sets of GTS in G E , then G 1 ∪ G 2 contains all GTS in G 1 and G 2 . This is clearly different from the set of all (L 1 1 ∪ L 2 1 , . . . , L This proof is an easy modification of the classical proof of closure properties for tree automata, see Chapter 1.

Proof. Let A 1 = (Q 1 , ∆ 1 , Ω 1 ) and A 2 = (Q 2 , ∆ 2 , Ω 2 ) be two generalized tree set automata over E. Without loss of generality we assume that

We denote by π 1 and π 2 the projections from

defined by (f (q 1 , . . . , q p ) l → q ∈ ∆ ′ ) ⇔ (∀i ∈ {1, 2} f (π i (q 1 ), . . . , π i (q p )) l → π i (q) ∈ ∆ i ) ,

where q 1 , . . . , q p , q ∈ Q ′ , f ∈ F p , l ∈ E, and Ω ′ is defined by

One can easily verify that

Let us remark that the previous constructions also prove that the class R SGTS is closed under union and intersection.

The class languages recognizable by deterministic generalized tree set automata is closed under complementation. But, this property is false in the general case of GTSA-recognizable languages.

Proposition 5.3.2. (a) Let A be a generalized tree set automaton, there exists a complete generalized tree set automaton A c such that L(A) = L(A c ).

(b) If

A cd is a deterministic and complete generalized tree set automaton, there exists a generalized tree set automaton

(c) The class of GTSA-recognizable languages is not closed under complementation.

(d) Non-determinism can not be reduced for generalized tree set automata.

Exercise 6.8. We identify words with trees over symbols of arity 1 or 0. Let relations

Prove that U is a deterministic linear complete bottomup transduction but not a deterministic top-down transduction. Prove that D is a deterministic linear complete top-down transduction but not a deterministic bottomup transduction.

Exercise 6.9. Prove point 3 of Comparison Theorem. Hint. Use rule-by-rule techniques as in Exercise 6.10.

Exercise 6.10. Prove Composition Theorem (Th. 6.4.5). Hints: Prove 1 and 2 using composition "rule-by-rule", illustrated as following. States of A • B are products of states of A and states of B. Let f (q(x)) →A q ′ (g(x, g(x, a))) and g(q1(x), g(q2(y), a) →B q4(u). Subterms substituted to x and y in the composition must be equal, and determinism implies q1 = q2. Then we build new rule f ((q, q1)(x)) →A•B(q ′ , q4)(u). Exercise 6.12. Use constructions of composition theorem to reduce the number of passes in process of Section 6.3.

Exercise 6.13. Prove recognizability theorem. Hint: as in exercise 6.10, "naive" constructions work.

Exercise 6.14. Prove Theorem 6.5.1. Hint: "naive" constructions work.

Exercise 6.15. Prove point 2 of Theorem 6.5.2. Hint: E denote the class of homomorphisms which are linear and symbol-to-symbol. L, LC, LCF denotes linear, linear complete, linear complete ε-free homomorphisms, respectively. Prove

Deduce from these properties and from point 1 of Theorem 6.5.2 that

1 , where Φ is the homomorphism used in point 1 of Theorem 6.5.2; Ψ1 identity on a, f (x), g(x, y), h(x, y, z), Ψ1(e(x)) = x; Ψ2 identity on a, f (x), g(x, y) and Ψ2(c(x, y, z) = b(b(x, y), z). Exercise 6.16. Sketch of proof of LCFB 2 = LCFB 3 (difficult). Distance D(x, y, u) of two nodes x and y in a tree u is the sum of the lengths of two branches which join x and y to their younger common ancestor in u. D(x, u) denotes the distance of x to the root of u.

Let H the class of deterministic top-down transducers T defined as follows: q0, . . . , qn are states of the transducer, q0 is the initial state. For every context, consider the result ui of the run starting from qi(u). ∃k, ∀ context u such that for every variable x of u, D(x, u) > k:

• u0 contains at least an occurrence of each variable of u,

• for any i, ui contains at least a non variable symbol,

• if two occurrences x ′ and x ′′ of a same variable x occur in ui, D(x ′ , x", ui) < k.

Remark that LCF is included in H and that there is no right hand side of rule with two occurrences of the same variable associated with the same state. Prove that 1. LCF -1 ⊆ Delabeling -1 • H Proof. We consider w.l.o.g. automata with only one initial state. Given A 1 and A 2 , with a disjoint set of states, we compute an automaton A whose states are those of A 1 and A 2 and one additional state q 0 . Transitions are those of A 1 and A 2 plus the additional transitions for the union:

where q 0 1 , q 0 2 are the initial states of A 1 and A 2 respectively. For the intersection, we add instead the transitions:

Concerning the complement, we simply exchange ∧ and ∨ (resp. true and false) in the transitions. The resulting automaton A will be called the dual automaton in what follows.

The proof that these constructions are correct for union and intersection are left to the reader. Let us only consider here the complement.

We prove, by induction on the size of t that, for every state q, t is accepted either by A or A in state q and not by both automata.

If t is a constant a, then δ(q, a) is either true or false. If δ(q, a) = true, then δ(q, a) = false and t is accepted by A and not by A. The other case is symmetric.

Assume now that t = f (t 1 , . . . , t n ) and δ(q, f ) = φ. Let S be the set of pairs (q j , i j ) such that t ij is accepted from state q j by A.

. By induction hypothesis, (q j , i) ∈ S iff t i is accepted in state q j by A.

We show that S |= φ iff S |= φ. ( φ is the dual formula, obtained by exchanging ∧ and ∨ on one hand and true and false on the other hand in φ). We show this by induction on the size of φ: if φ is true (resp. false), then S |= φ and S |= φ (resp. S = ∅) and the result is proved. Now, let, φ be, e.g., φ 1 ∧ φ 2 . S |= φ iff either S |= φ 1 or S |= φ 2 , which, by induction hypothesis, is equivalent to S |= φ 1 or S |= φ 2 . By construction, this is equivalent to S |= φ. The case φ = φ 1 ∨ φ 2 is similar. Now t is accepted in state q by A iff S |= φ iff S |= φ iff t not accepted in state q by A.

From Alternating to Deterministic Automata

The expressive power of alternating automata is exactly the same as finite (bottom-up) tree automata.

Theorem 7.4.1. If A is an alternating tree automaton, then there is a finite deterministic bottom-up tree automaton A ′ which accepts the same language. A ′ can be computed from A in deterministic exponential time.

and δ is defined as follows:

.3: The Dolev-Yao intruder capabilities 7.6.5 Two Way Automata and Pushdown Automata Two-way automata, though related to pushdown automata, are quite different. In fact, for every pushdown automaton, it is easy to construct a two-way automaton which accepts the possible contents of the stack (see Exercise 7.5). However, two-way tree (resp. word) automata have the same expressive power as standard tree (resp. word) automata: they only accept regular languages, while pushdown automata accept context-free languages, which strictly contain regular languages.

Note still that, as a corollary of Theorem 7.6.3, the language of possible stack contents in a pushdown automaton is regular.

An (other) example of application

Two-way automata naturally arise in the analysis of cryptographic protocols. In this context, terms are constructed using the function symbols { } (binary encryption symbols), < , > (pairing) and constants (and other symbols which are irrelevant here). The so-called Dolev-Yao model consists in the deduction rules of Figure 7.3, which express the capabilities of an intruder. For simplicity, we only consider here symmetric encryption keys, but there are similar rules for public key cryptosystems. The rules basically state that an intruder can encrypt a known message with a known key, can decrypt a known message encrypted with k, provided he knows k and can form and decompose pairs.

It is easy to construct a two-way automaton which, given a regular set of terms R, accepts the set of terms that can be derived by an intruder using the rules of Figure 7.3 (see Exercise 7.6).

Exercises

Exercise 7.1. Show that, for every alternating tree automaton, it is possible to compute in polynomial time an alternating tree automaton which accepts the same language and whose transitions are in disjunctive normal form, i.e. each transition has A projection is mapping h : Σ → Σ ′ . This mapping is extended to trees by applying it to each node label, i.e. we can view it as a function h : T (Σ) → T (Σ ′ ). On the level of sets of trees we look at h and its inverse, defined as

From the results in Section 1.4 we can easily derive the following.

Theorem 8.3.9. The class of recognizable unranked tree languages is closed under projections and inverse projections.

Weak Monadic Second Order Logic

Connections between automata and logic are a valuable tool for developing decision procedures for the logics under consideration. Furthermore, a robust logic which is equivalent to automata in expressive power can serve as a yardstick for the expressiveness of query languages.

In Section 3.3 we have seen a logical characterization of recognizable tree languages using the logic WSkS. In this section we present a similar logic for unranked trees. In WSkS one can directly access the ith successor of a node x by the term xi. For unranked trees this would lead to an infinite vocabulary, and as each formula can only use finitely many symbols it would not even be possible to write a single formula stating that two nodes have the same parent.

To avoid this problem we introduce the two binary relations child(x, y) and next-sibling(x, y) interpreted as "y is a child of x" and "y is the next sibling to the right of x", respectively. The first-order elements are now interpreted as strings over N * (as opposed to {1, . . . , k} * for WSkS). The semantics of the relations is the following:

• ∀p, p ′ ∈ N * , child(p, p ′ ) iff p ′ = pi for some i ∈ N ,

• ∀p, p ′ ∈ N * , next-sibling(p, p ′ ) iff there is p ′′ ∈ N * with p = p ′′ i, p ′ = p ′′ j for some i, j ∈ N with j = i + 1.

We now consider standard weak monadic second-order logic (WMSO) over this signature. We use first-order variables x, y, . . . interpreted by elements of N * , and monadic second-order variables X, Y, . . . interpreted by finite subsets of N * (similar to WSkS). WMSO-formulas are built from the atomic formulas x = y, x ∈ X, child(x, y), and next-sibling(x, y) by the logical connectives ∧, ∨, ¬, ⇒, etc., and by quantification over elements and finite sets of elements. We do not give a formal definition of the semantics because it is defined along the same lines as for WSkS.

Example 8.4.1. The following formula defines the right-sibling relation, i.e. the relation stating that x and y are siblings and that y is to the right of x. The formula right-sibling(x, y) is defined as follows:

In the same way it is possible to define the descendant relation, where descendant(x, y) is true if x is above y in the tree, i.e. x is a prefix of y.

Generic Algorithm for Uniform Membership input

.6: A generic algorithm for solving the uniform membership problem for hedge automata a generic algorithm that constructs for a given NFHA A = (Q, Σ, Q f , ∆) and a tree t a mapping ρ : Pos(t) → 2 Q labeling each p ∈ Pos(t) with the set M of those states that are reachable at p in a run of A on t. For this purpose, the algorithm picks a position p such that all its successor positions are already labeled by ρ and then checks for each transition a(R) → q with a = t(p) if it can be applied to some string that is obtained by picking for each successor one state. Note that that the algorithm starts at the leaves because in this case k = 0.

The only thing that might be non-polynomial in this algorithm is testing the condition in the if-statement inside the foreach-loop. In a naive implementation one would have to test all possible combinations of sequences q 1 • • • q k of states, which are exponentially many in general. But for some representations of the horizontal languages there are more efficient ways to check for the existence of a suitable sequence q 1 • • • q k . Theorem 8.5.6. The uniform membership problem for hedge automata has the following complexity, depending on the type of the given automaton:

(1) For NFHA(NFA) it is in PTIME.

(2) For DFHA(DFA) it is solvable in linear time.

(3) For NFHA(AFA) it is NP-complete. (4) For DFHA(AFA) it is in PTIME.

(5) For NFHA(RE ) it is NP-complete.

Proof. We use the generic algorithm for showing (1), (2), and (4). As already mentioned, we mainly have to pay attention to the condition tested in the ifstatement.

Document Type Definition (DTD)

A Document Type Definition (DTD) basically is a context-free (CF) grammar with regular expressions on the right-hand sides of the rules. The tree language defined by the DTD consists of all the derivation trees of this grammar. In Chapter 2 it is shown that for a standard CF grammar the set of derivation trees forms a regular tree language. This easily extends to the unranked setting. An attempt to formalize by a DTD the requirements on documents describing conference programs that are listed in the introduction to this section could look as follows The symbols used in the expressions on the right-hand side of the rules are interpreted as follows: | = choice + = one or more occurrences , = sequence ? = one or zero occurrences All the other element declarations that are missing (for authors, speaker, etc.) are assumed to be #PCDATA ("parsed character data"), which for our purpose simply denotes arbitrary character sequences coding the data inside the document.

The corresponding grammar looks as follows:

In the terminology of XML the right-hand side of a rule is also called the content model.

In this setting a DTD is tuple D = (Σ, s, δ) with a start symbol s ∈ Σ and a mapping δ assigning to each symbol from Σ a regular expression over Σ.

The easiest way to define the language generated by a DTD is to interpret it as a hedge automaton with the set of states being the same as the alphabet:

It is obvious that A D is a DFHA. We define the language L(D) defined by D to be the language L(A D ).

Proposition 8.7.9. The uniform membership and the emptiness problem for EDTDs are solvable in polynomial time.

In the next subsection we use EDTDs to describe the expressive power of XML Schema.

XML Schema

XML Schema is a formalism close to EDTDs. We present here only small code fragments to show how the extension of the conference example by invited sessions and contributed sessions from Example 8.7.7 can be formalized. The main point is that in XML schema it is possible to define types and that elements (that is, the tree labels) are allowed to have the same name but a different type in different contexts, as for EDTDs.

Lets come back to Example 8.7.7. With the EDTD from the example in mind, the syntax should be self explanatory. We directly start with the definition of tracks, the definition for the conference is similar. <xsd:complexType name="track"> <xsd:sequence minOccurs="1" maxOccurs="unbounded"> <xsd:choice> <xsd:element name="invSession" type="invSession" minOccurs="1" maxOccurs="1"/> <xsd:element name="conSession" type="conSession" minOccurs="1" maxOccurs="1"/> </xsd:choice> <xsd:element name="break" type="xsd:string" minOccurs="0" maxOccurs="1"/> </xsd:sequence> </xsd:complexType>

The two types of sessions can be defined as follows.

<xsd:complexType name="invSession"> <xsd:sequence> <xsd:element name="chair" type="xsd:string" minOccurs="1" maxOccurs="1"/> <xsd:element name="talk" type="invTalk" minOccurs="1" maxOccurs="1"/> </xsd:sequence> </xsd:complexType> <xsd:complexType name="conSession"> <xsd:sequence> <xsd:element name="chair" type="xsd:string" minOccurs="1" maxOccurs="1"/> <xsd:element name="talk" type="conTalk" minOccurs="1" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> Note that in both definitions we use the name talk for the element but we assign different types. The types invTalk and conTalk correspond to the types talk (1) and talk (2) in the EDTD from Example 8.7.7. A contributed session can contain more than one talk (maxOccurs = "unbounded") but invited sessions can have only one talk.

What remains is the definition of the two types of talks:

<xsd:complexType name="invTalk"> <xsd:sequence> <xsd:element name="title" type="xsd:string" minOccurs="1" maxOccurs="1"/> <xsd:element name="speaker" type="xsd:string" minOccurs="1" maxOccurs="1"/> </xsd:sequence> </xsd:complexType> <xsd:complexType name="conTalk"> <xsd:sequence> <xsd:element name="title" type="xsd:string" minOccurs="1" maxOccurs="1"/> <xsd:element name="authors" type="xsd:string" minOccurs="1" maxOccurs="1"/> </xsd:sequence> </xsd:complexType> Without any further restrictions this typing mechanism would give the full power of hedge automata (see Proposition 8.7.8). But the XML schema specification imposes a constraint called "Element Declarations Consistent", which basically requires that elements with the same name that appear in the same content model have to have the same type.

Assume, for example, that we do not want to distinguish the invited and contributed sessions by two different names. But we keep the restriction that a session consists of a single invited talk or a sequence of contributed talks, as expressed with the following code: <xsd:complexType name="track"> <xsd:sequence minOccurs="1" maxOccurs="unbounded"> <xsd:choice> <xsd:element name="session" type="invSession" minOccurs="1" maxOccurs="1"/> <xsd:element name="session" type="conSession" minOccurs="1" maxOccurs="1"/> </xsd:choice> <xsd:element name="break" type="xsd:string" minOccurs="0" maxOccurs="1"/> </xsd:sequence> </xsd:complexType> This code is not valid in XML schema because it does not satisfy the "Element Declarations Consistent" constraint: In the choice construct two elements with the same name session occur but they have different types.