Reasoning about integrity constraints for tree-structured data

We study a class of integrity constraints for tree-structured data modelled as data trees, whose nodes have a label from a finite alphabet and store a data value from an infinite data domain. The constraints require each tuple of nodes selected by a conjunctive query (using navigational axes and labels) to satisfy a positive combination of equalities and a positive combination of inequalities over the stored data values. Such constraints are instances of the general framework of XML-to-relational constraints proposed recently by Niewerth and Schwentick. They cover some common classes of constraints, including W3C XML Schema key and unique constraints, as well as domain restrictions and denial constraints, but cannot express inclusion constraints, such as reference keys. Our main result is that consistency of such integrity constraints with respect to a given schema (modelled as a tree automaton) is decidable. An easy extension gives decidability for the entailment problem. Equivalently, we show that validity and containment of unions of conjunctive queries using navigational axes, labels, data equalities and inequalities is decidable, as long as none of the conjunctive queries uses both equalities and inequalities; without this restriction, both problems are known to be undecidable. In the context of XML data exchange, our result can be used to establish decidability for a consistency problem for XML schema mappings. All the decision procedures are doubly exponential, with matching lower bounds. The complexity may be lowered to singly exponential, when conjunctive queries are replaced by tree patterns, and the number of data comparisons is bounded.


Introduction
Static analysis is an area of database theory that focuses on deciding properties of syntactic objects, like queries, integrity constraints, or data dependencies.The unifying paradigm is that because these objects are mostly usergenerated, they tend to be small; hence, higher complexities are tolerable.The fundamental problems include satisfiability, validity, containment, and equivalence of queries [9,25], as well as consistency and entailment of integrity constraints [16,28].More specialized tasks include query rewriting in data integration scenarios [24], and manipulating schema mappings in data exchange and schema evolution scenarios [1,15].Many of these problems are equivalent to satisfiability of fragments of first order logic, possibly over a restricted class of structures, but they are rarely presented this way, because the involved fragments are tailored for specific applications, and usually do not form natural sublogics.As satisfiability over arbitrary structures is undecidable even for relatively simple fragments of first order logic, in static analysis undecidability is always close [19,20].
In this paper we present a decidability result (with tight complexity bounds) for a problem in static analysis for tree-structured data.The specific model we consider is that of data trees: finite ordered unranked trees whose nodes have a label from a finite alphabet and store a data value from an infinite data domain.The problem has three possible interpretations: consistency modulo schema for a class of integrity constraints; validity modulo schema for a class of queries; and consistency for a class of schema mappings.
The more general problems of entailment (or implication) of constraints and containment of queries are-as is often the case-very close to their restricted counterparts listed above, and can be solved by easy modifications of our decision procedure.
Our basic setting is that of consistency of integrity constraints; it seems best suited for proofs and-in combination with entailment-the most appealing.We consider non-mixing constraints of the forms α(x) ⇒ η ∼ (x) and α(x) ⇒ η (x) that require each tuple x of nodes selected by α to satisfy, respectively, a positive combination of equalities η ∼ or a positive combination of inequalities η over the stored data values.As tuple selectors α(x) we use conjunctive queries over the signature including label tests and the usual navigational axes.For example, the constraint a(x) ∧ x ↓ y ∧ x ↓ y ∧ y → + y ⇒ y y expresses that different children of the same a-labelled node store different data values, and the constraint a(x) ∧ x ↓ y ∧ x ↓ y ∧ x ↓ y ⇒ y ∼ y ∨ y ∼ y ∨ y ∼ y expresses that at most two different data values are used by children of each alabelled node.The consistency problem is to decide if there exists an instance of a given schema that satisfies a given set of constraints.In the example above, there exists an instance satisfying both constraints if and only if the schema allows trees without a-labelled nodes with more than two children.What is the expressive power of non-mixing constraints?Let us first look at what they cannot do.Being first-order constraints, they cannot compare full subtrees, unlike some other formalisms [21,22].They have purely universal character (can be written as universal sentences of first order logic), so they cannot express general inclusion dependencies nor foreign keys, as these need quantifier alternation.Finally, the inability to mix freely data equalities and inequalities within a single constraint makes them unable to express general functional dependencies.What can they do, then?
Non-mixing integrity constraints can be seen as a special case of the general framework of XML-to-relational constraints (X2R constraints) introduced by Niewerth and Schwentick [27].Within this framework they cover a wide subclass of functional dependencies, dubbed XKFDs, which are particularly well suited for tree-structured data.They include W3C XML Schema key and unique constraints [18], as well as absolute and relative XML keys by Arenas, Fan, and Libkin [2], and XFDs by Arenas and Libkin [3].XKFDs can be expressed with non-mixing constraints of the form α(x) ⇒ η (x); that is, using only data inequalities.
Constraints of the form α(x) ⇒ η ∼ (x)-that is, using only equalities-can express all sorts of finite data domain restrictions, either to a specific set of constants or to a set of data values taken from the data tree (the latter can be seen as a limited variant of inclusion constraints), as well as cardinality restrictions over data values (like in the example above).
The novelty of our work is that we allow these two kinds of constraints simultaneously.Unrestricted mixing of data equalities and inequalities in constraints would immediately lead to undecidability [6], but for non-mixing constraints we can show decidability of the consistency problem, and a slight extension of the proof gives decidability for entailment (with the same complexity bounds).
Our approach leads through a simple model property, which asserts that a set of constraints is satisfiable if and only if it has a model of bounded data cut [7]; that is, the number of data values shared by any subforest of the model and its complement is bounded.This property can be seen as a strengthening of the bounded clique-width property [11], in which decompositions must follow the structure of data trees.The robustness of our approach is witnessed by the fact that it can be naturally extended to constraints in which tuple selectors α(x) are expressed in monadic second order logic (MSO) using label tests and navigational predicates.At the core of our argument lies a simple lemma of geometric nature.
Under the second interpretation our result shows decidability of validity and containment for unions of conjunctive queries where each conjunctive query can use either data equality or inequality, but never both.Seen this way, our result is a uniform extension of decidability results for UCQs using only data equality, and UCQs using only data inequality by Björklund, Martens and Schwentick [6] (see also [12]).However, it cannot be obtained via a combination of techniques used in these cases, as they are virtually contradictory: they require assuming that almost all data values in counter-examples are, respectively, different and equal.If data equalities and inequalities are mixed freely in UCQs, even validity is undecidable [6].
In its third incarnation, our result gives decidability of the consistency problem for XML schema mappings with source integrity constraints, which asks to decide if there exists a source instance which satisfies the integrity constraints and admits a target instance satisfying the requirements imposed by the schema mapping.
In all three cases (excluding the unsurprisingly non-elementary MSO extension), the decision procedure is doubly exponential.This bound is tight, as already validity modulo schema for UCQs over trees without data values is 2ExpTime-complete [6].We show that restricting the CQs to tree patterns does not help.However, the complexity does drop to ExpTime-complete when we replace CQs with tree patterns and bound the number of variables used in data comparisons.
A broader context for our work is the rich landscape of results on static analysis for the popular XML query language XPath [5,26] and related formalisms like alternating register automata [17,23] or the two-variable fragment of first order logic with data comparisons [8].These formalisms do not compare easily with ours.Arbitrary alternation of quantifiers (implicit, in the case of XPath) lets them reach far beyond conjunctive queries.But the restriction on the number of registers or variables (reflected in the the syntax of XPath) limits data comparisons: one cannot compare data values from too many nodes at the same time.In their basic form, our results imply decidability (with the same tight complexity bounds) of the containment problem in the presence of a schema for unions of XPath queries without negation, where each query uses either equality or inequality, but never both.The extension to MSO constraints allows free use of negation as long as data comparisons are not used under negation.
The remainder of the paper begins with a precise definition of non-mixing constraints and a short discussion of their scope (Section 2).Then we present the decision procedure for consistency of non-mixing constraints and show its optimality (Section 3).We continue with a potpourri of extensions and connections: the entailment problem (Section 4.1), the lower-complexity fragment (Section 4.2), the relationships with existing constraint formalisms (Section 4.4), the two alternative interpretations of our results (Section 4.3 and 4.5), a comparison with clique-width (Section 4.6), and the MSO extension (Section 4.7).We conclude with a brief discussion of further possible extensions and open questions (Section 5).This is an extended version of an 18-pages-long paper under the same title presented at ICDT 2016.The new material includes full proofs of all results, as well as the comparison with clique-width and the MSO extension.There is ... ... also a major difference in the way the proof of the main result is presented.In the conference version, register tree automata are used to recognize witnesses for consistency of bounded data cut.Here, we encode such witnesses as trees over a finite alphabet and use ordinary tree automata.The new formulation encapsulates reasoning about data values within the encoding, and harmonizes with the clique-width approach and the MSO extension.

Preliminaries
Let us fix a finite labelling alphabet Γ and a countably infinite set of data values D. A data tree t is a finite ordered unranked tree whose nodes are labelled with elements of Γ by function lab t : dom t → Γ , and with elements of D by function val t : dom t → D; here, dom t stands for the domain of tree t, that is, the set of its nodes.If lab t (v) = a and val t (v) = d, we say that node v has label a and stores data value d.A data forest f is a sequence of data trees whose roots are considered siblings (with the inherited order); lab f , val f , and dom f are defined naturally.While each data tree contains at least the root, a data forest can be empty.For a node v of t, we write t v for the data forest consisting of subtrees of t rooted at v itself and at all preceding siblings of v; by slight abuse of notation we write t − t v for the remaining part of t (see Figure 1 for illustration).For a forest f we use the analogous notation, f v and f − f v .We abstract schemas as tree automata in the "previous sibling, last child" variant.A tree automaton A is a tuple (Q, q 0 , F, δ), where Q is a finite set of states, q 0 ∈ Q is an initial state, F ⊆ Q is a set of accepting states, and δ ⊆ Q×Q×Γ ×Q is a set of transitions.During the computation the automaton assigns a state to each node v of the input tree t, based on the accumulated information about t v .More precisely, the state for the node v depends on the label of v and the states from the previous sibling and the last child of v.In leftmost siblings and in leaves we resort to imaginary nodes outside of the actual tree t, which are always assigned the initial state q 0 .Formally, let dom cl t be the set containing each node of t, an artificial previous sibling for each leftmost sibling in t, and an artificial (last) child for each leaf in t.A run of A on t is a function ρ : dom cl t → Q such that ρ(v) = q 0 for every node v ∈ dom cl t − dom t , and for every node v ∈ dom t with previous sibling v ps and last child v lc there is a transition (ρ(v ps ), ρ(v lc ), lab t (v), ρ(v)) ∈ δ.A run ρ is accepting if it assigns a state from F to the root of t, and a tree t is accepted by A if it admits an accepting run.Runs on forests are defined entirely analogously; acceptance is based on the state in the root of the last tree (if the forest is empty, we take the initial state q 0 ).An automaton is Each deterministic automaton has a unique run on each tree (and forest), and can be complemented (negated) simply by replacing the set of final states F with its complement Q − F .
To facilitate the use of the standard first order semantics, we model data trees and data forests as relational structures over signature Signature sig dt is infinite (because of D and Ď), but queries use only finite fragments.We include Ď in the signature to keep negation out of the syntax.

Definition
In their most general form, non-mixing integrity constraints σ are formulas of the form where α(x) is a conjunctive query over the signature sig nav = {↓, ↓ + , →, → + }∪Γ ; η ∼ (x) is a finite positive Boolean combination of atoms over the signature sig ∼ = {∼} ∪ D and variables x; η (x) is a finite positive Boolean combination of atoms over the signature sig = { } ∪ Ď and variables x.
Query α is called the selector of σ, and η ∼ , η are its assertions.Non-mixing constraints have the usual semantics of first order logic formulas: a data tree t satisfies constraint σ, denoted t |= σ, if each tuple v of nodes of t selected by α satisfies both η ∼ and η ; that is, For a set Σ of non-mixing constraints, we write Consequently, each set Σ of non-mixing constraints is equivalent to Σ ∼ ∪ Σ , where Σ ∼ is a set of constraints of the form α ⇒ η ∼ , Σ is a set of constraints of the form α ⇒ η , and the sizes of Σ ∼ and Σ are bounded by the size of Σ.Thus, without loss of generality, we restrict our attention to sets of constraints of the form Σ ∼ ∪ Σ , which do not mix sig ∼ and sig (hence "non-mixing").One can also assume that α is quantifier free:

Scope
Using non-mixing constraints one can express a variety of useful constraints.Let us consider a database storing information about banks, each in a separate sub-document.We want each bank to be identified by its BIC number.This key constraint can be expressed as where q bic selects the root of the sub-document for bank, and the node storing the BIC number.Depending on the schema, query q bic could be for instance q bic (x, x ) = bank(x) ∧ x ↓ x ∧ BIC(x ).Node inequality = is not part of the signature, but can be expressed using sig nav .Assuming that the roots of the sub-documents for banks are siblings, x = y can be replaced by x → + y.
In general, we also need to consider four other possible ways in which two different nodes x and y can be positioned in a tree (up to swapping x and y): which means that we need five non-mixing constraints to express a single key constraint.
Another natural constraint is that account numbers should be different for every account within the same bank, but different banks may use the same account numbers.Such a relative key constraint can also be expressed as where q acc (x, x ) selects account x and its number x , similarly to q bic .
We can also express multi-attribute keys (i.e.keys using composite fields).For example asserts that BIC and account number form an absolute key, not relative to bank sub-document.
If, as a result of redundancy, BIC appears in several places within a bank sub-document, using the singleton constraint bank we can guarantee that each time it gives the same value (for the same bank).
Assume now that each bank has a director and several branches, each of them having a team of employees among which one is the manager of the branch.The information about each employee is stored in a sub-document of its branch's sub-document.Each employee reports either to the manager of the branch or directly to the director of the bank.Using a conjunctive query q super (x, y, z), we can select the director's ID node x, the branch manager's ID node y and the node z storing the supervisor's ID for an employee of the same branch.The constraint on employee's supervisor can be encoded as Following this idea we can express inclusion constraints of a restricted form, where the intended superset is a tuple of values that can be selected by a conjunctive query.This includes enumerative domain restrictions, like the constraint ensuring that banks issue only Visa, Master Card, and American Express cards.Unrestricted inclusion constraints are beyond the scope of our formalism.Indeed, non-mixing constraints cannot be violated by removing nodes, which is not the case even for the simplest unary inclusion constraints, like each value stored in an a node is also stored in a b node.
Our formalism is also capable of expressing cardinality constraints.Assume, for instance, that banks support charity projects by delegating their employees to help.The projects are organized by category (culture, education, environment, etc.) and each project sub-document carries the list of involved employees.For the sake of balance, we want each category to involve at most ten different employees in total.This can be imposed by selecting eleven employee nodes below a single category node and imposing at least two of them to carry the same data value by means of a long disjunction of data equalities.We can also ensure that no employee is involved in more than three different projects: the conjunctive query selects four different project nodes and an employee for each of them; the assertion imposes at least two of the four employees to have different ID.
Let us remark that while these constraints look clumsy expressed as nonmixing constraints, one can easily imagine a syntactic-sugar layer on top of our formalism.The point is that all these constraints can be rewritten as nonmixing constraints of linear size (except for the cardinality constraints, where the size would grow by a factor proportional to the numerical bounds).
In Section 4 we examine the expressive power of non-mixing constraints further by comparing them to other existing formalisms.

Consistency problem
Our main result is decidability of the consistency problem for non-mixing constraints:

Problem: Consistency of non-mixing constraints
Input: A set Σ of non-mixing constraints, a tree automaton A. Question: Is there a data tree t ∈ L(A) such that t |= Σ ?More precisely, we show the following theorem, establishing tight complexity bounds.
Theorem 1 Consistency of non-mixing constraints is 2ExpTime-complete.
The reminder of this section is devoted to the proof of Theorem 1.The proof is based on a simple idea with a geometric flavour, but does not require any specialist knowledge from geometry or linear algebra.Consider a family of finite unions of affine subspaces of an Euclidean space.The intersection of this family can be also represented as a finite union of affine subspaces and we show that their number can be bounded independently of the cardinality of the family.From this bound we infer a "bounded data cut" model property for non-mixing constraints, where by data cut of a data tree t, denoted by datacut(t), we mean the maximum over nodes v ∈ dom t of the number of data values shared by t v and t − t v .With bounded data cut, we can reduce the consistency problem to the emptiness problem for tree automata (over a finite alphabet).In the final subsection we prove the lower bound.

Intersecting unions of subspaces
By a subspace of D we mean a subset of D defined by equating pairs of coordinates and fixing coordinates; that is, it is a set of points (x 1 , x 2 , . . ., x ) in space D defined by a conjunction of equalities of the form x i = x j or x i = d where d ∈ D. By simple rewriting of equalities, each nonempty subspace of D can be defined with a canonical set of at most equalities such that for each coordinate i we have either x i = x j with i < j, or x i = d with d ∈ D, or nothing; each coordinate j occurs at most once on the right side of an equality; and no data value d is used in more than one equality.
A subspace of D has dimension k if its canonical definition consists of − k equalities.In other words, each equality that does not follow from the others decreases the dimension by one.To enhance intuitions, let us remark that if we equip D with the structure of linear space by assuming that D is a field, this notion of dimension coincides with the classical notion of dimension for affine subspaces (of which the subspaces above are a special case).
An intersection X ∩ Y of subspaces X, Y is also a subspace, defined by the conjunction of conditions defining X and Y .If X ⊆ Y , then the canonical definition of X ∩ Y contains at least one more equation than that of X; consequently, the dimension of X ∩ Y is strictly smaller than the dimension of X.Similarly, intersecting unions of subspaces, we obtain a union of subspaces; the following lemma gives a bound on the size of such union.
where some of subspaces Y k may be empty.We have where each X j ∩ Y k is either empty or has dimension strictly smaller than X j .Thus, when X 1 ∪ X 2 ∪ • • • ∪ X p is intersected with Z i , each X j either does not change, or is split into at most n subspaces of strictly smaller dimension; if X j is a point, in the second possibility it disappears.Now, consider the following process: begin with D , a single subspace of dimension , and then intersect with Z i for i from 1 to m, one by one.Since with each split, the dimension strictly decreases, each non-empty subspace in the resulting union is obtained in the course of at most splits.Since each split generates at most n subspaces, we cannot obtain more than n subspaces in this process.
We remark that the bound in Lemma 1 is tight, as shown by the following example.

Bounding the data cut
Based on the geometric fact we have proved in the previous subsection, in Lemma 3 we bound the data cut of data trees witnessing consistency of nonmixing constraints.The proof relies on a simple compositionality property for conjunctive queries over trees, shown in Lemma 2.
Lemma 2 Let α(x, ȳ) be a conjunction of atoms over sig nav , where x and ȳ are disjoint, and let w be a node of a data tree t.For all tuples ū, ū of nodes from t w and tuples v, v of nodes from t − t w , if Proof Let ū, ū , v, v be as in the statement of the lemma.Since α(x, ȳ) is a conjunction of atoms, we only need to check that each atom of α(ū, v ) and α(ū , v) is satisfied in t.Given that t |= α(ū, v) and t |= α(ū , v ), it is enough to examine atoms using variables from both x and ȳ.That excludes unary relations and leaves us with atoms of the forms x i ↓ y j , x i ↓ + y j , x i → y j , x i → + y j , and symmetrical.Given that variables x are matched within t w , and variables ȳ are matched within t − t w , atoms x i ↓ y j , x i ↓ + y j , y j → x i , and y j → + x i are excluded by the combination of two things: the way t w and t − t w are positioned within tree t (see Figure 1 on page 5), and the fact that t |= α(ū, v).That is, it remains to consider y j ↓ x i , y j ↓ + x i , x i → y j , and x i → + y j .Suppose y j ↓ x i occurs in α.We know that v j ↓ u i and v j ↓ u i .Since nodes u i , u i are from t w and nodes v j , v j are from t−t w , it follows immediately that v j and v j are equal to the parent of node w, and u i , u i are siblings of w or w itself.Consequently, v j ↓ u i and v j ↓ u i .For the remaining three kinds of atoms the reasoning is similar.If v j ↓ + u i and v j ↓ + u i , then v j , v j are ancestors of w and u i , u i are nodes in t w , so v j ↓ + u i and v j ↓ + u i follows.
If u i → v j and u i → v j , then u i = u i = w and v j = v j is w's next sibling.Finally, if u i → + v j and u i → + v j , then u i , u j are preceding siblings of w (or w itself) and v j , v j are following siblings of w.
Lemma 3 If Σ ∼ ∪ Σ is satisfied in a data tree t, it is also satisfied in some data tree t obtained from t by changing data values, such that where and m are the maximal numbers of, respectively, variables and predicates from D ∪ Ď in the constraints from Σ ∼ .
Proof Assume that t |= Σ ∼ ∪ Σ .We show that for each node w of the data tree t, one can replace all but distinct fresh data values without violating Σ ∼ ∪ Σ .After this operation is performed for a node w, the number of data values used both in t w and t − t w is bounded by Moreover, as the fresh data values are to be distinct, the new ∼ relation over nodes of t is a subset of the old one.In consequence, the operation does not increase the number of data values shared by t w and t − t w for other nodes w .Consequently, applying this operation for each node of t in an arbitrary order, we obtain a model of bounded data cut.
Let us fix a node w of t.As long as the fresh values are pairwise different, the obtained tree will still satisfy Σ .Hence, we only need to ensure that Σ ∼ is not violated.Consider a constraint α ⇒ η ∼ in Σ ∼ .Recall that we assume that α is quantifier free.Let x, ȳ be a partition of variables used in α (one of the tuples x, ȳ may be empty).We shall indicate the partition of variables by writing the constraint as α(x, ȳ) ⇒ η ∼ (x, ȳ).The intended meaning is that the variables x refer to nodes in t w , and the variables ȳ refer to nodes outside of t w .Directly from the definition it follows that t |= α ⇒ η ∼ , if and only if for each partition x, ȳ of variables in α, for each tuple ū of nodes from t w and each tuple v of nodes from Fix a partition x, ȳ.By Lemma 2, the condition above is equivalent to: for all tuples ū, ū of nodes from t w and all tuples v, v of nodes from t − t w , if t |= α(ū, v) and t |= α(ū , v ), then t |= η ∼ (ū, v ).Let us turn this into a condition on stored data values.Define η(x, ȳ) as the formula obtained from η ∼ (x, ȳ) by replacing ∼ with =, and d(z) with z = d for all variables z and all d ∈ D. Reformulating the condition above we obtain: for each tuple ū of nodes from t w such that t |= α(ū, v) for some tuple v of nodes from t − t w , the tuple val t (ū) of data values belongs to the set where v ranges over tuples of nodes from t − t w satisfying t |= α(ū , v ) for some tuple ū of nodes from t w .
Writing η(x, val t (v )) in the disjunctive normal form, we see that the set c ∈ D |x| η(c, val t (v )) is a union of subspaces of D |x| .How many subspaces?The canonical definition of each nonempty subspace has for each coordinate i either an equality x i = x j for some j > i, or an equality x i = d for some d ∈ D, or nothing.In our case, d is a data value used explicitly in η or occurring in the data tuple val t (v ).Consequently, the number of these subspaces can be bounded by (N + |x| + |ȳ|) |x| , where N is the number of data values used explicitly in η.That is, Z α(x,ȳ)⇒η∼(x,ȳ) is an intersection of unions of at most (N + |x| + |ȳ|) |x| subspaces of D |x| .By Lemma 1, it can be represented as a union of at most (N + |x| + |ȳ|) |x| 2 subspaces.In the canonical definition of each of these subspaces, there are at most |x| equalities of the form values.From this we shall derive a bound on the number of important data values in t w that ensure satisfaction of Σ ∼ , and conclude that we can safely replace others with fresh ones.
Let val : dom t → D be a new data labelling of t.As we are only going to change data values in t w , keeping a constraint α ⇒ η ∼ satisfied requires only that for each partition x, ȳ of its variables, for each tuple ū of nodes from t w , if t |= α(ū, v) for some tuple v of nodes from t−t w , then val (ū) ∈ Z α(x,ȳ)⇒η∼(x,ȳ) .Moreover, replacing all occurrences of a data value d in t w with a given data value d does not affect equalities of the form x i = x j in the canonical definition of the set Z α(x,ȳ)⇒η∼(x,ȳ) .We only need to ensure that equalities of the form x i = d are not violated.Let D ⊆ D be the set of data values occurring in these equalities for all sets Z α(x,ȳ)⇒η∼(x,ȳ) , with α(x, ȳ) ⇒ η ∼ (x, ȳ) ranging over constraints from Σ ∼ with all possible partitions of variables.A labelling val that replaces each data value from D − D used in t w with a fresh data value does not violate Σ ∼ .For each constraint α ⇒ η ∼ there is at most 2 partitions x, ȳ of variables; each partition corresponds to a set Z α(x,ȳ)⇒η∼(x,ȳ) , which contributes at most • (m + ) 2 data values, where and m are the maximal numbers of variables and predicates from D ∪ Ď in constraints from Σ ∼ .Hence, we have

From bounded data cut to automata
In order to use automata, we need to encode data trees of bounded data cut as trees over a finite alphabet.Let C, D ⊆ D be two disjoint finite sets of data values; we shall call elements of C colours and elements of D distinguished data values.As encodings we shall use trees over the alphabet we shall refer to the values in the third component of label as refresh sets.
The distinguished data values (corresponding to data values used explicitly in the constraints) are represented explicitly in the encoding.The remaining data values are represented implicitly by colours and refresh sets: two nodes u, v store the same data value if and only if they have the same colour c and there is no node w such that u ∈ t w and v ∈ t − t w (or symmetrically), and the refresh set for w contains c.We define the semantics of the encoding slightly more generally: to every forest f over the alphabet Γ × (C ∪ D) × P(C) we associate a data forest f .It has the same domain as f , the structure and labelling with elements of Γ is inherited from f , and the assignment of data values is defined inductively based on the remaining two components of the labelling of f .If the forest f is empty, so is f .Otherwise, let us decompose f into a forest f followed by a tree further decomposed into the root and a forest f (see Figure 2); both f and f may be empty.Assume the root has label (a, d, R).The forest f is obtained by plugging f under a root with label a and data value d, appending the resulting tree to f , and then replacing each colour from the refresh set R used in the resulting forest with a globally fresh data value from D − (C ∪ D).Note that f is unique up to permutations of Proof Since we only aim at equality modulo a permutation of D − D, we may assume that no data value from C is used in f .As the structure of g must be identical to that of f , we only need to define the labelling.Moreover, in the label (a, d, R) of a node w, we must always have a = lab f (w).The remaining two components, d and R, are defined in the course of a procedure processing nodes in the usual bottom-up, left-to-right order, maintaining the following invariants: 1. g w = f w up to a bijection i w between the colours from C used in g w and the data values from D − D shared by f w and f − f w ; 2. if v is the last child of the next sibling of w, then i v and i w coincide over dom(i v ) ∩ dom(i w ), and For a node w the procedure first sets the values d and R in such a way that the first invariant is satisfied, and then applies a permutation of C to the whole g w to ensure the second invariant.Note that applying such a permutation affects g w , but does not violate the first invariant.
Let w and w be the previous sibling and the last child of w (if some of these do not exist, the argument is adjusted easily).For d there are three cases: which exists by the second invariant.
The refresh set R contains each colour c ∈ C currently used in g w , that represents a data value occurring in f w but not in f − f w .After these colours have been refreshed, all colours C 0 ⊆ C used in g w represent different data values shared by f w and f − f w ; the bijection i w can be defined by restricting to C 0 the union of i w , i w , and If w has no next sibling or the next sibling has no children, we are done.Otherwise, let v be the last child of the next sibling u of w.We need a permutation π of C such that i v and the updated bijection i w • (π C 0 ) −1 satisfy ... ... ... Fig. 3 The positioning of fw, fv, and f − (fw ∪ fv) in a forest f , when v is the last child of the next sibling u of w.
the second invariant.Let W, V, U ⊆ D − D be the sets of data values used, respectively, in the fragments f w , f v , and f − (f w ∪ f v ) shown in Figure 3, and By the definition of data cut applied to w, v, and u, we have where e = 1 if the data value in u is used in f − f u and does not belong V ∪ W , and e = 0 otherwise.In order to represent values in W ∩ U , V ∩ U , and W ∩ V , we need exactly k + + m + r colours.By adding the three inequalities above, we obtain that k . Hence, 3  2 • n colours are sufficient to accommodate the domains of i v and the updated bijection As the bounds in the three inequalities above can be attained simultaneously, with r = 0 and e = 0, 3  2 • n colours are also necessary.Consequently, the assumption in the lemma is tight, because if the data value in the node w does not occur anywhere else, we need one more colour to represent it.
Let Σ ∼ ∪ Σ be a set of non-mixing integrity constraints and let A be a tree automaton.By Lemma 3, it is enough to test satisfiability of Σ ∼ ∪Σ over trees of data cut bounded by a number n, singly exponential in the total size of constraints in Σ ∼ ∪ Σ .Let D ⊆ D be the set of data values used explicitly in Σ ∼ ∪ Σ , and let C ⊆ D − D be a fixed set such that |C| = 3 2 • n + 1.By Lemma 4, each tree of data cut bounded by n can be encoded as a tree over Γ × (C ∪ D) × P(C) up to a permutation of D − D. Since such permutations do not affect relations used in Σ ∼ ∪ Σ , there exists a data tree accepted by A and satisfying Σ ∼ ∪ Σ if and only if there exists a tree t such that the data tree t is accepted by A and satisfies Σ ∼ ∪ Σ .We reduce consistency of Σ ∼ ∪ Σ to the emptiness problem for tree automata, by constructing an automaton that recognizes such trees t.
The automaton is obtained by taking the product of two automata, testing acceptance by A and satisfaction of Σ ∼ ∪Σ , respectively.The first automaton is just the automaton A lifted to the product alphabet Γ × (C ∪ D) × P(C): it looks only at the first component of each label.Note that already this automaton has doubly exponential size, because of the size of the alphabet.The second automaton is the product over all constraints σ ∈ Σ ∼ ∪ Σ of automata B σ recognizing trees t such that t |= σ, which will be constructed in the next subsection.Each automaton B σ is doubly exponential and so is the whole construction.As the emptiness problem for tree automata is in PTime, we can conclude that the consistency problem is in 2ExpTime.

Translating constraints to automata over encodings
To complete the proof of the upper bound of Theorem 1, it remains to construct an automaton recognizing encodings of trees that satisfy a given constraint.
Let us fix a constraint α(x) ⇒ η(x) with x = (x 1 , x 2 , . . ., x ); for the present construction, it needs not to be non-mixing.Let D ⊆ D be a finite set of data values, containing each data value used explicitly in η(x), and let C ⊆ D − D be an arbitrary finite set.We shall construct an automaton B over the alphabet Γ × (C ∪ D) × P(C) recognizing the language It will read a tree t, compute a representation of tuples selected from the associated data tree t by the selector query α(x), and accept if all these tuples satisfy the assertion η(x).The representation of the selected tuples will be computed based on the maintained information about partial matchings of the selector query in the forest encoded by the processed part of the tree.This can be done in the usual way, except that we need to systematically refresh the colours, as specified in t.To explain the details, we need some auxiliary notions.
Recall that t and t have the same domain, structure, and labelling with elements of Γ ; the only difference lies in the way data values are represented: encoded in t and explicit in t.Consequently, as long as we do not care about data values, we can blur the distinction between the encoded and decoded data tree.Similarly, t w , t w , and t w are the same forest, up to the representation of data values.A partial valuation of variables x 1 , x 2 , . . ., x is a function g : {x 1 , x 2 , . . ., x } → dom t ∪ {⊥} .
If g(x i ) = ⊥, we say that x i is matched at g(x i ), and if u i = ⊥ we say that x i is not matched.Two partial valuations of x 1 , x 2 , . . ., x are disjoint, if no variable is matched by both of them.The union of disjoint partial valuations g, h of variables x 1 , x 2 , . . ., x is given as Recall that α(x) is a conjunction of atoms.A partial matching of α(x) in t w is a partial valuation g of variables x such that variables are matched only in the nodes of t w ; each atom in α(g(x)) that does not contain ⊥ holds true in t w ; and each atom that contains both a node from t w and ⊥ is of the form where w is a preceding sibling of w or w itself, and v is an arbitrary node of t w .
The last condition means that each such atom can be made true (independently of others) by replacing ⊥ with a node from t − t w , unless w has no following siblings or no ancestors in t.
If t |= α(ū), each partial valuation matching a subset of variables x i at nodes u i from t w is a partial matching of α.Conversely, if a partial matching g matches all variables x, then t |= α(g(x)).Note, however, that not every partial matching can be extended so that it matches all variables: remaining atoms may be satisfiable on their own, but not together.
The automaton collects information about tuples selected by α(x) node by node: when it is in a node w of the input tree t, it has information corresponding to partial matchings of α(x) in t w .More precisely, the states of the automaton B are subsets ∆ of Each such tuple represents a partial matching of α(x) in t w , and the whole ∆ represents a set of such partial matchings.The intended meaning of the symbolic values is as follows: c ∈ C ∪ D in the coordinate j of the tuple means that the variable x j is matched in a node of t w storing the data value c; i means that the variable x j is matched in a node storing some data value , where d 1 , d 2 , . . ., d are distinct and depend on the tuple; -⊥ means that variable x j has not been matched yet.
Let us describe the transition relation.Assume that automaton B is about to determine the state in a node w.Let w and w be, respectively, the previous sibling and the last child of w.The set of partial matchings of α(x) in t w depends only on the sets of partial matchings in t w and t w , and the label of w.Indeed, a partial valuation of x is a partial matching of α(x) in t w if it is the union of disjoint partial matchings of α(x) in t w and t w possibly extended by matching some (yet unmatched) variables at node w, respecting two conditions.For all atoms x i → x j , x i → + x j in α(x), either x i , x j are both matched in t w or none is; and the new matching of variables at w does not violate the definition of partial matching.The latter can be expressed as follows: if α(x) contains x i ↓ x j or x i ↓ + x j , we may match x i at w only if x j is matched in t w ; for x i ↓ x j , if x j is matched, we must match x i , unless it is matched in t w already; if α(x) contains x i → x j or x i → + x j , we may match x j at w only if x i is matched in t w ; for x i → x j , if x i is matched, we must match x j , unless it is matched in t w already; if α(x) contains a(x i ), we may match x i at w only if lab t (w) = (a, c, R) for some c, R.
Checking the conditions above requires only information about which variables are matched in t w and t w ; the used tree nodes are not relevant.Consequently, one can determine the set of tuples representing partial matchings in t w based on the sets of tuples representing partial matchings in t w and t w , and the label (a, c, R) of the current node w.Notice that the symbolic values i represent different data values in t w and t w , so before combining two tuples we rename these values to guarantee that none is used in both tuples ( values are always sufficient for this).The final step is to refresh colours: in each tuple we replace all occurrences of c ∈ R with some i not yet used in this tuple.

Lower bound
Lemma 5 Consistency of non-mixing constraints is 2ExpTime-hard.
Proof Relying on the fact that 2ExpTime = AExpSpace, we will be using alternating Turing machines.Such machines can be defined in multiple similar ways, and we use a definition that is most convenient for our encoding.We do not divide states of our machine into existential and universal; we only distinguish accepting states.Instead, we use the following notion of a run tree, requiring that from every configuration two different transitions can be applied.A run tree of an alternating Turing machine M on input word w is a tree labelled by configurations of M , where the root is labelled by the initial configuration for the input word w; every node not labelled by an accepting configuration has exactly two children, labelled by successors of this configuration, reached by applying to it two different transitions; every node labelled by an accepting configuration is a leaf.
We say that an input word w is accepted by M if there is a finite run tree of M for w.
To turn a standard machine with existential and universal states into a machine of the form above, one simply ensures that in universal states the machine has exactly two available transitions, and duplicates transitions available in existential states.
Consider an alternating Turing machine M (of the form described above) that works in space bounded by 2 |w| , where w is the input word.Note that we limit the space to 2 |w| instead of considering any exponential function, but already among such machines there is one solving an AExpSpace-hard problem.We show that for every input word w we can construct (in polynomial time) a tree automaton A and a set Σ of non-mixing constraints such that A and Σ are consistent if and only if M accepts w.More precisely, every tree t ∈ L(A) such that t |= Σ describes a run tree of M on w.Below we specify how such a tree t encodes a run tree of M on w, simultaneously saying how these properties are ensured by A or Σ.
Nodes labelled by s form a prefix of t that is a binary tree: the parent of every s-labelled node (if exists) is s-labelled, and every s-labelled node has zero or two s-labelled children.This is ensured by the automaton A. This part of t is called the skeleton, and will have the same shape as the run tree.
Additionally, each node of the skeleton has a c-labelled child (in addition to the zero or two children from the skeleton).The subtree rooted in this child forms a path, whose labels match the regular expression where b, l, n, r, h, p are new alphabet symbols, Q and A are the state set and the tape alphabet of M , and n = |w|, Again, this is ensured by A. Such path, called a configuration path, describes a configuration of M assigned to the corresponding node of the skeleton (which is also a node of the run tree).
At the beginning of each configuration path we have the transition used to reach this configuration: the second node is labelled by the letter present on the tape under the head in the previous configuration; the third node is labelled by the previous state; the fourth by the letter written on the tape; the fifth by the new state; the sixth by the direction in which the head was moved (left, no move, right).The automaton ensures that this is indeed a valid transition of M (except for the configuration path directly below the root, where we only ensure that the fifth node contains the initial state); that the label of the third node (previous state) is equal to the label of the fifth node (current state) of the parent configuration; that the transitions assigned to sibling configurations are different (as required in the definition of a run tree); that states are accepting in leaf configurations and not accepting in non-leaf configurations.
The next part of a configuration path consists of multiple blocks of length 2n+4; each of them describes a single letter on the tape.To identify a block, we use the first n c-labelled nodes for a binary counter encoding the position in the tape, using data values 0, 1 ∈ D. We assign data values 0, . . ., 0, 0 to these nodes in the first block, 0, . . ., 0, 1 in the second block, and so on, until 1, . . ., 1, 1 in the last block (we have 2 n blocks, which equals to the length of the tape).The next n nodes of the block also contain such a counter, but going back: we assign 1, . . ., 1, 1 to these nodes in the first block, and 0, . . ., 0, 0 in the last block.Notice that when one counter of a block contains bits b 1 , . . ., b n , then the other counter contains their inverses 1−b 1 , . . ., 1−b n .This double encoding of the position is the key trick that allows using non-mixing integrity constraints to check correctness of the run between two consecutive configurations.To enforce this behaviour of counters we use constraints.In the constraints we shall use queries matching tuples of variables x = (x $ , x h , x p , x 1 , . . ., x n , x 1 , . . ., x n , x d ) to the 2n + 4 consecutive nodes of blocks in configuration paths.It is easy to write a conjunctive query α fb (x) that matches x to the first block in any configuration path.We include in Σ the constraint We deal analogously with the last block.Then, using a conjunctive query α cb (x, ȳ) with ȳ defined as x above, that matches two consecutive blocks, we include the constraint ensuring that the counters in these two blocks encode consecutive numbers.It is a standard task to express this property as a positive Boolean combination η ∼ (x, ȳ) of atoms over {∼, 0, 1}, of a quadratic size.
The second node of each block is marked by h if the head of M is placed over this position of the tape, and the third node is marked by p if the head was placed over this position in the previous configuration.The automaton ensures that in each configuration path exactly one block is marked by h and exactly one block is marked by p; that in the initial configuration the head is over the first letter; that the relation between the p and h markers on a configuration path is as described by the sixth node of that path (l, n, or r).
To ensure that the position of p corresponds to the position of h in the previous configuration we use the constraint where α ch (x, ȳ) matches x to the h-marked block of a configuration and ȳ to the p-marked block of a child configuration.
The last node of each block carries the tape letter (from A) in the data value.To ensure that the initial configuration starts with the input word, we write a constraint where α ini (x 1 , . . ., x n ) selects the last node from each of the first n blocks of the topmost configuration path (to make sure that only the topmost configuration path is selected, we can check for the presence of the initial state, assuming w.l.o.g. that M cannot reach the initial state in any transition).Another constraint ensures that the rest of the initial tape contains blanks b ∈ A, where α bl (x) matches the last node of a block of the topmost configuration path other than the first n blocks.Next |A| constraints ensure that the p-marked block contains the letter written in the fourth node of the configuration path (letter written under the head), and another |A| constraints that the h-marked block of the previous configuration contains the letter written in the second node of the configuration path (letter seen under the head).
Finally, we have to ensure that the content of the tape is preserved (except the single letter under the head).Let α 2b (x, ȳ) be a conjunctive query matching some blocks on consecutive configuration paths, where the first of them is not marked by h.For every such pair x, ȳ, we want to enforce that either the two corresponding blocks carry the same letter or they represent two different positions in the tape.Using the double complementary encoding of the position in the blocks, this can be enforced using only ∼ in the following constraint: Notice that the property "x and ȳ encode different positions in the tape" seems to require , but thanks to the inverted counter stored in each block we may use ∼ instead, avoiding the illegal mixture of ∼ and in the assertion of the constraint.
By construction, witnesses for the obtained automaton A and set of constraints Σ correspond to run trees of the machine M , which ensures correctness of the reduction.
We remark that all conjunctive queries used in the above proof could be written using tree patterns (see Section 4.2 for the definition), and that the set Σ was empty.Thus the 2ExpTime-hardness result holds already for constraints of this form.If we only allow tree patterns as selectors and Σ ∼ is empty, the complexity might be lower.In Section 4.3 we shall see a different hardness argument, showing that there is no hope for lower complexity without restricting selectors.

Entailment of non-mixing constraints
A static analysis problem more general than consistency is entailment.Recall that a set of constraints Σ is entailed by a set of constraints Σ modulo a tree automaton A, written as Σ |= A Σ , if for each data tree t accepted by automaton A, t |= Σ implies t |= Σ .
The entailment problem is then defined as follows: Problem: Entailment problem for non-mixing constraints Input: Sets Σ, Σ of non-mixing constraints, tree automaton A. Question: Entailment is a more general problem than consistency, but for non-mixing constraints the results on consistency generalize to entailment almost effortlessly.
Theorem 2 Entailment of non-mixing constraints is 2ExpTime-complete.
Proof Inconsistency is a special case of entailment: Σ is inconsistent with respect to an automaton A if and only if Σ |= A ⊥, where ⊥ is an inconsistent set of constraints, say a(x) ⇒ 0(x) ∧ 1(x) a ∈ Γ .Thus, the lower bound follows.
Lemma 3 shows that witnesses for consistency can have bounded data cut.The same is true for counter-examples to entailment.Suppose t |= Σ and t |= Σ .Then, t |= α (ū) ∧ ¬η (ū) for some constraint α (x) ⇒ η (x) from Σ and some tuple ū of nodes of t.Let D 0 be the set of data values used in the nodes ū.We can repeat the construction of the tree t word for word, except that we replace the set D of values not to be touched by D ∪D 0 .This increases datacut(t ) by the maximal number of variables in the constraints of Σ .
The automata construction in Section 3.3 is modified similarly: the set D contains also the data values used explicitly in Σ , in the product automaton we include additionally the automata B σ for σ ∈ Σ , and we let it accept if at least one of these components rejects and all previously described components accept.As the automata B σ are deterministic, this does not involve any additional cost.
Note that the argument above works also if Σ mixes predicates from sig ∼ and sig .

A singly exponential fragment
A closer look at the complexity of our algorithm reveals that it is doubly exponential only in the maximal number of variables in the constraints.This number appears in three roles: in the exponent in the factors ( + m) 2 and 2 of the bound on the data cut, and as the length of tuples representing partial matchings of selectors.A slightly more detailed analysis of the proof of Lemma 3 shows that in the first role, could be replaced by the maximal number of variables actually used in the assertions.Indeed, since data equalities involve only variables occurring in the atoms of the assertions, everything is in fact happening in a space of dimension at most .While limiting the size of selector queries to lower the complexity makes little sense, limiting the number of variables actually used in assertions seems acceptable.But what about the other two roles of ?Concerning the third role, the need to represent all partial matchings (up to data equality type) comes from the fact that the automaton is essentially evaluating conjunctive queries.The standard technique to lower the complexity in such cases is to replace conjunctive queries with tree patterns, which are essentially tree-structured conjunctive queries.In the most basic form, with only ↓ and ↓ + axes allowed, a tree pattern is a conjunctive query α over signature {↓, ↓ + } ∪ Γ , such that graph is the canonical relational structure associated to query α in the usual way: the universe A α is the set of variables of α, and relations are given by the respective atoms in α.
Finally, we also have the factor 2 in the bound on the data cut.This factor appears because in the proof of Lemma 3, we consider separately each partition of variables into two tuples.As we shall see, the number of partitions can also be reduced for tree patterns.To this end, we prove the following analogue of Lemma 2.
Lemma 6 Let α(x, ȳ, z) be a tree pattern, where x, ȳ, and z are pairwise disjoint, and in ↓ α ∪ ↓ + α there are no edges from variables in z to variables in x, ȳ.Let w be a node of a data tree t.For all tuples ū, ū of nodes from t w , and tuples v, v of nodes from t − t w , if Proof We only prove that t |= ∃z α(ū, v , z), as the other part is symmetric.Let w and w be tuples of nodes from t such that t |= α(ū, v, w) and t |= α(ū , v , w ).The claim holds trivially if both x and ȳ are empty.Assume that at least one of these tuples is nonempty.Then the root of the tree pattern belongs to x or to ȳ.Let z = (z 1 , . . ., z k ), w = (w 1 , . . ., w k ), w = (w 1 , . . ., w k ).For i ∈ {1, . . ., k} we look at the nearest ancestor of z i that is in x or in ȳ.If it is in x, we take w i = w i , otherwise w i = w i , and we define w = (w 1 , . . ., w k ).We need to check that every atom of α(ū, v , w ) is satisfied in t.This is clear for unary atoms.Assume a binary atom involves a variable from z that is valuated as in ū, v, w.From the definition of w it then follows that the other variable, being its child or its parent in the tree pattern, is also valuated as in ū, v, w.It follows that the atom is satisfied, because t |= α(ū, v, w).We argue analogously for binary atoms with a variable from z valuated as in ū , v , w .It remains to consider binary atoms involving only variables from x and ȳ, and this can be done as in the proof of Lemma 2.
We remark that for non-mixing integrity constraints, restricting selectors to tree patterns alone does not suffice to lower the complexity: the reduction in Lemma 5 uses only such constraints (and no assertions over sig ).But together with the bound on the number of variables in assertions, it does suffice.
Proposition 1 For non-mixing constraints whose selectors are tree patterns and whose assertions use constantly many variables, consistency and entailment are ExpTime-complete.
Proof We first complete the proof that the data cut can be bounded polynomially.We have already argued that in the factor • ( + m) 2 of the bound given by Lemma 3 we can replace by the maximal number of variables used in the assertions, which is assumed to be constant.It remains to deal with the factor 2 .We show that the number of considered partitions can be limited by a polynomial.
Fix a tree t, its node w, and a constraint α ⇒ η ∼ in Σ ∼ .We say that a variable x used in α is important if either x or some descendant of x (in the sense of ↓ α ∪ ↓ + α ) is used in η ∼ ; otherwise x is unimportant.We shall partition only important variables: we write the tree pattern as α(x, ȳ, z), where x, ȳ is a partition of important variables, and z contains all unimportant variables.Notice that in ↓ α ∪ ↓ + α there are no edges from unimportant variables to important variables, and thus Lemma 6 can be used.
We additionally restrict ourselves to tame partitions, defined as follows: a partition x, ȳ of important variables is tame if in ↓ α ∪ ↓ + α there are no edges from variables in x to variables in ȳ.This way we only prune empty cases, because in the proof of Lemma 3 we only valuate variables from x with nodes from t w , and variables from ȳ with nodes from t − t w .
We thus have the following statement: t |= α ⇒ η ∼ if and only if for each tame partition x, ȳ of important variables in α, for each tuple ū of nodes from t w , each tuple v of nodes from t − t w , and each tuple w of nodes of t, if t |= ∃z α(ū, v, z), then t |= η ∼ (ū, v).This allows us to continue as in the proof of Lemma 3; the unimportant variables do not appear in η ∼ , so it is irrelevant whether they are valuated in t w or in t − t w .Finally, we observe that the number of tame partitions of important variables is polynomial in the size of the tree pattern, assuming that the number of variables used in η ∼ is constant.Indeed, for each of the constantly many variables used in η ∼ , we only have to decide how many of its closest ancestors (including itself) are to be taken to x (the ancestors being farther are then taken to ȳ).
We have thus proved that the bound on the data cut is polynomial.Hence, the size of the set of colours C is also polynomial.It remains to optimize the automaton B σ verifying a single constraint σ, assuming that the selector of σ is a tree pattern.
We use the standard method relying on the fact that subtrees of a tree pattern can be matched independently.By definition, the domain of a partial matching of a tree pattern is a collection of disjoint full subtrees of the pattern.Such a collection can be matched, if each of its elements can be matched independently; the information sufficient to represent all possible matchings is a set of subtrees that can be matched.For our purposes this is insufficient: we are interested not in just matching the selector, but in all tuples of data values that can be associated with the variables used in the assertion.This information cannot be stored separately for each subtree, as we are interested in the equalities and inequalities between data values assigned to variables in different subtrees; this is a property of a set of matched subtrees, and there can be ways of matching the same set that yield different equalities and inequalities.The solution is to treat subtrees with variables used in the assertion in a special way.The automaton remembers in each state a collection of subtrees without assertion variables and a collection of pairs consisting of a set of pairwise disjoint subtrees with assertion variables, and a tuple representing the associated data values (like before).
As the number of assertion variables is constant, the number of such sets and such tuples is polynomial.Hence, the whole automaton is singly exponential.This shows that both consistency and entailment are in ExpTime.
The lower bound follows immediately from ExpTime-hardness of consistency of schema mappings with trivially unsatisfiable right hand sides of dependencies [1, Proposition 18.2], which can be also reinterpreted as validity of unions of tree patterns modulo a given tree automaton.

Static analysis of unions of conjunctive queries
Our results can be reinterpreted in the framework of static analysis of unions of conjunctive queries (UCQs).Note that if and only if t |= ∃x α(x) ∧ ¬η(x) .
It follows immediately that the problem of validity of UCQs over signature sig dt that never mix predicates from sig ∼ and sig -call them non-mixing UCQsreduces in polynomial time to inconsistency of non-mixing constraints.Similarly, containment of such queries reduces to entailment of non-mixing constraints.The converse reduction is also possible, but it involves exponential blow-up when arbitrary Boolean combinations in assertions are rewritten in disjunctive normal form.This correspondence brings our results very close to the work by Björklund, Martens, and Schwentick on static analysis for UCQs over signature sig nav ∪ {∼, } [6].On one hand, our results immediately give the following new decidability result for the setting considered by Björklund, Martens, and Schwentick (constraints used in the lower bound of Lemma 5 can be rewritten without blow-up).
Theorem 3 Over sig nav ∪{∼, }, both validity of non-mixing UCQs and containment of UCQs in non-mixing UCQs (with respect to a given tree automaton) are 2ExpTime-complete.
Results of Björklund, Martens, and Schwentick give 2ExpTime upper bound for containment (with respect to a tree automaton) in UCQs over sig nav ∪ {∼} and UCQs over sig nav ∪ { }.The original work is on CQs, but arguments for UCQs are the same [12].Essentially, they amount to an observation that in counter-examples to containment of a query p in a query q, all data values can be set equal (in the case with ) or different (in the case with ∼), except for a bounded number of them needed to witness satisfaction of p; such counterexamples can be easily encoded as trees over a finite alphabet, and recognized by an automaton evaluating p and q in the usual way.Theorem 3 extends both these results.Since we have both ∼ and in query q, we cannot assume that all data values are equal, nor that all are different; our more involved approach seems necessary.The third relevant result of [6] is that containment of p in q is 2ExpTime-complete under the assumption that p is a CQ over sig nav ∪ {∼} and q is a CQ over sig nav ∪ {∼, }.It looks stronger than ours because query q can mix ∼ and .In fact, it is much weaker, depending entirely on the fact that q is a single CQ, not a UCQ.More specifically, the argument is as follows: if q uses , the answer is yes if and only if p is not satisfiable with respect to the tree automaton (otherwise p is satisfiable in a tree with all data values equal, and no such tree can satisfy q because of its atoms); if q does not use , we are back in the case of UCQs over sig nav ∪ {∼}.
On the other hand, some results of Björklund, Martens, and Schwentick give a broader context to our results.They show that validity with respect to a given automaton is already 2ExpTime-complete for unions of conjunctive queries over signature sig nav , that is, for trees without data.Consequently, restricting only assertions of non-mixing constraints would not lower the complexity.This is complementary to our lower bound of Lemma 5, which shows 2ExpTime-hardness for constraints using tree patterns as selectors.Hence, the only way to lower the complexity is to restrict both, selectors and assertions.Björklund, Martens, and Schwentick also show that for UCQs over sig nav ∪ {∼, } validity is undecidable; this means that we cannot go beyond non-mixing assertions.

XML constraints
Non-mixing constraints form an instance of the general framework of XML-torelational (X2R) constraints proposed by Niewerth and Schwentick [27], where selectors are arbitrary queries defining relations by selecting tuples of nodes and data values (in separate columns), and assertions are arbitrary relational constraints over the defined relations; the considered problem is entailment modulo schema.Our setting corresponds to a fragment in which selectors are conjunctive queries over sig nav interpreted as queries selecting tuples of data values, assertions are positive quantifier-free formulas using constants and either = or =, and schemas are tree automata.Niewerth and Schwentick investigate two classes of assertions: functional dependencies (FDs) and XMLkey FDs (XKFDs).In an FD A 1 , A 2 , . . ., A m , B are arbitrary columns of the relation defined by the selector (each referring either to nodes or to data values); in an XKFD, B is required to be a node column.Our setting captures XKFDs, but not general FDs.Consider an X2R constraint given by a CQ α(x 1 , . . ., x n ) populating a table with tuples (x 1 , . . ., x n , @x 1 , . . ., @x n ), where @x i stands for the data value stored in the node represented by variable x i , and an XKFD x 1 , . . ., x j , @x j+1 , . . ., @x n−1 → x n (it makes no sense to use both x i and @x i in the same constraint).Such constraint can be rewritten as which can be turned into a set of five non-mixing constraints by replacing x n = x n with simple subqueries describing possible ways of arranging two different nodes in a tree, as explained in Section 2.3.Note that these constraints do not use ∼.Hence, for XKFDs with UCQs over sig nav as tuple selectors decidability of entailment follows already from the results on containment of UCQs over sig nav ∪ {∼}, discussed in the previous subsection; the challenge tackled by Niewerth and Schwentick is to determine the exact complexity and identify tractable fragments.
If we replace the XKFD above with an FD x 1 , . . ., x j , @x j+1 , . . ., @x n−1 → @x n we have which cannot be expressed without mixing ∼ and .As we have explained, consistency and entailment is undecidable for such constraints, but one can investigate fragments with restricted schemas and tuple-selectors.This is what Niewerth and Schwentick do.
As XKFDs with tree patterns as tuple-selectors can express XML Schema key and unique constraints [18], XML keys by Arenas, Fan, and Libkin [2], and XFDs by Arenas and Libkin [3], so can non-mixing constraints.A technical subtlety is that some of these classes of constraints apply to nodes of a specified type (playing the role of a state in XML Schemas).As proposed by Niewerth and Schwentick, we can deal with it by annotating tree nodes with types (verified by the automaton encoding the schema), and let the patterns refer to types and labels.This slight extension does not affect our complexity bounds.Also, XML Schema unique constraints demand that each field path selects at most one node, and XML Schema key constraints demand exactly one node; the latter can be checked by the automaton too.In practice, one often wants at most (or exactly) one data value, not tree node.This may or may not be equivalent.To express that at most one data value is selected, we can use the singleton constraints discussed in Section 2.3.Note that this requires assertions over sig ∼ .

Consistency of XML schema mappings
Schema mappings are a formalism used in data exchange scenarios to specify relations between instances of two database schemas, a source schema and a target schema [1,14].In the basic setting for XML [4], schemas can be abstracted as tree automata, and the relation between source and target instances can be defined by a set Σ of dependencies of the form where α, α are conjunctive queries over sig nav , treated as queries selecting data values, not nodes.That is, a pair of data trees (t, t ) satisfies dependency σ of the form above, written as (t, t ) |= σ, if The consistency problem for XML schema mappings [4] is to decide for a given schema mapping M = (A, A , Σ), whether there exists a tree t accepted by automaton A and a tree t accepted by automaton A such that (t, t ) |= Σ.This problem is known to be decidable: without loss of generality one may assume that all data values in t and t are equal, and use standard automata techniques ignoring data values.This is not only uninspiring theoretically, but also not very practical: an instance with all data values equal is not a convincing witness that the mapping makes sense.What if the source schema includes constraints, say XML Schema key or unique constraints?We cannot assume that all data values are equal any more.As we have argued in the previous subsection, such constraints can be expressed with non-mixing constraints, which leads us to the problem of consistency with source constraints, a common generalization of consistency of constraints and schema mappings: given a schema mapping M = (A, A , Σ) and a set of non-mixing constraints Σ src , decide if there exist a tree t accepted by automaton A and a tree t accepted by automaton A such that t |= Σ src and (t, t ) |= Σ.
The following lemma gives the connection between XML schema mappings and non-mixing constraints that allows us to apply our decidability result.It was proved in a slightly different but equivalent form in [13].A non-mixing constraint with free data value predicates uses additional unary predicate symbols in the assertions.A data tree t satisfies a set Σ of such constraints (possibly sharing some additional predicate symbols) if it satisfies Σ obtained from Σ by replacing each additional predicate symbol with some d ∈ D. Free data value predicates are not problematic for the consistency algorithm, as it can guess the data values to replace them; up to equality type with respect to data values already used in Σ, there are only exponentially many possibilities.
Lemma 7 For each schema mapping M = (A, A , Σ) one can compute in doubly exponential time sets Σ 1 ∼ , Σ 2 ∼ , . . ., Σ m ∼ of non-mixing constraints with free data value predicates, each obtained from Σ by replacing target-side queries α (x) with assertions η ∼ (x) of exponential size, such that for each data tree t, t |= Σ i ∼ for some i ∈ {1, . . ., m} if and only (t, t ) |= Σ for some data tree t accepted by automaton A .
Thus, mapping M is consistent with source constraints Σ src if and only if at least one of the sets Σ i ∼ ∪Σ src obtained via Lemma 7 is consistent with respect to automaton A. Since the number of variables in each involved constraint is linear, the latter can be tested in 2ExpTime, as the algorithm from Section 3 is doubly exponential only in the maximal number of variables.As Lemma 7 translates mappings into constraints with assertions over sig ∼ , even if Σ src is just a set of key constraints (expressible with assertions over sig ), we need the full power of non-mixing constraints, allowing assertions over sig ∼ and sig .

Data cut and clique-width
A classical measure of simplicity for relational structures is that of cliquewidth [11].As has been noticed before for unordered data trees, clique-width and data cut are related [7].We shall now reexamine briefly this relationship for ordered data trees, and in the following subsection we shall see how it can be used to extend our decidability results to constraints with much more expressive selector queries.Let τ = {R 1 , . . ., R } be a relational signature, that is, a set of predicate symbols with arities ar(R i ).A (finite) τ -structure A is a tuple A, R A 1 , . . ., R A consisting of a finite universe A and relations R A i ⊆ A ar(Ri) (interpretations of the predicates).A k-coloured τ -structure is a pair (A, γ), consisting of a τstructure A and a mapping γ : A → {1, . . ., k}, assigning colours to elements of the universe of A.
Clique-width of structures is defined by means of an appropriate notion of decomposition, traditionally known as k-expression (over τ ).It is defined as a term over the following set of operations (function symbols) Op(τ, k): A k-expression for A is any k-expression e such that [[e]] = (A, γ) for some γ.The clique-width of A is the least k such that there exists a k-expression for A.
Example 2 Consider a data tree t n consisting of a root w and two branches u 1 , u 2 , . . ., u n and v 1 , v 2 , . . ., v n , in which all nodes have label a and the data values correspond to the node's depth in the tree, as shown in Figure 4.Then, t u1 and t − t u1 share n different data values, and the data cut of t n is n.Let us see t n as a relational structure over the signature sig nav ∪{∼}, where ∼ is interpreted as the equivalence relation with abstraction classes {w} and {u i , v i } for i = 1, 2, . . ., n.We claim that the clique width of t n is bounded by 7: if we construct t n top-down, level by level, at any point of the construction it is enough to distinguish between the root, the internal nodes on two branches, the two current leaves, and the two new nodes.
To see this, begin with a node of colour root and set its label with a(root), add two nodes of colours leaf 1 and leaf 2 with relations specified by for i = 1, 2 and then repeat the following n − 1 times: add two nodes of colours new 1 and new 2 with relations specified by and recolour using col(leaf i , internal i ), col(new i , leaf i ) for i = 1, 2.
The example shows that trees of bounded clique width can have arbitrary large data cut.We shall now see that bounded data cut implies bounded clique width.
For each set D ⊆ D, data trees can be seen as relational structures over the signature sig nav ∪ sig D ∼ , where sig D ∼ = {∼} ∪ D; that is, we restrict the unary predicates in sig ∼ to those associated to data values from D.
Proposition 2 For each finite D ⊆ D and each data tree t seen as a relational structure over  where the last operation is included only if c ∈ D (that is, c is in the signature).If w has children, let w be its last child.Then, the expression e w is already constructed and we incorporate it into the expression e w as follows: combine the expression built so far with e w using the operation ⊕; specify structural relations between the two parts using the operations Similarly, if w is the previous sibling of w, we incorporate the expression e w as follows: combine the expression build so far with e w using the operation ⊕; specify structural relations between the two parts using the operations Finally, we take care of data equalities and clean up the colours: specify data equalities between the combined parts using the operations Thus, bounded data cut is a stronger property than bounded clique width.It can be seen as a strengthening of bounded clique-width for data trees, in which decompositions must closely follow the structure of data trees.

MSO constraints
Our decidability results for consistency and entailment of non-mixing constraints can be naturally extended by allowing selectors expressed in monadic second-order logic (MSO), a powerful extension of first order-logic in which quantification over subsets of the universe is available.However, as is usually the case when MSO is involved, the complexity will be non-elementary.
The syntax of MSO formulae over sig nav is ϕ, ψ ::= ∃X ϕ ∃x ϕ ϕ ∧ ψ ¬ϕ x ∈ X x ↓ y x ↓ + y x → y x → + y a(x) for a ∈ Γ ; the semantics is the natural one, with the usual distinction between first-order variables (lower case) referring to elements of the universe and second-order variables (upper case) referring to subsets of the universe.We consider MSO constraints of the form where the selector ϕ(x) is an MSO formula over sig nav in which all free variables are first-order.As a first step, we reprove the bound on the data cut, shown in Lemma 3. Instead of using Lemma 2 we rely on the compositionality of MSO.For a forest f over Γ , a tuple v = (v 1 , . . ., v m ) of nodes of f , and a tuple Now, we can show a bound on the data cut for non-mixing MSO constraints.Unlike in Lemma 3, the bound is non-elementary: it is proportional to the maximal size of the automata for the MSO formulas used in the constraints.
Lemma 9 If a set Σ ∼ ∪ Σ of non-mixing MSO constraints is satisfied in a data tree t, it is also satisfied in some data tree t obtained from t by changing data values, such that where and m are the maximal numbers of, respectively, free variables and predicates from D∪ Ď in the constraints from Σ ∼ , and S is the maximal number of types for the selector formulas in the constraints from Σ ∼ .
The same is true for counter-examples to entailment, except that the bound on the data cut needs to be increased by the number of variables in the violated assertion.
Proof We proceed just like for Lemma 3. Let us take a node w of the data tree t and an MSO constraint ϕ(x, ȳ) ⇒ η ∼ (x, from Σ ∼ with a fixed partition x, ȳ of the free variables of ϕ.Using Lemma 8, we arrive at the following condition: for all tuples ū, ū of nodes from t w and all tuples v, v of nodes from t − t w , if t |= ϕ(ū, v), t |= ϕ(ū , v ), and the ϕ-types of t w , ū and t w , ū are equal, then t |= η ∼ (ū, v ).This can be reformulated as follows: for each tuple ū of nodes from t w such that the ϕ-type of t w ; ū is q and t |= ϕ(ū, v) for some tuple v of nodes from t − t w , the tuple val t (ū) of data values belongs to the set Z q ϕ(x,ȳ)⇒η∼(x,ȳ) where v ranges over tuples of nodes from t − t w satisfying t |= ϕ(ū , v ) for some tuple ū of nodes from t w such that the ϕ-type of t w ; ū is q.
Like before, we modify the tree t by changing to a fresh one each data value used in t w , except for those from the set D ⊆ D of data values used in the definitions of the sets Z q ϕ(x,ȳ)⇒η∼(x,ȳ) , with ϕ(x, ȳ) ⇒ η ∼ (x, ȳ) ranging over constraints from Σ ∼ with all possible partitions of free variables, and q ranging over all possible ϕ-types.As the bound on the number of data values used in the canonical definition of a single set Z q ϕ(x,ȳ)⇒η∼(x,ȳ) remains unchanged, we have 2 .Performing this modification for each node w, we guarantee the bound on data cut as stated in the lemma.For the second claim, extend the set D with the data values used in the tuple of nodes violating the assertion, as described in Section 4.1 for constraints with CQ selectors.
As each set of MSO constraints can be rewritten as a single MSO formula over the signature sig nav ∪sig ∼ , by Lemma 9 and Proposition 2 from Section 4.6, the consistency problem and the entailment problem reduce to satisfiability of MSO over structures of bounded clique-width (one has to ensure that the structure is indeed a data tree, but this can be easily expressed in MSO).As the latter is known to be decidable [10], we immediately obtain decidability of consistency and entailment.For completeness, we give a direct proof, avoiding the notion of clique-width.
Theorem 4 Consistency and entailment of non-mixing MSO constraints is decidable.
Proof Let Σ ∼ ∪ Σ be a set of non-mixing constraints and let A be a tree automaton.By Lemma 9, it is enough to test satisfiability of Σ ∼ ∪ Σ over trees of data cut bounded by a number N , computable from Σ ∼ ∪ Σ .Let D ⊆ D be the set of data values used explicitly in Σ ∼ ∪ Σ , and let C ⊆ D − D be a fixed set such that |C| = 3 2 • N + 1.Like before, by Lemma 4, the proof boils down to constructing an automaton recognizing the set of trees t over Γ × (C ∪ D) × P(C) such that the data tree t satisfies Σ ∼ ∪ Σ .Each MSO constraint ϕ(x) ⇒ η(x) is equivalent to a closed MSO formula ∀x ϕ(x) → η(x) over the signature sig nav ∪ sig ∼ (in the presence of negation, sig is redundant).Hence, a finite set of MSO constraints is equivalent to a conjunction of such formulas.Thus, it suffices to construct an automaton accepting trees t over Γ × (C ∪ D) × P(C) such that t satisfies ϕ, where ϕ is an MSO formula over sig nav ∪ sig ∼ , using only predicates associated with data values from the set D.
We modify the standard construction of the automaton A ϕ for a formula ϕ of MSO over sig nav .As the structure of the tree and the labelling with elements of Γ is the same in t and t, we only need to provide explicit constructions for the atomic formulas over sig ∼ .
For formulas of the form d(x), we have d ∈ D, so the data value d is represented explicitly in t.Hence, the automaton simply identifies the node with value 1 in the corresponding binary coordinate of the label, and accepts if and only if the non-binary component of this label is (a, d, R) for some a and R.
For formulas of the form x ∼ x , the automaton also identifies the nodes x and x in the input tree t, and then accepts if they are labelled with (a, d, R) and (a , d, R ) for some a, a , R, R , and additionally, if d ∈ C, then it is not refreshed before reaching the first node w such that t w contains both x and x .
For entailment, we use the additional claim of Lemma 9 and include in D also the data values used explicitly in the second set of constraints, Σ ∼ ∪ Σ .As the fact that Σ ∼ ∪ Σ holds and Σ ∼ ∪ Σ does not hold can also be expressed with a single closed MSO formula, we can use directly the construction described above.
Both approaches give non-elementary complexity, as already the bound of Lemma 9 is non-elementary.This cannot be improved, as the satisfiability problem for MSO over sig nav , well known to be non-elementary, easily reduces to inconsistency of MSO constraints: a closed formula ϕ is satisfiable if and only if ϕ ∧ a(x) ⇒ 0(x) ∧ 1(x) a ∈ Γ is inconsistent with respect to the trivial automaton accepting all trees.

Conclusions
We have shown that consistency and entailment of non-mixing constraints are decidable.Both problems are 2ExpTime-complete, but become ExpTimecomplete when we restrict selector queries to tree patterns and bound the number of variables in assertions; decidability can be pushed further to constraints with selector queries defined in monadic second order logic over the signature sig nav , but the complexity becomes non-elementary.We have reinterpreted these results in terms of validity and containment of conjunctive queries, as well as consistency of schema mappings.The latter setting best illustrates the benefits of combining assertions over sig ∼ and sig .Indeed, equalities are involved even in the simplest schema mappings, and inequalities allow to cover key constraints over the source database.
We worked with ordered trees, but all discussed results immediately carry over to unordered trees: as long as the signature does not contain the horizontal axes, one can freely move back and forth between ordered and unordered trees by forgetting the sibling order or introducing it arbitrarily.As both 2ExpTime lower bounds, the one from Lemma 5 and the one from [6], do not use the horizontal axes, they also hold for unordered trees.The same is true of the undecidability for the settings that mix equality and inequality [6].Similarly, restricting to ranked trees does not change the picture: the upper bounds carry over immediately, and the lower bounds only use trees of bounded branching.The reductions can be also adapted to the case of unlabelled trees: one can simulate labels with unique small tree gadgets attached to the main nodes of the tree and use the automaton to ensure that each main node has exactly one gadget attached.However, referring to the gadgets with selector queries requires either the next sibling or the following sibling relation.For unordered unlabelled trees the complexity might drop.
One might also ask how the presence of the schema affects the complexity.The fact that we model schemas as tree automata is inessential: all lower bounds can be adjusted to the setting where the schema language is restricted to DTDs [6].When there is no schema at all, the consistency problem trivializes, because if a tree satisfies a set of constraints, so does any tree obtained by removing nodes.Hence, it suffices to look for witnesses among trees with a single node, which leads to a polynomial-time algorithm.The question is more interesting for the entailment problem, because there the counter-example must contain enough nodes to falsify the non-entailed constraint.It is plausible that the complexity is lower than with a schema.

Fig. 1 A
Fig.1A tree t and a subforest tv associated with a node v.

Fig. 2 Lemma 4
Fig.2Forest f decomposed into a forest f followed by a tree further decomposed into the root and a forest f .

Fig. 4 A
Fig.4A tree of data-cut n and clique width bounded by 7.

3 2 •
datacut(t) +1.By Lemma 4, there exists a tree s over the alphabet Γ × (C ∪ D) × P(C) such that the encoded data tree s equals t up to a permutation of D − D. That is, s and t are equal when seen as relational structures over sig nav ∪ sig D ∼ .We shall turn s into a 4(|C| + |D| + 1)-expression for s, interpreting colours as elements of the set {last-root, other-root, new-root, not-root} × C ∪ D ∪ {⊥} .Processing the nodes of s in the usual order (bottom-up and left-to-right), for each node w we construct a 4(|C| + |D| + 1)-expression e w such that [[e w ]] = ( s w , γ) and for each node u the colour γ(u) satisfies the following properties: new-root, c), (other-root, d) , ↓ + (new-root, c), (other-root, d) , ↓ + (new-root, c), (not-root, d) for all d ∈ C ∪ D ∪ {⊥}; change last-root and other-root to not-root with the operations col (last-root, d), (not-root, d) , col (other-root, d), (not-root, d) for all d ∈ C ∪ D ∪ {⊥};
is, we have binary relations: child ↓, descendant ↓ + , next sibling →, and following sibling → + ; data equality relation ∼ and data inequality relation that contain pairs of nodes storing, respectively, the same data value and different data values; unary relation a for each label a ∈ Γ ; unary relations d and ď for each data value d ∈ D that contain nodes storing, respectively, data value d and any data value different from d.
1. the first coordinate describes the status of the node u in the forest s w : the last root, one of the other roots, or not a root (the value new-root will be used later); 2. the second coordinate is the data value stored in the node in s w if this value belongs to C ∪ D, or ⊥ if it does not.Let w be a node of s, labelled with (a, c, R).To build e w , we begin by creating a new node and specifying the unary relations for it (label and data value) with operations new (new-root, c) , a (new-root, c) , c (new-root, c) , sets of nodes of f , let f ; v; V be the forest over the alphabet Γ × {0, 1} m+n obtained from f by extending labels with binary vectors encoding v and V : a node w is labelled with (lab f (w), e 1 , ...e m , E 1 , ..., E n ) , where e i = 1 if and only if w = v i , and E j = 1 if and only if w ∈ V j .If v or V is empty, we skip it and write, for instance, f ; v .It is well known that for a given MSO formula ϕ(x 1 , ..., x m , X 1 , ...X n )one can effectively construct a deterministic automaton A ϕ (of non-elementary size) recognizing the tree languaget; v; V t |= ϕ(v, V ) .The construction follows the syntactic structure of MSO formulas: it begins with explicit automata for atomic formulas, and then turns logical connectives into Boolean operations on automata, and existential quantification into projecting out the corresponding binary coordinate from the alphabet.Defining the ϕ-type of a forest f over Γ × {0, 1} m+n as the state of the automaton A ϕ in the root of the last tree of f (in the unique run over f ), we obtain the following analogue of Lemma 2.
Lemma 8 Let ϕ(x, ȳ) be an MSO formula over sig nav , where x and ȳ are disjoint tuples of first-order variables, and let w be a node of a data tree t.For all tuples ū, ū of nodes from t w and tuples v, v of nodes from t − t w , ift |= ϕ(ū, v) and t |= ϕ(ū , v ) ,and the ϕ-types of t w ; ū and t w ; ū are equal, thent |= ϕ(ū, v ) and t |= ϕ(ū , v) .Proof As t |= ϕ(ū, v) and t |= ϕ(ū , v ), the trees t; ū, v and t; ū , v are accepted by the deterministic automaton A ϕ .Moreover, the state in the node w in the unique runs of A ϕ over these trees is the same, because t; ū, v w = t w ; ū and t; ū , v w = t w ; ū , and the ϕ-types of t w ; ū and t w ; ū are equal.Hence, swapping t; ū, v w and t; ū , v w does not affect acceptance by A ϕ .That is, the resulting trees t; ū , v and t; ū, v are accepted by A ϕ .Consequently, t |= ϕ(ū , v) and t |= ϕ(ū, v ).