Polyregular Functions on Unordered Trees of Bounded Height

We consider injective first-order interpretations that input and output trees of bounded height. The corresponding functions have polynomial output size, since a first-order interpretation can use a k-tuple of input nodes to represent a single output node. We prove that the equivalence problem for such functions is decidable, i.e. given two such interpretations, one can decide whether, for every input tree, the two output trees are isomorphic. We also give a calculus of typed functions and combinators which derives exactly injective first-order interpretations for unordered trees of bounded height. The calculus is based on a type system, where the type constructors are products, coproducts and a monad of multisets. Thanks to our results about tree-to-tree interpretations, the equivalence problem is decidable for this calculus. As an application, we show that the equivalence problem is decidable for first-order interpretations between classes of graphs that have bounded tree-depth. In all cases studied in this paper, first-order logic and MSO have the same expressive power, and hence all results apply also to MSO interpretations.


INTRODUCTION
This paper is about computational models that transform objects such as strings or trees, are powerful enough to describe interesting programs, but are weak enough to have a decidable halting problem.The point of departure is the class of polyregular functions [Bojańczyk 2022].This is a class of string-to-string functions that contains functions such as 123 ↦ → 123123123 squaring 123 ↦ → 321 reverse , and that can be defined by many equivalent models of computation, including: pebble transducers [Milo et al. 2003, Section 3.1], a certain imperative programming language [Bojańczyk 2022, Section 1], several functional programming languages with the same expressive power [Bojańczyk 2022, Sections 3 and 4] and [Bojańczyk 2023], and logical interpretations [Bojańczyk et al. 2019, Theorem 7].The general idea is that the polyregular functions are those string-to-string functions which have polynomial output size, and which can be computed by devices similar to automata.Due to their similarity to finite automata, certain problems are known to be decidable for polyregular functions (see e.g.[Bojańczyk 2022, Corollary 1.5]).An outstanding open problem about polyregular functions is decidability of the equivalence problem, i.e. it is not known if one can decide whether two devices (transducers, programs, interpretations) compute the same polyregular function.In this paper we make progress on this question by answering it in a different setup, where instead of strings the underlying data structure is nested multisets.
Let us begin by explaining the objects studied here.One description (see Section 2) is that these are data types that are constructed from finite sets using the multiset constructor M = finite multisets of elements from  .
(We also allow products and coproducts, but it is only the multiset constructor that can create infinite sets.)We use the name multiset types for such types1 .Another description of multiset types is that they describe trees, since nested multisets can be represented as trees, as explained in the following picture: a multiset of multisets we use double brackets for multisets the corresponding tree the same tree, again Importantly, the trees are unordered (there is no order on siblings, since multisets are unordered), and their height is bounded (by the nesting depth of the multiset constructor in a multiset type).
This paper is about functions on multiset types or, equivalently, unordered trees of bounded height.The contributions of this paper are: (1) In Section 2-4, we introduce a notion of polyregular function for such objects.These are functions between multiset types (or, equivalently, unordered trees of bounded height), that have polynomial output size, and that coincide with regular languages in the case of Boolean outputs.One example of such a polyregular function is the product operation (MΣ) × (MΓ) → M(Σ × Γ), that inputs two multisets, of cardinalities  and , respectively, and outputs a single multiset of cardinality  • .This function has quadratic output size.Another example, which has linear output size, is the multiset union operation of type MMΣ → MΣ.In our definition of polyregular functions, we propose two models, and prove that they are equivalent.The first model is first-order interpretations, which are a classical model of describing functions using logical formulas [Hodges 1993, Chapter 5].The second model uses certain prime functions (such as multiset union) and combinators (such as sequential composition of functions), inspired by a similar system for string-to-string polyregular functions [Bojańczyk 2022, Section 3].The proof that these models describe the same functions on multiset types is inspired by a similar result for strings [Bojańczyk et al. 2019, Theorem 7], except that in the multiset case we can avoid many technicalities that appear in the string case.One of the useful features of multiset types is that first-order (fo) logic has the same expressive power as monadic second-order (mso) logic.
(2) In Sections 5-6, we prove that the equivalence problem is decidable for the polyregular functions on multiset types.This means that one can decide if two programs represent the same function, i.e. for every input (which is taken from some multiset type), the two possible outputs are equal.For strings, this problem remains open [Bojańczyk 2022, Section 8], and the decidability result on multisets from this paper is the first significant progress on the problem (Section 6.3, we comment on the connection between the two problems).Our algorithm uses two main ingredients: a quantifier-elimination result, and an algorithm for the quantifier-free case that uses a data structure that involves trees with edge weights taken from a polynomial ring Z [𝑋 ].The equivalence algorithm is the main technical contribution of this paper.(3) Finally, in Section 7 we illustrate the strength of the equivalence result from the previous item by extending it to graphs of bounded tree-depth.
Context.One could place the present paper within the wider context of Hilbert's Entscheidungsproblem [Börger et al. 2001], which is to decide if a first-order formula is true.This problem can be seen as deciding equality on (the semantics) of formulas, i.e whether a formula  is equal to another formula, such as "true" or "false".The problem is famously undecidable, as shown by Church and Turing.One of the most successful methods of recovering decidability has been to use automata methods (tree automata, mso logic, tree decompositions, etc).The scope of such methods is now well understood; they will work if and only if one considers structures that are similar to trees, see [Seese 1991, Theorem 8] and [Courcelle and Oum 2007, Theorem 5.6] for formalisations of this statement.
In this paper, we address a functional version of the problem: instead of deciding equality on logically defined languages (functions with Boolean outputs), we want to decide it on logically defined functions (which input and output structures).In the functional version, logical formulas are replaced by logical interpretations, and one asks if for every input, the outputs produced by the two interpretations are isomorphic.This makes the problem nontrivial for output structures with nontrivial isomorphisms, such as graphs, or even unordered trees.This difficulty is not present in the language version, because isomorphism creates difficulties only for the output structures.Making progress on this problem seems to be very hard, even for tame structures such as unordered trees of bounded height or graphs of bounded tree-depth, as considered in this paper.
To our best knowledge, the results of this paper about interpretations on bounded tree-depth gives are the first known decidability results about equivalence for graph-to-graph interpretations.Previous results about equivalence involved trees, with the state of the art being the results on treeto-tree interpretations from [Seidl et al. 2018, Corollary 8.2] and [Boiret et al. 2018, Section 3].These papers deal with trees of unbounded depth, but the interpretations are restricted to have linear output size.The techniques are based on Hilbert's Basis Theorem and seem to fail for interpretations of non-linear output size, and also have a certain fragility regarding the type of structures that can be modelled (for example, the results work for linear interpretations on trees with a distinguished root, but the case of trees without distinguished roots remains open [Bojańczyk and Schmude 2020, p. 7]).The only known decidability results for equivalence of non-linear interpretations is for functions that output numbers [Douéneau-Tabot 2021, Corollary 19]; the techniques used there are based on weighted automata and seem to apply only to outputs that are numbers.
Nested multisets have been studied in database theory, in the context of nested relational algebra [Buneman et al. 1995;Cheney et al. 2014;Ricciotti and Cheney 2019].Calculi of typed functionals are used there to define transformations between nested collections, similarly to what we aim to do here.It appears that our approach is more restricted than most of the calculi considered there, with the advantage of decidable equivalence.Potential applications of our results in nested relational calculi remain to be investigated.

MULTISET TYPES
One way of describing trees of bounded height is to view them as values of certain algebraic datatypes.The essential ingredient will be the multiset type constructor, since an unordered tree can be seen as the multiset of its child subtrees.We begin the paper with this approach.Apart from the multiset constructor, we also allow products and coproducts, which will be useful for typing various helper functions.
Definition 2.1 (Multiset types).A multiset type is any type that can be generated using the following type constructors: Strictly speaking, this definition introduces two notions: a syntax of multiset types, and an obvious semantics of each type as a certain set of values.There is no need to be pedantic about this distinction for the moment, but in Section 3 we will introduce a more elaborate semantics of multiset types as sets of relational structures over certain vocabularies.
Example 1. M  1 is the type of unordered trees of height at most .(The height of a tree is defined to be the maximal number of edges on a root-to-leaf path.)The idea is that a tree is represented as the multiset of the representations of its child subtrees.For example, consider  = 2 and the following tree Assuming that we use double set brackets to represent multisets, the above tree is represented as the following multiset of multisets: where * denotes the unique element of the set 1. □ Example 2. We can extend the trees from the previous example by adding labels from some type Σ.There are two variants of such trees of height at most : • T edge  Σ: edge-labeled trees, and • T node  Σ: node-labeled tress.
These constructors can be simulated using multiset types, by induction on : We want to study a class of functions between multiset types which we call the polyregular functions, meant to be an analogue of the string-to-string polyregular functions from [Bojańczyk 2018].There will be two equivalent definitions of this class, one using fo interpretations (Section 3), and one using combinators (Section 4).

LOGIC
We describe a logical approach to polyregular functions on multiset types.The idea is to view each multiset type as a class of structures, in the sense of model theory, and to use fo interpretations to transform the structures.fo interpretations are the usual kind of functions from structures to structures, where the universe of the output structure is defined using tuples of elements in the input structure, and the relations of the output structure are defined using fo formulas.Precise definitions are given below.fo interpretations.We assume that the reader is familiar with the basic notions of first-order (fo) logic.We use the following terminology.A vocabulary is a finite set of relation names, each one with an associated arity in {0, 1, 2, . ..}.A structure over such a vocabulary consists of a set, called its universe, and for each relation name in the vocabulary a corresponding relation -of same arity -over the universe.We assume that the universe in a structure is nonempty.
When we talk about a class of structures, we mean any class that contains structures, over the same vocabulary, which is closed under isomorphism.To transform structures of one class into structures of another class, we use fo interpretations as defined below.This notion is commonly used in model theory (see e.g.[Hodges 1993, Chap. 5.3]).For a simple example, see Ex. 4 below.
Definition 3.1.Let Σ and Γ be classes of structures.A function  : Σ → Γ is called an fo interpretation if it can be described as follows: there is a finite set  , called the components of the interpretation, with each component  ∈  associated to a dimension   ∈ {0, 1, . ..}, and for every input structure  ∈ Σ the output structure  () is defined by: • Universe.For every component  there is an fo formula   over the vocabulary of Σ with   free variables, such that the universe of  () is Elements of the above disjoint union will be written as pairs (, ā).• Relations.For every relation name , say of arity , in the vocabulary of Γ and every tuple of components  1 , . . .,   ∈  , there is an fo formula  over the vocabulary of Σ with ) for all ( 1 , ā1 ), . . ., (  , ā ) in the universe of  ().
Remark 3.2.This definition is what is sometimes called an injective fo interpretation.In model theory one typically uses a more general notion of interpretation, where the universe of the output structure is a quotient where each ∼  is some equivalence relation that is defined by a formula with 2  free variables.The formulas defining the relations of the output structure are required to be invariant under these equivalences.This is a more powerful model, which we call non-injective interpretations, and which will not be discussed in this paper.
Multiset types as classes of structures.A multiset type can be viewed as a class of structures, as explained in the following inductive definition.
Definition 3.3.The type constructors are extended to classes of structures as follows: 1: This is the class of structures over the empty vocabulary, that contains only one structure: a universe with one element.Σ × Γ: If Σ and Γ are classes of structures, then Σ × Γ is the class over vocabulary one extra unary relation name (here + means disjoint union of vocabularies) that is defined as follows.A structure in Σ × Γ is obtained by taking a structure  ∈ Σ and a structure  ∈ Γ, and returning the following pair structure (, ): extend both  and  to the vocabulary voc(Σ) + voc(Γ) by interpreting new relation names as empty sets, then take their disjoint union, and finally interpret  as the set of elements that come from .Σ + Γ: If Σ and Γ are classes of structures, then Σ + Γ is the class over vocabulary one extra 0-ary relation name which contains structures that are obtained by either: (1) taking a structure in Σ, extending it to voc(Σ) + voc(Γ) and interpreting  as true; or (2) taking a structure in Γ, extending it to voc(Σ) + voc(Γ) and interpreting  as false.MΣ: If Σ is a class of structures, then voc(MΣ) arises from voc(Σ) by replacing every 0-ary relation by a unary relation, and then adding an extra binary relation ∼.A structure in MΣ is obtained by: (1) taking the disjoint union of some structures  1 , . . .,   ∈ Σ, (2) replacing every 0-ary predicate  from voc(Σ) by a unary relation that holds for all elements of those   for which  is true, (3) interpreting ∼ as the equivalence relation whose equivalence classes are the universes of the structures  1 , . . .,   , (4) and adding an extra element (called the root) that does not participate in any relations2 .
In this way, every multiset type can be seen as a class of structures.Therefore one can use fo sentences to define subsets of multisets types, and fo interpretations to define functions between multiset types.Remark 3.4.fo interpretations are closed under composition, and the identity is a fo interpretation.Therefore one can consider the following category: the objects are classes of structures, and the morphisms are fo interpretations modulo equivalence.(This means that two interpretations describe the same morphism if they are equivalent in the sense that for every input structure, the two output structures produced by the two interpretations are isomorphic.)It is not difficult to prove that 1, Σ + Γ and Σ × Γ in Definition 3.3 define respectively the terminal object, coproduct, and product in this category, and that M is a monad.We do not elaborate this categorical perspective in this paper, but it will inform our choice of prime functions and combinators in Definition 4.1.
Example 3.An unordered tree of height at most  can be seen as a relational structure over a vocabulary of  binary relations ∼ 1 , . . ., ∼  , with ∼  interpreted as relating those nodes that have a common ancestor at depth at least .It is easy to construct mutually inverse interpretations between this representation of trees and the more usual one based on a parent-child relation.By Definition 3.3, trees represented in this way are exactly structures of type M  1. □ By Lemma 4.3 below, all multiset types can be viewed as a special case of trees of bounded height.For such structures first-order logic has the same expressive power as monadic second-order logic, see [Elberfeld et al. 2016, Theorem 1.1].Therefore, mso and fo logics will define the same kind of interpretations between multiset types.We will therefore simply speak about interpretations from now on, without specifying that they are fo interpretations.
Example 4. Assume that we model the natural numbers as multisets Under this representation, which functions  : N → N can be obtained as interpretations?One example is all polynomials with non-negative coefficients.For example, the function  () = 3 4 +  2 + 7 is defined by an interpretation with 3 components of dimension 4, 1 component of dimension 2, and 7 components of dimension 0. In each of these components, the universe formula is "true".
Another example is the function that counts the number of non-repeating -tuples in the input, the output of this function is As a polynomial, this function has some negative coefficients.The corresponding interpretation has 1 component of dimension , with a universe formula that selects non-repeating tuples.As it turns out, non-repeating tuples are essentially the only thing that can be done.
Proof.The implication 2 ⇒ 1 is easy to show.For the converse, it is enough to prove the claim for interpretations with one component; since having several components corresponds to taking a sum of functions with non-negative co-efficients.Suppose then that  is defined by an interpretation with one component of dimension .The corresponding function inputs a number , and returns the number of -tuples that satisfy some first-order formula  ( 1 , . . .,   ) in the structure that has  elements and no nontrivial relations.Over such a structure, quantifiers are not useful, at least as long as  exceeds some threshold.Counting tuples that satisfy a quantifier-free formula gives a function as in item (2).□ As a corollary, e.g. the decrement function  () = max( − 1, 0) is not an interpretation.□

DERIVABLE FUNCTIONS
In this section, we give an alternative definition of polyregular functions on multiset types, which uses combinators.Then we prove that this definition is equivalent to the interpretations from Section 3. The idea is to start with certain prime functions, such as multiset union, and close them under certain combinators, such as composition of functions.A brutal approach would be to start with all functions that are interpretations; in this case, the combinators would not be needed.However, in the presence of combinators, only a small set of prime functions is needed.Two of these functions are explained in the following examples.
Example 5.For a multiset type Σ, consider the de-singleton function of type MΣ → 1 + Σ that maps singleton multisets to their unique elements, and otherwise returns the unique element of 1. (Like almost all prime functions, this is not a single function but a family of functions indexed by multiset types.)We claim that this is a first-order interpretation.This has a component of dimension zero, used to produce the error value in the case of non-singleton inputs.The universe formula for this component says that the input multiset is not a singleton, i.e. that it either consist solely of the root or it contains some non-root elements which are not related by the equivalence relation ∼ from the definition of MΣ: For singleton input multisets, the input structure should simply be copied to the output, removing the root.This is done by using an additional component of dimension one, whose universe formula says that the argument is not the root of the multiset.□ Example 6.Let Σ be a multiset type.One of our prime functions, and the only one whose growth is more than linear, is choices of the type This function, given a multiset where   ∈ Σ, outputs the following multiset with the same number of elements: The idea is that the output contains all possible multisets that can be obtained from the input multiset by choosing some distinguished element.
Let us prove that this function is a first-order interpretation.To represent an element of   in the output structure, we simply use the same element in the input structure.These elements are represented using a component of dimension one.To represent an element of   in the output structure, we use a pair (, ), where  is the root of   (see below) and  is an element of some   in the input structure with  ≠ .Formally, the universe formula for the corresponding component of dimension two is: where ∼ is the equivalence relation from the definition of MΣ, and  Σ is a formula that is satisfied for a unique element of every structure in Σ.Such a formula is defined by induction on Σ, using the root in the induction step for multisets.□ The above examples explain the only two non-obvious prime functions.The remaining prime functions and all the combinators are straightforward enough that we simply give their types and names, and we assume that the reader can guess their definitions.
Definition 4.1.The derivable functions are the least class of functions that: • Prime functions: contains the following functions for all types Σ, Σ 1 , Σ 2 : • Combinators: is closed under applying the following combinators: It is easy to prove that all prime functions are interpretations (see Theorem 4.4).In fact, recalling categorical considerations from Remark 3.4, most prime functions are natural transformations between the corresponding functors on the category of fo interpretations.A notable exception is choices, whose fo definition in Example 6 relies on root formulas that are defined only for multiset types and not for arbitrary structures.The need for roots would disappear if we considered non-injective fo interpretations as in Remark 3.2; then choices would become a natural transformation.It therefore seems natural to leave the full categorical framework to future work, until we extend our results to non-injective interpretations.For the present, we can use the flexibility afforded by our elementary framework to derive some other non-natural functions by induction on the structure of multiset types.
Example 7.Although the list of prime functions has the identity for every multiset type Σ, it is only really needed in type 1 → 1.For the remaining types, it can be derived using combinators.Also, for every type Σ we can derive the unique function !Σ of type Σ → 1.The proof is by induction on Σ, in the induction step for Σ = MΓ one uses the de-singleton operation.
We can also derive functions of type 1 → Σ by induction on Σ.For coproducts, this is done with coprojections; for products, with pairing; for multiset types, with the mapping combinator and the constant empty multiset function.□ Example 8. Define the Boolean type to be One can easily derive all Boolean operations, e.g.conjunction Bool 2 → Bool.In fact, for every finite types Σ and Γ, i.e. types that are built without the multiset constructor M, one can derive every function of type Σ → Γ. □ Example 9.The emptiness test  : M1 → Bool, that returns "true" for the empty multiset and "false" for nonempty ones, is derived as the composition of the following operations: The idea is that the empty multiset is the only one to which we can add and element to obtain a singleton.□ Example 10.We now derive the function that implements disjunction of unbounded arity: the function checks if the input multiset contains at least one "true" value.This function is derived as follows.To the input, which is a multiset of Booleans, we apply M , where  : Bool → M1 is the function that maps "false" to the empty multiset and "true" to the singleton multiset.After applying multiset union to the result, we test the resulting value for emptiness.Using the same idea, for any multiset types Σ and Γ we can derive a function that erases all elements of Γ from the given multiset.□ Example 11.For multiset types Σ and Γ, consider the function strength of type which, given an argument  ∈ Γ and a multiset returns the multiset of pairs: with the same number of elements.
Let us prove that strength is derivable.Given a structure in MΣ × Γ, perform the following steps: (1) use suitable coprojections to get to

□
Trees of bounded height.In Examples 1 and 3 we showed how unlabelled trees of height at most  can be modeled as structures of type M  1.The following lemma shows that such types are general, i.e. all multiset types can be encoded in them.We use the following notion of encoding: we say that a type Σ encodes in a type Γ if there are derivable functions Σ encode * * Γ decode j j such that encode;decode is the identity on Σ.
Proof.Induction on the structure of the type.For the type 1, there is nothing to do.For a type MΣ, we simply apply the mapping combinator to the encoding for Σ.We are left with products and coproducts.We only describe the construction for products Σ × Γ; coproducts can be treated in a similar way.By induction assumption, each of the types Σ and Γ encodes into trees of some height.We can assume that the heights are the same, because M  1 encodes into M +1 1.We pair the encodings as follows: a pair in Σ × Γ is sent to the following tree encoding of the Σ part encoding of the Γ part This tree lives in M +3 1, where  is the height of trees needed to encode Σ and Γ.It remains to describe the decoding.We explain how to extract the Σ component.In the argument below, a singleton tree is a tree where the root has a single child.The projection to the Σ coordinate is performed in five stages, summarised in the following picture: remove child subtrees that are singleton trees de-singleton the tree de-singleton the tree de-singleton the tree remove child subtrees that have exactly one node We omit the straightforward details of the construction.A similar construction is used for extracting the Γ component.□

Completeness of the derivable functions
Let us prove that on multiset types, first-order interpretations coincide with derivable functions.
Theorem 4.4.Let  : Σ → Γ be a function between multiset types.Then  is a first-order interpretation if and only if it is derivable.
The easier direction is soundness: every derivable function is also an interpretation.This is proved by a straightforward induction on the derivation: all prime functions are easily seen to be first-order interpretations (see Examples 5-6), and first-order interpretations are easily seen to be closed under applying the combinators.
We now move to the harder part of the theorem, which we call completeness: every first-order interpretation can be derived.This is proved first for Boolean outputs, and then for general outputs.
4.1.1Boolean outputs.We begin by deriving interpretations with Boolean outputs, which is the same as first-order sentences.(Indeed, all structures of type Bool have a one-element universe with a single nullary relation, so the only ingredient of the interpretation is the sentence which is the interpretation of that relation.)This is done by inlining the semantics of fo logic into our type system, with the choices function used to simulate a single quantifier.
In the proof it will be convenient to think of structures with distinguished elements as being a multiset type.This is done using the following type constructor, where  ∈ {0, 1, . ..}: We do not assume that the distinguished elements are pairwise distinct.This type constructor can be encoded using the existing type constructors: (the 1+ in the multiset case is due to the fact that the root element might be distinguished).As a result, for any multiset type Σ, we can view V  Σ as a multiset type.The semantics of a first-order formula  over the vocabulary of Σ that has  free variables is an interpretation of type The following lemma shows that such functions are derivable.
Lemma 4.5.Let Σ be a multiset type.For every first-order formula  over the vocabulary of Σ with  free variables, the function [[]] is derivable.
Proof.Induction on the size of .The induction base, when  is an atomic formula, is by straightforward induction on Σ.For example, the equality predicate  =  is modeled as a function easily derived by induction on Σ.
For the induction step of negation ¬, we simply compose the function of  with the negation operation of type Bool → Bool.The same works for disjunction and conjunction, except that we use pairing.
The last remaining induction step is that of a quantified formula of the form ∃ or ∀, where  is a formula with  + 1 free variables.Consider the extension function of type: that extends the input valuation in all possible ways by adding one element to the tuple.Since by definition  +1 Σ =  1 (  Σ), it is enough to derive this function for  = 0.This is done by induction on the type Σ; for ext MΣ we use choices and strength from Example 11, and for ext Σ×Γ we use strength again.
The functions [[∃]] and [[∀𝑥𝜑]] are derived by first applying the extension function, then applying [[]] to each element of the resulting multiset, and then applying disjunction/conjunction from Example 10 to the resulting multiset of Booleans.□ 4.1.2General outputs.We now show how to derive first-order interpretations that have outputs which can be any multiset type, not just the Booleans.Thanks to Lemma 4.3, which says that every multiset type encodes into trees, the problem will reduce to functions with tree outputs.
Valuation trees.To deal with tree outputs, we introduce a data structure called valuation trees.For a structure  and a number  ∈ {0, 1, . . ., }, the valuation tree of height  for  is defined as follows.Nodes of the tree are pairs (, ā) where ā is a list of at most  distinguished elements in ; in particular, the structure  is copied in each node in the tree.The ancestor relation is the prefix relation on the tuples of distinguished elements; in particular, the root of the tree uses the empty tuple of distinguished elements.The height of this tree is , and the leaves are labelled by tuples of  distinguished elements.
For a multiset type Σ, the valuation trees of height  for structures from Σ can be seen as a type: and T node  is the constructor of node-labelled trees from Example 2.Not all elements of this type are valuation trees, since a valuation tree requires that the label of a parent node is obtained from the label of any child node by removing the last distinguished element.For every  and multiset type Σ, there is a derivable function: that maps a structure to its valuation tree.This is by induction on , with valtree +1 Σ derived by: The extension function ext was derived in the proof of Lemma 4.5.
Completeness proof.Using valuation trees, we finish the completeness proof for Theorem 4.4.Suppose that we want to derive a first-order interpretation  : Σ → Γ. Apply Lemma 4.3 to the output type, yielding derivable functions Since the decoding function is derivable, it is enough to show that the composition is derivable.This function has tree outputs of bounded height, and it is a first-order interpretation.
For every such interpretation, there is an equivalent interpretation such that: (a) for every dimension  there is at most one component of this dimension; and (b) the ancestor ordering on nodes of the output tree is the prefix relation on tuples.To ensure (b) only, build an interpretation where nodes of the output structure are sequences (paths in the tree) of output nodes in the original interpretation, with new components arising from sequences (of length up to ) of the original components.The original parent-child relation now becomes part of the universe condition, and the new ancestor relation is just the prefix order.To furthermore ensure (a) in this construction, extend the dimension of every component (arising from a sequence of the original components) by adding a certain number of dummy coordinates at the end (and also, necessarily, in the middle, to ensure that the parent-child relation is still a prefix relation).
Assuming that  ;  has properties (a) and (b), and the maximal dimension used in the interpretation is  (typically  will be larger than ), one can decompose  ;  into four steps: (1) Compute the valuation tree of height , yielding a result in type T node  V ≤ Σ.
(2) Consider the universe formula of the first order-interpretation defining  ; , viewed as a function of type V ≤ Σ → Bool.Apply this function to the label of each node in the result of the previous step, yielding a result in type T node  Bool.
(3) In the tree computed so far, keep only nodes with label "true", while preserving the ancestor relation, yielding a tree in T node  1. (4) By the semantic properties of the first-order interpretation, we know that the output from the previous step will have height .However, we need to explicitly cast it into the output type T node  1.We therefore apply a derivable function that keeps only nodes at distance at most  from the root, yielding a tree in the correct output type T node  1.All these four steps are derivable.Indeed, as we have already remarked, the valuation tree can be computed using a derivable function.The second step is derivable by Lemma 4.5.Deriving the last two steps is straightforward.

DECIDING EQUIVALENCE FOR QUANTIFIER-FREE INTERPRETATIONS ON TREES OF BOUNDED HEIGHT
In the previous section we presented a list of prime functions and combinators that together generate all interpretations that input and output trees of bounded height.It is clear that these functions and combinators satisfy various equalities: pairing of the two projections from a product type is equal to the identity, the mapping combinator preserves function composition, and so on.One wonders whether there is an equational axiomatisation of the equivalence of interpretations presented in this way.Ideally, that equational theory would be decidable.We do not attempt to provide such a theory in this paper.However, we will prove that equivalence of interpretations is indeed decidable.We shall work directly with the logical presentation of interpretations, without a direct reference to the prime functions and combinators.
The problem is to decide, given two fo interpretations on multiset types, if they produce isomorphic outputs for every input.We first solve a special case of this problem, where the input and output types represent trees of bounded height, and -more importantly -the functions are quantifier-free interpretations.In Section 6 we will reduce the general problem to this special case.
We begin by specifying the exact variant of trees that is used, and their representations as logical structures.We need to be quite specific here, since for quantifier-free interpretations the exact choice of vocabulary plays a role.In Section 6 these details will become unimportant, as quantified formulas allow easy translations between various representations of trees.
For the output trees, we consider unlabelled trees with a height bound , where a tree is represented as a set of nodes with the parent-child relation.We will denote the class of such trees by M  1.This is a slight abuse of notation: in Section 3 this indeed denotes the same class of trees, but under a different relational representation.
For the input, we use trees with edge labels from a finite set Σ and with a height bound .This corresponds to the type T edge  Σ described in Example 2, but again, abusing the notation, we use a representation different from the one arising from Definition 3.3.In this edge represenation: • the universe of the tree is the set of its edges; • for every label , there is a unary relation that selects edges with label ; • there is a parent function, which maps an edge to its parent edge.For edges without parents, i.e. edges that originate in the root of the tree, the parent function loops.A useful property of this representation is that induced substructures have an intuitive meaning: they correspond to "pruned" trees that arise by removing some subtrees.The empty structure also has a meaning: it represents a root-only tree.This will be convenient when we apply generic results from Section 5.1 to labelled trees.
We will consider functions of type for a finite set Σ of edge labels.The functions will be quantifier-free interpretations, assuming tree representations as above.This is the special case of interpretations as in Definition 3.1, in which all formulas are quantifier-free.(Note that Definition 3.1 makes sense in the presence of functions in the input vocabulary.)This section is devoted to proving the following theorem.
Theorem 5.1.The following problem is decidable: Instance.Two quantifier-free interpretations  ,  : Are the functions equivalent in the following sense: for every input, the two outputs are isomorphic as trees?
We will even show that the problem is in polynomial time, assuming a suitable representation of quantifier-free interpretations, which we shall call patterns.

Patterns
In our solution to the equivalence problem, we use a more combinatorial representation of quantifierfree interpretations, which is defined by counting embeddings.
Recall that an embedding between structures over the same vocabulary is an injective map from the universe of the source structure into the universe of the target structure, that preserves and reflects all relations.We will use embeddings mainly for trees modelled using the functional edge representation as described above.Under that representation, an embedding of one tree into another is an injective map from edges in the source tree to edges in the target tree, that preserves the labels and the parent function.Since the parent function loops for edges without parents, such edges must be mapped to edges without parents.In other words, the root node must be mapped to the root node.Here is a picture: source tree target tree emb edd ing The following definition is the key notion of this section.We will apply it to labeled trees under the edge representation, but the definition makes sense for any class of structures that is closed under induced substructures.Here an induced substructure is obtained by restricting the universe to some (possibly empty) subset that is closed under the functions in the structure.
Definition 5.2 (Pattern).Let C be a class of structures that is closed under induced substructures.A pattern for C is a finite tree Φ where every node  is labelled by a structure Φ() in C , such that: • the root node is labelled by the empty structure, and • if a node  is the parent of a node , then Φ() is an induced substructure of Φ().
Example 12.Here is a picture of a pattern, where the class C is trees of height at most one with edges labelled red or blue: The dotted lines in the picture represent the inclusions of induced substructures between a node of the pattern and its children.□ Two patterns are isomorphic if there is: (i) a bijection between the underlying trees of the two patterns, that preserves the tree structure; and (ii) a family of isomorphisms, one for each node  in the first pattern, that isomorphically maps the structure labelling  in the first pattern to the structure labelling the corresponding node in the second pattern.The family of isomorphisms in (ii) must be consistent with the inclusion of labels, i.e. the isomorphism for a node  must extend the isomorphism for its parent.
Every pattern Φ determines a function which inputs structures from C and outputs unlabelled trees, and is defined as follows.For an input structure  ∈ C , the nodes of the output tree are pairs (, ) where  is a node of the pattern and  : Φ() ↩→  is an embedding from the structure that labels node  in the pattern to the input structure .The children of a node (, ) are nodes (, ) such that  is a child of  and the embedding  extends .
By definition, the height of the output tree is bounded by the height of the pattern.Moreover, the function defined by a pattern Φ is easily seen to be a quantifier-free interpretation.Indeed, one can take a component for each node  in Φ, with dimension equal to the size of the structure Φ(), and the universe formula determined by the structure Φ() itself.The parent-child relation is then defined by a suitable sub-tuple formula.All these formulas are quantifier-free.
The following lemma shows that every function of this kind arises from a pattern.
Lemma 5.3.Let C be a class of structures that is closed under induced substructures.Then a function from C to (unlabelled) trees is defined by a pattern if and only if it is a quantifier-free interpretation that produces outputs of bounded height.
Proof.Consider a quantifier-free interpretation  that, given an input structure in C , produces a tree of height at most .As we observed in the completeness proof in Section 4.1.2,there exists an equivalent interpretation f whose components are sequences of components of  of length up to ; the dimension of each such component is the sum of dimensions of the original components in the sequence.The universe formula for such a component combines the universe formulas for the original components with the parent relation formula of the output tree of  ; this is quantifier-free if all the constituent formulas are quantifier-free.Finally, the parent relation is simply the prefix relation of a suitable length; again, this is described by a quantifier-free formula.Now, f is an interpretation of the same type as  , but with the parent relation in the output tree defined as a prefix formula.Every quantifier-free interpretation with this property arises from a pattern.Indeed, the universe formula for each component is (equivalent to) a disjunction of conjunctive formulas that fully describe relations between a finite set of variables.Such a conjunctive formula is essentially a structure from C together with a valuation of the variables that generates the entire structure.A pattern whose nodes are the conjunctive formulas present in f , with the parent relation inherited from f , defines the interpretation f , which is equivalent to  .□ Importantly, the above proof is constructive: a pattern that defines a quantifier-free interpretation to unlabelled trees can be effectively reconstructed from (the number  and) a logical description of the interpretation.
Example 13.Let C be the class of trees of height at most two with edges labelled red or blue, and let  be the function that simply returns the input tree, forgetting the colors.This is a quantifier-free interpretation, defined by a single component of dimension one, with the universe formula "true" and an evident parent relation.It is defined by the pattern: In particular, the root node of this pattern has exactly one embedding into any input tree, and that embedding is the root of the output tree.□

Patterns with tree inputs
Although patterns make sense for general classes of input structures, we focus on patterns where the input class is trees of bounded height labelled by some finite alphabet, as in Theorem 5.1.By Lemma 5.3, all functions from the decision problem in Theorem 5.1 can be described using patterns, and these patterns can be computed from the original representation in terms of quantifier-free formulas.Therefore, Theorem 5.1 boils down to deciding equivalence for tree-to-tree functions defined by patterns.We will show that the latter problem is decidable, even in polynomial time, for a very simple reason: different patterns define different tree-to-tree functions.
Theorem 5.4.Consider two patterns Φ 1 and Φ 2 that define tree-to-tree functions.If the patterns are non-isomorphic, then the corresponding tree-to-tree functions are non-equivalent, i.e. for some input tree, the two output trees are non-isomorphic.
From this we can immediately conclude Theorem 5.1.Indeed, consider two tree-to-tree functions  1 and  2 , as in Theorem 5.1.By Lemma 5.3, these functions are defined by patterns, say Φ 1 and Φ 2 .By Theorem 5.4, the functions are equivalent if and only if the patterns are isomorphic.Isomorphism of patterns can be decided in polynomial time using a straightforward dynamic programming algorithm.Note, however, that there is an exponential overhead in translating a quantifier-free interpretation   to a pattern Φ  , hence the entire algorithm is not polynomial time.
The rest of Section 5 is devoted to proving Theorem 5.4.The general idea is that any two nonisomorphic patterns are distinguished by an input tree where every node, apart from leaves, has a large number of children of every color.To generate a distinguishing input, first a finite labeled tree  of the appropriate depth will be chosen, for example: Then every edge in  will be cloned into several copies: Finally, the resulting graph will be unfolded into a tree, with the result being: (2) We will show that, for an appropriate , cloning every edge into sufficiently many copies will be enough to distinguish any two given patterns.Actually  will not be particularly complicated, it will simply be a large complete tree of the appropriate depth.
To make these ideas precise, we shall consider trees edge-labeled with algebraic expressions that will denote the varying number of copies for every edge.

Symbolic trees
Our proof will rely on a representation of sets of input trees, which is called symbolic trees.Intuitively speaking, a symbolic tree is a tree, where each edge is labelled by a pair consisting of a colour from a finite set and a multivariate polynomial with integer coefficients.In the following picture the colours are red and blue, and the polynomials use variables  and : The formal definition of symbolic trees, given below, defines them as the least set closed under taking linear combinations of pairs (colour, smaller symbolic tree).One should think of such a linear combination as representing a tree where the elements of the linear combination are child subtrees, and the coefficients describe the polynomials; in particular, the zero linear combination represents a symbolic tree with a root node and no children.As mentioned before, a symbolic tree can be represented by a tree with edges labelled by pairs (colour, polynomial).This representation is not unique.For example, here are two representations of the same symbolic tree: The representation does become unique if we require that one cannot have two edges that have the same source, same colour (but possibly different polynomials), and isomorphic subtrees.Symbolic trees are similar to trees modulo bisimulation; the latter would correspond to Definition 5.5 if we used the Boolean semiring instead of the ring of polynomials Z[ ].
A weighted tree is the special case of a symbolic tree where the set of variables  is empty.This is a tree with possibly negative integer weights on edges.A weighted tree is called positive if all of its weights are positive.Such a tree is the same as an isomorphism class of usual, non-weighted, trees.
The purpose of symbolic trees is to generate weighted trees.This is done by substituting integer values for the variables.If  is a symbolic tree and ā ∈ Z  is a choice of integer parameters for its variables such that the value of every polynomial in  is positive, then we write  ( ā) for the tree that arises by substituting the parameters in each polynomial, and then unfolding the resulting weighted tree as illustrated in (2).
For our proof, we only care about positive weighted trees.One way to generate such trees is to use positive parameters and symbolic trees where all polynomials use only positive coefficients.However, this restriction would be too strong.For example, a typical polynomial that will arise in our proof will be  ( ) (see Example 4), which counts non-repeating -tuples.Although this polynomial has negative coefficients, it is ultimately positive: there is some  such that if all parameters are larger than  then the value of the polynomial is positive.This is the same as saying that all monomials of maximal degree have positive coefficients.In the proof below, we will only work with symbolic trees that are ultimately positive, i.e. all polynomials used in them are ultimately positive.For such symbolic trees, all sufficiently large parameters generate positive weighted trees.
Our first observation is that different symbolic trees will generate non-isomorphic trees for many choices of parameters.
Lemma 5.6.If two symbolic trees  and  over the same variables are not equal, then for every integer  there is a combination ā of parameters larger than  such that  ( ā) ≠  ( ā).
Proof.Let  1 , . . .,   be all the polynomials present in  and , listed without repetition.For any  there is a combination ā of parameters larger than  such that all values   ( ā) are pairwise different.Then  can be reconstructed from  ( ā) by looking at degrees of all nodes, starting from the leaves, and similarly for  and  ( ā). □ From the well-known Schwartz-Zippel lemma a stronger statement follows: if the parameters ā are randomly chosen from {1, . . .,  }  then the probability that  ( ā) ≠  ( ā) approaches 1 with  → ∞.However, in the following we will only need the crude Lemma 5.6.

Applying patterns to symbolic trees
Consider a symbolic tree , and a pattern Φ.If we choose some parameters ā sufficiently large for all polynomials in  being positive, and apply Φ to  ( ā), then we get some output tree.The following lemma shows that the dependence of the output tree on the parameter ā can be described using a symbolic tree.In other words, the lemma gives a way to apply patterns to symbolic trees.
Lemma 5.7.Let Φ be a pattern and let  be a symbolic tree with variables  .There exists a symbolic tree  with the same variables  , such that for all sufficiently large parameters ā.
Proof.See Appendix A. Note that thanks to Lemma 5.6, the symbolic tree  is unique.□ Example 14.Consider a simple scenario where the input trees and the patterns are of height one, and there is only one input label (i.e., input trees are effectively unlabelled).For the very simple symbolic input tree  and the pattern Φ as seen below, the symbolic tree that arises from Lemma 5.7: symbolic tree t pattern Φ Φ applied to has one edge labelled with the polynomial Indeed, for  > 3, this polynomial counts embeddings of the trees that label the nodes of Φ into the tree of height one with  children of the root.Note that the polynomial retains full information about the pattern, assuming that both the pattern and all labels of its nodes are of height one.In other words, the single-edge input symbolic tree distinguishes all patterns of this shape.Lemma 5.9 below says that this is a general phenomenon, although more complex input trees will be needed to distinguish more complex patterns.□ Example 15.Remaining in the unlabelled setting, consider the following symbolic input tree  and patterns Φ 1 and Φ 2 which are identical except for the embedding between the two bottom nodes: The output trees that arise from Lemma 5.7 are the same for both patterns.In other words, the symbolic input  does not distinguish the patterns.The slightly larger tree  ′ below does:

□
Example 16.Consider a setting with two labels for edges of input trees.For the symbolic input tree  and the pattern Φ as seen below, the tree that arises from Lemma 5.7 is shown on the right: symbolic input tree t Φ applied to t pattern Φ Indeed, substituting any positive numbers for the   's (with  4 ,  5 > 2), the output tree instance is the result of applying Φ to the input tree instance.□ We will only apply the Lemma 5.7 to symbolic trees which are free, meaning that all polynomials in them are pairwise distinct variables, as in Examples 14-16.We will also require the symbolic trees to be sufficiently large for Φ, in the following sense: Definition 5.8.A tree  is large for a class of trees  if for every tree  ∈  and its substructure  ′ (that is, a "pruned" tree that arises from  by removing some subtrees), every embedding of  ′ into  extends to an embedding of  into .
Every finite set of trees admits some large tree; it is enough to take a complete tree of large height and large degree.
We now state the main technical result in this section, which is that if we apply a pattern to a symbolic input tree that is free and large, then the output symbolic tree uniquely identifies the pattern.Using the notation from the statement of Lemma 5.7, this lemma says that Φ can be reconstructed from .
Lemma 5.9.Let Φ 1 and Φ 2 be patterns, and let  be a tree that is large for the set of trees that are present as node labels in either of the two patterns.View  as a free symbolic tree, with the variables being the edges of , and consider the two output symbolic trees that arise by applying Φ 1 and Φ 2 to it.If these output symbolic trees are equal, then the patterns Φ 1 and Φ 2 are isomorphic.

Proof. See Appendix B. □
To complete the proof Theorem 5.4, suppose that Φ 1 and Φ 2 are non-isomorphic patterns.Choose some large finite tree  5.9.Since the symbolic trees Φ 1 () and Φ 2 () are not equal, by Lemma 5.6, there must be some choice of parameters ā such that applying Φ 1 and Φ 2 to the input tree  ( ā) yields non-isomorphic outputs, thus proving Theorem 5.4.

DECIDING EQUIVALENCE FOR POLYREGULAR FUNCTIONS ON MULTISET TYPES
So far we have solved the equivalence problem for quantifier-free tree-to-tree interpretations on trees of bounded height.We shall now generalize that to polyregular functions on arbitrary multiset types.The more important part of the generalization is the ability of polyregular functions to use quantifiers; in this sense, the proof of the theorem below will amount to a quantifier elimination procedure that will reduce the problem to the quantifier-free case from Section 5. Theorem 6.1.The following problem is decidable: Instance.Two polyregular functions between multiset types  ,  : Σ → Γ given as first-order interpretations, or as derivations.Question.Are the functions equivalent in the following sense: for every input, the two outputs are isomorphic?
Since the proof of Theorem 4.4 is effective, i.e. for every first-order interpretation we can compute a corresponding derivation and vice versa, the representation of the input is not important as long as decidability is concerned.
We will prove Theorem 6.1 by reducing it to the equivalence problem for quantifier-free tree-totree interpretations that was shown decidable in Theorem 5.1.The reduction is non-elementary, i.e. both its running time and the size of the output instance are towers of exponentials whose height is polynomial in the input size.

Quantifier elimination
The most important part of the reduction is a quantifier-elimination result, given in Lemma 6.2 below.The idea is that every structure of a multiset type can be labelled with extra information so that first-order formulas can be replaced by quantifier-free formulas.
To formalise the notion of labelling, we use non-copying interpretations.These are interpretations in which there is only one component, and it has dimension one.For such an interpretation, the universe of the output structure can be regarded as a subset of the universe of the input structure.
Recall that the quantifier rank of a first-order formula is the maximal nesting of its quantifiers.For a rank  ∈ {0, 1, . ..}, the  -theory of a structure  with distinguished elements ā ∈   is the set of all first-order rank- formulas with  free variables that are satisfied in it.(This is often called the  -type, but we should not overload the word "type".)Lemma 6.2.For every multiset type Σ and numbers ,  ≥ 0, there is a multiset type Γ and a surjective3 non-copying interpretation  : Γ → Σ, such that for every rank- formula  ( 1 , . . .,   ) over the vocabulary of Σ there is a quantifier-free formula  ( 1 , . . .,   ) over the vocabulary of Γ such that for every structure  ∈ Γ and every tuple ā ∈   : , ā |=  iff all elements of ā are in the universe of  () and  (), ā |= .
Proof.See Appendix C. □ 6.2 Reduction to Theorem 5.1 We now use quantifier elimination from Lemma 6.2 to reduce the problem in Theorem 6.1, about equivalence for polyregular functions on multiset types, to the already solved problem from Theorem 5.1, about equivalence for quantifier-free interpretations on tree types.Consider an instance of the equivalence problem in Theorem 6.1.Apply Lemma 4.3 to the output type Γ, yielding some encoding: The encoding is injective, since it admits an inverse decoding.As a result, appending it to both functions does not change the answer to the equivalence problem.
Let  be the maximal quantifier rank among all of the first-order formulas used by the above two interpretations.Apply Lemma 6.2 yielding some surjective function  as in the following diagram: Because  is surjective, prepending it to the diagram does not change the answer to the equivalence problem.By the quantifier-elimination properties in Lemma 6.2, the two functions of type Γ ′ → M  1 in the above diagram are quantifier-free interpretations.
So far, we have managed to reduce the equivalence problem to the special case of quantifier-free interpretations that output unlabelled trees.The last remaining step in the reduction to Theorem 5.1 is turning the input type into trees.This works thanks to the following fact: Lemma 6.3.For every multiset type Γ there is a finite multiset type Δ, numbers ,  ∈ {0, 1, . ..} and a surjective quantifier-free interpretation times, with trees using edge representation → Γ.
Proof.Induction on Γ.For types of the form MΣ, use the fact that if an interpretation  is surjective and quantifier-free then so is M .□

Connections with the string-to-string case
In Theorem 6.1, we proved decidability of equivalence for tree-to-tree interpretations, with the trees being unordered and of bounded height.Decidability of the equivalence problem for string-to-string interpretations remains open.We finish this section with some comments about the connection between these two problems.As we explain below, these two problems are incomparable, because (1) as inputs, strings are more general than trees of bounded height; and (2) as outputs, trees of bounded height (in fact, height two) are more general than strings.In particular, a common generalisation of both problems would be interpretations that input strings and output trees of bounded height.Below, we give informal explanations for (1) and (2) above.Consider two interpretations: an injective interpretation from strings to trees of height at most two a subtree with n leaves represents the n-th input position a is viewed as a list subtrees an surjective interpretation from strings to trees of height at most k ↦ ↦ (()( ( ) )()( (()() () ) () The injective interpretation shows that trees of height two are harder than strings as outputs.The surjective one shows that strings are harder than trees of bounded height as inputs; the height bound on trees is needed there so that the interpretation can match brackets.We believe that the ideas developed in this paper, together with above representation of output strings as trees, might be useful in the solution of the string-to-string problem.

APPLICATIONS TO GRAPHS OF BOUNDED TREE DEPTH
In this section, we apply the results on tree-to-tree transducers to graph-to-graph transducers.The graphs in this section are undirected and without parallel edges.We use a straightforward representation of a graph as a structure: the universe is the vertices, and there is one binary relation describing the edges.Choosing another representation, such as having edges in the universe, would give the same results.We use fo interpretations to transform graphs into other graphs.
We would like to decide equivalence for fo interpretations that describe graph-to-graph functions.The problem is undecidable in general, even for interpretations with Boolean outputs.This is because the following satisfiability problem is undecidable: given a first-order sentence, decide if it is true in some finite graph [Courcelle and Engelfriet 2012, Theorem 5.5].A classical approach to working around this limitation is to consider graphs that are similar to trees.Several graph parameters can be used to formalize similarity to trees, with three important parameters being: tree-depth [Nešetřil and de Mendez 2012, Section 6.2], tree-width [Courcelle and Engelfriet 2012, Section 4.1] and clique-width [Courcelle and Engelfriet 2012, Section 4.3].The parameters are related as follows: every class of graphs satisfies the following implications bounded tree-depth ⇒ bounded tree-width ⇒ bounded clique-width.
For graphs of bounded clique-width (and therefore also for graphs of bounded tree-depth or treewidth), satisfiability is decidable, even if fo logic is extended to mso logic [Courcelle and Engelfriet 2012, Theorem 5.80].It is not known if one can decide equivalence for fo interpretations between graphs of bounded clique-width.In fact, the problem is open already for tree-width, even for tree-width 1 and dimension 1, see [Bojańczyk and Schmude 2020, p.7].We present the first progress on this problem: we show that the equivalence problem is decidable for bounded tree-depth, for interpretations of arbitrary dimension.We begin by defining tree-depth.Definition 7.1.A graph has tree-depth  = 1 if it has no edges.A graph has tree-depth at most  > 1 if there is a vertex, such that after removing that vertex, all connected components have tree depth at most  − 1.
Theorem 7.2.The following problem is decidable: Instance.Two fo interpretations, which input graphs of tree-depth at most  and output graphs of tree-depth at most ℓ.Question.Are the interpretations equivalent in the following sense: for every input, the two output graphs are isomorphic?
Before proving the theorem, let us make two remarks.First, the above problem would remain decidable if mso logic was used instead of fo logic.This is because, as we have mentioned before, fo and mso have the same expressive power on graphs of bounded tree-depth [Elberfeld et al. 2016, Theorem 1.1].The second remark is about how the instances of the decision problem are represented.We use the following representation: we are given the bounds  and ℓ on the tree-depth, well as a first-order interpretation that uses the vocabulary of graphs.The interpretation should have the property that if the input graph has tree-depth at most , then the output graph has tree-depth at most ℓ.This property is decidable, since fo logic is decidable on graphs of tree-depth at most , and there is a fo formula that checks if a graph has tree-depth at most ℓ.
We now proceed to prove Theorem 7.2.The difficulty in the theorem is that there is an implicit isomorphism check, i.e. the two interpretations might produce isomorphic graphs in different ways.This difficulty was already present in Theorems 5.1 and 6.1, because bounded-height trees also have non-trivial isomorphisms.As it turns out, that difficulty has already been addressed: Theorem 7.2 is proved by a relatively straightforward reduction to the case of multiset types from Theorem 6.1.The key step is to represent graphs of bounded tree-depth using multiset types: Lemma 7.3.For every  ∈ {1, 2, . ..} there are: (1) a surjective interpretation from some multiset type to graphs of tree-depth at most ; (2) an injective interpretation from graph of tree-depth at most  to some multiset type.
Before proving the lemma, we use it to complete the proof of Theorem 7.2.Consider an instance of the problem in the theorem.Apply Lemma 7.3, yielding a surjective interpretation onto the input graphs, and an injective interpretation from the output graphs, as shown in the following diagram: where G  (and G ℓ ) denote the class of graphs of tree-depth at most  (and ℓ).The equivalence of  1 and  2 is the same as the equivalence of the two paths in the diagram that go from Σ to Γ, and these paths represent interpretations between multiset types.For such interpretations, equivalence is decidable by Theorem 6.1.It remains to prove the lemma.
Proof of Lemma 7.3.In the proof, it will be convenient to work with vertex-labelled graphs.For a finite set Σ, let us write G  Σ for the class of graphs that have tree-depth at most , with vertices labelled by elements of Σ.Such graphs are viewed as structures in the same way as unlabelled graphs, with an additional unary predicate () for each possible label  ∈ Σ. Ultimately we care about unlabelled graphs, i.e. the case of Σ = 1, but the induction proofs will use other choices of Σ.
Surjective.We begin describing a surjective interpretation from some multiset type to G  Σ, for every finite set Σ.The interpretation is defined by induction on .For  = 1, there is nothing to do, since a graph of tree-depth 1 is nothing but a multiset of vertices, and therefore G 1 Σ = MΣ.
Consider now the induction step, where we already have a surjective interpretation for tree-depth , and we now want to define it for  + 1.By definition, a graph of tree-depth at most  + 1 has some distinguished vertex , such that after removing this vertex, every connected component has strictly smaller tree-depth.Therefore, in order to represent such a graph, it is enough to give: (a) the label of the removed vertex; (b) the multiset of graphs that represent the connected components after removing the vertex; and (c) for each vertex that is not removed, one bit of information that says if it was connected to the removed vertex by an edge.This is formalized in the following claim: Claim 7.4.For every finite set Σ of labels, there is a surjective interpretation Proof.The interpretation maps an element of the input type to a graph in the natural way: it takes the disjoint union of the graphs in the multiset from the second coordinate, adds a new vertex with the label from the first coordinate, connects this new vertex to the vertices in the disjoint union that have a 1 value on the extra bit, and removes this extra bit.This function is surjective by definition of tree-depth, and it is easily seen to be a first-order interpretation.□ Combining the above claim with an inductively defined interpretation from some multiset type to G  (Σ × {0, 1}), we get the desired surjective interpretation from a multiset type to G +1 Σ.
Injective.We now present an injective interpretation from graphs of tree-depth at most  to a multiset type.The rough idea is to use the inverse of the surjective interpretation described above.However, the rough idea needs some work, since there can be several choices for the removed vertex, and there might be no way of choosing a unique removed vertex.The solution is to output all possible choices, aggregated using a multiset.This is expressed in the following claim.
Claim 7.5.For every finite set Σ of labels, there is an injective interpretation Proof.This interpretation is defined as follows.Consider a vertex  of an input graph , and let  be a connected component of the graph obtained by deleting  in .Similarly to Claim 7.4, define   to be the graph with labels from Σ × Bool that is obtained from  by adding to the label of each vertex one bit of information that says if that vertex is connected to the deleted vertex  by an edge.The interpretation in the claim maps a graph  to is a vertex of  such that after removing it, every connected component has tree-depth at most This interpretation is injective, because it inverses the function from Claim 7.4 in the following sense: if we apply the function from this claim to a graph in G +1 Σ, and then apply the interpretation from Claim 7.4 to each element of the resulting multiset, then we get a multiset that contains several copies of the original input graph.
It remains to prove that the function described above is indeed a fo interpretation.The main observation is that the criterion for  in the outermost multiset is definable in fo logic assuming that the input graph has bounded tree-depth.The reason is that, although fo logic cannot define graph connectivity in general, it can do so for graphs of bounded tree-depth, because in graphs of tree-depth , paths have length at most 2  .Therefore, the operation described in this claim can be defined using a fo interpretation.This interpretation has dimension two, because elements of the output multiset of multisets are represented using pairs (, ) such that  is a deleted vertex and  is one of the remaining vertices.□ Similarly to the surjective case, the injective case is proved by induction on  using the above claim in the induction step.This completes the proof of Lemma 7.3.□ Claim A.2.If two nodes of the output tree Φ( ( ā)) have the same profile, then they have isomorphic subtrees in the output tree.
Proof.Suppose that both profiles use the same node , and the corresponding embeddings are  1 ,  2 : Φ() ↩→  ( ā).Since the profiles of the two embeddings are the same,  1 and  2 are equalised by the origin homomorphism (3).As a result, there is an automorphism  of the input tree  ( ā) that makes the following diagram commute: This automorphism witnesses isomorphism of the trees in the statement of the claim.□ Thanks to the above claim, for every profile and every choice of parameters ā there is a unique tree that arises as a subtree of the output tree that is rooted in a node with the given profile.We will show that this unique tree is in fact obtained by instantiating, with parameters ā, a certain symbolic tree that does not depend on ā.This will complete the proof of Lemma 5.7, since the entire output tree is obtained from the symbolic tree arising from the root profile.
The symbolic tree corresponding to a profile is defined by induction on the tree of profiles, starting with the leaves.If a profile is a leaf in the tree of profiles, then the corresponding subtree of the output tree has only one node, and no polynomials are used (since there are no edges).
Consider now a profile (, ℎ) that is not a leaf in the tree of profiles.The symbolic tree for the profile (, ℎ) is defined as follows: for every child (, ) we take the inductively defined symbolic tree, and connect it to the root by an edge that is labelled by a certain polynomial that counts embeddings: Claim A.3.Let (, ) be a profile that has a defined parent profile (, ℎ).There is a polynomial  ∈ Z[ ] such that for all sufficiently large parameters ā ∈ N  ,  ( ā) is the number of ways in which an embedding  : Φ() ↩→  ( ā) with profile (, ℎ) can be extended to an embedding  : Φ() ↩→  ( ā) with profile (, ).
Proof.The following diagram illustrates the various tree embeddings and homomorphisms involved:

□
Using the polynomial from the above claim, it is easy to define the symbolic tree for a profile (, ℎ); it is the linear combination ∑︁ (,) (polynomial from Claim A.3) • (symbolic tree for (, )).
This completes the proof of Lemma 5.7.□ B PROOF OF LEMMA 5.9 In the proof, it will be more convenient to work with a single pattern, and to analyze the different profiles for that pattern.We can merge any two patterns Φ 1 and Φ 2 into a single pattern Φ, by joining them with a common root that is labelled by a singleton tree.In the pattern Φ, the root has two children  1 and  2 that correspond to the patterns Φ 1 and Φ 2 .Since each of the nodes   is labelled by a singleton tree, it admits a unique homomorphism ℎ  to the symbolic tree .Consider two profiles ( 1 , ℎ 1 ) and ( 2 , ℎ 2 ) corresponding to these nodes.Recall that in the proof of Lemma 5.7, we showed that for every profile there is a unique symbolic tree that describes the corresponding subtree in the output tree; we call this tree the symbolic tree of the profile.The symbolic trees of the profiles ( 1 , ℎ 1 ) and ( 2 , ℎ 2 ) are the same, respectively, as the symbolic trees of the patterns Φ 1 and Φ 2 .At the end of this proof, we will show in Claim B.3 that if the symbolic trees of the profiles ( 1 , ℎ 1 ) and ( 2 , ℎ 2 ) are equal, then the patterns Φ 1 and Φ 2 are isomorphic, thus completing the proof of the lemma.
Recovering a tree from a polynomial.The general idea is that the structure of a profile and its descendants can be determined by a syntactic analysis of the polynomials that appear in its symbolic tree.We begin some simple observations used in this syntactic analysis.For a tree homomorphism ℎ, define its multiset (ℎ) to be the multiset of edges in the target tree which says how many times each edge of the target tree is produced by some edge in the source tree.Consider the symbolic tree of a profile (, ℎ) in some pattern Φ, for some symbolic input tree  which is free.Like any symbolic tree, this symbolic tree is a linear combination ∑︁ where  is a finite set of smaller symbolic trees and each coefficient   is a polynomial that uses the same variables as the symbolic input tree; these variables are the edges of the tree .Take some  ∈ .The polynomial   assigns to each monomial some coefficient.Since monomials can be viewed as multisets of variables, and the variables in this case are the edges of the tree , we can view the polynomial   as a function from multisets of edges in  to integers.Of course, only finitely many multisets are assigned nonzero coefficients.Furthermore, since the polynomial   is ultimately positive, the monomials of maximal degree (which correspond to inclusion-wise maximal multisets of edges in ) have positive coefficients.The following claim shows that the coefficients for monomials of maximal degree reveal certain information about the children of a profile.
Claim B.1.Let (, ℎ) be a profile for some pattern Φ and some free symbolic tree , with the symbolic tree of the profile equal to some ∑︁  ∈   • .
Let  ∈  and let  be a multiset of edges in the tree .In the polynomial   , the coefficient of (the monomial corresponding to) the multiset of edges  is equal to the number of profiles (, ), which: (1) are children of (, ℎ) in the profile tree; (2) have the symbolic tree equal to ; (3) satisfy  = () − (ℎ).
Proof.Follows from the construction used in the proof of Claim A.3, for the special case of  being free.□ Isomorphisms between profiles.Using Claim B.1 we will recover a profile from its symbolic output tree.This will only be possible up to an isomorphism of profiles, and we begin by making precise the notion of profile isomorphism.
For two profiles ( 1 , ℎ 1 ) and ( 2 , ℎ 2 ), a shallow isomorphism is defined to be an isomorphism between the two trees Φ( 1 ) and Φ( 2 ) that is consistent with the homomorphisms in the sense that the following diagram commutes: If the profile is injective, which means that its homomorphism is injective, then its shallow isomorphism class is determined by the image of its homomorphism, which is an induced subtree of .This image is stored in the mulitiset (ℎ), which is non-repeating in the case when ℎ is injective.This observation is summarised in the following claim.
What we actually care about is deep isomorphism between profiles, which corresponds to isomorphism of entire patterns.A deep isomorphism between two profiles ( 1 , ℎ 1 ) and ( 2 , ℎ 2 ) is defined to be a bijection  between the subtrees of these profiles in the tree of profiles, together with a family of shallow isomorphisms {( 1 ,  1 )  ( 1 , 1 ) / /  ( 1 ,  1 )} ( 1 , 1 ) , indexed by profiles in the subtree of ( 1 , ℎ 1 ), such that the shallow isomorphisms in the family are consistent with the extension structure of profiles.Equipped with this notion of deep isomorphism, we are ready to state the main claim in the proof of Lemma 5.9.
Claim B.3.Let Φ be a pattern, and let  be a free symbolic tree that is large for all trees that appear as node labels in Φ.Let ( 1 , ℎ 1 ) and ( 2 , ℎ 2 ) be two injective profiles that admit a shallow isomorphism.
Before proving the claim, we use it to complete the proof of Lemma 5.9.Consider two patterns Φ 1 and Φ 2 as in the assumption of the lemma, and consider the pattern Φ constructed by taking the union of two patterns Φ 1 and Φ 2 joined by a common root, as described before.The profiles ( 1 , ℎ 1 ) and ( 2 , ℎ 2 ) that correspond to the roots of Φ 1 and Φ 2 will admit a deep isomorphism if and only if the patterns are isomorphic.Also, the profiles are trivially injective, since the labels of the nodes  1 and  2 are singleton trees; for the same reasons the profiles admit a shallow isomorphism.The symbolic trees of Φ 1 and Φ 2 are the same as the symbolic trees of ( 1 , ℎ 1 ) and ( 2 , ℎ 2 ).If these symbolic trees are equal, then we can use Claim B.3 to conclude that the patterns are isomorphic.
It remains to prove Claim B.3.
Definition 5.5.For finite sets Σ and  , set of symbolic trees with edge colours in Σ and variables  is the least solution  to the inequality  ⊇ finite formal linear combinations of Σ ×  with coefficients in Z[ ].
For every edge  of the symbolic tree , define   the number of edges mapped to  by the homomorphism ℎ ℓ  the number of edges mapped to  by the homomorphism  Note that   ≤ ℓ  .Then put: ( ā) =  ∈edges of  ℓ  −1 = ((polynomial labelling the edge  in ) − ).