Linear Bounded Composition of Tree-Walking Tree Transducers: Linear Size Increase and Complexity
Joost Engelfriet, Kazuhiro Inaba, Sebastian Maneth

TL;DR
This paper proves that compositions of tree-walking tree transducers can be realized with linear size intermediate results, impacting their expressiveness and computational complexity.
Contribution
It introduces the concept of linear bounded composition for tree-walking transducers and analyzes the complexity and expressiveness of their compositions.
Findings
Compositions can be realized with intermediate results of linear size.
Linear size increase functions can be realized by a single deterministic transducer.
Deterministic compositions are computable in linear time and space; nondeterministic ones in polynomial time and linear space.
Abstract
Compositions of tree-walking tree transducers form a hierarchy with respect to the number of transducers in the composition. As main technical result it is proved that any such composition can be realized as a linear bounded composition, which means that the sizes of the intermediate results can be chosen to be at most linear in the size of the output tree. This has consequences for the expressiveness and complexity of the translations in the hierarchy. First, if the computed translation is a function of linear size increase, i.e., the size of the output tree is at most linear in the size of the input tree, then it can be realized by just one, deterministic, tree-walking tree transducer. For compositions of deterministic transducers it is decidable whether or not the translation is of linear size increase. Second, every composition of deterministic transducers can be computed in…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Linear-Bounded Composition of
Tree-Walking Tree Transducers:
Linear Size Increase and Complexity111Published at https://link.springer.com/article/10.1007/s00236-019-00360-8
Joost Engelfriet LIACS, Leiden University, P.O. Box 9512, 2300 RA Leiden, the Netherlands; email: [email protected]
Kazuhiro Inaba Google Japan G.K., Tokyo, Japan; email: [email protected]
Sebastian Maneth Department of Mathematics and Informatics, Universität Bremen, P.O. Box 330 440, 28334 Bremen, Germany; email: [email protected]
Abstract
Compositions of tree-walking tree transducers form a hierarchy with respect to the number of transducers in the composition. As main technical result it is proved that any such composition can be realized as a linear-bounded composition, which means that the sizes of the intermediate results can be chosen to be at most linear in the size of the output tree. This has consequences for the expressiveness and complexity of the translations in the hierarchy. First, if the computed translation is a function of linear size increase, i.e., the size of the output tree is at most linear in the size of the input tree, then it can be realized by just one, deterministic, tree-walking tree transducer. For compositions of deterministic transducers it is decidable whether or not the translation is of linear size increase. Second, every composition of deterministic transducers can be computed in deterministic linear time on a RAM and in deterministic linear space on a Turing machine, measured in the sum of the sizes of the input and output tree. Similarly, every composition of nondeterministic transducers can be computed in simultaneous polynomial time and linear space on a nondeterministic Turing machine. Their output tree languages are deterministic context-sensitive, i.e., can be recognized in deterministic linear space on a Turing machine. The membership problem for compositions of nondeterministic translations is nondeterministic polynomial time and deterministic linear space. All the above results also hold for compositions of macro tree transducers. The membership problem for the composition of a nondeterministic and a deterministic tree-walking tree translation (for a nondeterministic IO macro tree translation) is log-space reducible to a context-free language, whereas the membership problem for the composition of a deterministic and a nondeterministic tree-walking tree translation (for a nondeterministic OI macro tree translation) is possibly NP-complete.
Contents
1 Introduction
Tree transducers are used, e.g., in compiler theory or, more generally, the theory of syntax-directed semantics of context-free languages [39], and in the theory of XML queries and XML document transformation [69, 47]. One of the most basic types of tree transducer is the top-down tree transducer (in short tt↓). It is a finite-state device that walks top-down on the input tree, from parent to child, possibly branching into parallel copies of itself at each step (thus allowing the transducer to visit all children of the parent). During this process, the output tree is generated top-down. The tt↓ has been generalized in two different ways. By allowing it to walk also bottom-up, from child to parent, still possibly branching at every step and still generating the output tree top-down, one obtains the tree-walking tree transducer (in short, tt).222The name “tree-walking tree transducer” was introduced in [26]. The adjective “tree-walking” stands for the fact that the transducer walks on the input tree (just as the tree-walking automaton of [2]). The tt is the generalization to trees of the two-way finite-state string transducer, which walks on its input string in both directions and produces the output string one-way from left to right. Note that “tree-walking” and “two-way” alliterate.
On the other hand, restricting its walk to be top-down but allowing its states to have parameters of type output tree, one obtains the macro tree transducer (in short, mt). In general we consider nondeterministic transducers, with deterministic transducers as an important special case (abbreviated as dtt↓, dtt, and dmt).
To turn the tt↓ into a more flexible model of tree transformation, it was enhanced with the feature of regular look-ahead, which means that it can test whether or not the subtree at the current node of the input tree belongs to a given regular tree language. The mt already has the ability to implement regular look-ahead. Since both the enhanced tt↓ and the mt process the input tree top-down, they can also implement “regular look-around”, which means that they can test arbitrary regular properties of the current node of the input tree. More precisely, they can test whether the input tree, in which the current node is marked, belongs to a given regular tree language. Such regular look-around tests are also called mso tests, because they can be expressed by formulas of monadic second-order logic with one free node variable. The tt, as defined in [63], does not have regular look-ahead or look-around. One of the drawbacks of this is that the tt cannot recognize all regular tree languages without branching [9]. Hence, from now on, we assume that the tt (and the tt↓) is enhanced with regular look-around, i.e., with regular tests of the current input node. The resulting tt formalism is a quite robust, flexible, and intuitive model of tree transformation.
The tt and mt, generalizations of the tt↓, are closely related, in particular in the deterministic case. In fact, every dtt can be simulated by a dmt, whereas every dmt can be simulated by a composition of two dtt’s. Thus, every composition of dtt’s can be realized by a composition of dmt’s, and vice versa. Compositions of dtt’s form a proper hierarchy, in an obvious way. A single dtt is at most of exponential size increase, which means that the size of the output tree is at most exponential in the size of the input tree. However, a composition of two dtt’s can be of double exponential size increase. In general, compositions of dtt’s are at most, and can be, of -fold exponential size increase. Compositions of dmt’s form a proper hierarchy by a similar argument. For nondeterministic tt’s and mt’s the situation is similar but more complicated. Every mt can be simulated by a composition of two tt’s. However, as opposed to tt’s, mt’s are always finitary, which means that for every given input tree an mt computes finitely many output trees.
In this paper we investigate compositions of tt’s (and hence of mt’s) with respect to their expressivity and their complexity. Our main technical result is that every composition of tt’s can be realized by a linear-bounded composition of tt’s, which means that, when computing an output tree from an input tree, the intermediate results can be chosen in such a way that their sizes are at most linear in the size of the output tree. More precisely, a composition of two transducers (for simplicity) is linear-bounded if there is a constant such that for every pair of an input tree and output tree in the composed translation there is an intermediate tree (meaning that and are in the first and second translation, respectively) such that the size of is at most times the size of . Intuitively, to compute from there is no need to consider intermediate results that are much larger than . If both transducers are deterministic it means that for every input tree in the domain of the composed translation the size of the unique intermediate tree is at most linear in the size of the unique output tree .
To prove that every composition of two tt’s can be realized by a linear-bounded composition of two tt’s, we first show that every tt can be decomposed into a tt↓ that “prunes” the input tree, followed by a tt that is “productive” on at least one of the intermediate trees generated by the tt↓, which means that it uses each leaf and each monadic node of that intermediate tree in order to generate the output tree. Productivity guarantees that the composition of these two transducers is linear-bounded. We also prove that the composition of an arbitrary tt with a “pruning” top-down tt can be realized by one tt. Thus, when two tt’s are composed, the second tt can split off the pruning tt↓ (to the left), which can be absorbed (to the right) by the first tt. The composition of the resulting two tt’s is then linear-bounded. This also holds for deterministic transducers, in which case the pruning tt is also deterministic. Similar results were presented for macro tree transducers in [58, Section 3] and [51, Section 4].
Thus, roughly speaking, our main technical result provides a method to implement compositions of tt’s in such a way that the generation of superfluous nodes, i.e., nodes on which a tt just walks around without producing any output, is avoided by pruning those superfluous parts from the intermediate trees. As such it can be viewed as a static garbage collection procedure, and leads, in principle, to algorithms for automatic compiler and XML query optimization. Since tt’s are essentially finite-state automata walking on trees, it is not really surprising that only a linearly bounded amount of intermediate information is useful to the final output. However, proving this rigorously requires quite some effort. In particular, the subcomputations of the tt during which it does not produce output will be determined by regular look-around.
The above method can be used to obtain results on both the expressivity and the complexity of compositions of tt’s, as discussed in the next paragraphs.
Expressivity. We have seen above that compositions of tt’s can be of -fold exponential size increase. However, many real world tree transformations are of linear size increase. We prove that the hierarchy of compositions of deterministic tt’s collapses when restricted to translations of linear size increase: every composition of dtt’s that is of linear size increase can be realized by just one dtt. We also show that it is decidable whether or not a composition of dtt’s is of linear size increase. This means that a compiler or XML query, no matter how inefficiently programmed in several phases, can be realized in one efficient phase, provided it is of linear size increase. In fact, as we will see below, that single phase can be executed in linear time. More theoretically, we additionally prove that a function that can be realized by a composition of nondeterministic tt’s, can also be realized by a composition of deterministic tt’s, and hence by one deterministic tt if that function is of linear size increase. Thus, the only (functional) tree transformations that can be realized by a composition of tt’s but not by a single tt, are tree transformations of superlinear size increase.
The proof of the collapse of the hierarchy of compositions of dtt’s is based on the known fact that every dtt of linear size increase can be realized by a dtt that is “single-use”, which means that it never visits a node of the input tree twice in the same state. In fact, it is proved in [29, 32] that even dmt’s of linear size increase can be realized by single-use dtt’s. Vice versa, it is obvious that every single-use dtt is of linear size increase. In [7] it is shown that single-use dtt’s have the same power as deterministic mso tree transducers, which use formulas of monadic second-order logic to define the output tree in terms of the input tree (see [13, 14]).
By our main technical result, we may always assume that a composition of two dtt’s is linear-bounded. If the composition is of linear size increase, then the first dtt is obviously also of linear size increase, and can therefore be realized by a single-use dtt. We also prove that the composition of a single-use dtt with an arbitrary dtt can be realized by one dtt. Thus, altogether, if the composition of two dtt’s is of linear size increase, then it can be realized by a single-use dtt. This argument can easily be turned into an inductive proof for a composition of any number of dtt’s.
Complexity. We first consider deterministic tt’s. The translation realized by a deterministic tt can be computed on a RAM in linear time, in the sum of the sizes of the input and output tree. With respect to space, we prove that it can be computed on a deterministic Turing machine in linear space (again, in the sum of the sizes of the input and output tree). Since we may assume by our main technical result that the sizes of the intermediate results are at most linear in the size of the output tree, it should be clear that these facts also hold for compositions of dtt’s. We also consider output tree languages, i.e., the images of a regular tree language under a composition of dtt’s. Since the regular tree languages are closed under prunings, our technical decomposition result now implies that these output languages are in , i.e., can be recognized by a Turing machine in deterministic linear space (or, in other words, are deterministic context-sensitive). Since the yield of a tree can be computed by a dtt (representing it by a monadic tree), the output string languages, which are the yields of the output tree languages, are also in . The languages in the well-known io-hierarchy are examples of such output languages. For compositions of top-down tree transducers (even nondeterministic ones) this result on output languages was proved in [4], using a technical result very similar to ours.
Our results on nondeterministic tt’s (and their proofs) are very similar to those for dtt’s. The translation realized by a composition of tt’s can be computed by a nondeterministic Turing machine in simultaneous polynomial time and linear space (in the sum of the sizes of the input and output tree). The corresponding output languages can be recognized by such a Turing machine and hence are in NPTIME. Using the results on the membership problem for compositions of tt’s discussed in the next paragraph, we generalize the result of [4] and prove that these output languages are even in , which means that they are deterministic context-sensitive. The languages in the well-known oi-hierarchy are examples of such output languages.
Finally, we consider the membership problem for compositions of tt’s, which asks whether or not a given pair of input tree and output tree belongs to the composed translation. It follows easily from the above complexity results that for (non)deterministic tt’s the problem is decidable in (non)deterministic polynomial time and in (non)deterministic linear space. For the special case of the composition of a nondeterministic tt with a deterministic tt we prove that the problem is even in LOGCFL, i.e., log-space reducible to a context-free language, and hence in PTIME and . From this we conclude that for nondeterministic tt’s the problem is even decidable in deterministic linear space. However, for the special case of the composition of a deterministic tt with a nondeterministic one, the problem can be NP-complete. From the two special cases we obtain that the membership problem for a (single) nondeterministic macro tree transducer is in LOGCFL for io macro tree transducers (strengthening the result in [52] where it was shown to be in PTIME), whereas it can be NP-complete for oi macro tree transducers.
Structure of the paper. The reader is assumed to be familiar with the basics of formal language theory, in particular tree language theory, and complexity theory. The only formalisms used are tree-walking tree transducers (tt’s, of course), top-down tree transducers (tt↓’s, as a special case of tt’s), context-free grammars, regular tree grammars, and finite-state tree automata. Results on macro tree transducers are taken from the literature.
The main results are proved in Sections 8 to 12. Section 2 contains a number of preliminary notions, in particular linear-bounded composition, linear size increase, and regular look-around. In Section 3 we define the tree-walking tree transducer (with regular look-around), together with some of its special cases such as top-down and single-use. A tt that does not use regular look-around tests is called “local”. A “pruning” tt is a tt↓ that, roughly speaking, removes or relabels each node of the input tree and possibly deletes several of its children (together with their descendants). After giving two examples we present the composition hierarchy of dtt’s and end the section with some elementary syntactic properties of tt’s. In Section 4 it is shown how to separate the regular look-around from a tt and incorporate it into another tt. For instance, every tt can be decomposed into a deterministic pruning tt↓ that just relabels the nodes of the input tree (and hence does not really “prune”), followed by a local tt. We also state the fact that the domain of a tt is a regular tree language. Consequently, it is possible to define the regular tests of a tt as domains of other tt’s, which is a convenient technical tool. Section 5 contains three composition results. We prove that the composition of a tt with a pruning tt↓ can be realized by a tt (such that determinism is preserved). Together with the above-mentioned decomposition, this implies for instance that in a composition of two tt’s, the second tt can always be assumed to be local: the second tt splits off a pruning tt↓ that is absorbed by the first tt. In the deterministic case, we even prove that the composition of a dtt with an arbitrary dtt↓ can be realized by a dtt, and we also prove that the composition of a single-use dtt with a dtt can be realized by a dtt. Section 6 presents the known fact that every dtt of linear size increase can be realized by a single-use dtt, and discusses the relationship between tt’s, macro tree transducers, and mso tree transducers. In Section 7 we show that a (partial) function that can be realized by a composition of nondeterministic tt’s, can also be realized by a composition of deterministic tt’s. To prove this we first prove a lemma: for every tt↓ there is a deterministic tt↓ that realizes a “uniformizer” of the translation realized by the given tt↓, i.e., a function that is a subset of that translation, with the same domain. Section 8 contains our main technical result: every tt can be decomposed into a pruning tt and another tt such that the composition is linear-bounded. It implies (by splitting and absorbing) that a composition of tt’s can always be assumed to be linear-bounded. The “uniformizer” lemma of the previous section is applied to the pruning tt↓, proving the same result for deterministic tt’s. Section 9 presents the main results on linear size increase, and Sections 10 and 11 present the main results on the complexity of compositions of deterministic and nondeterministic tt’s, respectively. In Section 12 we prove the main results on the complexity of the membership problem for the composition of two tt’s. Finally, in Section 13 we show (in a straightforward way) that all main results also hold for transducers that transform unranked trees, or forests, which are a natural model of XML documents.
The reader who is interested only in complexity can disregard all results on single-use tt’s, and skip Sections 6.2 and 9. The reader who is interested only in expressivity can just skip Sections 10, 11, and 12.
Remarks on the literature. Top-down tree transducers were introduced in [66, 72]; regular look-ahead was added in [20]. Macro tree transducers were introduced in [15, 34]. Tree-walking tree transducers were introduced in [63] (where they are called 0-pebble tree transducers), and studied in, e.g., [31, 26, 62]. They were already mentioned in [24, Section 3(7)] (where they are called RT(Tree-walk) transducers). Regular look-around was added to tt’s in [14, Section 8.2] (where they are called ms tree-walking transducers); for tree-walking automata that was already done in [6]. However, formal models similar to the tt were introduced and studied before. The tree-walking automaton of [2] translates trees into strings. As explained in [24, Section 3(7)] and [31, Section 3.2], the tt is closely related to the attribute grammar [53], which is a well-known model of syntax-directed semantics (and a compiler construction tool). An attribute grammar translates derivation trees of an underlying context-free grammar into arbitrary values. Tree-valued attribute grammars were considered, e.g., in [27]. The attributed tree transducer, introduced in [38], is an operational version of the tree-valued attribute grammar, without underlying context-free grammar. Regular look-around was added to the attributed tree transducer in [7] (where it is called look-ahead). Attributed tree transducers are a special type of tt’s, of which the states are viewed as attributes of the nodes of the input tree. By definition a deterministic attributed tree transducer (like an attribute grammar) has to be noncircular, which means that it should generate an output tree whenever it is started in any state on any node of an input tree. Thus, it is total in a strong sense. This is natural from the point of view of syntax-directed semantics, but quite restrictive and inconvenient from the operational point of view of tree transformation. Several of the auxiliary results in Sections 3 to 5 are closely related to (and generalizations of) well-known results on attributed tree transducers (see, e.g., [39]). As an example, it is proved in [38, Theorem 4.3] that, for deterministic transducers, the composition of an attributed tree transducer with a top-down tree transducer can be realized by an attributed tree transducer. That does not immediately imply that the same is true for a dtt and a dtt↓, which we show in Section 5, because dtt’s are not necessarily total and they have regular look-around. Moreover, we wanted such results also to be understandable for readers unfamiliar with attribute grammars and attributed tree transducers.
The main results of this paper were first presented at FSTTCS ’02 [58] (on the complexity of compositions of deterministic mt’s), at FSTTCS ’03 [59] (on compositions of mt’s that realize functions of linear size increase), at FSTTCS ’08 [51] (on the complexity of compositions of nondeterministic mt’s), at PLAN-X ’09 [52] (on the complexity of the membership problem for mt’s), and in the Ph.D. Thesis of the second author [48] (on the last two subjects).
2 Preliminaries
Convention: All results stated and/or proved in this paper are effective.
Sets, strings, and relations. The set of natural numbers is . For , we denote the interval by . The cardinality or size of a set is denoted by . The set of strings over is denoted by . It consists of all sequences with and for every . The length of is denoted by . The empty string (of length [math]) is denoted by . The concatenation of two strings and is denoted by or just . Moreover, and for .
The domain and range of a binary relation are denoted by and , respectively. For , . The composition of with a binary relation is . The inverse of is . Note that and . If then the transitive-reflexive closure of is where and . The composition of two classes of binary relations and is . Moreover, and for . The relation is finitary if is finite for every , where denotes . It is a (partial) function from to if is empty or a singleton for every , and it is a total function if, moreover, .
Trees. An alphabet is a finite set of symbols. A ranked alphabet is an alphabet together with a mapping (of which the subscript will be dropped when it is clear from the context). The maximal rank of elements of is denoted . For every we denote by the elements of that have rank .
Trees over are recursively defined to be strings over , as follows. For every , if and are trees over , then is a tree over . For readability we also write the tree as the term . The set of all trees over is denoted ; thus . For an arbitrary finite set , disjoint with , we denote by the set , where each element of has rank 0.
As usual trees are viewed as directed labeled graphs. The nodes of a tree are indicated by Dewey notation, i.e., by elements of , which are strings of natural numbers. The root of is indicated by the empty string , but will also be denoted by for readability. The -th child of a node of is indicated by , and there is a directed edge from the parent to the child . Formally, the set of nodes of a tree over can be defined recursively by . Thus, . The root of has label , and the node of has the same label as the node of . The rank of node is the rank of its label, i.e., the number of its children. A leaf is a node of rank 0, and a monadic node is a node of rank 1. Every node of has a child number: each node has child number , and the root is given child number [math] for technical convenience. For a node of the subtree of with root is denoted ; thus, and . A node of is a descendant of a node of , and is an ancestor of , if there exists such that and (thus, is not a descendant/ancestor of itself). The size of a tree is , i.e., its length as a string. Note that because the nodes of correspond one-to-one to the positions in the string , i.e., for every , each occurrence of in corresponds to a node of with label . The left-to-right linear order on according to this correspondence is called the pre-order of the nodes of . The yield of is the string of labels of its leaves, in pre-order. The height of is the number of edges of a longest directed path from the root of to a leaf; thus, it is the maximal length of its nodes (which are strings over ).
A tree language is a set of trees over , for some ranked alphabet , i.e., . A tree translation is a binary relation between trees over and trees over , for some ranked alphabets and , i.e., .
Linear-bounded composition. Let , , and be ranked alphabets. For tree translations and , we say that the pair is linear-bounded if there is a constant such that for every there exists such that , , and . Thus, the intermediate result can be chosen such that its size is linear in the size of the output . Note that if and are functions, this means that for every .
For classes and of tree translations, we define to consist of all translations such that , , and is linear-bounded.
Lemma 1
Let , , and be classes of tree translations. Then
[TABLE]
**Proof. **Let for . If the pair is linear-bounded then so is the pair , with the same constant . If and are linear-bounded with constant and , respectively, then is linear-bounded with constant .
A function is of linear size increase if there is a constant such that for every . The class of functions of linear size increase will be denoted by LSIF.
Lemma 2
Let and be functions such that . If and is linear-bounded, then .
**Proof. **It follows from that . Since is linear-bounded, there is a such that for every . Since , there is a such that for every . Hence for every , which means that .
Grammars and automata. Context-free grammars and, in particular, regular tree grammars will be used to define the computations of tree-walking tree transducers, and to define the “regular look-around” used by these transducers. A context-free grammar is specified as a tuple , where is the nonterminal alphabet, the terminal alphabet (disjoint with ), the set of initial nonterminals, and the finite set of rules, where each rule is of the form with and . A sentential form of is a string such that for some , where is the usual derivation relation of : if is in , then for all . The language generated by is the set of all terminal sentential forms, i.e., . To formally define the derivation trees of as ranked trees, we need to subscript its nonterminals with ranks because can have rules and with . Let be the ranked alphabet consisting of all symbols , of rank , such that has a rule with . The terminal symbols in are given rank 0. Then the derivation trees of are generated by the context-free grammar such that , , and if contains a rule , then contains the rule where and is obtained from by changing every nonterminal into . Note that we only consider derivation trees that correspond to derivations with and . Such a derivation tree has yield , because when taking the yield of a derivation tree we skip the leaves with label . Moreover, when considering a derivation tree of , we will disregard the subscripts of the nonterminals and we will say that a node has label rather than . As an example, if has the rules , , , and , then has the rules , , , and . The string is generated by , and the derivation tree is generated by ; the nodes of this tree are labeled by , , , , and , and its yield is .
A context-free grammar is -free if it does not have -rules, i.e., rules . We will mainly deal with -free context-free grammars.
A context-free grammar is finitary if is finite. We need the following elementary lemma on finitary context-free grammars.
Lemma 3
Let be a finitary context-free grammar. For every string there exists a derivation tree such that the yield of is and the height of is at most .
**Proof. **Let be a derivation tree with yield and suppose that a node of and a descendant of have the same nonterminal label (disregarding the ranking subscripts). Then the tree can be pumped in the usual way. But since is finite, the yield of the pumped tree remains the same. Hence we can remove the pumped part from . Repeating this, we obtain a derivation tree as required.
A context-free grammar is forward deterministic if is a singleton and distinct rules have distinct left-hand sides.333That is as opposed to a “backward deterministic” context-free grammar in which distinct rules have distinct right-hand sides, see, e.g., [26]. A forward deterministic context-free grammar that generates a string is also called a “straight-line” context-free grammar.
Such a grammar generates at most one string in and has at most one derivation tree. If , then the height of is at most by Lemma 3.
A regular tree grammar is a context-free grammar such that is a ranked alphabet, and for every rule in . A regular tree grammar generates trees over , i.e., . Note that every regular tree grammar is -free. Note also that for every context-free grammar , the grammar is a regular tree grammar. If, in particular, is itself a regular tree grammar, as above, then it should be noted that the elements of all have rank 0 in . As an example, if has the rules , , , and , where , , and have ranks 2, 1 and 0, respectively, then has the rules , , , and . The tree is generated by , and the derivation tree by .
A (total deterministic) bottom-up finite-state tree automaton is specified as a tuple where is a ranked alphabet, is a finite set of states, is the set of final states, and is the state transition function such that for every and , where is the rank of . For every , we define the state in which arrives at the root of recursively by . The tree language recognized by is .
A regular tree language is a set of trees that can be generated by a regular tree grammar, or equivalently, recognized by a bottom-up finite-state tree automaton. The class of regular tree languages will be denoted by REGT. The basic properties of regular tree languages can be found in, e.g., [43, 44, 11, 19].
Regular look-around. Let be a ranked alphabet. A node test over is a set of trees over with a distinguished node, i.e., it is a subset of the set
[TABLE]
Intuitively it is a property of a node of a tree.
We introduce a new ranked alphabet , such that the rank of equals that of in . For a tree over and a node of we define to be the tree over that is obtained from by changing the label of into and changing the label of every other node into . Thus, is with one “marked” node . A regular (node) test over is a node test such that its marked representation is a regular tree language, i.e., . Note that and are regular tests, and that the class of regular tests over is closed under the boolean operations complement, intersection, and union, because REGT is closed under those operations. Hence every boolean combination of regular tests is again a regular test.
For a tree language we define the node test
[TABLE]
over . Intuitively it is a property of the distinguished node that only depends on the subtree at that node. Clearly, if is regular then is regular. A regular test of the form with will be called a regular sub-test. Note that and . Note also that for regular tree languages and over , and . This shows that the class of regular sub-tests over is also closed under the boolean operations complement, intersection, and union.
For a given node test over , we also wish to be able to apply to a node of a tree , where need not be equal to . Thus, we define the node test over to consist of all such that and . The test just disregards the marking of . It is easy to see that if is regular, then so is .
The reader familiar with monadic second-order logic (abbreviated mso logic) should realize that it easily follows from the result of Doner, Thatcher and Wright [18, 73] that a node test is regular if and only if it is mso definable (see [6, Lemma 7]). A node test over is mso definable if there is an mso formula over , with one free variable , such that , where means that the formula holds in for the node as value of . The formulas of mso logic on trees over use the atomic formulas and , for every , meaning that node has label , and that is the -th child of , respectively. In the literature, regular tests are also called mso tests.
3 Tree-Walking Tree Transducers
In this section we define tree-walking tree transducers, with and without regular look-around, and discuss some of their properties.
A tree-walking tree transducer (with regular look-around), in short tt, is a finite state device with one reading head that walks from node to node over its input tree following the edges in either direction. In addition to testing the label and child number of the current node, it can even test any regular property of that node. The output tree is produced recursively, in a top-down fashion. When the transducer produces a node of the output tree, labeled by an output symbol of rank , it branches into copies of itself, which then proceed independently, in parallel, to produce the subtrees rooted at the children of that output node.
The tt is specified as a tuple , where and are ranked alphabets of input and output symbols, is a finite set of states, is the set of initial states, and is a finite set of rules. The rules are divided into move rules and output rules. Each move rule is of the form such that , , , is a regular test over (specified in some effective way), and is one of the following instructions:
[TABLE]
Each output rule is of the form such that the left-hand side is as above, , , and are instructions as above. A rule with will be written . The tt is deterministic, in short a dtt, if is a singleton, and for every two distinct rules and in . A dtt with initial state will be specified as .
A configuration of the tt on a tree over is given by the current state of and the current position of the head of on . Formally, and . The set of all configurations of on is denoted , i.e., . A rule is applicable to a configuration of on if and satisfies the tests , , and , i.e., and are the label and child number of , and . For a node of and an instruction we define the node of as follows: if is , , or , then equals , is the parent of , or is the -th child of , respectively.
For every input tree we define the regular tree grammar where , and is defined as follows. Let be a configuration of on and let be a rule of that is applicable to . If then contains the rule , and if then contains the rule . The derivation relation will be written as . The translation realized by , denoted , is defined as . In other words, . Two tt’s and are equivalent if .
The domain of , denoted by , is defined to be the domain of the translation , i.e., . The tt is total if .
The tt is finitary if is finitary, which means that is finite (or equivalently, that is finitary) for every input tree . All classical top-down tree transducers (with or without regular look-ahead) and all macro tree transducers are finitary.
If is deterministic, then at most one rule of is applicable to a given configuration. Hence is forward deterministic and is either empty or a singleton. Thus, is a partial function from to (and a total function if is total). For every the context-free grammar has exactly one derivation tree, with root label and yield .
Intuitively, the derivation relation of the grammar formalizes the computation steps of the tt on the input tree , the derivations of are the sequential computations of on , and the derivation trees of , generated by the regular tree grammar , model the parallel computations of the independent copies of on . If is deterministic and , then has exactly one parallel computation on .
A sentential form of will be called an output form of on . It is a tree such that for some . Intuitively, such an output form consists on the one hand of -labeled nodes that were produced by previously in the computation, using output rules, and on the other hand of leaves that represent the independent copies of into which the computation has branched previously, due to those output rules, where each leaf is labeled by the current configuration of that copy. An output form is initial if it is the configuration for some , where is the root of , and it is final if it is in , which means that all copies of have disappeared.
Intuitively, the computation steps of lead from one output form to another, as follows. Let be an output form and let be a leaf of with label . If is a rule of , resulting from a move rule of that is applicable to configuration , as defined above, then where is obtained from by changing the label of into . Thus, this copy of just changes its configuration. Moreover, if is a rule of , resulting from an output rule of , as defined above, then where is obtained from by changing the label of into and adding children with labels , respectively. Thus, outputs , and for each child it branches into a new process, a copy of itself started in state at the node . In the particular case that , is obtained from by changing the label of into ; thus, the copy of corresponding to the node of disappears. The translation realized by consists of all pairs of trees over and over such that has a sequential computation on that starts with an initial output form and ends with the final output form .
Before giving an example of a tree-walking tree transducer, we define six properties of tt’s that will be used throughout this paper.
The tt is sub-testing, abbreviated tt, if the regular tests used by are regular sub-tests, i.e., only test the subtree at the current node. Formally, for every rule there is a regular tree language over such that . Recall that . Thus, informally, is sub-testing if it uses regular look-ahead rather than the more general regular look-around.
The tt is local, abbreviated ttℓ, if it does not use regular tests, i.e., () for every rule . So all its rules are written . Recall that ; thus, every local tt is sub-testing. Note that in the formalism of the (non-local) tt the tests on and could be dropped from a rule , because they can be incorporated in the regular test .
The tt is top-down, abbreviated tt↓, if it does not use the up-instruction in the right-hand sides of its rules. Due to the use of stay-instructions, a tt↓ need not be finitary. It is straightforward to show that the finitary (deterministic) tt and tt are equivalent to the classical nondeterministic (deterministic) top-down tree transducer, with and without regular look-ahead, respectively; see the end of this section. Note that in the rules of a tt or tt the test on the child number could be dropped, because can be stored in the finite state if necessary.
The tt is single-use, abbreviated ttsu, if it is deterministic and never visits a node of the input tree twice in the same state. Formally, it should satisfy the following property: for every , , , and , if then occurs at most once in . In other words, for every , no nonterminal occurs twice in the (unique) derivation tree of the context-free grammar . Note that, as discussed in the proof of Lemma 3 (and the paragraph following it), the configuration cannot occur at two distinct nodes on a path from the root of to a leaf. The single-use property also forbids to occur at two independent nodes of . It was introduced for attribute grammars in [40, 41, 45].
The tt is pruning, abbreviated ttpru, if it is a top-down tt of which each move rule is of the form , and each output rule is of the form such that . Intuitively, a pruning tt is a tt↓ without stay-instructions that, when arriving at an input node , either removes and all its children except one (together with the descendants of those children), or relabels and possibly removes some of its children (together with their descendants). Since a ttpru does not use the stay-instruction, it is finitary (and single-use if it is deterministic). Every tt and tt is equivalent to a classical linear top-down tree transducer, with and without regular look-ahead, but not vice versa because the latter transducer can generate an arbitrary finite number of output nodes at each computation step, rather than zero or one.
The tt is relabeling, abbreviated ttrel, if every rule of is an output rule of the form where . Thus, the label is replaced by the label . Obviously, every relabeling tt is pruning.
We use the notation TT for the class of translations realized by tree-walking tree transducers, and f TT and dTT for the subclasses realized by finitary and deterministic tt’s, respectively. Thus, . The subclasses of TT, f TT, and dTT realized by tt’s with the above six properties (and their combinations) are indicated by the superscripts ‘s’ and ‘’, and the subscripts ‘’, ‘su’, ‘pru’, and ‘rel’, as above. For instance, dTT denotes the class of translations realized by deterministic tree-walking tree transducers that are both sub-testing and top-down. Note that TTℓ is a proper subclass of TT, because a local tt of which all output symbols have rank 0 can be viewed as a tree-walking automaton, which cannot recognize all regular tree languages by the result of [9].
By [14, Section 8.4], the tt is equivalent to the ms tree-walking transducer of [14, Section 8.2]. As discussed in the Introduction, the ttℓ generalizes the attributed tree transducer of [38], which is required to be noncircular and hence finitary; the deterministic attributed tree transducer is also required to be total.444The tt is circular if there exist , , , and such that and occurs in . Thus, is noncircular if and only if is nonrecursive for every , which implies that is finite. Note that a total deterministic tt is noncircular if and only if for every , , and there exists such that . It can be shown that for every finitary tt there is an equivalent noncircular tt, but that will not be needed in this paper.
In the same way the deterministic tt generalizes the (deterministic) attributed tree transducer with look-ahead of [7]. In [26] all tree-walking tree transducers are local.
Example 4
Let with and , and let with , , and for every . Moreover, let be an arbitrary regular node test over . For simplicity we assume that is not satisfied at the leaves of , i.e., if then is not a leaf of . For instance, consists of all such that has at least one ancestor that has exactly one child that is a leaf, and at least one descendant with that same property. We consider a total deterministic tt that performs as a query, i.e., for every input tree it outputs all nodes of that satisfy , in pre-order. More precisely, if are the nodes of such that , in pre-order, then outputs the tree where if with . Note that the yield of is . The transducer performs a left-to-right depth-first traversal of the input tree and applies the test to every node of , in pre-order. Whenever finds a node that satisfies the test, it branches into two copies. The first copy outputs the tree with yield , walking from to the root, and the second copy continues the traversal.
Formally, has the set of states and initial state . Intuitively, stands for ‘down’, for ‘up from the -th child’, and for ‘print’. It has the following rules, where , , , and :
[TABLE]
where the rule abbreviates the two rules
[TABLE]
The tt does not have any of the six properties defined above. Note that is not single-use because it pays visits to the root of in state . For the example test it is not clear whether there is a local tt equivalent to , but that does not seem likely.
Example 5
Let as in Example 4. We consider a total deterministic local tt that translates each tree with leaves into the full binary tree of height with leaves. As in Example 4, it performs a depth-first left-to-right traversal of , and branches into two copies whenever it visits a leaf of . Formally, with and . Its rules are similar to those of in Example 4. In particular, the three rules for states and are the same. The rules for state are the following, with and :
[TABLE]
where the last rule abbreviates the two rules and .
An elementary property of the translation realized by a deterministic tt is that it is of “linear size-height increase”, as stated in the next lemma. Since the size of a tree is at most exponential in its height, this implies that it is of exponential size increase. This is well known for attributed tree transducers [38, Lemma 4.1] (see also [39, Lemma 5.40]) and for local tt’s [31, Lemma 7], and obviously also holds for tt’s. If, moreover, the tt is single-use, then it is of linear size increase.
Lemma 6
For every there is a constant such that for every the height of is at most . Moreover, \mbox{\sf dTT{}_{\mathrm{su}}}\subseteq\mbox{\sf LSIF}.
**Proof. **Let be a dtt and let . Let be the unique derivation tree generated by . Clearly, since each rule of outputs at most one node of , the height of is at most the height of . By Lemma 3 the height of is at most , which equals . Thus, we can take .
It should also be clear that the size of is at most the number of nodes of that are labeled by a configuration. If is single-use, then no configuration occurs twice in . Hence , i.e., the function is of linear size increase.
Example 5 and Lemma 6 imply that compositions of deterministic tt’s form a proper hierarchy. This was proved for attributed tree transducers in [38, Corollary 4.1] (see also [39, Theorem 5.45]), and the proof for tt’s is exactly the same.
Proposition 7
For every , .
**Proof. **Let be the translation realized by the dtt of Example 5. Then translates each tree with leaves into the full binary tree of height with leaves. Since , it follows from Lemma 6 that is not in dTT. Hence . In a similar way it can be shown that is not in . Since the size of a tree is at most exponential in its height, it follows from Lemma 6 that for every there is a constant such that for every the height of is at most . Similarly for , the height of is at most ()-fold exponential in .
Thus, in terms of size increase, a composition of dtt’s can create at most a -fold exponentially large output tree, whereas a composition of dtt’s can naturally create an output tree of -fold exponential size. In Section 7 we will prove that compositions of nondeterministic tt’s also form a hierarchy, with the same counter-examples. One of our aims is to show that these hierarchies collapse for functions of linear size increase, i.e., that for every .
We end this section by discussing some syntactic properties of tt’s. First, for an arbitrary tt it may always be assumed that its output rules only use the stay-instruction: an output rule can be replaced by the output rule and the move rules for every , where are new states. This replacement preserves determinism and the sub-testing, local, top-down, and single-use properties (but not pruning or relabeling).
Second, we may always assume that the regular tests of a tt are disjoint. For a tt , let be the set of regular tests in the left-hand sides of the rules of .
Lemma 8
For every tt there is an equivalent tt such that the tests in are mutually disjoint. The construction preserves determinism and the sub-testing, local, top-down, single-use, pruning, and relabeling properties.
**Proof. **If and , then every rule can be replaced by the two rules and . The transducer is obtained by repeating this procedure.
Third, we can extend the definition of a tt by allowing “general rules”, which can generate any finite number of output nodes, cf. [31, Lemma 2]. Simple examples of general rules are in Example 4 and in Example 5. Formally, a general rule is of the form such that is a tree in , where is the usual set of instructions: , (provided ), and with . If this rule is applicable to a configuration of on , then has the rule , where is obtained from by changing every label into . It is easy to see that a general rule can be replaced by the set of ordinary rules defined as follows. Let be a new state for every . Then the rules are , where is the root of , and all rules where is the label of in and is its rank. The first rule is a move rule that just changes state, and the latter rules output the -labeled nodes of one by one (), and then make the required moves (). This construction preserves determinism and the sub-testing, local, top-down, and single-use properties. Note that the classical top-down tree transducer has general rules.
If we allow general rules, then the stay-instruction is not needed any more in finitary tt’s. Let us say that a tt is stay-free if it does not use the stay-instruction in its rules. For every tt (with general rules) we can construct an equivalent stay-free tt with general rules, with possibly infinitely many rules but such that the right-hand sides of rules with the same left-hand side form a regular tree language. If is finitary, then we can transform into an equivalent stay-free tt with finitely many rules. The construction is as follows, where we may assume that the node tests in are mutually disjoint, by (the proof of) Lemma 8.
For every left-hand side of a rule of we define a regular tree grammar that simulates the computations of , starting in a configuration to which is applicable, without leaving the current node , i.e., executing stay-instructions only. Its set of nonterminals is with initial nonterminal . Its set of terminals is , where each element of which has rank 0. Finally, if is a rule of (with and the same , , and ), then has the rule .
We now define where consists of all general rules such that , for every left-hand side of a rule of . Even if has infinitely many rules, it should be clear that (with all the definitions as in the finite case) is equivalent to .
Note that if is deterministic, then so is , because is forward deterministic and hence is empty or a singleton. Thus, has finitely many rules.
Assume now that , and hence , is finitary. Let be the left-hand side of a rule of , and let . If has infinitely many rules with , then we remove those rules from . In fact, if would have a computation with in which one of those rules is applied, then it would have a similar computation (with the same and , but, in general, another ) in which any other of those rules is applied. Since contains at least as many occurrences of symbols in as , that would contradict the finitariness of . Removing all these rules, for every , we are left with an equivalent version of with finitely many rules. The construction is effective because is a regular tree language and hence its finiteness can be decided.
The above constructions also preserve the sub-testing, local, top-down, and single-use properties. Note that if is a finitary tt or tt, then is a classical top-down tree transducer (after incorporating the child number in its finite state), with or without regular look-ahead, respectively.
4 Regular Look-Around
In this section we discuss some basic properties of tt’s with respect to the feature of regular look-around. We start with the simple fact that the domain of a tt can always be restricted to a regular tree language, except when the tt is local.
Lemma 9
For every tt and every there is a tt such that . The construction preserves determinism and the sub-testing, top-down, single-use, pruning, and relabeling properties.
**Proof. **The tt simulates , but additionally verifies that the input tree is in , by using the regular sub-test at the root of . Formally, is obtained from by changing every rule into , for every initial state .
In the remainder of this section we show how to separate the regular look-around from a tt, by incorporating it into another tt. We first prove that every tt can be decomposed into a deterministic relabeling tt and a local tt . The relabeling tt preprocesses the input tree by adding to the label of each node of the truth values of the regular tests of at that node. This allows , during its simulation of , to inspect the new label of instead of testing . The idea is similar to that of removing regular look-ahead in [20, Theorem 2.6]. The translation realized by is called an mso relabeling in [7, 14] and [29, Section 4].
Lemma 10
\mbox{\sf TT}\subseteq\mbox{\sf dTT{}_{\mathrm{rel}}}\circ\mbox{\sf TT{}^{\ell}}, i.e., for every tt there are a deterministic relabeling tt and a local tt such that . The construction preserves determinism, the top-down property, and the pruning property.
**Proof. **Let be a tt, and let be the set of regular tests in the left-hand sides of the rules in . By Lemma 8 we may assume that the tests in are mutually disjoint. Now let where is the intersection of the complements of the tests in . Thus, for every and , belongs to a unique node test in . Let be the ranked alphabet such that has the same rank as .
We define the relabeling tt such that for every , , and , the output rule
[TABLE]
is in , where is the rank of . Additionally we define the local tt with the following rules. If is a rule in , then contains the rule . Note that is total and deterministic. Also, if is deterministic, then so is . It should be clear that for every , i.e., .
We will also need a variant of this lemma, for nondeterministic tt’s only.
Lemma 11
\mbox{\sf TT{}^{\hskip 1.13791pt\mathrm{s}}}\subseteq\mbox{\sf TT{}^{\ell}{\mathrm{rel}}}\circ\mbox{\sf TT{}^{\ell}}* and \mbox{\sf TT{}^{\hskip 1.13791pt\mathrm{s}}{\mathrm{pru}}}\subseteq\mbox{\sf TT{}^{\ell}{\mathrm{rel}}}\circ\mbox{\sf TT{}^{\ell}{\mathrm{pru}}}.*
**Proof. **Let be a sub-testing tt, and let be the set of regular tests in the left-hand sides of the rules in . As in the proof of Lemma 10 we may assume that the tests in are mutually disjoint (by Lemma 8), and we define as in that proof. Let where are regular tree languages. Clearly, there is a bottom-up finite-state tree automaton (where is irrelevant) and a partition of such that for every and , if and only if . We define the local relabeling tt such that it nondeterministically simulates top-down. For every of rank , every sequence of states , and every , if , then contains the rule . The local tt is defined as in the proof of Lemma 10.
The next lemma is based on the folklore technique of computing the states of a bottom-up finite-state tree automaton that are “successful” at the current node (see, e.g., the proofs of [7, Theorem 10] and [6, Theorem 8]). The lemma shows that every top-down tt is equivalent to one that is sub-testing, and hence to a classical top-down tree transducer with regular look-ahead if it is finitary. It is a slight generalization of the fact that every mso relabeling can be computed by a top-down tree transducer with regular look-ahead, as shown in [7, Theorem 10] and [31, Theorem 4.4].
Lemma 12
\mbox{\sf TT{}{\downarrow}}=\mbox{\sf TT{}^{\hskip 1.13791pt\mathrm{s}}{\downarrow}}. The construction preserves determinism, pruning, and relabeling.
**Proof. **Let be a tt↓ that uses a regular test over in its rules. For simplicity we first assume that uses in each of its rules. Let be a bottom-up finite-state tree automaton that recognizes . We identify the symbols and ; thus, can also handle trees over . For every tree and every node , we define the set of successful states of at to consist of all states such that recognizes when started at in state . To be precise, and if has label and , then is the set of all states such that , where , i.e., is the state in which arrives at the -th child of , for every . Obviously, is recognized by if and only if .
For every and every sequence of states let be the regular tree language consisting of all trees such that for every . Thus, the regular sub-test verifies that arrives at the -th child of the current node in state for every .
We construct a sub-testing tt↓ that is equivalent to . It keeps track of in its finite state. Its set of states is with set of initial states . The set of rules is defined as follows. Let be a rule in , let , and let such that where . Then contains the rule where is obtained from by changing every into and every into with .
In the general case where uses regular tests , the transducer must keep track of for each of the corresponding bottom-up finite-state tree automata .
The proof of Lemma 12 also shows that in a rule of a sub-testing tt↓ we may assume that is of the form for regular tree languages (where ). This is how regular look-ahead is usually defined for classical top-down tree transducers.
By Lemmas 10 and 12, \mbox{\sf dTT}\subseteq\mbox{\sf dTT{}^{\hskip 1.13791pt\mathrm{s}}{\downarrow}}\circ\mbox{\sf dTT{}^{\ell}}. It is proved in [28, Lemmas 49 and 50] that even \mbox{\sf dTT}\subseteq\mbox{\sf dTT{}^{\ell}{\downarrow}}\circ\mbox{\sf dTT{}^{\ell}}, but this will not be needed in what follows.555In [28], dTT and dTTℓ are denoted by dTT and dTT, respectively.
Using Lemmas 10 and 12 we can now prove three essential properties of tt’s, based on well-known results from the literature.
Lemma 13
The regular tree languages are closed under inverses of tt translations, i.e., if and , then .
**Proof. **Since the inverse of a composition is the composition of the inverses, it suffices to show this for dTT and TTℓ by Lemmas 10 and 12. For dTT it follows from [20, Theorem 2.6 and Lemma 1.2], and for TTℓ it is proved in [26, Lemma 3].666We note that an alternative proof is by Lemma 26 (in Section 6) and [34, Theorem 7.4] (see also [65, Section 5]). For the reader familiar with mso translations, see [14], we note that it is proved in [29, Section 4] that dTT is the class of mso (tree) relabelings, and that REGT, which is the class of mso definable tree languages, is closed under inverse mso (tree) transductions by [14, Corollary 7.12].
Corollary 14
The domain of a tt is regular, i.e., . More generally, for every , if then .
Corollary 14 was proved for (nondeterministic) attributed tree transducers in [5], from which it is easy to conclude that Lemma 13 holds for attributed tree transducers, as explained in [26, Lemma 3].
Lemma 15
The regular tree languages are closed under pruning tt translations, i.e., if and \tau\in\mbox{\sf TT{}_{\mathrm{pru}}}, then .
**Proof. **By Lemma 12, \mbox{\sf TT{}{\mathrm{pru}}}=\mbox{\sf TT{}^{\hskip 1.13791pt\mathrm{s}}{\mathrm{pru}}}. As observed before, every \tau\in\mbox{\sf TT{}^{\hskip 1.13791pt\mathrm{s}}_{\mathrm{pru}}} can be realized by a classical linear top-down tree transducer with regular look-ahead. It is well known that, due to linearity, REGT is closed under such translations, see, e.g., [43, Corollary IV.6.7].
Lemma 13, Corollary 14 and Lemma 15 are powerful technical tools because they allow us to show that certain node tests of a tt are regular by defining them in terms of, e.g., the domains of other tt’s or of variants of itself. In other words, a tt can use tt’s “to look around”. For instance, Lemma 13 is used for this purpose in the proof of Lemma 16 below, where we show the following.
In a composition of a dtt with a sub-testing tt the second transducer can even be assumed to be local, because the first transducer can determine the truth values of the regular sub-tests of the output tree by executing appropriate regular tests on its input tree.
Lemma 16
\mbox{\sf dTT}\circ\mbox{\sf TT{}^{\hskip 1.13791pt\mathrm{s}}}\subseteq\mbox{\sf dTT}\circ\mbox{\sf TT{}^{\ell}}. The construction preserves determinism (of the second transducer) and the top-down, single-use, pruning, and relabeling properties of both transducers.
**Proof. **Let be a dtt and let be a sub-testing tt with input alphabet . We will construct a dtt and a local tt that simulate the composition of and . The construction preserves the top-down, single-use, pruning, and relabeling property of each transducer, i.e., if has one of these properties, then so has , and similarly for and . Moreover, if is deterministic, then so is .
Let . The dtt simulates on the input tree . Simultaneously it executes the sub-tests of at every node of the output tree and preprocesses by adding to the label of the truth values of these sub-tests at , cf. the text before Lemma 10. This allows , during its simulation of on , to inspect the new label of instead of sub-testing .
Every node of is produced by an output rule of during its computation on . Let be an output form of on , and let be a leaf of with label . It should be clear that . Now let be a regular tree language over such that uses the sub-test . We claim that, in configuration , can test whether by a regular test . Note that if and only if . Thus, should test whether the output tree generated by the configuration is in . To prove that is regular, we define a dtt such that and we use Lemma 13. The transducer first uses a regular test at the root to verify that the input tree is of the form .777To be precise, the regular sub-test .
After that it walks to the (unique) marked node , using move rules to execute a depth-first search of the input tree, and then simulates starting in state at , producing the output tree . During that simulation it treats each symbol or as , and for each regular test of it instead uses the test , which is the set of all such that and , see Section 2.
The construction of and is similar to the construction of and in the proof of Lemma 10. Let be the set of regular tests in the left-hand sides of the rules of . As in the proof of Lemma 10 we may assume that the tests in are mutually disjoint (by Lemma 8), and we define as in that proof. Note that the elements of are still regular sub-tests. Note also that for every , and , belongs to a unique regular test in .
We define the dtt such that contains all move rules in , and moreover, if is an output rule in , then contains the rule
[TABLE]
for every . We define the local tt with input alphabet and the following rules. If is a rule of , then has the rule . It should now be clear that for every , i.e., . If is single-use, then is also single-use, because visits the nodes of the input tree in the same states as ; the same is true for and . Preservation of the other properties easily follows from the construction of and .
5 Composition
In this section we prove three composition results for tt’s. Our first aim is to prove that dtt’s are closed under right-composition with top-down dtt’s, and hence in particular with pruning dtt’s. As already mentioned at the end of the Introduction, this generalizes the result of [38, Theorem 4.3] for attributed tree transducers, because dtt’s need not be total and they have regular look-around. By Lemma 12 we may assume that the top-down tt is sub-testing. It may even be assumed to be local by Lemma 16.
Lemma 17
\mbox{\sf dTT}\circ\mbox{\sf dTT{}^{\ell}_{\downarrow}}\subseteq\mbox{\sf dTT}. In particular
[TABLE]
**Proof. **Since the domain of a tt can always be restricted to by Lemma 9 and Corollary 14, it suffices to show that for every dtt and every local top-down dtt , a dtt can be constructed such that for every input tree . For the case where is also local this construction was presented in the proof of [28, Theorem 55], which can easily be adapted to the general case. We repeat it here for completeness sake, and because the proofs of the other two composition closure results will be based on it.
The transducer is obtained by a straightforward product construction. For every , simulates on the input tree until uses an output rule that generates a node of . Then switches to the simulation of on , as long as executes stay-instructions. When executes a -instruction, switches again to the simulation of in order to generate the -th child of .
Formally, let and . To simplify the construction of we assume that keeps track in its finite state of the child number of the output node to be generated. To be precise, we assume that there is a mapping such that for every output form and every leaf of that is labeled by a configuration , the child number of in is . That is possible because the output tree is generated top-down. If does not satisfy this assumption, then we change as follows. The new set of states is , and we define . The new initial state is , because starts by generating the root of the output tree. Each move rule of is changed into the rules and each output rule into , for every . For the sake of the proof of Lemma 22 we note that this transformation of preserves the single-use property, because we have only added information to the states of .
The dtt has input alphabet and output alphabet . Its states are of the form or , where , , and is an output rule of , i.e., a rule of the form . Its initial state is . A state is used by to simulate the computation of that generates the next current node of when moves down (keeping the state of in memory). Initially simulates the computation of that generates the root of the output tree. A state is used by to simulate the computation of on the node that has generated with rule . The rules of are defined as follows.
First, rules that simulate . Let be a rule in . If , then has the rules for every . If is an output rule, then has the rules for every .
Second, rules that simulate . Let be a rule in and let be an output rule in , with the same and with . Then has the rule where is obtained from by changing every into , and every into . Note that the test on , , and is actually superfluous, because that was already tested when included in its state.
It is easy to see that for every input tree . If the rules of do not contain stay-instructions, then does not need the states . Its rules can then be simplified as follows. Let be a rule in . As above, if , then has the rules for every . If and is a rule in , with the same and with , then has the rule where is obtained from by changing every into . This shows that if both and are pruning, then is pruning too.
We obtain our first composition closure result from Lemmas 12, 16, and 17. Note that the closure under composition of dTT↓ already follows from Lemma 12 and [20, Theorem 2.11(2)].
Theorem 18
\mbox{\sf dTT}\circ\mbox{\sf dTT{}_{\downarrow}}\subseteq\mbox{\sf dTT}. In particular, dTT↓ and dTTpru are closed under composition.
Theorem 18 can be used to show that in a composition of two dtt’s we may always assume that the second one is local (thus strengthening Lemma 16): by Lemma 10 the second tt can be decomposed into a top-down tt and a local tt, and then (by Theorem 18), the top-down one can be absorbed by the first tt. Hence \mbox{\sf dTT}\circ\mbox{\sf dTT}\subseteq\mbox{\sf dTT}\circ\mbox{\sf dTT{}_{\downarrow}}\circ\mbox{\sf dTT{}^{\ell}}\subseteq\mbox{\sf dTT}\circ\mbox{\sf dTT{}^{\ell}}. This was already proved in [28, Theorem 53] by means of pebble tree transducers.
Our second composition result generalizes Theorem 18 to nondeterministic tt’s, restricted to right-composition with pruning tt’s. The proof of the next lemma is similar to that of Lemma 17.
Lemma 19
\mbox{\sf TT}\circ\mbox{\sf TT{}^{\ell}_{\mathrm{pru}}}\subseteq\mbox{\sf TT}. In particular
[TABLE]
**Proof. **Let be a tt and a local pruning tt. The construction of the transducer such that is a straightforward variant of the one in the last paragraph of the proof of Lemma 17. This time, we do not verify at the start that the input tree is in the domain of , because it has to be checked at each step of that can produce an output tree, in particular when deletes part of that output tree (cf. the proof of [20, Lemma 2.9]).
We define as follows. As in the proof of Lemma 17 we assume that keeps track in its finite state of the child number of the output node to be generated, through a mapping . Let be a rule in . As before, if , then has the rules for every . If and is a rule in , with the same and with , then has the rule where is obtained (as before) from by changing every into , and the node test consists of all such that for every there exists a computation for some . Thus, the only difference with the proof of Lemma 17 is the additional test . In fact, it suffices that tests every for which does not occur in . That guarantees the existence of an output tree of on which is simulated by . It should be clear that is regular by Corollary 14: it can be written as where is the domain of a tt that walks to node and then simulates starting in state .
We note that this construction does not work for an arbitrary top-down without stay-instructions. If some occurs twice in , then there are two occurrences and in and it is not guaranteed (as it should) that from both occurrences the same output subtree of is generated by . We finally note that, as in the proof of Lemma 17, if both and are pruning, then so is .
We obtain our second composition result from Lemma 12, the second inclusion of Lemma 11, and two applications of Lemma 19 (taking into account that \mbox{\sf TT{}^{\ell}{\mathrm{rel}}}\subseteq\mbox{\sf TT{}^{\ell}{\mathrm{pru}}}).
Theorem 20
\mbox{\sf TT}\circ\mbox{\sf TT{}{\mathrm{pru}}}\subseteq\mbox{\sf TT}*. In particular \mbox{\sf TT{}{\downarrow}}\circ\mbox{\sf TT{}{\mathrm{pru}}}\subseteq\mbox{\sf TT{}{\downarrow}}, and TTpru is closed under composition.*
Hence, also in a composition of two nondeterministic tt’s we may always assume that the second one is local: \mbox{\sf TT}\circ\mbox{\sf TT}\subseteq\mbox{\sf TT}\circ\mbox{\sf dTT{}_{\mathrm{rel}}}\circ\mbox{\sf TT{}^{\ell}}\subseteq\mbox{\sf TT}\circ\mbox{\sf TT{}^{\ell}} by Lemma 10 and Theorem 20, respectively.
The range of a deterministic tt can be restricted to a regular tree language by restricting its domain to , using Lemmas 9 and 13. For a nondeterministic tt we can use the next corollary.
Corollary 21
The translation is in TT for every and . If is in TT↓ or TTpru, then so is .
**Proof. **Let be the output alphabet of and let be a bottom-up finite-state tree automaton such that . Obviously where is the identity on , and obviously \tau_{L}\in\mbox{\sf TT{}^{\ell}_{\mathrm{rel}}}: it is realized by the local relabeling tt where consists of all rules
[TABLE]
such that . By Theorem 20, satisfies the requirements.
Our third composition result is that deterministic tt’s are closed under left-composition with (deterministic) single-use tt’s. This is a variant of one of the main results of [40, 41, 45] for (a variant of) attribute grammars, cf. the last paragraph of [7]. It is proved for attributed tree transducers in [56, Theorem 3] (see also [55, Satz 6.5]).
Lemma 22
\mbox{\sf dTT{}_{\mathrm{su}}}\circ\mbox{\sf dTT{}^{\ell}}\subseteq\mbox{\sf dTT}.
**Proof. **Let and be a single-use dtt and a local dtt, respectively. We extend the proof of Lemma 17 to the case that is an arbitrary local dtt. Thus, we have to deal with the fact that now can also move up on the output tree of . Let , and let be the derivation tree of the computation . Since is single-use, we can identify each node of that is labeled by a configuration with that configuration, because a configuration of occurs at most once in . Suppose that , in configuration on , has generated a node of . When executes an up-instruction at node , the new transducer has to backtrack on the computation of , back to the moment that the parent of in was generated by . Thus, starting with the configuration of , has to determine the ancestors of in , and stop at the first ancestor that is a configuration generating an output node. Since is single-use, each configuration has a unique parent configuration in . That allows us to find by a regular test, as follows.
For every and every instruction of , we will define a regular test such that for every and , if and only if is the parent of in the derivation tree of the computation .888For the definition of see Section 3.
We will construct a tt and define . Then is regular by Corollary 14. To be able to describe , we change notation and consider the node test for and instruction .
Let be the nondeterministic tt obtained from by changing every output rule into the move rules for every . Intuitively, for an input tree , the tree-walking automaton follows an arbitrary path in the unique derivation tree , from the root of down to the leaves. Whenever branches, nondeterministically follows one of those branches. The transducer , which is a variant of , has states with as above. The initial state is , with the second and third component fixed, but irrelevant (e.g., ). On a tree , uses the state to simulate the computations of in state on , but additionally keeps the previous configuration of in its finite state, as the pair . When it arrives at the marked node in state , it outputs a symbol of rank 0. Formally, let be a rule in , let , let be an instruction, and let . Then has the rule where , , and for every and . Additionally, has the rule , where is its unique output symbol, of rank 0. Thus, if the tree-walking automaton arrives in state at the marked node , it can accept . Hence, for every , accepts if and only if is the parent of in the derivation tree of the computation .
The transducer is an extension of the one in the proof of Lemma 17. It additionally has states and to simulate the first and the following backward steps of the computation of . Its rules are obtained as follows. First, it has the same rules that simulate (the forward computation of) . Second, the rules of that simulate are extended in such a way that, to obtain from , one has to change additionally every into . Third, additionally has rules that simulate the backward computation of . For each state it has all rules (where the tests on and are irrelevant, because arrived in state by a stay-instruction). For each state it has the following rules. Let be a rule of . If is a move rule, then has all rules . If is an output rule, then has the rule .
Theorem 23
\mbox{\sf dTT{}_{\mathrm{su}}}\circ\mbox{\sf dTT}\subseteq\mbox{\sf dTT}.
**Proof. **It follows from Lemmas 10, 12, and 16 that
[TABLE]
Thus, by Lemma 22, it suffices to show that \mbox{\sf dTT{}{\mathrm{su}}}\circ\mbox{\sf dTT{}^{\ell}{\mathrm{rel}}}\subseteq\mbox{\sf dTT{}_{\mathrm{su}}}. For a single-use dtt and a local relabeling dtt , consider the construction of the dtt in the last paragraph of the proof of Lemma 17. It should be clear that is single-use: if visits an input node in state , then visits that node in state for some .
It can be proved that dTTsu is closed under composition, which also follows from Proposition 29 in the next section. The inclusion \mbox{\sf dTT{}{\mathrm{su}}}\circ\mbox{\sf dTT{}^{\ell}{\mathrm{rel}}}\subseteq\mbox{\sf dTT{}_{\mathrm{su}}} in the previous proof is a special case of that.
6 Macro and MSO
In this section we collect some results on the connection between tt’s, macro tree transducers (in short mt’s) and mso tree transducers. They are taken from the literature or can easily be proved using results from the literature. This section can be skipped on first reading, except that the reader interested in linear size increase should glance at Corollaries 32 and 33.
6.1 Macro Tree Transducers
Let MT denote the class of translations realized by mt’s, with unrestricted or outside-in (oi) derivation mode, let dMT denote the subclass realized by deterministic mt’s, and let dtMT denote the class of total translations in dMT (see [34] where they are denoted by MT, DMT, and DtMT, respectively). We first consider the relationship between deterministic tt’s and mt’s.
It is proved in [28, Lemma 49 and Corollary 51] that , and in [14, Theorem 8.22] (see also [28, Corollary 51]) that \mbox{\sf dMT}=\mbox{\sf dTT{}^{\ell}_{\downarrow}}\circ\mbox{\sf dTT{}^{\ell}}. Here we prove the following variant.
Lemma 24
\mbox{\sf dTT}\subseteq\mbox{\sf dMT}=\mbox{\sf dTT{}_{\downarrow}}\circ\mbox{\sf dTT}.
**Proof. **We first show that \mbox{\sf dTT{}{\downarrow}}\circ\mbox{\sf dMT}\subseteq\mbox{\sf dMT}. By Lemma 12 it suffices to show that \mbox{\sf dTT{}^{\hskip 1.13791pt\mathrm{s}}{\downarrow}}\circ\mbox{\sf dMT}\subseteq\mbox{\sf dMT}. The inclusion \mbox{\sf dTT{}^{\ell}{\downarrow}}\circ\mbox{\sf dMT}\subseteq\mbox{\sf dMT} is proved in [34, Theorem 7.6(3)]. As also argued before [32, Theorem 7.5], this implies the inclusion \mbox{\sf dTT{}^{\hskip 1.13791pt\mathrm{s}}{\downarrow}}\circ\mbox{\sf dMT}\subseteq\mbox{\sf dMT} as follows. By [20, Theorem 2.6] \mbox{\sf dTT{}^{\hskip 1.13791pt\mathrm{s}}{\downarrow}}\subseteq\mbox{\sf DBQREL}\circ\mbox{\sf dTT{}^{\ell}{\downarrow}}, where DBQREL is the class of deterministic bottom-up finite-state relabelings. Hence \mbox{\sf dTT{}^{\hskip 1.13791pt\mathrm{s}}_{\downarrow}}\circ\mbox{\sf dMT}\subseteq\mbox{\sf DBQREL}\circ\mbox{\sf dMT}. Since dMT is closed under regular look-ahead by [34, Theorem 6.15], it is straightforward to prove that , similar to the proof of [34, Lemma 6.17].
By Lemma 10, \mbox{\sf dTT}\subseteq\mbox{\sf dTT{}_{\downarrow}}\circ\mbox{\sf dTT{}^{\ell}}. It is proved in [31, Theorem 35 for ] that \mbox{\sf dTT{}^{\ell}}\subseteq\mbox{\sf dMT}.999By mistake, [31, Theorem 35] is stated for only. It also holds for by [31, Lemma 34 and Theorem 31].
Hence \mbox{\sf dTT}\subseteq\mbox{\sf dTT{}{\downarrow}}\circ\mbox{\sf dTT{}^{\ell}}\subseteq\mbox{\sf dTT{}{\downarrow}}\circ\mbox{\sf dMT}\subseteq\mbox{\sf dMT}, which implies that \mbox{\sf dTT{}{\downarrow}}\circ\mbox{\sf dTT}\subseteq\mbox{\sf dTT{}{\downarrow}}\circ\mbox{\sf dMT}\subseteq\mbox{\sf dMT}. It now remains to show that \mbox{\sf dMT}\subseteq\mbox{\sf dTT{}{\downarrow}}\circ\mbox{\sf dTT}. It is proved in [31, Section 5.5] that \mbox{\sf d{}{\mathrm{t}}MT}\subseteq\mbox{\sf dTT{}^{\ell}{\downarrow}}\circ\mbox{\sf dTT{}^{\ell}}. As shown in [34, Theorem 6.18], every translation is the restriction to a regular tree language of a translation \tau^{\prime}\in\mbox{\sf d{}{\mathrm{t}}MT}. Hence \tau^{\prime}\in\mbox{\sf dTT{}^{\ell}{\downarrow}}\circ\mbox{\sf dTT{}^{\ell}} and so \tau\in\mbox{\sf dTT{}{\downarrow}}\circ\mbox{\sf dTT{}^{\ell}}, because the first tt can start by verifying that the input tree is in with a regular test at the root of , by Lemma 9.
From Lemma 24, together with Theorem 18, we obtain the following corollary on compositions.
Corollary 25
For every , \mbox{\sf dTT}^{k}\subseteq\mbox{\sf dMT}^{k}=\mbox{\sf dTT{}_{\downarrow}}\circ\mbox{\sf dTT}^{k}\subseteq\mbox{\sf dTT}^{k+1}.
The above two inclusions are proper, cf. [39, Lemma 6.54] and [34, Theorem 4.16]. In fact, the macro tree transducer is, and can be, of exponential height increase [34, Theorem 3.24]. Hence is not in , cf. the proof of Proposition 7. Also, is not in where is an mt that translates into (with of rank 1 and of rank 0).
The relationship between nondeterministic tt’s and mt’s is less straightforward. On the one hand, even TT↓ is not included in MT because all macro tree translations are finitary. But we can express every tt as a composition of two top-down tt’s and an mt.
Lemma 26
\mbox{\sf TT}\subseteq\mbox{\sf TT{}{\downarrow}}\circ\mbox{\sf TT{}{\downarrow}}\circ\mbox{\sf MT}.
**Proof. **By Lemma 10, \mbox{\sf TT}\subseteq\mbox{\sf TT{}_{\downarrow}}\circ\mbox{\sf TT{}^{\ell}}. It follows from [31, Lemmas 34 and 27] that \mbox{\sf TT{}^{\ell}}\subseteq\mbox{\sf MON}\circ\mbox{\sf MT}, where MON is a specific simple subclass of TT defined before [31, Lemma 27].
We note that by Lemma 10, \mbox{\sf TT}\subseteq\mbox{\sf dTT{}{\mathrm{rel}}}\circ\mbox{\sf TT{}^{\ell}} and that it is easy to prove that \mbox{\sf dTT{}{\mathrm{rel}}}\circ\mbox{\sf TT{}^{\ell}{\downarrow}}\subseteq\mbox{\sf TT{}{\downarrow}}. Hence we even obtain that \mbox{\sf TT}\subseteq\mbox{\sf TT{}_{\downarrow}}\circ\mbox{\sf MT}.
On the other hand, every mt can still be realized by a composition of two (finitary) tt’s.
Lemma 27
\mbox{\sf MT}\subseteq\mbox{\sf dTT{}{\downarrow}}\circ\mbox{\sf dTT}\circ\mbox{\sf TT{}{\mathrm{pru}}}\subseteq\mbox{\sf dTT{}_{\downarrow}}\circ\mbox{\sf f\,TT}.
**Proof. **By [34, Theorem 6.10], \mbox{\sf MT}=\mbox{\sf d{}{\mathrm{t}}MT}\circ\mbox{\sf SET}, and by the proof of [34, Theorem 6.10], \mbox{\sf SET}\subseteq\mbox{\sf TT{}^{\ell}{\mathrm{pru}}}. Hence \mbox{\sf MT}\subseteq\mbox{\sf d{}{\mathrm{t}}MT}\circ\mbox{\sf TT{}^{\ell}{\mathrm{pru}}}\subseteq\mbox{\sf dTT{}{\downarrow}}\circ\mbox{\sf dTT}\circ\mbox{\sf TT{}{\mathrm{pru}}} by Lemma 24. That is included in \mbox{\sf dTT{}_{\downarrow}}\circ\mbox{\sf f\,TT} by Theorem 20.
It can be shown that \mbox{\sf f\,TT}\subseteq\mbox{\sf MT}=\mbox{\sf dTT{}_{\downarrow}}\circ\mbox{\sf f\,TT}, thus generalizing Lemma 24 to the finitary case, but that will not be needed in what follows.
Finally, let MT denote the class of translations realized by mt’s with inside-out (io) derivation mode (see [34]), and let mrMT denote the class of translations realized by the multi-return macro tree transducers of [49, 50], which generalize io macro tree transducers.
Lemma 28
\mbox{\sf MT}_{\text{{\sc io}}}\subseteq\mbox{\sf mrMT{}{\text{{\sc io}}}}\subseteq\mbox{\sf f\,TT{}{\downarrow}}\circ\mbox{\sf dTT}.
**Proof. **It is shown in [34, Lemma 5.5] that \mbox{\sf MT{}{\text{{\sc io}}}}\subseteq\mbox{\sf f\,TT{}^{\ell}{\downarrow}}\circ\mbox{\sf YIELD}, and in [31, Lemma 36] that \mbox{\sf YIELD}\subseteq\mbox{\sf dTT{}^{\ell}}, and so \mbox{\sf MT{}{\text{{\sc io}}}}\subseteq\mbox{\sf f\,TT{}^{\ell}{\downarrow}}\circ\mbox{\sf dTT}. It follows from [50, Lemma 4] that \mbox{\sf mrMT{}{\text{{\sc io}}}}\subseteq\mbox{\sf dTT{}^{\ell}{\downarrow}}\circ\mbox{\sf MT{}{\text{{\sc io}}}}\circ\mbox{\sf dTT{}^{\ell}{\downarrow}}. Hence
[TABLE]
which is included in \mbox{\sf f\,TT{}^{\hskip 1.13791pt\mathrm{s}}_{\downarrow}}\circ\mbox{\sf dTT} by [20, Theorem 2.11(2)] and Theorem 18.
6.2 MSO Tree Transducers
Let dMSOT denote the class of deterministic mso tree translations (see [14, Chapter 8], where it is denoted DMSOT, and where mso tree translations are called ms-transductions of terms). The next result is a variant of the main result of [7], which concerns attributed tree transducers with look-ahead instead of tt’s. In its present form it is proved in [14, Theorems 8.6 and 8.7].
Proposition 29
\mbox{\sf dMSOT}=\mbox{\sf dTT{}_{\mathrm{su}}}.
The next proposition is the main result of [32].
Proposition 30
\mbox{\sf d{}_{\mathrm{t}}MT}\cap\mbox{\sf LSIF}\subseteq\mbox{\sf dMSOT}.
This can be extended to arbitrary deterministic oi macro tree translations as follows.
Lemma 31
.
**Proof. **Since the domain of any mt is regular ([34, Theorem 7.4]), and dMT is closed under regular look-ahead ([34, Theorem 6.15]), there is a total mt that extends by the identity on the complement of . Clearly, is of linear size increase if and only if is. Hence, by Propositions 29 and 30, if is of linear size increase, then is in dTTsu. And so , which is the restriction of to the regular tree language , is also in dTTsu by Lemma 9.
From Lemma 24, Lemma 31, Proposition 29, and Lemma 6 we obtain the following corollary.
Corollary 32
\mbox{\sf dTT}\cap\mbox{\sf LSIF}=\mbox{\sf dTT{}_{\mathrm{su}}}.
It is also shown in [32] that it is decidable for a total deterministic mt whether or not it is of linear size increase. That also holds for arbitrary deterministic mt’s by the proof of Lemma 31, and hence also for dtt’s by Lemma 24.
Corollary 33
It is decidable for a deterministic tt whether or not it is of linear size increase.
Note that since Corollary 32 is effective, if the dtt is indeed of linear size increase, then an equivalent ttsu can be constructed. One of our aims is to extend Corollaries 32 and 33 to arbitrary compositions of dtt’s.
7 Functional Nondeterminism
In this section we prove that for every nondeterministic top-down tt a deterministic top-down tt can be constructed that realizes a “uniformizer” of , i.e., a subset of with the same domain. This is a generalization of [21, Lemma], where it is proved for classical nondeterministic top-down tree transducers. Note that, as opposed to the deterministic case, the nondeterministic top-down tt is more powerful than the classical nondeterministic top-down tree transducer with regular look-ahead, because, due to the stay-instructions, it may not be finitary, i.e., it possibly translates one input tree into infinitely many output trees.
A uniformizer of a tree translation is a function such that and . Intuitively, selects for every input tree one of the elements of .
Lemma 34
Every \tau\in\mbox{\sf TT{}{\downarrow}} has a uniformizer \tau^{\prime}\in\mbox{\sf dTT{}{\downarrow}}. If \tau\in\mbox{\sf TT{}{\mathrm{pru}}}, then \tau^{\prime}\in\mbox{\sf dTT{}{\mathrm{pru}}}.
**Proof. **Let be a nondeterministic tt↓. Without loss of generality we assume that has exactly one initial state , i.e., . We have to construct a deterministic tt↓ that computes one possible output tree in for every . The idea of the proof of [21, Lemma] is to pick, at the current node of , one of the rules that lead to the generation of an output tree (which can be checked by a regular test). However, that idea does not work here, because may have an infinite computation on (see [24, New Observation 5.10]). Thus, we have to be more careful. Note that an infinite computation is entirely due to the stay-instructions in the rules of .
The stay-instructions can be removed from by constructing the equivalent stay-free tt , with general rules, as we did at the end of Section 3. Recall that we assume that the regular tests in are mutually disjoint, and that the set consists of all general rules such that , for every left-hand side of a rule of . In this case is a top-down tt, with possibly infinitely many rules. Since its rules do not contain stay-instructions any more, it does not have infinite computations on the trees in its domain. Thus, the idea above can be applied to , which means that for every , , , and we have to pick one general rule from , under the condition that its application leads to the generation of an output tree. This condition can be checked by a regular sub-test, as follows. Note that where .
For every , , and , let be the node test over consisting of all such that has label in and there is a computation for some . This node test is regular by Corollary 14 because is the domain of a tt that on input walks to the marked node , checks that its label is , moves to the -th child of , and then simulates on , starting in state . For every and , let be the regular node test that is the intersection of all such that and all such that . Obviously the node tests are mutually disjoint.
We now define the deterministic tt↓ , where consists of the following general rules. For every left-hand side of a rule of and every , if , then contains the general rule where is a fixed element of .
It should be clear that satisfies the requirements, i.e., it has the same domain as and it realizes a subset of . Note that can be constructed effectively, because is a regular tree language, and hence its nonemptiness can be decided and, if so, an element can be computed. Finally, the general rules of can be replaced by ordinary rules, as discussed after Lemma 8.
At the end of this section we prove that any function that is realized by a composition of nondeterministic tt’s can also be realized by a composition of deterministic tt’s. That will (only) be used to show that the results of Section 9 also hold for nondeterministic tt’s and mt’s. Let be the class of all partial functions from trees to trees.
Theorem 35
For every , (\mbox{\sf TT{}{\downarrow}}\circ\mbox{\sf TT}^{k})\cap{\cal F}\subseteq\mbox{\sf dTT{}{\downarrow}}\circ\mbox{\sf dTT}^{k}.
**Proof. **By Lemmas 26 and 27, \mbox{\sf TT}\subseteq\mbox{\sf TT{}{\downarrow}}\circ\mbox{\sf TT{}{\downarrow}}\circ\mbox{\sf dTT{}{\downarrow}}\circ\mbox{\sf dTT}\circ\mbox{\sf TT{}{\downarrow}}. Now let \tau\in(\mbox{\sf TT{}{\downarrow}}\circ\mbox{\sf TT}^{k})\cap{\cal F}. Then where , for every , and \tau_{i}\in\mbox{\sf TT{}{\downarrow}} for every . By Corollary 14, the domain of a translation in TT is regular. Hence, we may assume that for every . If not, then we change into for inductively as follows. First, . Second, for we obtain from by restricting its range to , see Corollary 21 and the paragraph preceding it.
Since is a function, it should be clear that where \tau^{\prime}_{i}\in\mbox{\sf dTT{}{\downarrow}} is the uniformizer of that exists by Lemma 34 if \tau_{i}\in\mbox{\sf TT{}{\downarrow}}, and if . Thus, \tau\in\mbox{\sf dTT{}{\downarrow}}\circ(\mbox{\sf dTT{}{\downarrow}}\circ\mbox{\sf dTT{}{\downarrow}}\circ\mbox{\sf dTT{}{\downarrow}}\circ\mbox{\sf dTT}\circ\mbox{\sf dTT{}{\downarrow}})^{k} and so, by Theorem 18, \tau\in\mbox{\sf dTT{}{\downarrow}}\circ\mbox{\sf dTT}^{k}.
Corollary 36
For every , .
**Proof. **By the same argument as in the proof of Theorem 35, using Lemma 27 only, we obtain that \mbox{\sf MT}^{k}\cap{\cal F}\subseteq(\mbox{\sf dTT{}{\downarrow}}\circ\mbox{\sf dTT}\circ\mbox{\sf dTT{}{\downarrow}})^{k}. By Theorem 18 that is included in \mbox{\sf dTT{}_{\downarrow}}\circ\mbox{\sf dTT}^{k}, which equals by Corollary 25.
Since the inclusions in Corollary 25 are proper, as discussed after that corollary, Theorem 35 and Corollary 36 imply that and are also proper hierarchies, i.e., and for every .
8 Productivity
In this section we prove that every tt can be decomposed into a pruning tt and another tt such that the composition is linear-bounded. It implies that we may always assume that a composition of two tt’s is linear-bounded. Recall from Section 2 that the composition of tree translations and is linear-bounded if there is a constant such that for every there exists such that , , and . Formally we say that the pair is linear-bounded. Recall also that for classes and of tree translations, the class consists of all translations such that , , and is linear-bounded. Two elementary properties of this class operation were stated in Lemma 1. We will prove the following theorem.
Theorem 37
\mbox{\sf TT}\subseteq\mbox{\sf TT{}{\mathrm{pru}}}\ast\mbox{\sf TT}* and \mbox{\sf dTT}\subseteq\mbox{\sf dTT{}{\mathrm{pru}}}\ast\mbox{\sf dTT}.*
Since pruning tt’s can be absorbed to the right by arbitrary tt’s (by Theorems 20 and 18), Theorem 37 can be generalized to compositions of tt’s. It implies that we may always assume that a composition of a tt with any number of tt’s is linear-bounded.
Corollary 38
Let .
\mbox{\sf TT}^{k}\subseteq\mbox{\sf TT{}_{\mathrm{pru}}}\ast\mbox{\sf TT}^{k}* and , and* 2.
\mbox{\sf dTT}^{k}\subseteq\mbox{\sf dTT{}_{\mathrm{pru}}}\ast\mbox{\sf dTT}^{k}* and .*
**Proof. **(1) The proof of the inclusion is by induction on . For it is Theorem 37. The induction step is proved as follows:
[TABLE]
where the first inclusion is by the induction hypothesis and the remaining inclusions are by Lemma 1, Theorem 20 (which says that \mbox{\sf TT}\circ\mbox{\sf TT{}_{\mathrm{pru}}}\subseteq\mbox{\sf TT}), Theorem 37, and Lemma 1 again. The equation now follows from the inclusions above.
(2) The proof is exactly the same as in (1), using Theorem 18 instead of Theorem 20.
The remainder of this section is devoted to the proof of Theorem 37. It is essentially a variant of the proof of [25, Lemma 4.1], which is the key lemma of [25] and concerns the removal of “superfluous computations” in attribute grammars. In its turn, that proof generalized the proof of [4, Lemma 1] where this was done for top-down tree transducers (and strangely enough, the author of [25] did not mention that).
To prove Theorem 37 it suffices, by Lemma 10, Lemma 1, and Theorems 20 and 18, to consider local tt’s, i.e., to prove that \mbox{\sf TT{}^{\ell}}\subseteq\mbox{\sf TT{}{\mathrm{pru}}}\ast\mbox{\sf TT} and that \mbox{\sf dTT{}^{\ell}}\subseteq\mbox{\sf dTT{}{\mathrm{pru}}}\ast\mbox{\sf dTT}. We prove the first and second inclusion in a first and second subsection, respectively. In the first subsection we additionally take care that the construction preserves the determinism of the given tt.
8.1 Nondeterministic Productivity
Let be a tt. For a pair and a computation with , we say that a node of is productive (in that computation) if there is a such that an output rule is applied to the configuration in the computation. Obviously, the size of is at least the number of productive nodes of . For we define the computation to be -productive if all nodes of of rank are productive.101010Recall from Section 2 that the rank of a node is the rank of its label, i.e., the number of its children.
Moreover, the computation is productive if it is both [math]-productive and -productive, i.e., all leaves and monadic nodes of are productive. Finally, we define to consist of all for which there is a 0-productive computation for some , and we define to consist of all for which there is a productive computation of that form. Since the size of is at most twice the number of leaves plus the number of monadic nodes of ,111111To be precise, where and are the number of leaves and monadic nodes of , respectively.
it follows that for every .
To prove that \mbox{\sf TT{}^{\ell}}\subseteq\mbox{\sf TT{}_{\mathrm{pru}}}\ast\mbox{\sf TT}, our goal is to construct, for a given ttℓ , a pruning tt and a ttℓ in such a way that and . This obviously implies that . The second inclusion says that for every there exists a tree such that and . Thus, as observed above, , and hence is linear-bounded (for the constant ).
To this aim, will remove sufficiently many unproductive nodes from the input tree, and add state transition information of to the labels of the remaining nodes, thus allowing to simulate without having to visit those unproductive nodes. Since productivity of a node of the input tree depends on the computation of on , nondeterministically guesses which nodes to remove, and uses its regular tests to determine the possible behaviour of on the remaining nodes. To reduce the technical complexity of the proof, the construction of and will be done in two steps, removing unproductive leaves and monadic nodes in the first and second step, respectively.
Lemma 39
For every ttℓ there are a ttpru and a ttℓ such that
[TABLE]
If is deterministic, then so is .
Lemma 40
For every ttℓ there are a ttpru and a ttℓ such that
[TABLE]
If is deterministic, then so is .
It is easy to see that applying these lemmas one after the other, we have obtained the goal above; note that pruning tt’s are closed under composition by Theorem 20. It remains to prove the two lemmas. The constructions in their proofs are similar to the removal of -rules and chain rules from a context-free grammar, respectively. As is well known, one should not remove these rules in the reverse order, because the removal of -rules can create new chain rules. Similarly in our case, we should remove unproductive leaves and monadic nodes in that order, because the removal of unproductive leaves can create new unproductive monadic nodes. Note also that removing -rules and chain rules in one construction is technically more complex.
Proof of Lemma 39. Let be a ttℓ. As discussed in the second paragraph after Proposition 7 (in Section 3), we may assume that the output rules of only use the stay-instruction. Let us consider and a computation with . The idea of the construction of the ttpru and ttℓ is that (nondeterministically) preprocesses by removing the maximal subtrees of that consist of unproductive nodes only, and that simulates on the rest of . Let us say that a node of is superfluous (in this computation) if it is unproductive and all its descendants are unproductive. Note that the root of is not superfluous. Thus, changes into by pruning all superfluous nodes of . Moreover, it adds state transition information of to the labels of the remaining nodes to allow on to simulate the above computation of on . In the resulting computation of on , the input tree of has no superfluous nodes, which means in particular that all its leaves are productive. Note that, due to the removal of the superfluous nodes, each remaining node loses its superfluous children. Since the pruning tt does not know which nodes are going to be superfluous in ’s computation, it just nondeterministically removes subtrees of the input tree and adds to the label of each remaining node all possible state transitions of in computations on the removed subtrees that use move rules only. Whereas just guesses the superfluous nodes, it uses its regular tests to determine the state transitions of on those nodes.
As intermediate alphabet we use the ranked alphabet consisting of all symbols such that , , , and . The rank of is . In the case where is deterministic we require to be a partial function from to . Intuitively, a node of with label that is not removed by , will be relabeled by such that the subtrees at its children with are removed by and is the set of all such that has a computation from to (using move rules only) that visits one of the removed subtrees.
Formally, we define with one state . For every symbol in and every , it has the rule
[TABLE]
where is defined as follows. Let and let . The state transition relation is uniquely determined by , and is expressed by . Let us say that a node is a ghost if for some and . Moreover, let us say that a computation
[TABLE]
, is a ghost computation from to if is a ghost for every . Note that such a computation is due to move rules only, that it visits at least one ghost, and that the ghosts all belong to a subtree at the same child . Finally, for states we will write if there is a ghost computation from to . We now define to consist of all such that . Note that is indeed a partial function if is deterministic. The test is regular because it is a boolean combination of tests , which are regular because the tree language is regular for every by Corollary 14: it is the domain of a tt that first walks to , then simulates a ghost computation of on from to , and finally outputs a symbol of rank 0.
We define with the following rules. Let be a rule in , and let be an element of (with the same ). If is an output rule or with , then contains the rule . If with , then contains the rule . Otherwise (i.e., with ), contains the rule for every . Note that if is deterministic, then so is .
It should be clear that , because for every the computations of on simulate computations of on .
To understand that , consider a computation with , and let be such that all superfluous nodes of (in this computation) are removed. Then it should be clear that the computation of on can be simulated by a computation of on . In fact, if visits a superfluous child of the current (non-superfluous) node of , then just stays in the node corresponding to in and changes its state to the one in which returns to . For a completely formal correctness proof one would have to formalize the obvious bijective correspondence between the non-superfluous nodes of and the nodes of . In fact, , and if is non-superfluous and are all the non-superfluous children of , then for every . Note that and have the same child number. However, the correctness of the construction should be clear without such a proof. The configurations of on , for every non-superfluous node , are simulated by the configurations of on . Finally, the above computation of on is 0-productive, because each leaf of corresponds to a non-superfluous node of of which all descendants are superfluous, i.e., to a productive node. Since simulates , it follows that is a productive node of . This ends the proof of Lemma 39.
Proof of Lemma 40. This proof is similar to the previous one. Let be a ttℓ. Again, we assume that the output rules of only use the stay-instruction. And again, let us consider and a computation with . This time we define a node of to be superfluous if it is unproductive (in this computation) and has rank 1. As before, changes into by pruning all superfluous nodes of , and adds information to the labels of the remaining nodes to allow on to simulate the above computation of on . Whereas in the previous case, had to shortcut the subcomputations of on maximal subtrees of superfluous nodes, in the present case has to shortcut the subcomputations of on maximal sequences of superfluous nodes (), where is the unique child of for every . For such a sequence, the unique child of is non-superfluous, and either is the root of , or the parent of is non-superfluous. In the second case, a subcomputation of on is as follows. When it moves from down to , it either returns to , or it walks to . And when it moves from up to , it either returns to , or it walks to . In the first case, can only move from up to and return to . Thus, to the label of every non-superfluous node of we have to add information both on trips to superfluous nodes above and trips to superfluous nodes below . In the first case, will be the root of . In the second case, will be the -th child of in , where is the child number of in . Thus, the child number of changes from 1 to 0, or from 1 to , respectively.
As in the previous proof, the pruning tt does not know in advance which nodes are going to be superfluous in ’s computation. Thus, it just nondeterministically removes monadic nodes of the input tree and adds to the label of each remaining node all possible state transitions of in subcomputations on the removed nodes that use move rules only. Rather than constructing directly, it is more convenient to realize this pruning of by two consecutive pruning tt’s and , and use Theorem 20. The local relabeling tt nondeterministically marks monadic nodes of , by possibly changing the label of a monadic node into . The (deterministic) tt then removes the marked nodes, and relabels the unmarked nodes, adding the appropriate state transitions of (determined by regular tests). Since it is easy to construct , we only discuss .
The intermediate alphabet now consists of all symbols such that , , , and , where is the set of all possible instructions. The rank of is the rank of . As before, in the case where is deterministic we require to be a partial function from to . Intuitively, a node of with label that is not marked by , will be relabeled by such that is its child number in , if and only if is marked by , and is the set of all such that the following holds: has a computation from to (using move rules only) that visits a maximal sequence of marked nodes, for some unmarked node such that , where and are the nodes corresponding to and in the tree .
We define , where , , and is defined as follows. For every and the transducer has the rule . Moreover, for every and it has the rule
[TABLE]
where and is defined as follows. Let be a tree over and let . We define to be the tree over that is obtained from by changing every label into . Both and are uniquely determined, and they are expressed by . Let us say that a node is a ghost if its label is in . A ghost computation is defined as in the previous proof, for ; note that . And let us write if there is a ghost computation from to . We now define to consist of all such that
- •
if and only has a parent and that parent is a ghost,
- •
if and only if is a ghost,
- •
if and only if ,
- •
if and only if for some ancestor of ,
- •
if and only if for some descendant of .
As before, if is deterministic, then is indeed a partial function. It is straightforward to prove, using Corollary 14, that is regular; we leave that to the reader.
We define with the following rules. Let be a rule of , and let be in (with the same and ). If is an output rule or with , then contains the rule for every (except when ). If with , then contains the rule for every and every (except when ).
Let . It should be clear that , as in the previous proof. To understand that , consider a 0-productive computation with , and let be obtained from by removing all superfluous nodes of . As in the previous proof, there is an obvious bijective correspondence between the non-superfluous nodes of and the nodes of . For a node of we define if is non-superfluous, and is the first (i.e., shortest) non-superfluous descendant of otherwise. Then , and if is non-superfluous and is a child of , then . And as before, there is a computation of on that simulates the computation of on , such that the configurations of , for every non-superfluous node of , are simulated by the configurations of . Since does not remove leaves of , the computation of is still 0-productive. Moreover, it is also 1-productive because all unproductive monadic nodes were removed by . This ends the proof of Lemma 40.
Remark 41
In the Introduction we observed that our main technical result can be viewed as a static garbage collection procedure, which leads, in principle, to algorithms for automatic compiler and XML query optimization. For practical applicability our proof of this result is, however, of restricted value because the sizes of the involved transducers are blown up exponentially. This is due to the fact that, in the proof of Lemmas 39 and 40, the pruning tt uses regular tests to determine the relevant state transition information (or ) of the given tt , due to its ghost computations. These regular tests are constructed through Corollary 14, applied to variants of . Naturally, the number of states of the finite-state tree automaton recognizing the domain of such a variant is exponential in the number of states of , cf. the proof of [26, Lemma 1]. If one now considers the proof of in Corollary 38 (in which the pruning tt for the second tt is incorporated in the first tt by Theorem 20), it can be seen that the number of states of the first constructed tt is -fold exponential in the number of states of . The additional exponential jump is due to Lemma 12, which turns the pruning tt into one that is sub-testing. This implies that in the construction for the inclusion of Corollary 38, the size of the first constructed tt can be -fold exponential in the size of the last given tt. This will also hold for the deterministic version.
8.2 Deterministic Productivity
Let be a deterministic tt. For we say that a node of is productive if it is productive in the computation , and we say that is productive (for ) if that computation is productive, i.e., if all leaves and monadic nodes of are productive.121212There are several such computations, but they all have the same unique derivation tree in . The definition of productivity clearly does not depend on the particular choice of the derivation.
We define to be the set of all productive trees . Note that is the restriction of to . The next lemma shows that the set of productive input trees is a regular tree language.
Lemma 42
Let be a deterministic tt.
There is a regular test over such that for every and , if and only if is productive. 2.
* is a regular tree language over .*
**Proof. **(1) Let be the nondeterministic tt such that has rank 0, and is defined as follows. If is a move rule in , then is a rule in for every . If is an output rule in , then contains the rules for every and it also contains the rule . Intuitively, for an input tree with , the tree-walking automaton follows an arbitrary path in the unique derivation tree , from the root of down to the leaves (cf. and in the proof of Lemma 22). Whenever branches at an unmarked node, nondeterministically follows one of those branches. It accepts when an output rule is applied to the marked node . It should be clear that satisfies the requirements. It is regular by Corollary 14.
(2) Let be a dtt that performs a depth-first left-to-right traversal of the input tree and verifies that for every leaf and monadic node of . Then , which is regular by Corollary 14.
For a given deterministic tt there are a nondeterministic pruning tt and a deterministic ttℓ such that and , by Lemmas 39 and 40. Our aim is to transform and in such a way that becomes deterministic. We basically do this by applying Lemma 34 to , replacing it by one of its uniformizers. But to preserve the above two properties we first restrict the domain of to productive input trees and then restrict the range of to the new domain, as follows.
By Lemma 42, the tree language is regular. Let be the dtt that is obtained from by restricting its domain to , see Lemma 9. Hence, and so . Since behaves in the same way as , every tree is productive (for ). Next, we change into the nondeterministic pruning tt by restricting its range to , by Corollary 21. Now and . Finally, we define \tau\in\mbox{\sf dTT{}{\mathrm{pru}}} to be the uniformizer of according to Lemma 34. Then . Now consider . Then for . Since is productive for , it follows that as observed at the end of the second paragraph of Section 8.1. Hence is linear-bounded, which shows that \tau_{M}\in\mbox{\sf dTT{}{\mathrm{pru}}}\ast\mbox{\sf dTT}.
9 Linear Size Increase
In this section we show our first main result: the hierarchy of tt’s collapses for functions of linear size increase.
Theorem 43
For every , \mbox{\sf dTT}^{k}\cap\mbox{\sf LSIF}=\mbox{\sf dTT{}_{\mathrm{su}}}.
**Proof. **The proof is by induction on . For it is Corollary 32. To prove that \mbox{\sf dTT}^{k+1}\cap\mbox{\sf LSIF}\subseteq\mbox{\sf dTT{}{\mathrm{su}}}, let and let be a dtt such that . By Corollary 38(2) we may assume that is linear-bounded. Moreover, by restricting the domain of to we may assume that , see Lemma 9 and Corollary 14. Hence by Lemma 2 and so \tau_{M}\in\mbox{\sf dTT{}{\mathrm{su}}} by Corollary 32. Then by Theorem 23. Hence \tau_{M}\circ\tau\in\mbox{\sf dTT{}_{\mathrm{su}}} by induction.
Theorem 44
It is decidable for a composition of deterministic tt’s whether or not it is of linear size increase.
**Proof. **The proof is, again, by induction on , the number of dtt’s in the composition. It goes along the lines of the proof of Theorem 43, using Corollary 33 instead of Corollary 32 for the case . Assuming that we have an algorithm for a composition of dtt’s, we construct as follows. Let be dtt’s, , and let . Since all our results are effective, we may assume as in the proof of Theorem 43 that is linear-bounded and . To decide whether or not is of linear size increase, we first decide whether or not is of linear size increase by Corollary 33. If not, then is not of linear size increase, by Lemma 2. If so, then a dtt that realizes can be constructed by Corollary 32 and Theorem 23, and we apply to .
Together with Lemma 24 and Proposition 29 in Section 6, Theorems 43 and 44 imply the following two corollaries on macro tree transducers.
Corollary 45
For every , \mbox{\sf dMT}^{k}\cap\mbox{\sf LSIF}=\mbox{\sf dMSOT}=\mbox{\sf dTT{}_{\mathrm{su}}}\subseteq\mbox{\sf dMT}.
Corollary 46
It is decidable for a composition of deterministic mt’s whether or not it is of linear size increase.
For the class dMT of translations realized by deterministic macro tree transducers with inside-out (io) derivation mode, we obtain that \mbox{\sf dMT}_{\text{{\sc io}}}^{k}\cap\mbox{\sf LSIF}\subseteq\mbox{\sf dTT{}_{\mathrm{su}}} for every , for the simple reason that dMT is a (proper) subclass of dMT by [34, Theorem 7.1(1)]. For the same reason Corollary 46 is also valid for those transducers. However, dTTsu is not included in dMT, because not every regular tree language is the domain of a deterministic io macro tree transducer (see [34, Corollary 5.6]).
Since , it follows from Theorems 43 and 35 that Theorem 43 also holds for nondeterministic tt’s, i.e., \mbox{\sf TT}^{k}\cap\mbox{\sf LSIF}=\mbox{\sf dTT{}_{\mathrm{su}}} for every .131313We do not know whether Theorem 44 holds for nondeterministic tt’s, i.e., whether it is decidable for a composition of nondeterministic tt’s whether or not it realizes a translation in LSIF.
Similarly, it follows from Corollaries 45 and 36 that Corollary 45 also holds for nondeterministic mt’s, i.e., \mbox{\sf MT}^{k}\cap\mbox{\sf LSIF}=\mbox{\sf dMSOT}=\mbox{\sf dTT{}{\mathrm{su}}}\subseteq\mbox{\sf dMT} for every . This even holds for the so-called stay-macro tree transducers that can use stay-instructions, introduced in [31, Section 5.3], because it is shown in [31, Lemma 37] that the stay-macro tree translations are in . For the class of nondeterministic io macro tree translations we also obtain that \mbox{\sf MT}_{\text{{\sc io}}}^{k}\cap\mbox{\sf LSIF}\subseteq\mbox{\sf dTT{}{\mathrm{su}}} for every , because by Lemma 28; the same is true for multi-return macro tree transducers.
The -pebble tree transducer was introduced in [63] as a model of XML document transformation. It is a tt that additionally can use distinct pebbles to drop on, and lift from, the nodes of the input tree. The life times of these pebbles must be nested. The tt is the 0-pebble tree transducer. It is shown in [31, Theorem 10] that every (deterministic) -pebble tree translation can be realized by a composition of (deterministic) tt’s. Hence Theorems 43 and 44 also hold for deterministic -pebble tree transducers, while Theorem 43 additionally holds for the nondeterministic case. In [28, Theorems 5 and 55] this is extended to -pebble tree transducers that, in addition to the distinct “visible” pebbles, can use an arbitrary number of “invisible” pebbles, still with nested life times: they can be realized by a composition of tt’s. Thus, Theorems 43 and 44 also hold for such transducers, cf. [28, Theorem 57].141414A “visible” pebble can be observed by the transducer during its entire life time (as usual for pebbles), whereas an “invisible” pebble cannot be observed during the life time of a pebble of which the life time is nested within the one of ; thus, such a pebble “hides” the pebble .
The high-level tree transducer was introduced in [35] as a generalization of both the top-down tree transducer and the macro tree transducer. It is proved in [35, Theorem 8.1(b)] that nondeterministic high-level tree transducers can be simulated by compositions of nondeterministic mt’s. Since every deterministic high-level tree transducer realizes a partial function (as should be clear from the proof of [35, Lemma 5.7]), it follows from Corollary 36 that, similarly, deterministic high-level tree transducers can be simulated by compositions of deterministic mt’s. Consequently, Corollaries 45 and 46 also hold for deterministic high-level tree transducers, and Corollary 45 additionally for the nondeterministic case.
10 Deterministic Complexity
Our first main complexity result says that a composition of deterministic tt’s can be computed by a RAM program in linear time, more precisely in time where is the sum of the sizes of the input and the output tree.
Theorem 47
For every and every there is an algorithm that computes, given an input , the output in time .
**Proof. **The proof is by induction on . We first prove the case , which is a slight generalization of the well-known fact for attribute grammars that the attribute evaluation of an input tree takes linear time (see, e.g., [17, 23]). Let and let be an input tree of . By Corollary 14, is regular and hence can be recognized by a bottom-up finite-state tree automaton. Thus, we can decide whether or not in time by running that automaton on . By Lemmas 10 and 12, with \tau_{1}\in\mbox{\sf dTT{}^{\hskip 1.13791pt\mathrm{s}}_{\mathrm{rel}}} and \tau_{2}\in\mbox{\sf dTT{}^{\ell}}. As observed in Section 3, can be realized by a classical linear deterministic top-down tree transducer with regular look-ahead. Thus, by (the proof of) [20, Theorem 2.6], it can be realized by a deterministic bottom-up finite-state relabeling (DBQREL) and a local relabeling tt. To run these two relabelings on obviously takes time . Thus, it remains to consider the case that \tau\in\mbox{\sf dTT{}^{\ell}}. Let be a local dtt that realizes . To compute , we first construct the regular tree grammar in time , the number of configurations of on . Then we remove the chain rules from the context-free grammar , i.e., the rules resulting from the move rules of . Since is forward deterministic, this can also be done in time , as follows. Viewing the chain rules as edges of a directed graph with configurations as nodes, we compute an evaluation order of the graph by topological sorting, in time . Then we compute the new rules by traversing this order from right to left, again in time . For an edge , if the (old or new) rule for is , then the new rule for is . Finally, we use this new regular tree grammar, equivalent to , to generate , which takes time because each rule generates a node of .
Now let such that and , . By Corollary 38(2) we may assume that is linear-bounded. Let be an input tree of . Since is regular by Corollary 14, we can check that in linear time, as above. By the case , the intermediate tree can be computed in time , and by induction the output tree can be computed in time . Since is linear-bounded, there is a constant such that , i.e., . Hence the total time is .
It should be noted that the constant in the time complexity can be large in terms of the size of the given transducers due to the use of linear-boundedness, cf. Remark 41.
Since deterministic macro tree transducers, pebble tree transducers, and high-level tree transducers can be realized as compositions of deterministic tt’s (see Section 9), Theorem 47 also holds for such transducers. For -pebble tree transducers this improves the result of [63, Proposition 3.5], where the time bound is .
Before we proceed, we need an elementary lemma on leftmost derivations of context-free grammars. For a context-free grammar , a leftmost sentential form is a string such that for some , where is the usual leftmost derivation relation of : if is in , then for all and .
Lemma 48
*Let be an -free context-free grammar, and let be the equivalent context-free grammar such that and , where is a new nonterminal. Let be a leftmost sentential form of , and let be a leftmost derivation of with and . Moreover, let be the derivation tree corresponding to that derivation. Then the number of occurrences of in is at most the height of .151515Note that there is a straightforward one-to-one correspondence between the leftmost derivations of and , and between their derivation trees. Since is -free, the derivation trees have the same height. *
**Proof. **Each occurrence of a nonterminal in corresponds to a node of with label in a well-known way. Let be the node of corresponding to the leftmost occurrence of in . Clearly the number of occurrences of in is equal to the number of edges on the path from to the root of .
By [64, Theorem 2.5] it follows from Theorem 47 that a composition of deterministic tt’s can be computed by a deterministic Turing machine in cubic time, more precisely in time where is the sum of the sizes of the input and the output tree. Our second complexity result says that a composition of deterministic tt’s can be computed by a deterministic multi-tape Turing machine in linear space (in the sum of the sizes of the input and output tree). On a work tape of we will represent the input tree over by the string over , where is the set consisting of the left- and right-parenthesis, defined such that if then . In other words, we formally insert the parentheses (but not the commas) that are always used informally to denote trees. The parentheses allow to walk on the tree , from node to node, because it can recognize a subtree of by checking that the numbers of left- and right-parentheses in the corresponding substring of are equal. In particular, it can determine the child number of a node of by counting the number of its younger siblings. Obviously, the mapping is injective, and can be computed in linear space (simulating a one-way push-down transducer). In what follows we identify and .
Theorem 49
For every and every there is a deterministic Turing machine that computes, given an input , the output in space .
**Proof. **Again, we first show this for . Let be a dtt, and let be an input tree. As usual we assume that the output rules of only contain stay-instructions. We describe a deterministic multi-tape Turing machine that computes in linear space. By Corollary 14, is a regular tree language and hence a context-free language, which can be recognized in deterministic linear space. Thus, starts by deciding whether or not . Now assume that . To compute , the machine simulates the (unique) leftmost derivation of the forward deterministic context-free grammar . Every leftmost sentential form of is of the form with and . If one views the states of as recursive procedures with one parameter of type ‘node of ’, then corresponds to the contents of the stack in the usual implementation of recursive procedures: each configuration is a call of procedure with actual parameter . The machine uses a one-way output tape on which it prints (which will finally be ), a work tape with the input tree (or rather ), and a work tape that contains a stack representing , with the top of the stack to the left. At each moment of time, a reading head of is at node of , and another reading head is at the top of the stack. Note that because every configuration will generate at least one symbol of . If would represent the parameters by their Dewey notation, the size of the stack could be , which is too much. Thus, we need a more compact representation of the nodes . In a rule of with left-hand side , every node in the right-hand side is a neighbour of , or itself, and so, the “difference” between and can be expressed by an instruction in . This allows us to represent by the node and a stack of the form where is a sequence of instructions that leads from to (with ). Let us now consider in detail how simulates the leftmost derivation of .
At each moment of time, the current node of and the current contents of the output tape and the stack tape represent a leftmost sentential form of , which is an element of . The stack tape contains a string in , where is the bottom stack symbol and is as above. The current node of and the current contents and of the output tape and stack tape, respectively, represent the leftmost sentential form , where the string is defined as follows (for every and ): , , and . Initially, starts at the root of , with empty output tape and with stack tape , representing the initial output form . If the top symbol of the stack is , then halts. Otherwise, to compute the next leftmost sentential form, first pops the top symbol off the stack. If that symbol was , and the current node of has label and child number , then selects the unique rule that is applicable to . Note that it can test in linear space whether or not , because is a context-free language. If , then moves to node of and pushes the string on the stack where is defined as follows: if is , , or , then is , , or , respectively. If , then outputs , and pushes on the stack (if ). It is easy to check that in both these cases the resulting configuration of represents the next leftmost sentential form of . If the top symbol of the stack was , the machine moves to node of . This does not change the represented leftmost sentential form. Thus, after applying a rule (with of rank [math]), removes instructions from the stack (and moves its reading head on accordingly) until the top of the stack is a state again. When halts, the output tape contains .
It remains to show that the length of the stack is linear in . As mentioned above, since every configuration will generate at least one symbol of , the number of occurrences of states in the stack is at most . To estimate the number of occurrences of instructions in the stack, we use Lemma 48. In the above case where is the top stack symbol and is the rule applicable to , the machine does not apply the rule of , but rather the rule where is defined as above. Moreover, when is the top stack symbol, applies the rule . From this it should be clear that, by Lemma 48 and footnote 15, the number of occurrences of instructions in the stack is at most the height of the derivation tree corresponding to the derivation of . As observed in Section 2 after Lemma 3, that height is at most , i.e., . Thus, the length of the stack is indeed .
The induction step can be proved in exactly the same way as in the proof of Theorem 47, with ‘time’ replaced by ‘space’.
For a class of tree translations and a class of tree languages, we denote by the class of tree languages with and . The elements of are called the output tree languages (or surface languages) of . Since by Lemma 24, it follows from the proof of [34, Theorem 7.5] that the output tree languages of are recursive. From Theorem 49 we now obtain that they are in , i.e., can be recognized by a Turing machine in deterministic linear space. This was shown for classical top-down tree transducers in [4].
Theorem 50
For every , .
**Proof. **Let and . By Corollary 38(2), such that \tau_{1}\in\mbox{\sf dTT{}_{\mathrm{pru}}}, , and is linear-bounded for some constant . Let , and note that and that by Lemma 15. It is straightforward to show that for every there exists such that and . To check whether a given tree is in , a deterministic Turing machine systematically enumerates all input trees (of ) such that . For each such it first checks that in space . Then it uses the algorithm of Theorem 49 to compute in space , but rejects as soon as the computation takes more than space ; thus, the space used is . Clearly, if and only if for some such .
For a tree we denote its yield by , for a tree language we define , and for a class of tree languages we define . For a class of tree translations, the languages in are called the output string languages (or target languages) of .
Corollary 51
For every , .
**Proof. **For an alphabet , let be the ranked alphabet such that has rank 0 and every element of has rank 1. For a string over we define . It is easy to see that for every ranked alphabet there is a dttℓ such that . From this and Theorem 50 the result follows.
We observe here, for , that and are included in LOGCFL, the class of languages that are log-space reducible to a context-free language. This will be proved in Corollaries 64 and 65. Note that .
We also observe that Theorem 50 and Corollary 51 also hold for nondeterministic tt’s, as will be proved in Theorem 67 (and was proved for classical top-down tree transducers in [4]).
As before, Theorems 49 and 50 and Corollary 51 also hold for deterministic macro tree transducers, pebble tree transducers, and high-level tree transducers. It is proved in [30, Theorem 23] that composition of deterministic mt’s yields a proper hierarchy of output string languages (called the -hierarchy), i.e., that for every . The io-hierarchy consists of the classes of string languages generated by level- grammars, with the inside-out (io) derivation mode (see, e.g., [16]). By [33, Theorem 7.5] the io-hierarchy can be defined as output string languages of tree transformations: . Since by [31, Lemma 36], we obtain that . Thus, the next corollary is immediate from Corollary 51. Note that it was already proved in [37, Theorem 3.3.8] that the io languages (i.e., the languages in ) are in ; in [3] this was improved to LOGCFL. It was proved in [16, Corollary 8.12] that the languages in the io-hierarchy are recursive.
Corollary 52
For every , .
Note that by [30, Theorem 36] the EDTOL control hierarchy is included in the io-hierarchy.
By Corollary 25, . It is proved in [30, Theorem 32] that there exists a language in that is not in . Since , that implies the following stronger version of Proposition 7.
Corollary 53
For every , .
11 Nondeterministic Complexity
We now turn to the complexity of compositions of nondeterministic tt’s. We first consider the case where all the transducers in the composition are finitary. The next lemma shows that Theorem 37 and Corollary 38 also hold for f TT.
Lemma 54
\mbox{\sf f\,TT}^{k}\subseteq\mbox{\sf TT{}_{\mathrm{pru}}}\ast\mbox{\sf f\,TT}^{k}* and for every .*
**Proof. **To show that \mbox{\sf f\,TT}\subseteq\mbox{\sf TT{}{\mathrm{pru}}}\ast\mbox{\sf f\,TT}, let . By Theorem 37, such that \tau_{1}\in\mbox{\sf TT{}{\mathrm{pru}}}, , and is linear-bounded. Since by Lemma 15, we may assume that by Lemma 9. Then is finitary too.
Theorem 20 implies that \mbox{\sf f\,TT}\circ\mbox{\sf TT{}_{\mathrm{pru}}}\subseteq\mbox{\sf f\,TT}, because the composition of two finitary translations is finitary. The remainder of the proof is now entirely similar to the one of Corollary 38.
We will prove that a composition of tt’s can be computed by a nondeterministic Turing machine in linear space and polynomial time (in the sum of the sizes of the input and output tree), which generalizes Theorem 49. In the next lemma we consider the case where all tt’s are finitary.
Lemma 55
For every and every there is a nondeterministic Turing machine that computes, given an input , any output in space and in time polynomial in .
**Proof. **For the case the proof is exactly the same as that of Theorem 49 except, of course, that the Turing machine nondeterministically simulates any leftmost derivation of , selecting nondeterministically a rule of to compute a next leftmost sentential form. It follows from Lemmas 48 and 3 that the number of occurrences of instruction symbols in the stack is . In fact, since is finitary, it suffices by Lemma 3 to simulate leftmost derivations of for which the corresponding derivation tree in has height at most . As in the proof of Theorem 49, Lemma 48 implies that is at most that height, i.e., at most . Thus, works in space . Moreover, it works in time , because the size of such a derivation tree (and hence the length of the leftmost derivation) is at most , and each step in the leftmost derivation takes time . Note that regular tree languages (which are context-free languages) can be recognized in nondeterministic linear time.
Now let such that and , . We may assume by Lemma 54 that is linear-bounded. So, there is a constant such that for every there exists a tree such that , , and . By the case , the intermediate tree can be computed from in nondeterministic space , and by induction, the output tree can be computed from in nondeterministic space . Hence, since , can be computed from in nondeterministic space . The time is polynomial in and , and hence polynomial in .
By Lemma 27, . Consequently Lemma 55 also holds for every .
We now turn to the output languages of . By we will denote the class of languages that can be recognized by a nondeterministic Turing machine in simultaneous linear space and polynomial time. Trivially, is included in both and NPTIME.
Lemma 56
For every , .
**Proof. **The proof is similar to the one of Theorem 50. Let and . By Lemma 54, where \tau_{1}\in\mbox{\sf TT{}_{\mathrm{pru}}}, , and is linear-bounded for some constant . Let . Then if and only if there exists such that and . To check whether a given tree is in , a nondeterministic Turing machine guesses an input tree such that , it checks that in time and space (because is a context-free language), and then computes any with in space and time polynomial in , by Lemma 55. Finally it checks that in time and space . Thus the space used is , and the time is polynomial in .
Although mt’s are finitary, whereas tt’s need not be finitary, it is proved in [31, Theorem 38 and Corollary 39] that compositions of mt’s have the same output languages as compositions of (local) tt’s. This implies that Lemmas 56 and 55 also hold for .
Theorem 57
For every , , and moreover, .
**Proof. **By Lemma 27, . Thus, by Lemma 56, . From Lemma 10 and Theorem 20 it follows (by induction on ) that \mbox{\sf TT}^{k}\subseteq\mbox{\sf dTT{}_{\mathrm{rel}}}\circ(\mbox{\sf TT{}^{\ell}})^{k} and hence \mbox{\sf TT}^{k}(\mbox{\sf REGT})\subseteq(\mbox{\sf TT{}^{\ell}})^{k}(\mbox{\sf REGT}) by Lemma 15. Finally, by [31, Theorem 38 and Corollary 39], (\mbox{\sf TT{}^{\ell}})^{k}(\mbox{\sf REGT})\subseteq\mbox{\sf MT}^{m}(\mbox{\sf REGT}) for some . Hence , by the above.
As observed already after Corollary 51, the space part of Theorem 57 will be strengthened to in Theorem 67.
Theorem 58
For every and every there is a nondeterministic Turing machine that computes, given an input , any output in space and in time polynomial in . The same holds for .
**Proof. **For this was already observed after Lemma 55. Now let with input alphabet . Let with be a set of new symbols, and let be obtained from by changing each label into . Finally, let be a new symbol of rank 2. It is easy to show that the tree language is in : the first transducer additionally copies the input to the output (with bars), and each other transducer copies the first subtree of the input to the output. By Theorem 57, there is a nondeterministic Turing machine that recognizes in linear space and polynomial time. We construct the nondeterministic Turing machine that, on input , guesses a possible output tree , writing on a worktape, uses as a subroutine to verify that , and outputs . Clearly, satisfies the requirements.
Since io (multi-return) macro tree translations, pebble tree translations, and high-level tree translations can be realized by compositions of tt’s (see Section 9), Theorems 57 and 58 also hold for those translations.
By the proof of Corollary 51, we additionally obtain from Theorem 57 that for every , and the same is true for . The oi-hierarchy consists of the classes of string languages generated by level- grammars, with the outside-in (oi) derivation mode (see, e.g., [16, 33]). It was shown in [37, Theorem 4.2.8] that equals the class of indexed languages of [1], and hence that by [1, Theorem 5.1]. Moreover, it was shown in [67, Proposition 2] that . In [16, Corollary 7.26] it was proved that the languages in the oi-hierarchy are recursive. As observed in the last paragraph of [35], is included in for some .
Corollary 59
For every , .
It is shown in [67] that there is an NP-complete language in both and y\mbox{\sf f\,TT{}{\downarrow}}(\mbox{\sf REGT}), and it is shown in [74] that there even is one in the class ETOL, which is a subclass of both and y\mbox{\sf f\,TT{}{\downarrow}}(\mbox{\sf REGT}). Note that by [75, Theorem 14] the ETOL control hierarchy is included in the oi-hierarchy.
It will be shown in Corollary 68 that .
12 Translation Complexity
In this section we study the time and space complexity of the membership problem of the tree translations in , i.e., for a fixed tree translation we want to know, for given trees and , how hard it is to decide whether or not . To formalize this, we denote by the string language , where is a new symbol. For simplicity, and without loss of generality, we assume that . Otherwise, we replace by as in the proof of Theorem 58. So, is a tree language over , where has rank 2. For a class of tree translations and a complexity class , we will write to mean that for every . As usual, we denote the class of languages that are accepted by a deterministic Turing machine in polynomial time by PTIME, and the class of languages that are log-space reducible to a context-free language by LOGCFL. Note that every regular tree language is a context-free language and hence is in LOGCFL. Note also that (see [68]) and (see [57, 68] and [46, Theorem 12.7.4]).
If then, on input , we can compute according to Theorems 47 and 49 (rejecting the input when the computation takes more than time or space for the given constant ) and then verify that , cf. the proof of Theorem 50. Thus, can be accepted by a RAM program in linear time and by a deterministic Turing machine in linear space. This means that and . If , then, as mentioned in the proof of Theorem 58, the tree language is in the class of output languages , and hence in by Theorem 57. This means that and . Due to the presence of both the input tree and the output tree in , one would expect that better upper bounds can be shown. Indeed, we will prove that .
Our main aim in this section is to prove that . We follow the approach of [25], using multi-head automata.
A multi-head tree-walking tree transducer (in short, mhtt) is defined in the same way as a tt, but has an arbitrary, fixed number of reading heads. Each of these heads can walk on the input tree, independent of the other heads. It can test the label and child number of the node that it is currently reading, and additionally apply a regular test to that node. Moreover, we assume that the heads are “sensing”, which means that can test which heads are currently scanning the same node. Thus, if has heads, then its move rules are of the form
[TABLE]
where is an equivalence relation. A configuration of on input tree is of the form , to which the rule is applicable if is in state , each satisfies the tests , , and , and for every . After application the new configuration is . The output rules are defined in a similar way. Initially all reading heads are at the root of the input tree. This is all similar to how multi-head automata on strings are defined.
We will use the mhtt as an acceptor of its domain. We will say that it accepts in polynomial time if there is a polynomial such that for every there is a computation of length at most for some and . Note that we consider nondeterministic mhtt’s only.
Lemma 60
For every multi-head tt , . Moreover, if accepts in polynomial time, then .
**Proof. **After this paragraph we will show that the domain of a multi-head tt can be accepted by an alternating multi-head finite automaton (in short, amfa), in a straightforward way. Moreover, we will show that if the mhtt accepts in polynomial time, then the corresponding amfa accepts in polynomial tree-size. That proves the lemma because PTIME is the class of languages accepted by amfa’s (see [10, 12]) and LOGCFL is the class of languages accepted by amfa’s in polynomial tree-size (see [68, 71]).
It is well known that the domain of a classical local tt can be accepted by an alternating (one-head) tree-walking automaton, see, e.g., [70], [24, Section 4], and [63, Section 4], and the same is true for the multi-head case. Let be an mhtt. The amfa that accepts simulates on the input , without producing output. The reading heads of are simulated by reading heads of in the obvious way. Every (initial) state of is simulated by the existential (initial) state of , and a move rule of is simulated by a transition of in an obvious way. If applies an output rule in state , then first goes into a universal state and then branches in the same way as , going into existential states. A regular test of is simulated by in a side branch, using an amfa subroutine that accepts the context-free language , with additional reading heads. Note that since the heads are sensing, the node to be tested is “marked” by a reading head. Similarly, to move a head from a parent to its -th child , first moves an auxiliary head nondeterministically to a position to the right of , then checks in a side branch that the string between and belongs to the context-free language , and finally moves to . In a similar way can move from to , and can determine the child number of .
If accepts in time , then the size of the corresponding computation tree of is polynomial in , because each computation step of takes polynomial tree-size. Thus, if accepts in polynomial time, then accepts in polynomial tree-size.
Note that if we assume that the simulation of a step of takes constant tree-size, and we assume moreover that only uses output rules (by eventually replacing the right-hand side of each move rule by , where has rank 1), then the output tree of can be viewed both as the derivation tree of the computation of and as the computation tree of , roughly speaking.
Thus, to prove that it suffices to show, for every with and , that can be accepted by a multi-head tt in polynomial time. Let and be tt’s that realize and . For an input tree and an output tree of , will simulate on , generating an intermediate tree , and verify that translates into . Since cannot store its output tree , it must verify the translation of into on the fly, i.e., while generating . That can be done because the context-free grammar is forward deterministic, and hence its reduced version has a unique fixed point: during the generation of the nodes of , can guess the values of the nonterminals of (which are subtrees of ) and check the fixed point equations for them. However, since need not be reduced, we have to be more careful.
Let be a forward deterministic context-free grammar, and let be a symbol not in (which stands for ‘undefined’). A string homomorphism is a fixed point of if (1) , (2) is a substring of for every such that , and (3) for every rule in such that , where is extended to by defining for every . In the special case that is a regular tree grammar, a tree fixed point of is a fixed point of such that for every and is a subtree of for every such that .
Lemma 61
Let be a forward deterministic context-free grammar such that . For every , if and only if there is a fixed point of such that . If is a regular tree grammar, then the same statement holds for and a tree fixed point.
**Proof. **Let , and define to be the unique string generated by , if that exists and is a substring of , and otherwise . It is easy to see that satisfies the requirements.
Let be a fixed point of such that . Then for every sentential form of . Since , this shows that .
Theorem 62
.
**Proof. **Let be a tt, and let be a dtt. We will denote and by and , respectively. Since it is easy to prove (as in the proof of Corollary 38) that , we may assume that is linear-bounded. We may also assume, by Lemma 10 and Theorem 20, that is local. That does not change the linear-boundedness of the composition: if is linear-bounded and \tau^{\prime}_{2}\in\mbox{\sf TT{}_{\mathrm{rel}}}, then is linear-bounded because is size-preserving. Similarly, we may assume that by Corollaries 14 and 21. Finally we assume (as in the proofs of Lemmas 17 and 19) that keeps track in its finite state of the child number of the output node to be generated, through a mapping .
On the basis of Lemma 60, we will describe a multi-head tt that accepts in polynomial time, where . Initially verifies by a regular test that the input tree is of the form with and . We will denote the root of by its label . As mentioned before, on input the transducer simulates on generating an output tree of , which is in the domain of because . It keeps the state of in its finite state, uses one of its heads to point at a node of (which it initially moves to the root of ), and instead of a regular test applies the regular test .161616Note that a node of has the same label and child number in and , except when it has child number 1 in in which case it has child number [math] or in , depending on whether or not its parent in has label .
While generating it guesses a tree fixed point of the regular tree grammar such that . If that fixed point can be guessed, then by Lemma 61, and hence .
Initially, guesses the values under of the configurations in that contain the root of , in linear time. For each the value of is guessed by nondeterministically moving a reading head named to a node of , i.e., node of , meaning that , or to node , meaning that (i.e., that is “undefined”). In particular, the head is moved to the root of , thus guessing that .
Suppose that is going to produce a node of with label , by simulating an output rule of . In such a situation, has already guessed the values under of the configurations in that contain , and also of those that contain the parent of (if it has one). For each the value of is stored using the reading head named , as explained above for , and the value of is stored in a similar way using a reading head named . Now guesses the values of the configurations that contain the children of , in linear time. For every and , the value is guessed by nondeterministically moving a reading head named to some node of or to . Then checks that these values satisfy requirement (3) of a fixed point of as follows, in linear time. If is a move rule of such that head does not point to , then checks that the heads and point to nodes with the same subtree. It can do this using two auxiliary heads that simultaneously perform a depth-first left-to-right traversal of those subtrees. Similarly, if is an output rule of such that head does not point to , then checks that it points to a node with label and that the subtree at the -th child of that node equals the subtree at the head , for every . After checking the fixed point requirement (3), outputs the node and branches in the same way as . In the -th branch (apart from simulating ’s rule in the obvious way) it moves head to the position of head and then moves head to the position of head , for every , in linear time.
This ends the description of . It should be clear that is the set of all pairs such that (because simulates ) and (because computes a tree fixed point of such that ). Hence . It remains to show that accepts in polynomial time.
There is a computation of of length at most that translates into , because if the number of move rules applied between two output rules is more than the number of configurations of on , then there is a loop in the computation that can be removed. Since is linear-bounded, we may assume that the size of is at most linear in the size of . Hence the length of that computation is polynomial in and , and hence in . Since simulates , and each simulated computation step takes linear time (as shown above), accepts in polynomial time.
From Theorem 62 and Lemma 28, which says that \mbox{\sf mrMT{}{\text{{\sc io}}}}\subseteq\mbox{\sf f\,TT{}{\downarrow}}\circ\mbox{\sf dTT}, we obtain the following corollary. Note that is larger than \mbox{\sf f\,TT{}{\downarrow}}\circ\mbox{\sf dTT} in two respects. First, it contains non-finitary translations. Second, it contains total functions for which the height of the output tree can be double exponential in the height of the input tree, viz. in the proof of Proposition 7, whereas that is at most exponential for total functions in \mbox{\sf TT{}{\downarrow}}\circ\mbox{\sf dTT} by Theorem 35, Lemma 24, and the paragraph after Corollary 25.
Corollary 63
\mbox{\sf MT{}{\text{{\sc io}}}}\subseteq\mbox{\sf mrMT{}{\text{{\sc io}}}}\subseteq\mbox{\sf LOGCFL}.
As another corollary we even obtain an upper bound on the complexity of the output languages of dTT that improves the one of Theorem 50. It was proved for attribute grammars in [25].
Corollary 64
.
**Proof. **Let be a regular tree language over and let be in dTT. Let with , and let . The one-state ttℓ with rules for every realizes the translation , and hence by Corollary 21. Let . Then . By Theorem 62 , and hence because is log-space reducible to .
Theorem 62 and Corollary 64 can be extended to deal with the yields of the output trees, as also proved in [25] for attribute grammars (generalizing the proof in [3] of ). For a ranked alphabet we define the mapping such that , the yield of . Let yield be the class of all such mappings . In what follows we will identify each string with the monadic tree as defined in the proof of Corollary 51. Hence, as mentioned in that proof, \mbox{\sf yield}\subseteq\mbox{\sf dTT{}^{\ell}}. This even holds if we assume the existence of special symbols in that are skipped when taking the yield of (such as the symbols in the derivation trees of context-free grammars with -rules, cf. Section 2).
Corollary 65
* and .*
**Proof. **It is straightforward to show that \mbox{\sf yield}\subseteq\mbox{\sf dTT{}_{\mathrm{pru}}}\ast\mbox{\sf yield}. In fact, the deterministic pruning tt removes all nodes of rank 1 and, using regular look-ahead, all subtrees of which the yield is the empty string (due to the special symbols mentioned above). Consequently, as in the proof of Corollary 38, . This allows us to repeat the proof of Theorem 62, this time with respect to the forward deterministic context-free grammar that generates the yields of the trees generated by : if is a rule of , then is a rule of . Thus, this time the mhtt guesses a fixed point of , rather than a tree fixed point. To do this it uses two heads and instead of the one head , to guess the left- and right-end of the substring generated by the configuration , and similarly for and . It should be clear that the fixed point requirement (3) can easily be checked, showing that one such substring equals another one or is the concatenation of several other ones.
The inclusion of Theorem 62 has consequences for both space and time complexity. We first consider space complexity.
Since , we obtain that from Theorem 62. This can easily be generalized to arbitrary compositions of tt’s.
Theorem 66
For every , .
**Proof. **The proof is by induction on , with an induction step similar to the one in the proof of Theorem 47.
Let such that and , . For a given input string it has to be checked whether . By Corollary 38(1) we may assume that is linear-bounded. Hence there is a constant such that for every there is an intermediate tree such that . To check whether a deterministic Turing machine systematically enumerates all trees such that (cf. the proof of Theorem 50). For each such it can check in linear space whether by the case . Moreover, by induction it can check in linear space whether . Thus it uses space .
This result allows us to prove one of our main results, viz. that the output languages of are in , originally proved in [48]. It generalizes the main result of [4] from classical top-down tree transducers to tree-walking tree transducers and macro tree transducers.
Theorem 67
For every ,
[TABLE]
**Proof. **The proof is similar to the one of Theorem 50. Let and . By Corollary 38(1), such that \tau_{1}\in\mbox{\sf TT{}_{\mathrm{pru}}}, , and is linear-bounded for some constant . Let , and note that and that by Lemma 15. It is straightforward to show that for every there exists such that and . To check whether a given tree is in , a deterministic Turing machine enumerates all input trees (of ) such that . For each such it first checks that in space . Then it uses the algorithm of Theorem 66 to check that in space .
The inclusion for is now immediate from Lemma 27.
As before, Theorems 66 and 67 also hold for io (multi-return) macro tree translations, pebble tree translations, and high-level tree translations, which can be realized by compositions of tt’s (see Section 9).
By the proof of Corollary 51, Theorem 67 implies that
[TABLE]
for every . Hence the oi-hierarchy is also contained in , cf. Corollaries 59 and 52.
Corollary 68
For every , .
Next we consider time complexity. Since , it follows from Theorem 62 that . This result can be generalized as follows.
One way to increase the power of the tt is to give it a more powerful feature of look-around. For a class of tree or string languages, we define the tt with look-around by allowing the tt to use node tests such that . Similarly we obtain the mhtt with look-around. We now consider in particular the case where . Obviously, (the proof of) the first sentence of Lemma 60 is still valid for a multi-head tt with PTIME look-around. Thus, the domain of an mhtt with PTIME look-around is in PTIME, and hence, in particular, the domain of a tt with PTIME look-around is in PTIME. This implies that Lemma 19, and hence Theorem 20, also holds if the first transducer has PTIME look-around. From the proof of Theorem 62 it now easily follows that \mbox{\sf TT{}^{\text{P}}}\circ\mbox{\sf dTT}\subseteq\mbox{\sf PTIME}, where the feature of PTIME look-around is indicated by a superscript P. This, in its turn, implies the following variant of Corollary 63 for (multi-return) io macro tree transducers with PTIME look-around (appropriately defined): \mbox{\sf MT{}{\text{{\sc io}}}^{\text{P}}}\subseteq\mbox{\sf mrMT{}{\text{{\sc io}}}^{\text{P}}}\subseteq\mbox{\sf PTIME}. Examples of tree languages in PTIME that can be used as look-around are those in , by Corollary 64, and the tree languages defined by bottom-up tree automata with equality and disequality constraints ([8]), which can obviously be accepted by a multi-head tt.
In the remainder of this section we show that there are translations in , even in \mbox{\sf dTT{}_{\downarrow}}\circ\mbox{\sf TT}, for which the membership problem is NP-complete. We will use a reduction of SAT, the satisfiability problem of boolean formulas (see, e.g., [42]), to such a membership problem.
Let with , , and . Let be the set of all trees over generated by the regular tree grammar with nonterminals and , initial nonterminal , and rules , , , , , and . Thus, is the set of all boolean formulas that use boolean variables of the form for . For a boolean formula we define to be the nesting-depth of its boolean operators, i.e., if is a variable, , and . For every and , let be the set of all formulas such that , and for every that occurs in . Thus, the formulas in have nesting-depth at most and use at most the variables .
The proof of the next lemma is essentially a variant of the one of [74, Theorem 3.1]. Let with and .
Lemma 69
There is a translation \tau\in\mbox{\sf f\,TT{}^{\ell}_{\downarrow}} such that, for every and every string of length , the set consists of all boolean formulas such that is true when the value of is the -th symbol of for every .
**Proof. **We construct the top-down local tt . Note that the initial state is . The boolean operations , , and on are defined as usual, where [math] stands for ‘false’ and for ‘true’. Since the child numbers of the nodes of the input tree will be irrelevant, we omit them from the left-hand sides of the rules of . The only instruction used in the right-hand sides of the rules is . The rules are the following, for every .
[TABLE]
Let be the node of the input tree with label . After consuming , the tt has nondeterministically generated any output form that is a boolean formula of nesting-depth at most and with the two configurations as variables, such that is true when the value of is . For instance, in the first step of that computation consumes and changes the initial output form into one of the output forms , , , , , or , where is the child of . After that, each generates any variable such that the -th symbol of is . Note that since and are not necessarily distinct, has in particular the rule for every . Thus, can nondeterministically choose any occurrence of in to output and end the computation.
Applying the translation of Lemma 69 to the regular tree language consisting of all trees such that and is a nonempty string over , produces the set of all satisfiable formulas in . Thus, since the membership problem for that set is NP-complete, we obtain the following corollary that was proved in [67], as already mentioned after Corollary 59. Note that it is easy to prove that \mbox{\sf f\,TT{}{\downarrow}}(\mbox{\sf REGT})\subseteq y\mbox{\sf f\,TT{}{\downarrow}}(\mbox{\sf REGT}): just change every output rule into the (general) rule where has rank (and now has rank [math]).
Corollary 70
There is an NP-complete language in \mbox{\sf f\,TT{}{\downarrow}}(\mbox{\sf REGT}), and hence there is one in y\mbox{\sf f\,TT{}{\downarrow}}(\mbox{\sf REGT}).
We now prove the existence of a translation in \mbox{\sf dTT{}_{\downarrow}}\circ\mbox{\sf TT} for which the membership problem is NP-complete. Recall that, for a tree translation , we denote by the tree language .
Theorem 71
There is a translation \tau\in\mbox{\sf dTT{}^{\ell}{\downarrow}}\circ\mbox{\sf dTT{}^{\ell}}\circ\mbox{\sf TT{}^{\ell}{\mathrm{pru}}}\subseteq\mbox{\sf dTT{}_{\downarrow}}\circ\mbox{\sf f\,TT} such that is NP-complete.
**Proof. **The inclusion \mbox{\sf dTT{}^{\ell}}\circ\mbox{\sf TT{}^{\ell}{\mathrm{pru}}}\subseteq\mbox{\sf f\,TT} is immediate from Lemma 19. We first describe a translation \tau\in\mbox{\sf dTT{}^{\ell}{\downarrow}}\circ\mbox{\sf f\,TT{}^{\ell}} such that is NP-complete. Let with and . The translation transforms each tree into all satisfiable boolean formulas in . This will be realized by the composition of two tt’s and such that the deterministic tt transforms into a tree of which the path language171717The path language of a tree consists of all strings in that are obtained by walking along a path from the root of to one of its leaves, writing down the labels of the nodes of that path from left to right.
consists of all strings with of length , and nondeterministically chooses a leaf of and then walks back to the root of while simulating the transducer of (the proof of) Lemma 69 on the tree . Thus, provides all possible valuations of the variables and chooses one such valuation and produces all formulas in that are true for that valuation.
Let with , , and . We define where and are the following tt’s. The deterministic tt has the following rules, for and .
[TABLE]
It should be clear that for an input tree , with and , the path language of the tree consists of all strings with of length .
The ttℓ has states and . On an input tree , it walks nondeterministically in state from the root to some leaf (without producing output), moves to the parent of that leaf, and then simulates the transducer of Lemma 69 on the tree while walking back to the root. It starts that simulation in the state of , and then uses the rules of with .
With this definition of and , it follows from Lemma 69 that the set consists of all boolean formulas such that is satisfiable. Thus, for a formula , is satisfiable if and only if is in . This shows that satisfiability is reducible to membership in , because the nesting-depth of and the number of variables it uses, can easily be computed from any in polynomial time.
We finally show that \tau_{M_{2}}\in\mbox{\sf dTT{}^{\ell}}\circ\mbox{\sf TT{}^{\ell}_{\mathrm{pru}}}, by a standard technique (see, e.g., [34, Section 6.1]). In fact, we will show that \tau_{M_{2}}\in\mbox{\sf dTT{}^{\ell}}\circ\mbox{\sf SET}, cf. the proof of Lemma 27. Let be a new symbol of rank 2, and a new symbol of rank 0. Let be the deterministic ttℓ with output alphabet that is obtained from as follows. For every triple such that , , and , if are all the rules of with left-hand side , then has the rule if , the rule if , the rule if , and the rule if . Let be the pruning tt with one state and rules for every , plus the rules and (for every child number ). Since first moves from the root to a leaf, and then moves back to the root, it does not have infinite computations. From that it should be clear that .
Corollary 72
There is a translation such that is NP-complete.
**Proof. **By Lemma 24, \mbox{\sf dTT{}^{\ell}{\downarrow}}\circ\mbox{\sf dTT{}^{\ell}}\subseteq\mbox{\sf dMT}. Moreover, by [34, Theorem 7.6(3)], \mbox{\sf dMT}\circ\mbox{\sf TT{}^{\ell}{\mathrm{pru}}}\subseteq\mbox{\sf MT}. Hence the translation of Theorem 71 is in MT.
Since \mbox{\sf MT}\subseteq\mbox{\sf MT{}^{2}{\text{{\sc io}}}} by [34, Theorem 6.10], this also shows that there is a translation \tau\in\mbox{\sf MT{}^{2}{\text{{\sc io}}}} such that is NP-complete, cf. Corollary 63.
13 Forest Transducers
Whereas we have considered ranked trees until now, i.e., trees over a ranked alphabet, XML documents naturally correspond to unranked trees or forests, over an ordinary unranked alphabet. For that reason we now consider transducers that transform forests into forests. Rather than generalizing the tt to a “forest-walking forest transducer”, we take the equivalent, natural approach of letting the tt transform representations of forests by (ranked) trees, cf. [63] and [28, Section 11].
For an ordinary (unranked) alphabet the set of forests over is the language generated by the context-free grammar with nonterminals and , initial nonterminal , set of terminals , where is the set consisting of the left and right square bracket, and rules , , and for every . Thus, intuitively, a forest is a sequence of unranked trees, and an unranked tree is of the form where each is an unranked tree. Note that every forest can be uniquely written as with and .
As usual, forests can be encoded as binary trees. With we associate the ranked alphabet where has rank 0 and every has rank 2. The mapping is defined as follows. The encoding of the empty forest is , and recursively, the encoding of a forest is . The mapping is a bijection, and the inverse decoding is denoted by . Let enc and dec denote the classes of encodings and decodings , respectively, for all alphabets . We define to be the class of tt forest translations. Thus, a tt forest translation is of the form where and are alphabets and is a tt with input alphabet and output alphabet , which in this context can be called a tt forest transducer. We first restrict attention to deterministic tt forest transducers, i.e., to the class .
The next simple lemma shows that the encodings of compositions are the compositions of encodings (of deterministic tt’s).
Lemma 73
For every , .
**Proof. **The inclusion is obvious, because is the identity on for every (unranked) alphabet . To show that , it suffices to prove that . Let be the (ranked) output alphabet of a first transducer, which is also the input alphabet of the second, and let be the identity on . By the composition results of Theorems 18 and 23, it now suffices to show that \mathrm{id}_{\Gamma}\in\mbox{\sf dTT{}^{\ell}{\downarrow}}\circ\mbox{\sf dec}\circ\mbox{\sf enc}\circ\mbox{\sf dTT{}^{\ell}{\mathrm{su}}}. We do this by encoding the trees over as binary trees, similar to the transformation of the derivation trees of a context-free grammar into those of its Chomsky Normal Form. Let be a new symbol, and let be the unranked alphabet . We encode the trees over as trees over the ranked alphabet , which are the usual encodings of forests over . The encoding is defined as follows: for every , if for every , then . It should be clear that is an injection. It should also be clear that h\in\mbox{\sf dTT{}^{\ell}_{\downarrow}} (in fact, is a tree homomorphism, which can be realized by a classical top-down tree transducer). Finally, it is also easy to construct a local top-down single-use tt such that for every . It has the set of states with initial state , and the following rules (where , , and , ):
[TABLE]
Note that and have rank 2 in .
We now wish to show that our main results also hold for deterministic tt forest translations. Let us first consider the complexity results of Section 10. It is easy to see that for every alphabet , the mappings and can be computed by a deterministic Turing machine in linear time and space, simulating a one-way pushdown transducer.181818In fact, can even be computed without pushdown: for every forest , can be obtained from by removing all left-brackets, changing each right-bracket into , and adding one at the end.
This implies, by Lemma 73, that Theorems 47 and 49 also hold for . We define a set of forests to be a regular forest language if , and we denote the class of regular forest languages by REGF. Then, for every , the class of output forest languages is included in the class by Lemma 73. Let and with output alphabet . Then a forest over is in if and only if is in . That implies that Theorem 50 also holds for , in the sense that .
Next we consider the results of Section 9, and extend the class LSIF in the obvious way to forest translations. Since it is easy to show that for every forest , we have (see footnote 18), a translation is of linear size increase if and only if is of linear size increase. Thus, since by Lemma 73, it is decidable for a given composition of deterministic tt forest transducers whether or not it is of linear size increase. And if so, an equivalent deterministic tt forest transducer can be constructed: \mbox{\sf dFT}^{k}\cap\mbox{\sf LSIF}=\mbox{\sf enc}\circ(\mbox{\sf dTT}^{k}\cap\mbox{\sf LSIF})\circ\mbox{\sf dec}=\mbox{\sf enc}\circ\mbox{\sf dTT{}{\mathrm{su}}}\circ\mbox{\sf dec}\subseteq\mbox{\sf dFT}. Intuitively, \mbox{\sf enc}\circ\mbox{\sf dTT{}{\mathrm{su}}}\circ\mbox{\sf dec} is the class of translations realized by “single-use forest-walking forest transducers”. Since \mbox{\sf dTT{}_{\mathrm{su}}}=\mbox{\sf dMSOT} by Proposition 29, it is also the class . Viewing forests as graphs, and hence as logical structures, in the obvious way (just as trees), every encoding and every decoding is a deterministic (i.e., parameterless) mso translation, as defined in [14, Chapter 7]. Hence, by the closure of mso translations under composition [14, Theorem 7.14], equals the (natural) class of deterministic mso translations from forests to forests.
As observed in [65] for macro tree transducers, whereas the encoding of forests as binary trees is quite natural for the input forest of a tt, for the output forest it is less natural, because it forces the tt to generate the output forest in its unique form . It is more natural to additionally allow the tt to generate as a concatenation of two forests and . To formalize this, as in [26, Section 7] and in accordance with [65], we associate with an alphabet the ranked alphabet where has rank 2, has rank 0, and every has rank 1. The mapping is a “flattening” defined as follows (for and ): , , the concatenation of and , and . The mapping is surjective but, in general, not injective. Let flat denote the class of flattenings , for all alphabets . We define to be the class of extended tt forest translations. An extended tt forest tree transducer is a tt with input alphabet and output alphabet . Again, we first restrict attention to deterministic transducers, i.e., to the class .
Let us show that there is an extended tt forest translation in that is not in dFT. That was shown for macro tree transducers in [65, Theorem 8] by a similar argument. Let and be alphabets, and let us identify the forest with the symbol , and similarly with . Then and . There is a deterministic extended tt forest transducer that translates the string into the string for every . In fact, let be the dtt (with general rules) that is obtained from the dtt of Example 5 by changing its output alphabet into , and changing into and into in the right-hand sides of its rules. Note that the input alphabet of and equals . The input tree is translated by into the full binary tree over with leaves. Clearly, translates into the tree that is obtained from by changing every into and every into . Thus, . This forest translation is not in dFT, because but the height of is , and so, by Lemma 6, there is no dtt that translates into .
We will show that . A similar result was proved for macro tree transducers in [65, Theorem 8 and Corollary 12]. To compare dFT and , and their compositions, we establish two relationships between dec and flat in the next lemma.
Lemma 74
\mbox{\sf dec}\subseteq\mbox{\sf dTT{}^{\ell}{\downarrow}}\circ\mbox{\sf flat}* and \mbox{\sf flat}\subseteq\mbox{\sf dTT{}^{\ell}{\mathrm{su}}}\circ\mbox{\sf dec}.*
**Proof. **To show the first inclusion, let be an alphabet and define the mapping such that and if and , then . It is straightforward to prove that . It is also easy to show that h\in\mbox{\sf dTT{}^{\ell}{\downarrow}} (as in the proof of Lemma 73, is a tree homomorphism, which can be realized by a classical top-down tree transducer). Hence {\rm dec}_{\Delta}\in\mbox{\sf dTT{}^{\ell}{\downarrow}}\circ\mbox{\sf flat}.
For the second inclusion, let be an alphabet. The mapping can be realized by a local single-use dtt that performs a depth-first left-to-right tree traversal in a special way. Rather than performing this traversal in one branch, it does so in all its branches together, each branch performing a separate piece of the traversal. When arrives from above at a node with label , it outputs and splits into two branches. The first branch traverses the subtree at , and the second branch continues the traversal after that subtree. Each branch outputs when arriving from below at a -labeled node (or at the root, at the end of the traversal). Formally, has the state set with initial state , cf. Examples 4 and 5. It has the following (general) rules, where , , and :
[TABLE]
Thus, since , it follows that {\rm flat}_{\Delta}=\tau_{M}\circ{\rm dec}_{\Delta}\in\mbox{\sf dTT{}^{\ell}_{\mathrm{su}}}\circ\mbox{\sf dec}.
We note that the mapping is denoted ‘eval’ in [65, Section 4], ‘APP’ in [61], and ‘app’ in [26, Section 7]. For the reader familiar with mso translations we observe that it is also easy to show that both and are deterministic mso translations, and hence their composition is one. The second inclusion then follows from Proposition 29.
It follows from the first inclusion of Lemma 74 that . In fact, \mbox{\sf enc}\circ\mbox{\sf dTT}\circ\mbox{\sf dec}\subseteq\mbox{\sf enc}\circ\mbox{\sf dTT}\circ\mbox{\sf dTT{}^{\ell}{\downarrow}}\circ\mbox{\sf flat}, which is included in by Theorem 18. It follows from the second inclusion that for every . In fact, \mbox{\sf dFT}_{@}^{k}=(\mbox{\sf enc}\circ\mbox{\sf dTT}\circ\mbox{\sf flat})^{k}\subseteq(\mbox{\sf enc}\circ\mbox{\sf dTT}\circ\mbox{\sf dTT{}^{\ell}{\mathrm{su}}}\circ\mbox{\sf dec})^{k}\subseteq\mbox{\sf enc}\circ(\mbox{\sf dTT}\circ\mbox{\sf dTT{}^{\ell}{\mathrm{su}}})^{k}\circ\mbox{\sf dec}, which is included in \mbox{\sf enc}\circ\mbox{\sf dTT}^{k}\circ\mbox{\sf dTT{}^{\ell}{\mathrm{su}}}\circ\mbox{\sf dec} by Theorem 23 and hence in , which equals by Lemma 73.
Corollary 75
* for every .*
From the second inclusion we obtain that our main results also hold for deterministic extended tt forest transducers. It is decidable whether or not a composition of such transducers is of linear size increase, and
[TABLE]
The complexity results of Theorems 47, 49, and 50 also hold for .
The class of deterministic macro forest translations of [65] can be defined as . Since by Lemma 24, we conclude by similar arguments as for that and hence our main results also hold for deterministic macro forest transducers. It is decidable whether or not a composition of such transducers is of linear size increase, and
[TABLE]
The complexity results of Theorems 47, 49, and 50 also hold for .
The main results of Sections 9 and 11 also hold for nondeterministic forest transducers. Instead of Lemma 73 we use the obvious fact that .191919It can be shown that the nondeterministic version of Lemma 73 also holds, but we will not do that here.
This implies, together with Lemma 74, that it suffices to prove that the results for also hold for the class . For the nondeterministic version of Theorem 43 in Section 9, we note that a translation is a function if and only if is a function. Consequently, by Theorem 35 and Lemma 73. Hence (\mbox{\sf enc}\circ\mbox{\sf TT}^{k}\circ\mbox{\sf dec})\cap\mbox{\sf LSIF}=\mbox{\sf enc}\circ\mbox{\sf dTT{}_{\mathrm{su}}}\circ\mbox{\sf dec}. Obviously, the complexity results of Theorems 57 and 58 in Section 11 hold for , with the same proof as in the deterministic case. The class of nondeterministic macro forest translations of [65] can be defined as . From Lemmas 27 and 74 we obtain that , and hence all these results also hold for macro forest transducers.
We finally show that the results of Section 12 also hold for nondeterministic forest transducers. We first consider and . For a forest translation we define the forest language . If with , then if and only if . Since can be computed by a deterministic finite-state transducer (see footnote 18), and similarly for , is log-space reducible to . Hence by Theorem 62. Similarly if , then if and only if for every , and hence by Corollary 64. To show the same results for flat instead of dec, we need the following small lemma.
Lemma 76
\mbox{\sf flat}\subseteq\mbox{\sf dTT{}_{\downarrow}}\circ\mbox{\sf yield}.
**Proof. **For an alphabet , let be the ranked alphabet such that , , and . We define the deterministic tt with the following (general) rules.
[TABLE]
for every . Assuming that the symbol is skipped when taking yields (cf. the sentence before Corollary 65), it should be clear that is the yield of for every .
It follows from Lemma 76 and Theorem 18 that and . If is a forest translation such that with , then if and only if . Hence by Corollary 65. Similarly if , then for every , and so by Corollary 65. If we define the class of io macro forest translations to be , then that class is included in by Lemma 28 and hence in LOGCFL by the above. Thus, Corollary 63 also holds for macro forest transducers.
For a forest translation with it is easy to prove that and that for every , as we did above for and , respectively, thus generalizing Theorems 66 and 67. That also holds for instead of , because by Lemma 74.
The NP-completeness results of Section 12 also hold for extended forest translations. The translation of Theorem 71 can be changed into a translation in \mbox{\sf enc}\circ\mbox{\sf dTT{}{\downarrow}}\circ\mbox{\sf f\,TT}\circ\mbox{\sf flat} as follows. First, change in the proof of Theorem 71 such that it obtains as input the encodings of the strings (viewed as forests). Second, change such that it outputs trees over rather than (by changing the rule of in the proof of Lemma 69 into the general rule , and similarly for ). As a result outputs boolean expressions as forests rather than ranked trees. Thus we obtain an NP-complete extended forest translation in \mbox{\sf enc}\circ\mbox{\sf dTT{}{\downarrow}}\circ\mbox{\sf f\,TT}\circ\mbox{\sf flat}, and hence one in . In a similar way we also obtain an NP-complete forest language in . The details are left to the reader. It is not clear whether these results hold for dec instead of flat.
14 Conclusion
Our main technical result transforms a composition of tt’s into a linear-bounded composition of tt’s, cf. Corollary 38. As observed in Remark 41, our proof of this result can involve a -fold blow-up of the sizes of the transducers, which also influences the constants of their time and space complexities, cf. the sentence after Theorem 47. We do not know whether this transformation can be realized in a more efficient way.
Our main result on expressivity is that for every , i.e., that every composition of dtt’s that is of linear size increase can be realized by one dtt. Moreover, it is decidable whether or not such a composition is of linear size increase. Do similar results hold for polynomial size increase? For instance, does there exist such that every translation in of quadratic size increase is in ? The same question can be asked for -fold exponential size increase, for each fixed .
We have shown in Section 7 that even for every , generalizing Theorem 43. Although this result is effective, we do not know whether Theorem 44 can also be generalized, i.e., whether it is decidable for a nondeterministic tt whether or not is a function of linear size increase. This would be solved if it was decidable whether or not is a function. But that is also unknown, whereas it has been proved for classical top-down tree transducers (with regular look-ahead) in [36, Theorem 8]. Note that deciding functionality of also solves the equivalence problem for dtt’s, which is already a long standing open problem (cf. [22, 60]); in fact, are the same if and only if they have the same domain and is functional.
Another open question for nondeterministic tt’s is whether or not there exists such that the inclusion holds for every , where LSIR consists of all relations of linear size increase, which means that there is a constant such that for every . It follows from (the proof of) [48, Theorem 3.21] (see also [49, 50]) that is not included in MT, and hence not in TT by the remark following Lemma 27.
Similar questions can be asked for macro tree transducers, i.e., for the classes dMT and MT.
We have shown in Lemma 12 that \mbox{\sf dTT{}{\downarrow}}=\mbox{\sf dTT{}^{\hskip 1.13791pt\mathrm{s}}{\downarrow}}, but we do not know whether or not \mbox{\sf dTT}=\mbox{\sf dTT{}^{\hskip 1.13791pt\mathrm{s}}}. In other words, we do not know whether for every tt there is an equivalent sub-testing tt, in which the regular test of a rule only inspects the subtree of the current node. Or even more informally, can regular look-around be simulated by regular look-ahead?
We have shown in Corollary 59 that the string languages in the oi-hierarchy, which are generated by high-level grammars, are in , and in Corollary 68 that they are in . However, the languages of the oi-hierarchy are generated by so-called “safe” high-level grammars, and it is not known whether the same results hold for unsafe high-level grammars. It is proved in [54] that the languages generated by unsafe level-2 grammars, the unsafe version of , are in .
In Section 12 we have shown that , that , and that contains an NP-complete translation. It remains to find out for whether or whether it contains an NP-complete translation.
Acknowledgements. We are grateful to the reviewers for their constructive comments.
The reference list from the paper itself. Each links out to its DOI / PubMed record.
- 1[1] Aho AV (1968) Indexed grammars - an extension of context-free grammars. Journal of the ACM 15: 647–671
- 2[2] Aho AV, Ullman JD (1971) Translations on a context-free grammar. Information and Control 19: 439–475
- 3[3] Asveld PRJ (1981) Time and space complexity of inside-out macro languages. International Journal of Computer Mathematics 10: 3–14
- 4[4] Baker BS (1978) Generalized syntax-directed translation, tree transducers, and linear space. SIAM Journal on Computing 7: 376–391
- 5[5] Bartha M (1982) An algebraic definition of attributed transformations. Acta Cybernetica 5: 409–421
- 6[6] Bloem R, Engelfriet J (1997) Monadic second order logic and node relations on graphs and trees. In: Mycielski J, Rozenberg G, Salomaa A (eds) Structures in Logic and Computer Science . Lecture Notes in Computer Science 1261, Springer-Verlag, pp 144–161. A corrected version is available at https://www.researchgate.net/publication/221350026
- 7[7] Bloem R, Engelfriet J (2000) A comparison of tree translations defined by monadic second order logic and by attribute grammars. Journal of Computer and System Sciences 61: 1–50
- 8[8] Bogaert B, Tison S (1992) Equality and disequality constraints on direct subterms in tree automata. In: Finkel A, Jantzen M (eds) Proc. STACS’92, Lecture Notes in Computer Science 577, Springer-Verlag, pp 161–171
