Deciding Equivalence of Separated Non-Nested Attribute Systems in Polynomial Time

In 1982, Courcelle and Franchi-Zannettacci showed that the equivalence problem of separated non-nested attribute systems can be reduced to the equivalence problem of total deterministic separated basic macro tree transducers. They also gave a procedure for deciding equivalence of transducer in the latter class. Here, we reconsider this equivalence problem. We present a new alternative decision procedure and prove that it runs in polynomial time. We also consider extensions of this result to partial transducers and to the case where parameters of transducers accumulate strings instead of trees.


Introduction
Attribute grammars are a well-established formalism for realizing computations on syntax trees [21,22], and implementations are available for various programming languages, see, e.g. [30,29,13]. A fundamental question for any such specification formalism is whether two specifications are semantically equivalent. As a particular case, attribute grammars have been considered which compute uninterpreted trees. Such devices that translate input trees (viz. the parse trees of a context-free grammar) into output trees, have also been studied under the name "attributed tree transducer" [15] (see also [16]). In 1982, Courcelle and Franchi-Zannettacci showed that the equivalence problem for (strongly noncircular) attribute systems reduces to the equivalence problem for primitive recursive schemes with parameters [3,4]; the latter model is also known under the name macro tree transducer [10]. Whether or not equivalence of attributed tree transducers (ATTs) or of (deterministic) macro tree transducers (MTTs) is decidable remain two intriguing (and very difficult) open problems.
For several subclasses of ATTs it has been proven that equivalence is decidable. The most general and very recent result that covers almost all other known ones about deterministic tree transducers is that "deterministic top-down tree-to-string transducers" have decidable equivalence [28]. Notice that the complexity of this problem remains unknown (the decidability is proved via two semi-decision procedures). The only result concerning deterministic tree transducers that we are aware of and that is not covered by this general result, is In a separated non-nested attribute system, distinct sets of operators are used for the construction of inherited and synthesized attributes, respectively, and inherited attributes may depend on inherited attributes only. Courcelle and Franchi-Zannettacci's algorithm first translates separated non-nested attribute grammars into separated total deterministic non-nested macro tree transducers. In the sequel we will use the more established term basic macro-tree transducers instead of non-nested MTTs. Here, a macro tree transducer is called separated if the alphabets used for the construction of parameter values and outside of parameter positions are disjoint. And the MTT is basic if there is no nesting of state calls, i.e., there are no state calls inside of parameter positions. Let us consider an example. We want to translate ternary numbers into expressions over +, * , EXP, plus the constants 0, 1, and 2. Additionally, operators s, p, and z are used to represent integers in unary. The ternary numbers are parsed into particular binary trees; e.g., the left of Figure 1 shows the binary tree for the number 2101.02. This tree is translated by our MTT into the tree in the right of Figure 1 (which indeed evaluates to 64.2 in decimal). The rules of our transducer M tern are shown in Figure 2. The example is similar to the one used by Knuth [21] q0(g(x1, x2)) → +(q(x1, z), q ′ (x2, p(z))) q(f (x1, x2), y) → +(r(x2, y), q(x1, s(y))) q ′ (f (x1, x2), y) → +(r(x1, y), q ′ (x2, p(y))) φ(i, y) → * (i, EXP(3, y)) for i ∈ {0, 1, 2}, φ ∈ {q, q ′ , r} in order to introduce attribute grammars. The transducer is indeed basic and separated: the operators p, s, and z are only used in parameter positions. Our polynomial time decision procedure works in two phases: first, the transducer is converted into an "earliest" normal form. In this form, output symbols that are not produced within parameter positions are produced as early as possible. In particular it means that the root output symbols of the right-hand sides of rules for one state must differ. For instance, our transducer M tern is not earliest, because all three r-rules produce the same output root symbol ( * ). Intuitively, this symbol should be produced earlier, e.g., at the place when the state r is called. The earliest form is a common technique used for normal forms and equivalence testing of different kinds of tree transducers [9,14,23]. We show that equivalent states of a transducer in this earliest form produce their state-output exactly in the same way. This means especially that the output of parameters is produced in the same places. It is therefore left to check, in the second phase, that also these parameter outputs are equivalent. To this end, we build an equivalence relation on states of earliest transducers that combines the two equivalence tests described before. Technically speaking, the equivalence relation is tested by constructing sets of Herbrand equalities. From these equalities, a fixed point algorithm can, after polynomially many iterations, produce a stable set of equalities.
An abridged version of this paper will be published within FoSSaCS 2019.

Separated Basic Macro Tree Transducers
Let Σ be a ranked alphabet, i.e., every symbol of the finite set Σ has associated with it a fixed rank k ∈ N. Generally, we assume that the input alphabet Σ is non-trivial, i.e., Σ has cardinality at least 2, and contains at least one symbol of rank 0 and at least one symbol of rank > 0. The set T Σ is the set of all (finite, ordered, rooted) trees over the alphabet Σ. We denote a tree as a string over Σ and parenthesis and commas, i.e., f (a, f (a, b)) is a tree over Σ, where f is of rank 2 and a, b are of rank zero. We use Dewey dotted decimal notation to refer to a node of a tree: The root node is denoted ε, and for a node u, its i-th child is denoted by u.i. For instance, in the tree f (a, f (a, b)) the b-node is at position 2.2. A pattern (or k-pattern) (over ∆) is a tree p ∈ T ∆∪{⊤} over a ranked alphabet ∆ and a disjoint symbol ⊤ (with exactly k occurrences of the symbol ⊤). The occurrences of the dedicated symbol ⊤ serve as place holders for other patterns. Assume that p is a k-pattern and that p 1 , . . . , p k are patterns; then p[p 1 , . . . , p k ] denotes the pattern obtained from p by replacing, for i = 1, . . . , k, the i-th occurrence (from left-to-right) of ⊤ by the pattern p i . A macro tree transducer (MTT ) M is a tuple (Q, Σ, ∆, δ) where Q is a ranked alphabet of states, Σ and ∆ are the ranked input and output alphabets, respectively, and δ is a finite set of rules of the form: where q ∈ Q is a state of rank l + 1, l ≥ 0, f ∈ Σ is an input symbol of rank k ≥ 0, x 1 , . . . , x k and y 1 , . . . , y l are the formal input and output parameters, respectively, and T is a tree built up according to the following grammar: for output symbols a ∈ ∆ of rank m ≥ 0 and states q ′ ∈ Q of rank n + 1, input parameter x i with 1 ≤ i ≤ k, and output parameter y j with 1 ≤ j ≤ l. For simplicity, we assume that all states q have the same number l of parameters. Our definition of an MTT does not contain an initial state. We therefore consider an MTT always together with an axiom . . , T m ∈ T l ∆ are vectors of output trees (of length l each). Sometimes we only use an MTT M without explicitly mentioning an axiom A, then some A is assumed implicitly. Intuitively, the state q of an MTT corresponds to a function in a functional language which is defined through pattern matching over its first argument, and which constructs tree output using tree top-concatenation only; the second to (l + 1)-th arguments of state q are its accumulating output parameters. The output produced by a state for a given input tree is determined by the right-hand side T of a rule of the transducer which matches the root symbol f of the current input tree. This right-hand side is built up from accumulating output parameters and calls to states for subtrees of the input and applications of output symbols from ∆. In general MTTs are nondeterministic and only partially defined. Here, however, we concentrate on total deterministic transducers. The MTT M is deterministic, if for every (q, f ) ∈ Q × Σ there is at most one rule of the form (1). The MTT M is total, if for every (q, f ) ∈ Q × Σ there is at least one rule of the form (1). For total deterministic transducers, the semantics of a state q ∈ Q with the rule q(f (x 1 , . . . , x k ), y 1 , . . . , y l ) → T can be considered as a function q : where S = (S 1 , . . . , S l ) ∈ T l ∆ is a vector of output trees. The semantics of a pair (M, A) with MTT M and axiom A = p[q 1 The MTT M is basic, if each argument tree T j of a subtree q ′ (x i , T 1 , . . . , T n ) of right-hand sides T of rules (1) may not contain further occurrences of states, i.e., is in T ∆∪Y . The MTT M is separated basic, if M is basic, and ∆ is the disjoint union of ranked alphabets ∆ out and ∆ in so that the argument trees T j of subtrees q ′ (x i , T 1 , . . . , T n ) are in T ∆in∪Y , while the output symbols a outside of such subtrees are from ∆ out . The same must hold for the axiom. Thus, letters directly produced by a state call are in ∆ out while letters produced in the parameters are in ∆ in . The MTT M tern from the Introduction is separated basic with ∆ out = {0, 1, 2, 3, * , +, EXP} and ∆ in = {p, s, z}.
As separated basic MTTs are in the focus of our interests, we make the grammar for their right-hand side trees T explicit: where a ∈ ∆ out , q ′ ∈ Q, b ∈ ∆ in of ranks m, n + 1 and m ′ , respectively, and p is an n-pattern over ∆. For separated basic MTTs only axioms . . , T m ∈ T l ∆in are considered. Note that equivalence of nondeterministic transducers is undecidable (even already for very small subclasses of transductions [19]). Therefore, we assume for the rest of the paper that all MTTs are deterministic and separated basic. We will also assume that all MTTs are total, with the exception of Section 5 where we also consider partial MTTs. Example 1. We reconsider the example from the Introduction and adjust it to our formal definition. The transducer was given without an axiom (but with a tacitly assumed "start state" q 0 ). Let us now remove the state q 0 and add the axiom A = q(x 1 , z). The new q rule for g is: To make the transducer total, we add for state q ′ the rule We restricted ourselves to total separated basic MTTs. However, we would like to be able to decide equivalence for partial transducers as well. For this reason we define now top-down tree automata, and will then decide equivalence of MTTs relative to some given DTA D. A deterministic top-down tree automaton (DTA) D is a tuple (B, Σ, b 0 , δ D ) where B is a finite set of states, Σ is a ranked alphabet of input symbols, b 0 ∈ B is the initial state, and δ D is the partial transition function with rules of the form we always assume that all states b of a DTA are productive, i.e., dom(b) = ∅. If we consider a MTT M relative to a DTA D we implicitly assume a mapping π : Q → B, that maps each state of M to a state of D, then we consider for q only input trees in dom(π(q)).

Top-Down Normalization of Transducers
In this section we show that each total deterministic basic separated MTT can be put into an "earliest" normal form relative to a fixed DTA D. Intuitively, state output (in ∆ out ) is produced as early as possible for a transducer in the normal form. It can then be shown that two equivalent transducers in normal form produce their state output in exactly the same way.
Recall the definition of patterns as trees over T ∆∪{⊤} . Substitution of ⊤symbols by other patterns induces a partial ordering ⊑ over patterns by p ⊑ p ′ if and only if p = p ′ [p 1 , . . . , p m ] for some patterns p 1 , . . . , p m . W.r.t. this ordering, ⊤ is the largest element, while all patterns without occurrences of ⊤ are minimal. By adding an artificial least element ⊥, the resulting partial ordering is in fact a complete lattice. Let us denote this complete lattice by P ∆ .
By this definition, each tree t ∈ T ∆∪Y can be uniquely decomposed into a ∆ outprefix p and subtrees t 1 , . . . , t m whose root symbols all are contained in Let M be a total separated basic MTT M , D be a given DTA. We define the ∆ out -prefix of a state q of M relative to D as the minimal pattern p ∈ T ∆out∪{⊤} so that each tree q (t, T ), t ∈ dom(π(q)), T ∈ T l ∆ , is of the form p[T 1 , . . . , T m ] for some sequence of subtrees T 1 , . . . , T m ∈ T ∆ . Let us denote this unique pattern p by pref o (q). If q(f, y 1 , . . . , y l ) → T is a rule of a separated basic MTT and there is an input tree f (t 1 , . . . , t k ) ∈ dom(π(q)) then |pref o (q)| ≤ |T |.

Lemma 1. Let M be a total separated basic MTT and D a given DTA. Let
The proof is similar to the one of [9, Theorem 8] for top-down tree transducers. This construction can be carried over as, for the computation of ∆ out -prefixes, the precise contents of the output parameters y j can be ignored. The complete proof can be found in the Appendix.

Example 2.
We compute the ∆ out -prefix of the MTT M from Example 1. We consider M relative to the trivial DTA D that consists only of one state b with dom(b) = T Σ . We therefore omit D in our example. We get the following system of in-equations: from the rules of state r we obtain The construction follows the same line as the one for the earliest form of top-down tree transducer, cf. [9,Theorem 11]. The proof can be found in the appendix. Note that for partial separated basic MTTs the size of the ∆ out -prefixes is at most exponential in the size of the transducer. However for total transducer that we consider here the ∆ out -prefixes are linear in the size of the transducer and can be computed in quadratic time, cf. [9]. Example 3. We construct an equivalent earliest MTT M ′ for the transducer from Example 1. In Example 2 we already computed the ∆ out -prefixes of states q, q ′ , r; pref o (q) = ⊤, pref o (q ′ ) = ⊤ and pref o (r) = * (⊤, EXP(3, ⊤)). As there is only one occurrence of symbol ⊤ in the ∆ out -prefixes of q and q ′ we call states q, 1 and q ′ , 1 by q and q ′ , respectively. Hence, a corresponding earliest transducer has axiom A = q(x 1 , z). The rules of q and q ′ for input symbol g do not change.
As there is only one occurrence of symbol ⊤ related to a recursive call in pref o (r) we call r, 1 by r. For state r we obtain new rules r(α(x 1 , x 2 ), y) → 0 with α ∈ {f, g} and r(i, y) → i with i ∈ {0, 1, 2}.
⊓ ⊔ We define a family of equivalence relation by induction, ∼ =b ⊆ ((Q, T k ∆in ) ∪ T ∆in ) × ((Q, T k ∆in ) ∪ T ∆in ) with b a state of a given DTA is the intersection of the equivalence relations ∼ = . . . , b k ), there is a pattern p such that q (f (x 1 , . . . , x k ), y) → p[t 1 , . . . , t m ] and q ′ (f (x 1 , . . . , x k ) if t i and t ′ i are both recursive calls to the same subtree, i.e., Intuitively, (q,  and let u i be the position of the i-th ⊤-node in the pattern p. For some t ∈ dom(b) and T ∈ T ∆in let t i and t ′ i be the subtree of (M, A) (t, T ) and (M ′ , A ′ ) (t, T ), respectively. Then t i = t ′ i and therefore (q i ,

Now, assume that the axioms
consist of the same pattern p and for i = 1, . . . , m,

Polynomial Time
In this section we prove the main result of this paper, namely, that for each fixed DTA D, equivalence of total deterministic basic separated MTTs (relative to D) can be decided in polynomial time. This is achieved by taking as input two D-earliest such transducers, and then collecting conditions on the parameters of pairs of states of the respective transducers for their produced outputs to be equal.

Example 4. Consider a DTA D with a single state only which accepts all inputs, and states
Then q and q ′ can only produce identical outputs for the input a (in dom(b)) if parameter y ′ 2 of q ′ contains the same output tree as parameter y 1 of q. This precondition can be formalized by the equality y ′ 2 . = y 1 . Note that in order to distinguish the output parameters of q ′ from those of q we have used primed copies y ′ i for q ′ . ⊓ ⊔ It turns out that conjunctions of equalities such as in example 4 are sufficient for proving equivalence of states. For states q, q ′ of total separated basic MTTs M, M ′ , respectively, that are both D-earliest for some fixed DTA D, h ≥ 0 and some fresh variable z, we define where ⊥ is the boolean value false. We denote the output parameters in Ψ b,q (z) but using y ′ for the output parameters. To substitute the output parameters with trees T , T ′ , we therefore use Ψ b,q (z) is true for all ground parameter values s and some T ∈ T ∆∪Y if q (t, s) = T [s/y] for all input trees t ∈ dom(b) of height at most h. Note that, since M is D-earliest, T is necessarily in T ∆in∪Y . W.l.o.g., we assume that every state b of D is productive, i.e., dom(b) = ∅. For each state b of D, we therefore may choose some input tree t b ∈ dom(b) of minimal depth. We define s b,q to be the output of q for a minimal input tree t r ∈ dom(b) and parameter values y -when considering formal output parameters as output symbols in ∆ in , i.e., s b,q = q (t r , y).

Example 5.
We consider again the trivial DTA D with only one state b that accepts all t ∈ T Σ . Thus, we may choose t b = a. For a state q with the following two rules q(a, y 1 , y 2 ) → y 1 and q(f (x), y 1 , y 2 ) → q(x, h(y 2 ), b), we have s b,q = y 1 . Moreover, we obtain We observe that Ψ b,q (z) and therefore for every h ≥ 2, Ψ ⊓ ⊔ According to our equivalence relation ∼ =b, b state of the DTA D, we define for states q, q ′ of D-earliest total deterministic separated basic MTTs M, M ′ , and is defined in the same lines as the equivalence relation ∼ = is true for all values of output parameters T , T ′ such that q (t, T ) = q ′ (t, T ′ ) for t ∈ dom(b) of height at most h. By induction on h ≥ 0, we obtain: Every satisfiable conjunction of equalities is equivalent to a (possible empty) finite conjunction of equations of the form y i . = t i , t i ∈ T ∆in∪Y where the y i are distinct and no equation is of the form y j . = y j . We call such conjunctions reduced. If we have two inequivalent reduced conjunctions φ 1 and φ 2 with φ 1 ⇒ φ 2 then φ 1 contains strictly more equations. From that follows that for every sequence φ 0 ⇒ . . . φ m of pairwise inequivalent reduced conjunctions φ j with k variables, m ≤ k + 1 holds. This observation is crucial for the termination of the fixpoint iteration we will use to compute Φ For h ≥ 0 we have: As we fixed the number of output parameters to the number l, for each pair (q, q ′ ) the conjunction Φ (h) b,(q,q ′ ) contains at most 2l variables y i , y ′ i . Assuming that the MTTs to which state q and q ′ belong have n states each, we conclude that Φ Therefore, we have: Proof. We successively compute the conjunctions Ψ , h ≥ 0, for all states b, q, q ′ . As discussed before, some h ≤ n 2 (2l + 1) exists such that the conjunctions for h + 1 are equivalent to the corresponding conjunctions for h -in which case, we terminate. It remains to prove that the conjunctions for h can be computed from the conjunctions for h − 1 in polynomial time. For that, it is crucial that we maintain reduced conjunctions. Nonetheless, the sizes of occurring right-hand sides of equalities may be quite large. Consider for example the conjunction . The corresponding reduced conjunction is then given by . . (f (a, a)) . . .) where the sizes of right-hand sides grow exponentially. In order to arrive at a polynomial-size representation, we therefore rely on compact representations where isomorphic subtrees are represented only once. W.r.t. this representation, reduction of a non-reduced conjunction, implications between reduced conjunctions as well as substitution of variables in conjunctions can all be realized in polynomial time. From that, the assertion of the lemma follows.
Example 6. Let D be a DTA with the following rules b(f (x)) → (b), b(g) → () and b(h) → (). Let q and q ′ be states of separated basic MTTs M , M ′ , respectively, that are D-earliest and π, π ′ be the mappings from the states of D to the states of M , (q(x, b(y 1 , y 1 In summary, we obtain the main theorem of our paper.
is equivalent to true. By Lemma 4 we can decide the second statements in time polynomial in the sizes of M 1 and M ′ 1 .

Applications
In this section we show several applications of our equivalence result. First, we consider partial transductions of separated basic MTTs. To decide the equivalence of partial transductions we need to decide a) whether the domain of two given MTTs is the same and if so, b) whether the transductions on this domain are the same. How the second part of the decision procedure is done was shown in detail in this paper if the domain is given by a DTA. It therefore remains to discuss how this DTA can be obtained. It was shown in [5, Theorem 3.1] that the domain of every top-down tree transducer T can be accepted by some DTA B T and this automaton can be constructed from T in exponential time. This construction can easily be extended to basic MTTs. The decidability of equivalence of DTAs is well-known and can be done in polynomial time [17,18]. To obtain a total transducer we add for each pair (q, f ), q ∈ Q and f ∈ Σ that has no rule a new rule q(f (x), y) → ⊥, where ⊥ is an arbitrary symbol in ∆ out of rank zero.

Example 7.
In Example 1 we discussed how to adjust the transducer from the introduction to our formal definition. We therefore had to introduce additional rules to obtain a total transducer. Now we still add rules for the same pairs (q, f ) but only with right-hand sides ⊥. Therefore the original domain of the transducer is given by a DTA D = (R, Σ, r 0 , δ D ) with the rules r 0 (g(x 1 , x 2 )) → (r(x 1 ), r(x 2 )), r(f (x 1 , x 2 )) → (r(x 1 ), r(x 2 )) and r(i) → ( ) for i = 1, 2, 3. ⊓ ⊔

Related Work
For several subclasses of attribute systems equivalence is known to be decidable. For instance, attributed grammars without inherited attributes are equivalent to deterministic top-down tree transducers (DT) [6,4]. For this class equivalence was shown to be decidable by Esik [11]. Later, a simplified algorithm was provided in [9]. If the tree translation of an attribute grammar is of linear size increase, then equivalence is decidable, because it is decidable for deterministic macro tree transducers (DMTT) of linear size increase. This follows from the fact that the latter class coincides with the class of (deterministic) MSO definable tree translations (DMSOTT) [7] for which equivalence is decidable [8]. Figure 3 shows a Hasse diagram of classes of translations realized by certain deterministic tree transducers. The prefixes "l", "sn", "b" and "sb" mean "linear size increase", "separated non-nested", "basic" and "separated basic", respectively. For deterministic top-down tree transducers, equivalence can be decided in EXPSPACE, and in NLOGSPACE if the transducers are total [26]. For the latter class of transducers, one can decide equivalence in polynomial time by transforming the transducer into a canonical normal form and then checking isomorphism of the resulting transducers [9]. In terms of hardness, we know that equivalence of deterministic top-down tree transducers is EXPTIME-hard. For linear size increase deterministic macro tree transducers the precise complexity is not known (but is at least NP-hard). More compexity results are known for other models of tree transducers such as streaming tree transducers [1], see [26] for a summary.

Conclusion
We have proved that the equivalence problem for separated non-nested attribute systems can be decided in polynomial time. In fact, we have shown a stronger statement, namely that in polynomial time equivalence of separated basic total deterministic macro tree transducers can be decided. To see that the latter is a strict superclass of the former, consider the translation that takes a binary tree as input, and outputs the same tree, but under each leaf a new monadic tree is output which represents the inverse Dewey path of that node. For instance, the tree f (f (a, a), a) is translated into the tree f (f (a (1(1(e))), a (2(1(e)))), a(2(e))). A macro tree transducer of the desired class can easily realize this translation using a rule of the form q (f (x 1 , 2 ), y) → f (q(x 1 , 1(y)), q(x 2 , 2(y))). In contrast, no attribute system can realize this translation. The reason is that for every attribute system, the number of distinct output subtrees is linearly bounded by the size of the input tree. For the given translation there is no linear such bound (it is bounded by |s| log(|s|)).
The idea of "separated" to use different output alphabets, is related to the idea of transducers "with origin" [2,12]. In future work we would like to define adequate notions of origin for macro tree transducer, and prove that equivalence of such (deterministic) transducers with origin is decidable. To compute the ∆ out -prefixes for every q ∈ Q we first compute some output tree t q = q(t, Y ) where t is a minimal input tree in dom(π(q)) and Y a minimal vector of terms over ∆ in . These t q can be computed in polynomial time and serve as lower bound for pref o (q), i.e., t q ⊑ pref o (q). We therefore take t q as inital values for Y q in the fixpoint iteration of the constraint system. Since in each iteration at least one subtree of the current value of Y q has to be replaced the fixpoint iteration ends after a polynomial time of iterations.  (x 1 , . . . , x k ), y) → s j for j = 1, . . . , r. This ends the construction of the new transducer M ′ with the corresponding axiom A ′ . Note, that the mapping π ′ from states of M ′ to states of D is given by π ′ ( q, v ) = b if and only if π(q) = b with q, v ∈ Q ′ , q ∈ Q, b ∈ B.
From the construction follows that M ′ is an earliest total deterministic separated basic MTT. We show that (M, A) is equivalent to (M ′ , A ′ ) by induction over the structure of the input trees. The semantics of the pairs (M, A) and (M ′ , A ′ ) is defined as (M, A) (t, T ) = p[ q 1 (t, T 1 ), . . . , q m (t, T m )] and (M ′ , A ′ ) (t, T ) = p[ t 1 , . . . , t m ] with t j = pref o (q j )[ q j , v j1 (t, T j ), . . . , q j , v jrj (t, T j )] for j = 1, . . . , m. Therefore, it suffices to show for every state q ∈ Q, every input tree t ∈ dom(π(q)) = dom(π ′ (q ′ )) and every vector of output parameters T ∈ T l ∆in , that holds if the subtrees ⊤ of pref o (q) occur at positions v 1 , . . . , v r , respectively. For j = 1, . . . , m, there are thus nodes v j1 , . . . , v jrj in pref o (q j ) such that for each input tree t ∈ dom(π(q j )) and vector of output parameters T ∈ T l ∆in , q j (t, T ) = pref o (q j )[ q j , v j1 (t, T ), . . . , q j , v jrj (t, T )]. Note, that in the base case when t = g and g ∈ Σ has rank 0 (m = 1), the right-hand side of a rule of q is a term t ∈ T ∆out∪Y , i. with t ∈ dom(π(q)) = dom(π ′ (q ′ )). Accordingly, for all input trees t ∈ dom(π(q)) and parameter vectors T ∈ T l ∆in , M, A (t, T ) = M ′ , A ′ (t, T ). Assume that n is the number of states of M , and D is the maximal size of a common ∆ out -prefix. Thus D is at most of the size of a right-hand side of a rule for a symbol of rank 0. Then each state q of M gives rise to at most n · D states q, v of M ′ where each right-hand side of q, v is at most D + 1 times the size of the corresponding right-hand side of q. Thus, the size of M ′ is polynomial in the size of M . Likewise, the axiom A ′ is only a factor of D + 1 larger than the axiom A. Since the ∆ out -prefixes of states of M can be computed in polynomial time, the overall algorithm runs in polynomial time. ⊓ ⊔