Weak Greibach Normal Form for Hyperedge Replacement Grammars
Abstract
It is known that hyperedge replacement grammars are similar to string context-free grammars in the sense of definitions and properties. Therefore, we expect that there is a generalization of the well-known Greibach normal form from string grammars to hypergraph grammars. Such generalized normal forms are presented in several papers; however, they do not cover a large class of hypergraph languages (e.g. languages consisting of star graphs). In this paper, we introduce a weak Greibach normal form, whose definition corresponds to the lexicalized normal form for string grammars, and prove that every context-free hypergraph language (with nonsubstantial exceptions) can be generated by a grammar in this normal form. The proof presented in this paper generalizes a corresponding one for string grammars with a few more technicalities.
1 Introduction
Extensions of formal grammars and languages from strings to graphs are considered in a wide variety of works. The resulting formalisms called graph grammars generate graph languages by means of productions: each production is of the form ; it allows one to replace a part of a graph labeled by with the graph if certain conditions are satisfied. An overview on graph grammars can be found in “Handbook on Graph Grammars and Computing by Graph Transformation” [12].
In this paper, we focus on a particular approach called hyperedge replacement grammar (HRG). An overview on HRG can be found in the book [8] or in a chapter of the handbook mentioned above [4]. In brief, a hyperedge replacement grammar contains productions that allow one to replace an edge with a certain label by a hypergraph; the rest is similar to string context-free grammar definitions. HRGs appeared in the seventies, and they became popular from theoretical and practical points of view; particularly, they can be used in machine translation or programming (see, for instance, [10]). Many structural properties of HRGs have been studied. Nicely, many theorems regarding context-free string grammars (CFGs) can be extended to HRGs in a natural way; besides, it is often the case that proofs for CFGs can be generalized to HRGs so there is no need to invent anything new.
For context-free grammars, there is a so-called Greibach normal form, which is helpful in a number of investigations, e.g. to connect CFGs with categorial grammars (see [3]). Each production in a grammar in the Greibach normal form has to begin with a terminal symbol and proceed with at most two nonterminal ones. This definition can be weakened: one says that a grammar is in the weak Greibach normal form (it is often called lexicalized) if there is exactly one terminal symbol in the right-hand side of each production. Obviously, the same definition can be introduced for graphs. Namely, an HRG is said to be in the weak Greibach normal form if for each production the hypergraph has exactly one edge labeled by a terminal symbol.
The main objective of this paper is to present a precise class of graph languages that can be generated by HRGs in the weak Greibach normal form. In order to do this we generalize the proof of existence of the Greibach normal form for context-free grammars taken from [2] in a straightforward way. However, several differences exist. Firstly, there is a nonsubstantial class of hypergraph context-free languages that cannot be generated by grammars in the weak Greibach normal form (a problem arises because of isolated nodes). Secondly, there is a trick in the proof for CFGs that exploits the string nature of grammars, so it is hard to generalize it to hypergraphs. This led us to a large and technically heavy proof. Finally, there are bad news regarding algorithmical complexity: conversion of an HRG into an equivalent one in the weak Greibach normal form cannot be done even in exponential time.
In Sect. 2 we compare our contribution with other studies related to the Greibach normal form for graph grammars. In Sect. 3 formal definitions related to hypergraphs and HRGs are presented. In Sect. 4 the weak Greibach normal form is introduced, related issues are discussed. Sect. 5 is devoted to the main theorem. In Sect. 6 we discuss algorithmic complexity of the normalization procedure. In Sect. 7 we conclude.
2 Related Work
There are several works devoted to the Greibach normal form for graph grammars. The paper of Joost Engelfriet [5] establishes that HRGs that produce languages of bounded degree are equivalent to apex HRGs; this result generalizes the double Greibach normal form for CFGs. To recall, a language is of bounded degree if for some all nodes of all hypergraphs in have degree not exceeding . Obviously, there are substantive examples of languages of unbounded degree: for instance, the language of star graphs, which have one node and arbitrarily many edges outgoing from it. Besides, the property of being apex is stronger than the weak Greibach normal form we are interested in.
In the paper of Christina Jansen et al. [9] the local Greibach normal form is presented. The authors prove that data structure grammars (it is a specific kind of grammars that generate so-called heap configurations) can be transformed into grammars in the local Greibach normal form; after the proof the authors point out that the normalization can be generalized to HRGs of bounded degree. However, the authors also note that their procedure being algorithmically efficient cannot be generalized to all HRGs.
The weak Greibach normal form in the sense we are interested in is introduced for another type of graph grammars. Namely, in [6] it is proved that each B-eNCE grammar (here we do not consider definitions regarding this formalism) is equivalent to a B-eNCE grammar in the weak Greibach normal form. In [7] it is shown that B-edNCE grammars and HRGs have the same recognizing power in some sense (namely, since B-edNCE grammars produce usual graphs with labeled nodes and edges while HRGs produce hypergraphs with labeled edges, the result is established w.r.t. two translations, from graphs to hypergraphs and vice versa). However, it seems to be impossible that these two results can be combined in order to obtain the normal form for HRGs.
Therefore, to our best knowledge, the question of whether each HRG is equivalent to an HRG in the weak Greibach normal form has hitherto remained open. We answer it in this paper.
3 Preliminaries
This section is concerned with definitions related to hypergraphs. All of them are taken from [4]. Note that we use a slightly different notation from that in the handbook mentioned above.
3.1 Hypergraphs, Sub-hypergraphs
includes . The set of integers from to is denoted by .
It is convenient for us to use the following notation: if is an indexed set of integers such that for holds, then it is called index-ordered and the set is denoted as .
The set is the set of all strings over the alphabet including the empty string . The length of the word is the number of positions in . The -th symbol in is denote by (). denotes the set of all nonempty strings. The set is the set of all strings consisting of distinct symbols. The set of all symbols contained in the word is denoted by . If is a function from one set to another, then it is naturally extended as a function ().
Let be some fixed set of labels, for which the function is considered.
Definition 1.
A hypergraph over is a tuple where is the set of nodes, is the set of hyperedges, assigns an ordered set of attachment nodes to each edge, labels each hyperedge by some element of in such a way that whenever , and is an ordered set of external nodes.
Components of a hypergraph are denoted by .
In the remainder of the paper, hypergraphs are simply called graphs, and hyperedges are simply called edges. The set of all graphs with labels from is denoted by . In this work, figures contain graph drawings and sketches. In drawings, nodes are depicted by black dots, edges are denotes as labeled boxes, is represented with numbered lines (called “tentacles”), external nodes are depicted by numbers in brackets. If an edge has type 2, it is depicted by an arrow. If we are not interested in a specific form of a graph but we want to have a closer look at some its part, we depict the whole graph as an area but draw its part of interest in detail.
Example 1.
This is a graph:
If is a graph, and is labeled by , then can be denoted by .
Definition 2.
The function (or to be exact) returns the number of nodes attached to some edge in a graph : . If is a graph, then .
Definition 3.
A sub-hypergraph (or just subgraph) of a hypergraph is a hypergraph such that , , and for all , .
Definition 4.
If , and , then is called a handle. It is denoted by .
Definition 5.
An isomorphism between graphs and is a pair of bijective functions , such that , , . In this work, we do not distinguish between isomorphic graphs.
3.2 Replacement
This procedure is defined in [4]. In short, the replacement of an edge in with a graph can be done if as follows:
-
1.
Remove ;
-
2.
Insert an isomorphic copy of (namely, and have to consist of disjoint sets of nodes and edges);
-
3.
For each , fuse the -th external node of with the -th attachement node of .
To be more precise, the set of edges in the resulting graph is , and the set of nodes is . The result is denoted by .
3.3 Hyperedge Replacement Grammars
Definition 6.
A hyperedge replacement grammar (HRG) is a tuple , where is a finite alphabet of nonterminal symbols, is a finite alphabet of terminal symbols (), is a set of productions, and . Each production is of the form where , and . For we denote .
Edges labeled by terminal (nonterminal) symbols are called terminal edges (nonterminal edges resp.). If a graph contains terminal edges only, it is called terminal.
If is a graph, , and , then directly derives (we write or ). The transitive reflexive closure of is denoted by . If , then is said to derive . The corresponding sequence of production applications is called a derivation.
Definition 7.
The language generated by an HRG is the set of graphs such that . It is denoted by .
A graph language is said to be a hypergraph context-free language (HCFL) if it is generated by some HRG.
Two grammars are said to be equivalent if they generate the same language.
Further we simply write instead of .
4 Weak Greibach Normal Form
In this section we introduce the formal definition of the normal form we are interested in, and establish a simple property of languages generated by grammars in this normal form.
Definition 8.
An HRG is in the weak Greibach normal form (WGNF) if there is exactly one terminal edge in the right-hand side of each production. Formally, .
Example 2.
The grammar is in the WGNF where contains the following rules ():
This grammar generates the language of star 1-edged -labeled hypergraphs, which is unbounded.
Remark 1.
If is in the WGNF and for some , then has exactly terminal edges (each production adds exactly one terminal edge).
Note that not each hypergraph context-free language can be generated by some HRG in the WGNF. This follows from
Example 3.
Consider the HRG where contains the following rules
():
The first production just adds an isolated node; thus this grammar produces graphs that have exactly one edge labeled by and arbitrarily many isolated nodes. If there is an equivalent in the WGNF, then each right-hand side of each production in contains exactly one terminal edge. Note that if for some in , then has terminal edges (Remark 1); hence has to be equal to and therefore . However, there are infinitely many graphs in while . ∎
It is seen that the reason of this problem is in isolated nodes. In the string case if a language contains the empty word, then it cannot be generated by a grammar in the WGNF due to obvious reasons: each production adds at least one terminal symbol so it is impossible to produce the empty word. In the case of graphs, we also have to prohibit somehow undesired languages with “too many” isolated nodes occuring in graphs.
Below we describe the precise class of languages generated by grammars in the weak Greibach normal form. We denote by the number of edges in , and by the number of isolated nodes in .
Definition 9.
An HCFL is said to be isolated-node bounded (ibHCFL) if there is a constant such that, for each , . An HRG is called isolated-node bounded if it generates an ibHCFL.
Theorem 1.
Each HRG in the WGNF generates an ibHCFL.
Proof.
Let . Define as the number of terminal edges in . We prove by induction on that for each graph such that . Remark 1 implies that .
Basis. If , then , and the statement is trivial ().
Step. Let . By the induction hypothesis, . The number of isolated nodes appeared at the last step does not exceed by the definition of . Then .
Note finally that . ∎
The other direction of this statement is of central interest in this paper. The next section is devoted to it.
5 Transformation of HRGs Generating IBHCFLs into HRGs in the Weak Greibach Normal Form
The main theorem we are going to prove is the following:
Theorem 2.
Each ibHCFL can be generated by an HRG in the WGNF.
In other words, this theorem states that each context-free hypergraph language satisfying the isolated-node boundedness property can be generated by a grammar in the weak Greibach normal form.
Structurally, the proof of this theorem is based on the corresponding one for string context-free grammars. Let us recall the mains steps of the latter in brief (see details in [2]).
The input of the algorithm is a context-free grammar that does not generate the empty word (this property is related to isolated-node boundedness). The desired output is an equivalent grammar in the weak Greibach normal form (i.e. in which each production is of the form where is terminal while are nonterminal).
-
1.
Useless rules and symbols, -rules (i.e. rules of the form ) and chain rules (i.e. rules of the form for being nonterminal) are eliminated.
-
2.
It is shown how to eliminate recursive -productions, i.e. productions of the form for some fixed nonterminal symbol . The trick is to move from the left side of to the right side. It is done as follows: if are all the -productions (here means enumeration of productions), then they are replaced by the productions and .
-
3.
Left recursion is completely eliminated: nonterminals are numbered as and then a procedure involving application of step 2 is done such that its result is a grammar where each production is either of the form for or of the form for being terminal.
-
4.
By taking compositions of the above productions and adding new nonterminal symbols the grammar is normalized. The resulting grammar includes rules of the form ( is terminal, is a string of nonterminals) only.
Our goal is to recreate this proof for HRGs. Note that steps 2-4 of the above plan actively exploit string nature of CFGs: transformations of productions are based on movements of symbols from the leftmost position to the rightmost one. Graphs in general do not have leftmost positions unlike strings, so we are going to distinguish arbitrary edges in graphs so they play the role of “the leftmost symbol”. It is done by means of (see the proof below).
In the proof we use the following
Lemma 1.
If is a production of a grammar for being nonterminal, and are all the productions in with in the left-hand side, then replacing by productions does not change the language generated.
It directly follows from the well-known context-freeness lemma.
5.1 Eliminating Useless, Edgeless and Chain Productions
Our first objective is to eliminate useless productions, productions with no edges in the right-hand side and productions with one nonterminal edge only in the right-hand side. It appears that only this step requires isolated-node boundedness. In the below transformations we provide theoretical reasonings that they can be done irregarding their algorithmic realization; however, the latter can be done similarly to the string case (see [2]).
Definition 10.
A nonterminal symbol in a grammar is useless if there is no derivation of the form in this grammar where is terminal.
Transformation 1 (eliminating useless symbols).
Input: an HRG .
Output: an equivalent HRG without useless nonterminal symbols.
It suffices to remove all the useless symbols and all the productions containing them. This does not affect the language generated.
Definition 11.
A graph is called edgeless if it does not contain edges. A production is called edgeless if is edgeless.
Transformation 2 (eliminating edgeless productions).
Input: an HRG that generates an ibHCFL without useless symbols.
Output: an HRG without edgeless productions such that .
Method.
Let . Let . This set is finite, because otherwise there is a symbol for which arbitrarily large edgeless graphs exist such that ; this contradicts the fact that (it is important that is not useless).
Let and . Let contain the rules of the form where for at least one (then replacement of by changes nothing) and belongs to otherwise. It is argued that does not have productions with edgeless right-hand sides (this follows from the construction) and that . ∎
Definition 12.
A production is called a chain production if and is nonterminal.
Example 4.
The first production in the grammar is chain.
Transformation 3 (eliminating chain productions).
Input: an HRG that generates an ibHCFL without useless symbols.
Output: an HRG without chain productions such that .
Method.
Let . Consider the set . Note that is finite (again, otherwise one can derive a graph with arbitrarily many isolated nodes having a fixed number of edges). Let where and . Thus we removed all the productions having a graph with one edge in the right-hand side. It can be easily shown that .
∎
Remark 2.
Example 5.
The grammar from Example 3 cannot be turned into an equivalent one without edgeless and chain productions.
The above procedures complete the first step of normalization.
5.2 Defining and Eliminating Recursive Productions
Now we start proving Theorem 2. Let be a grammar that generates . Applying Transformations 1, 2, 3, we can assume that does not have useless symbols, edgeless productions and chain productions. Thus, the right-hand side of each production has at least two edges or one terminal edge.
Let us carefully examine what happens in the string case at Step 2. Consider the following
Example 6.
Let be all the -productions in a string context-free grammar. After Step 2 there are the following ones: . Below we show how a derivation in the old grammar is remodeled in the new one:
Old: | . |
---|---|
New: | . |
The underlying idea is to invert the derivation: in the new derivation one starts with and applies new productions in reverse order w.r.t. to the old derivation.
The same idea is used in the graph case. The difficulty is that we do not have the leftmost symbol in productions. However, it suffices to distinguish an arbitrary edge in the right-hand side of each production to play the role of the leftmost symbol. We do this by means of the function .
Definition 13.
Let us fix an arbitrary function which acts on in such a way that belongs to . We denote .
Now plays the role of the “leftmost” symbol of a production . Then we define recursive productions as expected.
Definition 14.
A production is recursive if . A production is an -production if .
Definition 15.
A derivation is called a -derivation if each of its productions is applied to the edge that is of the previous production. Formally, if , then has to be appied to (in the subgraph that appears after the -th step). We say that the final label of such a derivation is . Note that has to be nonterminal for (but can be terminal).
Below we study how to eliminate all the recursive -productions for some fixed . In the string case the idea is quite simple: one moves from the beginning of the string to its end in order to invert a derivation process. Here we also exploit the idea of inverting the derivation but, of course, we have to take into account more complex and general graph structures.
Let be a -derivation such that for and (compare this with the old derivation in Example 6). We provide the following intuition behind the below construction. Imagine that one has a hole in his sweater (this metaphor is related to that in [5]), and he sews it up starting from edges (i.e. he applies ) and finishing by sewing on a patch in the center of the hole (i.e. he applies ). In the new derivation one starts with the patch (that is, the right-hand side of ), then he sews up right-hand sides of in this order (thus the patch grows and becomes bigger) and finishing by connecting it with edges of the hole w.r.t. the production (see also Fig. 5 which provides a sketch of this process).
The major problem of this idea is the following: if we want to invert a derivation such as on Figure 5(a) and to obtain a new one, such as one drawn on Figure 5(b), we have to carefully control external nodes. Namely, in the old derivation external nodes of are predefined by while in the new derivation appears at the very last step. In order to place external nodes correctly, we introduce complex nonterminal symbols that describe how external nodes of a graph on the current derivation step correspond to external nodes of a graph on the next and on the last step. This description is done by means of partial functions.
Now we proceed with formal realization of this idea. Let . Let be all the recursive -productions in and let be the remaining -productions in . Our goal is to construct a grammar equivalent to without recursive -productions. Firstly, we simply remove them: . In order to compensate for the lack of these rules we add new ones accordingly to the procedure below.
Definition 16.
is a partial function if is a function on some subset of . We denote the domain of by , and the range of by .
Definition 17.
is a partial bijection if is a partial function such that is a bijection.
Definition 18.
If , are partial functions, then is a partial function defined on that acts on this set as a usual composition.
Let for some and let for some . We define , , and . Illustrations of these productions are presented in Fig. 1. Firstly, we extend by new nonterminal symbols of the form where are two partial bijections; the resulting set is denoted by . Then we add to rules of the following three forms:
Type I.
Recall the metaphor about a sweater and a patch. If one imagines an -labeled edge at the beginning of a derivation as a hole in a sweater, then productions of type I are designed to add a patch at the very beginning of sewing up (= of a derivation). Partial functions are used to describe what external nodes of (edges of a patch) are equal to attachment nodes of the -labelled edge (edges of a hole).
Let be two partial bijections. Informally, specifies what nodes of are external on the second step of the inverted derivation (see again Fig. 5(b)); specifies what external nodes of the second step graph are external at the last step.
Let .
We set
-
•
for being new nodes;
-
•
where is new;
-
•
For we set and ;
-
•
For we set ;
-
•
;
-
•
Let (note that is bijective so and are of the same size). Then we set , if or for .
We are ready to announce that . Finally, we introduce the following rule:
We define (note that is nonrecursive so is ).
Remark 3.
Type of equals .
Figure 2 illustrates this type of productions.
Type II.
Production of type II are used at the last step of a derivation such a on Fig. 5(b); returning to the metaphor they allow one to finish sewing up and to finally connect a patch (that has grown by applying productions of types I and III) with the edges of a hole.
We recall that such that and . Let be a function which is defined by the following relation: . Obviously, is a partial bijection. We set
-
•
;
-
•
;
-
•
,
-
•
Let be equal to and let . Then .
We set . Finally, we introduce and set for some chosen (note that there is one since ). Here is the identity function. See Figure 3.
Remark 4.
. Thus the production is defined correctly.
Type III.
Productions of type III serve to make a “sewing up step” from inside to outside. that specify relations between external nodes on the current step, on the next step and on the final step are changed by related functions .
Let be partial bijections.
The whole procedure described below can be done if .
We set
-
•
such that are new nodes ( is defined below);
-
•
where and is new;
-
•
For we set and ;
-
•
For we set ;
-
•
;
-
•
Let
-
–
(nodes of the current step that will be external at the last step but that were not taken into account at the previous step);
-
–
;
-
–
;
-
–
Let where is index-ordered; here we note that , thus .
Then we set and
-
–
for ;
-
–
for ;
-
–
for .
-
–
We set . Then . We put for some . The production is illustrated on Figure 4.
Remark 5.
Again, we prove well-definedness of this production:
-
•
Firstly, we check that : ;
-
•
Secondly, we have to check that : . Note that . This yields .
We say that is obtained from by adding all possible productions of all the above types. Obviously, their number is finite (each production is defined by at most four partial functions from to ).
Lemma 2.
The grammar is equivalent to .
Proof.
Informally, it suffices to notice that the design of new productions allows one to invert productions in the way which is shown on Figure 5. Example 7 provides an illustration of the formal proof, which is given below.
Firstly, we check that . In order to do that, we show how to model a branch of a derivation that consists of rules of the form and finishes with a rule by means of . Let be a -derivation in where and . It is convenient to put and say that where . For the sake of simplyfing notations we write instead of and instead of .
Let be defined inductively as follows: ; . Note that
To prove the claimed inclusion, it suffices to show then that .
Observe that . Then can be considered as a subgraph of , which is a subgraph of . Let be a partial function defined by the following correspondence: . Similarly we define : . It follows from these definitions that .
Let and . We prove by the reverse induction on that then .
Basis. Since is not a recursive -production, we added in our grammar. This completes the basis case.
Step. We assume by the induction hypothesis that and our aim is to prove the same for . contains an edge labeled by . Then a type III rule is applied to this edge: . The design of such rules allows us to perform exactly the substitution of into .
Therefore, . Note that the right-hand side of this derivation contains an edge labeled by . Since , we see that is the identity function . Thus we can apply the type II rule of the form whose left-hand side equals . This rule is also designed in such a way that its application is equivalent to substitution of into . This means that , as required.
Now, if there is an arbitrary derivation where the rule is applied (), then we find the largest -derivation within the derivation that includes this occurence and remodel it as described above. Thus, the above reasonings complete the proof for one of the inclusions.
To prove the reverse inclusion, it suffices to show how to transform a branch of a derivation containing nonterminals of the form into a derivation in . Let
be such a branch (it has to be of a similar form). Then we can consider a derivation in of the form ; the first part of the proof of this theorem allows us to conclude that . Note that functions and in the first derivation can be arbitrary (they only have to satisfy the condition of type III rules); however, it is not hard to show that they are the same as the functions and that are built on the basis of the second derivation.
This finishes the proof. ∎
There are two important observations regarding the procedure and the lemma above:
-
1.
After such a procedure there are no recursive -productions;
-
2.
For each nonterminal there is no rule such that .
Note that does not preserve all the properties that had. Namely, rules of Type II can contain only one edge. However, our further actions do not affect type II and type III rules so this does not matter. Besides, useless symbols can appear, which also does not bother us (we deleted them only to perform Transformations 2 and 3). This finishes the second step.
Example 7.
Let a grammar contain two -productions: the first one is recursive and the second one is not recursive. They are depicted below; of each production is represented by the red color.
In this grammar the following -derivation is possible:
In the new grammar this derivation turns into the following one:
Here are all the involved partial functions; it is easy to check that they actually satisfy conditions from definitions. Note that if is the total number of derivation steps, then specifies a relation between external nodes on the -th and on the -th steps and it is defined by a corresponding production in the old derivation. In this example, are all defined by the production , thus they are the same. defines a relation between external nodes on the -th step and external nodes at the end of a derivation (on the -th step). As expected, is the identity function since and , so specifies a relation between external nodes on the last and on the last step.
5.3 Eliminating Recursion and Convertion into the WGNF
The rest of the steps are similar to those in the string case. Let us start with ; let . Then the following transformation is done.
Transformation 4 (eliminating recursion).
Input: an HRG as at the beginning of the proof (without useless symbols or edgeless or chain productions).
Output: an equivalent HRG with the same properties such that for each with either and or .
Method.
-
1.
Set .
-
2.
Eliminate all the recursive -productions according to Lemma 2. Now it is argued that if belongs to the set of productions and , then for or is terminal.
-
3.
If , then a desired grammar is obtained. Otherwise, set and .
-
4.
Let be all the productions. Let be a production with . Then we can replace by the rules without changing the generated language (see Lemma 1). For these rules we set . It will now be the case (due to the previous steps of this transformation) that for each -production equals either a terminal or for . Thus all the -productions will have this property after such replacement.
- 5.
∎
Let be a grammar that is obtained from after Transformation 4. Let (note that is really large). We already know that does not have recursions, i.e. there are no -derivations such that . Indeed, due to the second observation after Lemma 2: nonterminals of the form cannot participate in recursive -derivations since they do not appear as values of . For the remaining nonterminals this is a consequence of the result of Transformation 4. Thus we can put a linear order on in such a way that for , if , then either is terminal or it is nonterminal and .
We define the final set of productions as follows: belongs to if there is a -derivation of the length such that is terminal. Obviously, the last requirement yields that has at least one terminal edge.
Lemma 3.
is equivalent to .
Proof.
Clearly, , because productions in are composed of that in . The reverse inclusion is proved by induction on the length of derivation in in more general form: is equivalent to for each .
Basis. If then it is also in since is terminal.
Step. Let (where ) be a derivation of a terminal graph . This derivation contains a -derivation and let (we also set ). Then , is terminal and all are different; thus and . Then the source derivation is rebuilt as follows: we apply to and then do the same with nonterminal edges in using the induction hypothesis. This completes the proof.
∎
Thus . Now we have to overcome the following problem: the weak Greibach normal form requires right-hand sides of productions to have exactly one terminal edge while we can guarantee for that there is at least one terminal edge. This problem is easily fixed: for each we introduce a new nonterminal symbol and we add rules of the form . Now, if has more than one terminal symbol in the right-hand side, then we choose one of them and replace the other ones by corresponding nonterminals: . After this step the modified grammar still generates , and it is in the weak Greibach normal form.
6 Algorithmic Complexity
In the string case polynomial-time algorithms of convertion into the Greibach normal form are known; one is interested whether they exist in the hypergraph case.
It can be seen that the proof we have presented is horrible from the point of view of algorithmic complexity. The main problem is in the second step: the amount of partial bijections from the set to itself is equal to , which grows even faster then any exponential function. It is less obvious but another “heavy” part of the algorithm is the first step — eliminating chain productions. One would hope that presence of these slow parts is the problem of our proof but this is not the case.
Example 8.
Consider a grammar where has 3 productions (, ):
-
1.
, , ;
-
2.
, , ;
-
3.
.
Obviously, this grammar has a size . It generates graphs with one -labeled edge such that attachment nodes of this edge are obtained from external nodes of the graph by a permutation composed of the transposition and of the cycle . Since these permutations are generators of , the language contains hypergraphs. All of them have exactly one hyperedge, so for all a production has to belong to a grammar in the WGNF; therefore, even the number of productions grows faster than any exponent apart from the algorithm involved.
This yields the following
Proposition 1.
There is no exponential-time algorithm that takes an HRG generating an and returns an equivalent HRG in the WGNF.
However, if we consider only HRGs of order for some fixed (i.e. in which types of symbols are not greater than ), then the above example ceases to be a problem as well as the first and the second steps in our proof since the number of partial bijections from to itself (and, in particular, the size of ) is constant when is fixed.
7 Conclusion
Our desire to introduce the weak Greibach normal form appeared due to another research about hypergraph basic categorial grammars (we presented a paper [11] about them at ICGT-2020); in that work we introduce a new approach to describing graph languages and prove that each grammar in this new formalism can be transformed into an equivalent HRG in the WGNF and vice versa. Theorems 1 and 2 show that ibHCFL is exactly the class of languages generated by grammars in the weak Greibach normal form; thus we also answer a question about the recognizing power of hypergraph basic categorial grammars — they also generate exactly ibHCFL. Besides, we suppose that the issue of the WGNF is a fundamental theoretical question, and we have presented an answer in line with those in [5, 9]. Note that the result gives a natural grammar characterization of the language class ibHCFL.
Acknowledgments. I thank my scientific advisor prof. Mati Pentus and anonymous reviewers for their valuable advices.
References
- [1]
- [2] Alfred V. Aho & Jeffrey D. Ullman (1972): The theory of parsing, translation, and compiling. 1: Parsing. Prentice-Hall. Available at https://www.worldcat.org/oclc/310805937.
- [3] Y. Bar-Hillel, C. Caifman & E. Shamir (1960): On Categorial and Phrase-structure Grammars. Weizmann Science Press.
- [4] Frank Drewes, Hans-Jörg Kreowski & Annegret Habel (1997): Hyperedge Replacement, Graph Grammars. In Grzegorz Rozenberg, editor: Handbook of Graph Grammars and Computing by Graph Transformations, Volume 1: Foundations, World Scientific, pp. 95–162, 10.1142/9789812384720_0002.
- [5] Joost Engelfriet (1992): A Greibach Normal Form for Context-free Graph Grammars. In Werner Kuich, editor: Automata, Languages and Programming, 19th International Colloquium, ICALP92, Vienna, Austria, July 13-17, 1992, Proceedings, Lecture Notes in Computer Science 623, Springer, pp. 138–149, 10.1007/3-540-55719-9_70.
- [6] Joost Engelfriet, George Leih & Emo Welzl (1990): Boundary Graph Grammars with Dynamic Edge Relabeling. J. Comput. Syst. Sci. 40(3), pp. 307–345, 10.1016/0022-0000(90)90002-3.
- [7] Joost Engelfriet & Grzegorz Rozenberg (1990): A Comparison of Boundary Graph Grammars and Context-Free Hypergraph Grammars. Inf. Comput. 84(2), pp. 163–206, 10.1016/0890-5401(90)90038-J.
- [8] Annegret Habel (1992): Hyperedge Replacement: Grammars and Languages. Lecture Notes in Computer Science 643, Springer, 10.1007/BFb0013875.
- [9] Christina Jansen, Jonathan Heinen, Joost-Pieter Katoen & Thomas Noll (2011): A Local Greibach Normal Form for Hyperedge Replacement Grammars. In Adrian-Horia Dediu, Shunsuke Inenaga & Carlos Martín-Vide, editors: Language and Automata Theory and Applications - 5th International Conference, LATA 2011, Tarragona, Spain, May 26-31, 2011. Proceedings, Lecture Notes in Computer Science 6638, Springer, pp. 323–335, 10.1007/978-3-642-21254-3_25.
- [10] Bevan K. Jones, Jacob Andreas, Daniel Bauer, Karl Moritz Hermann & Kevin Knight (2012): Semantics-Based Machine Translation with Hyperedge Replacement Grammars. In Martin Kay & Christian Boitet, editors: COLING 2012, 24th International Conference on Computational Linguistics, Proceedings of the Conference: Technical Papers, 8-15 December 2012, Mumbai, India, Indian Institute of Technology Bombay, pp. 1359–1376. Available at https://www.aclweb.org/anthology/C12-1083/.
- [11] Tikhon Pshenitsyn (2020): Hypergraph Basic Categorial Grammars. In Fabio Gadducci & Timo Kehrer, editors: Graph Transformation - 13th International Conference, ICGT 2020, Held as Part of STAF 2020, Online, June 25-26, 2020, Proceedings, Lecture Notes in Computer Science 12150, Springer, pp. 146–162, 10.1007/978-3-030-51372-6_9.
- [12] Grzegorz Rozenberg, editor (1997): Handbook of Graph Grammars and Computing by Graph Transformations, Volume 1: Foundations. World Scientific, 10.1142/3303.