arXiv:2610.11337cs.FLOct 2026

Manuscript Offprint

arXiv:2610.11337

Type-Checking for Pattern-Based Tree Transformations

C. Aiswarya, Sahil Mhaskar, M. Praveen

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

We introduce and study pattern-based tree transformations. As an illustrating example, consider a source pattern (x⋅y)+(x⋅z)(x \cdot y) + (x \cdot z) and a target pattern x⋅(y+z)x \cdot (y + z) as a pair. This source pattern matches any expression ee of the form (e1⋅e2)+(e1⋅e3)(e_1 \cdot e_2) + (e_1 \cdot e_3) (by substituting xx with e1e_1, yy with e2e_2, and zz with e3e_3) and the pair transforms it into the expression e1⋅(e2+e3)e_1 \cdot (e_2 + e_3) as dictated by the target pattern. Note that in this example, the set of expressions that match the source pattern is not a regular tree language.

We propose a model of tree transformations given by a finite representation of a (possibly infinite) set of such (source pattern, target pattern) pairs. The expressive power of this model comes at the cost of undecidability of checking equivalence. Nevertheless, we show that the type-checking problem is decidable for our model of pattern-based tree transformations. The type-checking problem asks whether applying a given transformation to trees having a given regular property (type) preserves the property. Our decision procedure is by a reduction to the emptiness problem of alternating tree automata.

2012 ACM Subject Classification Theory of computation → Tree languages; Theory of computation → Transducers

Keywords and phrases Tree Transducers, Type-checking, Alternating Tree Automata, Pattern-matching

Related Version Full version of a preprint accepted at FSTTCS 2026

1 Introduction

Tree transformations in various forms of machines and logics have been studied for applications such as XML processing, programming languages, and HTML sanitisation [5, 11, 12, 14]. Classical formalisms for specifying tree transductions such as finite-state top-down and bottom-up tree transducers, macro tree transducers, attribute grammars and MSO (Monadic Second-Order Logic)-definable graph transductions typically aim for robustness with respect to operations involving regular tree languages and decidability of the equivalence problem.

We introduce a model for tree transductions targeting scenarios where the domain of the transduction is not necessarily regular, and undecidability of equivalence does not render the model useless. Expanding on the example from the abstract, consider expressions of the form t⋅e1+t⋅e2+⋯+t⋅ent \cdot e_1 + t \cdot e_2 + \cdots + t \cdot e_n, where nn is any number. An equivalent expression is t⋅(e1+e2+⋯+en)t \cdot (e_1 + e_2 + \cdots + e_n). Transformations like this are routinely used in Horner's method, an efficient way to evaluate polynomials. We consider the corresponding expression trees and

1^{1} Corresponding author.

Type-Checking for Pattern-Based Tree Transformations

model this transformation by matching the source tree with a source pattern and the target tree with a target pattern. The patterns are themselves trees, which can have placeholder variables to represent subtrees, like tt in the above example, which must repeat in multiple positions. The number nn can be arbitrary, so we need infinitely many pairs of patterns. For the example above, for each n>0n > 0 we need (x⋅e1+x⋅e2+⋯+x⋅en(x \cdot e_1 + x \cdot e_2 + \cdots + x \cdot e_n, x⋅(e1+e2+⋯+en)x \cdot (e_1 + e_2 + \cdots + e_n) as a (source pattern, target pattern) pair, where xx is a placeholder variable intended to match any expression tt. We represent such infinite sets (of pairs of patterns) using (standard) tree transductions. We allow placeholder variables in patterns to be substituted with any tree, as long as it satisfies a guard condition associated with the variable. The guard condition is given by a regular tree language called the guard language. It allows, for example, to restrict the expression tt above to be a valid expression. In some situations we may want to restrict it further, say, to not contain any products inside. In this example, the set of source trees to which the transformation is applicable needs to have the same subtree tt repeat in multiple positions. Thus the set of source trees on which transformations are defined need not be a regular tree language in general, which makes our model different from classical tree transductions.

The backbone of our model is a finite representation of the infinite set of (source pattern, target pattern) pairs. Such a finite representation can be any formalism for tree transductions; in this paper we have chosen to use bimorphisms for technical convenience. Bimorphisms are given by a regular seed language SS and two morphisms ϕsrc,ϕtgt\phi_{src}, \phi_{tgt}. The transduction is defined as the relation {(ϕsrc(t),ϕtgt(t))∣t∈S}\{(\phi_{src}(t), \phi_{tgt}(t)) \mid t \in S\}. Over words, bimorphisms are equivalent to rational transductions [15]. Over trees, bimorphisms capture subclasses of tree transducers (cf. [4, Section 6.5] and [6]).

For example, consider the seed language given by ab1(0+1)∗(⊕b1(0+1)∗)∗cab1(0+1)^{*}(\oplus b1(0+1)^{*})^{*}c. This is a regular word language over the alphabet {a,b,c,⊕,0,1}\{a,b,c,\oplus,0,1\}. We define the source and target morphisms ϕsrc,ϕtgt\phi_{src}, \phi_{tgt}: {a,b,c,⊕,0,1}→{0,1,+,⋅,x,(,)}∗\{a,b,c,\oplus,0,1\} \to \{0,1,+,\cdot,x,(,)\}^{*} as given by the following: ϕsrc:={a↦ε,b↦x⋅,c↦ε,⊕↦+,0↦0,1↦1}\phi_{src} := \{a \mapsto \varepsilon, b \mapsto x \cdot, c \mapsto \varepsilon, \oplus \mapsto +, 0 \mapsto 0, 1 \mapsto 1\} and similarly we define: ϕtgt:={a↦x⋅(,b↦ε,c↦),⊕↦+,0↦0,1↦1}\phi_{tgt} := \{a \mapsto x \cdot (, b \mapsto \varepsilon, c \mapsto), \oplus \mapsto +, 0 \mapsto 0, 1 \mapsto 1\}. We note that this bimorphism generates pairs of the form (x⋅e1+x⋅e2+⋯+x⋅en,x⋅(e1+e2+⋯+en))(x \cdot e_1 + x \cdot e_2 + \cdots + x \cdot e_n, \quad x \cdot (e_1 + e_2 + \cdots + e_n)) where eie_i is a nonzero binary number, from the seed word abe1⊕be2⊕⋯⊕bencabe_1 \oplus be_2 \oplus \cdots \oplus be_n c. We may add a guard to xx saying that xx can take values only from 1(0+1)∗1(0+1)^*, capturing completely the distributivity of multiplication over addition for binary numbers. Note that this only requires bimorphisms over words and defines transduction over words. If instead we allow the guard language of xx to be any syntactically valid expression tree, this now defines transformations from trees to trees, though given by a bimorphism over words. In fact, if we wish e1,e2…ene_1, e_2 \ldots e_n to be also expressions, we would require a bimorphism over trees. This case is detailed as an example in Section 2.

Notice that bimorphisms over words which do not produce placeholder variables anywhere already capture rational relations over words. Since equivalence-checking is undecidable for rational word relations [8, 10], it is undecidable for our model as well. However we show that the type-checking problem is decidable, even for transductions defined by bimorphisms over trees and potentially producing variables in the output of both morphisms. We first motivate the need for type-checking in the next paragraph, and give insights to our algorithm in the paragraphs following that.

Continuing with our example from above, we may want to check that applying the transformation does not increase the alternation between the operators ⋅\cdot and ++. This can be checked by verifying that if the transformation is applied to any tree from a language L consisting of trees with alternation depth bounded by a constant c, the resulting tree is in

L as well. On the other hand, for reasons of numerical stability, we may be interested in ensuring that size of subtrees made up of only the + operator is bounded. It can be checked that this regular property is not preserved by the transformation. Instead of arithmetic expressions, if we consider Boolean expressions made up of ∧ and ∨ operators, we can reason about expressions being in normal forms like conjunctive normal form (CNF), disjunctive normal form (DNF) etc. We consider the type-checking problem in general where the source trees have a property represented by a regular language LsrcL_{src} and output trees are required to have a property represented by another (possibly different) regular language LtgtL_{tgt}.

The main idea of our decision procedure for the type-checking problem is the following observation: if the given instance of the type-checking problem is a negative instance, a counterexample is a single tree in the seed language S, satisfying multiple conditions under multiple transformations. On the source side, applying the morphism ϕsrc\phi_{src} to the seed tree and then applying a substitution for the placeholder variables should result in a tree in LsrcL_{src}. On the output side, applying the morphism ϕtgt\phi_{tgt} to the same seed tree and then applying the same substitution for the placeholder variables should result in a tree not in LtgtL_{tgt}. These conditions can be checked by an alternating tree automaton running on trees in the seed language, thus reducing the type-checking problem to the emptiness-checking of alternating tree automata.

Along the way, we consider some related/simpler problems. The simple question of whether a given tree matches a given pattern is NP-complete, a result known already for words [4]. The special case of the type-checking problem where the transformation is given by a single pair of patterns is EXPTIME-complete. This generalises the work of pattern-based word transformations [1] to trees.