scieee AI-readable full text Open interactive document viewer

Decidable classes of tree automata mixing local and global constraints modulo flat theories

Barguño, Luis,Creus López, Carles,Godoy Balil, Guillem,Jacquemard, Florent,Vacher, Camile

Abstract

We define a class of ranked tree automata TABG generalizing both the tree automata with local tests between brothers of Bogaert and Tison (1992) and with global equality and disequality constraints (TAGED) of Filiot et al. (2007). TABG can test for equality and disequality modulo a given flat equational theory between brother subterms and between subterms whose positions are defined by the states reached during a computation. In particular, TABG can check that all the subterms reaching a given state are distinct. This constraint is related to monadic key constraints for XML documents, meaning that every two distinct positions of a given type have different values. We prove decidability of the emptiness problem for TABG. This solves, in particular, the open question of the decidability of emptiness for TAGED. We further extend our result by allowing global arithmetic constraints for counting the number of occurrences of some state or the number of different equivalence classes of subterms (modulo a given flat equational theory) reaching some state during a computation. We also adapt the model to unranked ordered terms. As a consequence of our results for TABG, we prove the decidability of a fragment of the monadic second order logic on trees extended with predicates for equality and disequality between subtrees, and cardinality.

Full text

Logical Methods in Computer Science Vol. 9(2:01)2013, pp. 1–39 www.lmcs-online.org Submitted Sep. 28, 2012 Published Apr. 2, 2013 DECIDABLE CLASSES OF TREE AUTOMATA MIXING LOCAL AND GLOBAL CONSTRAINTS MODULO FLAT THEORIES ∗ LUIS BARGU˜ N´ Oa, CARLES CREUS b, GUILLEM GODOY c, FLORENT JACQUEMARD d, AND CAMILLE VACHER e a,b,c Universitat Polit`ecnica de Catalunya, Jordi Girona 1, Barcelona, Spain e-mail address:{luisbargu,ccreuslopez}@gmail.com, ggodo[email protected]c.edu dINRIA Saclay, LSV-CNRS/ENS Cachan e-mail address: floren[email protected]han.fr eLIFL, Univ. Lille I, INRIA Lille, 40 avenue Halley, 59650 Villeneuve d’Ascq, France e-mail address: vac[email protected]han.fr Abstract. We define a class of ranked tree automata TABG generalizing both the tree automata with local tests between brothers of Bogaert and Tison (1992) and with global equality and disequality constraints (TAGED) of Filiot et al. (2007). TABG can test for equality and disequality modulo a given flat equational theory between brother subterms and between subterms whose positions are defined by the states reached during a computation. In particular, TABG can check that all the subterms reaching a given state are distinct. This constraint is related to monadic key constraints for XML documents, meaning that every two distinct positions of a given type have different values. We prove decidability of the emptiness problem for TABG. This solves, in particular, the open question of the decidability of emptiness for TAGED. We further extend our result by allowing global arithmetic constraints for counting the number of occurrences of some state or the number of different equivalence classes of subterms (modulo a given flat equational theory) reaching some state during a computation. We also adapt the model to unranked ordered terms. As a consequence of our results for TABG, we prove the decidability of a fragment of the monadic second order logic on trees extended with predicates for equality and disequality between subtrees, and cardinality. 2012 ACM CCS: [Theory of computation]: Formal languages and automata theory—Tree languages; Logic—Higher order logic. Key words and phrases: Logic, symbolic constraints, tree automata, XML processing. ∗A preliminary version [BCG+10] appeared in the Proceedings of the 25th Annual IEEE Symposium on Logic In Computer Science (LICS 2010). Here, we generalize the results by allowing the constraints to be interpreted modulo a flat equational theory, and make the results stronger and easier to follow by presenting completely new proofs for the part on arithmetic constraints. a,b,c The first three authors were supported by the FORMALISM project (TIN2007-66523), by the SweetLogics project (TIN2010-21062-C02-01), and by an FI-DGR grant. d,e The last two authors were supported by the Future and Emerging Technologies (FET) program under the FET-Open grant agreement FOX number FP7-ICT-23359, and by the INRIA ARC 2010 project ACCESS. LOGICAL METHODS l IN COMPUTER SCIENCE DOI:10.2168/LMCS-9(2:01)2013 c L. Barguñó, C. Creus, G. Godoy, F. Jacquemard, and C. Vacher CC Creative Commons 2 L. BARGU˜ N´ O, C. CREUS, G. GODOY, F. JACQUEMARD, AND C. VACHER 1. Introduction Tree automata techniques are widely used in several domains like automated deduction (see e.g. [CDG+07]), static analysis of programs [BT05] or protocols [VGL07, FGVTT04], and XML processing [Sch07]. However, a severe limitation of standard tree automata (TA) is that they are not able to test for equality (isomorphism) or disequality between subterms in an input term. For instance, the language of terms matching a non-linear pattern such as f(x, x) is not regular (i.e. there exists no TA recognizing this language). Let us illustrate how this limitation can be problematic in the context of XML documents processing. XML documents are commonly represented as labeled trees, and they can be constrained by XML schemas, which define both typing restrictions and integrity constraints. All the typing formalisms currently used for XML are based on finite tree automata. The key constraints for databases are common integrity constraints expressing that every two distinct positions of a given type have different values. This is typically the kind of constraints that can not be characterized by TA. One first approach to overcome this limitation of TA consists in adding the possibility to make equality or disequality tests at each step of the computation of the automaton. The tests are performed locally, between subterms at a bounded distance from the current computation position in the input term. The emptiness problem, i.e. whether the language recognized by a given automaton is empty, is undecidable with such tests [Mon81]. A decidable subclass is obtained by restricting the tests to sibling subterms [BT92] (see [CDG+07] for a survey). Another approach was proposed more recently in [FTT07, FTT08] with the definition of tree automata with global equality and disequality tests (TAGED). The TAGED do not perform the tests during the computation steps but globally on the term, at the end of the computation, at positions which are defined by the states reached during the computation. For instance, they can express that all the subterms that reached a given state qare equal, or that every two subterms that reached respectively the states qand q′are different. Nevertheless, arbitrary disequalities are not allowed in TAGED, since such qand q′must be different. The emptiness has been shown decidable for several subclasses of TAGED [FTT07, FTT08], but the decidability of emptiness for the whole class remained a challenging open question. In this paper, we answer this question positively, for a class of tree recognizers more general than TAGED. We propose (in Section 3) a class of tree automata with local constraints between siblings and global constraints (TABG) which significantly extends TAGED in several directions: (i)TABG combine global constraints a la TAGED with local equality and disequality constraints between brother subterms a la [BT92], (ii) the equality and disequality constraints are treated modulo a given flat equational theory (here flat means that both sides of the equation have the same variables and height, and that this height is bounded by 1), allowing to consider relations more general than syntactic equalities and disequalities, like e.g. structural equalities and disequalities, (iii) testing global disequality constraints between subterms that reached the same state is allowed (such test specify key constraints, which are not expressible with TAGED), (iv) the global constraints are arbitrary Boolean combinations (including negation) of atomic equality and disequality (in TAGED, only conjunction of atoms are allowed, without negation). TA WITH LOCAL AND GLOBAL CONSTRAINTS 3 In Section 4, we consider the addition to TABG of global counting constraints on the number |q|of occurrences of a given state qin a computation, or the number kqkof distinct equivalence classes (modulo the flat theory) of subterms reaching a given state qin a computation. These counting constraints are only allowed to compare states to constants, like in |q| ≤ 5 or kqk+ 2kq′k ≥ 9 (with counting constraints being able to compare state cardinalities, like in |q|=|q′|, the emptiness problem becomes undecidable). Using this formalism as an intermediate step, we show that negative literals and disjunctions can be eliminated without loss of generality in the global constraints of TABG, i.e. that TABG whose global constraints are restricted to be conjunctions of positive literals (namely positive conjunctive TABG) have already the same expressiveness of the full TABG class. In particular, the counting constraints do not improve the expressiveness of TABG. Our main result, presented in Section 5, is that emptiness is decidable for positive conjunctive TABG (and hence for TABG). The decision algorithm uses an involved pumping argument: every sufficiently large term recognized by the given TABG can be reduced by an operation of parallel pumping into a smaller term which is still recognized. The existence of the bound for the minimum accepted term is based on a particular well quasi-ordering. We show that the emptiness decision algorithm of Section 5 can also be applied to a generalization of the subclass TAG of TABG without the local constraints computing on unranked ordered labeled trees (Section 6). This demonstrates the robustness of the method. As an application of our results, in Section 7 we present a (strict) extension of the monadic second order logic on trees whose existential fragment corresponds exactly to TAG. In particular, we conclude its decidability. Related Work. TABG is a strict (decidable) extension of TAG and TA with local equality and disequality constraints, since the expressiveness of both subclasses is incomparable (see e.g. [JKV09]). The tree automata model of [BT92] has been generalized from ranked trees to unranked ordered trees into a decidable class called UTASC [WL07, LW09]. In unranked trees, the number of brothers (under a position) is unbounded, and UTASC transitions use MSO formulae (on words) with 2 free variables in order to select the sibling positions to be tested for equality and disequality. The decidable generalization of TAG to unranked ordered trees proposed in Section 6 and the automata of [WL07, LW09] are incomparable. The combination of both formalisms could be the object of a further study. Another way to handle subterm equalities is to use automata computing on DAG representation of terms [Cha99, ANR05]. This model is incomparable to TAG whose constraints are conjunctions of equalities [JKV09]. The decidable extension of TA with one tree shaped memory [CC05] can simulate TAG with equality constraints only, providing that at most one state per run can be used to test equalities [FTT07]. We show in Section 3 that the TABG strictly generalize the TAGED of [FTT07, FTT08]. The latter have been introduced as a tool to decide a fragment of the spatial logic TQL [FTT07]. Decidable subclasses of TAGED were also shown decidable in correspondence with fragments of monadic second order logic on the tree extended with predicates for subtree (dis)equality tests. In Section 7, we generalize this correspondence to TAG and a more natural extension of MSO. There have been several approaches to extend TA with arithmetic constraints on cardinalities |q|described above: the constraints can be added to transitions in order to count between siblings [SSM03, DL06] (in this case we could call them local by analogy with 4 L. BARGU˜ N´ O, C. CREUS, G. GODOY, F. JACQUEMARD, AND C. VACHER equality tests) or they can be global [KR02]. We compare in Section 4 the latter approach (closer to our settings) with our extension of TABG, with respect to emptiness decision. To our knowledge, this is the first time that arithmetic constraints on cardinalities of the form kqkare studied. 2. Preliminaries 2.1. Terms, Positions, Replacements. We use the standard notations for terms and positions, see [BN98]. A signature Σ is a finite set of function symbols with arity. We sometimes denote Σ explicitly as {f1:a1,...,fn:an}where f1,...,fnare the function symbols, and a1,...,anare the corresponding arities, or as {f1,...,fn}when the arities are omitted. We denote the subset of function symbols of Σ of arity mas Σm. The set of (ranked) terms over the signature Σ is defined recursively as T(Σ) := {f(t1,...,tm)| f:m∈Σ, t1,...,tm∈ T (Σ)}. Note that the base case of this definition is {f|f: 0 ∈Σ}, which coincides with Σ0by omitting the arity. Elements of this subset are called constants. Positions in terms are denoted by sequences of natural numbers. With λwe denote the empty sequence (root position), and p.p′denotes the concatenation of positions pand p′. The set of positions of a term is defined recursively as Posf(t1,...,tm)={λ} ∪ {i.p |i∈ {1,...,m} ∧ p∈Pos(ti)}. A term t∈ T (Σ) can be seen as a function from its set of positions Pos(t) into Σ. For this reason, the symbol labeling the position pin tshall be denoted by t(p). By p < p′and p≤p′we denote that pis a proper prefix of p′, and that pis a prefix of p′, respectively. In these cases, p′is necessarily of the form p.p′′, and we define p′−pas p′′. Two positions p1, p2incomparable with respect to the prefix ordering are called parallel, and it is denoted by p1kp2. The subterm of tat position p, denoted t|p, is defined recursively as t|λ=tand f(t1,...,tm)|i.p =ti|p. The replacement in t of the subterm at position pby s, denoted t[s]p, is defined recursively as t[s]λ=sand f(t1,...,ti−1, ti, ti+1,...,tm)[s]i.p =f(t1,...,ti−1, ti[s]p, ti+1,...,tm). The height of a term t, denoted h(t), is the maximal length of a position of Pos(t). In particular, the length of λis 0. 2.2. Tree automata. Atree automaton (TA, see e.g. [CDG+07]) is a tuple A=hQ, Σ, F, ∆i where Qis a finite set of states, Σ is a signature, F⊆Qis a subset of final (or accepting) states and ∆ is a set of transition rules of the form f(q1,...,qm)→qwhere f:m∈Σ, q1,...,qm, q ∈Q. Sometimes, we shall refer to Aas a subscript of its components, like in QAto indicate that this is the set of states of A. Arun of Ais a pair r=ht, Miwhere tis a term in T(Σ) and M:Pos(t)→∆Ais a mapping satisfying the following statement for each p∈Pos(t): if t|pis written of the form f(t1,...,tm), and M(p.1),...,M(p.m) are rules with right-hand side states q1,...,qm∈ QA, respectively, then M(p) is a rule of the form f(q1,...,qm)→qfor some q∈QA. We write r(p) for the right-hand side state of M(p), and say that ris a run of Aon t. Moreover, by term(r) we refer to t, and by symbol(r) we refer to t(λ). The run ris called successful (or accepting) if r(λ) is in FA. The language L(A) of Ais the set of terms tfor which there exists a successful run of A. A language Lis called regular if there exists a TA Asatisfying L=L(A). For facility of explanations, we shall use term-like notations for runs defined as follows in the natural way. For a run r=ht, Mi, by Pos(r) we denote Pos(t), and by h(r) we denote h(t). Similarly, by r|pwe denote the run ht|p, M|pi, where M|pis defined as TA WITH LOCAL AND GLOBAL CONSTRAINTS 5 M|p(p′) = M(p.p′) for each p′in Pos(t|p), and say that r|pis a subrun of r. Moreover, for a run r′=ht′, M′isuch that the states r′(λ) and r(p) coincide, by r[r′]pwe denote the run ht[t′]p, M[M′]pi, where M[M′]pis defined as M[M′]p(p.p′) = M′(p′) for each p′in Pos(t′), and as M[M′]p(p′) = M(p′) for each p′with p6≤ p′. 2.3. Tree automata with local constraints between brothers. Atree automaton with constraints between brothers (defined in [BT92] and called TACBB in [CDG+07]) is a tuple A=hQ, Σ, F, ∆iwhere Q, Σ and Fare defined as for TA, but with the difference that ∆ is a set of constrained rules of the form f(q1,...,qm)C →q, where Cis a set of equalities and disequalities of the form i≈jor i6≈ jfor i, j ∈ {1,...,m}. We call Ca local constraint between brothers. By ta(A) we define the TA obtained from Aby removing all constraints from ∆. Arun of a TACBB Ais a pair r=ht, Midefined similarly to the case of TA;tis a term in T(Σ) and the mapping M:Pos(t)→∆Asatisfies the following statement for each p∈Pos(t): if t|pis written of the form f(t1,...,tm), and M(p.1),...,M(p.m) are rules with right-hand side states q1,...,qm∈QA, respectively, then M(p) is a rule of the form f(q1,...,qm)C →qfor some q∈QAand constraint between brothers C. Moreover, for each equality i≈jin C,ti=tjholds, and for each disequality i6≈ jin C,ti6=tjholds. The notions of successful run and recognized language are defined for TACBB analogously to the case of TA. 2.4. Term equations. Given a set of variables X, the set of (ranked) terms over Σ and Xis defined as T(Σ ∪ X) by considering arity 0 for the elements of X. A substitution σis a mapping from variables to terms σ:X → T (Σ ∪ X ). It is also considered as a function from arbitrary terms to terms σ:T(Σ∪X)→ T (Σ∪X) by the recursive definition σ(f(t1,...,tm)) = f(σ(t1),...,σ(tm)) for every function symbol fand subterms t1,...,tm. An equation between terms is an unordered pair of terms denoted l≈r. Given a set of equations Eand two terms s, t, we say that sand tare equivalent modulo E, denoted s=Et, if there exist terms s1, s2,...,sn, n ≥1 satisfying the following statement: s=s1, sn=t, and for each i∈ {1,...,n−1}, there exists an equation l≈rin E, a substitution σ, and a position p, such that si|p=σ(l) and si+1 =si[σ(r)]p. A flat equation is an equation l≈rwhere land rare terms satisfying h(l) = h(r)≤1, and any variable xoccurs in lif and only if xoccurs in r. A flat theory is a set of flat equations. The following technical lemma shows that equivalence modulo a flat theory is preserved by certain replacements of subterms. It will be useful in Section 5. Lemma 2.1. Let Ebe a flat theory. Let s=f(s1,...,sn),t=g(t1,...,tm),s′= f(s′ 1,...,s′ n)and t′=g(t′ 1,...,t′ m)be terms satisfying the following conditions: •For each i∈ {1,...,n},(si∈Σ0⇔s′ i∈Σ0)and (si, s′ i∈Σ0⇒si=Es′ i)hold. •For each j∈ {1,...,m},(tj∈Σ0⇔t′ j∈Σ0)and (tj, t′ j∈Σ0⇒tj=Et′ j)hold. •For each i∈ {1,...,n}and j∈ {1,...,m},(s′ i=Et′ j⇔si=Etj)holds. Then, s=Et⇔s′=Et′holds. Proof. We prove the left-to-right direction only. The other one is analogous by swapping the roles of sand tby the roles of s′and t′, respectively. 6 L. BARGU˜ N´ O, C. CREUS, G. GODOY, F. JACQUEMARD, AND C. VACHER Since s=Etholds, there exist terms u1, u2,...,uk, k ≥1 satisfying the following statement: s=u1,uk=t, and for each i∈ {1,...,k−1}, there exists an equation l≈rin E, a substitution σ, and a position p, such that ui|p=σ(l) and ui+1 =ui[σ(r)]p. We prove the statement by induction on k. For k= 1, s=tholds. Thus, gis f,mis n, and for each i∈ {1,...,n},si=tiholds. In particular, each si=Etiholds. Therefore, each s′ i=Et′ ialso holds, and hence s′=f(s′ 1,...,s′ n) =Ef(t′ 1,...,t′ n) = t′holds. Now, assume k > 1. Let l≈r,pand σbe the rule, position and substitution satisfying u1|p=σ(l) and u2=u1[σ(r)]p. Recall that u1is s. First, suppose that pis not λ. Then, p is of the form j.p′for some j∈ {1,...,n}and position p′. Note that u2|j=Eu1|jholds, and for each i∈ {1,...,n}\{j},u2|i=u1|iholds. Thus, u2is of the form f(v1,...,vn) and for each i∈ {1,...,n},vi=Esiholds. Moreover, since Eis a flat theory, the step at ppreserves the height, and hence, for each i∈ {1,...,n},vi∈Σ0⇔si∈Σ0and vi, si∈Σ0⇒vi=Esi hold. From the statement of the lemma, the following conditions follow: •For each i∈ {1,...,n}, (vi∈Σ0⇔s′ i∈Σ0) and (vi, s′ i∈Σ0⇒vi=Es′ i) hold. •For each j∈ {1,...,m}, (tj∈Σ0⇔t′ j∈Σ0) and (tj, t′ j∈Σ0⇒tj=Et′ j) hold. •For each i∈ {1,...,n}and j∈ {1,...,m}, (s′ i=Et′ j⇔vi=Etj) holds. By induction hypothesis, f(s′ 1,...,s′ n) =Eg(t′ 1,...,t′ m) holds, and we are done. Now, consider the case where pis λ. In this case s=u1=σ(l), and u2=σ(r). Since E is a flat theory, land rare of the form f(α1,...,αn) and h(β1,...,βµ), where either n, µ > 0 or n=µ= 0, and α1,...,αn, β1,...,βµare either constants or variables. Moreover, a variable occurs in lif and only if it occurs in r. Note that σ(α1) = s1,...,σ(αn) = sn holds. We call v1=σ(β1),...,vµ=σ(βµ). Note that u2=h(v1,...,vµ). We define terms v′ 1,...,v′ µas follows for each iin {1,...,µ}. If viis a constant, then we define v′ ias vi. Otherwise, if viis not a constant, then βiis a variable x. Since Eis a flat theory, some αj(we choose any) must be x. In this case we define v′ ias s′ j. With these definitions, the following conditions follow: •For each i∈ {1,...,µ}, (vi∈Σ0⇔v′ i∈Σ0) and (vi, v′ i∈Σ0⇒vi=Ev′ i) hold. •For each j∈ {1,...,m}, (tj∈Σ0⇔t′ j∈Σ0) and (tj, t′ j∈Σ0⇒tj=Et′ j) hold. •For each i∈ {1,...,µ}and j∈ {1,...,m}, (v′ i=Et′ j⇔vi=Etj) holds. By induction hypothesis, h(v′ 1,...,v′ µ) =Eg(t′ 1,...,t′ m) holds. Now, let s′′ 1,...,s′′ nbe defined as follows for each iin {1,...,n}. If s′ iis not a constant then define s′′ ias s′ i. Otherwise, if s′ iis a constant, then define s′′ ias si. By the condition (si, s′ i∈Σ0⇒si=Es′ i) we have that f(s′ 1,...,s′ n) =Ef(s′′ 1,...,s′′ n) holds. Moreover, the same rule l≈rcan be used to prove f(s′′ 1,...,s′′ n) =Eh(v′ 1,...,v′ µ). Hence, f(s′ 1,...,s′ n) =E f(s′′ 1,...,s′′ n) =Eh(v′ 1,...,v′ µ) =Eg(t′ 1,...,t′ m) holds, and we are done. 2.5. Well quasi-orderings. Awell quasi-ordering [Gal91] ≤on a set Sis a reflexive and transitive relation such that any infinite sequence of elements e1, e2,... of Scontains an increasing pair ei≤ejwith i < j. 3. Tree Automata with Global Constraints In this subsection, we define a class of tree automata with global constraints strictly generalizing both the TACBB of [BT92] and the TAGED of [FTT08]. The generalization consists TA WITH LOCAL AND GLOBAL CONSTRAINTS 7 in considering more general global constraints, and interpreting all the constraints modulo a flat equational theory. As an intermediate step, we define an extension of the TACBB of [BT92] where the local constraints between brothers are considered modulo a flat equational theory. Definition 3.1. Atree automaton with constraints between brothers modulo a flat theory (TAB) is a tuple A=hQ, Σ, F, ∆, Eiwhere hQ, Σ, F, ∆iis a TACBB and Eis a flat equational theory. By ta(A) we denote ta(hQ, Σ, F, ∆i). Arun of a TAB A=hQ, Σ, F, ∆, Eiis a pair r=ht, Midefined analogously to a run of a TACBB, except that the constraints between brothers are interpreted modulo E. More specifically, for each position pin Pos(t), if t|pis written of the form f(t1,...,tm), and M(p.1),...,M(p.m) are rules with right-hand side states q1,...,qm∈Q, respectively, then M(p) is a transition rule of ∆Aof the form f(q1,...,qm)C →qfor some q∈Qand constraint between brothers C. Moreover, for each equality i≈jin C,ti=Etjholds, and for each disequality i6≈ jin C,ti6=Etjholds. The notions of successful run and recognized language are defined for TAB analogously to the case of TA. We further extend this class TAB with global equality and disequality constraints generalizing those of TAGED [FTT08]. Definition 3.2. Atree automaton with global and brother constraints modulo a flat theory (TABG) is a tuple A=hQ, Σ, F, ∆, E, Ciwhere hQ, Σ, F, ∆, Eiis a TAB, denoted tab(A), and Cis a Boolean combination of atomic constraints of the form q≈q′or q6≈ q′, where q, q′∈Q. By ta(A) we denote ta(tab(A)). Arun of a TABG A=hQ, Σ, F, ∆, E, Ciis a run r=ht, Miof tab(A) such that rsatisfies C, denoted r|=C, where the satisfiability of constraints is defined as follows. For atomic constraints, r|=q≈q′(respectively r|=q6≈ q′) holds if and only if for all different positions p, p′∈Pos(t) such that M(p) = qand M(p′) = q′,t|p=Et|p′(respectively t|p6=Et|p′) holds. This notion of satisfiability is extended to Boolean combinations as usual. As for TA, we say that ris a run of Aon t. A run rof Aon t∈ T (Σ) is successful (or accepting) if r(λ)∈F. The language L(A) of Ais the set of terms tfor which there exists a successful run of A. It is important to note that the semantics of ¬(q≈q′) and q6≈ q′differ, as well as the semantics of ¬(q6≈ q′) and q≈q′. This is because we have a “for all” quantifier in both definitions of semantics of q≈q′and q6≈ q′. Let us introduce some notations, summarized in Figure 1 that we use below to characterize some classes of tree automata related to TABG (Figure 1 also refers to a class defined in Section 4). A TABG Ais called positive if CAis a disjunction of conjunctions of atomic constraints and it is called positive conjunctive if CAis a conjunction of atomic constraints. The subclass of positive conjunctive TABG is denoted by TABG∧. We recall that a TAB where all the constraints are empty is just a TA. For a TABG A, when the theory EAis empty and tab(A) is just a TA, we say that Ais just a tree automaton with global constraints (TAG). Its subclass with positive conjunctive constraints is denoted TAG∧. With the notation TABG[τ1,...,τm], we characterize the class of tree automata with global and brother constraints modulo a flat theory whose global constraints are Boolean 8 L. BARGU˜ N´ O, C. CREUS, G. GODOY, F. JACQUEMARD, AND C. VACHER TABG[≈,6≈,N]TABG[≈,6≈] positive TABG[≈,6≈]TABG∧[≈,6≈] TAG[≈,6≈] TAG[≈]TABG[≈]TABG[6≈]TAG[6≈] TAB TACBB TA : effective strict inclusion : effective equivalence Figure 1: Decidable classes of TA with local and global constraints combination of atomic constraints of types τ1,...,τm. The types ≈and 6≈ denote respectively the atomic constraints of the form q≈q′and q6≈ q′, where q, q′are states. For instance, the abbreviation TABG used in Definition 3.2 stands for TABG[≈,6≈]. This notation is extended to the positive conjunctive fragment by TABG∧[τ1,...,τk] and to the fragment without local constraints between brother, by TAG[τ1,...,τk]. 3.1. Expressiveness. The class of regular languages is strictly included in the class of TABG languages due to the constraints. Example 3.3. Let Σ = {a: 0, f : 2}. The set {f(t, t)|t∈ T (Σ)}is not a regular tree language (this can be shown using a classical pumping argument). However, it is recognized by the following TAB: {q0, qf},Σ,{qf},{a→q0, f(q0, q0)→q0, f(q0, q0)−−−→ 1≈2qf},∅, and it is also recognized by the following TAG[≈]: A={q0, q1, qf},Σ,{qf},{a→q0|q1, f(q0, q0)→q0|q1, f(q1, q1)→qf},∅, q1≈q1, where t→q|qris an abbreviation for t→qand t→qr. An example of successful run of Aon t=f(f(a, a), f(a, a)) is qfq1(q0, q0), q1(q0, q0), where we use term-like notation for marking the reached state at each position. Moreover, the TAGED of [FTT08] are also a particular case of TAG[≈,6≈], since they can be redefined in our setting as restricted TAG∧[≈,6≈], where the equational theory is empty, and where qand q′are required to be distinct in any atomic constraint of the form q6≈ q′. Reflexive disequality constraints such as q6≈ qcorrespond to monadic key constraints for XML documents, meaning that every two distinct positions of type qhave different values. A state qof a TAG[≈,6≈] can be used for instance to characterize unique identifiers as in the following example, which presents a TAG[≈,6≈] whose language cannot be recognized by a TAGED. This example will be referred several times in Section 5, in order to illustrate the definitions used in the decision procedure of the emptiness problem for TAG[≈,6≈]. TA WITH LOCAL AND GLOBAL CONSTRAINTS 9 M qM 1 qid N qt 2 qd 0 qN L qL 2 qid N qt 2 qd 0 qN L qL 3 qid N qt 2 qd 0 qN L0 qL 4 qid N qt 2 qd 0 qN Figure 2: Term and successful run (Example 3.4). Example 3.4. The TAG[≈,6≈] of our running example accepts (in state qM) lists of dishes called menus, where every dish is associated with one identifier (state qid) and the time needed to cook it (state qt). We have other states accepting digits (qd), numbers (qN) and lists of dishes (qL). The TAG[≈,6≈]A=hQ, Σ, F, ∆,∅, Ciis defined as follows: Σ = {0,...,9 : 0, N, L0: 2, L, M :3},Q={qd, qN, qid, qt, qL, qM},F={qM}, and ∆ = {i→qd|qN|qid |qt: 0 ≤i≤9} ∪ {N(qd, qN)→qN|qid |qt, L0(qid, qt)→qL, L(qid, qt, qL)→qL, M(qid, qt, qL)→qM}. The constraint Censures that all the identifiers of the dishes in a menu are pairwise distinct (i.e. that qid is a key) and that the time to cook is the same for all dishes: C= qid 6≈ qid ∧qt≈qt. A term in L(A) together with an associated successful run are depicted in Figure 2. Althought this is a simple exercise, let us establish formally that TAG[≈,6≈] are strictly more expressive than TAGED. Lemma 3.5. The class of languages recognized by TAG∧[≈,6≈]strictly includes the class of languages recognized by TAGED. Proof. Since a TAGED is just a TAG∧[≈,6≈] where no constraint of the form q6≈ qoccurs, the inclusion holds. In order to see that it is strict, it suffices to show a language Lwhich can be recognized by a TAG∧[≈,6≈] but not by a TAGED. Let Σ = {a: 0, s : 1, f : 2}. The set Lof terms of T(Σ) of the form f(sn1(a), f(sn2(a), ...,f(snk(a), a)...)), such that k≥0 and the natural numbers ni, for i≤k, are pairwise distinct, is recognized by the following TAG∧[≈,6≈]: *{qa, q, qf},Σ,{qf},   a→qa|q|qf, s(qa)→qa|q, f(q, qf)→qf   ,∅, q 6≈ q+. Assume that there exists a TAG∧[≈,6≈]Awithout reflexive disequality constraints of the form q6≈ q(i.e. a TAGED), recognizing this language L. Then, there exists an accepting run rof Aon the term t=f(s(a), f(s2(a),...f(s|QA|+1(a), a)...)) ∈L. Therefore, r|=CA (the global constraint of A, which is positive by hypothesis). There are two different positions pi= i z}| { 2.2.....2.1 and pj= j z}| { 2.2.....2.1, 0 ≤i < j ≤ |QA|such that r(pi) = r(pj). Let us show that r′=r[r|pi]pjis an accepting run of Aon 16 L. BARGU˜ N´ O, C. CREUS, G. GODOY, F. JACQUEMARD, AND C. VACHER simple transformations: inequalities are inverted and equalities become disjunctions of inequalities. Third, strict inequalities are converted into non-strict by adding or subtracting 1 to a side. Fourth, by applying simple arithmetic operations all such literals are made of the required form a1kq1k+...+ankqnk⊗kor a1|q1|+...+an|qn|⊗k, for ⊗in {≥,≤,=},n > 0 and strictly positive a1,...,an. In this step, a trivially false literal is replaced by false, and a trivially true literal is replaced by true. Finally, by applying the standard transformation into disjunctive conjunctive normal form we get the desired result. In order to remove negative equality and disequality literals and positive arithmetic constraints, we use the idea of inserting new states which are synonyms of existing states. Intuitively, a synonym is a new state ˆqthat behaves analogous to an existing state ¯q, i.e. the rules and constraints are modified such that the relation of ˆqwith the other states is the same as for ¯q. Nevertheless, the constraints are further modified to ensure that, whenever ¯qoccurs in an execution, ˆqalso occurs. Moreover, all subterms reaching ˆqare the same (or equivalent modulo the relation induced by the flat theory), but are different from (nonequivalent to) the ones reaching ¯q. This way, an execution of the original automaton with occurrences of ¯qcan be transformed into an execution of the new automaton, where the occurrences of a concrete subterm (up to the equivalence relation) reaching ¯qin the original execution now reach ˆqinstead. Definition 4.5. Let A=hQ, Σ, F, ∆, E, Cibe a TABG[≈,6≈,N]. Let ¯qbe a state in Q. Let ˆqbe a state not in Q. We define F¯q❀ˆqas Fif ¯qis not in F, and as F∪ {ˆq}if ¯qis in F. We define ∆¯q❀ˆqas the set of rules obtained from the rules of ∆ with all possible replacements of occurrences of ¯qby ˆq. More formally, ∆¯q❀ˆqis {f(q′ 1,...,q′ n)→q′ n+1 | ∃f(q1,...,qn)→qn+1 ∈∆ : ∀i∈ {1,...,n+ 1}: (qi=q′ i∨(qi= ¯q∧q′ i= ˆq))}. We define C¯q❀ˆqas the constraint (k¯qk= 0 ∧ kˆqk= 0) ∨(kˆqk= 1 ∧¯q6≈ ˆq)∧C′, where C′is obtained from the normalization of Cby replacing each literal by a new formula according to the following description. •Each literal (q1≈q2) is replaced by the conjunction of the literals of the set q′ 1≈q′ 2 ((q′ 1=q1∨(q1= ¯q∧q′ 1= ˆq)) ∧(q′ 2=q2∨(q2= ¯q∧q′ 2= ˆq))). •Each literal (q16≈ q2) is replaced by the conjunction of the literals of the set q′ 16≈ q′ 2 ((q′ 1=q1∨(q1= ¯q∧q′ 1= ˆq)) ∧(q′ 2=q2∨(q2= ¯q∧q′ 2= ˆq))). •Each literal ¬(q1≈q2) is replaced by the disjunction of the literals of the set ¬(q′ 1≈ q′ 2)((q′ 1=q1∨(q1= ¯q∧q′ 1= ˆq)) ∧(q′ 2=q2∨(q2= ¯q∧q′ 2= ˆq))). •Each literal ¬(q16≈ q2) is replaced by the disjunction of the literals of the set ¬(q′ 16≈ q′ 2)((q′ 1=q1∨(q1= ¯q∧q′ 1= ˆq)) ∧(q′ 2=q2∨(q2= ¯q∧q′ 2= ˆq))). •Each occurrence of |¯q|is replaced by |¯q|+|ˆq|, and each occurrence of k¯qkis replaced by k¯qk+kˆqk. We define A¯q❀ˆqas hQ∪ {ˆq},Σ, F¯q❀ˆq,∆¯q❀ˆq, E, C¯q❀ˆqi. We write (F¯q❀ˆq)¯q′❀ˆq′for ˆq6= ¯q′and ˆq6= ˆq′more succinctly as F¯q,¯q′❀ˆq,ˆq′, and similarly for ∆¯q,¯q′❀ˆq,ˆq′,C¯q,¯q′❀ˆq,ˆq′and A¯q,¯q′❀ˆq,ˆq′. The condition (k¯qk= 0 ∧ kˆqk= 0) added to C¯q❀ˆqis necessary to satisfy L(A¯q❀ˆq) = L(A), as it is proved in Lemma 4.6. This lemma is not used in the rest of the article, since the introduction of synonyms is combined with other constraints in further transformations. Nevertheless, we preserve Lemma 4.6 since its proof gives intuition about the definition of synonyms, and the arguments are similar to other ones appearing later. TA WITH LOCAL AND GLOBAL CONSTRAINTS 17 Lemma 4.6. Let A=hQ, Σ, F, ∆, E, Cibe a TABG[≈,6≈,N]. Let ¯qbe a state in Q. Let ˆq be a state not in Q. Then, L(A¯q❀ˆq) = L(A). Proof. Accepting runs of Ahaving no occurrence of ¯qare also accepting runs of A¯q❀ˆq. An accepting run of Ahaving occurrences of ¯qcan be converted into an accepting run of A¯q❀ˆq by choosing one subterm treaching ¯qand replacing ¯qby ˆqat all positions with subterms equivalent to tby the relation induced by E. Accepting runs of A¯q❀ˆqcan be converted into accepting runs of Aby replacing each occurrence of ˆqby ¯q. The following lemma makes use of synonyms in order to remove a negative literal of the form ¬(¯q≈¯q′) preserving the language. The next one, Lemma 4.8, analogously permits to remove a negative literal of the form ¬(¯q6≈ ¯q′). Lemma 4.7. Let A=hQ, Σ, F, ∆, E, Cibe a TABG[≈,6≈,N]. Let ¯q,¯q′be states in Q. Let ˆq,ˆq′be distinct states not in Q. Let Cbe of the form ¬(¯q≈¯q′)∧C′. Let A′be hQ∪ {ˆq, ˆq′},Σ, F¯q,¯q′❀ˆq,ˆq′,∆¯q,¯q′❀ˆq,ˆq′, E, (kˆqk= 1 ∧ kˆq′k= 1 ∧ˆq6≈ ˆq′)∧C′ ¯q,¯q′❀ˆq,ˆq′i. Then, L(A′) = L(A)holds. Proof. Accepting runs of Acan be converted into accepting runs of A′as follows. First, we choose two subterms ¯ tand ¯ t′different modulo the equivalence relation induced by E and reaching ¯qand ¯q′, respectively. Note that these terms must exist in order to satisfy the literal ¬(¯q≈¯q′) of C. Second, we replace ¯qby ˆqat all the positions with subterms equivalent to ¯ tby the relation induced by E. Similarly, we replace ¯q′by ˆq′at all the positions with subterms equivalent to ¯ t′by the relation induced by E. This way, the subconstraint kˆqk= 1 ∧ kˆq′k= 1 ∧ˆq6≈ ˆq′is satisfied, but also C′ ¯q,¯q′❀ˆq,ˆq′is satisfied. Accepting runs of A′can be converted into accepting runs of Aby replacing each occurrence of ˆqby ¯q, and each occurrence of ˆq′by ¯q′. Note that the subconstraint kˆqk= 1∧ kˆq′k= 1 ∧ˆq6≈ ˆq′ensures the existence of such occurrences, and with subterms which are different modulo the equivalence relation induced by E. Thus, the literal ¬(¯q≈¯q′) of Cis satisfied. The constraint C′is also satisfied. Lemma 4.8. Consider the same assumptions as in Lemma 4.7, except that Cis of the form ¬(¯q6≈ ¯q′)∧C′and the constraint of A′is (kˆqk= 1 ∧ kˆq′k= 1 ∧ˆq≈ˆq′)∧C′ ¯q,¯q′❀ˆq,ˆq′ Then, L(A′) = L(A)holds. Proof. Analogous to the proof of Lemma 4.8. The following definition will be used to remove literals of type k.kN. Definition 4.9. Let Cbe a constraint, and let kbe a natural number. By Ck¯qk❀kwe define the constraint obtained from Cby replacing all occurrences of k¯qkby k. The following two lemmas show how to remove literals of the form kqk= 1 or kqk= 0 preserving the language. Lemma 4.10. Let A=hQ, Σ, F, ∆, E, Cibe a TABG[≈,6≈,N]. Let ¯qbe a state in Q. Let C be of the form k¯qk= 1 ∧C′. Let A′be hQ, Σ, F, ∆, E, |¯q| ≥ 1∧¯q≈¯q∧C′ k¯qk❀1i. Then, L(A′) = L(A)holds. Proof. Accepting runs of A′and Acoincide because the constraints Cand CA′have the same semantics. 18 L. BARGU˜ N´ O, C. CREUS, G. GODOY, F. JACQUEMARD, AND C. VACHER Lemma 4.11. Let A=hQ, Σ, F, ∆, E, Cibe a TABG[≈,6≈,N]. Let ¯qbe a state in Q. Let C be of the form k¯qk= 0 ∧C′. Let A′be hQ, Σ, F, ∆, E, |¯q|= 0 ∧C′ k¯qk❀0i. Then, L(A′) = L(A)holds. Proof. Accepting runs of A′and Acoincide because the constraints Cand CA′have the same semantics. Now, we will use the above lemmas in order to iteratively remove all negative literals and the arithmetic literals of type k.kN. Each removal step is not defined for arbitrary normalized TABG[≈,6≈,N], but just for normalized conjunctive TABG[≈,6≈,N]. For this reason, we first describe how to transform a given normalized TABG[≈,6≈,N] into a list of normalized conjunctive TABG[≈,6≈,N] such that, the union of their languages coincides with the language of the original TABG[≈,6≈,N]. Definition 4.12. Let A=hQ, Σ, F, ∆, E, Cibe a normalized TABG[≈,6≈,N], such that C is of the form C1∨C2∨...∨Cnfor conjunctive constraints C1, C2,...,Cn. Let A1= hQ, Σ, F, ∆, E, C1i,A2=hQ, Σ, F, ∆, E, C2i,...,An=hQ, Σ, F, ∆, E, Cni. These automata are conjunctive and normalized and, moreover, L(A) = L(A1)∪ L(A2)∪...∪ L(An) holds. We say that A1,A2,...,Anis the subdivision of A. Iteratively, we will transform a list of normalized conjunctive TABG[≈,6≈,N] into a new list of automata of the same kind but with simplified constraints, preserving the language. In order to show that this process terminates, we define a measure on normalized conjunctive TABG[≈,6≈,N] which will decrease at each step. Moreover, a case with minimal measure corresponds to a positive TABG[≈,6≈,|.|N]. This measure is a pair of natural numbers which depends on the constraint Cof the normalized conjunctive TABG[≈,6≈,N]. In the first component we have the amount of negative literals in C. In the second component we have the addition of the isolated constants in all arithmetic literal constraints of type k.kNplus the number of uses of the function symbol k.kN. Definition 4.13. We define the measure of a normalized conjunctive constraint C, denoted hCias a pair of natural numbers. We describe it by distinguishing the following cases. •If Cis of the form q1≈q2or q16≈ q2, then its measure is h0,0i. •If Cis of the form ¬(q1≈q2) or ¬(q16≈ q2), then its measure is h1,0i. •If Cis of the form (a1kq1k+...+ankqnk ⊗ k), where ⊗is in {=,≥,≤}, then its measure is h0, n +ki. •If Cis of the form (a1|q1|+...+an|qn| ⊗ k), where ⊗is in {=,≥,≤}, then its measure is h0,0i. •If Cis either true or false, then its measure is h0,0i. •If Cis a conjunction of two or more literals l1∧l2∧... ∧lnwith measures ha1, b1i, ha2, b2i,...,han, bni, then its measure is ha1+a2+...+an, b1+b2+...+bni. Let A=hQ, Σ, F, ∆, E, Cibe a normalized conjunctive TABG[≈,6≈,N]. The measure of A, denoted hAi is defined as hCi. We say that A1is bigger than A2(or, equivalently, that A2is smaller than A1), denoted A1>A2(or A2<A1), if the measure of A1is bigger (or smaller) than the measure of A2, according to the lexicographic extension of the relation >of natural numbers. The following lemma shows that any normalized conjunctive TABG[≈,6≈,N] with nonminimal measure can be transformed into a list of TABG[≈,6≈,N] of the same kind with smaller measures and preserving the language. TA WITH LOCAL AND GLOBAL CONSTRAINTS 19 Lemma 4.14. Let A=hQ, Σ, F, ∆, E, Cibe a normalized conjunctive TABG[≈,6≈,N]whose measure is not h0,0i. Then one can construct normalized conjunctive TABG[≈,6≈,N]A1,...,Anwith the same equational theory E, each of them having a measure smaller than hAi and such that L(A) = L(A1)∪...∪ L(An)holds. Proof. In the case where Chas some negative literal ¬(q≈q′) or ¬(q6≈ q′), the transformations described in Lemmas 4.7 and 4.8 give a new TABG[≈,6≈,N]A′, and the subdivision A1,...,Anof the normalization of A′(as defined in Definition 4.12) is such that the constraints CA1,...,CAnhave one less negative literal than C. Thus, the measure of each of these automata is smaller than the measure of A. In the case where Chas no negative literals of the form ¬(q≈q′) or ¬(q6≈ q′), its measure is of the form h0, mifor m > 0. It follows that there is at least one literal of the form (ak¯qk+Pai·kqik⊗k), where ⊗is in {=,≥,≤}. We consider a new state ˆqand the automaton A¯q❀ˆq. Its constraint C¯q❀ˆqis of the form (k¯qk= 0 ∧ kˆqk= 0) ∨(kˆqk= 1 ∧¯q6≈ ˆq)∧C′. Note that, according to Definition 4.5, C′is a conjunction because there are no negative literals of the form ¬(q≈q′) or ¬(q6≈ q′) in C. Thus, C¯q❀ˆqcan be rewritten as the disjunction of two conjunctions C1and C2, where C1is k¯qk= 0 ∧ kˆqk= 0 ∧C′and C2is kˆqk= 1∧¯q6≈ ˆq∧C′. Hence, the subdivision of the normalization of A¯q❀ˆqare the automata A1,A2obtained from A¯q❀ˆqby replacing its constraint by C1and C2, respectively. The measures of C1and C2may be bigger than the one of C. In order to conclude, for each case we show that additional transformations can be applied to A1and A2, producing automata with smaller measures than the one of Aand preserving the represented language. •The literals of C1of type k.kNare k¯qk= 0 and kˆqk= 0, and those obtained from the literals of Cof type k.kNby replacing k¯qkby k¯qk+kˆqk. Note that original literals of the form (ak¯qk+Pai·kqik⊗k) have been converted into (ak¯qk+akˆqk+Pai·kqik⊗k), and recall that there is at least one literal of this form in C. Applying to A1the transformation described in Lemma 4.11 for ¯qand ˆq, each one of the above literals is transformed into (a·0 + a·0 + Pai· kqik ⊗ k), which has a smaller measure than the original literal (ak¯qk+Pai· kqik ⊗ k). Moreover, the literals k¯qk= 0 and kˆqk= 0 are converted into |¯q|= 0 and |ˆq|= 0, respectively. In summary, the measure of ((C1)¯q❀0)ˆq❀0is smaller than the one of C. •Similarly, the literals of C2of type k.kNare kˆqk= 1 and those obtained from the literals of Cof type k.kNby replacing k¯qkby k¯qk+kˆqk. As above, note that original literals of the form (ak¯qk+Pai· kqik ⊗ k) have been transformed into (ak¯qk+akˆqk+Pai· kqik ⊗ k), and recall that there is at least one literal of this form in C. Applying to C2the transformation described in Lemma 4.10 for ˆq, each one of the above literals is converted into (a·k¯qk+a·1+Pai·kqik⊗k). The normalization of such a literal is the normalization of (a· k¯qk+Pai· kqik ⊗ k−a), which might be already normalized or must be replaced by true or false in order to normalize it, depending on k−aand ⊗. In every case, the resulting literal has a smaller measure than the original literal (ak¯qk+Pai· kqik ⊗ k). Moreover, the literal kˆqk= 1 is replaced by |ˆq| ≥ 1∧ˆq≈ˆqas a consequence of the transformation of Lemma 4.10. To summarize, the measure of (C2)ˆq❀1is smaller than the one of C. Corollary 4.15. Let A=hQ, Σ, F, ∆, E, Cibe a TABG[≈,6≈,N]. Then, one can construct some TABG∧[≈,6≈,|.|N]A1,...,Anwith the same equational theory Esuch that L(A) = L(A1)∪...∪ L(An). 20 L. BARGU˜ N´ O, C. CREUS, G. GODOY, F. JACQUEMARD, AND C. VACHER Proof. Without loss of generality, the constraint Ccan be assumed to be normalized. The subdivision of Ais a collection of normalized conjunctive TABG[≈,6≈,N] such that the union of their languages coincides with L(A). By iterated application of the Lemma 4.14 to each automaton of the subdivision, combined with the fact that the ordering on measures is well founded, we conclude to the effective existence of normalized conjunctive TABG[≈,6≈,N]A1,...,Ansuch that L(A) = L(A1)∪...∪ L(An) and each of them has measure h0,0i. This kind of automata are, in fact, TABG∧[≈,6≈,|.|N], since measure h0,0iimplies that negative literals and literals of type k.kNdo not occur. Now, in order to remove all arithmetic constraints, it remains to remove the ones of type |.|N. This is a rather easy task. For a given TABG∧[≈,6≈,|.|N]Awe create a new TABG∧[≈,6≈] A6Nwhose purpose is to simulate the computations of A. To this end, the states of A6N count the number of occurrences of the states of Ain the simulated computation, up to a certain maximum value. This allows A6Nto check the constraints of type |.|Nof Adirectly through states. Thus, each state of A6Nis of the form qMfor a state qof Aand a mapping M:QA→N, that is, a mapping counting the number of occurrences of each state. Definition 4.16. Let A=hQ, Σ, F, ∆, E, Cibe a normalized TABG∧[≈,6≈,|.|N]. We define maxAas one plus the maximum isolated constant occurring in the literals of Cof type |.|N, i.e. one plus the maximum constant koccurring in a literal of Cof the form (a1|q1|+...+an|qn| ⊗ k), for ⊗in {≥,≤,=}. Given two mappings M1:Q→ {0,...,maxA}and M2:Q→ {0,...,maxA}, the sum of M1and M2is defined as the mapping M1+M2:Q→ {0,...,maxA}satisfying (M1+M2)(q) = min(M1(q) + M2(q),maxA). Given a state qin Qwe define Mq:Q→ {0,...,maxA}as the mapping satisfying Mq(q) = 1 and Mq(q′) = 0 for all q′∈Q\ {q}. We define A6Nas the TABG∧[≈,6≈]hQ6N,Σ, F6N,∆6N, E, C6Ni, where: •Q6Nis {qM|q∈Q∧M:Q→ {0,...,maxA}}. •F6Nis {qM∈Q6N|q∈F∧ ∀(a1|q1|+...+an|qn| ⊗ k)∈C, ⊗ ∈ {≥,≤,=}: (a1M(q1) + ...+anM(qn)⊗k)}. •∆6Nis {f((q1)M1,...,(qm)Mm)D →qM1+...+Mm+Mq|(f(q1,...,qm)D →q)∈∆}. •C6Nis {¯q¯ M≈˜q˜ M|(¯q≈˜q)∈C} ∪ {¯q¯ M6≈ ˜q˜ M|(¯q6≈ ˜q)∈C}. Lemma 4.17. Let A=hQ, Σ, F, ∆, E, Cibe a TABG∧[≈,6≈,|.|N]. Then, L(A6N) = L(A). Proof. The accepting runs of Acan be converted into accepting runs of A6Nand vice-versa, following the transformations described below. •A run r6Nof A6Ncan be converted into a run rof Aby replacing each occurrence of a state qMby the corresponding state q. •A run rof Acan be converted into a run r6Nof A6N. The transformation can be defined recursively as follows. Let rbe a run of the form (f(q1,...,qm)D →q)(r1,...,rm). Let (r1)6N,...,(rm)6Nbe the transformations of r1,...,rm, and let (q1)M1,...,(qm)Mmbe the states reached by (r1)6N,...,(rm)6N, respectively. Then, r6Nis (f((q1)M1,...,(qm)Mm)D → qM1+...+Mm+Mq)((r1)6N,...,(rm)6N). Each one of the two above transformations is the inverse of the other. Thus, they describe a bijection between runs of Aand runs of A6N. Moreover, for each run rof A, the state qMreached by r6Nholds that each q′∈Qsatisfies M(q′) = min(|r−1(q′)|,maxA) (note that TA WITH LOCAL AND GLOBAL CONSTRAINTS 21 r−1(q′) is the set of positions reaching state q′). Hence, by the definition of F6N, it follows that qis in Fand rsatisfies the arithmetic constraints of Cif and only if qMis in FN. As a consequence, ris accepting if and only if r6Nis accepting. Thus, L(A6N) = L(A) holds. The following corollary is a consequence of Corollary 4.15 combined with Lemma 4.17. Corollary 4.18. Let A=hQ, Σ, F, ∆, E, Cibe a TABG[≈,6≈,N]. Then, one can construct some TABG∧[≈,6≈]A1,...,Anwith the same equational theory Esuch that L(A) = L(A1)∪...∪ L(An). As a final step, we show that TABG∧[≈,6≈] are closed under union for a fixed E. Lemma 4.19. Let A1and A2be TABG∧[≈,6≈]with the same equational theory E. Then, a TABG∧[≈,6≈]Awith the same equational theory Ecan be effectively constructed satisfying L(A) = L(A1)∪ L(A2). Proof. Let A1be hQ1,Σ, F1,∆1, E, C1iand A2be hQ2,Σ, F2,∆2, E, C2i. Without loss of generality we can assume that the sets of states Q1and Q2are disjoint. In the case where C1is just false the result follows by defining A:= A2. Similarly, in the case where C2is just false the result follows by defining A:= A1. From now on we assume that these cases do not take place. We define Aas hQ1⊎Q2,Σ, F1⊎F2,∆1⊎∆2, E, C1∧C2i. Note that Ais a TABG∧[≈,6≈]. It is clear that any accepting run of Ais also an accepting run of either A1or A2. Moreover, it can be proved that any accepting run of either A1or A2is also an accepting run of A. We show this fact only for A1, since the case for A2is analogous. Let rbe an accepting run of A1. Then, r|=C1holds. In order to see that it is, in fact, an accepting run of A, it remains to prove r|=C2. Since A2is a TABG∧[≈,6≈], C2is a conjunction of positive literals of type ≈,6≈ applied to states of Q2. Therefore, r|=C2 holds, since C2is not false and any positive literal holds because ruses only states from Q1. Corollary 4.20. Let A=hQ, Σ, F, ∆, E, Cibe a TABG[≈,6≈,N]. Then, one can construct a TABG∧[≈,6≈]A′with the same equational theory Esuch that L(A′) = L(A). Corollary 4.21. The class of TABG languages (modulo the same equational theory) is closed under union. In order to complete the closure results for TABG languages under basic set operations, we show that they are also closed under intersection, but not under complementation. Lemma 4.22. The class of TABG languages (modulo the same equational theory) is closed under intersection. Proof. We use a classical Cartesian product of sets of states, with a careful redefinition of constraints on this product. More precisely, let A1=hQ1,Σ, F1,∆1, E, C1iand A2=hQ2,Σ, F2,∆2, E, C2ibe two TABG. We construct the TABG A=hQ1×Q2,Σ, F1×F2,∆, E, Ciwhere ∆ = fhq1,1, q2,1i, . . . , hq1,n, q2,ni→ hq1, q2if(qi,1,...,qi,n)→qi∈∆ifor i∈ {1,2}and the constraint Cis obtained from C1∧C2by replacing every atom q1≈q′ 1with q1, q′ 1∈Q1(respectively q2≈q′ 2 with q2, q′ 2∈Q2) by Vq2,q′ 2∈Q2hq1, q2i ≈ hq′ 1, q′ 2i(respectively Vq1,q′ 1∈Q1hq1, q2i ≈ hq′ 1, q′ 2i), and similarly for the atoms q16≈ q′ 1,q26≈ q′ 2. With this construction, L(A) = L(A1)∩L(A2) 22 L. BARGU˜ N´ O, C. CREUS, G. GODOY, F. JACQUEMARD, AND C. VACHER holds: the left (respectively right) projection of a successful run of Aon a term t∈ T (Σ) is a successful run of A1(respectively A2) on t, and the product of two successful runs r1of A1and r2of A2, both on the same term t∈ T (Σ), is a a successful run of Aon t. Lemma 4.23. The class of TABG languages is not closed under complementation. Proof. To prove the statement it suffices to define a language Lsuch that Lis not recognizable by TABG but its complement Lis. In order to simplify the presentation, we denote terms of the form f(gn1(a), f(gn2(a),...f(gnk−1(a), gnk(a)) ...)) simply with [n1, n2,...,nk−1, nk]. Let Lbe the language defined as: L={[n1,...,nk]|k, n1,...,nk∈N∧ ∀i∈ {1,...,k} ∃!j∈ {1,...,k}\{i}:ni=nj} In order to prove that Lis not recognizable by TABG, by Corollary 4.20, it suffices to prove it for TABG∧[≈,6≈]. We proceed by contradiction assuming that there exists a TABG∧[≈,6≈] Asuch that L(A) = L. Let t∈Lbe the term [1,...,n,n,...,1], where n > |QA|, and let rbe an accepting run of Aon t. By the pigeonhole principle, there exist i, j ∈ {1,...,n}, with i < j, such that the positions pi= i−1 z}| { 2.....2 and pj= j−1 z}| { 2.....2 satisfy r(pi) = r(pj). Let r′be the replacement r[r|pj]pi. Note that r′is an accepting run of ta(A) on the term [1,...,i −1,j,...,n,n,...,1], which is not in L. To conclude, it remains to prove that the constraints of Aare satisfied in r′. First, note that this replacement only introduces new subterms at the positions ˆ P={ˆp∈Pos(r)|ˆp < pi}. Moreover, the rules applied by r′at positions in ˆ Pare the same as in r, and any constraint affecting a position in ˆ Pin ris necessarily a disequality, since term(r|ˆp)6=EAterm(r|p′) holds for ˆp∈ˆ Pand p′∈Pos(r)\ {ˆp}. By the definition of r′, necessarily term(r′|ˆp)6=EAterm(r′|p′) holds also for ˆp∈ˆ Pand p′∈Pos(r′)\ {ˆp}. Therefore, r′satisfies all the constraints, and hence, r′is an accepting run of A, a contradiction. It remains to prove that Lcan be recognized by a TABG. We start by decomposing Linto simpler languages. First, let L1be the language of the malformed terms, i.e. the terms over {f: 2, g : 1, a : 0}that are not of the form [n1,...,nk]. Second, let L2be the language of the well-formed terms [n1,...,nk] such that for some i∈ {1,...,k}there exists no j∈ {1,...,k} \ {i}satisfying ni=nj. Third, let L3be the language of the well-formed terms [n1,...,nk] such that there exist different i1, i2, i3∈ {1,...,k}satisfying ni1=ni2=ni3. It is easy to see that L=L1∪L2∪L3. Moreover, note that L1can be recognized by a TA,L2can be recognized by a TABG∧[6≈,|.|N] and L3can be recognized by aTABG∧[≈,|.|N]. By Corollaries 4.20 and 4.21, this concludes the proof. 5. Emptiness Decision Algorithm In this section we prove the decidability of the emptiness problem for TABG∧. As a consequence of this result and the results of Section 4, it follows the decidability of emptiness for TABG, and even more, of TABG[≈,6≈,N]. The decidability of emptiness for TABG∧is proved in three steps. In Subsection 5.1, we present a new notion of pumping which allows to transform a run into a smaller run under certain conditions. In Subsection 5.2, we define a well quasi-ordering ≤on a certain set S. In Subsection 5.3, we connect the two previous subsections by describing how to compute, TA WITH LOCAL AND GLOBAL CONSTRAINTS 23 i Hiˇ Hi˚ Hi 5{λ} ∅ ∅ 4{3} {2} {1} 3{3.3} {2,3.2} {1,3.1} 2{3.3.3} {2,3.2,3.3.2} {1,3.1,3.3.1} 1{2,3.2,3.3.2,3.3.3.2} ∅ {1,3.1,3.3.1,3.3.3.1} Figure 4: Hi,ˇ Hiand ˚ Hiof Example 5.2. for each run rwith height h=h(r), a certain sequence eh,...,e1of elements of Ssatisfying the following fact: there exists a pumping on rif and only if ei≤ejfor some h≥i > j ≥1. Moreover, each eiof the computed sequence is chosen among a finite number of possibilities. Finally, all of these constructions are used as follows. Suppose the existence of an accepting run r. If ris “too high”, the fact that ≤is a well quasi-ordering and the properties of the sequence imply the existence of such i, j. Thus, it follows the existence of a pumping providing a smaller accepting run r′. We conclude the existence of a computational bound for the height of a minimum accepting run, and hence, decidability of emptiness. 5.1. Global Pumpings. Pumping is a traditional concept in automata theory, and in particular, it is very useful in order to reason about tree automata. The basic idea is to convert a given run rinto another run by replacing a subrun at a certain position pin r by a run r′, thus obtaining a run r[r′]p. Pumpings are useful for deciding emptiness: if a “big” run can always be reduced by a pumping, then decision of emptiness is obtained by a search of an accepting “small” run. For plain tree automata, a necessary and sufficient condition to ensure that r[r′]pis a run is that the resulting states of r|pand r′coincide, since the correct application of a rule at a certain position depends only on the resulting states of the subruns of the direct children. In this case, an accepting run with height bounded by the number of states exists, whenever the accepted language is not empty. When the tree automaton has equality and disequality constraints, the constraints may be falsified when replacing a subrun by a new run. For TABG∧, we will define a notion of pumping ensuring that the constraints are satisfied. This notion of pumping requires to perform several replacements in parallel. We first define the sets of positions involved in such kind of pumping. Definition 5.1. Let Abe a TABG∧. Let rbe a run of A. Let ibe an integer between 1 and h(r). We define Hias {p∈Pos(r)|0< h(r|p) = i}, ˇ Hias {p.j ∈Pos(r)|0< h(r|p.j)< i ∧h(r|p)> i}, ˚ Hias {p.j ∈Pos(r)|0 = h(r|p.j)< i ∧h(r|p)> i}. Example 5.2. According to Definition 5.1, for our running example (Example 3.4), we have the Hi,ˇ Hiand ˚ Hipresented in Figure 4. The following lemma is rather straightforward from the previous definition. Lemma 5.3. Let Abe a TABG∧. Let rbe a run of A. Let ibe an integer between 1and h(r). Then, any two different positions in Hi∪ˇ Hi∪˚ Hiare parallel, and for any arbitrary 24 L. BARGU˜ N´ O, C. CREUS, G. GODOY, F. JACQUEMARD, AND C. VACHER M qM 1 qid N qt 2 qd 0 qN L qL 3 qid N qt 2 qd 0 qN L0 qL 4 qid N qt 2 qd 0 qN Figure 5: Global pumping of Example 5.5. position pin Pos(r)there is a position ¯pin Hi∪ˇ Hi∪˚ Hisuch that, either pis a prefix of ¯p, or ¯pis a prefix of p. Proof. For the first fact, note that any proper prefix pof a position ¯pin Hi∪ˇ Hi∪˚ Hisatisfies h(r|p)> i. Thus, such a pis not in Hi∪ˇ Hi∪˚ Hi. For the second fact, consider any pin Pos(r). If h(r|p)≤iholds, then the smallest position ¯psatisfying ¯p≤pand h(r|¯p)≤iis in Hi∪ˇ Hi∪˚ Hi, and we are done. Otherwise, if h(r|p)> i holds, then the smallest position ¯pof the form p.1.....1 and satisfying h(r|¯p)≤iis in Hi∪ˇ Hi∪˚ Hi, and we are done. Definition 5.4. Let Abe a TABG∧. Let Ebe EA. Let rbe a run of A. Let i, j be integers satisfying 1 ≤j < i ≤h(r). A pump-injection I: (Hi∪ˇ Hi∪˚ Hi)→(Hj∪ˇ Hj∪˚ Hj) is an injective function such that the following conditions hold: (C1)I(Hi)⊆Hj,I(ˇ Hi)⊆ˇ Hjand I(˚ Hi)⊆˚ Hj. Moreover, Irestricted to ˚ Hiis the identity, i.e. I(p) = pfor each pin ˚ Hi. (C2) For each ¯pin Hi∪ˇ Hi∪˚ Hi,r(¯p) = r(I(¯p)). (C3) For each ¯p1,¯p2in Hi∪ˇ Hi∪˚ Hi, (term(r|¯p1) =Eterm(r|¯p2)) ⇔(term(r|I(¯p1)) =E term(r|I(¯p2))). Let {¯p1,...,¯pn}be Hi∪ˇ Hi∪˚ Himore explicitly written. The run r[r|I(¯p1)]¯p1... [r|I(¯pn)]¯pn is called a global pumping on rwith indexes i, j, and injection I. By Condition C2,r[r|I(¯p1)]¯p1...[r|I(¯pn)]¯pnis a run of ta(A), but it is still necessary to prove that it is a run of A. By abuse of notation, when we write r[r|I(¯p1)]¯p1...[r|I(¯pn)]¯pn, we sometimes consider that Iand {¯p1,...,¯pn}are still explicit, and say that it is a global pumping with some indexes 1 ≤j < i ≤h(r). Example 5.5. Following our running example, we define a pump-injection I: (H4∪ˇ H4∪ ˚ H4)→(H3∪ˇ H3∪˚ H3) as follows: I(1) = 1, I(2) = 2, I(3) = 3.3. We note that Iis a correct pump-injection: I(H4)⊆H3,I(ˇ H4)⊆ˇ H3and I(˚ H4)⊆˚ H3hold, and Irestricted to ˚ H4is, in fact, the identity, thus (C1) holds. For (C2), we have r(1) = r(I(1)) = qid, r(2) = r(I(2)) = qt, and r(3) = r(I(3)) = qL. Regarding (C3), for each different ¯p1,¯p2 in H4∪ˇ H4∪˚ H4,term(r|¯p1)6=term(r|¯p2) and term(r|I(¯p1))6=term(r|I(¯p2)) hold. After applying the pump-injection I, we obtain the term and run r′of Figure 5. Our goal is to prove that any global pumping r[r|I(¯p1)]¯p1...[r|I(¯pn)]¯pnis a run, and in particular, that all equality and disequality constraints are satisfied. To this end we first state the following intermediate statement, which determines the height of the terms TA WITH LOCAL AND GLOBAL CONSTRAINTS 25 pending at some positions after the pumping. It can be easily proved by induction on the height of the involved term. Lemma 5.6. Let Abe a TABG∧. Let rbe a run of A. Let r′be the global pumping r[r|I(¯p1)]¯p1...[r|I(¯pn)]¯pnon rwith indexes 1≤j < i ≤h(r)and injection I. Let k≥0be a natural number and let pbe a position of rsuch that h(r|p)is i+k. Then, pis also a position of r′and h(r′|p)is j+k. Proof. Position pis obviously a position of r′since no position in Hi∪ˇ Hi∪˚ Hiis a proper prefix of p. We prove the second part of the statement by induction on k. First, assume k= 0. Then, h(r|p) is i. Thus, pis in Hi, say pis ¯p1. Therefore, r′|pis r|I(¯p1). By Condition (C1) of the definition of pump-injection, I(¯p1)∈Hjholds. Hence, h(r′|p) = h(r|I(¯p1)) = j. Now, assume k > 0. Let mbe the arity of symbol(r|p). Thus, p.1, . . . , p.m are all the child positions of pin r. Since h(r|p) is i+k, all h(r|p.1),...,h(r|p.m) are smaller than or equal to i+k−1, and at least one of them is equal to i+k−1. Consider any αin {1,...,m}. If h(r|p.α) is i+k′for some 0 ≤k′≤k−1, then, by induction hypothesis, h(r′|p.α) is j+k′. Otherwise, if h(r|p.α) is strictly smaller than i, then p.α is one of the positions in ˇ Hi∪˚ Hi, say ¯p1. In this case, r′|¯p1is r|I(¯p1), and by Condition (C1) of the definition of I,I(¯p1) belongs to ˇ Hj∪˚ Hj. Therefore, h(r|I(¯p1))< j holds, and hence, h(r′|p.α) = h(r′|¯p1) = h(r|I(¯p1))< j ≤j+k−1 holds. From the above cases we conclude that, if h(r|p.α) is i+k−1, then h(r′|p.α) is j+k−1, and if h(r|p.α) is smaller than i+k−1, then h(r′|p.α) is smaller than j+k−1. It follows that all h(r′|p.1),...,h(r′|p.m) are smaller than or equal to j+k−1, and at least one of them is equal to j+k−1. As a consequence, h(r′|p) is j+k. Corollary 5.7. Let Abe a TABG∧. Let rbe a run of A. Let r′be a global pumping on r. Then, h(r′)< h(r). The following lemma states that equality and disequality relations are preserved, not only for terms pending at the positions of the domain of I, but also for terms pending at prefixes of positions of such domain. Again, it is rather easy to prove by induction on the height of the involved terms. Lemma 5.8. Let Abe a TABG∧. Let rbe a run of A. Let r′be the global pumping r[r|I(¯p1)]¯p1...[r|I(¯pn)]¯pnwith indexes 1≤j < i ≤h(r)and injection I. Let p1, p2be positions of rsatisfying that each of them is a prefix of a position in Hi∪ˇ Hi∪˚ Hi. Then, p1, p2are positions of r′and (term(r|p1) =Eterm(r|p2)) ⇔(term(r′|p1) =E term(r′|p2)) holds. Proof. The first statement follows by Lemma 5.6. We prove the second part of the statement by induction on h(r|p1) + h(r|p2). We distinguish the following cases: •Assume that both p1and p2are positions in Hi∪ˇ Hi∪˚ Hi, say ¯p1and ¯p2, respectively. Therefore, r′|p1is r|I(¯p1)and r′|p2is r|I(¯p2). By Condition (C3) of the definition of pumpinjection, (term(r|¯p1) =Eterm(r|¯p2)) ⇔(term(r|I(¯p1)) =Eterm(r|I(¯p2))) holds. Thus, (term(r|p1) =Eterm(r|p2)) ⇔(term(r′|p1) =Eterm(r′|p2)) holds, and we are done. •Assume that one of p1or p2, say p1, is a proper prefix of a position in Hi∪ˇ Hi∪˚ Hi, and p2is a position in Hi∪ˇ Hi∪˚ Hi. Then, h(r|p1) = i+kfor some k > 0, and h(r|p2)≤i holds. Thus, (term(r|p1)6=Eterm(r|p2)) holds. By Lemma 5.6, h(r′|p1) = j+k. By the definition of pump-injection, h(r′|p2)≤j. Thus, also (term(r′|p1)6=Eterm(r′|p2)) holds, and we are done. 32 L. BARGU˜ N´ O, C. CREUS, G. GODOY, F. JACQUEMARD, AND C. VACHER The decidability of emptiness of Afollows, since the existence of successful runs implies that one of them can be found among a computable and finite set of possibilities. Using Corollary 4.20 and Theorem 5.22, we can conclude the decidability of emptiness for TABG, and more generally for TABG[≈,6≈,N]. Corollary 5.23. Emptiness is decidable for TABG. Corollary 5.24. Emptiness is decidable for TABG[≈,6≈,N]. 6. Unranked Ordered Trees Our tree automata models and results can be generalized from ranked to unranked ordered terms. In this setting, Σ is called an unranked signature, meaning that there is no arity fixed for its symbols, i.e. that in a term a(t1,...,tn), the number nof children is arbitrary and does not depend on a. Let us denote by U(Σ) the set of unranked ordered terms over Σ. The notions of positions, subterms, etc., are defined for unranked terms of U(Σ) as for ranked terms of T(Σ). We extend the definition of automata for unranked ordered terms, called hedge automata [Mur99], with global constraints. We do not consider constraints between brothers nor flat theories in this setting. Definition 6.1. Ahedge automaton with global constraints (HAG) over an unranked signature Σ is a tuple A=hQ, Σ, F, ∆, Ciwhere Qis a finite set of states, F⊆Qis the subset of final states, Cis a Boolean combination of atomic constraints of the form q≈q′or q6≈ q′, with q, q′∈Q, and ∆ is a set of transition rules of the form a(L)→qwhere a∈Σ, q∈Q and Lis a regular (word) language over Q∗, assumed given by a finite state automaton with input alphabet Q. We still use the notation HAG[τ1,...,τn] where the types τican be ≈,6≈,|.|N,k.kN,N. The notion of run of TAG is extended to HAG in the natural way. A run of a HAG Ais a pair r=ht, Miwhere t∈ U(Σ) is an unranked ordered term and Mis a mapping from Pos(t) into ∆Asuch that for each position p∈Pos(t) with nchildren, if M(p.1),...,M(p.n) are rules with right-hand side states q1,...,qn∈QA, respectively, then M(p) is a transition rule of the form t(p)(L)→qin ∆, and the word q1···qnbelongs to L. Moreover, r|=CA, where satisfiability of CAby ris defined like in Section 3. A run ris called successful (or accepting) if r(λ)∈FA. The emptiness decision results of Corollary 5.24 can be transposed from TAG into HAG using a standard transformation from unranked to ranked binary terms, like the extension encoding described in [CDG+07], Chapter 8. Let us associate to the unranked signature Σ the (ranked) signature Σ@:= {a: 0 |a∈ Σ} ∪ {@ : 2}where @ is a new symbol not in Σ. The operator curry is a bijection from U(Σ) into T(Σ@) recursively defined as follows: curry(a) = afor all a∈Σ currya(t1,...,tn)= @currya(t1,...,tn−1),curry(tn) An example of application of this operator is presented in Figure 7. We extend the application of the operator curry to sets of unranked ordered terms by curry(L) = {curry(t)| t∈L}. TA WITH LOCAL AND GLOBAL CONSTRAINTS 33 a b c d f g h 7→curry @ @ @ a@ b c d @ @ f g h Figure 7: Currying an unranked term. Proposition 6.2. For all HAG[≈,6≈,N]Aover Σ, one can construct effectively in PTIME aTAG[≈,6≈,N]A′over Σ@such that L(A′) = curryL(A). Proof. Let Abe hQ, Σ, F, ∆, Cimore explicitly written. Without loss of generality, we assume that for each a∈Σ, q ∈Q, the set of rules ∆ contains exactly one transition of the form a(L)→q, and we denote by ¯ Aa,q the NFA recognizing the corresponding language L. Recall that such automata have Qas input alphabet. Without loss of generality, we assume that the sets of states of Aand all ¯ Aa,q are pairwise disjoint. Let ¯ Qbe the union of all states of all the automata ¯ Aa,q. Intuitively, the transitions of the automaton A′will simulate both the transitions of Aand the transitions of the NFAs ¯ Aa,q, when running on curry(t) for some t∈ U(Σ). Let A′=hQ∪¯ Q, Σ, F, ∆′, Ciwhere ∆′contains the following transitions for each a∈Σ, q ∈Q: •a→qif ¯ Aa,q recognizes the empty word, •a→¯qwhere ¯qis the initial state of ¯ Aa,q, •@(¯q, q′)→¯q′if there is a transition ¯q−−→ q′¯q′in ¯ Aa,q, and •@(¯q, q′)→qif there is a transition ¯q−−→ q′¯q′in ¯ Aa,q and ¯q′is a final state of ¯ Aa,q. It is not difficult to see that there exists an accepting run of Aif and only if there exists an accepting run of A′. There exist alternative encodings from unranked to ranked trees in the literature, e.g., the first-child next-sibling encoding: see Figure 8 for an example of this transformation. This alternative encoding makes the representation of equality and disequality between subterms of the original unranked term difficult, since the transformed subterms may have original siblings occurring now as their subterms. For example, in Figure 8, the two occurrences of the subterm ccorrespond to different terms in the result of the transformation. The following emptiness decision result is a direct consequence of Proposition 6.2 and Corollary 5.24. Corollary 6.3. Emptiness is decidable for HAG[≈,6≈,N]. 7. Logics on Trees In this section, we discuss the application of our results to second order logics interpreted over domains defined by terms. We propose a strict extension of the second order monadic logic of the tree with equality, disequality and arithmetic constraints, and show that satisfiability is decidable for this extension thanks to a correspondence with TAG[≈,6≈,N]. 34 L. BARGU˜ N´ O, C. CREUS, G. GODOY, F. JACQUEMARD, AND C. VACHER a b c c f g h 7→fcns a b c # # c #f g #h # # # # Figure 8: First-child next-sibling encoding of an unranked term. 7.1. MSO on Ranked Terms. A ranked term t∈ T (Σ) over Σ can be seen as a model for logical formulae, with an interpretation domain which is the set of positions Pos(t). We consider monadic second order formulae interpreted on such models, built with the usual Boolean connectors, with quantifications over first order variables (interpreted as positions), denoted x, y . . . and over unary predicates (i.e. second order variables interpreted as sets of positions), denoted X, Y . . ., and with the following predicates, •equality: x=y, •membership: X(x), •labeling: a(x), for a∈Σ •navigation: Si(x, y), for all ismaller than or equal to the maximal arity of symbols of Σ (we call +1 the type of such predicates), •term equality: X≈Y, term disequality: X6≈ Y(predicate types ≈and 6≈), •linear inequalities: Pai· |Xi| ≥ aor Pai· kXik ≥ a, where every aiand abelong to Z (predicate types |.|Zand k.kZ). We write MSO[τ1,...,τk] for the set of monadic second order logic formulae with equality, membership, labeling predicates and other predicates of types τ1,...,τk, amongst the above types +1, ≈,6≈, and |.|Z,k.kZ. We also use the notations |.|Nand k.kNfor natural linear inequalities (linear inequalities whose coefficient all have the same sign) and the abbreviations Zand Nof Section 4. Let ∃MSO[τ1,...,τk] be the fragment of MSO[τ1,...,τk] containing the formulae of the form ∃X1...∃Xnφsuch that all the atoms of type ≈,6≈,Zor Nin φinvolve only second order variables amongst X1,...,Xn. A variable assignment into a term t∈ T (Σ) is a function σmapping first order variables into positions of Pos(t) and second order variables into subsets of Pos(t). The satisfiability of a formula φby a term t∈ T (Σ) and a variable assignment σ, denoted t, σ |=φis defined in the usual Tarskian manner, with: TA WITH LOCAL AND GLOBAL CONSTRAINTS 35 t, σ |=x=yiff σ(x) = σ(y) t, σ |=X(x) iff σ(x)∈σ(X) t, σ |=a(x) iff t(σ(x)) = a t, σ |=Si(x, y) iff σ(x).i =σ(y) t, σ |=X≈Yiff ∀p∈σ(X), p′∈σ(Y), p 6=p′:t|p=t|p′ t, σ |=X6≈ Yiff ∀p∈σ(X), p′∈σ(Y), p 6=p′:t|p6=t|p′ t, σ |=Pai· |Xi| ≥ aiff Piai· |σ(Xi)| ≥ a t, σ |=Pai· kXik ≥ aiff Piai·{t|p|p∈σ(Xi)}≥a Example 7.1. The following formula of ∃MSO[≈,6≈] expresses that all the subterms headed by ain a term tare pairwise different: ∃Xa((∀x Xa(x)↔a(x)) ∧Xa6≈ Xa). In other words, ais used to mark monadic keys in t(see Example 3.4). A seminal result of [TW68] shows that MSO[+1] has exactly the same expressiveness as TA, and therefore it is decidable. The extension MSO[+1,≈] is undecidable, see e.g. [FTT07]. The extension MSO[+1,|.|Z] is undecidable as well [KR02]. On the other side, the fragment ∃MSO[+1,|.|Z] is decidable [KR02], and a fragment of ∃MSO[+1,≈,6≈] is shown decidable in [FTT08] for a restricted variant of 6≈, using a two way correspondence between these formulae and a decidable subclass of TAGED. This latter construction can be straightforwardly adapted to establish a two way correspondence between ∃MSO[+1,≈,6≈,N] and TAG[≈,6≈,N]. Theorem 7.2. ∃MSO[+1,≈,6≈,N]is decidable on ranked terms. Proof. Following the same proof scheme as [FTT08], we show that for every closed formula φin ∃MSO[+1,≈,6≈,N], we can construct a TAG[≈,6≈,N] recognizing exactly the set of models of φ. Then, the decidability of the logic follows from Theorem 5.24. Without loss of generality, we may assume that φis of the form ∃X1...∃Xn(φ0(X)∧φ≈(X)∧φN(X)) where φ0(X) is a MSO[+1] formula with free variables X=X1,...,Xn, and φ≈(X) and φN(X) are Boolean combinations of atoms of the respective form Xi≈Xj,Xi6≈ Xjand Pai·|Xi| ≥ a,Pai·kXik ≥ a. Moreover, we shall also assume that φ≈(X) and φN(X) are conjunctions of atoms or negations of atoms of the above form. Otherwise, we put them into disjunctive normal form and then split φinto an equivalent formula φ1∨...∨φk, where each φi,i≤k, is of the form requested: φi=∃X1...∃Xn(φi 0(X)∧φi ≈(X)∧φi N(X)), where φi 0(X)∈MSO[+1] and φi ≈(X) and φi N(X) are conjunctions of atoms or negations of atoms as above, and we solve satisfiability separately for each φi. First, we recall the definitions of [TW68] of the signature Σ×{0,1}n, where the arity of a symbol hf, b1,...,bniis the arity of f, and of the term t⊗σover this signature obtained, from a term tover Σ and a mapping σ:{X1,...,Xn} → 2Pos(t), by relabeling every position p∈Pos(t) by ht(p), b1,...,bni, where for each i≤n,bi= 1 if p∈σ(Xi) and bi= 0 otherwise. Also, from [TW68] we get the construction of a TA A0=hQ, Σ× {0,1}n, F, ∆0i which recognizes the set of terms {t⊗σ∈ T Σ× {0,1}n|t, σ |=φ0(X)}. Second, following a construction in [NPTT05], we shift in A0the bit-vectors from the signature into the state symbols, obtaining a TA A′ 0=hQ×{0,1}n,Σ, F ×{0,1}n,∆iwhere ∆ contains all the transition rules fhq1, b1,1,...,b1,ni,...,hqm, bm,1,...,bm,ni→ hq, b1,...,bni 36 L. BARGU˜ N´ O, C. CREUS, G. GODOY, F. JACQUEMARD, AND C. VACHER such that f∈Σ, hf, b1,...,bniq1,...,qm→q∈∆0and b1,1,...,b1,n, . . . , bm,1,...,bm,n ∈ {0,1}. This automaton A′ 0recognizes the projection (on the first components) of the terms recognized by A0, i.e. it recognizes the set of terms t∈ T (Σ) such that there exists σ:{X1,...,Xn} → 2Pos(t)satisfying t, σ |=φ0(X). Third, we obtain a constraint Cby rewriting all the atoms of φ≈(X)∧φN(X) with the following rules: Xi≈Xj7→ ^ bi=b′ j=1 hq, b1,...,bni ≈ hq′, b′ 1,...,b′ ni Xi6≈ Xj7→ ^ bi=b′ j=1 hq, b1,...,bni 6≈ hq′, b′ 1,...,b′ ni X i ai· |Xi| ≥ a7→ X iX bi=1 ai· |hq, b1,...,bni| ≥ a X i ai· kXik ≥ a7→ X iX bi=1 ai· khq, b1,...,bnik ≥ a The TAG[≈,6≈,N]A=hQ× {0,1}n,Σ, F × {0,1}n,∆, Cirecognizes {t∈ L(A)|t|=φ}. The above transformation also works in the other direction (this result is not necessary for the proof of Theorem 7.2 though): for every TAG[≈,6≈,N], we can construct a formula φ in ∃MSO[+1,≈,6≈,N], whose set of models is L(A). Note that ∃MSO[+1,≈] is strictly more expressive than MSO, since the equality between subterms is not expressible in MSO (see e.g. [CDG+07]). The TA construction of [TW68] for the decidability of MSO[+1] involves the closure under projection on components for TA languages over signatures made of tuples of symbols (for the elimination of ∃quantifiers). TAG languages are not closed under projection on some components of tuples, as it is already the case for simpler form tree automata with equality [Tre00]. Thus, the same approach cannot be used to prove decidability of emptiness of TAG. 7.2. MSO on Unranked Ordered Terms. In unranked ordered terms of U(Σ), the number of children of a position is unbounded. Therefore, for navigating in such terms with logical formulae, the successor predicates Si(x, y) of Section 7.1 are not sufficient. In order to describe unranked ordered terms as models, we replace these above predicates Siby: •S↓(x, y) (yis a child of x), •S→(x, y) (yis the successor sibling of x). The type of these predicates is still called +1. Note that the above predicates S1, S2,... can be expressed using these two predicates only. The satisfiability of the above atoms by a term t∈ U(Σ) and a variable assignment σ is defined as follows: t, σ |=S↓(x, y) iff there exists isuch that σ(x).i =σ(y), t, σ |=S→(x, y) iff there exists p∈Pos(t) and isuch that σ(x) = p.i and σ(y) = p.(i+ 1). It is shown in [SSM03] that the extension MSO[+1,|.|Z] is undecidable for unranked ordered terms when counting constraints are applied to sibling positions. Using the results of Section 6, and an easy adaptation of the automata construction in the proof of Theorem 7.2, we can generalize Theorem 7.2 to ∃MSO over unranked ordered terms. TA WITH LOCAL AND GLOBAL CONSTRAINTS 37 Theorem 7.3. ∃MSO[+1,≈,6≈,N]is decidable on unranked ordered terms. 8. Conclusion We have answered (positively) the open problem of decidability of the emptiness problem for the TAGED [FTT08], by proposing a decision algorithm for a class TABG of tree automata with global constraints strictly extending the global constraints of TAGED in several directions. Moreover, the TABG combine the global constraints with local tests between brother subterms a la [BT92] and equality interpreted modulo flat theories. Our method for emptiness decision, presented in Section 5 appeared to be robust enough to deal with several extensions like global counting constraints, and generalization to unranked terms. A challenging question would be to investigate the precise complexity of the emptiness problem, avoiding the use of Higman’s Lemma in the algorithm. For instance, in [FTT08], it is shown, using a direct reduction into solving positive and negative set constraints [CP94, GTT94, Ste94], that emptiness is decidable in NEXPTIME for TAGED (i.e. for TAG∧[6≈] modulo an empty theory and such that in every atomic constraint q6≈ q′,qand q′are distinct states). On the other hand, the best known lower bound for emptiness decision for TABG is EXPTIME-hardness (this holds already for TAG∧[≈] as shown in [FTT08]). Another interesting problem mentioned in the introduction is the combination of the HAG of Section 6 with the unranked tree automata with tests between siblings, UTASC [WL07, LW09]. Perhaps, the techniques of Section 5 could help for the emptiness decision for a formalism using for instance MSO binary querying (following e.g. [NPTT05]) for selecting the test position of global constraints. Finally, another branch of research related to TABG concerns automata and logics for data trees, i.e. trees labeled over an infinite (countable) alphabet (see [Seg06] for a survey). Indeed, data trees can be represented by terms over a finite alphabet, with an encoding of the data values into terms. This can be done in several ways, and with such encodings, the data equality relation becomes the equality between subterms. Therefore, this could be worth studying in order to relate our results on TAG to decidability results on automata or logics on data trees like those in [JL07, BMSL09]. Acknowledgement We thank Luc Segoufin for many valuable discussions and the anonymous referees at LICS 2010 for their useful comments and suggestions. References [ANR05] S. Anantharaman, P. Narendran, and M. Rusinowitch. Closure properties and decision problems of DAG automata. Information Processing Letters, 94(5):231–240, 2005. [BCG+10] L. Bargu˜n´o, C. Creus, G. Godoy, F. Jacquemard, and C. Vacher. The emptiness problem for tree automata with global constraints. In Logic in Computer Science (LICS), pages 263–272, 2010. [BMSL09] M. Bojanczyk, A. Muscholl, T. Schwentick, and Segoufin L. Two-variable logic on data trees and applications to XML reasoning. JACM, 56(3), 2009. A preliminary version was presented at PODS 06. [BN98] F. Baader and T. Nipkow. Term Rewriting and All That. Cambridge University Press, New York, 1998. 38 L. BARGU˜ N´ O, C. CREUS, G. GODOY, F. JACQUEMARD, AND C. VACHER [BT92] B. Bogaert and S. Tison. Equality and Disequality Constraints on Direct Subterms in Tree Automata. In 9th Symp. on Theoretical Aspects of Computer Science, STACS, volume 577 of LNCS, pages 161–171. Springer, 1992. [BT05] A. Bouajjani and T. Touili. On computing reachability sets of process rewrite systems. In J¨urgen Giesl, editor, Term Rewriting and Applications, 16th International Conference, RTA 2005, Nara, Japan, April 19-21, 2005, Proceedings, volume 3467 of Lecture Notes in Computer Science, pages 484–499. Springer, 2005. [CC05] H. Comon and V. Cortier. Tree automata with one memory, set constraints and cryptographic protocols. Theoretical Computer Science, 331(1):143–214, February 2005. [CDG+07] H. Comon, M. Dauchet, R. Gilleron, F. Jacquemard, C. L¨oding, D. Lugiez, S. Tison, and M. Tommasi. Tree Automata Techniques and Applications.http://tata.gforge.inria.fr, 2007. [Cha99] W. Charatonik. Automata on DAG representations of finite trees. Technical Report Technical Report MPI-I-99-2-001, Max-Planck-Institut f¨ur Informatik, Saarbr¨ucken, Germany, 1999. [CHJ94] H. Comon, M. Haberstrau, and J.P. Jouannaud. Syntacticness, cycle-syntacticness, and shallow theories. Information and Computation, 111(1):154–191, 1994. [CP94] W. Charatonik and L. Pacholski. Set constraints with projections are in NEXPTIME. In Proceedings of the 35th Symp. Foundations of Computer Science, pages 642–653, 1994. [DL06] S. Dal and D. Lugiez. XML schema, tree logic and sheaves automata. Journal Applicable Algebra in Engineering, Communication and Computing, 17(5):337–377, 2006. [FGVTT04] G. Feuillade, T. Genet, and V. Viet Triem Tong. Reachability Analysis over Term Rewriting Systems. Journal of Automated Reasoning, 33 (3-4):341–383, 2004. [FTT07] E. Filiot, J.-M. Talbot, and S. Tison. Satisfiability of a spatial logic with tree variables. In Proceedings of the 21st International Workshop on Computer Science Logic (CSL 2007), volume 4646 of Lecture Notes in Computer Science, pages 130–145. Springer, 2007. [FTT08] E. Filiot, J.-M. Talbot, and S. Tison. Tree automata with global constraints. In 12th International Conference in Developments in Language Theory (DLT 2008), volume 5257 of Lecture Notes in Computer Science, pages 314–326. Springer, 2008. [Gal91] J. H. Gallier. What’s so special about kruskal’s theorem and the ordinal gamma0? a survey of some results in proof theory. Annals of Pure Applied Logic, 53(3):199–260, 1991. [GTT94] R. Gilleron, S. Tison, and M. Tommasi. Some new decidability results on positive and negative set constraints. In Proceedings, First International Conference on Constraints in Computational Logics, volume 845 of LNCS, pages 336–351. Spinger, 1994. [JKV09] F. Jacquemard, F. Klay, and C. Vacher. Rigid tree automata. In Adrian Horia Dediu, Armand Mihai Ionescu, and Carlos Mart´ın-Vide, editors, Proceedings of the 3rd International Conference on Language and Automata Theory and Applications (LATA’09), volume 5457 of Lecture Notes in Computer Science, pages 446–457, Tarragona, Spain, April 2009. Springer. [JL07] M. Jurdzinski and R. Lazic. Alternation-free modal mu-calculus for data trees. In Logic in Computer Science (LICS), pages 131–140. IEEE Computer Society, 2007. [KR02] F. Klaedtke and H. Ruess. Parikh automata and monadic second-order logics with linear cardinality constraints. Technical Report 177, Intitute of Computer Science at Freiburg University, 2002. [LW09] C. L¨oding and K. Wong. On nondeterministic unranked tree automata with sibling constraints. In In IARCS Annual Conference on Foundations of Software Technology and Theoretical Computer Science (FSTTCS 2009), Leibniz International Proceedings in Informatics. Schloss Dagstuhl - Leibniz Center for Informatics, 2009. [Mon81] J. Mongy. Transformation de noyaux reconnaissables d’arbres. Forˆets RATEG. PhD thesis, Laboratoire d’Informatique Fondamentale de Lille, Universit´e des Sciences et Technologies de Lille, Villeneuve d’Ascq, France, 1981. [Mur99] M. Murata. Hedge automata: a formal model for XML schemata. Technical report, Fuji Xerox INformation Systems, 1999. [Nie96] R. Nieuwenhuis. Basic paramodulation and decidable theories (extended abstract). In Logic in Computer Science (LICS), pages 473–482, 1996. TA WITH LOCAL AND GLOBAL CONSTRAINTS 39 [NPTT05] J. Niehren, L. Planque, J.-M. Talbot, and S. Tison. N-ary queries by tree automata. In Proceedings of the 10th International Symposium on Database Programming Languages (DBPL), volume 3774 of Lecture Notes in Computer Science, pages 217–231. Springer, 2005. [Sch07] T. Schwentick. Automata for XML - a survey. J. Comput. Syst. Sci., 73(3):289–315, 2007. [Seg06] L. Segoufin. Automata and logics for words and trees over an infinite alphabet. In Computer Science Logic, volume 4207 of LNCS. Springer, 2006. [SSM03] H. Seidl, T. Schwentick, and A. Muscholl. Numerical document queries. In Principle of Databases Systems (PODS), pages 155–166. ACM Press, 2003. [Ste94] K. Stefansson. Systems of set constraints with negative constraints are nexptime-complete. In Proceedings, Ninth Annual IEEE Symposium on Logic in Computer Science, pages 137–141. IEEE Computer Society Press, 1994. [Tre00] R. Treinen. Predicate logic and tree automata with tests. In J. Tiuryn, editor, Proc. of the 3rd Int. Conf. on Foundations of Software Science and Computation Structures, FoSSaCS, volume 1784 of LNCS, pages 329–343. Springer, 2000. [TW68] J. W. Thatcher and J. B. Wright. Generalized finite automata theory with an application to a decision problem of second-order logic. Mathematical System Theory, 2:57–82, 1968. [VGL07] K. N. Verma and J. Goubault-Larrecq. Alternating two-way ac-tree automata. Information and Computation, 205(6):817–869, 2007. [WL07] K. Wong and C. L¨oding. Unranked tree automata with sibling equalities and disequalities. In In Proceedings of the 34th International Colloquium on Automata, Languages and Programming (ICALP), volume 4596 of LNCS, pages 875–887. Springer, 2007. This work is licensed under the Creative Commons Attribution-NoDerivs License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nd/2.0/ or send a letter to Creative Commons, 171 Second St, Suite 300, San Francisco, CA 94105, USA, or Eisenacher Strasse 2, 10777 Berlin, Germany