Thomas Place

Luc Segoufin

DECIDING DEFINABILITY IN FO 2 (< v , < h ) ON TREES

Keywords: Tree Languages, Tree Automata, Two-Variables First-Order Logic, Characterization

We provide a decidable characterization of regular forest languages definable in FO 2 (<v, < h ). By FO 2 (<v, < h ) we refer to the two variable fragment of first order logic built from the descendant relation and the following sibling relation. In terms of expressive power it corresponds to a fragment of the navigational core of XPath that contains modalities for going up to some ancestor, down to some descendant, left to some preceding sibling, and right to some following sibling.

We also show that our techniques can be applied to other two variable first-order logics having exactly the same vertical modalities as FO 2 (<v, < h ) but having different horizontal modalities.

Introduction

Logics for expressing properties of labeled trees and forests figure importantly in several different areas of Computer Science. This paper is about logics on finite unranked trees. The most prominent one is monadic second-order logic (MSO) as it can be captured by finite tree automata. All the logics we consider are less expressive than monadic secondorder logic. Even with these restrictions, this encompasses a large body of important logics, such as variants of first-order logic, temporal logics including CTL * or CTL, as well as query languages used for XML data.

This paper is part of a research program devoted to understanding and comparing the expressive power of such logics.

We say that a logic has a decidable characterization if the following problem is decidable: given as input a finite tree automaton (or equivalently a formula of MSO), decide if the recognized language is definable by the logic in question. Usually a decidable characterization requires a solid understanding of the expressive power of the corresponding logic as witnessed by decades of research, especially for logics for strings. The main open problem in this research program is to find a decidable characterization of FO(< v ), the first-order logic using a binary predicate < v for the ancestor relation.

In this paper we work with unranked ordered trees and by FO(< v , < h ) we refer to the logic that has two binary predicates, one for the descendant relation, one for the following sibling relation. We investigate an important fragment of FO(< v , < h ), its two variable restriction denoted FO 2 (< v , < h ). This is a robust formalism that, in terms of expressive power, has an equivalent counterpart in temporal logic. This temporal counterpart can be seen as the fragment of the navigational core of XPath that does not use the successor axis [START_REF] Marx | First order paths in ordered trees[END_REF]. More precisely, it corresponds to the temporal logic EF + F -1 (F h , F h -1 ) that navigates in the tree using two "vertical" modalities, one for going to some ancestor node (F -1 ) and one for going to some descendant node (EF), and two "horizontal" modalities for going to some following sibling (F h ) or some preceding sibling (F h -1 ). We provide a characterization of FO 2 (< v , < h ), or equivalently EF + F -1 (F h , F h -1 ), over unranked ordered trees. We also show that this characterization is decidable. Since FO 2 (< v , < h ) can express the fact that a tree has rank k for any fix number k, our result also applies to ranked trees.

Our characterization is stated using closure properties expressed partly using identities that must be satisfied by the syntactic forest algebra of the input regular language, and partly via a mechanism that we call saturation.

Here, a forest algebra is essentially a pair of finite semigroups, the "horizontal" semigroup for forest types and the "vertical" semigroup for context types, together with an action of contexts over forests. It was introduced in [START_REF] Miko | Forest algebras[END_REF], using monoids instead of semigroups, and is a formalism for recognizing forest languages whose expressive power is equivalent to definability in MSO. Given a formula of MSO, one can compute its syntactic forest algebra, which recognizes the set of forests satisfying the formula. Hence any characterization based on a finite set of identities over the syntactic forest algebra can be tested effectively when given a regular language as long as each identity can be effectively tested, which will always be the case in this paper.

The syntactic forest algebra was used successfully for obtaining decidable characterizations for the classes of tree languages definable in EF + EX -1 [START_REF] Miko | Characterizing EF and EX tree logics[END_REF], EF + F -1 [Boj09], BΣ 1 (< v ) [START_REF] Miko Laj Bojańczyk | Piecewise testable tree languages[END_REF] and ∆ 2 (< v ) [START_REF] Miko | Tree languages defined in first-order logic with one quantifier alternation[END_REF]. Here EF + EX -1 is the class of languages definable in a temporal logic that navigates in trees using two vertical modalities, EF, that we have already seen before, and EX, which goes to a child of the current node. EF + F -1 is the class of languages definable in EF + F -1 (F h , F h -1 ) without using the horizontal modalities. BΣ 1 (< v ) stands for the class of languages definable by a Boolean combination of existential formulas of FO(< v ) and ∆ 2 (< v ) is the class of languages definable in FO(< v ) by both a formula of the form ∃ * ∀ * and a formula of the form ∀ * ∃ * .

Over strings, the logics induced by ∆ 2 (<), FO 2 (<) and F+ F -1 , have exactly the same expressive power [START_REF] Etessami | First-order logic with two variables and unary temporal logic[END_REF][START_REF] Thérien | Over words, two variables are as powerful as one quantifier alternation[END_REF]. But over trees this is not the case. For instance EF + F -1 is closed under bisimulation while the other two are not. While decidable characterizations were obtained for EF + F -1 and ∆ 2 (< v ) [START_REF] Miko | Two-way unary temporal logic over trees[END_REF][START_REF] Miko | Tree languages defined in first-order logic with one quantifier alternation[END_REF], the important case of FO 2 (< v , < h ) was still missing and is solved in this paper.

Over strings, a regular language is definable in FO 2 (<) iff its syntactic semigroup satisfies an identity that can be effectively tested [START_REF] Thérien | Over words, two variables are as powerful as one quantifier alternation[END_REF]. Not surprisingly our first set of identities requires that the horizontal and vertical semigroups of the syntactic forest algebra both satisfy this identity. Our extra property is more complex and mixes at the same time the vertical and horizontal navigational power of FO 2 (< v , < h ). We call it closure under saturation.

It is immediate from the string case that being definable in FO 2 (< v , < h ) implies that the vertical and horizontal semigroups of the syntactic forest algebra satisfy the required identity. That closure under saturation is also necessary is proved via a classical, but tedious, Ehrenfeucht-Fraïssé game argument. As usual in this area, the difficulty is to show that the closure conditions are sufficient. In order to do so, as it is standard when dealing with FO 2 (< v , < h ) (see e.g. [Boj09, BS10, TW98]), we introduce Green-like relations for comparing elements of the syntactic algebra. However, in our case, we parametrize these relations with a set of forbidden patterns: the contexts authorized for going from one type to another type cannot use any of the forbidden pattern. We are then able to perform an induction using this set of forbidden patterns, thus refining our comparison relations more and more until they become trivial.

Our proof has many similarities with the one of Bojańczyk that provides a decidable characterization for the logic EF + F -1 [Boj09] and we reuse several ideas developed in this paper. However it departs from it in many essential ways. First of all the closure under bisimulation of EF + F -1 was used in [START_REF] Miko | Two-way unary temporal logic over trees[END_REF] in an essential way in order to compute a subalgebra and perform inductions on the size of the algebra. Moreover, because EF + F -1 does not have horizontal navigation, Bojańczyk was able to isolate certain labels and then also perform inductions on the size of the alphabet. It is the combination of the induction on the size of the alphabet and on the size of the algebra that gave an elegant proof of the correctness of the identities for EF + F -1 given in [START_REF] Miko | Two-way unary temporal logic over trees[END_REF]. The logic FO 2 (< v , < h ) is no longer closed under bisimulation and we were not able to perform an induction on the algebra. Moreover because our logic has horizontal navigation, it is no longer possible to isolate the label of a node from the labels of its siblings, hence it is no longer possible to perform an induction on the size of the alphabet. In order to overcome these problems our proof replaces the inductions used in [START_REF] Miko | Two-way unary temporal logic over trees[END_REF] by an induction on the set of forbidden patterns. This makes the two proofs technically fairly different.

It turns out that our proof technique applies to various horizontal modalities. In the final section of the paper we show how to adapt the characterization obtained for FO 2 (< v , < h ) in order to obtain characterizations for EF + F -1 (X h , F h , X h -1 , F h -1 ), EF + F -1 (S) and EF + F -1 (S = ), where X h , X h -1 , S and S = are horizontal navigational modalities moving respectively to the next sibling, previous sibling, an arbitrary sibling including the current node, or an arbitrary different sibling excluding the current node.

Other related work. Our characterization is essentially given using forest algebras. There exist several other formalisms that were used for providing characterizations of logical fragments of MSO (see e.g. [BS09, PS11, Wil96, ÉW05]). It is not clear however how to use these formalisms in order to provide a characterization of FO 2 (< v , < h ).

There exist decidable characterizations of EF + F -1 and ∆ 2 (< v ) over trees of bounded rank [START_REF] Place | Characterization of logics over ranked tree languages[END_REF]. But, as these logics cannot express the fact that a tree is binary, the unranked and bounded rank characterizations are different. As mentioned above, we don't have this problem with FO 2 (< v , < h ).

Organization of the paper. We first provide the preliminary definitions in Section 2. The main definitions and their basic properties are described in Section 5. Our characterization is stated in Section 6. That our properties are necessary for being definable in FO 2 (< v , < h ) is proved in Section 7. We give the proof that our characterization for FO 2 (< v , < h ) is sufficient in Section 8. Decidability of closure under saturation is not immediate and Section 9 is devoted to this issue. In Section 10 we show how to adapt the arguments in order to characterize several other horizontal navigation modalities.

Note that Section 7, Section 8 and Section 9 can be read in an arbitrary order.

This paper is the journal version of [START_REF] Place | Deciding definability in FO2(<) (or XPath) on trees[END_REF]. From the conference version the statement of the characterization has been slightly changed and the proofs have been significantly modified in order to simplify the presentation.

Preliminaries

We work with finite unranked ordered trees and forests labeled over a finite alphabet A. A finite alphabet is a pair A = (A, B) where A and B are finite sets of labels. We use A to label leaves and B to label inner nodes. Making the distinction between leaves and inner nodes labels makes our presentation slightly simpler without harming the generality of our results. Given a finite alphabet A = (A, B), trees and forests are defined inductively as follows: for any a ∈ A, a is a tree. If t 1 , • • • , t k is a finite non-empty sequence of trees then t 1 + • • • + t k is a forest. If s is a forest and b ∈ B, then b(s) is a tree. Notice that we do not consider empty trees nor empty forests. A set of trees (forests) over a finite alphabet A is called a tree language (forest language).

We use standard terminology for trees and forests defining nodes, ancestors, descendants, following and preceding siblings. We write x < v y to say that x is a strict ancestor of y or, equivalently, that y is a strict descendant of x. We write x < h y to say that x is a strict preceding sibling of y or, equivalently, that y is a strict following sibling of x.

A context is a forest over (A ∪ {2}, B) with a single leaf of label 2 that cannot be a root and that has no sibling. This distinguished node is called the port of the context (see Figure 1). This definition is not standard as usually contexts are defined without the "no sibling" restriction but it is important for this paper to work with this non-standard definition. If c is a context, the path in c containing all the ancestors of its port is called the backbone of c.

A context c can be composed with another context c or with a forest s in the obvious way by substituting c or s in place of the port of c. This composition yields either the context cc or the forest cs. If x is a node of a forest then the subtree at x is the tree rooted at x. The subforest of x is the forest consisting of all the subtrees that are rooted at siblings of x (including x). Finally, if x is not a leaf, the subforest below x is the forest consisting of all the subtrees that are rooted at children of x, see Figure 2. Notice that from the definitions if follows that s is a subforest of a forest t iff there exists a context c such that t = cs. In particular if we consider the forest b(a 1 + a 2 + a 3 ), A forest can be seen as a relational structure. The domain of the structure is the set of nodes. The signature contains a unary predicate P a for each symbol a ∈ A plus the binary predicates < v and < h . By MSO(< v , < h ) we denote the monadic second order logic over this relational signature. We use the classical semantics for MSO(< v , < h ) and write s |= φ(ū) if the formula φ is true on s when interpreting its free variables with the corresponding nodes of ū. As usual, each sentence ϕ of MSO(< v , < h ) defines a forest language L ϕ = {s | s |= ϕ}. A language defined in MSO(< v , < h ) is called a regular language.

b c a 1 a 1 c b a 2 a 2 b a c k b o n e Context b c a 1 a 1 c b a 1 a 2 a 2

Not a Context

a 1 + a 2 + a 3 is a subforest but not a 1 + a 2 . b b d c d a 1 a 1 a 2 a 3 a 3 a 1 a 2 a 3 x ⇒ { Subtree at x d a 1 a 2 a 3 Subforest of x b d c d a 1 a 1 a 2 a 3 a 3 a 1 a 2 a 3 Subforest below x a 1 a 2 a 3
As usual regular languages form a robust class of languages and there is a matching notion of unranked ordered forests automata (see for instance [CDG + , chapter 8]). We will see in Section 4 a corresponding notion of recognizability using forest algebras. The logic of interest for this paper is FO 2 (< v , < h ), the two variable restriction of the first-order fragment of MSO(< v , < h ).

In terms of expressive power, FO

2 (< v , < h ) is equivalent to EF + F -1 (F h , F h -1
), a temporal logic that we now describe. Essentially,

EF + F -1 (F h , F h -1
) is the restriction of the navigational core of XPath without the child, parent, next-sibling and previoussibling predicates. It is defined using the following grammar:

ϕ :: A | ϕ ∨ ϕ | ϕ ∧ ϕ | ¬ϕ | EFϕ | F -1 ϕ | F h ϕ | F -1 h ϕ
We use the classical semantics for this logic which defines when a formula holds at a node x of a forest s. In particular, EFϕ holds at x if there is a strict descendant of x where ϕ holds, F -1 ϕ holds at x if there is a strict ancestor of x where ϕ holds, F h ϕ holds at x if ϕ holds at some strict following sibling of x, and F -1 h ϕ holds at x if ϕ holds at some strict preceding sibling of x. We then say that a forest s satisfies a formula φ if φ holds at the root of the first tree of s. The following result is immediate from [START_REF] Marx | First order paths in ordered trees[END_REF]:

Theorem 3.1. For any FO 2 (< v , < h ) formula φ(x), there exists a EF + F -1 (F h , F h -1
) formula ϕ holding true on the same set of nodes for every forests. In particular a forest language is definable in

FO 2 (< v , < h ) iff it is definable in EF + F -1 (F h , F h -1 ).
We aim at providing a decidable characterization of regular forest languages definable in FO 2 (< v , < h ). This means finding an algorithm that decides whether or not a given regular forest language is definable in FO 2 (< v , < h ).

Note that FO 2 (< v , < h ) is expressive enough to test whether a forest is a tree and, for each k whether it has rank k. Hence any result concerning forest languages definable in FO 2 (< v , < h ) also applies to tree languages definable in FO 2 (< v , < h ) and covers the ranked and unranked cases.

We shall mostly adopt the EF + F -1 (F h , F h -1 ) point of view as it is useful when considering other horizontal modalities or when making comparisons with the decision algorithm obtained for EF + F -1 in [START_REF] Miko | Two-way unary temporal logic over trees[END_REF].

3.2. Ehrenfeucht-Fraïssé Games. As usual definability in FO 2 (< v , < h ) corresponds to winning strategies in a Ehrenfeucht-Fraïssé game that we briefly describe here. We adopt the EF + F -1 (F h , F h -1 ) point of view as the corresponding game is slightly simpler. Its definition is standard.

There are two players, Duplicator and Spoiler. The board consists in two forests and the number k of rounds is fixed in advance. At any time during the game there is one pebble placed on a node of one forest and one pebble placed on a node of the other forest and both nodes have the same label. If the initial position is not specified, the game starts with the two pebbles placed on the root of the leftmost tree in each forest. Each round starts with Spoiler moving one of the pebbles inside its forest, either to some ancestor of its current position, or to some descendant or to some left or right sibling. Duplicator must respond by moving the other pebble inside the other forest in the same direction to a node of the same label. If during a round Duplicator cannot move then Spoiler wins the game. If Duplicator was able to respond to all the moves of Spoiler then she wins the game. Winning strategies are defined as usual. If Duplicator has a winning strategy for the game played on the forests s, t then we say that s and t are k-equivalent.

The following results on games are classical and simple to prove.

Lemma 3.2 (Folklore).

(1) For every k, k-equivalence is an equivalence relation of finite index.

(2) For every k, each class of the k-equivalence relation is definable by a sentence of

EF + F -1 (F h , F h -1
) such that the nesting depth of its navigational modalities is bounded by k.

(3) For every k, if s and t are k-equivalent then they satisfy the same sentences of

EF + F -1 (F h , F h -1
) such that the nesting depth of their navigational modalities is bounded by k.

When played on words instead of forests, the game is the same except that now Spoiler can move either to a previous or to a following position. The results are identical after replacing FO 2 (< v , < h ) with FO 2 (<), the two variable first-order logic on strings, using the predicate < for the following position relation.

Antichain Composition Principle.

As mentioned in the introduction, we use induction to prove that if L satisfies the characterization then we can construct a FO 2 (< v , < h ) formula for L. At each step in this construction, we prove that L can be defined as the composition of simpler languages such that a formula for L can be constructed from formulas defining the simpler languages. This is what we do with the following simple composition lemma, essentially adapted from [START_REF] Miko | Two-way unary temporal logic over trees[END_REF] and using the same terminology.

A formula of FO 2 (< v , < h ) with one free variable is called antichain if in every forest, the set of nodes where it holds forms an antichain, i.e. a set (not necessarily maximal) of nodes pairwise incomparable with respect to the descendant relation. This is a semantic property that may not be apparent just by looking at the syntax of the formula. A typical antichain formula selects in a forest the set of nodes of label b ∈ B that have no ancestor of label b.

Given (i) an antichain formula ϕ, (ii

) disjoint forest languages L 1 , • • • , L n and (iii) labels a 1 , • • • , a n ∈ A and (iv) a forest s, we define the forest s = s[(L 1 , ϕ) → a 1 , • • • , (L n , ϕ) → a n ]
as follows. For each node x of s such that s |= ϕ(x), we determine the unique i such that the forest language L i contains the subforest below x. If such an i exists, we remove the whole subforest below x, and replace it by a leaf of label a i . Since ϕ is antichain, this can be done simultaneously for all x. Note that the formula ϕ may also depend on ancestors of x, while the languages L i only talk about the subforest below x.

The composition method that we will use is summarized in the the following lemma:

Lemma 3.3. [Antichain Composition Lemma] Let ϕ , L 1 , .
. . , L n and a 1 , . . . , a n be as above. If L 1 , . . . , L n and K are languages definable in FO 2 (< v , < h ), then so is

L = {t | t[(L 1 , ϕ) → a 1 , • • • , (L n , ϕ) → a n ] ∈ K}.
This lemma follows from a simple Ehrenfeucht-Fraïssé game argument. Using the

EF + F -1 (F h , F h -1
) point of view we can also construct a formula defining L. The formula for L is obtained from the one for K by restricting all navigation to nodes that are not descendants of nodes satisfying ϕ and by replacing each test that a label is a i by the formula for L i where all navigations are now restricted to nodes that are descendants of a node that satisfies ϕ. The fact that ϕ is antichain makes this construction sound. The details are simple and are omitted here as they paraphrase those given in [START_REF] Miko | Two-way unary temporal logic over trees[END_REF] for EF + F -1 .

The inductive step of our proof consists in exhibiting L 1 , . . . , L n and K, together with an antichain formula ϕ such that

L = {t | t[(L 1 , ϕ) → a 1 , • • • , (L n , ϕ) → a n ]
∈ K} and K, L 1 , . . . , L n have smaller inductive parameters than L. In [START_REF] Miko | Two-way unary temporal logic over trees[END_REF] the antichain formula is of the form: "select the set of nodes of label b ∈ B that have no ancestor of label b." Observe that such a formula allows us to use the size of B as an induction parameter as K does not contain the label b. In our case, we replace B by sibling patterns that we will define in Section 5.

Forest algebras

A key ingredient in our characterization is based on syntactic forest algebras. Forest algebras were introduced by Bojańczyk and Walukiewicz as an algebraic formalism for studying regular forest languages [START_REF] Miko | Forest algebras[END_REF]. We work with the semigroup variant of forest algebras. Moreover we require that the port of each context has no sibling. These restrictions are necessary as, without them, the languages definable in FO 2 (< v , < h ) would not form a variety, i.e. would not be characterizable by its syntactic forest algebra only.

We give a brief summary of the definition of forest algebras and of their important properties. More details can be found in [START_REF] Miko | Forest algebras[END_REF]. A forest algebra consists of a pair (H, V ) of finite semigroups, subject to some additional requirements, which we describe below. We write the operation in V multiplicatively and the operation in H additively, although H is not assumed to be commutative.

We require that V acts on the left of H. That is, there is a map

(h, v) ∈ H × V → vh ∈ H
such that w(vh) = (wv)h for all h ∈ H and v, w ∈ V . We further require that for every g ∈ H and v ∈ V , V contains elements (v + g) and (g + v) such that

(v + g)h = vh + g, (g + v)h = g + vh for all h ∈ H.
Let A = (A, B) be a finite alphabet. The free forest algebra on A, denoted by A , is the pair of semigroups (H A , V A ) where H A is the set of forests over A equipped with the + operation and V A the set of contexts equipped with the composition operation, together with the natural action. One can verify that this action turns A into a forest algebra.

A morphism α :

(H 1 , V 1 ) → (H 2 , V 2 ) of forest algebras is a pair (γ, δ) of semigroup morphisms γ : H 1 → H 2 , δ : V 1 → V 2 such that γ(vh) = δ(v)γ(h) for all h ∈ H, v ∈ V.
However, we will abuse notation slightly and denote both component maps by α.

We say that a forest algebra (H, V ) recognizes a forest language L if there is a morphism α : A → (H, V ) and a subset X of H such that L = α -1 (X). We also say that the morphism α recognizes L. It is easy to show that a forest language is regular if and only if it is recognized by a finite forest algebra.

Consider some forest language L over an alphabet A. We define an equivalence relation ∼ L over contexts and over forests. Given two forests t 1 , t 2 , we say that t 1 ∼ L t 2 iff for any two forests s, s and any context c, c(s + t 1 + s ) ∈ L iff c(s + t 2 + s ) ∈ L. Given two contexts c 1 , c 2 we say that c 1 ∼ L c 2 iff for any forest s, c 1 s ∼ L c 2 s. This equivalence is a congruence of forest algebras that is of finite index iff L is regular. The quotient of A by this congruence yields a forest algebra recognizing L which we call the syntactic forest algebra of L. The mapping sending a forest or a context to its equivalence class in the syntactic forest algebra, denoted α L , is a morphism called the syntactic morphism of L.

It is also important to know that given an MSO(< v , < h ) sentence φ, the syntactic forest algebra of L φ and the syntactic morphism α φ can be computed from φ.

Idempotents. It follows from standard arguments of semigroup theory that given any finite semigroup S, there exists a number ω(S) (denoted by ω when S is understood from the context) such that for each element x of S, x ω is an idempotent: x ω = x ω x ω . Given a forest algebra (H, V ) we will denote by ω(H, V ) (or just ω when (H, V ) is understood from the context) the product of ω(H) and ω(V ) and for any element u ∈ V and g ∈ H we will write u ω and ωg for the corresponding idempotents.

Finally, given a semigroup S we will denote by S 1 the monoid formed from S by adding a neutral element.

Leaf Surjective Morphisms. Let A = (A, B) be a finite alphabet and let α : A → (H, V ) be a morphism into a finite forest algebra (H, V ). We say that α is leaf surjective iff for any h ∈ H, there exists a ∈ A such that α(a) = h.

Observe that given any morphism α : (A, B) → (H, V ), one can construct a leaf surjective one β : (A ∪ H, B) → (H, V ) by extending α in the obvious way. We call β the leaf completion of α.

Lemma 4.1. Let α : A → (H, V ) be a morphism into a finite forest algebra, β be its leaf completion and h ∈ H be such that

β -1 (h) is FO 2 (< v , < h ) definable. Then α -1 (h) is FO 2 (< v , < h ) definable.
Proof. A forest in α -1 (h) is a forest in β -1 (h) that contains no leaf with label in H. Therefore, one can construct an FO 2 (< v , < h ) formula for α -1 (h) from a formula for β -1 (h).

Working with leaf surjective morphisms will be convenient for us. Typically when applying the Antichain Composition Lemma we will construct K from L by replacing some subforests of L by leaf nodes with the same forest type. It is therefore important that such nodes exist.

The string case. A reason for using syntactic forest algebras is that the same problem for strings was solved using syntactic semigroups. In the string case there is only one linear order and the corresponding logic is denoted by FO 2 (<). Recall that the syntactic semigroup (monoid) of a regular string language is the transition semigroup (monoid) of its minimal deterministic automata. It is therefore computable from any reasonable presentation of the regular string language. The following characterization was actually stated using syntactic monoids, but it is equivalent to this statement 1 .

Theorem 4.2 ([TW98]

). A regular string language is definable in FO 2 (<) iff its syntactic semigroup S satisfies for all u, v ∈ S:

(uv) ω v(uv) ω = (uv) ω
Unfortunately in the case of forest languages we were not able to state our characterization using only the syntactic forest algebra of the input regular language. We will need an extra ingredient that we call saturation.

Shallow multicontexts

In this section, we define shallow multicontexts which represent sequences of siblings. We will often manipulate shallow multicontexts modulo FO 2 (< v , < h ) definability. This is captured by an equivalence relation on shallow multicontexts that we also define in this section.

This notion of shallow multicontext is central for this paper as we will use it not only as a parameter in the inductive argument but also to define the notion of saturation that we use in our characterization of FO 2 (< v , < h ).

Set A = (A, B) as a finite alphabet. All definitions are parametrized by a morphism α : A → (H, V ). Note that while the definitions make sense for any morphism α, they are designed to be used with a leaf surjective one. Given a forest s (a context p) we refer to its image under α as the forest type of s (the context type of p).

1 We are actually not using the identity of [START_REF] Thérien | Over words, two variables are as powerful as one quantifier alternation[END_REF]. Ours can easily seen to be equivalent to it. This is a folklore result. A proof can be found in [START_REF] Kufleitner | Logical Fragments for Mazurkiewicz Traces: Expressive Power and Algebraic Characterizations[END_REF].

Shallow multicontexts.

A multicontext is defined in the same way as a context but with several ports, possibly none. The arity of a multicontext is the number of its ports, possibly 0. Note that as our forests are ordered, each multicontext implicitly defines a linear order on its ports. A multicontext is said to be shallow if each of its trees is either a single node a ∈ A, a single inner node with a port below, b(2), or a tree of the form b(a) where b ∈ B and a ∈ A (see Figure 3).

For technical reasons we do not consider forests with a single tree of the form a ∈ A as a shallow multicontext. Observe that in our definition of shallow multicontext we include trees of the form b(a). This is because, as mentioned earlier, we will often replace a subforest by a node having the same type and therefore it is convenient to immediately have access to this type by looking at the label of that node. Let x be a node of a forest s. Let t = t 1 + • • • + t be the subforest of x, composed of trees. The shallow multicontext of x in s is the sequence

p 1 + • • • + p such that p i := a if t i = a ∈ A, p i := b(a) if t i = b(a), and p i := b(2) if t i = b(s ), where a ∈ A, b ∈ B and s / ∈ A.
A shallow multicontext p occurs in a forest s iff there exists a node x of s such that p is the shallow multicontext of x in s. In the rest of the paper, a node x will almost always be considered together with the shallow multicontext p occurring at x. For this reason we will write "let (p, x) be a node of a tree t" when x is a node of t and p is the shallow multicontext at x. Similarly, if P is a set of shallow multicontexts, we will write "let (p, x) ∈ P " when p ∈ P and x is a node of p.

Given a shallow multicontext p of arity n and a sequence T of n forests, p[T ] denotes the forest obtained after placing the i th forest of T at the i th port of p. Moreover, given a node x of p whose unique child is a port (i.e. x is the root of a tree of the form b(2) within p) and a sequence T of n -1 forests, p[T, x] denotes the context obtained as above but leaving the subtree at x unchanged. P -Valid Forests and Contexts. Let P be a set of shallow multicontexts. Later on P will be a key parameter for the induction. We say that a forest t is P -valid iff it has more than one node and all shallow multicontexts occurring in t are in P . Similarly we define the notion of a P -valid context. Note that we distinguish forests with one node in the definition. This is a technical restriction that will be convenient without harming the generality of the argument as the omitted forests are definable in FO 2 (< v , < h ). We extend the notion of P -validity to elements of H and V . We say h ∈ H is P -valid iff there exists a P -valid forest t such that h = α(t). Similarly for v ∈ V . P -Reachability. The logic FO 2 (< v , < h ) can be seen as a two-way logic navigating up and down within forests. Over strings, this two-way behavior is reflected by two partial orders over the syntactic semigroup capturing respectively the current knowledge when reading the string from left to right and from right to left, and correspond to the Green's relations L and R.

Over forests it turns out that the relevant bottom-up order is a partial order on forest types while the relevant top-down order is a partial order on context types [START_REF] Miko | Two-way unary temporal logic over trees[END_REF]. In our case those are even parametrized by a set P of shallow multicontexts and are called P -reachability. The index within these orders will be another parameter in our induction.

Let h, h be two P -valid forest types, h is said to be P -reachable from the forest type h if there exists a P -valid context type v such that h = vh . Two forest types are P -equivalent if they are mutually P -reachable.

The definition is similar for context types and is defined for any v, v ∈ V , not just P -valid ones. Given two contexts v, v ∈ V we say that v is P -reachable from v whenever there is a P -valid context type u such that v = v u.

Notice that for both partial orders, if P ⊆ P then P -reachability implies P -reachability.

We will reduce the case when all shallow multicontexts of P have arity 1 or less to the string case. On the other hand, when P contains at least one shallow multicontext of arity at least 2 we will make use of the following property: Claim 5.1. If P contains a shallow multicontext of arity at least 2 then among P -equivalence classes of P -valid forest types there exists a unique maximal one with respect to P -reachability.

Proof. Take p ∈ P of arity n ≥ 2. Given h, h ∈ H that are P -valid, consider t and t two P -valid forests such that α(t) = h and α(t ) = h . Consider the sequence T of n P -valid forests containing copies of t and t , with at least one copy of t and one copy of t . Now α(p[T ]) is P -reachable from both h and h . The result follows.

In the cases when Claim 5.1 applies we say that P is branching and we denote by H P the maximal class given by Claim 5.1. Finally, we say that a branching set of shallow multicontexts P is reduced if all P -valid forest types are mutually reachable, i.e. H p is the whole set of P -valid forest types. 5.2. FO 2 (< v , < h )-Equivalence for Shallow multicontexts. It will often be necessary to manipulate shallow multicontexts modulo definability in FO 2 (< v , < h ). Typically, when applying the Antichain Composition Lemma with a formula of the form "select all nodes whose shallow multicontext is in P but have no ancestor with that property", it will be necessary that P is definable in FO 2 (< v , < h ).

Definable set of shallow multicontexts. Intuitively, FO 2 (< v , < h ) treats a shallow multicontext as a string whose letters are a, b(a), or b(2). More formally, we define A s as the alphabet containing the letters a, b(2) and b(a) for all a ∈ A and b ∈ B. We say that b is the inner-label of b(2) or b(a). We see a shallow multicontext p as a string over the alphabet A s .

For each positive integer k and any two shallow multicontexts p and p , we write p ≡ k p for the fact that Spoiler has a winning strategy in the game played on p and p , seen as strings over A s . In particular, we say that a set P of shallow multicontexts is k-definable iff it is a union of classes of under ≡ k . As the name suggests a set P of k-definable shallow multicontexts is definable in FO 2 (< v , < h ). In particular we get the following claim which is an immediate consequence of Lemma 3.2. Claim 5.2. For any k and any k-definable set P of shallow multicontexts, the language of P -valid forests is definable in FO 2 (< v , < h ).

Definable nodes in shallow multicontexts. It will also sometimes be necessary to refer to an explicit node within a shallow multicontext. Typically, when applying the Antichain Composition Lemma with a formula of the form "select all nodes (p, x) such that . . . and having no ancestor with that property". We will of course need to treat (p, x) modulo definability. It would be tempting to use a notion of definability similar to the one used for shallow multicontexts in the previous paragraph. However the notion of saturation building from this would give a necessary but not sufficient characterization for languages definable in FO 2 (< v , < h ). In particular, the induction in our suffiency proof would not terminate (see Lemma 8.12). Our notion of definability is based on an Ehrenfeucht-Fraïssé game relaxing the rules defined in Section 3.2 in order to grant more power to Duplicator. Moreover it will be useful to parametrize the game by a set X ⊆ H. In the sequel X will be another parameter of the induction denoting those forest types for which we are still looking for a formula defining the set of forests for that type. When applying the Antichain Composition Lemma, any forest of type h ∈ X can be safely replaced by a node with the appropriate label as the corresponding language is definable in FO 2 (< v , < h ).

Given X, we distinguish between three kinds of nodes within shallow multicontexts: port-nodes are nodes that are roots of trees of the form b(2) with b ∈ B, X-nodes are nodes that are roots of trees of the form b(a) with a ∈ A, b ∈ B and α(a) ∈ X, finally X-nodes are the remaining nodes, i.e. nodes with label a ∈ A or roots of trees of the form b(a) with a ∈ A, b ∈ B and α(a) ∈ X.

Let p and p be two shallow multicontexts, seen as strings over A s . The k-round X-relaxed game between p and p is defined as in Section 3.2 but tests on labels in this new game are relaxed, making the game easier for Duplicator. Since this alone makes the equivalence too permissive (this yields a non-necessary characterization), we compensate by giving Spoiler a third "safety" move in addition to the usual left and right sibling moves. Spoiler can use this third move only under specific conditions depending on the labels of the nodes the pebbles are currently on. These two modifications achieve the right balance of expressive power.

At the start of each round Spoiler can move one of the two pebbles inside its shallow multicontext to some left or right sibling x. Duplicator must respond by moving the other pebble inside the other shallow multicontext in the same direction to a node y, if x is an X-node then y must have the same label as x. Otherwise, if x is a port-or X-node, y must be a port-or X-node with the same inner-label. Hence, at any point in the game the pebbles may lie on nodes with labels b(c), b(c ) with c = c and c, c ∈ A ∪ {2}. In that particular case Spoiler can use a 'safety' move: he selects one of the two pebbles but does not move it, by hypothesis this pebble is on a node of label b(2) or b(a) with α(a) ∈ X. Duplicator must then place the other pebble on a node of label b(2).

Given two nodes (p, x) and (p , x ), we write (p, x) ∼ = X k (p, x ) if i) p and p contain the same set of labels in A s , ii) x, x have the same label and iii) Duplicator wins the k-rounds X-relaxed game between p and p starting at positions (p, x) and (p , x ). It will also be convenient to define ∼ = X k on shallow multicontexts only. We write p ∼ = X k p iff (p, x) ∼ = X k (p , x ) with x, x the leftmost positions in p, p . The following claim is immediate from the definitions:

Claim 5.3. Assume p ∼ = X k+2 p , then for any port-node x ∈ p (resp. x ∈ p ) there exists a port-node x ∈ p (resp x ∈ p) such that (p, x) ∼ = X k (p , x ).
Proof. Set y, y as the leftmost positions in p, p . In the (k + 2)-rounds X-relaxed game between (p, y) and (p , y ), Spoiler can use the two initial rounds to move the pebble to x in p (resp. to x in p) and then use (if necessary) a safety move. Duplicator's strategy yields the desired port-node x in p (resp. x ∈ p ).

It is not immediate from the definitions that ∼ = X k is an equivalence relation (transitivity is not obvious). We prove it in the next lemma.

Lemma 5.4. For all X ⊆ H and all k, ∼ = X k is an equivalence relation. Proof. It is clear from the definitions that the relation is reflexive and symmetric. We now prove transitivity. Assume (p,

x) ∼ = X k (p , x ) and (p , x ) ∼ = X k (p , x ). We want to show that (p, x) ∼ = X k (p , x ).
It is clear that p and p contain the same set of labels and that x and x have the same label. We need to prove that Duplicator has a winning strategy in the k-rounds X-relaxed game between (p, x) and (p , x ).

By hypothesis, Duplicator has winning strategies in the k-rounds X-relaxed games between (p, x) and (p , x ) and between (p , x ) and (p , x ). We combine these strategies in the obvious way. Assume that Spoiler makes a non safety move on p, then Duplicator obtains an answer in p from her strategy in the game on p and p , plays that answer as a move for Spoiler in the game on p and p which yields an answer in p from her strategy on that game. This is her answer to Spoiler's move, and it is immediate to check that this is a correct answer. By symmetry she can answer a similar move of Spoiler on p .

Assume now that Spoiler makes a safety move on p. Observe that this cannot happen in the first-round since x and x have the same label. Therefore after this round there will be at most k -2 rounds left to play. Let b be the inner label of the pebble on p. Since a safety move was used, the pebbles in p and p must have different labels. Hence at least one of these labels is different from the label of the pebble in p . We distinguish two cases depending on which one it is.

If the pebbles on p and p have different labels, then Duplicator can use a Safety move in the game between p and p to get y in p with label b(2) from where she can continue to play the game. If the pebbles on p and p have different labels, then Duplicator can use a Safety move in the game between p and p to get y in p with label b(2). We can then use Claim 5.3 to get y with label b(2) and such that (p , y ) ∼ = X k-2 (p , y ), this is Duplicator's answer. It is correct since the number of rounds left to play is less than k -2.

As for Lemma 3.2 is it easy to show that for all k, ∼ = X k has finite index. Finally, the following claim is a simple variant of Claim 5.2: Claim 5.5. Let X ⊆ H and (p, x) be a node. There is a FO 2 (< v , < h ) formula ψ p,x having one free variable and such that for any forest s, ψ p,x holds exactly at all nodes

(p , x ) such that (p, x) ∼ = X k (p , x ). Proof. It is immediate that (p, x) ≡ k (p , x ) ⇒ (p, x) ∼ = X k (p , x
) (following the strategy provided by (p, x) ≡ k (p , x ) prevents Spoiler from using any safety move in the X-relaxed game). Hence any ∼ = X k -class is a union of ≡ k -classes and the result follows.

Decidable Characterization of FO

2 (< v , < h )
In this section we present our decidable characterization for FO 2 (< v , < h ). It involves three properties of the syntactic morphism of the language. As we explained, the first two are simple identities on H and V , the third one, saturation is a new notion that is parametrized by a set P of shallow multicontexts and the associated equivalences. We first define saturation and then state the characterization.

6.1. Saturation. Let α : A → (H, V ) be a morphism into a finite forest algebra (H, V ). Note that as for shallow multicontexts while saturation makes sense for any morphism, it is designed to be used with leaf surjective ones. In particular, in the characterization, we state saturation on the leaf completion of the syntactic morphism of the language. Consider some branching and reduced set P of shallow multicontexts (note that we do not ask P to be definable). Recall that P will be the set of allowed patterns. Let H P be the unique maximal class given by Claim 5.1. Note that since P is reduced, H P is also the set of P -valid forest types.

Set k ∈ N. We say that a context ∆ is (P, k)-saturated if (i) it is P -valid and, (ii) for each port-node (p, x) ∈ P there exists a port-node (p , x ) on the backbone of ∆ such that (p, x) ∼ = H P k (p , x ). We say that α is closed under k-saturation if for all branching and reduced sets P of shallow multicontexts, for all contexts ∆ that are (P, k)-saturated and all h 1 , h 2 ∈ H P , we have:

α(∆) ω h 1 = α(∆) ω h 2 (6.1)
We say that α is closed under saturation if it is closed under k-saturation for some k. We will need the following simple observation. Lemma 6.1. Let α : A → (H, V ) be a morphism into a finite forest algebra (H, V ) and k, k two integers such that k > k. If α is closed under k-saturation then α is closed under k -saturation.

Proof. This is immediate since by definition, any ∆ that is (P, k )-saturated is (P, k)saturated as well.

6.2. Characterization of FO 2 (< v , < h ). We are now ready to state the main result of this paper.

Theorem 6.2. A regular forest language L is definable in FO 2 (< v , < h ) iff its syntactic morphism α : A → (H, V ) satisfies the following properties: a) H satisfies the equation ω(h + g) + g + ω(h + g) = ω(h + g) (6.2) b) V satisfies the equation (uv) ω v(uv) ω = (uv) ω (6.3) c) the leaf completion of α is closed under saturation.
Notice that (6.2) and (6.3) above are exactly the identities characterizing, over strings, definability in FO 2 (<) (recall Theorem 4.2) and are therefore necessary for being definable in FO 2 (< v , < h ). It is easy to see that they are not sufficient to characterize FO 2 (< v , < h ).

To see this, consider the language of trees that corresponds to Boolean expressions, with and and or inner nodes and 0 or 1 leaves, that evaluates to 1. One can verify that the syntactic forest algebra of this language satisfies (6.2) and (6.3). However it is not definable in FO 2 (< v , < h ), actually not even in FO(< v , < h ) [START_REF] Potthoff | Modulo-counting quantifiers over finite trees[END_REF].

Recall that FO 2 (< v , < h ) can express the fact that a forest is a tree and, for each k, that a tree has rank k, hence Theorem 6.2 also apply for regular tree languages and regular ranked tree languages.

In Section 7 we will prove that the properties listed in the statement of Theorem 6.2 are necessary for having definability in FO 2 (< v , < h ) using a simple but tedious Ehrenfeucht-Fraïssé argument. In Section 8 we prove the difficult direction of Theorem 6.2, i.e. that the properties imply definability in FO 2 (< v , < h ).

Finally in Section 9 we show that the properties listed in Theorem 6.2 can be effectively tested. This is simple for (6.2) and (6.3) but will require an intricate pumping argument for saturation. Altogether Theorem 6.2 achieves our goal and provides a decidable characterization of regular forest languages definable in FO 2 (< v , < h ).

Correctness of the properties

In this section we prove that the properties stated in Theorem 6.2 are necessary for being definable in FO 2 (< v , < h ). We prove that any language L definable in FO 2 (< v , < h ) is closed under saturation and its syntactic forest algebra satisfies the identities (6.2) and (6.3).

If L is definable in FO 2 (< v , < h ) then it is simple to see that its syntactic forest algebra must satisfy the identities (6.2) and (6.3). This is because Identity (6.2) is essentially concerned by sequences of forests with the + operation. Therefore each such sequence can be treated as a string over < h and Theorem 4.2 can be applied to show that the identity is necessary. Similarly Identity (6.3) concerns only sequences of contexts that can also be treated as strings over < v .

The necessary part of Theorem 6.2 then follows from the following proposition.

Proposition 7.1. Let L be a forest language that is definable in FO 2 (< v , < h ). Then the leaf completion of the syntactic morphism of L is closed under saturation.

The rest of this section is devoted to the proof of Proposition 7.

1. It is a classical but tedious Ehrenfeucht-Fraïssé argument. Assume L is definable in FO 2 (< v , < h ). It follows from Theorem 3.1 that L is definable in EF + F -1 (F h , F h -1
). Let α : A → (H, V ) be the leaf completion of its syntactic morphism. Let k be the nesting depth of the navigational modalities used in the formula recognizing L, we prove that α is closed under k-saturation.

Let P be a branching and reduced set of shallow multicontexts. Let X = H P be the associated class of P -valid forest types. Let ∆ be a (P, k)-saturated context. Let u = α(∆) and h 1 , h 2 be two forest types in H P . We need to show that u ω h 1 = u ω h 2 .

For this we exhibit two forests S 1 and S 2 over A such that α(S 1 ) = u ω h 1 and α(S 2 ) = u ω h 2 and such that Duplicator has a winning strategy for the k-move game described in Section 3.2 when playing on S 1 and S 2 . Therefore it follows from Lemma 3.2 that no formula

of EF + F -1 (F h , F h -1
) whose nesting depth of its navigational modalities is less than k can distinguish between the two forests. This implies u ω h 1 = u ω h 2 as desired.

Our agenda is now as follows. In Section 7.1 we define the two forests S 1 and S 2 on which we will play. Then in Section 7.3 we give the winning strategy for Duplicator in the k-move game on S 1 and S 2 .

We start with some definitions that will play the key role in the proof. The root of a forest is the root of the leftmost tree of that forest. Recall that the backbone of a context is the path containing all the ancestors of the port of that context. The skeleton of a context is the set of nodes composed of the backbone together with their siblings. Both notions are illustrated in Figure 4.

P = {h 1 , • • • , h }.
Recall that since P is reduced, X is also the set of P -valid types. In particular all subforests of a P -valid forest or context that are not leaves have a type in X. We fix a set {s 1 , . . . , s } of P -valid forests such that for all i, s i ∈ A and α(s i ) = h i . This is without loss of generality as for each i, h i is in H P and therefore reachable from any type and therefore there is a forest of arbitrary depth of that type. Given a P -valid context C and forests t 1 , • • • , t , we say that C is the context obtained from C by replacing all subforests of type h j by t j if C is constructed by considering all the nodes x that are on the skeleton of C but not on the backbone and, if the subforest below x is s where α(s) = h j with j ≤ , we replace it with t j . By construction, C and C have the same skeleton. Notice that since P is reduced and C is assumed to be P -valid, the construction replaces the subforests below all ports and X-nodes on the skeleton of C that are not on the backbone and leaves the X-nodes unchanged. Since we assumed that all s i are not in A, this means that all X-nodes on the skeleton of C become port nodes within C . Therefore, C may contain on its backbone shallow multicontexts that are not in P and saturation may not be preserved. We will show how to deal with this fact later.

Since P is branching, there exists a shallow multicontext q 0 ∈ P of arity greater than 1. For i ≤ , we denote by V i the context obtained from q 0 by placing the forest s i into all the ports of q 0 except for the rightmost one.

By maximality of H P relative to P -reachability, for all i ≤ there exists a P -valid context U i such that

h i = α(U i )α(V • • • V 1 )u ω h 1 . For i ≤ , we write U i for the context U i V • • • V 0 .
For all i ≤ we write u i = α(U i ). By definition, for i ≤ , the contexts U i have the following properties:

• U i is P -valid, • u i u ω h 1 = h i ,
• the context U i contains for all j ≤ a subforest of type h j such that all nodes on the path to this copy are port-nodes (namely s j within V j ). We now construct by induction on j contexts ∆ j and U i,j , and forests T i,j such that for all i ≤ , we have α(∆ j ) = u, α(U i,j ) = u i and α(T i,j ) = h i . We initialize the process by setting for all i ≤ :

• U i,0 is formed from U i by replacing all subforests of type h j by s j ,

• ∆ 0 is obtained from ∆ by replacing all subforests of type h j with s j ,

• T i,0 := U i,0 • (∆ 0 ) ω • s 1 .
By construction we have α(∆ 0 ) = u, α(U i,0 ) = u i and α(T i,0 ) = u i u ω h 1 = h i as desired. When j > 0, the inductive step of the construction is done as follows for all i ≤ :

• U i,j is formed from U i by replacing each subforest of type h i by T i ,j-1 (see Figure 5),

• ∆ j is formed from ∆ by replacing each subforest of type h i by T i ,j-1 ,

• T i,j = U i,j • (∆ j ) ω • • • (∆ 0 ) ω • s 1 . b a b a b h 1 h 2 h 1 a c h 3 d d a b h 1 U i b a b a b T 1,j T 2,j T 1,j a c T 3,j d d a b T 1,j U i,j+1
Figure 5: Illustration of the construction of U i,j from U i : each subforest of type h i in U i is replaced by T i ,j-1 .

By induction we have for all

j ≤ , α(U i,j ) = α(U i ) = u i , α(∆ j ) = α(∆) = u and α(T i,j ) = u i u ω h 1 = h i as required.
Notice that each U i,j contains a copy of T i ,j-1 for all i ≤ . Let m = 2 k and let:

S 1 := (∆ m ) (m+1)ω • T 1,m S 2 := (∆ m ) (m+1)ω • T 2,m (7.1)
Note that by definition α(S 1 ) = u ω h 1 and α(S 2 ) = u ω h 2 . Therefore the following lemma concludes the proof of Proposition 7.1. Lemma 7.2. Duplicator has a winning strategy for the k-move game between S 1 and S 2 . 7.2. Basic Properties. Before proving Lemma 7.2 we state some basic properties of the construction.

Recall that the operation constructing C from a P -valid C by replacing all subforests of type h j by t j does not preserve saturation. The issue is that all X-nodes become port-nodes and the resulting shallow multicontext may no longer be equivalent to one occurring in the backbone of C. In order to cope with this problem, we remember what the initial situation was. If x is a port-node on the skeleton of C (recall that C and C have the same skeleton) we say that:

• x is an ex-port-node if x, as a node of C, was a port-node.

• x is an ex-X-node if x, as a node of C, was a X-node. Observe that, by construction, for any port-node x of C , the subtree at x in C is b(t j ) for some j and some b ∈ B. For ex-X-nodes, this is by construction. For ex-port-nodes, this is because P is reduced and C was P -valid, hence all subforets of C but leaves had type in H P . Also notice that all remaining nodes of C are X-nodes and are unchanged with respect to C.

Let x 1 (resp. x 2 ) be a node on the skeleton of a context C 1 (resp. C 2 ) constructed from a P -valid context C 1 (resp. C 2 ) by replacing all subforests of type h i by T i,j 1 for some fixed j 1 (resp. T i,j 2 for some fixed j 2 ). Let x 1 , x 2 be the corresponding nodes on the skeletons of C 1 , C 2 . We write

x 1 ∼ X n x 2 when x 1 ∼ = X n x 2 . Because ∼ = X n is an equivalence, it is straightforward to verify that ∼ X
n is also an equivalence relation. There is a game definition of ∼ X n , called pseudo-X-relaxed game. In this game Spoiler can now use the safety move when one pebble is on a ex-port-node and the other on a ex-X-node or when both pebbles are on ex-X-nodes with subtrees b(T i 1 ,j 1 ), b(T i 2 ,j 2 ) such that i 1 = i 2 . In this case Duplicator must answer by placing the other pebble on a ex-port-node.

By construction the following property is an immediate consequence of the (P, k)saturation of ∆: Assume C is P -valid and that C is constructed from C by replacing all subforests of type h i by T i,j for some fixed j. Then for any n and any ex-port-node x of C there exists a y in the backbone of ∆ n such that x ∼ X k y. We call this property, the pseudo-saturation of ∆ n .

Notice that when using pseudo-saturation in her strategy, Duplicator may end up in a situation where the pebbles are above subtrees T i,j 1 and T i,j 2 with j 1 = j 2 . Note that T i,j 1 and T i,j 2 are essentially the same tree, only with different nesting. In this situation, Duplicator may have to play a subgame within the trees T i,j 1 and T i,j 2 . The following lemma states that this is possible as soon as j 1 , j 2 are large enough.

Lemma 7.3. Given integers i, n, j 1 , j 2 such that 2(n -1) + 1 ≤ j 1 , j 2 , Duplicator has a winning strategy for the n-move game between T i,j 1 and T i,j 2 .

Proof. This can be proved by a simple induction on n. Essentially this is a straightforward generalization of a classical argument used to prove that the words w j 1 and w j 2 cannot be distinguished by a first-order formula of fixed quantifier rank provided that j 1 , j 2 are large enough (see [START_REF] Straubing | Finite Automata, Formal Logic and Circuit Complexity[END_REF] for example). 7.3. The winning strategy: Proof of Lemma 7.2. We give a winning strategy for Duplicator in the k-move game between S 1 and S 2 . In order to be able to formulate this strategy, we first define the useful parameters and their key properties that we will later use.

The backbone of S 1 (S 2 ) is the path going through all the ports of the copies of ∆ m within S 1 (S 2 ) and the skeleton of S 1 is the set of nodes within the backbone of S 1 together with their siblings.

The nesting level of a node x of S 1 or S 2 is the minimal number j such that x belongs to a context ∆ j or U i,j . We set the nesting level of the nodes that are in any copy of a forest s 1 , . . . , s to 0. The notion of nesting level is illustrated in Figure 6. Note that this number is equal in siblings and may only increase when going up in the tree. When this number is low, we are near the leaves of the forest and we need to make sure that the current positions of the game point to isomorphic subtrees. Recall that because of the construction of the context U i,j , a node of nesting level j always has, for all i ≤ , a descendant that is at the root of a copy of T i ,j-1 and, for all j < j a descendant that is at the root of a copy of ∆ j . The upward number of a node x ∈ S 1 (or x ∈ S 2 ) is the number of occurrences of ∆ m in the path from x to the root of S 1 (see Figure 7). When this number is low, we are near the roots and we need to make sure the current positions are identical. Fortunately the two forests S 1 and S 2 are identical up to a certain depth. This number is equal in siblings. When moving up in the tree this number may only decrease and, by construction, it can only decrease when traversing a copy of ∆ m and therefore the resulting node must be on the backbone of S 1 (S 2 ).

Given a node x ∈ S 1 (or x ∈ S 2 ), the horizontal number of x is the maximal number n ≤ k such that for all strict ancestors y of x, there exists a node z on the backbone of ∆ m such that y ∼ X n z. Note that this number is equal in siblings and can only increase when going up in the tree. Recall also that if y is an ex-port-node by pseudo-saturation y ∼ X k z for some z on the backbone of ∆ m . Hence, if all the strict ancestors of x are ex-port-nodes, then its horizontal number is k. In particular all nodes x in the skeleton of S 1 (or S 2 ) have horizontal number k.

∆ m ∆ m T 1,m m • ω copies of ∆
We now state a property P(n) that depends on an integer n and two nodes x ∈ S 1 and y ∈ S 2 . We then show that when P(n + 1) holds in a game starting at x, y, then Duplicator can play one move while enforcing P(n). As it is easy to see that P(k) holds for the roots of S 1 and S 2 , this will conclude the proof of Lemma 7.2. The inductive property P(n) is a disjunction of three cases:

(1) There exist ancestors x, ŷ of x, y such that x and ŷ have nesting level ≥ 2n + 1, upward number ≥ n and horizontal number ≥ n. Furthermore, either (a) x ∼ X n ŷ and Duplicator has a winning strategy in the n-move game played on the subtrees at x and ŷ, starting at positions x and y, or, (b) Duplicator has a winning strategy in the n-move game played on the subforests of x and ŷ, starting at positions x and y.

(2) The nodes x and y are at the same relative position within the copy of the context (∆ m ) mω in their respective forest.

(3) The upward numbers of x and y are ≥ n, their nesting levels are ≥ 2n + 1 and their horizontal number are ≥ n. Moreover, we have x ∼ X n y. Observe that there is a factor 2 involved in the conditions on the nesting levels of the nodes. We need this factor in order to be able to use Lemma 7.3.

Assume we are in a situation where P(n + 1) holds. We show how Duplicator can play to enforce P(n). The strategy depends on why P(n + 1) holds. In all cases we assume that Spoiler moves the pebble from x in S 1 . The case when Spoiler moves the pebble from y in S 2 is symmetrical. Recall that n < k, and m = 2 k > 2n. 7.3.1. Case 1. P(n + 1) holds because of Item (1).

In this case we have two nodes x, and ŷ satisfying the properties of Item (1).

• Spoiler moves from x to a node that is still in the subtree at x. In that case, Duplicator simply responds in the subtree at ŷ using the strategy provided by Item (1) of P(n + 1) and P(n) holds because Item (1) remains true.

• Spoiler moves to a sibling x of x. This can only occur if x = x and y = ŷ. If a) holds, by hypothesis we have x ∼ X n+1 ŷ, therefore, Duplicator can answer with a sibling y of ŷ such that x ∼ X n y . Since x (y ) is a sibling of x (ŷ), it has the same upward number, nesting level and horizontal number as x (ŷ). Hence by hypothesis, all those numbers satisfy Item (3) of P(n) and we are done. If b) holds Duplicator simply responds in the subforest of ŷ using the strategy provided by b) and P(n) holds because Item (1.b) remains true.

• Spoiler moves to an ancestor x of x. Assume first that the upward number of x is < n. Recall that by hypothesis the upward number of x is ≥ n + 1. Hence x is on the backbone of S 1 . As, by hypothesis, ŷ has also an upward number ≥ (n + 1), the copy y of x in the other forest is also an ancestor of ŷ. Duplicator then selects y as her answer, satisfying Item (2) of P(n).

Assume now that the upward number of x is ≥ n. Since the horizontal number of x is ≥ n + 1, there exists a node z on the skeleton of ∆ m such that x ∼ X n+1 z. By hypothesis the upward number of ŷ is ≥ (n + 1). Hence we can find above ŷ an occurrence of ∆ m of upward number ≥ n. Duplicator answers by the copy of z in this occurrence of ∆ m . By construction, x , y have upward numbers ≥ n. Moreover x (y ) is an ancestor of x (ŷ) and therefore has a bigger nesting level. As by hypothesis the latter was ≥ 2(n + 1) + 1, x and y have nesting level ≥ 2n + 1. For the same reason the horizontal number of x is larger than the one of x and is therefore ≥ n. It follows that Item (3) of P(n) is satisfied. 7.3.2. Case 2. P(n + 1) holds because of Item (2).

In this case x and y are at the same relative position within the copy of the context (∆ m ) mω in their respective forest.

• Spoiler moves to a node x that remains within the context (∆ m ) mω . Then Duplicator copies this move in the other forest and P(n) is satisfied because of Item (2).

• Spoiler moves to a node x that is within the subforest T 1,m of S 1 . In particular this means that x, y are on the backbones of S 1 , S 2 . By construction the subforest T 2,m of S 2 contains at least one copy of the forest T 1,m-1 that can be chosen such that all nodes occurring on the path to this copy are ex-port-nodes. It follows from Lemma 7.3 that there exists a node y in T 1,m-1 such that Duplicator has a winning strategy in the n-move game played on T 1,m and T 1,m-1 , starting at positions x and y . This is Duplicator's answer.

Set x and ŷ as the roots of the copies T 1,m and T 1,m-1 in S 1 and S 2 . Observe that by construction, x and ŷ have nesting level ≥ m -1 ≥ 2n + 1, upward number mω ≥ n and horizontal number k ≥ n. Moreover, by choice of y , Duplicator has a winning strategy in the n-move game played on the subforest of x and ŷ, starting at positions x and y . We conclude that P(n) holds because of Item (1.b).

Case 3. P(n + 1) holds because of Item (3).

In this case the upward numbers of x and y are ≥ n + 1, their nesting levels are ≥ 2(n + 1) + 1 and their horizontal number are ≥ n + 1. Moreover we have x ∼ X n+1 y. • Spoiler moves horizontally. Then Duplicator moves according to the winning strategy provided by x ∼ X n+1 y and Item (3) of P(n) holds. • Spoiler moves to an ancestor x of x.

If the upward number of x is < n, as the upward number of x ≥ n + 1, x must be on the backbone of S 1 . Duplicator answers by the copy y of x in the other forest, satisfying Item (2) of P(n). Note that the upward number of y is ≥ n + 1. Therefore y , having an upward number < n is indeed an ancestor of y.

If the upward number of x is ≥ n. By hypothesis, the horizontal number of x is ≥ n+1, therefore, there exists a node z in the skeleton of ∆ m such that x ∼ X n+1 z. By hypothesis the upward number of y is ≥ n + 1. Hence we can find above y an occurrence of ∆ m of upward number n. Duplicator answers by the copy y of z in this occurrence of ∆ m . By construction we have x ∼ X n y . By hypothesis, for x , and by construction, for y , both have upward number ≥ n. As this is a move up, the nesting level increases and therefore remains ≥ 2n + 1. Hence Item (3) of P(n) is satisfied.

• Spoiler moves down to some node x . Note that this means that x is a port-node and therefore either an ex-X-node or an ex-port-node. Moreover, since x ∼ X n+1 y, this is also true of y. Set T ix,jx and T iy,jy as the subforests below x and y. Observe that by hypothesis j x , j y ≥ 2(n + 1). We distinguish two cases:

Assume first that x and y are both ex-X-nodes and i x = i y . Set x as x and ŷ as y. Using Lemma 7.3, we get that Duplicator wins the (n + 1)-moves game played on the subtrees at x and ŷ. This gives Duplicator's answer y to x and Item (1.a) of P(n) holds.

Otherwise, we use pseudo-saturation to prove that there exists a node z on the backbone of ∆ m such that z ∼ X n x ∼ X n y and provide an answer satisfying Item (1.b) of P(n) for Duplicator.

When either x or y is an ex-port-node node, the existence of z is immediate from pseudo-saturation and transitivity of ∼ X n . In the only remaining case, x and y are both ex-X-nodes and i x = i y . Therefore, Spoiler is allowed to use the safety move in the pseudo-X-relaxed game x ∼ X n+1 y, and we get a ex-port-node z in the shallow multicontext of y such that z ∼ X n x. By pseudo-saturation we then obtain z on the backbone of ∆ m such that z ∼ X k z . By transitivity, we get that z ∼ X n x ∼ X n y. We can now describe Duplicator's answer. By hypothesis, x belongs to T ix,jx and by definition T iy,jy contains at least one copy of the forest T ix,jy-1 that can be chosen such that all nodes occurring on the path to this copy are ex-port-nodes. Since j x , j y ≥ 2(n + 1), it follows from Lemma 7.3 that there exists a node y in T ix,jy-1 such that Duplicator has a winning strategy in the n-move game played on T ix,jx and T ix,jy-1 , starting at positions x and y . This is Duplicator's answer.

Set x and ŷ as the roots of the copies T ix,jx and T ix,jx-1 in S 1 and S 2 . Observe that by definition, x and ŷ have nesting level j x , j y -1 ≥ 2n + 1 and upward numbers ≥ n + 1 > n (the same as x, y). Moreover, all ancestors of x, ŷ are either ancestors of x, y, ex-port-nodes or x, y themselves. Since we proved that there exists z on the backbone of ∆ m such that z ∼ X n x ∼ X n y, it follows that x, ŷ have horizontal number ≥ n. Finally, by choice of y , Duplicator has a winning strategy in the n-move game played on the subforests of x and ŷ, starting at positions x and y . We conclude that P(n) holds because of Item (1.b).

This concludes the proof of Lemma 7.2 and therefore the proof of Proposition 7.1.

Sufficiency of the properties

For this section we fix a regular forest language L recognized by a morphism α : A → (H, V ) into a finite forest algebra (H, V ). Assume that H and V satisfy Identities (6.2) and (6.3) and that the leaf completion of α is closed under saturation. We prove that any language recognized by α, including L, is definable in FO 2 (< v , < h ), concluding the proof of Theorem 6.2.

Recall that given a forest s (a context p) we refer to its image by α as the forest type of s (the context type of p). In view of Lemma 4.1, we assume without loss of generality that α itself is leaf surjective and closed under saturation. By definition, this implies in particular that for each h ∈ H there exists a tree consisting of a single node whose forest type is h.

As mentioned earlier, we will often manipulate shallow multicontexts modulo ≡ k for some fixed integer k. We start by defining a suitable k. Given a shallow multicontext q and a forest s we denote by q[s] the forest constructed from q by placing s at each port of q.

Lemma 8.1. There exists a number k such that for all k ≥ k , for all shallow multicontexts p ≡ k p and for all forests s, p[s] and p [s] have the same forest type.

Proof. This is a consequence of Theorem 4.2 and the fact that H satisfies Identity (6.2). Consider strings over H as alphabet and the natural morphism β : H + → H. Since H satisfies Identity (6.2), it follows from Theorem 4.2 that for every h ∈ H, β -1 (h) is definable using a formula of ϕ h of FO 2 (<). We choose k as the maximal rank of all these formulas.

Let k ≥ k and take p ≡ k p and s some forest. Let t 1 , . . . , t n be the sequence of trees occurring in p[s] and t 1 , . . . , t n be the sequence of trees occurring in p [s]. For all i let h i = α(t i ) and h i = α(t i ). As p ≡ k p the strings h 1 . . . h n and h 1 . . . h n satisfy the same formulas of FO 2 (<) of rank k over the alphabet

H. Let h = β(h 1 . . . h n ), by our choice of k it follows that h 1 . . . h n |= ϕ h . Hence β(h 1 . . . h n ) = h = β(h 1 . . . h n ). Therefore α(p[s]) = α(p [s]).
As α is closed under saturation, there is an integer k such that α is closed under ksaturation. We set k as the maximum of k as given by Lemma 8.1 and k . By Lemma 6.1, α remains closed under k-saturation. Recall that a set P of shallow multicontexts is kdefinable if it is a union of equivalence classes of ≡ k .

Recall that V 1 is the monoid obtained from V by adding a neutral element 1 V . For each h ∈ H, v ∈ V 1 and each set P of shallow multicontexts let L P v,h = {t | vα(t) = h and t is P -valid} Our goal in this section is to show that: Proposition 8.2. For all h ∈ H, all v ∈ V 1 and all sets P of shallow multicontexts, there exists a language definable in FO 2 (< v , < h ) that agrees with L P v,h on P -valid forests. Theorem 6.2 is a direct consequence of Proposition 8.2. Let L be the union of all definable languages resulting from applying Proposition 8.2 to all L P v,h where h ∈ α(L), v = 1 V and P is the set of all shallow multicontexts. By definition L is definable in FO 2 (< v , < h ) and agrees with L on all P -valid forests. Hence

L = L ∪ {a ∈ A | a ∈ L} which is definable in FO 2 (< v , < h ).
The remainder of this section is devoted to the proof of Proposition 8.2. Assume that v, h and P are fixed as in the statement of the proposition, we prove that there exists a definable language that agrees on L P v,h on P -valid forests. We begin by considering the special case when P is not branching (i.e. contains only shallow multicontexts of arity 0 or 1). In that case we conclude directly by applying Theorem 4.2. 8.1. Special Case: P is not branching. In this case we treat our forests as strings and use the known results on strings. Since all shallow multicontexts in P have arity 0 or 1, any P -valid forest t is of the form:

c 1 • • • c k s
where k is possibly 0 and the c 1 , • • • , c k are P -valid shallow multicontexts of arity 1 and s a P -valid shallow multicontext of arity 0. For each u ∈ V 1 and g ∈ H, consider the languages:

M u,g = {t | t = c 1 • • • c k s is P -valid, α(c 1 • • • c k ) = u,

and α(s) = g}

Notice that L P v,h is the union of those languages where vug = h. We show that for any u and g, there exists a language definable in FO 2 (< v , < h ) that agrees with M u,g on P -valid forests. This will conclude this case.

By definition shallow multicontexts of arity 1 are contexts. Let {v 1 , ..., v n } be the context types that are images of shallow multicontexts of arity 1 in P .

Let P be the set of shallow multicontexts from P of arity 1. Let p, p ∈ P , by Lemma 8.1 if p ≡ k p for all forests s, p[s] and p [s] have the same forest type. Hence, p and p have the same context type. This means that for all v i the set of shallow multicontexts of context type v i is k-definable. Therefore, by Claim 5.2, there is a formula θ v i (x) of FO 2 (< v , < h ) testing whether the shallow multicontext of x has v i as forest type.

Let Γ = {d 1 , ..., d n } be an alphabet and define a morphism β : Γ * → V by β(d i ) = v i . Since V satisfies Identity (6.3), for each u ∈ V there is a FO 2 (<) formula ϕ u such that the strings of Γ * satisfying ϕ u are the strings of type u under β. From ϕ u we construct a formula Ψ u of FO 2 (< v , < h ) defining all P -valid contexts having u as context type. This is done by replacing in ϕ u all atomic formulas P d i (x) with θ v i (x). We can also easily define in FO 2 (< v , < h ) the set of shallow multicontexts of arity 0 such that α(s) = g. After combining this last formula with Ψ u we get the desired language definable in FO 2 (< v , < h ) and agreeing with M u,g on P -valid forests.

In the remainder of the proof we assume that P is branching, i.e. it contains one shallow multicontext of arity at least 2. Recall, that by Claim 5.1, it follows that there exists a unique maximal P -reachable class H P . The rest of the proof is by induction on three parameters that we now define. 8.2. Induction Parameters. The first and most important of our induction parameters is the size of the set of P -valid forest types. We denote this set by X. Observe that by definition H P ⊆ X.

Our second parameter is an index defined on sets P of shallow multicontexts. During the proof we will construct from P new sets P by replacing some of their port-nodes with X-nodes. Our definition ensures that the index of P will be smaller than the index of P , hence guarantees termination of the induction. It is based on following preorder on shallow multicontexts called simulation modulo X.

Given two shallow multicontexts p and p , we say that p simulates p modulo X if p is obtained from p by replacing some of its port-nodes b(2) by an X-node b(a) with the same inner label. Observe that simulation modulo X is a partial order.

For each shallow multicontext p its X-number is the number of non ∼ = X k+2 -equivalent shallow multicontexts q (not necessarily in P ) that can be simulated modulo X by p. For each set P of shallow multicontexts the n-index of P is the number of non ∼ = X k+2 -equivalent shallow multicontexts p ∈ P of X-number n. Our second induction parameter, called the index of P , is the sequence of its n-indexes ordered by decreasing n.

The third parameter is based on v. Consider the preorder on context types defined by the quotient of the P -reachability relation by the P -equivalence relation. The P -depth of a context type v is the maximal length of a path in this preorder from the empty context to v.

We prove Proposition 8.2 by induction on the following three parameters, given below in their order of importance:

(i) |X| (ii) the index of P (iii) the P -depth of v We distinguish three cases: a base case and two cases in which we will use antichain composition and induction. We say that a context type u P -preserves v if v is P -reachable from vu. A context c P -preserves v if its context-type P -preserves v.

8.3.

Base Case: P is reduced and v is P -preserved by a (P, k)-saturated context ∆. We use saturation to prove that v is constant over the set X = H P of P -valid forest types, i.e. for any P -valid h 1 , h 2 ∈ H, vh 1 = vh 2 . Since all forests in L P v,h are P -valid, it follows that L P v,h is either empty or the language of all P -valid forests. The desired definable language is therefore either the empty language of the language of all forests.

Since ∆ P -preserves v, there exists a P -valid context c such that vα(∆c) = v. It follows that v = vα(∆c) ω . Moreover, observe that since ∆ is P -saturated and c is P -valid, ∆c is P -saturated as well. It then follows from saturation that vh 1 = vα(∆c) ω h 1 = vα(∆c) ω h 2 = vh 2 This terminates the proof of the base case. We now consider two cases in which we conclude by induction. 8.4. Case 1: P is not reduced, Bottom-Up Induction. By definition, since P is not reduced there exists a P -valid forest type g ∈ X \ H P . We choose g to be minimal with respect to P -reachability, i.e., any P -valid forest type g is either P -equivalent to g or g is not P -reachable from g . Let G be the set of P -valid forest types that are Pequivalent g. Observe that by minimality of g, in any P -valid forest s whose type is in G, all subforests of s that are not single leaves have a forest type in G (recall that a subforest consists of all the children of some node). Moreover, by choice of g, G ∩ H P = ∅ and all g ∈ X such that G is P -reachable from g are in G. We obtain the desired definable language for L P v,h via the Antichain Composition Lemma using languages that we prove to be definable in FO 2 (< v , < h ) by induction on |X|. Correctness of the construction relies on both Equation (6.2) and Equation (6.3).

Outline. Our agenda is as follows. We construct from P a k-definable set P and prove that a P -valid forest has a type in G iff it contains no shallow multicontext of P . Since k-definable sets of shallow multicontexts can be expressed in FO 2 (< v , < h ), we use P to define an antichain formula ϕ which selects all positions whose subforest contains a shallow multicontext in P (i.e. has a forest type outside G) but have no descendant with that property (i.e. all descendants of the position have a subforest of type in G). This formula splits P -valid forests into two parts: a lower part and upper part. In the lower part all subforests have type in G X and in the upper part the set of valid forest types is included in X \ G. In both cases we get definable languages by induction on |X| we glue them back together using the Antichain Composition Lemma. This situation is illustrated in Figure 8. ) ∈ G} We prove in the next lemma that P is well-defined, i.e. that its definition does not depend on the choice of s.

Lemma 8.3. Let p be a shallow multicontext of arity n and T and T be two sequences of n P -valid forests of forest type in G. We have:

α(p[T ]) ∈ G ⇔ α(p[T ]) ∈ G
Proof. We use Identity (6.3) to prove this lemma. Let T = (t 1 , ..., t n ) and T = (t 1 , ..., t n ). For i ∈ [1, n] we write c i the context obtained from p[T ] by replacing t i by a port and t j by t j for j > i. Notice that by hypothesis on p, T and T , c i is P -valid for all i ≤ n. For all i ≤ n, we write u i = α(c i ), h i = α(t i ) and h i = α(t i ). We first show that:

∀i ≤ n, u i h i ∈ G ⇔ u i h i ∈ G (8.1)
Assuming that u i h i ∈ G, we show that u i h i ∈ G. By symmetry this will prove (8.1). As G is closed under mutual P -reachability, it is enough to show that u i h i is mutually P -reachable from h i . By definition u i h i is P -reachable from h i , therefore it remains to show that h i is P -reachable from u i h i . From u i h i ∈ G we get that h i is P -reachable from u i h i and therefore there is a P -valid context u such that h i = uu i h i . By hypothesis h i is P -reachable from h i and therefore there exists a P -valid context u such that h i = u h i . A little bit of algebra and Identity (6.3) yields:

h i = uu i u h i = (uu i u ) ω+1 h i = uu i (u uu i ) ω u h i = uu i (u uu i ) ω uu i (u uu i ) ω u h i using Identity (6.3) = (uu i u ) ω uu i (uu i u ) ω+1 h i = (uu i u ) ω u u i h i as (uu i u ) ω u is P -valid, h i is P -reachable from u i h i and (8.1) is proved.
For concluding the proof of the lemma, notice that by construction

α(p[T ]) = u 1 h 1 , α(p[T ]) = u n h n and u i h i = u i+1 h i+1 . As from (8.1) we get u i h i ∈ G iff u i h i ∈ G, this implies by induction on i that for all i ≤ n, u 1 h 1 ∈ G iff u i h i ∈ G iff u i h i ∈ G.
The case i = n proves the lemma.

We now prove that P can be used to test whether a P -valid forest has a type in G.

Lemma 8.4. A P -valid forest has type in G iff it is (P \ P )-valid.

Proof. This is a consequence of Lemma 8.3. Let t be a P -valid forest such that α(t) ∈ G. We prove that t contains a shallow multicontext of P . Consider a minimal subforest t of t whose type is not in G. Then we have t = p[T ] where p is a shallow multicontext and T a sequence of forests of forest type in G (possibly empty if p is of arity 0). Let T be the sequence s for some s with α(s) ∈ G. By Lemma 8.3 α(p[T ]) ∈ G and therefore p ∈ P .

Conversely, if α(t) ∈ G, by minimality of G, all subforests of t are in G. It is then immediate by definition of P and Lemma 8.3 that t cannot contain a shallow multicontext of P .

Setting up the Composition. Let ϕ be the antichain formula which holds at port-nodes (p, x) such that p ∈ P and x has no descendant with that property. It follows from the next lemma that ϕ is expressible in FO 2 (< v , < h ). Lemma 8.5. P is k-definable.

Proof. This is a consequence of Lemma 8.1 (which is itself a consequence of (6.2)). Set p ∈ P and p ≡ k p. We prove that p ∈ P . We now define the languages that we will use to apply the Antichain Composition Lemma.

Lemma 8.6. For any g ∈ G, there exists a language definable in FO 2 (< v , < h ) that agrees with L P 1 V ,g on P -valid forests. Proof. Notice that the set of all (P \ P )-valid forest types is G X. Hence by induction on the first parameter in Proposition 8.2 there exists a language L 1 definable in FO 2 (< v , < h ) that agrees with L (P \P ) 1 V ,g on (P \ P )-valid forests. By Lemma 8.4, a P -valid forest has type g ∈ G iff it is (P \ P )-valid. Hence L 1 agrees with L P 1 V ,g on P -valid forests.

Assume G = {g 1 , • • • , g n }.
For all i ≤ n, let L i be a language definable in FO 2 (< v , < h ) that agrees with L P 1 V ,g i on P -valid forests given by Lemma 8.6. Let Q be the set of shallow multicontexts q that can be obtained from some p ∈ P by replacing some port-nodes (possibly none) with G-nodes of the same inner label and such that either:

• q has arity greater than 1 (i.e. one port-node of p was left unchanged)

• or q has arity 0 and p ∈ P (hence α(q) ∈ G).

We have:

Lemma 8.7. There is a language

K definable in FO 2 (< v , < h ) that agrees with L Q v,h on Q-valid forests.
Proof. Let Y be the set of Q-valid forest types. We prove that Y ⊆ X and Y ∩ G = ∅. It will follow that |Y | < |X|. Hence K is obtained by applying Proposition 8.2 by induction on the first parameter.

Let h ∈ Y , by definition, there exists a Q-valid forest s such that α(s) = h. All shallow multicontexts q ∈ Q occurring in s are constructed from p ∈ P by replacing some portnodes of p with G-nodes. As G contains only P -valid forest types, for any g ∈ G there exists a P -valid forest whose type is g. By replacing the newly introduced G-nodes in s by the correspond P -valid forest with the same type we get a P -valid forest s whose type remains h. Hence h ∈ X. Moreover, for any shallow multicontext of arity 0 occurring in s, the corresponding shallow multicontext occurring in s must belong to P . It follows that s contains at least one shallow multicontext in P and by Lemma 8.4 that h ∈ G.

Applying Antichain Composition. We now apply the Antichain Composition Lemma to the languages K, and L 1 • • • L n defined above. The situation is depicted in Figure 8.

Recall that

G = {g 1 , • • • , g n }. For any i ≤ n, let a i ∈ A be such that α(a i ) = g i . Set L = {t | t[(L 1 , ϕ) → a 1 , • • • , (L n , ϕ) → a n ] ∈ K}. Since K, L 1 , . . . , L n are definable in FO 2 (< v , < h ), it follows from Lemma 3.3 that L is definable in FO 2 (< v , < h ).
We terminate the proof by proving that L agrees with L P v,h on P -valid forests. Lemma 8.8. Let t be a P -valid forest, then

α(t) = α(t[(L 1 , ϕ) → a 1 , • • • , (L n , ϕ) → a n ]).
Proof. This is immediate by definition of Q, K and L 1 • • • L n . 8.5. Case 2: P is reduced but there exists no (P, k)-saturated context ∆ that Ppreserves v, Top-Down Induction. In this case we use again the Antichain Composition Lemma using languages that we prove to be definable by induction on the index of P and the P -depth of v. Recall that since P is reduced, X = H P . Correctness relies on Identity (6.3).

Outline. We proceed as follows. First we use our hypothesis to define a port-node (p, x) ∈ P with the following properties. For any P -valid forest t and port-node (p , x ) of t such that (p, x) ∼ = X k (p , x ), the context c obtained from t by replacing the subforest below x by a port does not P -preserve v. Since by Claim 5.5 all such nodes (p , x ) can be defined in FO 2 (< v , < h ), this gives an antichain formula ϕ which selects such nodes having no ancestor with that property. Such a formula splits a forest in two parts: an upper part and a lower part. For the upper part, we will prove that the set of occurring shallow multicontexts has smaller index and use induction on that parameter. Moreover, observe that by choice of Given two elements g and g of H, we say that g is v + -equivalent to g if for all context types u which do not P -preserve v (hence the P -depth of vu is strictly higher that the P -depth of v) we have vug = vug . Set {γ 1 , . . . , γ n } as the set of all v + -equivalence classes. For all i, we define M i = {s | α(s) ∈ γ i and s P -valid}.

Lemma 8.11. For all i, there is a language L i definable in FO 2 (< v , < h ) that agrees with M i on P -valid forests.

Proof. Fix a v + -equivalence class γ i and let g ∈ γ i . For any u such that vu is not Preachable from v, by induction in Proposition 8.2, the third parameter has increased and the other two are unchanged, there is a language K u definable in FO 2 (< v , < h ) that agrees with L P vu,vug on P -valid forests. The lemma then follows by taking for L i the intersection of all languages K u for u such that vu is not P -reachable from v.

Let P = {p | p ∼ = X k+2 p }.
Observe that by Claim 5.3, any shallow multicontext p in P contain at least one position x such that (p, x) ∼ = X k (p , x ). For p ∈ P , let x 1 , • • • , x be all the port-nodes of p such that (p, x) ∼ = X k (p , x i ). Let b(2) be the label of all the x i in p . Let ∆ p be the set of all the shallow multicontexts that are constructed from p by replacing at all the positions x i , b(2) by a label b(a) (possibly different for each position), for a such that α(a) ∈ X. Let P be the union of all ∆ p for p ∈ P . Finally, let Q = (P \ P ) ∪ P .

Lemma 8.12. There is a language

K definable in FO 2 (< v , < h ) that agrees with L Q v,h on Q-definable forests.
Proof. Let Y be the set of all Q-valid forest types. We first observe that Y ⊆ X. The argument is similar to the one in the proof of Lemma 8.7 as the newly introduced shallow multicontexts can be represented by P -definable forests. If Y X, then the lemma follows by induction on the first parameter in Proposition 8.2. Otherwise X = Y and we prove that Q has smaller index than P . The result is then immediate by induction on the second parameter in Proposition 8.2. Note that this is where we use the fact that our notion of equivalence between positions is weaker than ≡ k . With a stronger notion, it would not be possible to prove that the index has decreased.

Set n ∈ N as the largest integer such that there exists a shallow multicontext in P with X-number n. We prove that all p ∈ P have a X-number that is strictly smaller than n. It will then be immediate from the definitions that Q has smaller index than P .

Let p ∈ P . By definition, there exists p ∈ P and x 1 , • • • , x ∈ p such that for all i, (p, x) ∼ = X k (p , x i ) and replacing the labels b(2) at all positions x i in p by b(a) for α(a) ∈ X yields p. In particular this means that p simulates p modulo X and that the X-number of p is smaller or equal to that of p and hence smaller or equal to n. We prove that p does not simulate any p ∼ = X k+2 p modulo X. It will follow that the inequality is strict which terminates the proof.

We proceed by contradiction, assume that there exists p ∼ = X k+2 p such that p simulates p modulo X. By definition, p ∼ = X k+2 p ∼ = X k+2 p, hence, by Claim 5.3, p contains a portnode x such that (p , x ) ∼ = X k (p, x). By definition of simulation, x corresponds to a port-node x in p and a port-node x in p . Moreover, since x is a port-node, this means that

x ∈ {x 1 , • • • , x }, i.e. (p , x ) is not ∼ = X
k -equivalent to (p, x). This contradicts the following claim.

Claim 8.13. (p , x ) ∼ = X k (p , x ) ∼ = X k (p, x).
It remains to prove Claim 8.13. We prove that (p , x ) ∼ = X k (p , x ). By definition, p and p use the same set of labels in A s and x , x have the same label b(2). We give a winning strategy for Duplicator in the X-relaxed game between (p , x ) and (p , x ). By definition p is obtained from p by replacing some port nodes with X-nodes with the same inner-node label. Therefore as long as Spoiler does not use a safety move, Duplicator can answer by playing the isomorphism. Assume now that Spoiler does a safety move. Then Applying Antichain Composition. Let K and L 1 • • • L n be languages definable in FO 2 (< v , < h ) as given by Lemma 8.12 and Lemma 8.11. For all i let a i ∈ A be such that α(a i )

∈ γ i . Set L = {t | t[(L 1 , ϕ) → a 1 , • • • , (L k , ϕ) → a n ] ∈ K}. It follows from Lemma 3.3 that L is definable in FO 2 (< v , < h ).
We terminate the proof by proving that L agrees with L P v,h on P -valid forests. Lemma 8.14. For any P -valid forest t, vα(t

) = vα(t[(L 1 , ϕ) → a 1 , • • • , (L k , ϕ) → a k ]).
Proof. This is because (p, x) is P -bad for v. The proof goes by induction on the number of occurrences in t of port-node (q, y) such that (q, y) ∼ = X k (p, x). If there is no occurrence, this is immediate as the substitution does nothing.

Consider a node y of a shallow multicontext q such that (q, y) ∼ = X k (p, x) and no node above y satisfies that property. Let s be the subforest below y in t and let i be such that α(s) ∈ γ i . Let c be the context formed from t by replacing s by a port and let u c be its type. Since (p, x) is P -bad for v, u c does not P -preserve v. Hence, vα(t) = vu c α(s) = vu c α(a i ) by definition of v + -equivalence.

We write t = ca i , we already know that vα(t ) = vα(t). Observe that by construction t

[(L 1 , ϕ) → a 1 , • • • , (L k , ϕ) → a k ] is t[(L 1 , ϕ) → a 1 , • • • , (L k , ϕ) → a k ]. By induction we have that vα(t ) = vα(t [(L 1 , ϕ) → a 1 , • • • , (L k , ϕ) → a k ]
) which terminates the proof.

Decidability

In this section we prove that the characterization of FO 2 (< v , < h ) given in Theorem 6.2 is decidable.

Theorem 9.1. Let L be a regular language of forests. It is decidable whether L is definable in FO 2 (< v , < h ).

In view of Theorem 6.2 the decision procedure works as follows. From L we first compute its syntactic morphism α : A → (H, V ). Then we check that (6.2) holds in H, that (6.3) holds in V and that α is closed under saturation. This is straightforward for (6.2) and (6.3) as H and V contain only finitely many elements. However it is not obvious from the definitions that closure under saturation can be decided. The main result of this section is an algorithm which, given as input a morphism α, decides whether α is closed under saturation.

Recall the definition of saturation. It requires the existence of a number k such that for all branching and reduced sets P of shallow multicontexts and all (P, k)-saturated contexts a property holds. The main problem is that all these quantifications range over infinite sets. In the first part of this section we introduce an "abstract" version of these sets with finitely many objects together with an associated "abstract" notion of saturation and show that closure under saturation corresponds to closure under the abstract notion of saturation.

Then, in the remaining part of the section we present an algorithm that computes the needed abstract sets. 9.1. Abstraction. Let A = (A, B) be a finite alphabet and α : A → (H, V ) be a morphism into a finite forest algebra (H, V ). Recall that we see shallow multicontexts as strings over A s , i.e. as elements of A + s . In order to stay consistent with our notation on shallow multicontexts, we will denote by + the concatenation within

A + s . Recall that if Q ⊆ A +
s is a set of shallow multicontexts, then we write (p, x) ∈ Q instead of x is a node of some shallow multicontext p ∈ Q.

We start with some terminology. Let p be a shallow multicontext of arity n and let G ⊆ H. We denote by p(G) the set of forest types h ∈ H such that there exists a sequence T of n forests which all have a type in G and such that α(p[T ]) = h. For a port-node x of p, we denote by p(G, x) the set of context types v ∈ V such that there exists a sequence T of n -1 forests which have all a type in G such that α(p[T, x]) = v. If x is not a port-node of p then we set p(G, x) = ∅ for all G. The following fact is immediate. Fact 9.2. Let (p, x) and (q, y) be nodes and r = p + q. Then for any G ⊆ H, r(G) = p(G) + q(G), r(G, x) = p(G, x) + q(G) and r(G, y) = p(G) + q(G, y).

Abstracting shallow multicontexts: Profiles. We now define an abstract version of positions in shallow multicontexts that we call profiles.

Consider a pair (p, x) where p is a shallow multicontext and x a position in p. The profile of (p, x), denoted β(p, x) is the quadruple v = (i, B s , f H , f V ) where

(1) i ∈ {0, 1, 2} is the arity of p counted up to threshold 2, (2) B s ⊆ A s is the alphabet p, i.e. the set of labels used in p, (3) f H : 2 H → 2 H is the forest mapping of p, defined as the mapping G → p(G), (4) f V : 2 H → 2 V is the context mapping of (p, x), defined as the mapping G → p(G, x). Observe that if p has arity 0 (i.e. p is a forest) then f H is the mapping G → {α(p)}. Moreover, whenever x is not a port-node, f V is the mapping G → ∅. We let P be the set of profiles of all shallow multicontexts. Observe that P is finite:

P ⊆ {0, 1, 2} × 2 As × (2 H ) 2 H × (2 V ) 2 H
In the rest of this section we shall denote by u, v, . . . profiles (elements of P), by U, V, . . . sets of profiles (subsets of P) and by U, V, . . . sets of sets of profiles (subsets of 2 P ).

Let us first present two semigroup operations for P. Both operations are adapted from the concatenation operation between shallow multicontexts. If (p, x) and (p , x ) are pairs where p, p are shallow multicontexts and x, x are positions of p, p , then one can use concatenation to construct two new pairs: (p + p , x) in which we keep the position x of p and (p + p , x ) in which we keep the position x of p .

Abstracted on profiles, this yields the two following operations. Let v, v ∈ P be two profiles and set (i,

B s , f H , f V ) = v and (i , B s , f H , f V ) = v . We define, two new profiles v + v ∈ P and v + r v ∈ P as follows, v + v = (j, C s , g H , g V ) with • j = min(i + i , 2) • C s = B s ∪ B s . • g H : G → f H (G) + f H (G). • g V : G → f V (G) + f H (G). v + r v = (j, C s , g H , g V ) with • j = min(i + i , 2) • C s = B s ∪ B s . • g H : G → f H (G) + f H (G). • g V : G → f H (G) + f V (G).
On the shallow multicontext level, the definition exactly means that for any (p, x), (p , x ) ∈ A + s such that v = β(p, x) and v = β(p , x ), we have v + v = β(p + p , x) and v + r v = β(p + p , x ). One can verify that + r and + are both semigroup operations. Moreover, the following fact is immediate from the definitions and states that one can use the operations + and + r to compute the whole set P from the profiles of one-letter shallow multicontexts.

Fact 9.1. P is the smallest subset of {0, 1, 2} × 2 As × (2 H ) 2 H × (2 V
) 2 H such that:

• P contains the profiles of one-letter shallow multicontexts: for all c ∈ A s , β(c, x) ∈ P (where x is the unique position in c)

• P is closed under + . • P is closed under + r .
Abstracting sets of shallow multicontexts: Configurations. Recall the definition of saturated contexts: let P be a set of shallow multicontexts, a context is (P, k)-saturated iff it is P -valid and for all (p, x) ∈ P , there exists a ∼ = X k -equivalent position on the backbone of the context. This means that we need to define an abstraction of sets of shallow multicontexts P that contains two informations:

• the set of P -valid types.

• the set of images under α of (P, k)-saturated contexts. For this we introduce the notion of configurations. Notice that this abstraction needs to be parametrized by the equivalence ∼ = X k . In order to do this, we will abstract this equivalence on profiles which are our abstraction of the objects compared by ∼ = X k . There is an issue however. Intuitively, we want two profiles u and v to be "equivalent" if one can find (p, x) and (q, y) such that (p, x) ∼ = X k (q, y), β(p, x) = v and β(q, y) = u. Unfortunately, this is not the right definition as the relation we obtain is not transitive in general and hence not an equivalence anymore. This is a problem since the definition of a saturated context requires to pick one position (p, x) among a set of equivalent ones. We solve this problem by abstracting sets of equivalent positions directly by sets of profiles.

Moreover, if P ⊆ A + s , the configuration that abstracts P needs to have exhaustive information about all sets of equivalent positions that can be found in P . Therefore we define a configuration as a sets of sets of profiles, i.e. an element of the set:

C = 2 2 P
Of course, we are only interested in elements of C that correspond to actual sets of shallow multicontexts. Let k ∈ N and X ⊆ H, we let I k [α, X] be the set of (X, k)-relevant configurations:

I k [α, X] = {V ∈ C | ∃Q ⊆ A + s such that 1. ∀q, q ∈ Q, ∃x, x ∈ q, q s.t. (q, x) ∼ = X k (q , x ) 2. ∀(q, x) ∈ Q there exist (q 1 , x 1 ) ∼ = X k • • • ∼ = X k (q n , x n ) ∼ = X k (q, x) ∈ Q such that {β(q 1 , x 1 ), . . . , β(q n , x n )} ∈ V 3. ∀V ∈ V there exist (q 1 , x 1 ) ∼ = X k • • • ∼ = X k (q n , x n ) ∈ Q such that V = {β(q 1 , x 1 ), . . . , β(q n , x n )} }
Note that condition (1) restricts the definition to sets of shallow multicontexts that are ∼ = X k -equivalent. This will later be necessary when computing the sets of relevant configurations. However, when considering saturation, we will actually work with unions of relevant configurations.

This definition takes care of the quantification over the infinite set of sets of shallow multicontexts in the definition of saturation. One quantification needs to be dealt with: quantification over k ∈ N. We achieve this by defining the set of X-relevant configurations as the intersection of the previous sets for all k:

I[α, X] = k I k [α, X]
We will present an algorithm for computing I[α, X] in the second part of this section. The following fact is immediate from the definitions:

Fact 9.3. For any k, k ∈ N such that k ≤ k and X ⊆ H, I[α, X] ⊆ I k [α, X] ⊆ I k [α, X].
In particular, there exists ∈ N such that for all k ≥ and all X ⊆ H,

I[α, X] = I k [α, X].
Note that while proving the existence of in Fact 9.3 is simple, computing an actual bound on is more difficult and will be a consequence of our algorithm computing I[α, X].

Finally we equip C with a semigroup operation by generalizing the operations + and + r defined on P. Observe that + and + r can be generalized on sets of profiles: we define the sum of two sets as the set of all possible sums of elements of the two sets. If U, V ∈ C, we can now define U + V as the set

{U + V∈V V | U ∈ U} ∪ { U∈U U + r V | V ∈ V}
The following fact can be verified from the definitions. Validity and Reachability for Configurations. Let V be a configuration and let V ∈ 2 P be the union of all sets in V. The set of V-valid forest types is the smallest X ⊆ H such that for every (i,

B s , f H , f V ) ∈ V, f H (H) ⊆ X when i = 0 and f H (X) ⊆ X otherwise. V-valid context types are defined as the smallest Y ⊆ V such that Y • Y ⊆ Y and for all (i, B s , f H , f V ) ∈ V, f V (X) ⊆ Y (with X the set of V-valid forest types).
Finally, given V-valid forest types h and h , we say that h is V-reachable from h iff there exists v ∈ V that is V-valid and such that h = vh . The following fact can be verified from the definitions. Fact 9.5. Let Q be a set of shallow multicontexts such that V = {β(q, x) | (q, x) ∈ Q}.

Then h ∈ H (resp. v ∈ V ) is V-valid iff it is Q-valid. Moreover, for all V-valid h, h ∈ H, h is V-reachable from h iff h is Q-reachable from h .
We say that V is branching iff V contains a profile of arity 2. One can verify that this implies the existence of a maximal V-reachability class denoted H V . Finally, we say that a branching V is reduced when all V-valid forest types are mutually reachable, i.e. H V is the whole set of V-valid forest types.

Profile Saturation. We are now ready to rephrase saturation as a property of the sets

I[α, X]. Set X ⊆ H, we say that a configuration V ∈ C is X-compatible iff it is branching, it is reduced, H V = X and V = i V i with V i ∈ I[α, X] for all i.
Let V be an X-compatible configuration. We say that

v ∈ V is V-saturated iff there exist v 1 • • • v n = v such that:
• for all j, v j is V-valid.

• for all V ∈ V there exists (i, B s , f H , f V ) ∈ V such that either i = 0 (i.e. V abstracts a set of non-port nodes) or v j ∈ f V (H V ) for some j. Let be as defined in Fact 9.3. The following fact is a simple consequence of the definitions.

Fact 9.6. Set X ⊆ H and v be an idempotent of V . For every k ≥ the following properties are equivalent:

(1) There exists a branching and reduced

Q ⊆ A + s such that X = H Q and v is the image of some (Q, k)-saturated context. (2) There exists a X-compatible V ∈ C such that v is V-saturated.
Proof sketch. From top to bottom. Let Q and v be as in (1). Let ∆ be the (Q, k)-saturated context such that α(∆) = v. We construct V and v 1 • • • v n witnessing (2) as follows. To each (q, x) ∈ Q, we associate the set U = {β(q , x ) | (q , x ) ∼ = X k (q, x)}. We then set V as the set of all such sets U. It follows from the definition and Fact 9.5 that H Q = X = H V . Moreover, V is by definition a union of elements of I k [α, X] (and hence of I k [α, X] by definition of k) and is therefore X-compatible. It is then immediate to check that the (Q, k)-saturation of ∆ implies the existence of v 1 • • • v n with the desired properties. Note that we did not use the hypothesis that v is idempotent, it is only required for the other direction.

From bottom to top. Let V and v 1 • • • v n be as required for (2). By definition, we have V = i V i where each V i is H V -relevant and therefore (H V , k)-relevant. This means that for all i, there exists a set of shallow multicontext Q i for V i as in the definition of

I k [α, H Q ]. We set Q = i Q i .
It is immediate from the definition of Q and Fact 9.5 that H Q = X = H V and that v 1 , . . . , v n are Q-valid. We construct the desired (Q, k)-saturated context ∆ as follows. For any node (p, x) ∈ Q, we construct a Q-valid context of type v having a node (p , x ) on its backbone satisfying (p , x ) ∼ = H Q k (p, x). It will then suffice to define ∆ as the concatenation of all these contexts. Since v is idempotent ∆ will have type v as well.

Let (p, x) with p in Q and x a port-node of p, by definition, there exist some i, some V ∈ V i and some (i,

B s , f H , f V ) ∈ V such that (i, B s , f H , f V ) = β(q, y) with (p, x) ∼ = H Q k
(q, y). As x is a port-node, so is y and we have f V (H Q ) = ∅ and therefore by V-saturation of v, we get (i , B s , f H , f V ) ∈ V such that f V (H Q ) contains v j for some j. By definition, we get (p , x ) ∼ =

H Q k (q, y) ∼ = H Q k (p, x) such that β(p , x ) = (i , B s , f H , f V ).
Hence we can create a Q-valid context of type v j , with a unique position (p , x ) on its backbone. Since v 1 , . . . , v n are all Q-valid, this context can then be completed into a Q-valid context of type v which terminates the proof.

We say that α is closed under profile saturation iff for all X ⊆ H, for all X-compatible V ∈ C, for all v ∈ V that are V-saturated and all h 1 , h 2 ∈ H V :

v ω h 1 = v ω h 2
Observe that all quantifications in the definition range over finite sets. Therefore, if one can compute the X-compatible configurations for all X, one can decide closure under profile saturation by testing all possible combinations. In the next proposition, we prove that this is equivalent to testing closure under saturation.

Proposition 9.7. Let α : A → (H, V ) be a morphism into a finite forest algebra. Then the following three properties are equivalent:

(1) α is closed under saturation.

(2) α is closed under -saturation (3) α is closed under profile saturation.

Proof. We prove that 1) ⇒ 3) ⇒ 2) ⇒ 1). That 2) ⇒ 1) is immediate by definition of saturation.

We now prove 1) ⇒ 3). Assume that α is closed under saturation. By Lemma 6.1, α is closed by k-saturation for some k ≥ . We need to prove that α is closed under profile

saturation. Let X ⊆ H, V ∈ C that is X-compatible V ∈ C, v ∈ V that is V-saturated and h 1 , h 2 ∈ H V . Using Fact 9.6, we get Q ⊆ A + s such that H V = H Q and v ω is the image of some (Q, k)-saturated context. It is now immediate from k-saturation that v ω h 1 = v ω h 2 .
It remains to prove that 3) ⇒ 2). Assume that α is closed under profile saturation. We need to prove that α is closed under -saturation. Let Q ⊆ A + s , ∆ that is (Q, )-saturated and h 1 , h 2 ∈ H Q . Using Fact 9.6,we get V ∈ C such that H V = H Q and α(∆ ω ) is Vsaturated. It is now immediate from profile saturation that α(∆) ω h 1 = α(∆) ω h 2 .

In view of Proposition 9.7, it is enough to show that closure under profile saturation is decidable in order to prove Theorem 9.1. Because all the quantifications inside the definition of profile saturation range over finite sets, it is enough to show that those finite sets, namely I[α, X] for all X ⊆ H, can be computed. This is immediate in the case of ranked trees. Indeed for trees of rank l, the set of legal shallow multicontexts is a subset of A l s . Therefore I[α, X] = I l+1 [α, X] can now be computed by considering all the finitely many possible sets Q ⊆ A l s . Hence Theorem 9.1 is proved for regular languages of ranked trees.

In the general case it is not obvious how to compute I[α, X] and this is the goal of the remaining part of this section. 9.2. Computing the Sets of X-indistinguishable Configurations. We present an algorithm which, given as input α : A → (H, V ) and X ⊆ H, computes the set I[α, X]. This is a fixpoint algorithm that starts from trivial configurations corresponding to sets of shallow multicontexts that are singletons composed of a single letter shallow multicontext and saturate the set with two operations.

Our first operation is the semigroup operation on C (recall Fact 9.4) which corresponds to concatenating shallow multicontexts. Our second and most important operation is derived from a well-known property of FO 2 (<) on strings. Let C be a finite string alphabet and let u, u ∈ C + such that u, u both contain all labels in C. Then for all k ∈ N and any

u ∈ C + : (u) k u (u ) k ≡ k (u) k (u ) k
In our case however, the situation will be slightly more complicated as we work with the weaker equivalence ∼ = X k in which tests on labels are relaxed. Remark 9.8. By definition for any V ∈ I[α, X] all profiles contained in sets of V have the same alphabet. Therefore, we will assume implicitly that this is true of all sets of profiles we consider from now and whenever we refer to "the alphabet of V" we mean this common alphabet.

Fixpoint Algorithm. Recall from Fact 9.4 that C is equipped with a semigroup operation. We start with a few definitions about alphabets that we will need in order to present the algorithm. To each alphabet B s ⊆ A s , we associate a configuration B s as follows, An important remark is that while B s is a configuration, in general, it is not an X-relevant configuration (for any X). The main idea behind the fixpoint algorithm is that B s can become X-relevant if one adds "appropriate" X-relevant configurations to its left and to its right. The definition of "appropriate" is based on the notion of X-approximation of an alphabet that we define now.

In the X-relaxed game, there are three types of nodes, port-nodes, X-nodes and Xnodes. Let B s ⊆ A s , and let c, c ∈ B s we say that c, c are B s [X]-equivalent iff c = c or there exists b(2) ∈ B s such that c, c are port-nodes or X-nodes labels of inner label b. Finally, an X-approximation of B s is an alphabet C s ⊆ B s such for any c ∈ B s , there exists c ∈ C s that is B s [X]-equivalent to c.

We can now present the algorithm. Set T[α] ⊆ I[α, X] for all X as the set of configurations associated to sets of shallow multicontexts of the form {c} where c is a single letter in A s . More precisely, T[α] is the set of configurations: {{{β(c, x)}} | c ∈ A s and x the unique position in c} We set Sat[X, α] as the smallest set S ⊆ C containing T[α] and such that:

(1) For all V, V ∈ S, V + V ∈ S.

(2) For all B s ⊆ A s , if V, V ∈ S have (possibly different) alphabets that are both X-approximations of B s , then ωV + B s + ωV ∈ S. where ω = ω(C). Clearly Sat[X, α] can be computed from α. It is connected to

I[α, X] via the proposition below. For U 1 , U 2 ∈ C, we write U 1 U 2 iff (1) For every V 1 ∈ U 1 there exists V 2 ∈ U 2 such that V 1 ⊆ V 2 .
(2) For every

V 2 ∈ U 2 there exists V 1 ∈ U 1 such that V 1 ⊆ V 2 . One can verify that is a preorder. If V ⊆ C , the downset of V is set ↓ V = {V | ∃U ∈ V such that V U}. Fact 9.9. Within C, + is compatible with (i.e. V 1 V 2 and U 1 U 2 implies V 1 + U 1 V 2 + U 2 ).
Proposition 9.10. Let = 2|A s | 2 (|C| + 1) and X ⊆ H, then for any k ≥ :

I[α, X] = I k [α, X] = ↓ Sat[X, α]
It follows from Proposition 9.10 that I[α, X] can be computed for any X ⊆ H. By combining this with Proposition 9.7, we obtain the desired corollary: Corollary 9.11. Let α : A → (H, V ) be a morphism into a finite forest algebra. It is decidable whether α is closed under saturation.

Observe that Proposition 9.10 also contains a bound for in Fact 9.3. This bound is of particular interest: as explained in Proposition 9.7, is also a bound for saturation, if α is closed under saturation, then it is closed under -saturation.

It now remains to prove Proposition 9.10. We prove that for any k

≥ , I[α, X] ⊆ I k [α, X] ⊆ ↓ Sat[X, α] ⊆ I[α, X]. Observe that I[α, X] ⊆ I k [α, X]
is immediate by Fact 9.3. We give the two remaining inclusions their own subsections. 9.3. Proof of Correctness. We prove that Sat[X, α] ⊆ I[α, X]. One can then verify that ↓

I[α, X] = I[α, X] and therefore that ↓ Sat[X, α] ⊆ I[α, X]. Recall that I[α, X] is defined as k∈N I k [α, X]
. This means that it suffices to prove that for all k ∈ N, Sat[X, α] ⊆ I k [α, X]. We fix such a k ∈ N for remainder of the proof.

By definition, T[α] ⊆ I k [α, X] for every k ∈ N. We prove that I k [α, X] is closed under the two operations in the definition of Sat. We begin with Operation (1).

Operation (1). Let V, V ∈ I k [α, X] and let Q, Q be the sets of shallow multicontexts witnessing the membership of V and V in I k [α, X]. Set R = {q + q | q ∈ Q and q ∈ Q }, we prove that R witnesses the membership of V + V in I k [α, X]. This is a consequence of Fact 9.2 and the following lemma: Lemma 9.12. Let (p 1 , x 1 ), (p 2 , x 2 ) ∈ Q such that (p 1 , x 1 ) ∼ = X k (p 2 , x 2 ) and (p 1 , x 1 ), (p 2 , x 2 ) ∈ Q such that (p 1 , x 1 ) ∼ = X k (p 2 , x 2 ). Then if r 1 = p 1 + p 1 and r 2 = p 2 + p 2 , (r 1 , x 1 ) ∼ = X k (r 2 , x 2 ) and (r 1 , x 1 ) ∼ = X k (r 2 , x 2 ) Proof. This is a composition lemma whose proof is immediate using Ehrenfeucht-Fraïssé games.

We have three conditions to check. That (1) holds is immediate from Lemma 9.12. For (2), if (r, x) ∈ R, we have r = p + p with p, p ∈ Q, Q . By symmetry, assume that x ∈ p. By definition of Q, we get (p 1 , x 1 ), . . . ,

(p n , x n ) ∈ Q such that (p, x) ∼ = X k (p 1 , x 1 ) ∼ = X k • • • ∼ = X k (p n , x n ) and V = {β(p i , x i ) | i ≤ n} ∈ V.
Set V as the union of all sets in V and set R as the set of pairs (q, y) such that q = p j + p with j ≤ n and p ∈ Q . By Lemma 9.12 for all (q, y) ∈ R , (r, x) ∼ = X k (q, y). Moreover, one can verify using Fact 9.2 that

β(R ) = V + V ∈ V It remains to verify (3). Set U ∈ V + V . By symmetry, assume that U = V + V with V ∈ V and V the union of all sets of V . By definition of Q, Q there exists (p 1 , x 1 ) ∼ = X k • • • ∼ = X k (p n , x n ) ∈ Q such that V = {β(p i , x i ) | i ≤ n}.
Using the same set R of pairs (q, y) as above we get that all pairs in R are ∼ = X k -equivalent and

β(R ) = V + V = U Operation (2). Let B s ⊆ A s and V, V ∈ I k [α, X]
having alphabets C s , C s that are Xapproximations of B s and let V and V be the unions of all sets in V and V respectively. Let Q and Q be the sets of shallow multicontexts witnessing the membership of V and V into I k [α, X]. Furthermore, set R as the set of all shallow multicontexts of alphabet B s . We prove that P = kωQ+R+kωQ witnesses the fact that kωV + B s +kωV = ωV + B s +ωV belongs to I k [α, X]. Most of the proof is based on the following property of the equivalence ∼ = X k . Lemma 9.13. Let q1 , q2 ∈ kωQ, q1 q2 ∈ kωQ and r 1 , r 2 ∈ R. Then for every nodes x 1 , x 2 of r 1 , r 2 with the same label c ∈ B s

( q1 + r 1 + q1 , x 1 ) ∼ = X k ( q2 + r 2 + q2 , x 2 ) Proof.
We give a winning strategy for Duplicator in the X-relaxed game. We simplify the argument by assuming that q1 = q2 = kωq for some q ∈ Q and that q1 = q2 = kωq for some q ∈ Q . Since all shallow multicontexts in Q (resp. Q ) are ∼ = X k -equivalent (see Item (1) in the definition of I k [α, X]), one can then obtain a strategy for the general case by adapting this special case.

Recall that q (resp. q ) has alphabet C s (resp. C s ) and that C s and C s are Xapproximations of B s . Therefore, using a standard game argument, one can verify that Duplicator can win k moves of the X-relaxed game between (kωq + r 1 + kωq , x 1 ) and (kωq + r 2 + kωq , x 2 ) as long as no safety move is played. In case a safety move is played the X-approximation hypothesis guarantees that r 1 , r 2 of alphabet B s contains the appropriate letter with a port-node label.

We now prove that the set P satisfies the definition of I k [α, X] for kωV + B s + kωV . We have three conditions to verify. That (1) holds is immediate from Lemma 9.13.

For (2), consider (p, x) ∈ P . By definition, p = q + r + q with r ∈ R, q ∈ kωQ and q ∈ kωQ . We treat the case when x ∈ r (the other cases are treated with a similar argument). Let c be the label of x and let (r 1 , x 1 ) . . . (r n , x n ) be all nodes such that r i ∈ R and x i is a node of r i of label c. By definition of B s and R, we have

U = {β(r 1 , x 1 ), . . . , β(r n , x n )} ∈ B s
Let (p 1 , y 1 ) . . . (p m , y m ) be all nodes such that p i ∈ P and y i is a node of label c in the "R-part" of p i . From Lemma 9.13 we have:

(p, x) ∼ = X k (p 1 , y 1 ) ∼ = X k . . . ∼ = X k (p m , y m )
Observe that viewed as nodes of the "R-part" of p i , the nodes y i are exactly the nodes x j . Using Fact 9.2 one can then verify that

{β(p i , y i ) | i ≤ m} = V + r • • • + r V kω times + r U + V + • • • + V kω times ∈ kωV + B s + kωV
It remains to prove (3). Let U ∈ ωV + B s + ωV . Again, we concentrate on the case when

U = V + r • • • + r V kω times + r W + V + • • • + V kω times
with W ∈ R (other cases are treated in a similar way). By definition of B s , we have W = {β(r 1 , x 1 ), . . . , β(r n , x n )} ∈ B s with (r 1 , x 1 ) . . . (r n , x n ) as all nodes such that r i ∈ R and x i is a node of r i of label c for some fixed c. Let (p 1 , y 1 ), . . . , (p m , y m ) ∈ P be all the shallow multicontexts of P such that y i is a node of p i with label c in the "R-part" of p i . By Lemma 9.13, we have (p 1 , y 1 ) ∼ = X k . . . ∼ = X k (p m , y m ) Observe that viewed as nodes of the "R-part" of p i , the nodes y i correspond exactly to the nodes x j . Using Fact 9.2 one can then verify that {β(p i , y i ) | i ≤ m} = U 9.4. Proof of Completeness. Let be defined as in Proposition 9.10. We prove that for any k ≥ , I k [α, X] ⊆ Sat[X, α]. We will need the following definition.

Let k ∈ N, X ⊆ H. To every shallow multicontext q ∈ A + s , we associate a configuration

G k [X](q) ∈ I[α, X]. For any p, x set V p,x = {β(p , x ) | (p, x) ∼ = X k (p , x )}. We set G k [X](q) = {V q,y | y ∈ q}
The following two facts are immediate consequences of the definitions:

Fact 9.14. For all k ≤ k ∈ N, X ⊆ H and q ∈ A + s we have G k [X](q) G k [X](q). Fact 9.15. For all k ∈ N and X ⊆ H we have I k [α, X] = ↓{G k [X](q) | q ∈ A + s }.
We can now finish the proof of Proposition 9.10. The proof is by induction on the size of the alphabet as stated in the proposition below. For the sake of simplifying the presentation, we assume that p can be an empty shallow multicontext denoted 'ε' and that Sat[X, α] contains an artificial neutral element '0' such that G k [X](ε) = 0 for any k. As ε will be the only shallow multicontext having that property this does not harm the generality of the proof.

As explained above, the proof is by induction on the size of B s . The base case happens when B s = ∅. In that case, p = ε and G k [X](ε) ∈ Sat[X, α] by definition. Assume now that B s = ∅, we set k ≥ 2|B s | 2 (|C| + 1) and p as a shallow multicontext containing only labels in B s . We need to prove that G

k [X](p) ∈ ↓ Sat[X, α].
First observe that when p does not contain all labels in B s , the result is immediate by induction. Therefore, assume that p contains all labels in B s . We proceed as follows. First, we define a new notion called a (B s [X], n)-pattern. Intuitively, a shallow multicontext q contains a (B s [X], n)-pattern iff all labels in B s (modulo B s [X]-equivalence) are repeated at least n times in q. Then, we prove that if p contains a (B s [X], n)-pattern for a large enough n, then G k [X](p) can be decomposed in such a way that it can be proved to be in Sat[X, α] by using induction on the factors, and Operations (1) and (2) to compose them. Otherwise, we prove that G k [X](p) can be decomposed as a sum of bounded length whose elements can be proved to be in Sat[X, α] by induction. We then conclude using Operation (1). We begin with the definition of (B s [X], n)-patterns.

(B s [X], n)-patterns. Consider the B s [X]-equivalence of labels in B s and let m be the number of equivalence classes. We fix an arbitrary order on these classes that we denote by C 0 , . . . , C m-1 ⊆ B s . Recall that C s is a an X-approximation of B s iff C s contains at least one element of each class. Let n ∈ N. We say that a shallow multicontext q contains a (B s [X], n)-pattern iff q can be decomposed as

q = q 0 + c 0 + q 1 + c 1 + • • • + q n + c n + q n+1
such that for all i ≤ n, c i ∈ C j (with j = i mod m) and q i is a (possibly empty) shallow multicontext. In particular, the decomposition above is called the leftmost decomposition iff for all i ≤ n no label in C j (with j = i mod m) occurs in q i . Symmetrically, in the rightmost decomposition, for all i ≥ 0, no label in C i (with j = i mod m) occurs in q i+1 . Observe that by definition the leftmost and rightmost decompositions are unique. In the proof, we use the following decomposition lemma.

Lemma 9.17 (Decomposition Lemma). Let n ∈ N. Let q be a shallow multicontext that contains a (B s [X], n)-pattern and let q = q 0 + c 0 + • • • + c n + q n+1 be the associated leftmost or rightmost decomposition. Then

G k [X](q) G k-n [X](q 0 ) + G k-n [X](c 0 ) + • • • + G k-n [X](c n ) + G k-n [X](q n+1 )
Proof. This is a simple Ehrenfeucht-Fraïssé game argument. Because of the missing boundary labels within the q j , using at most n moves, Spoiler can make sure that the game stays within the appropriate segment q j and can use the remaining k -n moves for describing that segment. This finishes the definition of patterns. Set n = m(|C| + 1). We now consider two cases depending on whether our shallow multicontext p contains a (B s [X], 2n)-pattern.

Case 1: p does not contain a (B s [X], 2n)-pattern. In that case we conclude using induction and Operation (1). Let n be the largest number such that p contains a (B s [X], n )pattern. By hypothesis n < 2n. Let p = p 0 +c 0 +• • •+c n +p n +1 be the associated leftmost decomposition. Observe that by definition, for i ≤ n , p i uses a strictly smaller alphabet than B s . Moreover, since p does not contain a (B s [X], n + 1)-pattern this is also the case for p n +1 . Set k = k -n , by choice of k, we have k ≥ 2(|B s | -1) 2 (|C| + 1). Therefore, we can use our induction hypothesis and for all i we get,

G k[X ](p i ) ∈ ↓ Sat[X, α] Moreover, for all i, G k[X ](c i ) ∈ T[α] ⊆ Sat[X, α].
Finally, using Lemma 9.17 we obtain

G k [X](p) G k[X ](p 0 ) + G k[X ](c 0 ) + • • • + G k[X ](c n ) + G k[X ](p n +1 ) From Operation (1) the right-hand sum is in ↓ Sat[X, α]. We then conclude that G k [X](p) ∈ ↓ Sat[X, α] which terminates this case.
Case 2: p contains a (B s [X], 2n)-pattern. In that case we conclude using induction, Operation (1) and Operation (2). By hypothesis, we know that p contains a (B s [X], n)pattern, let p = p 0 + c 0 + • • • + c n + p n+1 be the associated leftmost decomposition. Since p contains a (B s [X], 2n)-pattern, p n+1 must contain a (B s [X], n)-pattern. We set p n+1 = p + c 0 + • • • + c n + p n+1 as the associated rightmost decomposition. In the end we get

p = p 0 + c 0 + • • • + c n + p + c 0 + p 1 + • • • + c n + p n+1
Set k = k -2n and observe that by choice of k, k ≥ 2(|B s | -1) 2 (|C| + 1). Therefore, as in the previous case, we get by induction that for all i, G k

[X ](p i ) ∈ ↓ Sat[X, α], G k[X ](p i ) ∈ ↓ Sat[X, α], G k[X ](c i ) ∈ ↓ Sat[X, α] and G k[X ](c i ) ∈ ↓ Sat[X, α].
Using the same inductive argument for p may not be possible as p might contain all labels in B s .

If p does not contain all labels in B s , then, by induction, G k[X ](p ) ∈ ↓ Sat[X, α] and we can then use Lemma 9.17 as in Case 1 to conclude that G k [X](p) ∈ ↓ Sat[X, α]. Assume now that p contains all labels in B s . Recall that m is the number of B s [X]-equivalence classes. For all j ≤ |C|, set

V j = m-1+jm i=jm (G k[X ](p i ) + G k[X ](c i )) V j = m-1+jm i=jm (G k[X ](c i ) + G k[X ](p i+1 ))
Observe that for all j, by definition V j , V j have an alphabet which is an X-approximation of B s and by Operation (1), V j , V j ∈ ↓ Sat[X, α]. Moreover, it follows from a pigeon-hole principle argument that the sequences V 0 +• • •+V |C| and V 0 +• • •+V |C| must contain "loops", i.e. there exists j 1 < j 2 and j 1 < j 2 such that

V 0 + • • • + V j 1 = V 0 + • • • + V j 2 V j 2 + • • • + V |C| = V j 1 + • • • + V |C| Set U 1 = V 0 + • • • + V j 1 , U 2 = V j 1 +1 + • • • + V j 2 , U 1 = V j 1 + • • • V j 2 -1 and U 2 = V j 2 + • • • + V |C| .
Observe that by Operation (1), we have U 1 , U 2 , U 1 , U 2 ∈ ↓ Sat[X, α] and that by construction the alphabets of U 2 , U 1 are X-approximations of B s . Moreover, a little algebra yields

U 1 = U 1 + U 2 = U 1 + ωU 2 and U 2 = U 1 + U 2 = ωU 1 + U 2 . Set p = p j 2 m + • • • + c n + p + c 0 + • • • + p j 1 m-1
. Observe that by hypothesis on p , p contains all labels in B s . It follows from Fact 9.14 and Lemma 9.17 that

G k [X](p) U 1 + U 2 + G k[X ](p ) + U 1 + U 2 = U 1 + ωU 2 + G k[
G k [X](p) U 1 + ωU 2 + B s + ωU 1 + U 2 ∈ ↓ Sat[X, α]
We conclude that G k [X](p) ∈ ↓ Sat[X, α] which terminates the proof.

Other logics

It turns out that the proof of Theorem 6.2 depends on the horizontal modalities of the logic only via the notion of definability within shallow multicontexts. It can therefore be adapted to many other horizontal modalities assuming those can at least express the fact that two nodes are siblings (ie. can talk about the shallow multicontext of a given node). By tuning this notion one can obtain several new characterizations. We illustrate this feature in this section with the horizontal predicates X h , X h -1 , S and S = , adopting the point of view of temporal logic.

The semantic of these predicates is defined as follows. The formula S = ϕ holds at a node x if ϕ holds at some sibling of x distinct from x. It is a shorthand for F h ϕ ∨ F h -1 ϕ. The formula Sϕ holds at x if ϕ holds at some sibling of x including x. It is a shorthand for ϕ ∨ S = ϕ. The predicates X h and X h -1 are the usual next sibling and previous sibling modalities.

The vertical navigational modalities remain the same and the corresponding logics are denoted by EF + F -1 (S), EF + F -1 (S = ), EF + F -1 (X h , F h , X h -1 , F h -1 ) and a characterization can be obtained for each of them using the same scheme as for EF + F -1 (F h , F h -1 ).

As before EF + F -1 (S = ) and EF + F -1 (X h , F h , X h -1 , F h -1 ) are equivalent to twovariable fragments of first-order logic. EF + F -1 (S = ) has the same expressive power as FO 2 (s, < v ) while EF + F -1 (X h , F h , X h -1 , F h -1 ) corresponds to FO 2 (Succ h , < h , < v ). Here s(x, y) is a binary predicate that holds when x and y are siblings and Succ h is a binary predicate that holds when y is the next sibling of x. These facts can be proved along the same way as the equivalence between FO 2 (< v , < h ) and EF + F -1 (F h , F h -1 ), see Theorem 3.1. Note that this is no longer the case for EF + F -1 (S) as languages defined in this formalism are closed under bisimulation while in the two variable fragment of first-order logic it is possible to have quantifications over incomparable nodes by using the equality and negation which rules out closure under bisimulation.

The proof techniques presented in the previous sections require at least the power of testing whether two nodes are sibling in order to extract a shallow multicontext within a forest. Hence it cannot be applied to FO 2 (< v ) and finding a decidable characterization for this logic remains an open question. Similarly, we rely on the fact that the child relation cannot be expressed and finding a decidable characterization in the presence of this predicate remains also an open question.

As we don't have a vertical successor modality, the characterizations we obtain for EF + F -1 (S), EF + F -1 (S = ) and EF + F -1 (X h , F h , X h -1 , F h -1 ) still require Identity (6.3) on the vertical monoid V of the forest algebra. Identity (6.2) is now replaced by the appropriate identity corresponding to the new horizontal expressive power. Finally the notion of saturation is adapted by replacing ∼ = X k with a notion reflecting the horizontal expressive power of the logic. It is defined as in Section 5 by only modifying the allowed moves in the game in order to reflect the horizontal expressive power of the associated logic (the constraints on the labels remaining untouched within each game). In a similar way, ≡ k is replaced in the proof by the suitable game. Besides these changes at the level of definitions, the characterization is stated and proved as for Theorem 6.2. 10.1. EF + F -1 (S). In this case the games on shallow multicontexts are defined with no navigational constraints on Duplicators moves: Duplicator can respond by choosing an arbitrary node, the restriction being only on its label.

Note that the games no longer depend on k, as only the presence or absence of a given symbol of A s inside the shallow multicontext matters. We write S-≡ and S-∼ = X the equivalence relations resulting from this game and its X-relaxed variant.

The following analog of Claim 5.5 is an immediate consequences of the definitions.

Claim 10.1. Let X ⊆ H and (p, x) be a node. There is a EF + F -1 (S) formula ψ p,x having one free variable and such that for any forest s, ψ p,x holds exactly at all nodes (p , x ) such that (p, x) S-∼ = X (p , x ).

Recall the definition of saturation given in Section 6.2. The notion of S-saturation is obtained identically after replacing ∼ = X k with S-∼ = X . With these new definitions we get: Theorem 10.2. A regular forest language L is definable in EF + F -1 (S) iff its syntactic morphism α : A ∆ → (H, V ) satisfies: Note that (10.1) simply states that the logic is closed under bisimulation, hence reflecting exactly the horizontal expressive power of EF + F -1 (S).

Concerning the proof of Theorem 10.2, aside from the initial choice of the integer k which is no longer necessary here, it is identical to the one we gave for Theorem 6.2 after replacing Lemma 8.1 by the following result: Lemma 10.3. Let L be a language whose syntactic forest algebra satisfies the identities stated in Theorem 10.2. For all shallow multicontexts p S-≡ p and for all forests s, p[s] and p [s] have the same forest type. 10.2. EF + F -1 (S = ) and FO 2 (s, < v ). As before the key point is the allowed moves in the Ehrenfeucht-Fraïssé games. In this case we only require that Duplicator moves in a different position as soon as Spoiler does.

As in the previous section, the games no longer depend on k as it only matters whether or not a label occurs and whether or not it occurs twice. We write S = -≡ and S = -∼ = X the equivalence relations resulting from this game and its X-relaxed variant.

The following analog of Claim 5.5 is an immediate consequences of the definitions.

Claim 10.4. Let X ⊆ H and (p, x) be a node. There is a EF + F -1 (S = ) formula ψ p,x having one free variable and such that for any forest s, ψ p,x holds exactly at all nodes (p , x ) such that (p, x) S = -∼ = X (p , x ).

As in the previous case, replacing ∼ = X k with S = -∼ = X in the definition of saturation yields a new notion of saturation that we call S = -saturation. We can show: Theorem 10.5. A regular forest language L is definable in EF + F -1 (S = ) iff its syntactic morphism α : A ∆ → (H, V ) satisfies: a) H satisfies the identities Notice that (10.2) reflects exactly the horizontal expressive power of EF + F -1 (S = ): no horizontal order and counting up to threshold 2.

Concerning the proof of Theorem 10.5, aside from the initial choice of the integer k which is no longer necessary here, it is identical to the one we gave for Theorem 6.2 after replacing Lemma 8.1 by the following result: Lemma 10.6. Let L be a language whose syntactic forest algebra satisfies the identities stated in Theorem 10.5. For all shallow multicontexts p S = -≡ p and all forests s, p[s] and p [s] have the same forest type. 10.4. Decidability. Deciding whether a regular forest language is definable in EF + F -1 (S) and EF + F -1 (S = ) is simple from Theorem 10.2 and Theorem 10.5. As in Section 9 we prove that the corresponding notions of saturation are equivalent to their abstract variant. The latter are decidable because they don't depend on k and, up to equivalence, only finitely many Q ⊆ A + s needs to be considered. However, for FO 2 (Succ, <), it is not clear how to generalize the construction of the indistinguishable sets. We leave this and the status of deciding definability in FO 2 (Succ h , < h , < v ) as an open problem.

Discussion

We have obtained a characterization for FO 2 (< v , < h ), using identities on the syntactic forest algebra and the new notion of saturation. Our proof technique applies to many other logical formalisms assuming these only differ from FO 2 (< v , < h ) by their horizontal expressive power and that they can at least express the fact that two nodes are siblings.

We have shown all these characterizations to be decidable except for FO 2 (Succ h , < h , < v ). We leave this case as an open problem. As explained in Section 10, it would be enough to generalize our algorithm for computing profiles (i.e. Proposition 9.10) to the appropriate notion of profile for FO 2 (Succ h , < h , < v ).

Since FO 2 (< v ) is unable to express the sibling relation, it cannot be covered by our techniques and we leave open the problem of finding a decidable characterization for this logic.

It would also be interesting to incorporate the vertical successor in our proofs to obtain a decidable characterization for FO 2 (Succ h , < h , Succ v , < v ). This would yield a decidable characterization of the navigational core of XPath. We believe this requires new ideas.

It terms of complexity, a rough analysis of the proof of Theorem 9.1 yields a 4-Exptime upper bound on the complexity of the problem. It is likely that this can be improved. Recall that the complexity of the same problem for the corresponding logics over words, which amounts to checking (6.3), is polynomial is the size of the syntactic monoid.

It would also be interesting to obtain an equivalent characterization of FO 2 (< v , < h ) which remains decidable while avoiding the cumbersome notion of saturation. For instance it is not clear whether the notion of confusion introduced in [BSW12] can be used as a replacement. We leave this as an open problem.

Figure 1 :

 1 Figure 1: Illustration of the notion of context. The squared nodes represent ports. The right part is not a context because the port has a sibling.

Figure 2 :

 2 Figure 2: Illustration of the notion of subtrees and subforests

Figure 3 :

 3 Figure 3: Illustration of a shallow multicontext of arity 3

Figure 4 :

 4 Figure 4: Illustration of the notions of backbone and skeleton.

Figure 6 :

 6 Figure 6: Illustration of the notion of nesting level in the proof of Lemma 7.2.

Figure 7 :

 7 Figure 7: Illustration of the notion of upward number in the proof of Lemma 7.2.

Figure 8 :

 8 Figure 8: Illustration of the Antichain Composition Lemma for Case 1. The marked are the lowest nodes whose subforest contains a shallow multicontext in P

  By definition of P , α(p[s]) ∈ G. As p ≡ k p , by choice of k and Lemma 8.1 we get α(p [s]) = α(p[s]). Hence α(p [s]) ∈ G and p ∈ P .

  the pebbles are on positions z ∈ p and z ∈ p with labels b(2) and b(a) as Duplicator's strategy disallow any other possibility such as b(a), b(a ) where a = a . Is Spoiler selects z , then Duplicator continues to play the isomorphism by leaving the other pebble on z . If Spoiler selects z , observe that since p ∼ = X k+2 p , we can use Claim 5.3 and get a node y ∈ p such that (p , x ) ∼ = X k (p , y ), this is Duplicator's answer. Duplicator can then continue to play by using the strategy given by (p , x ) ∼ = X k (p , y ).

Fact 9

 9 .4. (C, +) is a semigroup.

B

  s = {{β(p, x) | p has alphabet B s and x has label c} | c ∈ B s } ∈ C Observe that for any B s , it is simple to compute B s from α. Indeed, for any c ∈ B s , if y denotes the unique position in the shallow multicontext c, one can verify that, β(p, x) | p has alphabet B s and x has label c = P + r {β(c, y)} + P {v ∈ P | v has alphabet B s }

  Proposition 9.16. Let B s ⊆ A s , k ≥ 2|B s | 2 (|C| + 1) and p a shallow multicontext such that p contains only labels in B s . Then G k [X](p) ∈ ↓ Sat[X, α]. Using Proposition 9.16 with B s = A s , we obtain that for any k ≥ and any p ∈ A + s , we have G k [X](p) ∈ ↓ Sat[X, α]. It then follows from Fact 9.15 that I k [α, X] ⊆ ↓ Sat[X, α] which terminates the proof of Proposition 9.10. It now remains to prove Proposition 9.16. The remainder of the section is devoted to this proof.

  a) H satisfies the identities 2h = h and f + g = g + f (10.1) b) V satisfies Identity (6.3) (uv) ω v(uv) ω = (uv) ω c) the leaf completion of α is closed under S-saturation.

  Proof. Since p S-≡ p the forests p[s] and p [s] contain the same symbols but possibly with a different number of occurrences. It follows from (10.1) that α(p[s]) = α(p [s]).

  3h = 2h and f + g = g + f (10.2) b) V satisfies Identity (6.3) (uv) ω v(uv) ω = (uv) ω c) the leaf completion of α is closed under S = -saturation.

  X ](p ) + ωU 1 + U 2 Moreover, since p has alphabet B s , it is immediate that G k[X ](p ) B s . Therefore, G k [X](p) U 1 + ωU 2 + B s + ωU 1 + U 2 It is now immediate from Operation (2) ωU 2 + B s + ωU 1 ∈ ↓ Sat[X, α]. By combining this with Operation (1), we obtain

Acknowledgment. We thanks the reviewers for their comments on earlier versions of this article. Their comments led to significant improvements of the paper.

(p, x), each subforest in the lower part is below a context that has larger P -depth than v, we will use induction on this parameter. This situation is depicted in Figure 9. Definition of (p, x). Let (p, x) be a port-node in P . We say that (p, x) is P -bad for v iff there exists no P -valid context c satisfying the two following properties:

(1) c P -preserves v.

(2) the port-node (p , x ) above the port of c verifies (p, x) ∼ = X k (p , x ). Lemma 8.9. There exists a port-node (p, x) ∈ P that is P -bad for v.

Proof. This is where Identity (6.3) is used. We proceed by contradiction and assume that no port-node (p, x) ∈ P is P -bad for v.

By definition, for all port-nodes (p, x) ∈ P we get a P -valid context c p,x that P -preserves v and such that the port-node (p , x ) above the port of c p,x verifies (p, x) ∼ = X k (p , x ). Note that since ∼ = X k is of finite index, we may assume that there are finitely many different contexts c p,x for all (p, x) ∈ P . Let ∆ be the context obtained by concatenating all these finitely many contexts c p,x for all (p, x). By definition ∆ is (P, k)-saturated. We use Identity (6.3) to prove that ∆ P -preserves v which contradicts the hypothesis of this case. This is an immediate consequence of the next claim.

Claim 8.10. Let u, u ∈ V such that both u and u P -preserve v. Then uu P -preserves v.

We finish the proof of Lemma 8.9 by proving Claim 8.10. By hypothesis, we have w, w ∈ V that are P -valid and such that vuw = v and vu w = v. Set e = (wu w u) ω , a little algebra yields vue = vu. Applying Identity (6.3), we get that vu = vue = vueu w ue = vuu w ue Hence v = vuu w uew and since w uew is P -valid, this terminates the proof.

Setting-up the Composition. For the remainder of the proof we set (p, x) ∈ P as a port-node which is P -bad for v as given by Lemma 8.9. We define our antichain formula ϕ as the formula holding exactly at all port-nodes (p , x ) such that (p, x) ∼ = X k (p, x ) and having no ancestor with that property. By definition, ϕ is antichain and by Claim 5.5, ϕ is expressible in FO 2 (< v , < h ). We now define the languages L 1 , . . . , L n and K necessary for applying the Antichain Composition Lemma.

Proof. Since p S = -≡ p the forests p[s] and p [s] contain the same symbols with the same number of occurrences up to threshold 2. It follows from (10.2) that α(p[s]) = α(p [s]).

EF

) and FO 2 (Succ h , < h , < v ). In this case Duplicator not only must respect the direction in which Spoiler has moved his pebble, but she also must place her pebble on the successor (predecessor) of the current position if this was also the situation for Spoiler.

The games now depends on k and we write Suc-≡ k and Suc-∼ = X k the equivalence relations resulting from this game and its X-relaxed variant.

The following analog of Claim 5.5 is an immediate consequences of the definitions.

Claim 10.7. Let X ⊆ H and (p, x) be a node. There is a

) formula ψ p,x having one free variable and such that for any forest s, ψ p,x holds exactly at all nodes (p , x ) such that (p, x) Suc-∼ = X k (p , x ). As in the previous cases, we obtain from Suc-∼ = X k a new notion of saturation that we call X h -saturation. We can show: Theorem 10.8. A regular forest language L is definable in FO 2 (Succ h , < h , < v ) iff its syntactic morphism α : A ∆ → (H, V ) satisfies: a) H satisfies for all h, g ∈ H, for all e ∈ H such that 2e = e: ω(e + h + e + g + e) + g + ω(e + h + e + g + e) = ω(e + h + e + g + e)

(10.3) b) V satisfies Identity (6.3) (uv) ω v(uv) ω = (uv) ω c) the leaf completion of α is closed under X h -saturation. Equation (10.3) is extracted from the following result which is essentially proved in [START_REF] Thérien | Over words, two variables are as powerful as one quantifier alternation[END_REF] based on a result of [START_REF] Almeida | A syntactical proof of locality of DA[END_REF] (see Footnote on page 9). Theorem 10.9 ([TW98], [START_REF] Almeida | A syntactical proof of locality of DA[END_REF]). A regular string language L is definable in FO 2 (Succ, <) iff its syntactic semigroup S satisfies for all u, v ∈ S, for all e ∈ S such that e 2 = e:

(eueve) ω v(eueve) ω = (eueve) ω Again, the proof of Theorem 10.8 follows the lines of the proof of Theorem 6.2 after replacing Lemma 8.1 by the following simple result: Lemma 10.10. Let L be a language whose syntactic forest algebra satisfies the identities stated in Theorem 10.8. There exists a number k such that for all k ≥ k , all shallow multicontexts p Suc-≡ k p and all forests s, p[s] and p [s] have the same forest type.

Proof. This is a consequence of the fact that H satisfies Identity (10.3). The proof is identical to the one we provided for Lemma 8.1 replacing Theorem 4.2 by Theorem 10.9 and ≡ k with Suc-≡ k .