A Characterization of the Sets of Hypertrees Generated by Hyperedge-Replacement Graph Grammars Frank Drewes
Department of Computer Science, University of Bremen, P.O. Box 33 04 40, D{28334 Bremen, Germany e-mail:
[email protected] Abstract. A characterization of the sets of hypertrees generated by hyperedge-
replacement graph grammars is given. The characterization says that these sets are exactly those which have the form val (T ), where T , a set of terms over hyperedgereplacement operations, is the output language of a nite-copying top-down tree transducer. Furthermore, the terms in T may be required to consist of hyperedgereplacement operations whose underlying hypergraphs are hypertrees. The result is closely related to a similar characterization that was obtained for the case of string graphs by Engelfriet and Heyker some years ago. In fact, the results of this paper also yield a new proof for the characterization by Engelfriet and Heyker.
1 Introduction Hyperedge-replacement graph grammars, also called context-free hypergraph grammars, are well-studied devices for the generation of graph and hypergraph languages (see, e.g., [Hab92, Eng97, DHK97]). Their basic operation is the replacement of a non-terminal hyperedge by a hypergraph. This works by removing the replaced hyperedge e and adding the replacing hypergraph H in such a way that, if e has k incident nodes, these nodes are identi ed with k distinguished nodes of H called its points. Thus, the points are the only places where H is connected to the host hypergraph. This suggests immediately that the power of hyperedgereplacement graph grammars depends on the maximum type of right-hand side hypergraphs (called the order of the grammar), where the type of a hypergraph is the number of points. In fact, it is well-known that the generation of the set of all k-trees requires order k (see [Hab92]). But even if the very special case of string graphs (i.e., the natural representation of strings by edge-labelled graphs) is considered, the generating power of hyperedge-replacement graph grammars increases properly whenever the order is increased by 2 (see [EH91, Hab92]). There is an important dierence between these two examples. If one is interested in generating (k + 1)-trees using a grammar of order k, then the generation mechanism used is simply too weak to generate the sort of objects wanted. By contrast, even if only right-hand sides of type 2 are used one can easily generate the set of all string graphs over a xed alphabet. Here, the diculty appears on another, more subtle level: Making use of larger and larger types, hyperedge-replacement graph grammars may describe more and more sophisticated subsets of this basic set. For example, the set of string graphs corresponding to fan1 an2k j n 1g (k 1) can be generated, but it requires a grammar of order 2k (for Partially supported by the EC TMR Network GETGRATS (General Theory of Graph Transformation Systems) through the University of Bremen.
1
fan1 an2k?1 j n 1g also order 2k is needed, see [EH91, Hab92]).
For a closer look at this phenomenon it is useful to turn to a slightly dierent view of hyperedge-replacement graph grammars. In a natural way, the right-hand sides of productions can be seen as operations on hypergraphs (cf. [Cou91, Dre96]), so-called hr operations. Suppose the right-hand side is a hypergraph H with n non-terminal hyperedges. Then it corresponds to an operation of arity n. The result of applying this operation to n hypergraphs is obtained by replacing the ith non-terminal hyperedge by the ith argument hypergraph, for i = 1; : : : ; n. Given a set of such hr operations a set T T of terms over de nes the hypergraph language val (T ) = fval (t) j t 2 T g, where val is the evaluation mapping on terms. The languages of the form val (T ) where T is a regular set of terms are exactly those which are generated by hyperedge-replacement graph grammars (cf. [Cou91]), and are called context-free. (The set T corresponds closely to the set of derivation trees of the corresponding hyperedge-replacement graph grammar.) Now, the observations concerning string graphs can be formulated as follows. Let (k) denote the set of all hr operations of type k. Then val (T ) contains all string graphs. Nevertheless, not for every context-free string-graph language L there exists a regular subset of T which de nes L. In other words, if L = val (T ) for a regular set T T k , one can obtain from T some T 0 T such that L = val (T 0), but in general the required construction cannot preserve regularity. It is therefore a natural question to ask how complex the set T 0 must necessarily be. For the case of string graphs Engelfriet and Heyker [EH91] answered this question: A string-graph language L is context-free i L = val (T 0) for a set T 0 T which is the output language of a nite-copying top-down tree transducer (cf. [ERS80]). In fact, they also established a characterization of the context-free string-graph languages generated by grammars of order 2k or 2k + 1: L = val (T ) for a regular subset of T k if and only if L = val (T 0) for a set T 0 T which is the output language of a k-copying top-down tree transducer. The same holds for (2k+1) instead of (2k) , i.e., hyperedge-replacement graph grammars of order 2k and of order 2k + 1 have the same string-generating power. In this paper it is shown that quite a similar result can be obtained if the more general case of trees and hypertrees is considered. Hypertrees are a straightforward generalization of trees, obtained by viewing a hyperedge of type m 1 as a directed hyperedge with m ? 1 sources and one target. The exact de nition is given in Section 5. Let Tm denote the set of all hypertrees of type m, where the type of hyperedges is at most m, too. Furthermore, let ht(m) denote the signature consisting of all hr operations given by hypertrees in Tm . The main result of this paper says that the following statements are equivalent for sets L Tm : (i) L is context-free; (ii) L = val (T ), where T T m is the output language of a nite-copying top-down tree transducer; (iii) L = val (T ), where T is the output language of a nite-copying top-down tree transducer whose output signature consists of arbitrary hyperedge-replacement operations. Intuitively, the reason for these equivalences is that large hyperedges can be used to control several places in a hypergraph simultaneously during a derivation, which allows for a nite (2)
(2)
( )
(2)
(2)
(2 )
(2)
ht(
)
2
amount of synchronization between parts that otherwise would have to be derived independently. Top-down tree transducers with the nite-copying property can be used to achieve a similar eect by copying an input term (or a subterm thereof) and using the identical copies to synchronize sub-derivations. The main result can also be stated in terms of the top-down tree-to-graph transducers (tg transducers) of [EV94]. Then it says that L Tm is context-free i L is the output language of a nite-copying tg transducer whose rules have right-hand sides in Tm i L is the output language of a nite-copying tg transducer. The paper is structured as follows. In the next two sections the basic notions concerning tree transducers and hyperedge replacement are recalled. The implication (i))(ii) is proved in Section 5. Before doing that, however, in Section 4 a general method is developed that allows to construct top-down tree transductions which translate terms over one set of hr operations into equivalent terms over another set of hr operations. In Section 5 this method is applied twice in order to obtain the desired result. Section 6 establishes (iii))(i). In Section 7 these results are combined in order to obtain the main theorem. Finally, in Section 8 it is shown how the mentioned characterization by Engelfriet and Heyker can be obtained using the results and methods of this paper.
2 Tree transductions In this section the basic notions concerning regular tree grammars and top-down tree transducers are recalled. In this context, the word tree refers to terms, which may be seen as rooted, labelled and ordered trees in the usual way. A regular tree grammar is a nite-state device quite similar to a regular string grammar that generates a set of terms. A top-down tree transducer computes a transformation of terms, like a generalized sequential machine computes a transformation of strings. The study of top-down tree transducers was begun in the seventies by Rounds and Thatcher [Rou70, Tha70, Tha73], and was continued by several other authors. In this paper, we will mainly consider the variant de ned and investigated by Engelfriet in [Eng77] (see also [Eng78, ERS80, FV89, SV95, GV96]), called top-down tree transducer with regular look-ahead. For surveys on the theory of tree languages and tree transductions see [GS84, NP92, GS97]. Throughout the paper N denotes the set of natural numbers (including 0) and N + = N nf0g. For n 2 N , [n] denotes the set f1; : : : ; ng. A sequence of length n 2 N over a set A is a mapping l : [n] ! A. The length n of l is denoted by jlj, denotes the empty sequence (i.e., the one of length 0), and the set of all sequences over A is denoted by A . Concatenation of sequences is denoted by juxtaposition. If f : A ! B is a mapping that yields sequences, f (a; i) denotes f (a)(i). The canonical extensions of a function f : A ! B to the powerset of A and to A are denoted by f , too. Hence, f (A0) = ff (a) j a 2 A0g for all A0 A, and f (l) = f (l(1)) f (l(jlj)) for all l 2 A . The domain restriction of a relation r A B to A0 A is denoted by rjA0 , that is, rjA0 = f(a; b) 2 r j a 2 A0 g. The re exive and transitive closure of r is denoted by r. The composition of binary relations (and, in particular, of functions) r A B and r0 B C is given by r0 r = f(a; c) 2 A C j (a; b) 2 r and (b; c) 2 r0 for some b 2 B g. For classes R, R0 of binary rela3
tions R0 R = fr0 r j r 2 R; r0 2 R0 g. A (one-sorted) signature is a set of symbols such that for every f 2 a natural number, called its rank, is speci ed. To indicate that f has rank k the notation f (k) will be used. Taking subsets of signatures or unions of disjoint signatures is assumed to preserve ranks. For the rest of this paper we x an indexed set X = fx1 ; x2; : : : g of pairwise distinct variables and let Xn = fx1 ; : : : ; xng for all n 2 N . The variables in X are assumed to be distinct from all symbols that occur in the considered signatures. The set T (Y ) of all terms over with variables in Y X is de ned inductively, as usual: For all xi 2 Y , xi 2 T (Y ), and for all f (k) 2 and all t1; : : : ; tk 2 , f [t1 ; : : : ; tk ] 2 T(Y ). Here, \[", \]", and \," are meta symbols not contained in . In the following, the notation f [t1 ; : : : ; tk ] always implies that t1 ; : : : ; tk are well formed terms. Furthermore, for a(0) 2 , a is identi ed with a[]. The set T (;) of terms over (i.e., without variables) is denoted by T . For t 2 T(Xn) and s1 ; : : : ; sn 2 T0 (X ) the substitution of si for xi in t is denoted by t[ s1 ; : : : ; sn] , that is, t[ s1 ; : : : ; sn] equals si if t = xi and f [t1[ s1 ; : : : ; sn] ; : : : ; tk [ s1 ; : : : ; sn] ] if t = f [t1; : : : ; tk ]. A term rewrite system R is a set of rules s ! s0 , where s and s0 are terms such that all variables in s0 occur in s, too. The term rewrite relation determined by R is denoted by !R. The de nition of !R is as usual. If R contains a rule s ! s0 and t has the form t = t0 [ s[ t1; : : : ; tn] ] , where t0 contains exactly one occurrence of x1 , then t !R t0 where t0 = t0 [ s0 [ t1; : : : ; tn] ] . Next, the concepts of regular tree grammars and top-down tree transducers with regular look-ahead are recalled. 2.1 De nition (regular tree grammar, cf. [GS97]) A regular tree grammar is a system g = (N; ; P; S ), where N and are disjoint nite signatures, all symbols in N (the nonterminals ) have rank 0, P N T[N is a nite set of term rewrite rules (the productions ), and S (the start symbol ) is in N . The set of terms generated by g is L(g) = ft 2 T j S !P tg and is called a regular set of terms. A tree transduction is a relation T T0 where and 0 are nite signatures. The tree transductions of interest for this paper are computed by nite-state devices called top-down tree transducers, because they compute tree transductions by processing an input \tree" (i.e., a term viewed as a tree) from the top down. 2.2 De nition (top-down tree transducer with regular look-ahead, cf. [Eng77]) A top-down tree transducer with regular look-ahead (tdr transducer) is a system tdr = (; 0 ; ?; R; 0), where and 0 are nite signatures of input and output symbols, respectively, ? with ? \ ( [ 0) = ; is a nite signature of states each of which has rank 1, 0 2 ? is the initial state, and R is a nite set of rules of the form ( [f [x1 ; : : : ; xk ]] ! t[ 1[xi ]; : : : ; l[xil ]]]; reg ): Here, f (k) 2 , ; 1; : : : ; l 2 ?, t 2 T0 (Xl ) for some l 2 N , xi ; : : : ; xil 2 Xk , and reg is a mapping that assigns a regular subset reg (xi) of T to every variable xi 2 Xk .1 For terms s; s0, s !R s0 if R contains a rule as above, such that s = s0[ [f [t1 ; : : : ; tk ]]]] with ti 2 reg (xi ) for every i 2 [k] and s0 = s0 [ t[ 1 [ti ]; : : : ; l[til ]]]] . The derivation relation !R is also denoted 1 Note that reg may be nitely represented by k regular tree grammars. 1
1
1
4
by !tdr . The tree transduction tdr T T0 computed by tdr is given by 0 t g: tdr = f(t; t0 ) 2 T T0 j 0 [t] ! tdr If (l ! r; reg ) is a rule in R then l is its left-hand side and r is its right-hand side. The domain of tdr is the set dom (tdr) = ft 2 T j (t; t0 ) 2 tdr for some t0 2 T0 g, and its output language is out (tdr) = ft0 2 T j (t; t0) 2 tdr for some t 2 T g. If C is a class of tree transductions and a signature then OUT (C ) = fout ( ) T j 2 C g. Note that, according to the de nition, a rule ( [f [x1; : : : ; xk ]] ! t[ 1[xi ]; : : : ; l[xil ]]]; reg ) of a tdr transducer has the eect of the term rewrite rule [f [x1; : : : ; xk ]] ! t[ 1[xi ]; : : : ; l [xil ]]], but it applies only if every subterm ti matched by a variable xi is an element of reg (xi ). A tdr transducer tdr = (; 0; ?; R; 0) is a top-down tree transducer (td transducer) if for all rules ( [f [x1 ; : : : ; xk ]] ! r; reg ) 2 R and all i 2 [k] it holds that reg (xi) = T (thus, in this case the regular look-ahead is trivial and will be dropped in the following), deterministic if for every pair of distinct rules (l ! r; reg ) and (l0 ! r0; reg 0) in R with l = l0 = [f [x1 ; : : : ; xk ]] there is some i 2 [k] such that reg (xi) \ reg 0(xi) = ;, linear if for every rule ( [f [x1 ; : : : ; xk ]] ! r; reg ) 2 R each variable occurs at most once in r, and non-deleting if for every rule ( [f [x1 ; : : : ; xk ]] ! r; reg ) 2 R each of the variables x1 ; : : : ; xk occurs in r at least once. Note that, if tdr is a deterministic tdr transducer then tdr is a partial function tdr : T ! T0 . As far as this paper is concerned, the most important restriction of tdr transducers is given by the nite-copying property. This property was rst considered in [AU71]. For tdr transducers, nite copying was introduced in [ERS80]. The de nition is based on a rewrite relation R (where R is the set of rules of a tdr transducer) on pairs (w; s) 2 ? T . Intuitively, the idea is to have ( 0; s) R ( 1 n; s0) if there is a derivation using !R that starts with 0[s] and copies a subterm s0 of s n times, where 1; : : : ; n are the states in which the dierent copies are reached. Formally, if ( [f [x1 ; : : : ; xk ]] ! r; reg ) is a rule in R and i 2 [k], let 8 (l) 2 > < i (r1 ) i (rl ) if r = g [r1 ; : : : ; rl ] with g i (r) = > 0 if r = 0[xi ] : if r = 0[xj ] with j 6= i. Thus, i(r) is the sequence of states on top of occurrences of xi in r (read from left to right). To de ne R let ( 1 n; t) 2 ? T with t = f [t1 ; : : : ; tk ] and assume that R contains a rule ( j [f [x1; : : : ; xk ]] ! rj ; reg j ) for every j 2 [n], where ti 2 reg j (xi ) for all i 2 [k]. Then ( 1 n; t) R (i(r1 ) i(rn); ti) for every i 2 [k]. Now, tdr = (; 0 ; ?; R; 0) is said to be m-copying on input t 2 T if ( 0; t) R (w; t0) implies jwj m. If tdr is m-copying on all input terms t 2 T then it is m-copying, and it is nite-copying if it is m-copying for some m 2 N . A number m 2 N such that tdr is m-copying is called a copying bound of tdr. Note that nite copying is a generalization of linearity: tdr is linear if and only if it is 1-copying. It must be remarked that the de nition of nite-copying given above is slightly more restric1
1
5
tive than the one in [ERS80] because it requires nite copying for all derivations whereas in [ERS80] only \successful" derivations (i.e., those which end in a term without states) are considered. It is easy to see, however, that this dierence is unimportant because for all classes of tdr (and td) transducers considered here a transducer which is m-copying in the sense of [ERS80] yields a tree transducer (in the same class) which is m-copying in the sense of this paper. The class of tree transductions computed by tdr transducers (by td transducers) is denoted by TDR (by TD, respectively). To denote the subclasses of tree transductions given by restricting the considered tree transducers to deterministic, linear, or nondeleting ones, (combinations of) the pre xes d, l, and n are added to this notation. Similarly, the subscripts fc and fc(m) indicate the restriction to nite-copying and m-copying tree transducers, respectively. Thus, for example, ldTD denotes the class of linear deterministic td transductions, i.e., those computed by linear and deterministic td transducers, and dTDRfc(m) denotes the class of deterministic m-copying tdr transductions. Since most of the constructions given in this paper concern the class dTDRfc the following result of [ERS80] turns out to be useful. 2.3 Lemma ([ERS80, Theorem 5.4]) dTDRfc(n) dTDRfc(m) = dTDRfc(mn) for all m; n 2 N .
The construction underlying this lemma is eective.
3 Hyperedge replacement In this section the notion of hyperedge replacement is recalled. Hyperedge replacement is a simple generation mechanism for hypergraphs that was introduced in the early seventies (under other names) by Feder and Pavlidis [Fed71, Pav72]. Its systematic study began more than 15 years later, initiated through papers by Bauderon and Courcelle [BC87] and Habel and Kreowski [HK87]. This work was continued in diverse directions. For references see, e.g., [Hab92], [Eng97], and [Roz97, Chapters 1, 2, and 5]. Results that establish|in dierent ways|connections between tree transductions and hyperedge replacement can be found in, e.g., [EH91, EH92, Eng94, EV94, EV96, Dre96]. The notion of hypergraphs to be used in this paper is de ned below. 3.1 De nition (pointed hypergraph ) A pointed hypergraph is a tuple G = (V; E; att ; lab ; point ), where V is the nite set of nodes, E with E \ V = ; is the nite set of hyperedges, att : E ! V is the attachment of hyperedges, lab : E ! L is the labelling of hyperedges (where L is an arbitrary set of labels ), and point 2 V is the sequence of points of G. It is required that att (e) (for all e 2 E ) and point are injective. The set of all points of G, that is, [point ], is also denoted by points (G). 6
1 1
3 3
1
3
B 2
e
1 1
2
2
A
2
Figure 1: Hypergraph From now on the term \hypergraph" will be used instead of \pointed hypergraph". Whenever the components of a hypergraph G are not given explicitly they are denoted by VG, EG, att G, lab G , and point G, respectively. The empty hypergraph G with VG = EG = ; is denoted by ;. An unlabelled hyperedge is a hyperedge that carries a special label which intuitively means \no label". If all hyperedges of G are unlabelled then G is said to be an unlabelled hypergraph and the component lab G is dropped. The type of e 2 EG in G, denoted by type G(e), is the number jatt G(e)j of attached nodes. The type of G, denoted by type (G), is the number jpoint Gj of points. Furthermore, maxtype (G) = max(ftype (G)g [ ftype G(e) j e 2 EGg). It must be stressed that, for technical convenience, the sequence of points of a hypergraph G as well as the sequence of attached nodes of a hyperedge e 2 EG are not allowed to contain repetitions, that is, point G = v1 vn or att G(e) = v1 vn implies vi 6= vj for 1 i < j n. As a consequence, the notion of hyperedge replacement de ned below is repetition-free in the sense of [Hab92, De nition I.4.5]. Nevertheless, the results of this paper remain valid if this restriction is dropped. This is because, as shown in [Dre96, Lemma 2.29], in the more general case repetition-freeness turns out to be a normal-form which can be obtained by applying a suitable ldTDR transduction (using a construction similar to the proof of the corresponding Theorem I.4.6 of [Hab92]). Furthermore, the class dTDRfc(m) on which the results of this paper are based is closed under composition with linear deterministic td transductions, i.e., dTDRfc(m) ldTDR = dTDRfc(m) , by Lemma 2.3. Hypergraphs are visualized as shown in Figure 1. A hyperedge is drawn as a rectangle surrounding its label (unless it is unlabelled, in which case there is only a small square). If needed for reference the name of the hyperedge is placed next to the hyperedge (see the unlabelled hyperedge e in the gure). The attachment is indicated by numbered lines that connect a hyperedge with its attached nodes, where the numbering may be dropped if it is irrelevant or clear from the context. Unlabelled edges (i.e., unlabelled hyperedges of type 2) are depicted as arrows pointing from the rst attached node towards the second. Unless a node is a point it is drawn as a bullet, whereas a point is drawn as a circle with the respective number inside. A morphism m : G ! H from a hypergraph G to a hypergraph H is a pair m = (mV ; mE ) of mappings mV : VG ! VH , mE : EG ! EH such that mV (att G(e)) = att H (mE (e)) and lab H (mE (e)) = lab G (e) for all e 2 EG . A morphism is injective (surjective, bijective ) if both of its components are injective (surjective, bijective, respectively). If m is injective and point H = mV (point G) then G is a sub-hypergraph of H , which is denoted by G H . 7
A bijective morphism m : G ! H with point H = mV (point G) is an isomporphism. If an isomorphism between G and H exists then G and H are said to be isomorphic, which is denoted by G = H . Note that G = H if and only if G H and H G. In this paper isomorphic hypergraphs will not be distinguished very strictly, that is, the focus is on abstract hypergraphs, isomorphism classes of hypergraphs, as opposed to concrete ones. In order to be able to speak about the components of hypergraphs, however, concrete hypergraphs are used as representatives of their isomorphism classes without stressing this point explicitly. It is now possible to de ne the notion of hyperedge replacement. For this, hypergraphs G and H are called disjoint if (VG [ EG ) \ (VH \ EH ) = ;. Furthermore, for a hypergraph G and a subset E of EG, G ? E denotes the removal of E from G, i.e., G ? E = (VG; EG n E; attG jEGnE ; ; labGjEGnE ; point G). 3.2 De nition (hyperedge replacement, cf. [Hab92]) Let G; G1; : : : ; Gk be hypergraphs and let e1 ; : : : ; ek 2 EG be pairwise distinct hyperedges such that type G(ei) = type (Gi) for all i 2 [k]. Let G0 = G ? fe1; : : : ; ek g and assume that G0; G1; : : : ; Gk are pairwise disjoint (otherwise, take suitable isomorphic copies of G1; : : : ; Gk ). For every node v 2 S i=0;:::;k VGi de ne image (v ) = att G (ei ; j ) if v = point Gi (j ) for some i 2 [k], j 2 [type (Gi )], and image (v) = v otherwise. Then the hyperedge replacement Ghe1 =G1; : : : ; ek =Gk i yields the hypergraph (V; E; att ; lab ; point ) such that V = VG [ Si2[k](VGi n points (Gi)) and E = Si=0;:::;k EGi , att (e) = image (att Gi (e)) for every e 2 EGi (i 2 f0; : : : ; kg), lab (e) = lab Gi (e) for every e 2 EGi (i 2 f0; : : : ; kg), and point = point G. The reader should notice that, strictly speaking, Ghe1 =G1; : : : ; ek =Gk i is de ned only up to isomorphism, because one has to rename nodes and hyperedges if the given hypergraphs are not disjoint. For technical convenience it will be assumed in the following that all nodes and hyperedges of G0 = G ? fe1; : : : ; ek g and of G1; : : : ; Gk are retained in Ghe1=G1; : : : ; ek =Gk i, that is, the morphism mi : Gi ! Ghe1 =G1; : : : ; ek =Gk i that maps Gi to its image in Ghe1=G1 ; : : : ; ek =Gk i is a pair of identical mappings for every i 2 f0; : : : ; kg. The following lemma states some basic facts concerning hyperedge replacement that follow directly from the de nition. 3.3 Lemma (cf. [Hab92, Lemma 2.3(2){(5)]) Let G; G1; : : : ; Gk be hypergraphs and let e1 ; : : : ; ek 2 EG be pairwise disjoint, where type G(ei) = type (Gi) for all i 2 [k]. Then (1) for all permutations on [k], Ghe(1) =G(1) ; : : : ; e(k)=G(k)i = Ghe1 =G1; : : : ; ek =Gk i, (2) Ghe1 =G1; : : : ; ek =Gk i = Ghe1=G1i hek =Gk i, and (3) for all e01 2 EG and all hypergraphs G01 such that type (G01) = type G (e01 ) it holds that Ghe1 =G1he01 =G01ii = Ghe1 =G1ihe01 =G01i. The second equation of Lemma 3.3 can sometimes be used to simplify reasonings, as follows. Suppose that for all hypergraphs G; G0 and all e 2 EG with type G(e) = type (G0), Ghe=G0i satis es a property if G satis es this property and G0 satis es another property 0. Then it follows by induction that this statement extends to arbitrary hyperedge replacements 1
1
8
Ghe1=G1 ; : : : ; ek =Gk i: If G satis es and G1 ; : : : ; Gk satisfy 0 then Ghe1 =G1; : : : ; ek =Gk i satis es . 3.4 De nition (hyperedge replacement operation, cf. [Cou91]) A hyperedge-replacement operation (hr operation) is a k-ary partial operation F on hypergraphs given by a hypergraph GF and a sequence vir F = e1 ek of pairwise distinct unlabelled hyperedges e1 ; : : : ; ek 2 EGF such that F (G1; : : : ; Gk ) = GF he1 =G1; : : : ; ek =Gk i for all hypergraphs G1; : : : ; Gk . The hyperedges e1 ; : : : ; ek are called the virtual hyperedges of F . If F is an hr operation then the components of GF are also denoted by VF , EF , att F , lab F , and point F , respectively. An hr operation of arity 0 is identi ed with its underlying hypergraph. A hyperedge-replacement signature (hr signature) is a signature whose elements are hr operations, where ranks coincide with arities. For t 2 T, val (t) denotes the value of t, i.e., if t = F [t1 ; : : : ; tk ] then val (t) = F (val (t1 ); : : : ; val (tk )). In order to prevent unnecessary technicalities, we shall only be interested in terms with a de ned value. Thus, throughout the whole paper the following convention is employed.
Convention If is an hr signature then T denotes the set of all those terms t over
for which val (t) is de nd. Furthermore, only these terms are allowed to appear as input or output terms of tree transductions or regular tree grammars. It is easy to see that this convention does not have any in uence on the results of this paper, because for every nite hr signature the set of terms t such that val (t) is de ned, is regular (and the class of regular sets of terms is closed under intersection). If is an hr signature, a set of hypergraphs is said to be -context-free if it has the form val (T ) for a regular subset T of T, and is called context-free if it is -context-free for some hr signature . It follows from general results by Mezei and Wright ([MW67], see also Corollary 1.10 of [Cou91]) that a set of hypergraphs is context-free (i.e., equational in the terminology of [MW67]) if and only if it is a nite union of languages generated by repetitionfree hyperedge-replacement graph grammars in the sense of [Hab92]. (Here, taking a nite union is necessary because a hyperedge-replacement grammar cannot generate hypergraphs of dierent types.) This section closes by proving a lemma that will turn out to be useful in Section 6. It states that, if a td transducer td is given (where the output signature is an hr signature) and one is only interested in val td (rather than in td itself) then the right-hand sides of rules may be assumed to have a particularly simple form. For this, call a td transducer td = (; 0 ; ?; R; 0) unitary if every right-hand side of a rule in R has the form F [ 1[xi ]; : : : ; l [xil ]] (where, due to the de nition, F (l) 2 0 and 1; : : : ; l 2 ?). 3.5 Lemma Let td be a td transducer whose output signature is an hr signature. Then 0 one can eectively construct a unitary td transducer td such that val td 0 = val td . The construction preserves linearity, copying bound, and the nondeleting property (but not necessarily determinism). Proof. Let td = (; 0 ; ?; R; 0) and consider a right-hand side t[ 1[xi ]; : : : ; l[xil ]]] of a rule in R. By Lemma 3.3(3), if t has the form F [t1 ; : : : ; ti?1; F 0[t01; : : : ; t0m ]; ti+1; : : : ; tn] 1
1
9
then val td is not aected by replacing the right-hand side with t0[ 1[xi ]; : : : ; l [xil ]]], where t0 = F 00[t1 ; : : : ; ti?1; t01 ; : : : ; t0m ; ti+1; : : : ; tn] with GF 00 = GF hvir F (i)=GF 0 i and vir F 00 = vir F (1 (i ? 1))vir F 0 vir F ((i + 1) n)). Therefore, in the remainder of the proof it may be assumed that every rule in R that does not comply with the de nition of unitary td transducers has the form [f [x1; : : : ; xk ]] ! 0[xi ] for some 0 2 ?; i 2 [k]. Hence, it remains to be shown how to remove these rules. Let n0 be the smallest natural number such that n0 type (GF ) for all F 2 0 . For every i 2 N let id i be the identity on hypergraphs of type i (i.e., Gid i = ([i]; feg; att ; point ) where att (e) = point = 1 i and vir id i = e). Now de ne td0 = (; 00 ; ?0 ; R0 [ R00 ; 0 ) where 00 = 0 [ fid i j i 2 [n0]g, ?0 = (? [n0 ]) [ f 0g, and R0 and R00 are constructed as follows. For every rule [f [x1 ; : : : ; xk ]] ! F [ 1[xi ]; : : : ; l[xil ]] in R the rule ( ; j )[f [x1 ; : : : ; xk ]] ! F [( 1; j1 )[xi ]; : : : ; ( l; jl )[xil ]] is included in R0, where j = type (GF ) and, for all i 2 [l], ji = type GF (vir F (i)). For every rule [f [x1 ; : : : ; xk ]] ! 0[xi ] in R, all rules ( ; j )[f [x1; : : : ; xk ]] ! id j [( ; j )[xi ]] with j 2 [n0 ] are included in R0 . For every rule ( 0; j )[f [x1 ; : : : ; xk ]] ! t in R0 (i.e., where the rst component of the state is the initial state of td) R00 contains the rule 0[f [x1 ; : : : ; xk ]] ! t. It should be clear (and can be veri ed in a straightforward way) that val td 0 = val td , as required. Obviously, td0 is unitary and the construction does not aect linearity, the copying bound, or the nondeleting property. (Note, however, that the rules in R00 turn a deterministic td transducer into a nondeterministic one, in general.) A similar result can be proved (with an even simpler construction) for tdr transducers. In this case even determinism can be preserved. 1
1
1
4 A lemma on translations In this section a lemma is shown that provides a method to obtain deterministic nite-copying tdr transducers computing a sort of translations between terms over dierent hr signatures. To achieve this, three sets G , G , and G 0 of hypergraphs and a partial function : G ! G are considered, that satisfy certain requirements. Intuitively, the idea is as follows. The set G , which is required to be closed under hyperedge replacement, contains the underlying hypergraphs of operations in the considered input terms. The sets G and G 0 contain the underlying hypergraphs of operations in the output signature. The central requirement is that every hypergraph G 2 G has a unique decomposition G = Ghe1 =G(e1); : : : ; ek =G(ek )i if G is de ned. Furthermore, it is required that distributes over the term structure and that, if only argument hypergraphs de ned by nitely many operations are considered, has a nite image. This will be used to show that, for an input term t, val (t) can be determined by the use of regular look-ahead. Together with the required uniqueness of the decomposition Ghe1=G(e1 ); : : : ; ek =G(ek )i of G = val (t) this makes it possible to construct a deterministic nite-copying tdr transducer tdr such that tdr (t) is de ned if and only if val (t) is de ned, and in this case tdr (t) is a term F [t1; : : : ; tk ] with the same value as t, where GF = val (t) and all underlying hypergraphs of operations in t1 ; : : : ; tk are elements of G 0 . 10
Formally, let G , G , and G 0 be sets of hypergraphs such that G consists of unlabelled hypergraphs in G , and let : G ! G be a partial function. For the rest of this section it will be assumed that G , G , G 0 , and satisfy the following ve requirements. (T1) For all hypergraphs G, G0 and all e 2 EG such that type (G0) = type G(e), G; G0 2 G implies Ghe=G0i 2 G and G; G0 2 G 0 implies Ghe=G0i 2 G 0 . (T2) For all G 2 G such that G is de ned and EG = fe1 ; : : : ; ek g, there are G1; : : : ; Gk 2 G 0 such that type (Gi) = type G(ei ) for all i 2 [k], and G = Ghe1=G1 ; : : : ; ek =Gk i. (T3) For all G 2 G with EG = fe1; : : : ; ek g and G1; : : : ; Gk ; G01 ; : : : ; G0k 2 G 0 with type (Gi) = type G (ei) = type (G0i ) for i 2 [k], Ghe1 =G1 ; : : : ; ek =Gk i = Ghe1=G01; : : : ; ek =G0k i implies Gi = G0i for all i 2 [k]. (T4) For all G; G0 2 G and all e 2 EG such that type (G0) = type G(e), Ghe=G0i is de ned if and only if Ghe=G0i is de ned, and in this case Ghe=G0 i = Ghe=G0 i. (T5) For every nite hr signature such that GF 2 G for all F 2 , the set val (T) is nite.2 If G 2 G is a hypergraph such that G is de ned and EG = fe1 ; : : : ; ek g then G(e1 ); : : : ; G(ek ) denote the (by virtue of (T3) unique) hypergraphs in G 0 such that type (G(ei)) = type G(ei ) for all i 2 [k] and Ghe1=G(e1 ); : : : ; ek =G(ek )i = G. In proofs it will always be assumed without loss of generality that the corresponding isomorphism is a pair of identical mappings. The rst result states one of the facts mentioned above, namely that regular look-ahead can be used to determine val (t). 4.1 Lemma Let be a nite hr signature such that GF 2 G for all F 2 . For all G 2 G the set ft 2 T j val (t) = Gg is regular. Proof. Let g = (; N; P; AG) where N = fAH j H 2 val (T ) [ fGgg and where P consists of all rules AH ! F [AH ; : : : ; AHk ] such that H = F (H1; : : : ; Hk ), where F (k) 2 and H1; : : : ; Hk 2 val (T ) with type (Hi) = type GF (vir F (i)) for all i 2 [k]. By (T5) val (T ) is nite, and hence N and P are nite. By an obvious induction using (T4) and the fact that, by (T1), val (T) G , it follows that L(g) = ft 2 T j val (t) = Gg, as required. Using Lemma 4.1 it is now possible to prove the promised lemma. 4.2 Lemma Let be a nite hr signature such that GF 2 G for all F 2 . Then there is a deterministic nite-copying tdr transducer tdr such that (i) dom (tdr ) = fs 2 T j val (s) is de nedg, (ii) val (s) = val (tdr (s)) for all terms s 2 dom (tdr ), and (iii) every term t 2 out (tdr ) has the form F [t1 ; : : : ; tk ], where the underlying hypergraphs of operations in t1 ; : : : ; tk are elements of G 0 , GF = val (t), and [vir F ] = EF . Moreover, for every term s 2 T with m = maxfjEG j j G = val (s0) for a subterm s0 of sg, tdr is m-copying on input s. 2 For a set S G , S denotes fG j G 2 S and G is de nedg. 1
11
Proof. Let tdr = (; 0 ; ? [f 0g; R [ R0 ; 0), where the components are de ned as follows. 0 isSthe set of hr operations that occur in the right-hand sides of rules in R [ R0 . As ? the set fEG j G 2 val (T)g is chosen, where 0 is an additional state that does not occur in ?. By (T5) ? is nite. The set R of rules is de ned next. Intuitively, the purpose of R is to compute, on input s 2 T with val (s) = H , in state e 2 EH a term denoting H (e) that consists of operations with underlying hypergraphs in G 0 . Consider some operation F (k) 2 and let Gi 2 val (T) with type (Gi) = type GF (vir F (i)) for all i 2 [k]. Let furthermore G = F (G1 ; : : : ; Gk ) and assume that G is de ned, where EG = fe1 ; : : : ; elg and thus G = Ghe1=G(e1 ); : : : ; el =G(el )i. Let EGi = fei;1; : : : ; ei;mi g for every i 2 [k]. As F (G1; : : : ; Gk ) = G = Ghe1=G(e1 ); : : : ; el =G(el )i each of the sets EG(ei ) consists of hyperedges in EF n [vir F ] and hyperedges ej;j0 where j 2 [k] and j 0 2 [mj ]. Now, consider some hyperedge e 2 EG (i.e., e = ei forSsome i 2 [l]) and let ei ;j ; : : : ; ein;jn be an arbitrary but xed ordering of the set EG(e) \ j2[k] EGj . Then R contains the rule (e[F [x1 ; : : : ; xk ]] ! F 0[ei ;j [xi ]; : : : ; ein ;jn [xin ]]; reg ) where GF 0 = G(e) and vir F 0 = ei ;j ein ;jn , and where reg (xj ) = ft 2 T j val (t) = Gj g for all j 2 [n]. (Remember that, according to Lemma 4.1, reg (xj ) is regular.) Since the right-hand sides of rules in R contain only operations F with GF 2 G 0 it follows that the terms that can be derived using !R consist of operations whose underlying hypergraphs are elements of G 0 . Furthermore, R is deterministic as the considered regular sets are pairwise disjoint and at most one rule is included in R for every choice of e, F , and G1; : : : ; Gk . Before the construction of tdr is completed by de ning R0, a claim that summarizes the eect of the rules in R is proved. Claim 1. Let s 2 T with val (s) = H be such that H is de ned, and let e 2 EH . Then e[s] !R t for some term t such that val (t) = H (e). Claim 1 is proved by structural induction on s. Let s = F [s1; : : : ; sk ] with val (si) = Hi for all i 2 [k] and assume that the claim holds for the subterms s1 ; : : : ; sk . By (T4) Gi = Hi is de ned for all i 2 [k]. Therefore, by de ning G = F (G1; : : : ; Gk ) one gets G = H , again using (T4). Consequently|if the remaining notation from the de nition of R is adopted as well|the rule constructed above applies to e[s] (and is in fact the only one that does, by determinism), that is, e[s] ! F 0[ei ;j [si ]; : : : ; ein ;jn [sin ]]: R 1
1
1
1
1
1
1
1
1
1
By construction, eip;jp 2 EGip = Hip for all p 2 [n]. Hence, the induction hypothesis applies and yields terms t1; : : : ; tn such that val (tp) = Hip (eip;jp ) for p 2 [n] and 0 F [t1 ; : : : ; tn]: F 0[ei ;j [si ]; : : : ; ein;jn [sin ]] ! R 1
1
1
It remains to be shown that H (e) = F 0(val (t1); : : : ; val (tn)). Using the associativity of
12
hyperedge replacement (see Lemma 3.3(3)) twice one gets H = F (H1; : : : ; Hk ) = F (G1he1;1=H1(e1;1 ); : : : ; e1;m =H1 (e1;m )i; : : : ; Gk hek;1=Hk (ek;1); : : : ; ek;mk =Hk (ek;mk )i) = F (G1; : : : ; Gk )he1;1=H1(e1;1 ); : : : ; e1;m =H1(e1;m ); : : : ; ek;1=Hk (ek;1); : : : ; ek;mk =Hk (ek;mk )i = Ghe1=G(e1 ); : : : ; el =G(el )ihe1;1=H1(e1;1 ); : : : ; e1;m =H1(e1;m ); : : : ; ek;1=Hk (ek;1); : : : ; ek;mk =Hk (ek;mk )i = Gh : : : ; G(e)hei ;j =Hi (ei ;j ); : : : ; ein ;jn =Hin (ein;jn )i; : : : i Here, the ellipses in the last line abbreviate analogous expressions as for e associated with the remaining hyperedges e1 ; : : : ; ei?1; ei+1; : : : ; el of G, if e = ei. By (T1) it holds that G(e)hei ;j =Hi (ei ;j ); : : : ; ein ;jn =Hin (ein ;jn )i 2 G 0 since G(e); Hi (ei ;j ); : : : ; Hin (ein ;jn ) 2 G 0 . Consequently, G(e)hei ;j =Hi (ei ;j ); : : : ; ein;jn =Hin (ein ;jn )i = H (e), by (T3) and the fact that H = G. This completes the proof of Claim 1. Next, the rules of R0 are de ned. The purpose of these rules is to provide the outermost operation of the computed term. As required by (iii) the underlying operation of this operation is val (s) if s is the input term. Consider again an operation F (k) 2 and hypergraphs G1 ; : : : ; Gk 2 val (T ) with type (Gi) = type G(vir F (i)) for all i 2 [k]. Let G = F (G1; : : : ; Gk ) and assume that G is de ned, where EG = fe1 ; : : : ; el g. Let reg (xi) = ft 2 T j val (t) = Gig for all i 2 [k] and assume that (e1 [F [x1; : : : ; xk ]] ! t1 ; reg ); ... (el [F [x1 ; : : : ; xk ]] ! tl ; reg ) are the corresponding rules in R (i.e., those which apply to terms of the form ei[F [s1; : : : ; sk ]] with val (sj ) = Gj for all j 2 [k]). Then R0 contains the rule ( 0[F [x1 ; : : : ; xk ]] ! F0 [t1 ; : : : ; tl ]; reg ) where GF = G and vir F = e1 el . Since G = val (s) for all input terms s such that the rule above applies to 0[s], it is clear that tdr satis es (iii) and that val (s) is de ned if s 2 dom (tdr ). Now, let s = F [s1 ; : : : ; sk ] and assume that val (s) is de ned. Let H; H1 ; : : : ; Hk and G; G1; : : : ; Gl be as in the proof of Claim 1. Then the only rule of R [ R0 that applies to 0[s] is the one constructed above (and this one does apply!), which together with Claim 1 yields 0[s] !tdr F0[t01 ; : : : ; t0l ], where val (t0i) = H (ei) for all i 2 [l]. Consequently, val (tdr (s)) = Ghe1 =H (e1); : : : ; el =H (el )i = H he1 =H (e1); : : : ; el =H (el)i = H = val (s). This proves (ii) and shows that tdr (s) is de ned if val (s) is de ned. Thus, (i) is satis ed, too. To complete the proof of the lemma it remains to be shown that tdr is m-copying on input s, where m = maxfjEG j j G = val (s0) for a subterm s0 of sg. For this, it basically suces to prove the following claim. 1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
0
13
1
1
Claim 2. Let s = F [s1 ; : : : ; sk ] 2 T be such that val (s) is de ned, and consider a sequence w of pairwise distinct hyperedges in Eval (s). If (w; s) R (w0; sp) (p 2 [k]) then w0 consists of pairwise distinct hyperedges in Eval (sp) . For the proof, let H; H1; : : : ; Hk ; G; G1; : : : ; Gl be as above, again, and consider the relevant rules (e1 [F [x1 ; : : : ; xk ]] ! t1 ; reg ); : : : ; (el [F [x1; : : : ; xk ]] ! tl ; reg ), where reg is given by reg (xi) = ft 2 T j val (si) = Gig for all i 2 [k]. By the de nition of these rules, if ti (i 2 [l]) contains a subterm e[xp ] then e 2 EGp = Eval (sp ). This proves that w0 consists of hyperedges in Eval (sp). On the other hand, the states which occur in ti (i 2 [l]) are pairwise distinct elements of EG(ei ), which means that no state occurs twice in t1; : : : ; tl because EG(ei ) \EG(ej ) = ; for 1 i < j l (technically, this argument makes use of the assumption that the morphisms associated with Ghe1=G(e1 ); : : : ; el =G(el )i consist of identical mappings). Hence, w0 contains no state twice, which proves Claim 2. Now consider a derivation ( 0; s) R0 (w0; s0) R (w00; s00 ). By the de nition of R0 it follows that (w; s) R (w0; s0) R (w00; s00) where w = e1 el if val (s) = G is as above. Hence, by induction Claim 2 shows that w00 is a sequence of pairwise distinct hyperedges in Eval (s00) , i.e., jw00j m (where m is as in the lemma) because s00 is a subterm of s. Lemma 4.2 does not say anything about eectiveness. Clearly, the construction cannot be performed eectively if even cannot be computed. Furthermore, it is necessary to be able to decide whether a hypergraph belongs to G 0 . It is now shown that these serve in fact as sucient conditions for the construction to be eective. 4.3 Lemma The tdr transducer in the statement of Lemma 4.2 can be constructed algorithmically on input if an algorithm is known which decides for every G 2 G whether G is de ned and if so, constructs G, and an algorithm is known which decides for every hypergraph G whether G 2 G 0 . Proof. In order to perform the constructions in the proofs of Lemma 4.1 and Lemma 4.2 algorithmically, it is necessary to compute the set val (T ) (because this determines the set of states in both cases) and the decomposition Ghe1=G(e1 ); : : : ; el =G(el )i of a given hypergraph G (because this is needed to determine the rules in both cases). The computation of valS(T ) can be done by a standard enumeration technique. For this, notice that val (T) = i2N Si by property (T4), where (i) S0 = ; and (ii) for all i 2 N , Si+1 is the set of all hypergraphs F (G1; : : : ; Gk ) such that F (k) 2 and G1; : : : ; Gk 2 Si with type (Gj ) = type GF (vir F (j )) for all j 2 [k]. Since is nite and is assumed to be computable it is clear that the sets Si can be computed one after another. Since val (T ) is nite and S0 S1 it follows that there is some i0 2 N such that val (T ) = Si . Furthermore, because of the fact that Si+1 = Si implies Si+2 = Si+1 (which follows directly from (ii)) i0 is the smallest index i satisfying Si = Si +1 . Thus, val (T ) can be computed by enumerating S0 ; S1; : : : until some Si with Si = Si+1, which then equals val (T), is encountered. 0
0
0
14
It remains to be shown that the decomposition Ghe1 =G(e1); : : : ; el =G(el )i of a hypergraph G can be computed. By assumption, G can be computed. Therefore, one can enumerate all the ( nitely many) ways to write G as Ghe1=G1 ; : : : ; el =Gl i until one is found that satis es G1 ; : : : ; Gl 2 G 0 . By (T3) G1; : : : ; Gl 2 G 0 implies Gi = G(ei); the proof is complete. In order to make use of Lemma 4.2 in a concrete situation the main task is to nd a way to write a hypergraph G as Ghe1=G(e1 ); : : : ; ek =G(ek )i. If such a decomposition has been de ned the need arises to prove that it indeed satis es G = Ghe1=G(e1 ); : : : ; ek =G(ek )i. For this, the following lemma turns out to be a convenient means. 4.4 Lemma Let G0; G; G1; : : : ; Gk be hypergraphs and let e1 ; : : : ; ek 2 EG be pairwise distinct hyperedges such that type G(ei) = type (Gi) for all i 2 [k]. Let G0 = G ? fe1 ; : : : ; ek g and let mi : Gi ! G0 be an injective morphism for i = 0; : : : ; k, where m0 (point G) = point G0 . Then G0 = Ghe1=G1; : : : ; ek =Gk i if S (i) m0 E (EG ); : : : ; mkE (EGk ) form a partition of EG0 and VG0 = i=0;::: ;k miV (VGi ), (ii) m0 V (VG ) \ miV (VGi ) = miV (points (Gi)) and miV (point Gi ) = m0V (att G(ei )) for all i 2 [k], and (iii) miV (VGi ) \ mj V (VGj ) m0 V (VG ) for all distinct i; j 2 [k]. Proof. It suces to prove the statement for unlabelled hypergraphs, which is done by induction on k. For i = 0; : : : ; k let Vi = miV (VGi ) and Ei = miE (EGi ). For k = 0 one obtains from (i) that m0 is surjective, so in this case m0 is actually an isomorphism between G and G0 since it is injective and m0 (point G) = point G0 , by assumption. Now, let k > 0 and assume the statement holds for k ? 1. De ne H = (V; E; att ; point G0 ), where V = VG0 n mk V (VGk n points (Gk )), E = (EG0 n Ek ) [fek g, and for all e 2 E , att (e) = mk V (point Gk ) if e = ek and att (e) = att G0 (e) otherwise. Then H is well-de ned, which can be seen as follows. Since the Ei form a partition of EG0 every e 2 E n fek g satis es e 2 Ei for some unique i, 0 i < k. Therefore, v 2 [att G0 (e)] implies v 2 V because v 2 Vk yields v 2 Vi \ Vk and thus v 2 V0 (by (iii)), which reveals v 2 mkV (points (Gk )) (by (ii)). Furthermore, for v 2 [point G0 ] we have v 2 V as well, because in this case v 2 V0 (since m0 (point G) = point G0 ), which means that v 2 Vk implies v 2 mkV (points (Gk )) by (ii), again. By the construction of H it is clear that H hek =Gk i = G0. Now, extend m0 to a morphism m00 : (G ? fe1; : : : ; ek?1g) ! H by de ning m00 E (ek ) = ek . Then H , G, G1 ; : : : ; Gk?1, and the morphisms m00 ; m1; : : : ; mk?1 satisfy (i){(iii), so the induction hypothesis yields H = Ghe1 =G1; : : : ; ek?1=Gk?1i. Together, these facts amount to the required equation Ghe1=G1 ; : : : ; ek =Gk i = G0, which com= H hek =Gk i = Ghe1 =G1; : : : ; ek?1=Gk?1ihek =Gk i pletes the proof. 0
0
0
5 From context-freeness to output languages of td transducers In this section the results of Section 4 are applied to context-free sets of hypergraphs that consist of hypertrees (i.e., of hypergraphs with a tree-like structure). The de nition and investigation of hypertrees requires some additional notations and conventions. The hyper15
edges of a hypergraph G are regarded as directed hyperedges, as follows. If att G (e) = v1 vk with k 1 then the sequence sG(e) of sources of e is v1 vk?1 and its target is tG (e) = vk . Furthermore, if point G = v10 vl0 with l 1 then s(G) = v10 vl0?1 and t(G) = vl0. A path in G is a non-empty sequence a1 an 2 (VG [ EG ) such that, for all i 2 [n ? 1], ai 2 VG implies ai+1 2 EG and ai 2 sG(ai+1 ), and ai 2 EG implies ai+1 = tG(ai) (thus, only directed paths are considered). Such a path is also called an a1 an -path and is said to pass a2 ; : : : ; an?1. The path is empty if n = 1. G is called acyclic if the only vv-paths in G (v 2 VG) are the empty ones. The in-degree (out-degree ) of v 2 VG is the number of hyperedges e 2 EG with v = tG(e) (with v 2 [sG(e)], respectively). 5.1 De nition (hyperforest and hypertree ) A hypergraph G 6= ; is a hyperforest if (i) G is acyclic, (ii) for all nodes v 2 VG the out-degree of v in G is at most 1, and (iii) for all a 2 VG [ EG there is an av-path in G for some v 2 points (G). G is a hypertree if, in addition, every node in [s(G)] has in-degree 0 and out-degree 1. For all m 2 N , Tm denotes the set of all hypertrees G such that maxtype (G) m. Notice that De nition 5.1(iii) implies type (G) 1 (since G 6= ;) and type G (e) 1 for all e 2 EG. Moreover, if type G (e) 1 for all e 2 EG then only nodes a 2 VG need to be considered in (iii) (since, for a 2 EG , pG(a; v) exists if pG(tG (a); v)) exists). Note that, intuitively, the nodes in [s(G)] are leaves of a hypertree G and t(G) is the root. In particular, the out-degree of t(G) is 0 and for all a 2 VG [ EG there is an at(G)-path in G. In drawings of hyperforests and -trees targets of hyperedges will be indicated by arrows. In the following, for all m 2 N , (m) denotes the hr signature consisting of all hr operations F such that maxtype (GF ) m, ht(m) = fF 2 (m) j GF is a hypertreeg denotes the signature S of operations in whose underlying hypergraphs are hypertrees, = (m) () m2N (m) , and S ht() = m2N ht(m) . Since the out-degree of a node in a hyperforest G is at most one there can be at most one simple ab-path in G, for all a; b 2 VG [ EG . In the following, this path is denoted by pG (a; b) if it exists. The next lemma, which concerns these paths, turns out to be useful. 5.2 Lemma Let G be a hyperforest, and let a 2 VG [ EG and v; v0 2 VG nfag be such that pG(a; v) and pG(a; v0) exist. If pG(a; v) does not pass v0 and pG(a; v0) does not pass v then v = v0. Proof. Since the out-degree of every node in G is at most 1 it follows that one of the paths is an initial segment of the other one. Suppose pG (a; v) is an initial segment of pG(a; v0). Then pG(a; v0) passes v unless v = v0. The aim of this section is to show that every context-free set L Tm has the form val (T ) where T 2 OUT m (TDfc). In order to establish this result, a tree transduction in dTDRfc is constructed that takes as input a term s 2 T and transforms it into an equivalent term in T m with m = maxtype (val (s)) if val (s) is a hypertree. This tree transduction is obtained in two steps, using Lemma 4.2 twice (which is possible due to Lemma 2.3). The rst application of the lemma yields a tree transduction whose output terms are elements of +
+
ht(
)
( )
ht(
)
16
ht() , whereas the second takes care for the types and yields terms in T m . For the rst step, from this point onwards and until the end of the proof of Theorem 5.9, G , G , G 0 , and : G ! G refer to the following. G is the set of all hypergraphs. G is the set of all unlabelled hyperforests G such that, if type (G) = n, (i) VG = points (G), (ii) EG = fe1 ; : : : ; eng where tG (ei) = point G(i) for all i 2 [n], and (iii) sG(ei) = point G (i1 ik ) implies i1 < < ik for all i 2 [n]. G 0 is the set of all hypertrees. For all G 2 G , G is de ned if and only if G is a hyperforest. In this case G is given as follows: VG = points (G), point G = point G , and [sG(ei)] (i 2 [type (G)]) is the set of all point G(j ) with i 6= j such that pG(point G(j ); point G(i)) exists and does not pass a point (note that the order of nodes in sG(ei) is determined by (iii) above). In order to understand the intuition behind these choices consider a hyperforest G and a point v 2 points (G). From v one can descend down the hyperforest, passing hyperedges against their direction on a reverse path, until another point is reached (or until the path cannot be extended any further). Obviously, the sub-hypergraph H 0 of G consisting of all nodes and hyperedges reachable from v in this manner is a hypertree if the node v is chosen as t(H 0) and the points of G reached on the mentioned paths are taken as s(H 0). Now, imagine that all hyperedges and all non-points of H 0 are deleted from G, while a hyperedge e is added whose attachment is the sequence of points of H 0. Then, the resulting hypergraph H is a hyperforest satisfying H he=H 0i = G. If all k points of G are treated in this way then G and the corresponding components G(e1); : : : ; G(ek ) are obtained. This is what is depicted schematically in Figure 2. By a series of lemmas it is now shown that the choice of G , G , G 0 , and ful lls the requirements, and in particular (T1){(T5). The rst lemma states that the image of is indeed a subset of G . 5.3 Lemma G 2 G for every hyperforest G. Proof. It suces to show that G is a hyperforest since (i){(iii) in the de nition of G are satis ed by de nition. Due to the construction of G, for all i; j 2 [type (G)], if pG(point G(i); point G(j )) exists then pG (point G(i); point G(j )) exists, too. This implies that G is acyclic since G is acyclic. To verify that De nition 5.1(ii) is ful lled, assume there are i; j; l 2 [type (G)] such that point G(l) 2 [sG(ei )] \ [sG(ej )]. Then pG(point G(l); point G(i)) and pG(point G(l); point G(j )) both exist and do not pass a point. In particular, they do not pass point G (i) and point G (j ), which by Lemma 5.2 yields i = j . Finally, notice that De nition 5.1(iii) is trivially satis ed because VG = points (G). ht(
)
5.4 Lemma (veri cation of (T1)) Let G; G0 be hypergraphs and e 2 EG with type G(e) = type (G0). If G is a hyperforest (hypertree) and G0 is a hypertree then Ghe=G0 i is a hyperforest (hypertree, respectively).
17
3
2
G(e2) 1
G(e1 )
4
G(e3 )
7
2
3
e2 5
1
G(e4) G(e7 ) G(e5 )
2
4
e4
1
e1
6
7
2
e7
e3 1
5
e5
6
e6
G(e6) G
G
Figure 2: Schematic view of a hyperforest G and the corresponding hyperforest G. Proof. The proof consists in a straightforward veri cation of the relevant properties and is therefore omitted.
5.5 Lemma (veri cation of (T2)) Let G be a hyperforest with EG = fe1; : : : ; ek g. Then there are hypertrees G1 ; : : : ; Gk with type (Gi) = type G(ei) for all i 2 [k], such that G = Ghe1=G1 ; : : : ; ek =Gk i. Proof. For i 2 [k] let Ei be the set of all hyperedges e 2 EG such that pG (e; point G(i)) exists and does not pass a point. If Ei = ;, de ne Gi to be the hypergraph of type 1
consisting of the single node point G(i) and no hyperedges. Otherwise, Gi = (V; Ei; att GjEi ; point G(i1 il i)) S where V = e2Ei [att G(e)] and point G(fi1; : : : ; il ; ig) = points (G) \ V with i1 < < il . The sets E1; : : : ; Ek form a partition of EG, which can be seen as follows. As G is a hyperforest, for all e 2 EG there is some v 2 points (G) such that pG (e; v) exists. This yields E1 [ [ Ek = EG . On the other hand, by Lemma 5.2 there is only one i 2 [type (G)] such that pG(e; v) exists and does not pass a point. Therefore, Ei \ Ej = ; for all distinct i; j 2 [type (G)], which means that E1 ; : : : ; Ek indeed form a partition of EG. By Lemma 4.4 (where the mi are identical morphisms) this yields Ghe1 =G1; : : : ; ek =Gk i = G as soon as the following can be shown. VG \ VGi = points (Gi) and point Gi = att G (ei) for all i 2 [k], and VGi \ VGj VG for all distinct i; j 2 [k]. By de nition, points (Gi) = points (G) \ VGi = VG \ VGi and point Gi = att G (ei). Concerning the last inclusion, if v 2 VGi \ VGj for distinct i; j 2 [k] then either Ei = ; or Ej = ;, in which case v 2 VG by de nition, or there are e 2 Ei , e0 2 Ej such that v 2 [att G(e)] \ [att G(e0 )]. This is impossible unless v 2 [sG(e)] or v 2 [sG(e0)] as tG(e) = tG(e0) implies i = j . Therefore, 18
assume without loss of generality v = tG(e) 2 [sG(e0 )]. Then pG(v; point G(i)) does not pass point G (j ) and pG(v; point G (j )) does not pass point G (i). Since i 6= j and pG (v; point G (j )) is not empty, Lemma 5.2 yields that pG(v; point G(i)) is empty, i.e., v = point G (i) 2 VG. Thus, Ghe1 =G1; : : : ; ek =Gk i = G. It remains to be noticed that Gi is a hypertree for all i 2 [k], which follows directly from the construction, together with the fact that G is a hyperforest. 5.6 Lemma (veri cation of (T3)) Let G 2 G with EG = fe1; : : : ; ek g and let Gi; G0i be hypertrees with type (Gi) = type G(ei) = type (G0i) for i 2 [k]. Then Ghe1 =G1; : : : ; ek =Gk i = 0 0 0 Ghe1=G1 ; : : : ; ek =Gk i implies Gi = Gi for all i 2 [k]. Proof. Let m be an isomorphism between the hypergraphs H = Ghe1 =G1 ; : : : ; ek =Gk i and H 0 = Ghe1 =G01; : : : ; ek =G0k i. By Lemma 5.4 H and H 0 are hyperforests. The proof works by showing that the restriction of m to Gi (i 2 [k]) yields an isomorphism between Gi and G0i. Since VG = points (G) and mV (point H ) = point H 0 it follows that mV (att G (ei)) = att G (ei) and hence mV (point Gi ) = point G0i . Therefore, it remains to be veri ed that the equations mV (VGi n points (Gi)) = VG0i n points (G0i) and mE (EGi ) = EG0i hold. In fact, by the symmetry of the situation it suces to show mE (EGi ) EG0i , since mE (e) 2 EGS0i implies mV ([att G (e)]) VG0i and Gi is a hypertree, which means VGi n points (Gi) e2EGi [att Gi (e)]. Suppose e 2 EGi and let e0 = mE (e). Since Gi is a hypertree pGi (e; t(Gi)) exists and does not pass any point (since every node in [s(Gi)] has in-degree 0). Hence, pH (e; point H (i)) exists and does not pass a point. Similarly, if e0 2 EG0j for some j 2 [k] then pH 0 (e0 ; point H 0 (j )) exists and does not pass a point. Now, an application of Lemma 5.2 to pH 0 (e0 ; point H 0 (j )) and the image of pH (e; point H (i)) in H 0 reveals that i = j and thus e0 2 EG0i , which completes the proof.
5.7 Lemma (veri cation of (T4)) For all hypergraphs G; G0 and all e 2 EG with type G(e) = type (G0), Ghe=G0i is a hyperforest if and only if G0 and Ghe=G0 i are hyperforests. In this case Ghe=G0 i = Ghe=G0i.
Proof. The lemma is proved by means of a series of claims. Claim 1. Let H be a hyperforest. Then, for all v 2 VH the out-degrees of v in H and in H coincide. By the de nition of H the out-degree of v in H is at least one (and thus exactly one, by Lemma 5.3) if and only if there is some v0 2 points (H ) such that v 6= v0 and pH (v; v0) exists; otherwise, its out-degree is 0. Clearly, v0 cannot exist if the out-degree of v in H is 0. Therefore, let v 2 [sH (e)] for some e 2 EH . By De nition 5.1(iii) there is a point v0 of H such that pH (e; v0) exists, i.e., pH (v; v0) exists, which implies that the out-degree of v in H is one. Claim 2. Let H be a hyperforest. For all v; v 0 2 VH , pH (v; v 0 ) exists if and only if pH (v; v 0) exists. By the de nition of H , if pH (v; v0) exists then so does pH (v; v0). Conversely, if v0p1 v1 pnvn is a vv0-path in H , where v0 ; : : : ; vn are the points on this path and vi = point H (ji) for all
19
i 2 [n], then the hyperedge eji (i 2 [n]) in H satis es vi?1 2 [sH (eji )] and vi = tH (eji ), so v0 ej v1 ejn vn is a vv0-path in H . Claim 3. If Ghe=G0 i is a hyperforest then so is G0 . If G0 contains a cycle then so does Ghe=G0i, and if a node in G0 is of out-degree greater than 1 the same holds in Ghe=G0i. Finally, if G0 contains a node for which there is no path leading to a point of G0 this holds in Ghe=G0i, too, by the de nition of hyperedge replacement. Claim 4. Suppose G0 is a hyperforest. Then Ghe=G0 i is a hyperforest if and only if Ghe=G0i is a hyperforest. By Claim 2, for all nodes v; v0 of Ghe=G0 i there is a vv0-path in Ghe=G0i if and only if there is such a path in Ghe=G0i. Hence, Ghe=G0i satis es (i) and (iii) of De nition 5.1 if and only if Ghe=G0i does. Moreover, by Claim 1 De nition 5.1(ii) holds in Ghe=G0i if and only if it holds in Ghe=G0i. Claim 5. If Ghe=G0 i is de ned then Ghe=G0i = Ghe=G0 i. For every hyperforest H the de nition of H depends only on type (H ) and on the paths between the points of H . By Claim 2 this means Ghe=G0i and Ghe=G0i are equal. This completes the proof of the lemma, since Claims 3 and 4 yield the rst statement and Claim 5 is the last one. 5.8 Lemma (veri cation of (T5)) For every k 2 N the number of hypergraphs G 2 G satisfying type (G) k is nite. Proof. This is obvious as all nodes of such a hypergraph G are points, every node has in-degree 1, and there are no hyperedges of type 0. It is now possible to apply Lemma 4.2 in order to obtain the rst of the tdr transducers mentioned in the discussion above. 5.9 Theorem For every nite hr signature one can eectively construct a deterministic nite-copying tdr transduction tdr : T ! T such that val (tdr (s)) = val (s) for all s 2 T for which val (s) is a hypertree, and tdr (s) is unde ned if val (s) is no hypertree. Proof. Due to the lemmas 5.3{5.8, Lemma 4.2 applies, with the given choices of G , G , G 0 , and . Let tdr0 : T ! T be the tdr transduction this yields. Obviously, the conditions given in Lemma 4.3 are ful lled, which means that the corresponding deterministic nitecopying tdr transducer tdr0 can be obtained eectively. By Lemma 4.2 dom (tdr ) = fs 2 T j val (s) is a hyperforestg and for all s 2 dom (tdr ), t = tdr (s) has the form F [t1; : : : ; tk ], where GF 2 G , [vir F ] = EF (which in particular implies k 1), and t1 ; : : : ; tk 2 T . Therefore, val (t) = val (s) is a hypertree if and only if att F (vir F (k)) = point F and, for all i 2 [k ? 1], val (ti) is the single-node hypertree G0 without hyperedges. Obviously, the set T = ft 2 T j val (t) = G0g is regular. Therefore, it is straightforward to construct a linear deterministic tdr transducer tdr0 which on input t = F [t1 ; : : : ; tk ] yields tk if att F (vir F (k)) = point F and val (t1 ) = G0, and = val (tk?1) = is unde ned otherwise. According to the observation above, for all t 2 out (tdr 0 ), t0 = tdr (t) is de ned if and only if val (t) is a hypertree, and in this case val (t0) = val (t). Therefore, 1
ht( )
0
ht( )
0
20
tdr = tdr 0 tdr 0 (which by Lemma 2.3 is an element of dTDRfc) satis es the statement of the theorem. By Theorem 5.9 it is now possible to restrict one's attention to input terms that consist of operations whose underlying hypergraphs are hypertrees. In other words, for the second application of Lemma 4.2 G will be the set of all hypertrees. The decomposition Ghe1=G(e1 ); : : : ; ek =G(ek )i of a hypertree G must then be chosen in such a way that the types of the component hypertrees G(e1); : : : ; G(ek ) are small (because the aim is to obtain an output term in T m if the the input term denotes a hypertree in Tm ). For the necessary de nitions the notion of fork nodes de ned next is used. 5.10 De nition (fork node ) Let G be a hypertree. A node v 2 VG is a fork node of G if v 2 points (G) or there are distinct points v1; v2 2 points (G) such that pG(v1 ; v) and pG(v2; v) both exist and do not pass a common node. The set of all fork nodes of G is denoted by fork (G). Intuitively, the structure of a hypertree G induces a hypertree-like structure on fork (G). For a node v 2 fork (G) n ft(G)g consider the rst fork node v0 dierent from v that appears on the path pG(v0; t(G)). Since t(G) is a fork node such a node must exist. Obviously, v0 is the unique node such that pG(v; v0) exists, is non-empty, and does not pass a fork node. Now, the idea to construct G is to keep only the fork nodes as nodes and to connect v and v0 by a hyperedge in such a way that v is one of its sources and v0 is the target. Of course, there may be further fork nodes related to v0 in the same way as v. Therefore, it has to be made precise how many dierent hyperedges with target v0 are used, how the potential sources v are divided among them, and how the sources of a hyperedges are ordered. To answer these questions in a natural way that re ects the structure of G, notice that pG(v1; v0) and pG(v2 ; v0) (where v1 6= v2 ) may be related in two dierent ways. They never pass a common node (since the rst node at which both paths meet must be a fork node), but the last hyperedges they pass may or may not be equal. In G, v1 and v2 will be sources of the same hyperedge (with target v0) in the rst case, and they will be incident with dierent hyperedges in the second. As a by-product this decision provides a natural order on the sources of each hyperedge. If both pG(v1 ; v0) and pG(v2 ; v0) pass e 2 EG they must enter e through dierent sources sG(e; i1 ) and sG(e; i2 ) since the paths do not pass a common node. In the sequence of sources of the new hyperedge v1 will appear before v2 if i1 < i2 . In order to make things precise, consider a hypertree G and a hyperedge e 2 EG . Then G (e) denotes the sequence v1 vn 2 VG which is given as follows: fv1; : : : ; vng is the set of all nodes v 2 fork (G) such that pG(v; e) exists and does not pass a fork node. Furthermore, if j1; : : : ; jn are such that pG(vi; e) passes sG(e; ji) for all i 2 [n], then j1 < < jn. It was argued above on an intuitive level that the de nition of G (e) is well given, that is, the condition j1 < < jn is satis able. In order to show that this is indeed the case (and also for future use), denote the concatenation a1 ar a02 a0s of paths p = a1 ar and p0 = a01 a0s with ar = a01 by p p0. To derive a contradiction suppose that there are k; l 2 [n] such that vk 6= vl but jk = jl . Then, there is a node v that is passed by both pG(vk ; e) and pG(vl ; e), such that p = pG(vk ; v) and q = pG(vl ; v) are non-empty paths that do not pass a common node. Furthermore, since vk and vl are fork nodes there are vk0 ; vl0 2 points (G) such ht(
)
21
5
2
1
5
3
4
2
1
G
3
4
G
Figure 3: Hypertrees G and G. Fork nodes except points are emphasized by extra circles. Sources are assumed to be ordered from left to right. that p0 = pG(vk0 ; vk ) and q0 = pG(vl0; vl) exist. Now, p0 p and q0 q do not pass a common node (since otherwise p0 p = p00 p0 and q0 q = q00 p0 for a non-empty path p0, which would imply that p and q pass a common node) and thus v 2 fork (G). A contradiction. For all hypergraphs G and all v 2 VG denote by in G(v) the set fe 2 EG j tG(e) = vg. It is now possible to give the new choices of G , G , G 0 , and : G ! G . For the rest of this section these notations refer to the following. G is the set of all hypertrees. G is the set of all unlabelled hypertrees G such that { fork (G) = VG and { for all v 2 VG there is at most one hyperedge e 2 in G(v) that has type 1. G 0 is the set of all hypertrees G such that { jEG j 1 and { if type (G) > 1 then in G (t(G)) = fe0g for some hyperedge e0 with G(e0 ) = s(G). (Notice that the second condition implies fork (G) = points (G).) For all hypertrees G de ne G = (fork (G); E; att ; point G), where E contains for every node v 2 fork (G) and every sequence w 2 fG (e) j e 2 in G(v)g a hyperedge e with att (e) = wv (see Figure 3). Notice that is total. To gain a proper intuition concerning the reader should notice the following subtle point of the de nition above. For all hyperedges e; e0 2 in G (v) the sequences 22
w = G(e) and w0 = G (e0) are distinct unless w = w0 = . Thus, the hyperedges e 2 in G(v) with G (e) 6= (i.e., those reachable from a fork node) give rise to pairwise distinct counterparts in EG whereas those with G (e) = all correspond to the same hyperedge of type 0 in EG. In particular, at most one hyperedge of type 0 is attached to each node of G, as required in the de nition of G . The following lemma is needed to verify the required properties of G , G , G 0 , and . 5.11 Lemma Let G be a hypertree with e 2 EG and let G0 2 G , where type (G0) = type G (e). Then Ghe=G0i = G. Proof. First notice that, by Lemma 5.4, Ghe=G0 i is de ned because Ghe=G0 i is a hypertree. It is clear that, for all nodes v; v0 2 VG, pG(v; v0) exists if and only if pGhe=G0i (v; v0) exists. More precisely, by the de nition of hyperedge replacement the path pG(v; v0) exists and has the form p1 sG(e; i) e tG(e) p2 (that is, passes e by entering it through the ith source) if and only if pGhe=G0 i exists and has the form p1 pG0 (s(G0; i); t(G0)) p2. Since G0 2 G 0 only the points of G0 are fork nodes. Therefore, paths pG0 (s(G0 ; i); t(G0)) and pG0 (s(G0; j ); t(G0)) with 1 i < j < type (G0) never pass common nodes. Hence, fork (Ghe=G0i) VG, and a node v 2 VG is a fork node in G if and only if it is a fork node in Ghe=G0i. The latter holds because, if pGhe=G0i (u; v) exists (where u 2 VG) then it passes exactly those nodes of G which are passed by pG(u; v) in G, by the observations above. This amounts to the equation fork (G) = fork (Ghe=G0i). Now, for all hyperedges e0 2 EG de ne ee0 2 EGhe=G0 i as follows. If e0 = e then ee0 is an arbitrary hyperedge e0 2 in G0 (t(G0)). Otherwise, ee0 = e0 . Notice that in G0 (t(G0)) 6= ; since G0 2 G 0 , and that ee is uniquely determined if type G(e) = type (G0 ) > 1. By the de nition of G, the proof is nished if it can be shown that Ghe=G0i (ee0) = G (e0) for all e0 2 EG . Since fork (G) = fork (Ghe=G0i), for every node v 2 VG such that pG(v; e0) exists, this path passes a fork node if and only if pGhe=G0i (v; ee0) passes a fork node. Therefore, it remains to be shown that, for all v; v0 2 VG and all e0 2 EG such that pG(v; e0) = p sG(e0; i)e0 and pG(v0; e0 ) = p0 sG(e0 ; i0)e0 with i < i0, the paths pGhe=G0 i(v; ee0) = q sGhe=G0i (ee0; j )ee0 and pGhe=G0i (v0; ee0 ) = q0 sGhe=G0i (ee0; j 0)ee0 satisfy j < j 0. This is obvious if e0 6= e since then i = j and i0 = j 0. Furthermore, for e there are paths q0 ; q00 such that pG0 (sG0 (i); t(G0)) = q0 sG0 (ee; j )ee and pG0 (sG0 (i0); t(G0)) = q0 sG0 (ee; j 0)ee, which yields j < j 0 as G0 (ee) = s(G0 ) by the de nition of G 0 . Now, the veri cation of the conditions imposed on G , G , G 0 , and can start. The fact that G 2 G for all hypertrees G will turn out as a by-product of Lemma 5.13. Therefore, the next lemma concerns (T1). 5.12 Lemma (veri cation of (T1)) Let G; G0 be hypertrees with e 2 EG and type G(e) = type (G0). Then Ghe=G0 i is a hypertree, and if G; G0 2 G 0 then Ghe=G0 i 2 G 0 , too. Proof. It was proved in Lemma 5.4 that Ghe=G0 i is a hypertree, so assume G; G0 2 G 0 . Then EGhe=G0i jEG0 j 1, as required. To verify the second requirement, assume type (Ghe=G0 i) > 1. Since type (G) = type (Ghe=G0i) it follows that there is some e0 2 EG such that fe0g = in G(t(G)) with G(e0 ) = s(G). Let E = in Ghe=G0i(t(Ghe=G0i). It must be shown that E is a singleton fe00 g and that e00 23
t(G) !
t(G) !
n
n
e
e
v
v
e0
i
i
Figure 4: The two cases of the inductive step in the proof of Lemma 5.13. satis es Ghe=G0 i(e00 ) = s(Ghe=G0i). For the rst part, it is clear that E = fe0 g if e0 6= e. Otherwise, type G (e) = type G (e0) > s(G) = 1. Therefore, in this case in G0 (t(G0)) = fe00g for some hyperedge e00 and hence E = fe00g. Finally, by Lemma 5.11 Ghe=G0i = G, which in particular implies Ghe=G0i (e00 ) = G(e0 ) = s(G) = s(Ghe=G0i).
5.13 Lemma (veri cation of (T2)) For every hypertree G with EG = fe1; : : : ; ek g there are hypertrees G1 ; : : : ; Gk 2 G 0 with type (Gi) = type G (ei) for all i 2 [k] such that G = GhG1; : : : ; Gk i. Furthermore, G is an element of G . Proof. The proof is by induction on jVG n fork (G)j. To start with, if VG = fork (G) observe that G (e) = sG(e) for all e 2 EG. Therefore, G is the hypertree obtained from G
by removing (1) all hyperedge labels and (2) for every node v all but one of the hyperedges e 2 in E (v) of type 1, if there are any. (In other words, hyperedges of type 1 attached to the same node are identi ed.) This implies immediately that G 2 G . Furthermore, it reveals that G = Ghe1=G1; : : : ; ek =Gk i, where Gi = ([att G(ei)]; E; att GjE ; lab GjE ; att G (ei)) with E = fe 2 EG j att G(e) = att G(ei)g for i 2 [k]. Obviously, Gi 2 G 0 for all i 2 [k], as required (note that jE j 1 in the de nition of Gi, where equality holds if type G(ei) > 1, because the out-degree of nodes is at most 1). Now suppose there is some node v 2 VG n fork (G). There are two cases. Case 1. One can choose v in such a way that there is no v 0 2 [s(G)] such that pG (v 0; v) exists. In this case it may be assumed without loss of generality that in G(v) contains no hyperedge of type > 1. This situation is depicted in Figure 4 on the left. Let e 2 EG be the unique hyperedge with v 2 [sG(e)] and let E = feg [ fe0 2 EG j att G (e0) = vg. Then E = fe0 2 EG j v 2 [att G(e0 )]g. Let att G(e) = w1 vw2 and de ne G0 = ([att G (e)]; E; att GjE ; w1w2). Furthermore, let G0 = (VG n fvg; EG n (E n feg); att ; point G) where att (e0) = att G(e0) for all e0 2 EG n E and att (e) = w1 w2. It should be obvious (and can be checked in a straightforward way, using Lemma 4.4) that G0 he=G0 i = G. Moreover, by construction G0 is a hypertree and G0 2 G 0 , so Lemma 5.11 yields G0 = G. By the induction hypothesis, G 2 G and there are 24
H1; : : : ; Hk 2 G 0 such that G0 = Ghe1 =H1; : : : ; ek =Hk i. Therefore, if e 2 EHi , G = G0 he=G0 i = Ghe1 =H1; : : : ; ek =Hk ihe=G0i = Ghe1 =H1; : : : ei?1=Hi?1; ei=Hihe=G0i; ei+1=Hi+1; : : : ; ek =Hk i; which nishes the reasoning for Case 1 since Hihe=G0 i 2 G 0 by (T1). Case 2. For every node v0 2 VG there is some v 0 2 [s(G)] such that pG (v 0; v0) exists. In this case there are unique hyperedges e0 ; e 2 EG such that tG(e0 ) = v 2 [sG(e)] and type G(e0 ) > 1, which can be seen as follows. Since the out-degree of v is 1, e is uniquely S determined. Furthermore, for every node v0 2 e02in G (v) [sG (e0)] there is some v0 2 [s(G)] such that pG(v0; v0) exists. Consequently, if there were two such nodes v0 , v would turn out to be a fork node. Hence, e0 is uniquely determined and, what is more, type G(e0) = 2. Hence, the situation turns out to be the one depicted in Figure 4 on the right. Suppose att G(e) = w1vw2 and let E = fe0; eg [ fe 2 EG j att G(e) = vg. Again, E = fe0 2 EG j v 2 [att G(e0 )]g. Now de ne G0 = (VG n fvg; EG n (E n feg); att ; point G) where att (e0 ) = att G (e0) for all e0 2 EG n E and att (e) = w1 sG (e0 )w2 . Furthermore, let G0 = ([att G(e)] [fsG (e0)g; E; att GjE ; w1sG(e0)w2 ). Then, as in the rst case, G0 is a hypertree and G0 2 G 0 , and it holds that G0 he=G0 i = G. Therefore, the same arguments as in the rst case complete the proof. 5.14 Lemma (veri cation of (T3)) Let G 2 G with EG = fe1; : : : ; ek g and let Gi; G0i 2 G 0 with type (Gi ) = type G (ei ) = type (G0i ) for all i 2 [k ]. Then Ghe1 =G1 ; : : : ; ek =Gk i = 0 0 0 Ghe1=G1 ; : : : ; ek =Gk i implies Gi = Gi for all i 2 [k]. Proof. Let m be an isomorphism between the hypergraphs H = Ghe1 =G1 ; : : : ; ek =Gk i and H 0 = Ghe1 =G01; : : : ; ek =G0k i, which by Lemma 5.4 are hypertrees. As in the proof of Lemma 5.6 it suces to show that for every i 2 [k] and every hyperedge e 2 EGi it holds that mE (e) 2 EG0i . Therefore, it suces to show that for every hyperedge e 2 EH the index i 2 [k] with e 2 EGi is uniquely determined by G and H , that is, does not depend on the particular choice of G1; : : : ; Gk . By Lemma 5.11, H = G, which implies fork (H ) = VG. Now, consider some hyperedge e 2 EH and let p = v1 e02 v2 e0nvn be the unique path in H such that v1 = tH (e), vn 2 fork (H ), and v1; : : : ; vn?1 62 fork (H ). Then v1 ; : : : ; vn?1 62 VG, which by the de nition of hyperedge replacement implies e02; : : : ; e0n 2 EGi for the index i 2 [k] such that e 2 EGi . Therefore, it means no loss of generality to assume in the following that tH (e) 2 fork (H ). Let I = fi 2 [k] j type G(ei) > 1g and choose some vi0 2 [sG(ei)] for every i 2 I . By the de nition of G 0 , for every i 2 I there is a hyperedge e 2 EGi such that in Gi (t(Gi)) = feg. Hence, this hyperedge must be the last hyperedge on the path pGi (vi0 ; t(Gi)). This is equivalent to saying that e is the last hyperedge on the path pH (vi0 ; tG(ei)). Consequently, for every i 2 I , e 2 EGi if and only if pH (vi0 ; tG(ei )) passes e. It remains to consider the case where no i 2 I exists such that pH (vi0 ; tG(ei )) passes e. In this case it follows that there is some j 2 J = [k] n I such that e 2 EGj . This is possible only if tG (ej ) = t(Gj ). By the de nition of G there is at most one such j 2 J , which completes the proof. 25
5.15 Lemma (veri cation of (T4)) For all hypertrees G; G0 with e 2 EG and type G (e) = type (G0), Ghe=G0 i = Ghe=G0 i. Proof. Suppose EG0 = fe1 ; : : : ; ek g. By (T2) (i.e., Lemma 5.13) there are G1 ; : : : ; Gk 2 G 0 such that G0he1=G1; : : : ; ek =Gk i. Therefore, Ghe=G0i = GhG0he1=G1; : : : ; ek =Gk ii = Ghe=G0ihe1 =G1; : : : ; ek =Gk i = Ghe=G0i
using Lemma 3.3 for the second and k times Lemma 5.11 for the third equality. 5.16 Lemma (veri cation of (T5)) For every k 2 N the set fG 2 G j type (G) kg is nite. Proof. Let G 2 G , where type (G) = l. If l = 1 then jVGj = 1. Otherwise, since every node of G is a fork node, replacing every hyperedge e 2 EG of type m with m ? 1 edges from the sources of e to its target yields a tree (i.e., a hypertree that contains only hyperedges of type 2) each non-point of which has in-degree at least two. Hence, jVG n ft(G)gj = jVG j ? 1 is bounded from above by the number of nodes of a binary tree with js(G)j = l ? 1 leaves, that is, jVGj 2(l ? 1). As the out-degree of nodes v 2 VG is 1 it follows that jfe 2 EG j type G(e) > 1gj < jVGj. By the de nition of G 0 , jfe 2 EG j type G(e) = 1gj VG. This proves the lemma since the number of unlabelled hypertrees with a xed number of nodes and hyperedges is nite.
5.17 Theorem For every nite hr signature one can eectively construct a deterministic nite-copying tdr transduction tdr : T ! T such that val (tdr (s)) = val (s) for all s 2 T for which val (s) is a hypertree, and tdr (s) is unde ned if val (s) is no hypertree. Furthermore, for all t 2 out (tdr ) with val (t) 2 Tm (m 2 N ) it holds that t 2 T m . ht( )
ht(
)
Proof. Let tdr0 be the deterministic nite-copying tdr transducer provided by Theorem 5.9 and let 0 be the output signature of tdr0 . Then, since out (tdr 0 ) T it can be assumed without loss of generality that 0 ht() . By the lemmas 5.12{5.16, Lemma 4.2 applies to 0 , with the given choices of G , G , G 0 , and . Let tdr 1 : T ! T0 be the tdr transducer obtained in this way. Again, it should be clear that the assumptions of Lemma 4.3 are ful lled, so a corresponding tdr transducer tdr0 can indeed be constructed. Let tdr = tdr 1 tdr 0 (which by Lemma 2.3 is an element of dTDRfc). Then it follows immediately that val (tdr (s)) = val (s) for all s 2 T for which val (s) is a hypertree, and that tdr (s) is unde ned if val (s) is no hypertree. It remains to be veri ed that every term t = F [t1; : : : ; tk ] 2 out (tdr 1) with val (t) = G satis es t 2 T m , where m = maxtype (G) (note that m 1 since ht(0) = ;). For this, it suces to show that type (GF 0 ) m for all operations F 0 that occur in t. Clearly, type (GF ) = type (G) m. Furthermore, by Lemma 4.2 all underlying hypergraphs of operations in t1; : : : ; tk are elements of G 0 . Consider a subterm t0 = F 0[t01 ; : : : ; t0m ] of one of the terms t1; : : : ; tn and let val (t0) = G0. By (T1) G0 2 G 0 . Therefore, if type (GF 0 ) = type (G0) > 1 then there is a hyperedge e0 2 EG0 such that G0 (e0 ) = s(G0). This yields type (G0) = js(G0)j + 1 = jG0 (e0 )j + 1 jsG0 (e0 )j + 1 = type G0 (e0 ) maxtype (G0) maxtype (G). ht( )
0
ht(
)
26
As a consequence of Theorem 5.17 the main result of this section is obtained. It says that every context-free set L Tm is de nable by the output language of a nite-copying td transducer that uses only operations in ht(m) . 5.18 Theorem Let m 2 N and let L Tm be context-free. Then L = val (T ) for some T 2 OUT m (TDfc). Proof. Let T0 T be a regular set of terms such that val (T0 ) = L, where is a nite hr signature, let tdr be as in Theorem 5.17, and T = tdr (T0). Then T T m and val (T ) = val (T0 ) = L. Since T0 is regular, it is obvious that the domain restriction tdr jT of tdr to T0 is an element of dTDRfc . Therefore, T = tdr (T0 ) = out (tdr jT ) 2 OUT m (TDRfc). Furthermore, OUT (TDRfc(n)) = OUT (TDfc(n) ) for all signatures and all n 2 N (which is an easy nite-copying variant of [Eng77, Theorem 4.2]). Clearly, Theorem 5.18 is eective in the sense that a nite-copying td transducer td with L = val (out (td )) can be constructed algorithmically, where the input is a regular tree grammar g such that L = val (L(g)). There is an alternative view and use of Theorem 5.17 that shall brie y be discussed here. As mentioned before, a tree transduction as in the theorem can be seen as a sort of translation. It takes as input a term over (which is an arbitrary hr signature) and yields|provided that the term denotes a hypergraph in the class of interest (i.e., a hypertree in Tm in this case)|an equivalent term in T m . (For a formalization of the concept of translations see [Dre96, De nition 3.3].) This view turns out to be useful in the context of computation by tree transductions (cf. [Dre96]). Let ; 0 be signatures of operations over sets A and B , respectively. A partial function f : A ! B is said to be (eectively) C computable with respect to and 0 for a class C of tree transductions if for every nite signature 0 a tree transduction 2 C exists (can be constructed algorithmically) such that f (val (t)) = val 0 ( (t)) for all t 2 T (where val and val 0 denote the respective evaluation functions). As a corollary to Theorem 5.17 the following result is obtained. 5.19 Theorem Let be a signature of operations on a set A and let m 2 N . 1. A partial function f : A ! Tm is (eectively) dTDRfc computable with respect to and () if and only if it is (eectively) dTDRfc computable with respect to and ht(m) . 2. A partial function f : Tm ! A is (eectively) dTDRfc computable with respect to () and if and only if it is (eectively) dTDRfc computable with respect to ht(m) and . Proof. In both cases one direction is trivial whereas the other one is obtained by composing the tdr transduction provided by Theorem 5.17 (for every nite hr signature) with the assumed tdr transduction (using Lemma 2.3). ht(
)
ht(
)
0
0
ht(
ht(
)
)
0
6 From output languages of td transducers to context-freeness In this section the converse of Theorem 5.18 is proved. In fact, the statement holds for arbitrary sets of hypergraphs (rather than only for sets of hypertrees). It says that for every 27
set T 2 OUT m (TDfc(n) ) the set val (T ) is (mn) -context-free. This result is more or less a direct consequence of the following lemma. 6.1 Lemma Let td be an n-copying td transducer such that out (td ) T m , for some m 2 N ; n 2 N + . Then one can eectively construct a linear and nondeleting td transducer td0 such that out (td 0 ) T mn and val td 0 = val td . Proof. Let td = (; 0 ; ?; R; 0). By Lemma 3.5 it may be assumed without loss of generality that td is unitary. Let ?0 be the (in nite) set of all states of the form where (1) 1; : : : ; l 2 ? and (2) F is an hr operation of arity l with VF = [point F ] = S e2EF [att F (e)], EF = [vir F ], and type GF (e) m for all e 2 EF . Before the rules are constructed formally, the idea behind ?0 and these rules is explained. Intuitively, a state corresponds to a virtual hyperedge of type type (GF ) in the td transducer td0 to be constructed. The state indicates that this virtual hyperedge comprises l of the virtual hyperedges of operations in rules of td (where 1; : : : ; l are the corresponding states). These l hyperedges are the virtual ones of F . In other words, the purpose of F is to remember the way in which the new hyperedge is composed of the l original ones. According to this intuition the rules will be constructed. A rule with left-hand side [f [x1 ; : : : ; xk ]] accomplishes the work of l rules of td. Its righthand side is obtained from the right-hand sides of l rules in R whose left-hand sides are
1[f [x1 ; : : : ; xk ]]; : : : ; l[f [x1 ; : : : ; xk ]]. Figure 5 illustrates by means of an example how this is done (where k = 2). For clearness sake, in this gure the virtual hyperedges of the operations F1, F2 , F10 , F20 , and F30 are drawn in a special way. They are labelled with the corresponding subterm of the right-hand side (an idea taken from [EV94]), and those which correspond to the variable x2 are distinguished from those corresponding to x3 by a dierent shading. Numbers next to the virtual hyperedges indicate their order. The construction is done in two steps. Intuitively, in the rst step the corresponding situation in td is reconstructed by applying F to (the underlying hypergraphs of) F1 and F2. This yields the hypergraph in the centre of the gure. Afterwards, in the second step all virtual hyperedges that correspond to subterms with the same variable are grouped together. This is done by re-writing the hypergraph as F 0(GF 0 ; GF 0 ; GF 0 ), where GFi0 is the part that contains all the virtual hyperedges corresponding to xi (and no others). Finally, let wi be the sequence of states in the subterms corresponding to the virtual hyperedges of Fi0. Then, the constructed rule is [f [x1; x2 ; x3 ]] ! F 0[[x1 ]; [x2 ]; [x3 ]]. Formally, an in nite set of rules R0 is constructed as follows. Let = 2 ?0 and assume that R contains rules
1[f [x1 ; : : : ; xk ]] ! F1 [ 1;1[x1;1 ]; : : : ; 1;r [x1;r ]] ...
l [f [x1 ; : : : ; xk ]] ! Fl [ l;1[xl;1 ]; : : : ; l;rl [xl;rl ]] such that type (GFi ) = type GF (vir F (i)) for all i 2 [l]. Choose an hr operation F 0 of arity k 0 0 > 2 ?0 for all p 2 [k], where type (GF 0 ) = type (vir F 0 (p)), and states p = Claim 2. Let = and e = . From Let and s be as above and let (; s) R (p; sp) where p =