{'fraction_non_alphanumeric': 0.07147533099090192, 'fraction_numerical': 0.010420702462224953, 'mean_word_length': 3.3904041292744442, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 107, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
On Typechecking Top-Down XML Tranformations: Fixed Input or Output Schemas

Typechecking consists of statically verifying whether the output of an XML transformation always conforms to an output type for documents satisfying a given input type. In this general setting, both the input and output schema as well as the transformation are part of the input for the problem. However, scenarios where the input or output schema can be considered to be fixed, are quite common in practice. In the present work, we investigate the computational complexity of the typechecking problem in the latter setting.


Introduction
In a typical XML data exchange scenario on the web, a user community creates a common schema and agrees on producing only XML data conforming to that schema. This raises the issue of typechecking: verifying at compile time that every XML document which is the result of a specified query or document transformation applied to a valid input document satisfies the output schema [32,33].
The typechecking problem is determined by three parameters: the classes of allowed input and output schemas, and the class of XML-transformations. As typechecking quickly becomes intractable [2,23,25], we focus on simple but practical XML transformations where only little restructuring is needed, such as, for instance, in filtering of documents. In this connection, we think, for example, of transformations that can be expressed by structural recursion [8] or by a top-down fragment of XSLT [5]. As is customary, we abstract such transformations by unranked tree transducers [19,23]. As schemas, we adopt the usual Document Type Definitions (DTDs) and their robust extensions: regular tree languages [25,17] or, equivalently, specialized DTDs [28,3]. The latter serve as a formal model for XML Schema [30].
Our work studies sound and complete typechecking algorithms, an approach that should be contrasted with the work on general-purpose XML programming languages like XDuce [14] and CDuce [4], for instance, where the main objective is fast and sound typechecking. The latter kind of typechecking is always incomplete due to the Turing-completeness of the considered XML-transformations. That is, it can happen that type safe transformations are rejected by the typechecker. As we only consider very simple transformations which are by no means Turing-complete, it makes sense to ask for complete algorithms.
The typechecking scenario outlined above is very general: both the schemas and the transducer are determined to be part of the input. However, for some exchange scenarios, it makes sense to consider the input and/or output schema to be fixed when transformations are always from within and/or to a specific community. Therefore, we revisit the various instances of the typechecking problem considered in [23] and determine the complexity in the presence of fixed input and/or output schemas. The main goal of this paper is to investigate to which extent the complexity of the typechecking problem is lowered in scenarios where the input and/or output schema is fixed. An overview of our results is presented in Table 2.
The remainder of the paper is organized as follows. In Section 2, we discuss related work. In Section 3, we provide the necessary definitions. In Section 4, we discuss typechecking in the restricted settings of fixed output and/or input schemas. The results are summarized in Table 2. We obtain several new cases for which typechecking is in polynomial time: (i) when the input schema is fixed and the schemas are DTDs with SL-expressions; (ii) when the output schema is fixed and the schemas are DTDs with NFAs; and (iii) when both the input and output schemas are fixed and the schemas are DTDs using DFAs, NFAs, or SL-expressions. We conclude in Section 5.

Related Work
The research on typechecking XML transformations was initiated by Milo, Suciu, and Vianu [25]. They obtained the decidability for typechecking of transformations realized by k-pebble transducers via a reduction to satisfiability of monadic second-order logic. Unfortunately, in this general setting, the latter non-elementary algorithm cannot be improved [25]. Interestingly, typechecking of k-pebble transducers has recently been related to typechecking of compositions of macro tree transducers [12]. Alon et al. [1,2] investigated typechecking in the presence of data values and show that the problem quickly turns undecidable. As our interest lies in formalisms with a more manageable complexity for the typechecking problem, we choose to work with XML transformations that are much less expressive than k-pebble transducers and that do not change or use data values in the process of transformation.
A problem related to typechecking is type inference [24,28]. This problem consists in constructing a tight output schema, given an input schema and a transformation. Of course, solving the type inference problem implies a solution for the typechecking problem, namely, checking containment of the inferred schema into the given one. However, characterizing output languages of transformations is quite hard [28]. For this reason, we adopt different techniques for obtaining complexity upper bounds for the typechecking problem.
The transducers considered in the present paper are restricted versions of the DTL-programs, studied by Maneth and Neven [19]. They already obtained a non-elementary upper bound on the complexity of typechecking (due to the use of monadic second-order logic in the definition of the transducers). Recently, Maneth et al. considered the typechecking problem for an extension of DTL-programs and obtained that typechecking was still decidable [20]. Their typechecking algorithm, like the one of [25], is based on inverse type inference. That is, they compute the pre-image of all ill-formed output documents and test whether the intersection of the pre-image and the input schema is empty. Tozawa considered typechecking with respect to tree automata for a fragment of top-down XSLT [34]. He uses a more general framework, but he was not able to derive a bound better than double-exponential on the complexity of his algorithm.
Martens and Neven investigated polynomial time fragments of the typechecking problem by putting syntactical restrictions on the tree transducers, and making them as general as possible [21]. Here, tractability of the typechecking problem is obtained by bounding the deletion path width of the tree transducers. The deletion path width is a notion that measures the number of times that a tree transducer copies part of its input. In particular, it also gives rise to tractable fragments of the typechecking problem where the transducer is allowed to delete in a limited manner.

Preliminaries
In this section we provide the necessary background on trees, automata, and tree transducers. In the following, Σ always denotes a finite alphabet.
By N we denote the set of natural numbers. A string w = a 1 · · · a n is a finite sequence of Σ-symbols. The set of positions, or the domain, of w is Dom(w) = {1, . . . , n}. The length of w, denoted by |w|, is the number of symbols occurring in it. The label a i of position i in w is denoted by lab w (i). The size of a set S, is denoted by |S|.
As usual, a nondeterministic finite automaton (NFA) over Σ is a tuple N = (Q, Σ, δ, I, F ) where Q is a finite set of states, δ : Q × Σ → 2 Q is the transition function, I ⊆ Q is the set of initial states, and F ⊆ Q is the set of final states. A run ρ of N on a string w ∈ Σ * is a mapping from Dom(w) to Q such that ρ(1) ∈ δ(q, lab w (1)) for q ∈ I, and for i = 1, . . . , |w| − 1, ρ(i + 1) ∈ δ(ρ(i), lab w (i + 1)). A run is accepting if ρ(|w|) ∈ F . A string is accepted if there is an accepting run. The language accepted by N is denoted by L(N ). The size of N is defined as |Q| + |Σ| + q∈Q,a∈Σ |δ(q, a)|.
A deterministic finite automaton (DFA) is an NFA where (i) I is a singleton and (ii) |δ(q, a)| ≤ 1 for all q ∈ Q and a ∈ Σ.

Trees and Hedges
It is common to view XML documents as finite trees with labels from a finite alphabet Σ. Figures 1(a) and 1(b) give an example of an XML document together with its tree representation. Of course, elements in XML documents can also contain references to nodes. But, as XML schema languages usually do not constrain these nor the data values at leaves, it is safe to view schemas as simply defining tree languages over a finite alphabet. In the rest of this section, we introduce the necessary background concerning XML schema languages. <store> <dvd> <title> "Amelie" </title> <price> 17 </price> </dvd> <dvd> <title> "Good bye, Lenin!" </title> <price> 20 </price> </dvd> <dvd> <title> "Pulp Fiction" </title> <price> 11 </price> <discount> 6 </discount> </dvd> </store>  The set of unranked Σ-trees, denoted by T Σ , is the smallest set of strings over Σ and the parenthesis symbols "(" and ")" such that, for a ∈ Σ and w ∈ T Σ * , a(w) is in T Σ . So, a tree is either ε (empty) or is of the form a(t 1 · · · t n ) where store (ε) The tree of Figure 1(b) without data values. The nodes are annotated next to the labels, between brackets.
store (1) dvd (1 1) title Figure 2(a) viewed as a hedge. The nodes are annotated next to the labels, between brackets.  Figure 1 without data values, viewed as a tree and as a hedge.
each t i is a tree. In the tree a(t 1 · · · t n ), the subtrees t 1 , . . . , t n are attached to a root labeled a. We write a rather than a(). Note that there is no a priori bound on the number of children of a node in a Σ-tree; such trees are therefore unranked. For every t ∈ T Σ , the set of tree-nodes of t, denoted by Dom T (t), is the set defined as follows: (i) if t = ε, then Dom T (t) = ∅; and, Figure 2(a) contains a tree in which we annotated the nodes between brackets. Observe that the n child nodes of a node u are always u1, . . . , un, from left to right. The label of a node u in the tree t = a(t 1 · · · t n ), denoted by lab t T (u), is defined as follows: (i) if u = ε, then lab t T (u) = a; and, (ii) if u = iu ′ , then lab t T (u) = lab ti T (u ′ ). We define the depth of a tree t, denoted by depth(t), as follows: if t = ε, then depth(t) = 0; and if t = a(t 1 · · · t n ), then depth(t) = max{depth(t i ) | 1 ≤ i ≤ n} + 1. In the sequel, whenever we say tree, we always mean Σ-tree. A tree language is a set of trees.
A hedge is a finite sequence of trees. Hence, the set of hedges, denoted by H Σ , equals T * Σ . For every hedge h ∈ H Σ , the set of hedge-nodes of h, denoted by Dom H (h), is the subset of N * defined as follows: The label of a node u = iu ′ in the hedge h = t 1 · · · t n , denoted by lab h H (u), is defined as lab h H (u) = lab ti T (u ′ ). Note that the set of hedge-nodes of a hedge consisting of one tree is different from the set of tree-nodes of this tree. For example: if the tree in Figure 2(a) were to represent a single-tree hedge, it would have the set of hedge-nodes {1, 11,12,13,111,112,121,122,131, 132, 133}, as shown in Figure 2(b). The depth of the hedge h = t 1 · · · t n , denoted by depth(h), is defined as max{depth(t i ) | i = 1, . . . , n}. For a hedge h = t 1 · · · t n , we denote by top(h) the string obtained by concatenating the root symbols of all t i s, that is, lab t1 H (1) · · · lab tn H (n). In the sequel, we adopt the following conventions: we use t, t 1 , t 2 , . . . to denote trees and h, h 1 , h 2 , . . . to denote hedges. Hence, when we write h = t 1 · · · t n we tacitly assume that all t i 's are trees. We denote Dom T and Dom H simply by Dom, and we denote lab T and lab H by lab when it is understood from the context whether we are working with trees or hedges.

DTDs and Tree Automata
We use extended context-free grammars and tree automata to abstract from DTDs and the various proposals for XML schemas. We parameterize the definition of DTDs by a class of representations M of regular string languages such as, for instance, the class of DFAs (Deterministic Finite Automata) or NFAs (Non-deterministic Finite Automata). For M ∈ M, we denote by L(M ) the set of strings accepted by M . We then abstract DTDs as follows.
Definition 3.1. Let M be a class of representations of regular string languages over Σ. A DTD is a tuple (d, s d ) where d is a function that maps Σ-symbols to elements of M and s d ∈ Σ is the start symbol.
For convenience of notation, we denote (d, s d ) by d and leave the start symbol s d implicit whenever this cannot give rise to confusion. A tree t satisfies d if (i) lab t (ε) = s d and, (ii) for every u ∈ Dom(t) with n children, lab t (u1) · · · lab t (un) ∈ L(d(lab t (u))). By L(d) we denote the set of trees satisfying d.
Given a DTD d, we say that a Σ-symbol a occurs in d(b) when there exist Σ-strings w 1 and w 2 such that w 1 aw 2 ∈ L(d(b)). We say that a occurs in d if a occurs in d(b) for some b ∈ Σ.
We denote by DTD(M) the class of DTDs where the regular string languages are represented by elements of M. The size of a DTD is the sum of the sizes of the elements of M used to represent the function d.
This DTD defines the set of trees where the root is labeled with "store"; the children of "store" are all labeled with "dvd"; and every "dvd"-labeled node has a "title", "price", and an optional "discount" child.
In some cases, our algorithms are easier to explain on well-behaved DTDs as considered next. A DTD d is reduced if, for every symbol a that occurs in d, there exists a tree t ∈ L(d) and a node u ∈ Dom(t) such that lab t (u) = a. Hence, for example, the DTD (d, a) where d(a) = a is not reduced. Reducing a DTD(DFA) is in ptime, while reducing a DTD(SL) is in conp (see the Appendix, Corrollary .9). Here, SL is a logic as defined next.
To define unordered languages, we make use of the specification language SL inspired by [27] and also used in [1,2]. The syntax of this language is as follows: For every a ∈ Σ and natural number i, a =i and a ≥i are atomic SL-formulas; "true" is also an atomic SL-formula. Every atomic SL-formula is an SL-formula and the negation, conjunction, and disjunction of SL-formulas are also SL-formulas.
A string w over Σ satisfies an atomic formula a =i if it has exactly i occurrences of a; w satisfies a ≥i if it has at least i occurrences of a. Furthermore, "true" is satisfied by every string. Satisfaction of Boolean combinations of atomic formulas is defined in the obvious way. 1 By w |= φ, we denote that w satisfies the SL-formula φ.
As an example, consider the SL-formula ¬(discount ≥1 ∧ ¬price ≥1 ). This expresses the constraint that a discount can only occur when a price occurs. The size of an SL-formula is the number of symbols that occur in it, that is, Σ-symbols, logical symbols, and numbers (every i in a =i or a ≥i is written in binary notation).
We recall the definition of non-deterministic tree automata from [6]. We refer the unfamiliar reader to [26] for a gentle introduction. Definition 3.4. A nondeterministic tree automaton (NTA) is a 4-tuple B = (Q, Σ, δ, F ), where Q is a finite set of states, F ⊆ Q is the set of final states, and δ : Q × Σ → 2 Q * is a function such that δ(q, a) is a regular string language over Q for every a ∈ Σ and q ∈ Q.
For simplicity, we often denote the regular languages in B's transition function by regular expressions.
A run of B on a tree t is a labeling λ : Dom(t) → Q such that, for every v ∈ Dom(t) with n children, λ(v1) · · · λ(vn) ∈ δ(λ(v), lab t (v)). Note that, when v has no children, the criterion reduces to ε ∈ δ(λ(v), lab t (v)). A run is accepting if the root is labeled with an accepting state, that is, λ(ε) ∈ F . A tree is accepted if there is an accepting run. The set of all accepted trees is denoted by L(B) and is called a regular tree language.
A tree automaton is bottom-up deterministic if, for all q, q ′ ∈ Q with q = q ′ and a ∈ Σ, δ(q, a) ∩ δ(q ′ , a) = ∅. We denote the set of bottom-up deterministic NTAs by DTA.
Example 3.5. We give a bottom-up deterministic tree automaton B = (Q, Σ, δ, F ) which accepts the parse trees of well-formed Boolean expressions that are true. Here, the alphabet Σ is {∧, ∨, ¬, true, false}. The states set Q contains the states q true and q false , and the accepting state set F is the singleton {q true }. The transition function of B is defined as follows: • δ(q true , true) = ε. We assign the state q true to leafs with label "true".
• δ(q false , false) = ε. We assigns the state q false to leafs with label "false".
Consider the tree t depicted in Figure 3(a). The unique accepting run r of B on t can be graphically represented as shown in Figure 3(b). Formally, the run of B on t is the function λ : Dom(t) → Q : u → lab r (u). Note that B is a DTA.
As for DTDs, we parameterize NTAs by the formalism used to represent the regular languages in the transition functions δ(q, a). So, for a class of representations of regular languages M, we denote by NTA(M) the class of NTAs where all transition functions are represented by elements of M. The size of an automaton B then is |Q| + |Σ| + q∈Q,a∈Σ |δ(q, a)|. Here, by |δ(q, a)|, we denote the size of the automaton accepting δ(q, a). Unless explicitly specified otherwise, δ(q, a) is always represented by an NFA.
In our proofs, we will use reductions from the following decision problems for string automata:  Intersection emptiness: Given the automata A 1 , . . . , A n , is L(A 1 ) ∩ · · · ∩ L(A n ) = ∅?
The corresponding decision problems for tree automata are defined analogously.
In the Appendix, we show that the following statements hold over the alphabet {0, 1} (Corollary .2): 1. Intersection emptiness of an arbitrary number of DFAs is pspace-hard.

Transducers
We adhere to transducers as a formal model for simple transformations corresponding to structural recursion [8] and a fragment of top-down XSLT. As in [25], the abstraction focuses on structure rather than on content. We next define the tree transducers used in this paper. To simplify notation, we restrict ourselves to one alphabet. That is, we consider transducers mapping Σ-trees to Σ-trees. 2 For a set Q, denote by H Σ (Q) (respectively T Σ (Q)) the set of Σ-hedges (respectively trees) where leaf nodes are labeled with elements from Σ ∪ Q instead of only Σ. Definition 3.6. A tree transducer is a 4-tuple T = (Q, Σ, q 0 , R), where Q is a finite set of states, Σ is the input and output alphabet, q 0 ∈ Q is the initial state, and R is a finite set of rules of the form (q, a) → h, where a ∈ Σ, q ∈ Q, and h ∈ H Σ (Q). When q = q 0 , h is restricted to be either empty, or consist of only one tree with a Σ-symbol as its root label.
The restriction on rules with the initial state ensures that the output is always a tree rather than a hedge. Transducers are required to be deterministic: for every pair (q, a), there is at most one rule in R.
The translation defined by a tree transducer T = (Q, Σ, q 0 , R) on a tree t in state q, denoted by T q (t), is inductively defined as follows: if t = ε then T q (t) := ε; if t = a(t 1 · · · t n ) and there is a rule (q, a) → h ∈ R then T q (t) is obtained from h by replacing every node u in h labeled with state p by the hedge T p (t 1 ) · · · T p (t n ). Note that such nodes u can only occur at leaves. So, h is only extended downwards. If there is no rule (q, a) → h ∈ R then T q (t) := ε. Finally, the transformation of t by T , denoted by T (t), is defined as T q 0 (t), interpreted as a tree.
For a ∈ Σ, q ∈ Q and (q, a) → h ∈ R, we denote h by rhs(q, a). If q and a are not important, we say that h is an rhs. The size of T is |Q| + |Σ| + q∈Q,a∈Σ |rhs(q, a)|, where |rhs(q, a)| denotes the number of nodes in rhs(q, a). In the sequel, we always use p, p 1 , p 2 , . . . and q, q 1 , q 2 , . . . to denote states.
Let q be a state of tree transducer T and a ∈ Σ. We then define q T [a] := top(T q (a)). For a string w = a 1 · · · a n , we define q T [w] := q T [a 1 ] · · · q T [a n ]. In the sequel, we leave T implicit whenever T is clear from the context.
We give an example of a tree transducer: Note that the right-hand side of (q, a) → c p is a hedge consisting of two trees, while the other right-hand sides consist of only one tree.
We discuss two important features of tree transducers: copying and deletion. In Example 3.7, the rule (q, b) → c(p q) copies the children of the current node in the input tree twice: one copy is processed in state p and the other in state q. The symbol c is the parent node of the two copies. So, one could say that the current node is translated in the new parent node labeled c. The rule (q, a) → c p copies the children of the current node only once. However, no parent node is given for this copy. So, there is no node in the output tree that can be interpreted as the translation of the current node in the input tree. We therefore say that it is deleted. For instance, T q (a(b)) = c d where d corresponds to b and not to a.
We define some relevant classes of transducers. A transducer is non-deleting if no states occur at the top-level of any rhs. We denote by T nd the class of non-deleting transducers and by T d the class of transducers where we allow deletion. Furthermore, a transducer T has copying width k if there are at most k occurrences of states in every sequence of siblings in an rhs. For instance, the transducer in Example 3.7 has copying width 2. Given a natural number k, which we will leave implicit, we denote by T bc the class of transducers of copying width k. The abbreviation "bc" stands for bounded copying. We denote intersections of these classes by combining the indexes. For instance, T nd,bc is The translation of t by the transducer T of Example 3.7. the class of non-deleting transducers with bounded copying. When we want to emphasize that we also allow unbounded copying in a certain application, we write, for instance, T nd,uc instead of T nd .

The Typechecking Problem
Definition 3.9. A tree transducer T typechecks with respect to to an input tree language S in and an output tree language S out , if T (t) ∈ S out for every t ∈ S in .
We now define the problem central to this paper.
Definition 3.10. Given S in , S out , and T , the typechecking problem consists in verifying whether T typechecks with respect to S in and S out .
We parameterize the typechecking problem by the kind of tree transducers and tree languages we allow. Let T be a class of transducers and S be a representation of a class of tree languages. Then TC[T , S] denotes the typechecking problem where T ∈ T and S in , S out ∈ S. Examples of classes of tree languages are those defined by tree automata or DTDs. Classes of transducers are discussed in the previous section. The complexity of the problem is measured in terms of the sum of the sizes of the input and output schemas S in and S out and the transducer T . Table 1 summarizes the results obtained in [23]. Unless specified otherwise, all problems are complete for the mentioned complexity classes. In the set-  Table 1: Results of [23] (upper and lower bounds). The top row shows the representation of the input and output schemas and the left column shows the class of tree transducer: "d", "nd", "uc", and "bc" stand for "deleting", "nondeleting", "unbounded copying", and "bounded copying" respectively.
ting of [23], typechecking is only tractable when restricting to non-deleting and bounded copying transducers in the presence of DTDs with DFAs.
Recall that, in this article, we are interested in variants of the typechecking problem where the input and/or output schema is fixed. We therefore introduce some notations that are central to the paper. We denote the typechecking problem where the input schema, the output schema, or both are fixed by respectively. The complexity of these subproblems is measured in terms of the sum of the sizes of the input and output schemas S in and S out , and the transducer T , minus the size of the fixed schema(s).

fixed
TT NTA DTA DTD(NFA) DTD(DFA) DTD(SL) in, out, d,uc EXPTIME EXPTIME EXPTIME EXPTIME EXPTIME in+out d,bc EXPTIME EXPTIME EXPTIME EXPTIME EXPTIME in nd,uc EXPTIME EXPTIME PSPACE PSPACE in PTIME nd,bc EXPTIME EXPTIME PSPACE NL in PTIME out nd,uc EXPTIME EXPTIME PSPACE PSPACE conp nd,bc EXPTIME EXPTIME PTIME ptime conp in+out nd,uc EXPTIME EXPTIME NL NL NL nd,bc EXPTIME EXPTIME NL NL NL Table 2: Complexities of the typechecking problem in the new setting (upper and lower bounds). The top row shows the representation of the input and output schemas, the leftmost column shows which schemas are fixed, and the second column to the left shows the class of tree transducer: "d", "nd", "uc", and "bc" stand for "deleting", "non-deleting", "unbounded copying", and "bounded copying" respectively. In the case of deleting transformations, the different possibilities are grouped as all complexities coincide.
As argued in the Introduction, it makes sense to consider the input and/or output schema not as part of the input for some scenarios. From a complexity theory point of view, it is important to note here that the input and/or output alphabet then also becomes fixed. In this article, we revisit the results of [23] from that perspective.
The results are summarized in Table 2. As some results already follow from proofs in [23], we printed the results requiring a new proof in bold. The entries where the complexity was lowered (assuming that the complexity classes in question are different) are underlined. Again, all problems are complete for the mentioned complexity classes unless specified otherwise.
We discuss the obtained results: for non-deleting transformations, we get three new tractable cases: (i) fixed input schema, unbounded copying, and DTD(SL)s; (ii) fixed output schema, bounded copying and DTD(NFA)s; and, (iii) fixed input and output, unbounded copying and all DTDs. It is striking, however, that in the presence of deletion or tree automata (even deterministic ones) typechecking remains exptime-hard for all scenarios.
Mostly, we only needed to strengthen the lower bound proofs of [23].

Deletion: Fixed Input Schema, Fixed Output Schema, and Fixed Input and Output Schema
The exptime upper bound for typechecking already follows from [23]. Therefore, it remains to show the lower bounds for TC io [T d,bc ,DTD(DFA)] and TC io [T d,bc ,DTD(SL)], which we do in Theorem 4.1. In fact, if follows from the proof that the lower bounds already hold for transducers with copying width 2.
We require the notion of top-down deterministic binary tree automata in the proof of Theorem 4.1. A binary tree automaton (BTA) is a non-deterministic tree automaton B = (Q, Σ, δ, F ) operating on binary trees. These are trees where every node has zero, one, or two children. We assume that the alphabet is partitioned in internal labels and leaf labels. When a label a is an internal label, the regular language δ(q, a) only contains strings of length one or two. When a is a leaf label, the regular language δ(q, a) only contains the empty string. A binary tree automaton is top-down deterministic if (i) F is a singleton and, (ii) for every q, q ′ ∈ Q with q = q ′ and a ∈ Σ, δ(q, a) contains at most one string. We abbreviate "top-down deterministic binary tree automaton" by TDBTA.
Proof. The exptime upper bound follows from Theorem 11 in [23]. We proceed by proving the lower bounds. We give a logspace reduction from the intersection emptiness problem of an arbitrary number of top-down deterministic binary tree automata (TDB-TAs) over the alphabet Σ = {0, 1, 0 ′ , 1 ′ }. The intersection emptiness problem of Without loss of generality, we can assume that the state sets Q i are pairwise disjoint. We call 0 and 1 internal labels and 0 ′ and 1 ′ leaf labels. In our proof, we use the markers 'ℓ' and 'r' to denote that a certain node is a left or a right child. Formally, define Σ ℓ := {a ℓ | a ∈ Σ} and Σ r := {a r | a ∈ Σ}. We use symbols from Σ ℓ and Σ r for the left and right children of nodes, respectively.
We now define a transducer T and two DTDs d in and d out such that n i=1 L(A i ) = ∅ if and only if T typechecks with respect to d in and d out . In the construction, we exploit the copying power of transducers to make n copies of the input tree: one for each A i . By using deleting states, we can execute each A i on its copy of the input tree without producing output. When an A i does not accept, we output an error symbol under the root of the output tree. The output DTD should then only check that an error symbol always appears. A bit of care needs to be taken, as a bounded copying transducer can not make an arbitrary number of copies of the input tree in the same rule. The transducer therefore goes through an initial copying phase where it repeatedly copies part of the input tree twice, until there are (at least) n copies. The transducer remains in the copying phase as long as it processes special symbols "#". The input trees are therefore of the form as depicted in Figure 6. In addition, the transducer should verify that the number of #-symbols in the input equals ⌈log n⌉.
The input DTD (d in , s), which we will describe next, uses the alphabet Σ ℓ ∪ Σ r ∪ {s, #}, and defines all trees of the form as described in Figure 6, where s and # are alphabet symbols, and every internal node of t (which is depicted in Figure 6) has one or two children. When a node is an only child, it is labeled with an element of Σ ℓ . Otherwise, it is labeled with an element of Σ ℓ or an element of Σ r if it is a left child or a right child, respectively. In this way, the transducer knows whether a node is a left or a right child by examining the label. The root symbol of t is labeled with a symbol from Σ ℓ . Furthermore, all internal nodes of t are labeled with labels in {0 ℓ , 0 r , 1 ℓ , 1 r } and all leaf nodes are labeled with labels in As explained above, we will use the sequence of #-symbols to make a sufficient number of copies of t.
The input DTD (d in , s) is defined as follows: Obviously, (d in , s) can be expressed as a DTD(DFA). It can also be expressed as a DTD(SL), as follows for every a ∈ {0 ℓ , 1 ℓ , 0 r , 1 r }, where • ⊕ denotes the "exclusive or"; • for every i ∈ {ℓ, r} and Notice that the size of the SL-formula expressing d in (a) is constant. We construct a tree transducer . . , n}}. The transducer will use ⌈log n⌉ special copying states q j copy to make at least n copies of the input tree. To define Q T formally, we first introduce the notation D(k), for k = 0, . . . , ⌈log n⌉. Intuitively, D(k) corresponds to the set of nodes of a complete binary tree of depth k + 1. For example, D(1) = {ε, 0, 1} and D(2) = {ε, 0, 1, 00, 01, 10, 11}. The idea is that, the set {q j copy | j ∈ D(⌈log n⌉)} and the set {start ℓ j | n + 1 ≤ j ≤ 2 ⌈log n⌉ }. Note that the last set can be empty. It only contains dummy states translating any input to the empty string.
We next describe the action of the tree transducer T . Roughly, the operation of T on the input s(#(#(· · · #(t)))) can be divided in two parts: (i) copying the tree t a sufficient number of times while reading the #-symbols; and, (ii) simulating one of the TDBTAs on each copy of t. The tree transducer outputs the symbol "error" when one of the TDBTAs rejects t, or when the number of #-symbols in its input is not equal to ⌈log n⌉. Apart from copying the root symbol s to the output tree, T only writes the symbol "error" to the output. Hence, the output tree always has a root labeled s which has zero or more children labeled "error". The output DTD, which we define later, should then verify whether the root has always one "error"-labeled child.
Formally, the transition rules in R T are defined as follows: • (q ε copy , s) → s(q 0 copy q 1 copy ). This rule puts s as the root symbol of the output tree.
These rules copy the tree t in the input at least n times, provided that there are enough #-symbols.
, and i is the binary representation of k. This rule starts the in-parallel simulation of the A i 's. For i = n + 1, . . . , 2 ⌈log n⌉ , start ℓ i is just a dummy state transforming everything to the empty tree.
• (q i copy , a) → error for a ∈ Σ and i ∈ D(⌈log n⌉). This rule makes sure that the output of T is accepted by the output tree automaton if there are not enough #-symbols in the input.
• (start ℓ k , #) → error for all k = 1, . . . , 2 ⌈log n⌉ . This rule makes sure that the output of T is accepted by the output tree automaton if there are too much #-symbols in the input.
• (q ℓ , a r ) → ε and (q r , a ℓ ) → ε for all q ∈ Q j , j = 1, . . . , n. This rule ensures that tree automata states intended for left (respectively right) children are not applied to right (respectively left) children.
• (q ℓ , a ℓ ) → q ℓ 1 q r 2 and (q r , a r ) → q ℓ 1 q r 2 , for every q ∈ Q i , i = 1, . . . , n, such that δ i (q, a) = q 1 q 2 , and a is an internal symbol. This rule does the actual simulation of the tree automata A i , i = 1, . . . , n.
• (q ℓ , a ℓ ) → q ℓ 1 and (q r , a r ) → q ℓ 1 , for every q ∈ Q i , i = 1, . . . , n, such that δ i (q, a) = q 1 and a is an internal symbol. This rule does the actual simulation of the tree automata A i , i = 1, . . . , n.
• (q ℓ , a ℓ ) → ε and (q r , a r ) → ε for every q ∈ Q i , i = 1, . . . , n, such that δ i (q, a) = ε and a is a leaf symbol. This rule simulates accepting computations of the A i 's.
• (q ℓ , a ℓ ) → error and (q r , a r ) → error for every q ∈ Q i , i = 1, . . . , n, such that δ i (q, a) is undefined. This rule simulates rejecting computations of the A i 's.
It is straightforward to verify that, on input s(#(#(· · · #(t)))), T outputs the tree s if and only if there are ⌈log n⌉ #-symbols in the input and t ∈ L(A 1 ) ∩ · · · ∩ L(A n ). Finally, d out (s) = error error * , which can easily be defined as a DTD(DFA) and as a DTD(SL).
It is easy to see that the reduction can be carried out in deterministic logarithmic space, that T has copying width 2, and that d in and d out do not depend on A 1 , . . . , A n .

Non-deleting: Fixed Input Schema
We turn to the typechecking problem in which we consider the input schema as fixed. We start by showing that typechecking is in ptime in the case where we use DTDs with SL-expressions and the tree transducer is non-deleting (Theorem 4.3). To this end, we recall a lemma and introduce some necessary notions that are needed for the proof of Theorem 4.3.
For an SL-formula φ, we say that two strings w 1 and w 2 are φ-equivalent For a ∈ Σ and w ∈ Σ * , we denote by # a (w) the number of a's occurring in w. We recall Lemma 17 from [23]: Let φ be an SL-formula and let k be the largest integer occurring in φ. For every w, w ′ ∈ Σ * , for every a ∈ Σ, • if # a (w ′ ) > k when # a (w) > k, and For a hedge h and a DTD d, we say that h partly satisfies d if for every u ∈ Dom(h), lab h (u1) · · · lab h (un) ∈ L(d(lab h (u))) where u has n children. Note that there is no requirement on the root nodes of the trees in h. Hence, the term "partly".
We are now ready to show the first ptime result: Proof. Denote the tree transformation by T = (Q T , Σ, q 0 T , R T ) and the input and output DTDs by (d in , s in ) and (d out , s out ), respectively. As d in is fixed, we can assume that d in is reduced.
Intuitively, the typechecking algorithm is successful when T does not typecheck with respect to d in and d out . The outline of the typechecking algorithm is as follows: 1. Compute the set RP of "reachable pairs" (q, a) for which there exists a tree t ∈ L(d in ) and a node u ∈ Dom(t) such that lab t (u) = a and T visits u in state q. That is, we compute all pairs (q, a) such that either • q = q 0 T and a = s in ; or • (q ′ , a ′ ) ∈ RP , there is a q-labeled node in rhs(q ′ , a ′ ), and there exists a string w 1 aw 2 ∈ d in (a ′ ) for w 1 , w 2 ∈ Σ * .
2. For each such pair (q, a) and for each node v ∈ Dom(rhs(q, a)), test whether there exists a string w ∈ d in (a) such that T q (a(w)) does not partly satisfy d out . We call w a counterexample.
The algorithm is successful, if and only if there exists a counterexample. We illustrate the general operation of the typechecking algorithm in Figure 7. In this figure, T visits the a-labeled node on the left in state q. Consequently, T outputs the hedge rhs(q, a), which is illustraded by dotted lines on the right. The typechecking algorithm searches for a node u in rhs(q, a) (which is labeled by c in the figure), such that the string of children of u is not in L(d out (c)).
Notice that the typechecking algorithm does not assume that d out is reduced (recall the definition of a reduced DTD from Section 3.2). We need to show that the algorithm is correct, that is, there exists a counterexample if and only if T does not typecheck with respect to d in and d out . Clearly, when the algorithm does not find a counterexample, T typechecks with respect to d in and d out . Conversely, suppose that the algorithm finds a pair (q, a) and a string w such that T q (a(w)) does not partly satisfy d out . So, since we assumed that d in is reduced, there exists a tree t ∈ L(d in ) and a node u ∈ Dom(t) such that lab t (u) = a and u is visited by T in state q. Also, there exists a node v in T q (a(w)), such that the label of u is c and the string of children of u is not in d out (c). We argue that T (t) ∈ L(d out ). There are two cases: (i) if L(d out ) contains a tree with a c-labeled node, then T (t) ∈ d out since T q (a(w)) does not partly satisfy d out ; and (ii) if L(d out ) does not contain a tree with a c-labeled node, then T (t) ∈ d out since T (t) contains a c-labeled node.
We proceed by showing that the algorithm can be carried out in polynomial time. As the input schema is fixed, step (1) of the algorithm is in polynomial time. Indeed, we can compute the set RP of reachable pairs (q, a) in a top-down manner by a straightforward reachability algorithm.
To show that step (2) of the typechecking algorithm is in polynomial time, fix a tuple (q, a) that was computed in step (1) and a node u in rhs(q, a) with label b. Let z 0 q 1 z 1 · · · q n z n be the concatenation of u's children, where all z 0 , . . . , z n ∈ Σ * and q 1 , . . . , q n ∈ Q T . We now search for a string w ∈ Σ * for which w |= d in (a), but for which z 0 q 1 [w]z 1 · · · q n [w]z n |= d out (b). Recall from Section 3.3 that q[w] is the homomorphic extension of q[a] for a ∈ Σ, which is top(rhs(q, a))) in the case of non-deleting tree transducers.
Denote d in (a) by φ. Let {a 1 , . . . , a s } be the different symbols occurring in φ and let k be the largest integer occurring in φ. According to Lemma 4.2, every Σ-string is φ-equivalent to a string of the form w = a m1 1 · · · a ms s with 0 ≤ m i ≤ k + 1 for each i = 1, . . . , s. Note that there are (k + 1) s such strings, which is a constant number, as it only depends on the input schema. For the following, the algorithm considers each such string w.
Fix such a string w such that w |= φ. For each symbol c in d out (b), the number # c (z 0 q 1 [w]z 1 · · · q n [w]z n ) is equal to the linear sum where k c = # c (z 0 · · · z n ) and for each i = 1, . . . , s, k c i = # c (q 1 [a i ] · · · q n [a i ]). We now must test if there exists a string w ′ ≡ φ w such that z 0 q 1 [w ′ ]z 1 · · · q n [w ′ ]z n |= d out (b). Let a 1 , . . . , a ℓ be the symbols that occur at least k + 1 times in w and a ℓ+1 , . . . , a s be the symbols that occur at most k times in w, respectively. Then, deciding whether w ′ exists is equivalent to finding an integer solution to the variables x a1 , . . . , x as for the boolean combination of linear (in)equalities x aj = # aj (w) ; and • Φ 2 states that z 0 q 1 (w ′ )z 1 · · · q n (w ′ )z n |= d out (b), that is, Φ 2 is defined by replacing every occurrence of c =i or c ≥i in d out (b) by the equation respectively.
In the above (in)equalities, x ai , 1 ≤ i ≤ s, represents the number of occurrences of a i in w ′ . Finding a solution for Φ now consists of finding integer values for x a1 , . . . , x as so that Φ evaluates to true. Corollary .7 in the Appendix shows that we can decide in ptime whether such a solution for Φ exists.

Theorem 4.4. T C i [T nd,bc , DTD(DFA)] is nlogspace-complete.
Proof. In Theorem 4.9(2), we prove that the problem is nlogspace-hard, even if both the input and output schemas are fixed. Hence, it remains to show that the problem is in nlogspace.
Let us denote the tree transformation by T = (Q T , Σ, q 0 T , R T ) and the input and output DTDs by (d in , r) and d out , respectively. We can assume that d in is reduced. 3 Then, the typechecking algorithm can be summarized as follows: 1. Guess a sequence of pairs (q 0 , a 0 ), (q 1 , a 1 ), . . . , (q n , a n ) in Q T × Σ in , such that • (q 0 , a 0 ) = (q 0 T , r); and • for every pair (q i , a i ), q i+1 occurs in rhs(q i , a i ) and a i+1 occurs in some string in L(d in (a i )).
We only need to remember (q n , a n ) as a result of this step.
2. Guess a node u in rhs(q n , a n ) -say that u is labeled with b -and test whether there exists a string w ∈ d in (a n ) such that T q (a n (w)) does not partly satisfy d out .
The algorithm is successful if and only if w exists and, hence, the problem does not typecheck. The first step is a straightforward reachability algorithm, which is in nlogspace. It remains to show that the second step is in nlogspace.
Let (q, a) be the pair (q n , a n ) computed in step two. Let d out (b) = (Q out , Σ, δ out , {p I }, {p F }) be a DFA and let k be the copying bound of T . Let z 0 q 1 z 1 · · · q ℓ z ℓ be the concatenation of u's children, where ℓ ≤ k. So we want to check whether there exists a string w such that z 0 q 1 [w]z 1 · · · q ℓ [w]z ℓ is not accepted by d out (b). We guess w one symbol at a time and simulate in parallel ℓ copies of d out (b) and one copy of d in (a).
Byδ we denote the canonical extension of δ to strings in Σ * . We start by guessing states p 1 , . . . , p ℓ of d out (b), where p 1 =δ out (p I , z 0 ), and keep a copy of these on tape, to which we refer as p ′ 1 , . . . , p ′ ℓ . Next, we keep on guessing symbols c of w, whereafter we replace each p i byδ out (p i , q i (c)). The input automaton obviously starts in its initial state and is simulated in the straightforward way.
The machine non-deterministically stops guessing, and checks whether, for each i = 1, . . . , ℓ − 1,δ out (p i , z i ) = p ′ i+1 andδ out (p ℓ , z ℓ ) = p F . For the input automaton, it simply checks whether the current state is the final state. If the latter tests are positive, then the algorithm accepts, otherwise, it rejects.
We only keep 2ℓ + 1 states on tape, which is a constant number, so the algorithm runs in nlogspace. Proof. In [23], it was shown that both problems are in pspace. We proceed by showing that they are also pspace-hard.
(1) We reduce the intersection emptiness problem of an arbitrary number of deterministic finite automata with alphabet {0, 1} to the typechecking problem. This problem is known to be pspace-hard, as shown in Corollary .2(1) in the Appendix. Our reduction only requires logarithmic space. We define a transducer T = (Q T , {0, 1, # 0 , . . . , # n }, q 0 T , R T ) and two DTDs d in and d out such that T typechecks with respect to d in and d out if and only if n i=1 L(M i ) = ∅. The DTD (d in , s) defines trees of depth two, where the string formed by the children of the root is an arbitrary string in {0, 1} * , so d in (s) = (0 + 1) * . The transducer makes n copies of this string, separated by the delimiters # i : Q T = {q, q 0 T } and R T contains the rules (q 0 T , s) → s(# 0 q# 1 q . . . # n−1 q# n ) and (q, a) → a, for every a ∈ Σ. Finally, (d out , s) defines a tree of depth two as follows: Clearly, d out (s) can be represented by a DFA whose size is polynomial in the sizes of the M i 's. Indeed, the DFA just simulates every M i on the string following # i−1 , until it encounters # i . It then verifies that at least one M i rejects. It is easy to see that this reduction can be carried out by a deterministic logspace algorithm.
(2) This is an easy reduction from the universality problem of an NFA N with alphabet {0, 1}. The latter problem is pspace-hard, as shown in Corollary .2(2) in the Appendix. Again, the input DTD (d in , s) defines a tree of depth two where d in (s) = (0 + 1) * . The tree transducer is the identity transformation.
The output DTD d out has as start symbol s and d out (s) = L(N ). Hence, this instance typechecks if and only if {0, 1} * ⊆ L(N ).
This reduction can be carried out by a deterministic logspace algorithm.

Non-deleting: Fixed Output Schema
Again, upper bounds carry over from [23]. Also, when the output DTD is a DTD(NFA), we can convert it into an equivalent DTD(DFA) in constant time. As the ptime typechecking algorithm for TC[T nd,bc ,DTD(DFA)] in [23] also works when the input DTD is a DTD(NFA), we have that the problem TC o [T nd,bc ,DTD(NFA)] is in ptime. As the ptime-hardness proof for TC[T nd,bc ,DTD(DFA)] in [23] uses a fixed output schema, we immediately obtain the following.  Proof. In [23], it was shown that the problem is in pspace. We proceed by showing pspace-hardness.
We use a logspace reduction from the corridor tiling problem [9]. Let (T, V, H,θ,β) be a tiling system, where T = {ϑ 1 , . . . , ϑ k } is the set of tiles, V ⊆ T × T and H ⊆ T × T are the sets of vertical and horizontal constraints respectively, andθ andβ are the top and bottom row, respectively. Let n be the width of ϑ andβ. The tiling system has a solution if there is an m ∈ N such that the space m × n (m rows and n columns) can be correctly tiled with the additional requirement that the bottom and top row areβ andθ, respectively.
We now construct a tree transducer B = (Q B , Σ, q 0 B , R B ) and an output DTD d out such that T has no correct corridor tiling if and only if B typechecks with respect to d in and d out . Intuitively, the transducer and the output DTD have to work together to determine errors in input tilings. There can only be two types of error: two tiles do not match horizontally or two tiles do not match vertically. The main difficulty is that the output DTD is fixed and can, therefore, not depend on the tiling system. The transducer is constructed in such a way that it prepares in parallel the verification for all horizontal and vertical constraints by the output schema. In particular, the transducer outputs specific symbols from a fixed set independent of the tiling system allowing the output schema to determine whether an error occurred.
The state set Q B is partitioned into two sets, Q hor and Q ver : • Q hor is for the horizontal constraints: for every i ∈ {1, . . . , n − 1} and ϑ ∈ T , q i,ϑ ∈ Q hor transforms the rows in the tiling such that it is possible to check that when position i carries a ϑ, position i + 1 carries a ϑ ′ such that (ϑ, ϑ ′ ) ∈ H; and, • Q ver is for the vertical constraints: for every i ∈ {1, . . . , n} and ϑ ∈ T , p i,ϑ ∈ Q ver transforms the rows in the tiling such that it is possible to check that when position i carries a ϑ, the next row carries a ϑ ′ on position i such that (ϑ, ϑ ′ ) ∈ V .
The tree transducer B always starts its transformation with the rule (q 0 B , r) → r(w), where w is the concatenation of all of the above states, separated by the delimiter $. The other rules are of the following form: • Horizontal constraints: for all (j, ϑ) ∈ Σ add the rule (q i,ϑ , (j, ϑ ′ )) → α where q i,ϑ ∈ Q hor and The intuition is as follows: if the i-th position in a row is labeled with ϑ, then this position is transformed into trigger. Position i + 1 is transformed to ok when it carries a tile that matches ϑ horizontally. Otherwise, it is transformed to error. All other symbols are transformed into an other.
On a row, delimited by two hor-symbols, the output DFA rejects if and only if there is a trigger immediately followed by an error. When there is no trigger, then position i was not labeled with ϑ. So, the label trigger acts as a trigger for the output automaton.
• Vertical constraints: for all (j, ϑ) ∈ Σ, add the rule (p i,ϑ , (j, ϑ ′ )) → α where p i,ϑ ∈ Q ver and The intuition is as follows: if the i-th position in a row is labeled with ϑ, then this position is transformed into trigger1 when (ϑ, ϑ) ∈ V and to trigger2 when (ϑ, ϑ) ∈ V . Here, both trigger1 and trigger2 act as a trigger for the output automaton: they mean that position i was labeled with ϑ. But no trigger1 and trigger2 can occur in the same transformed row as either (θ, θ) ∈ V or (θ, θ) ∈ V . When position i is labeled with ϑ ′ = ϑ, then we transform this position into ok when (ϑ, ϑ ′ ) ∈ V , and in error when (ϑ, ϑ ′ ) ∈ V . All other positions are transformed into other.
The output DFA then works as follows. If a position is labeled trigger1 then it rejects if there is a trigger2 or a error occurring after the next ver. If a position is labeled trigger2, then it rejects if there is a trigger2 or a error occurring after the next ver. Otherwise, it accepts that row.
By making use of the delimiters ver and hor, both above described automata can be combined into one automaton, taking care of the vertical and the horizontal constraints. This automaton resets to its initial state whenever it reads the delimiter symbol $. Note that the output automaton is defined over the fixed alphabet {trigger, trigger1, trigger2, error, ok, other, hor, ver, $}.
Although the results in [23] were formulated in the context of variable schemas, the proofs for bounded copying, non-deleting tree transducers with DTD(SL) and with DTD(DFA) schemas actually used a fixed output schema. We can therefore sharpen these results as follows.

Non-deleting: Fixed Input and Output Schema
We turn to the case where both input and output schemas are fixed. The following two theorems give us several new tractable cases.

T C io [T nd,bc , DTD(DFA)] is nlogspace-complete.
Proof. For both problems, membership in nlogspace follows from Theorem 4.10. Indeed, every DTD(SL) can be rewritten into an equivalent DTD(NFA) in constant time as the input and output schemas are fixed. We proceed by showing nlogspace-hardness. We say that an NFA N = (Q N , Σ, δ N , I N , F N ) has degree of nondeterminism 2 if (i) I N has at most two elements and (ii) for every q ∈ Q N and a ∈ Σ, the set δ N (q, a) has at most two elements. We give a logspace reduction from the emptiness problem of an NFA with alphabet {0, 1} and a degree of nondeterminism 2 to the typechecking problem. According to Lemma .3 in the Appendix, this problem is nlogspacehard. Intuitively, the input DTD will define all possible strings over alphabet {0, 1}. The tree transducer simulates the NFA and outputs "accept" if a computation branch accepts, and "error" if a computation branch rejects. The output DTD defines trees where all leaves are labeled with "error".
More concretely, let N = (Q N , {0, 1}, δ N , {q 0 N }, F N ) be an NFA with degree of nondeterminism 2. The input DTD (d in , r) defines all unary trees, where the unique leaf is labeled with a special marker #. That is, d in (r) = d in (0) = d in (1) = (0 + 1 + #) and d in (#) = ε. Note that these languages can be defined by SL-formulas or DFAs which are sufficiently small for our purpose.
Given a tree t = r(a 1 (· · · (a n (#)) · · · )), the tree transducer will simulate every computation of N on the string a 1 · · · a n . The tree transducer T = (Q T , {r, #, 0, 1, error, accept}, q 0 T , R T ) simulates N 's nondeterminism by copying the remainder of the input twice in every step. Formally, Q T is the union of {q 0 T } and Q N , and R T contains the following rules: . This rule puts r as the root symbol of the output tree and starts the simulation of N .
This rule does the actual simulation of N . By continuing in both states q 1 N and q 2 N , we simulate all possible computations of N .
If N rejects, we output the symbol "error".
• (q N , #) → error for q N ∈ F N ; and • (q N , #) → accept for q N ∈ F N . These last two rules verify whether N is in an accepting state after reading the entire input string.
Notice that T outputs the symbol "error" (respectively "accept") if and only if a computation branch of N rejects (respectively accepts).
The output of T is always a tree in which only the symbols "error" and "accept" occur at the leaves. The output DTD then needs to verify that only the symbol "error" occurs at the leaves. Formally, d out (r) = d out (0) = d out (1) = {0, 1, error} + and d out (error) = ε. Again, these languages can be defined by sufficiently small SL-formulas or DFAs.
It is easy to see that the reduction only requires logarithmic space. Proof. The nlogspace-hardness of the problem follows from Theorem 4.9(b), where it shown that the problem is already nlogspace-hard when DTD(DFA)s are used as input and output schema. We show that the problem is also in nlogspace. Thereto, let T = (Q T , Σ, q 0 T , R T ) be the tree transducer, and let (d in , r) and d out be the input and output DTDs, respectively. As both d in and d out are fixed, we can assume without loss of generality that they are reduced. 4 For the same reason, we can also assume that the NFAs in d in and d out are determinized.
We guess a sequence of state-label pairs (p 0 , a 0 ), (p 1 , a 1 ), . . . , (p n , a n ) where n < |Q T ||Σ| such that • (p 0 , a 0 ) = (q 0 T , r); and • for every pair (p i , a i ), p i+1 occurs in rhs(p i , a i ) and a i+1 occurs in some string in L(d in (a i )).
Each time we guess a new pair in this sequence, we forget the previous one, so that we only keep a state, an alphabet symbol, a counter, and the binary representation of |Q T ||Σ| on tape.
For simplicity, we write (p n , a n ) as (p, a) in the remainder of the proof. We guess a node u ∈ Dom(rhs(p, a)). Let b = lab rhs(p,a) (u) and let z 0 q 1 z 1 · · · q k z k be the concatenation of u's children, where every z 0 , . . . , z k ∈ Σ * and every q 1 , . . . , q k ∈ Q T , then we want to check whether there exists a string w ∈ d in (a) such that z 0 q 1 [w]z 1 · · · q k [w]z k is not accepted by d out (b). Recall from Section 3.3 that, for a state q ∈ Q T , we denote by q[w] the homomorphic extension of q[c] for c ∈ Σ, which is top(rhs(q, c))) in the case of non-deleting tree transducers. We could do this by guessing w one symbol at a time and simulating k copies of d out (b) and one copy of d in (a) in parallel, like in the proof of Theorem 4.4. However, as k is not fixed, the algorithm would use superlogarithmic space. So, we need a different approach. To this end, let A = (Q in , Σ, δ in , q 0 in , F in ) and B = (Q out , Σ, δ out , q 0 out , F out ) be the DFAs accepting d in (a) and d out (b), respectively. To every q ∈ Q T , we associate a function whereδ out denotes the canonical extension of δ out to strings in Σ * . Note that there are maximally |Q out | |Qout||Σ| such functions. Let K be the cardinality of the set {f q | q ∈ Q T }. Hence, K is bounded from above by |Q out | |Qout||Σ| , which is a constant (with respect to the input). Let f 1 , . . . , f K an arbitrary enumeration of {f q | q ∈ Q T }.
It now remains to verify whether w was indeed a string such that w ∈ d in (a) and z 0 q 1 [w]z 1 · · · q k [w]z k ∈ d out (b). The former condition is easy to test: we simply have to test whether p ′ 0 ∈ F in . To test the latter condition, we read the string z 0 q 1 z 1 · · · q k z k from left to right while performing the following tests. We keep a state of d out (b) in memory and refer to it as the "current state".
1. The initial current state is q 0 out .
2. If the current state is p ′ and we read z j , then we change the current state toδ out (p ′ , z j ).
3. If the current state is p ′ and we read q j , then we change the current state to p ′ i inp, where for i, the following condition holds. Let ℓ, m = 1, . . . , K · |Q out | be the smallest integers such that Note that deciding whether p ′ = q ′ ℓ and f qj = f m can be done deterministically in logarithmic space, as the output schema is fixed. Consequently, i can also be computed in constant time and space. 4. We stop and accept if the current state is a non-accepting state after reading z k . Proof. The proof is quite analogous to the proof of Theorem 4.1. As deletion is now disallowed, whereas it was allowed in Theorem 4.1, we need to define the rules of the transducer T = (Q T , Σ T , q ε copy , R T ) differently. The language defined by the input schema is exaclty the same as in Theorem 4.1. The transition rules in R T are defined as follows: • (q ε copy , s) → s(q 0 copy q 1 copy ); • (q i copy , #) → #(q i0 copy q i1 copy ) for i ∈ D(⌈log n⌉ − 1) − {ε}; • (q i copy , #) → #(start ℓ k ), where i ∈ D(⌈log n⌉) − D(⌈log n⌉ − 1), and i is the binary representation of k; • (q i copy , a) → error for a ∈ Σ and i ∈ D(⌈log n⌉); • (start ℓ k , #) → error for all k = 1, . . . , 2 ⌈log n⌉ ; • (q ℓ , a r ) → ε and (q r , a ℓ ) → ε for all q ∈ Q j , j = 1, . . . , n; • (q ℓ , a ℓ ) → a ℓ (q ℓ 1 q r 2 ) and (q r , a r ) → a r (q ℓ 1 q r 2 ), for every q ∈ Q i , i = 1, . . . , n, such that δ i (q, a) = q 1 q 2 , and a is an internal symbol; • (q ℓ , a ℓ ) → a ℓ (q ℓ 1 ) and (q r , a r ) → a r (q ℓ 1 ), for every q ∈ Q i , i = 1, . . . , n, such that δ i (q, a) = q 1 and a is an internal symbol; • (q ℓ , a ℓ ) → ε and (q r , a r ) → ε for every q ∈ Q i , i = 1, . . . , n, such that δ i (q, a) = ε and a is a leaf symbol; and • (q ℓ , a ℓ ) → error and (q r , a r ) → error for every q ∈ Q i , i = 1, . . . , n, such that δ i (q, a) is undefined.
It is straightforward to verify that, on input s(#(#(· · · #(t)))), T performs the identity transformation if and only if there are ⌈log n⌉ #-symbols in the input and t ∈ L(A 1 ) ∩ · · · ∩ L(A n ). All other outputs contain at least one leaf labeled "error". Finally, the output tree automaton accepts all trees with at least one leaf that is labeled "error". So the only counterexamples for typechecking are those trees that are accepted by all automata.
It is easy to see that the reduction can be carried out in deterministic logarithmic space, that T has copying width 2, and that the input and output schemas do not depend on A 1 , . . . , A n .

Conclusion
We considered the complexity of typechecking in the presence of fixed input and/or output schemas. We have settled an open question in [23], namely that TC[T nd,bc , DT A] is exptime-complete.
In comparison with the results in [23], fixing input and/or output schemas only lowers the complexity in the presence of DTDs and when deletion is disallowed. Here, we see that the complexity is lowered when In all of these cases, the complexity of the typechecking problem is in polynomial time.
It is striking, however, that in many cases, the complexity of typechecking does not decrease significantly by fixing the input and/or output schema, and most cases remain intractable. We have to leave the precise complexity (that is, the ptime-hardness) of T C i [T nd,uc , DTD(SL)] as an open problem.

Appendix: Definitions and Basic Results
The purpose of this Appendix is to prove some lemmas that we use in the body of the paper. We first introduce some notations and definitions needed for the propositions and proofs further on in this Appendix. We also survey some complexity bounds on decisions problems concerning automata that are used throughout the paper.
We show that the complexities of the classical decision problems of string and tree automata are preserved when the automata operate over fixed alphabets. We will consider the following decision problems for string automata: Emptiness: Given an automaton A, is L(A) = ∅?
The corresponding decision problems for tree automata are defined analogously. We associate to each label a ∈ Σ a unique binary string enc(a) ∈ {0, 1} * of length ⌈log |Σ|⌉. For a string s = a 1 · · · a n , enc(s) = enc(a 1 ) · · · enc(a n ). This encoding can be extended to string languages in the obvious way.
We show how to extend the encoding "enc" to trees over alphabet {0, 1, 0 ′ , 1 ′ }. Here, 0 and 1 are internal labels, while 0 ′ and 1 ′ are leaf labels. Let enc(a) = b 1 · · · b k for a ∈ Σ. Then we denote by tree-enc(a) the unary tree b 1 (b 2 (· · · (b k )), if a is an internal label, and the unary tree b 1 (b 2 (· · · (b ′ k )), otherwise. Then, the enc-fuction can be extended to trees as follows: for t = a(t 1 · · · t n ), enc(t) = tree-enc(a)(enc(t 1 ) · · · enc(t n )). Note that we abuse notation here. The hedge enc(t 1 ) · · · enc(t n ) is intended to be the child of the leaf in tree-enc(a). The encoding can be extended to tree languages in the obvious way.
To define the transition function, we introduce some notation. For each a ∈ Σ and i, j It is straightforward to show that Proposition .1 also holds for NFAs and DFAs (the proofs are analogous). It is immediate from Proposition .1, that lower bounds of decision problems for automata over arbitrary alphabets [16,29,31] carry over to automata working over fixed alphabets. Hence, we obtain the following corollary to Proposition .1: Corollary .2. Over the alphabet {0, 1}, the following statements hold: 1. Intersection emptiness of an arbitrary number of DFAs is pspace-hard.
Lemma .3 now immediately follows from nlogspace-hardness of the reachability problem on graphs with out-degree 2 [15].
We now aim at proving Proposition .6, which states that we can find integer solutions to arbitrary Boolean combinations of linear (in)equalities in polynomial time, when the number of variables is fixed. To this end, we revisit a lemma that is due to Ferrante and Rackoff [13].
First, we need some definitions. We define logical formulas with variables x 1 , x 2 , . . . and linear equations with factors in Q. A term is an expression of the form a 1 /b 1 , a 1 /b 1 x 1 + · · · + a n /b n x n , or a 1 /b 1 x 1 + · · · + a n−1 /b n−1 x n−1 + a n /b n where a i , b i ∈ N for i = 1, . . . , n. An atomic formula is either the string "true", the string "false", or a formula of the form ϑ 1 = ϑ 2 , ϑ 1 < ϑ 2 , or ϑ 1 > ϑ 2 . A formula is built up from atomic formulas using conjunction, disjunction, negation, and the symbol ∃ in the usual manner. Formulas are interpreted in the obvious manner over Q. For instance, the formula ¬∃x 1 , x 2 (x 1 < x 2 ) ∧ ¬ ∃x 3 (x 1 < x 3 ∧ x 3 < x 2 ) states that for every two different rational numbers, there exists a third rational number that lies strictly between them.
The size of a formula Φ is the sum of the number of brackets, Boolean connectives, the sizes of the variables, and the sizes of all rational constants occurring in Φ. Here, we assume that all rational constants are written as a/b, where a and b are integers, written in binary notation. We assume that variables are written as x i , where i is written in binary notation.
Step 1: Solve for x n in each atomic formula of Φ. That is, obtain a quantifierfree formula, Ψ n (x 1 , . . . , x n ), such that every atomic formula of Ψ n either does not involve x n or is of the form (i) x n < ϑ, (ii) x n > ϑ, or (iii) x n = ϑ, where ϑ is a term not involving x n .
The intuition is that, for any rational numbers r 1 , . . . , r n−1 , if r is a sufficiently small rational number, then Ψ n (r 1 , . . . , r n−1 , r) and Ψ n −∞ (r 1 , . . . , r n−1 ) are equivalent. A similar statement can be made for Ψ n ∞ for r sufficiently large.
The following proposition is implicit in the work by Ferrante and Rackoff [13], we prove it for completeness: Proposition .5. Let Φ(x 1 , . . . , x n ) be a quantifier-free formula. If n is fixed, then satisfiability of Φ over Q can be decided in ptime. Moreover, if Φ is satisfiable, we can find (v 1 , . . . , v n ) ∈ Q n such that Φ(v 1 , . . . , v n ) is true in polynomial time.
Proof. We first show that satisfiability can be decided in ptime. To this end, we simply iterate over the three steps in the proof of Lemma .4 until we obtain a formula without variables. Hence, in each iteration, one variable x i is eliminated from Φ. For every i = 1, . . . , n, let Φ i be the formula obtained after eliminating variable x i .
Notice that, in each iteration of the algorithm, the number of atomic formulas grows quadratically when going from Φ i to Φ i−1 . However, as there are only a constant number of iterations, the number of atomic formulas in the resulting formula Φ 1 is still polynomial. Moreover, Ferrante and Rackoff show that the absolute value of every integer constant occurring in any rational constant in Φ i is at most (s 0 ) 14 n , where s 0 is the largest absolute value of any integer constant occurring in any rational constant in Φ (cfr. page 73 in [13]). As n is a fixed number, we can decide whether Φ 1 is satisfiable in polynomial time.
Suppose that Φ is satisfiable. We now show how we can construct (v 1 , . . . , v n ) ∈ Q n in polynomial time such that Φ(v 1 , . . . , v n ) is true. For a term ϑ using variables x 1 , . . . , x i , we denote by ϑ(v 1 , . . . , v i−1 ) the rational number obtained by replacing the variables x 1 , . . . , x i in ϑ by v 1 , . . . , v i−1 and evaluating the resulting expression.
For every i = 1, . . . , n, we construct v i from Ψ i , Ψ i −∞ , Ψ i ∞ , and Ψ i,ϑ,ϑ ′ (which are defined in the proof of Lemma .4) as follows: It remains to show that we can represent every v i in a polynomial manner. In the proof of Lemma 2 in [13], Ferrante and Rackoff show that, if w i is the maximum absolute value of any integer occurring in the definition of v 1 , . . . , v i , then we have the recurrence for a constant c and s 0 defined as before. Let c ′ = 2 cn . Hence, the maximum number of bits needed to represent the largest integer in v i+1 is log (s 0 ) c ′ · (w i ) i = c ′ log(s 0 ) · i log(w i ), which is polynomially larger than log(w i ), the number of bits needed to represent the largest integer in v i .
As we only have a constant number of iterations, the number of bits needed to represent the largest integer occurring in the definition of v n is also polynomial.
The following proposition is a generalization of a well-known theorem by Lenstra which states that there exists a polynomial time algorithm to find an integer solution for a conjunction of linear (in)equalities with rational factors and a fixed number of variables [18].

Proposition .6. There exists a ptime algorithm that decides whether a Boolean combination of linear (in)equalities with rational factors and a fixed number of variables has an integer solution.
Proof. Note that we cannot simply put the Boolean combination into disjunctive normal form, as this would lead to an exponential increase of its size.
Let Φ(x 1 , . . . , x n ) be a Boolean combination of formulas ϕ 1 , . . . , ϕ m with variables x 1 , . . . , x n that range over Z. Here, n is a constant integer greater than zero. Without loss of generality, we can assume that every ϕ i is of the form We describe a ptime procedure for finding a solution for x 1 , . . . , x n , that is, for finding values v 1 , . . . , v n ∈ Z such that Φ(v 1 , . . . , v n ) evaluates to true.
First, we introduce some notation and terminology. For every i = 1, . . . , m, we denote by ϕ ′ i the formula k i,1 × x 1 + · · · + k i,n × x n + k i = 0. In the following, we freely identify ϕ ′ i with the hyperplane it defines in R n . For an n-tuple y = (y 1 , . . . , y n ) ∈ Q n , we denote by ϕ ′ i (y) the rational number k i,1 × y 1 + · · · + k i,n × y n + k i .
Given a set of hyperplanes H in R n , we say that C ⊆ R n is a cell of H when (i) for every hyperplane ϕ ′ i in H, and for every pair of points y, z ∈ C, we have that ϕ ′ i (y) θ 0 if and only if ϕ ′ i (z) θ 0, where, θ denotes "<", ">", or "="; and (ii) there exists no C ′ C with property (i).
Let H be the set of hyperplanes {ϕ ′ i | 1 ≤ i ≤ m}. We now describe the ptime algorithm. The algorithm iterates over the following steps: . . , v ′ n ) exists, the algorithm rejects.
5 Note that we abuse notation here, as the variables in Φ range over Z and not Q. and go back to step (1).
We show that the algorithm is correct. Clearly, if the algorithm accepts, Φ has a solution. Conversely, suppose that Φ has a solution. Hence, the algorithm computes a value (v ′ 1 , . . . , v ′ n ) ∈ Q n in step (1) of its first iteration. It follows from the following two observations that the algorithm accepts: (i) If the algorithm computes (v ′ 1 , . . . , v ′ n ) ∈ Q n in step (1), and the cell C of H containing (v ′ 1 , . . . , v ′ n ) also contains a point in Z n , then step (3) finds a solution (v 1 , . . . , v n ) ∈ Z n ; and, (ii) If the algorithm computes (v ′ 1 , . . . , v ′ n ) ∈ Q n in step (1), and the cell C of H containing (v ′ 1 , . . . , v ′ n ) does not contain a point in Z n , then step (3) does not find a solution. By construction of Φ ′′ in step (5), the solutions to the formula Φ ′′ are the solutions of Φ, minus the points in C. As C did not contain a solution, we have that Φ has a solution if and only if Φ ′′ has a solution. Moreover, there exists no (v ′′ 1 , . . . , v ′′ n ) ∈ C such that Φ ′′ (v ′′ 1 , . . . , v ′′ n ) evaluates to true. To show that the algorithm can be implemented to run in polynomial time, we first argue that there are at most a polynomial number of iterations. This follows from the observation in step (2) that the points satisfying Φ ′ (x 1 , . . . , x n ) are precisely all the points in a cell C of H. Indeed, when we do not find a solution to the problem in step (3), we adapt Φ to exclude all the points in cell C in step (5). Hence, in the following iteration, step (1) cannot find a solution in cell C anymore. It follows that the number of iterations is bounded by the number of cells in H, which is Θ(m n ) (see, e.g. [7], or Theorem 1.3 in [11] for a more recent reference).
Finally, we argue that every step of the algorithm can be computed in ptime.
Step (1) can be solved by the quantifier elimination method of Ferrante and Rackoff (Lemma .4). Proposition .5 states that we can find (v ′ 1 , . . . , v ′ n ) in polynomial time.
Step (2) is easily to be seen to be in ptime: we only have to evaluate every ϕ ′ i once on (v ′ 1 , . . . , v ′ n ).
Step (3) can be executed in ptime by Lenstra's algorithm for integer linear programming with a fixed number of variables [18].
Step (5) replaces Φ(x 1 , . . . , x n ) by the formula Φ(x 1 , . . . , x n )∧¬Φ ′ (x 1 , . . . , x n ). As the size of Φ ′ (x 1 , . . . , x n ) is bounded by n plus the sum of the sizes of ϕ ′′ i for i = 1, . . . , n, the formula Φ only grows by a linear term in each iteration. As the number of iterations is bounded by a polynomial, the maximum size of Φ is also bounded by a polynomial.
It follows that the algoritm is correct, and can be implemented to run in polynomial time.
Corollary .7. There exists a ptime algorithm that decides whether a Boolean combination of linear (in)equalities with rational factors and a fixed number of variables has a solution of positive integers.
In the following proposition, we treat the emptiness problem for DTDs: given a DTD d, is L(d) = ∅? Note that L(d) can be empty even when d is not. For instance, the trivial grammar a → a generates no finite trees.
Proof. (1) The upper bound follows from a reduction to the emptiness problem for NTA(NFA)s, which is in ptime (cf. Theorem 19(1) in [23]) For the lower bound, we reduce from path systems [10], which is known to be ptime-complete. path systems is the decision problem defined as follows: given a finite set of propositions P , a set A ⊆ P of axioms, a set R ⊆ P × P × P of inference rules and some p ∈ P , is p provable from A using R? Here, (i) every proposition in A is provable from A using R and, (ii) if (p 1 , p 2 , p 3 ) ∈ R and if p 1 and p 2 are provable from A using R, then p 3 is also provable from A using R.
In our reduction, we construct a DTD (d, p) such that (d, p) is not empty if and only if p is provable. Concretely, for every (a, b, c) ∈ R, we add the string ab to d(c); for every a ∈ A, d(a) = {ε}. Clearly, (d, p) satisfies the requirements.
(2) We provide an np algorithm to check whether a DTD(SL) (d, r) defines a non-empty language. Intuitively, the algorithm computes the set S = {a ∈ Σ | L((d, a)) = ∅} in an iterative manner and accepts when r ∈ S.
Let k be the largest integer occurring in any SL-formula in d. Initially, S is empty.
The iterative step is as follows. Guess a sequence of different symbols b 1 , . . . , b m in S. Then guess a vector (v 1 , . . . , v m ) ∈ {0, . . . , k + 1} m , where k is the largest integer occurring in any SL-formula in d. Intuitively, the vector (v 1 , . . . , v m ) represents the string b v1 1 · · · b vm m . From Lemma 4.2 it follows that any SL-formula in d is satisfiable if and only if it is satisfiable by a string of the form a u1 1 · · · a un n , where Σ = {a 1 , . . . , a n }, and for all i = 1, . . . , n, u i ∈ {0, . . . , k + 1}. Now add to S each a ∈ Σ for which b v1 1 · · · b vm m |= d(a). Note that this condition can be checked in ptime. Repeat the iterative step at most |Σ| times and accept when r ∈ S.
The conp-lowerbound follows from an easy reduction of non-satisfiability. Let φ be a propositional formula with variables x 1 , . . . , x n . Let Σ be the set {a 1 , . . . , a n }. Let (d, r) be the DTD where d(r) = φ ′ , where φ ′ is the formula φ in which every x i is replaced by a =1 i . Hence, (d, r) defines the empty tree language if and only if φ is unsatisfiable.
Reducing a grammar is the act of finding an equivalent reduced grammar.
Corollary .9. Reducing a DTD(NFA) is ptime-complete; and reducing a DTD(SL) is np-complete.
Proof. We first show the upper bounds. Let (d, s) be a DTD(NFA) or DTD(SL) over alphabet Σ. In both cases, the algorithm performs the following steps for each a ∈ Σ: (i) Test whether a is reachable from s. That is, test whether there is a sequence of Σ-symbols a 1 , . . . , a n such that • a = s and a n = a; and • for every i = 2, . . . , n, there exists a string w 1 a i w 2 ∈ d(a i−1 ), for w 1 , w 2 ∈ Σ * .
Symbols that do not pass test (i) and (ii) are deleted from the alphabet of the DTD. Let c be such a deleted symbol. In the case of SL, every atom c ≥i and c =i is replaced by true when i = 0 and false otherwise. Further, in the case of NFAs, every transition mentioning c is removed.
In the case of a DTD(NFA), step (i) is in nlogspace and step (ii) is in ptime. In the case of a DTD(SL), both tests (i) and (ii) are in np.
For the lower bound, we argue that (1) if there exists an nlogspace-algorithm for reducing a DTD(NFA), then emptiness of a DTD(NFA) is in nlogspace; and, (2) if there exists a ptime-algorithm for reducing a DTD(SL), then emptiness of a DTD(SL) is in ptime.
Statements (1) and (2) are easy to show: one only has to observe that an emptiness test of a DTD can be obtained by reducing the DTD and verifying whether the alphabet of the DTD still contains the start symbol.