logic hypergraph grammars and context-free hypergraph grammars

11
Systems and Computers i n Japan, Vol. 22, No, 7, 1991 Translated from Denshi Joho Tsushin Gakkai Ronbunshi, Vol. 73-DI, No. 4, April 1990, pp. 385-396 Logic Hypergraph Grammars and Context-Free Hypergraph Grammars Isamu Shioya and Katsuhiko Nakamura, Members Faculty of Science and Engineering, Tokyo Denki University, Saitama, Japan 350-03 SUMMARY This paper presents an extended graph grammar, c a l l e d a logic hypergraph grammar (LHG), and d i s c u s s e s its capabilities and parsing method. This grammar generates hypergraphs by resolution in logic program- ming and is intended to be a basis for anal- yzing and recognizing general structures by logic programming. An LHG is called a con- text-free hypergraph grammar (CFHG) if each production rule represents a replacement of a hyperedge by a subhypergraph. normal forms are presented for CFHG and for a hierarchy on subclasses of languages of CFHGs with respect to the maximum number of vertices in nonterminal hyperedges. Finally, a parsing method of LHG using Prolog is pre- sen ted. Several 1. Introduction Numerous researches have been made on extended formal grammars such as picture grammars and graph grammars for analyzing and recognizing structures of general pat- terns as described by Fu [5]. Production rules of these grammars represent replace- ments of subpatterns or subgraphs. Many reports have presented several types of graph grammars and their extensions and dis- cussed their capabilities [2-41. In some others, applications for syntactic pattern recognition have been discussed. However, almost all these researches deal only with fundamental aspects and few parsing methods have been presented for these grammars. Here, we present an extended graph grammar, c a l l e d a logic hypergraph grammar (LHG), and discuss its capabilities and parsing method. be a basis for analyzing and recognizing general structures based on logic program- ming. A hypergraph is a finite multiple set This grammar is intended to 1 of hyperedges, each of which is an extended edge connecting arbitrary numbers of ver- tices. A hyperedge connecting two vertices is an ordinal edge of a graph. each production rule of LHG by a Horn clause, and define the derivation of hyper- graphs by resolution in logic programming. We represent An LHG is called a context-free hyper- graph grammar (CFHG) if each production rule represents a replacement of a hyperedge by a subhypergraph. Each production rule in t h i s grammar is a Horn clause without any function symbols or lists. This grammar can be considered as an extension of logic gram- mars for string languages proposed by Kowal- ski [8]. The class of context-free hyper- graph grammars includes context-free graph grammars similar to the graph grammars of Habel and Kreowski [6] in the sense that each production rule represents a replace- ment of an edge by a subgraph. We introduce three normal forms of CFHG and show that every CFHG can be transformed into these normal forms. Also, we show a hierarchy on the subclasses of the languages of CFHGs with respect to the maximum number of ver- tices in nonterminal hyperedges. Numerous papers have been published on several types of grammars for graphs and their extensions, including undirected graphs, directed graphs, multiple graphs, etc. In addition to the graph grammars by Habel and Kreowski [6], Vigna and Chezzi [ll] discuss the graph grammars in which each production rule represents a replace- ment of a vertex by a subgraph. Also, Habel and Kreowski [7] and Sopena [lo] discuss the hypergraph grammars in which each production rule represents a replacement of a hyperedge by a subhypergraph. For parsing of extended graph grammars by logic programming, Peng et al. [12] proposed a graph grammar called a C-Plex grammar and discussed its applica- tion for analyzing logic circuits. Tanaka 1SSN0882-1666/91/0007-0001$7.50/0 0 1991 Scripta Technica, Inc.

Upload: isamu-shioya

Post on 06-Jul-2016

236 views

Category:

Documents


2 download

TRANSCRIPT

Systems and Computers i n Japan, Vol. 22, No, 7, 1991 Translated from Denshi Joho Tsushin Gakkai Ronbunshi, Vol. 73-DI, No. 4, April 1990, pp. 385-396

Logic Hypergraph Grammars and Context-Free Hypergraph Grammars

Isamu Shioya and Katsuhiko Nakamura, Members

Facul ty of Science and Engineering, Tokyo Denki Un ive r s i ty , Saitama, Japan 350-03

SUMMARY

This paper p r e s e n t s an extended graph grammar, c a l l e d a l o g i c hypergraph grammar (LHG), and d i scusses i t s c a p a b i l i t i e s and pars ing method. This grammar gene ra t e s hypergraphs by r e s o l u t i o n i n l o g i c program- ming and is intended t o be a b a s i s f o r anal- yzing and recognizing gene ra l s t r u c t u r e s by l o g i c programming. An LHG i s c a l l e d a con- t ex t - f r ee hypergraph grammar (CFHG) i f each production r u l e r e p r e s e n t s a replacement of a hyperedge by a subhypergraph. normal forms a r e presented f o r CFHG and f o r a hierarchy on subc la s ses of languages of CFHGs with r e spec t t o t h e maximum number of v e r t i c e s i n nonterminal hyperedges. F i n a l l y , a pars ing method of LHG using Prolog i s pre- sen ted.

Several

1. In t roduc t ion

Numerous r e sea rches have been made on extended formal grammars such as p i c t u r e grammars and graph grammars f o r analyzing and recognizing s t r u c t u r e s of gene ra l pat- t e r n s as descr ibed by Fu [5] . Production r u l e s of t hese grammars r ep resen t replace- ments of subpa t t e rns o r subgraphs. Many r e p o r t s have presented s e v e r a l t ypes of graph grammars and t h e i r extensions and d i s - cussed t h e i r c a p a b i l i t i e s [2-41. I n some o t h e r s , a p p l i c a t i o n s f o r s y n t a c t i c p a t t e r n r ecogn i t ion have been discussed. However, almost a l l t hese r e sea rches dea l only with fundamental a s p e c t s and few pa r s ing methods have been presented f o r t hese grammars.

Here, w e p re sen t an extended graph grammar, c a l l e d a l o g i c hypergraph grammar (LHG), and d i s c u s s i t s c a p a b i l i t i e s and pars ing method. be a b a s i s f o r analyzing and recognizing general s t r u c t u r e s based on l o g i c program- ming. A hypergraph i s a f i n i t e m u l t i p l e set

This grammar i s intended t o

1

of hyperedges, each of which i s an extended edge connecting a r b i t r a r y numbers of ver- tices. A hyperedge connect ing two v e r t i c e s i s an o r d i n a l edge of a graph. each product ion r u l e of LHG by a Horn c l ause , and d e f i n e t h e d e r i v a t i o n of hyper- graphs by r e s o l u t i o n i n l o g i c programming.

We rep resen t

An LHG i s c a l l e d a con tex t - f r ee hyper- graph grammar (CFHG) if each product ion r u l e r e p r e s e n t s a replacement of a hyperedge by a subhypergraph. Each product ion r u l e i n t h i s grammar is a Horn c l a u s e without any func t ion symbols o r lists. This grammar can be considered as an ex tens ion of l o g i c gram- mars f o r s t r i n g languages proposed by Kowal- s k i [8 ] . The class of con tex t - f r ee hyper- graph grammars inc ludes con tex t - f r ee graph grammars similar t o t h e graph grammars of Habel and Kreowski [6 ] i n t h e sense t h a t each product ion r u l e r e p r e s e n t s a replace- ment of an edge by a subgraph. We introduce t h r e e normal forms of CFHG and show t h a t every CFHG can be transformed i n t o these normal forms. Also, w e show a h i e ra rchy on t h e subc la s ses of t h e languages of CFHGs with r e s p e c t t o t h e maximum number of ver- tices i n nonterminal hyperedges.

Numerous papers have been publ ished on s e v e r a l t ypes of grammars f o r graphs and t h e i r ex tens ions , i nc lud ing und i rec t ed graphs, d i r e c t e d graphs, m u l t i p l e graphs, etc. I n a d d i t i o n t o t h e graph grammars by Habel and Kreowski [ 6 ] , Vigna and Chezzi [ l l ] d i s c u s s t h e graph grammars i n which each product ion r u l e r e p r e s e n t s a replace- ment of a v e r t e x by a subgraph. Also, Habel and Kreowski [7 ] and Sopena [ l o ] d i s c u s s t h e hypergraph grammars i n which each product ion r u l e r e p r e s e n t s a replacement of a hyperedge by a subhypergraph. For pa r s ing of extended graph grammars by l o g i c programming, Peng e t a l . [ 1 2 ] proposed a graph grammar c a l l e d a C-Plex grammar and discussed i t s appl ica- t i o n f o r analyzing l o g i c c i r c u i t s . Tanaka

1SSN0882-1666/91/0007-0001$7.50/0 0 1991 S c r i p t a Technica, Inc.

[13] a l s o proposes an extended grammar of DCG ( d e f i n i t e c l a u s e grammar) f o r l o g i c c i r c u i t s .

Our grammar i s d i f f e r e n t from t h o s e mentioned i n t h e fo rego ing i n t h e fo l lowing two p o i n t s . F i r s t , s i n c e d e r i v a t i o n of hypergraphs by LHG i s de f ined by r e s o l u t i o n i n l o g i c programming, d e f i n i t i o n of der iva- t i o n by LHGs i s s imple , and LHGs can gener- a t e l a r g e r c l a s s e s of hypergraph languages. On t h e o t h e r hand, most o t h e r graph grammars and t h e i r e x t e n s i o n s r e q u i r e compl ica ted d e s c r i p t i o n s f o r connec t ion between a re- p laced subgraph and t h e rest of an o r i g i n a l graph. Second, w e can e a s i l y t ransform LHGs i n t o l o g i c programs o r P ro log programs f o r p a r s i n g i n p u t hypergraphs , a l though few p a r s i n g methods have been p resen ted f o r most graph grammars and t h e i r ex tens ions .

2 . Hypergraphs

We r e p r e s e n t a l a b e l e d d i r e c t e d hyperedge by an a tomic formula i n f i r s t - o r d e r l o g i c . A hypergraph i s de f ined as a m u l t i p l e set of hyperedges: i t can i n c l u d e more t h a n two i d e n t i c a l hyperedges as i n most graph gram- mars. The r e l a t i o n s " € " and " & " and t h e set o p e r a t i o n s as union "U , ' I i n t e r s e c t i o n " f l " and d i f f e rence" - ' ' a l s o are de f ined f o r m u l t i p l e sets. For example, t h e union /ZUB of any m u l t i p l e sets A and B can be p a r t i - t i oned i n t o A and B .

D e f i n i t i o n 2.1. hyperedge i s of t h e form

A (labe Zed d irec ted)

P( UI, uz, * * ' , Un ), n 2 O

where p i s a Zabel of t h e hyperedge, and each u i s a vertex of t h e hyperedge. The

a r i t y n i s determined un ique ly by p . hyperedge of p w i t h n = 0 is rep resen ted simply a s p .

i The

D e f i n i t i o n 2.2. A (labeled, directed, mul t ip le ) hypergraph i s a f i n i t e m u l t i p l e set of hyperedges. graph G i s t h e maximum a r i t y of t h e hyper- edges i n G. edge X , ver(X) deno tes t h e set of t h e ver- t i c e s i n X , and label(X) t h e set of t h e l a b e l s i n X . graph of a hypergraph H , i f G i s a s u b s e t of H .

The rank of a hyper-

For a hypergraph X o r a hyper-

A hypergraph G i s a subhyper-

An o r d i n a l ( l a b e l e d d i r e c t e d m u l t i p l e ) graph is a hypergraph c o n s i s t i n g of hyper- edges w i t h t h e rank 2.

Example 2.1. The hypergraph { p ( a , b, c ) , q(b, d ) , q (d , c) l can be i l l u s t r a t e d as i n F ig . 1. The rank of t h i s hypergraph i s 3.

F ig . 1. A sample hypergraph.

3 . Logic Hypergraph Grammars and Context- F r e e Hypergraph Grammars

I n t h i s s e c t i o n , w e d e f i n e two c l a s s e s of hypergraph grammars c a l l e d l o g i c hyper- graph grammars (LHGs) and c o n t e x t - f r e e hyper- graph grammars (CFHGs). A l l hyperedges i n hypergraphs gene ra t ed by t h i s grammar are r e p r e s e n t e d by a tomic formulae (a toms) , and each v e r t e x i s rep resen ted by e i t h e r a v a r i - a b l e o r a c o n s t a n t .

A p roduc t ion r u l e i n CFHG r e p r e s e n t s a rep lacement of a hyperedge by a subhyper- graph. graphs by o u r grammars, we can ex tend t h e CFHG t o a c o n t e x t - s e n s i t i v e hypergraph gram- mar such t h a t t h e l e f t -hand s i d e of each p roduc t ion r u l e i s a subhypergraph r a t h e r than a hyperedge. I n LHG, w e employ a n o t h e r method such t h a t t h e l e f t -hand s i d e of r u l e s can be ex tended hyperedges con ta in ing l i s ts of v a r i a b l e s , because t h i s method i s s i m p l e r and s u i t a b l e f o r l o g i c programming.

To d e f i n e l a r g e r c l a s s e s of hyper-

D e f i n i t i o n 3.1. A l i s t over a set A of symbols i s de f ined r e c u r s i v e l y by t h e f o l - lowing r u l e s :

(1) An empty l i s t [ I i s a l i s t ove r A .

( 2 ) I f each of t and t i s e i t h e r a n

1 2

1 2 e lement of A o r a l i s t ove r A , t hen [t It 3 i s a l i s t ove r .

2

X. For a set C of c o n s t a n t s and a set V of v a r i a b l e s , a n atom o v e r CU V i s of t h e form

where p is a pred ica te , and each u i s

e i t h e r an e lement of CU L' o r a l i s t o v e r CU I/. We assume t h a t n i s de termined u n i q u e l y by t h e p r e d i c a t e p as i n D e f i n i t i o n 2.1. Note t h a t i f an atom c o n t a i n s no l i s t s , t h e n t h e atom r e p r e s e n t s a hyperedge , and i t s arguments ( c o n s t a n t s and v a r i a b l e s ) a r e v e r t i c e s .

i

D e f i n i t i o n 3.2. A l og ic hypergraph g r m a r (LHG) U is a s y s t e m (C, V , N , T, P, S) , where:

(1) C, I/, N , and T are sets of con- s t a n t s , v a r i a b l e s , n o n t e r m i n a l l a b e l s and t e r m i n a l l a b e l s , r e s p e c t i v e l y , d i s j o i n t t o each o t h e r ;

( 2 ) P i s a f i n i t e set of p r o d u c t i o n r u l e s o f t h e form

where g is a n atom o v e r cu L' w i t h t h e non- t e r m i n a l l a b e l , and e a c h h . i s a n atom o v e r

CU 1/ w i t h e i t h e r t h e t e r m i n a l o r nontermin- a1 l a b e l ; and

2

( 3 ) S, c a l l e d an i n i t i a l semihyper- graph, i s a s i n g l e t o n of a n atom o v e r CU V w i t h e i t h e r t h e t e r m i n a l o r n o n t e r m i n a l l a b e l .

The rank of D i s t h e maximum a r i t y of t h e atoms w i t h t h e n o n t e r m i n a l l a b e l s .

We d e n o t e c o n s t a n t s by a, b, c, a b . i' z, c ...; v a r i a b l e s by W , X, z , wi, xi, zi, i' .... , and v a r i a b l e s o r c o n s t a n t s by u, V , ui,

D e f i n i t i o n 3 . 3 . A context- f r e e hyper- graph grammar(CFHG) i s a n LHG n o t i n c l u d i n g l i s t s i n t h e p r o d u c t i o n r u l e s and t h e i n - i t i a l semihypergraph ( i . e . , a l l t h e atoms are h y p e r e d g e s ) .

Now, w e can d e f i n e a l a n g u a g e of LHG u s i n g t e r m i n o l o g i e s i n l o g i c programming. A s u b s t i t u t i o n i s a f i n i t e set of t h e form

{~i/ti,~~/ti,...,~,/tn}, zi # ti,zi # zj (1 # j )

where each x i s a v a r i a b l e , and each t . i s

e i t h e r a c o n s t a n t , a v a r i a b l e o r a l i s t . We assume t h a t a n i n s tance X8 of a n atom X o r a m u l t i p l e set X of a toms, a composition

i 3

t(X2'X4) I

F i g . 2. Samples

Bo of s u b s t i t u t i o n s

of comple te g r a p h s .

f3 and o, a most general u n i f i e r 8 = m g u f g , h ) of atoms g and-h, and a var ian t between two atoms are d e f i n e d a s i n l o g i c programming [ 9 ] . For any two a toms ( o r m u l t i p l e sets o f a toms) G and H, G i s i somorphic t o H, w r i t t e n G = H , i f G and H are v a r i a n t s t o e a c h o t h e r .

D e f i n i t i o n 3 . 4 . F o r any LHG D = (C, V , N , T, P, S ) , t h e b i n a r y r e l a t i o n on

t h e class of m u l t i p l e sets of a toms i s de- f i n e d by

@ + I ] & t h e r e e x i s t a n atom s E G and a p r o d u c t i o n r u l e /h -+h i , .-.,

ho E P such t h a t e = mgu(g, ho)

I )

and H = ( G - { g ) ) B U (hi, ..., h n ) O .

where the v a r i a b l e s of t h e p r o d u c t i o n r u l e are renamed t o new v a r i a b l e s s o t h a t a l l t h e v a r i a b l e s i n t h e r u l e do n o t a p p e a r i n G.

from G. Let J h d e n o t e t h e r e f l e x i v e and

t r a n s i t i v e c l o s u r e of t h e r e l a t i o n JD,

and J h t h e t r a n s i t i v e c l o s u r e of JD.

I f G J D H , w e s a y t h a t F! i s derived

D e f i n i t i o n 3.5. For any LHG D = (C, V , f i n e d by

N , T , P, S ) , a language L (D) i s de-

L ( D ) = {ff I S $ H , H i s a h y p e r g r a p h composed o n l y of h y p e r e d g e s 1

label(H)C T and

* Any m u l t i p l e set G w i t h s3G i s c a l l e d a

semihypergraph. F o r any two LHGs D and D', D i s equ iva len t t o D ' , w r i t t e n C ( D ) s L(D'),

3

i f f o r every H E L ( D ) t h e r e e x i s t s a hyper- graph H ' such t h a t I H', and v i c e versa.

Example 3 . 1 . A complete graph i s a graph such t h a t every p a i r of v e r t i c e s h a s an edge a s shown i n F ig . 2. L e t D be t h e 1 LHG (C, v, IS, r, 81, { t I , PI, IS(x) I ) , where P c o n s i s t s of 1

We can show t h a t L(D1) is t h e c l a s s o€ a l l complete graphs by i n d u c t i o n on t h e numbers of v e r t i c e s i n graphs.

Example 3 . 2 . Kowalski [8] shows a p a r s i n g method of s t r i n g languages by repre- s e n t i n g a s t r i n g a a 2...an by t h e set of

u n i t c l a u s e s ( ~ i ( ~ o , ci), u A c I , ~ z ) , * * * , O , , ( C , 1,

c,,)}. Because t h i s set r e p r e s e n t s a l inear graph , t h e l o g i c program f o r t h i s p a r s i n g method i s e s s e n t i a l l y a CFHG. The s t r i n g

l anguages gene ra t ed by t h e s e grammars do n o t on ly i n c l u d e c o n t e x t - f r e e languages b u t a l s o some c o n t e x t - s e n s i t i v e languages . For example, t h e CFHG uz=(c, v, { b , Q ] , ( Y , s , t }, Pz, ( b ( x , y ) I ) g e n e r a t e s t h e c l a s s of l i n e a r graphs r e p r e s e n t i n g t h e s t r i n g s Y " s " ~ " ( n = l , 2 , 3 , *..I, where P2 c o n s i s t s of

t h e fo l lowing r u l e s :

b(zv Z I ) ~ Q ( Z , I, X , Y, Y, 2 1 )

q ( Z , 21, I, XI, Y, . ! / i ) - ' Y ( Z , Z I ) , S ( X , Xi) , t ( y , Yl)

q ( z , Z Z , I , I Z , y, Y Z ) + Y ( Z , Z l ) , S ( I , I,), l ( y , y 1 ) ,

~ ( Z I , Zz, X I , f z , !/I, Yz)

Example 3 . 3 . The hypergraphs r ep re - s e n t i n g f l o w c h a r t s c o n s t r u c t e d from t h e ele- ments i n F ig . 3 a r e gene ra t ed by t h e CFHG (c, v, {flowchart, b lock} , { s t a r t , end, branch, process I, P3, {flowchart 1 ) , where

P i s t h e set of t h e fo l lowing p roduc t ion

r u l e s : 3

flowchart+start(.r ), block(x, y 1, end(y block(x, Y )+process(x, y 1 block(x, z )-+block(x, Y ), block(y, z )

block(r, y)+branch(r, y, z ) , block(y, I ) block(w, z)+branch(w, x , z 1, block(x, Z )

sequence i f - t h e n - e l s e while-do

Fig. 3 . Contro l s t r u c t u r e s of f lowchar t .

s t a r t cr> s t a r t (x ) end (x ) b ranch(x ,y , z)

process 9 p r o c e s s ( x , y )

Fig. 4 . Flowchar t symbols.

4

The f o l l o w i n g theorem shows t h a t s e m i - hypergraphs d e r i v e d by any LHG do n o t depend on t h e o r d e r of a p p l i c a t i o n s of p r o d u c t i o n r u l e s .

Theorem 3 . 6 . L e t D be a n LHG and G b e a semihypergraph. Suppose t h a t :

(1) H1 and H a r e d e r i v e d from G by 2 apply ing P and P t o d i s t i n c t a toms e and

e i n G , r e s p e c t i v e l y ; and 1 2 1

2

(2) K1 and K are de r ived from H and

H2 app ly ing P and P t o t h e i n s t a n c e e: E

HI of e 2 and t h e i n s t a n c e e: E Hi of el, re-

s p e c t i v e l y , as

2 1

2 1

G? H i 2 K I G? H23 K2

Then w e have I { I = K ~ .

Proof . We o b t a i n immediately t h e proof by "Switching Lemma" [ 91.

4. Normal Forms of CFHGs

I n t h i s s e c t i o n , w e p r e s e n t s e v e r a l normal forms of CFHG, and show t h a t eve ry CFHG can b e t ransformed i n t o t h e s e normal forms.

Theorem 4.1. Every CFHG can b e t r a n s - formed i n t o a n e q u i v a l e n t "cons tan t - f reel' CFHG, i . e . , c o n t a i n i n g no c o n s t a n t s i n t h e nontermina l hyperedges .

Proof . For any CFHG D, w e o b t a i n t h e c o n s t a n t - f r e e CFHG D' by app ly ing t h e f o l - lowing p rocedure t o D , w h i l e t h e r e remains a p roduc t ion r u l e c o n t a i n i n g c o n s t a n t s i n t h e non te rmina l hyperedges. L e t a = u be i a c o n s t a n t con ta ined i n t h e non te rmina l hyperedge p(ul, . . . , un).

(1) R e w r i t e t h i s hyperedge as t h e hyper- edge Pu,J( U I , * * * , Ui-lr U J + i , ..., 2-4,) ' w i t h a r i t y n - 1, where p i s a non te rmina l l a b e l .

a, j

( 2 ) For eve ry p r o d u c t i o n r u l e of t h e form p ( v I , * . * , Vn)+hi , *.., hr such t h a t i f u = mgu(a, v . ) is d e f i n e d , w e add t h e p roduc t ion

r u l e 3

t o D'.

(3) For e v e r y p r o d u c t i o n r u l e of t h e form g+hl, . * a , ~ ( v I , - * * , V n ) , * * * , hr such t h a t i f 5 = mgu(a, v , ) i s d e f i n e d , w e add t h e

p r o d u c t i o n r u l e d

(9 + hl, * * . ) P a . j ( v l , . * . t ~ j - 1 , t l j + l , * . * v ~ n ) , h k ) F

t o D'. Note t h a t i f t h e r e are more t h a n two hyperedges w i t h p i n t h e r igh t -hand s i d e of t h e r u l e , w e add t h e two p r o d u c t i o n r u l e as i n t h e f o r e g o i n g t o D'. Fur thermore , i f a r u l e added i n s t e p ( 3 ) a l s o h a s t h e l a b e l p , t hen w e a p p l y s t e p ( 3 ) t o t h i s r u l e .

( 4 ) I f t h e i n i t i a l semihypergraph h a s an atom w i t h l a b e l p and u = mgu(a, v . ) is

3 d e f i n e d , t h e n w e r e p l a c e i t by { h l , where h i s a new non te rmina l hyperedge wi thou t any arguments , and add t h e p r o d u c t i o n r u l e s of t h e forms

t o D ' , where w e add on ly t h e p r o d u c t i o n r u l e of t h e form ( b ) , i f t h e i n i t i a l semihyper- graph h a s a l r e a d y been a l t e r e d .

The p r o d u c t i o n r u l e s added i n t h e s t e p s ( 2 ) and ( 3 ) may c o n t a i n c o n s t a n t s i n t h e hyperedges . For t h i s case, w e can a l s o ob- t a i n t h e c o n s t a n t - f r e e CFHG a f t e r t h e f i n - i t e a p p l i c a t i o n s of t h e p rocedure , s i n c e f o r a non te rmina l l a b e l p w i t h a r i t y n, t h e num- b e r of l a b e l s p , w i t h a r i t y (n-1) gener-

a t e d by t h e

We can t o D by t h e 4.1.2. L e t hypergraphs wr i te G +; H.

U J d procedure i s f i n i t e .

show t h a t CFHG D' i s e q u i v a l e n t f o l l o w i n g Lemmas 4.1.1 and S and S ' b e t h e i n i t i a l s e m i - of D and D ' , r e s p e c t i v e l y . We H i f G + D H ~ JD ... JD Hn = H .

Lemma 4.1.1. For any i n t e g e r and any l a b e l p , i f s *b { ~ ( V I , - , U , , ) } U G, t h e n

S' { p ( ( , ..., u;)} U G' ( k i s e i t h e r o r

Z - 1). I f a = ( a , v . ') i s d e f i n e d , t hen 3

where v ' and G' are t h e v a r i a n t s of v and

G, r e s p e c t i v e l y . i i

Lemma 4.1.2. For any i n t e g e r k and any l a b e l p , i f S' +Li {p(v; , ..., vk)} U GI, t hen w e

5

have s ab{p(ui, ..., urn)} UG ( 2 is e i t h e r k o r

k + l ) , where v ' and G ' are t h e v a r i a n t s of

V . and G , r e spec t ive ly . I f i

2

then ,

S' {P(u{, ... ,u;)} U G',-d Q =

The foregoing two lemma can be proved by induc t ion on t h e l eng th N of de r iva t ions .

D e f i n i t i o n 4.2.

( 1 ) A hyperedge i s simple, o r (loop- free), i f a l l t h e v e r t i c e s i n t h e hyperedge a r e d i f f e r e n t . A p roduct ion r u l e i s simple i f a l l t h e nonterminal hyperedges i n t h i s product ion r u l e a r e simple.

( 2 ) A production r u l e i s monotone i f a l l v e r t i c e s i n t h e le f t -hand s i d e of t h i s product ion r u l e a l s o occur i n t h e right-hand s i d e .

Any CFHG D i s simple ( o r monotone) i f a l l t h e rules i n D are simple (or monotone).

Theorem 4 .3 . Every CFHG can be t r ans - formed i n t o an equ iva len t and simple CFHG.

Proof. For any CFHG D, w e o b t a i n a simple CFHG D' by t h e fo l lowing transforma- t i o n . hyperedge p(z

Suppose t h a t D con ta ins a nonterminal ...' IC ) with IC = x . ( i < j ) : 1' n i J

(1) Replace t h i s hyperedge by b i , j ( X l g .*., xJ-i ,xJti9 .**,I,) with a r i t y n - 1.

( 2 ) For a l l r u l e s of t h e forms

~ ( Y I , * * . , . V n ) + k ~ t hk, g+l'LI, '", p(zl, "', t n ) , j t k

i' such t h a t i f u = mgufyi, y . ) and 5 = mgufz z . ) a r e def ined , w e add t h e fo l lowing pro-

duc t ion r u l e s to the grammar:

J 3

( / J , , J ( , ~ I , " * , .VJ I , yjt I r * " ( y n ) " h I , * ' * * 1 t k ) O t

(g+hl , * * . , b t , j ( Z l t * * * I Zj-1, Zjtl, * + * p Zn), * ' . t h*)€

(3) I f t h e i n i t i a l hypergraph c o n t a i n s t h e l a b e l p , then w e change it as t h e proof of Theorem 4 .1 . This t r ans fo rma t ion t e r - minates a f t e r a p p l i c a t i o n s of t h e fore- going r u l e s , even i f t h e r u l e s added i n t h e s t e p ( 2 ) are also simple, because t h e number of t h e l a b e l s p . in t roduced

by t h e l a b e l p is a t most n(n - 1 ) / 2 , 2 , j

and t h e procedure produces a l a b e l w i th a r i t y one a f t e r f i n i t e r e p e t i t i o n . Sim- i l a r l y t o t h e proof of Theorem 4 . 1 , w e can show t h a t D' i s equ iva len t t o D.

Theorem 4.4. Every CFHG can be t r ans - formed i n t o a n e q u i v a l e n t , s imple and mono- tone CFHG.

Proof . L e t D be a CFHG no t con ta in ing c o n s t a n t s i n t h e nonterminal hyperedges. We r e p e a t t h e fo l lowing t r ans fo rma t ions , whi le D h a s a nonmonotone p roduc t ion r u l e . L e t XI, * - * , I" )+hI, * * * , h m be a nonmonotone product ion r u l e , and y , . . ., yi be t h e

subsequence of t h e v a r i a b l e s z l , . . . , z which appear on ly i n t h e right-hand s i d e of t h e r u l e .

n

(1) R e w r i t e t h i s product ion r u l e as ~ ' ( Y I , * * . , y j ) j h l r ..., hm where p ' is a new nonterminal l a b e l .

( 2 ) For each product ion r u l e gO+g,, ..., 9, such t h a t g i i s isomorphic t o p ( z 1' ...' x n ) , w e add t h e product ion r u l e

go-*gi, ** . , gt-1, ~ ' ( y l , * * ' , Y J ) ~ ~i t I + * * * I gn

( 3 ) I f t h e i n i t i a l semihypergraph has t h e l a b e l p , w e change i t as i n t h e proof of Theorem 4 . 1 ( 4 ) . We can prove t h a t i f D i s monotone, t h e grammar D ' ob ta ined from t h i s procedure i s s imple and monotone a s t h e proof i n Theorem 4 .1 .

D e f i n i t i o n 4 . 5 . A CFHG D = (C, V , N , T, P, S) i s reduced i f :

(1) f o r every nonterminal DEN U T , S 4 C and F l a b e l ( ( ; ) ;

( 2 ) f o r every nontermina l hyperedge h ,

( h ) $ G and ZabeZ(C)ST; and

(3) no product ion r u l e s a r e of t h e form g -+ h , where g and h are hyperedges wi th nontermina l l a b e l s .

Theorem 4 .6 . Every CFHG can be t r a n s - formed i n t o an e q u i v a l e n t , simple, monotone and reduced CFHG.

Proof . L e t D be a CFHG D. By Theorem 4 .4 , w e can assume wi thou t l o s s of gene ra l - i t y t h a t D i s s imple and monotone. We can t ransform D i n t o an equ iva len t CFHG D ' = (C, V , N, T, P, S) s a t i s f y i n g t h e condi- t i o n s (1) and ( 2 ) i n D e f i n i t i o n 4.5 i n a manner similar t o t h a t f o r con tex t - f r ee grammars [ 1 4 ] . fo l lowing t r ans fo rma t ion f o r D' .

Furthermore, w e apply t h e

6

X'(X1, ..., Xnl

Fig. 5. An i l l u s t r a t i o n of G[X]H.

L e t P1 be t h e set of production r u l e s

of t h e form g -+ h (label((g,h)) P 2 be P - P1.

N ) i n p and L e t

p3 = ( 9 + h I ( 9 ) +-$ { h } by applying the

product ion r u l e s of P 1, 1 p4 = { [ g + h l , ..., h m p I 8 = rng4b lho) l

g --t 9' E & i h O + h l ~ . . - , h m E p z }

Note t h a t P is f i n i t e . We can show t h a t

t he CFHG wi th t h e set of product ion r u l e s PZ U P , i s equivalent t o D.

3

5. Generat ive Powers of CFHGs

The following theorem corresponds t h e "uvwxy theorem'' i n formal language theory , and a l s o t o t h e "pumping lemma'' graph grammar theory [2]. We w r i t e G[X

0

i n H

t o r ep resen t a hypergraph composed of two subhypergraphs G and H such t h a t ver (G)n ver(H) = x (Fig. 5).

Theorem 5.1 I (Pwnp ing Lema) . CFHG D, t h e r e e x i s t s an i n t e g e r m y such t h a t f o r a l l H E L(D), i f IHl 2 rn, then H = Ao[Xo]Bo[Xi]Ai and

For any

where B. and B . are isomorphic t o each o t h e r

f o r a l l i and j, B; # 8, 2 3

and A1 3 A:.

Proof. L e t D = (C, V, N, T, P, S ) be any CFHG, k = ( N I , and be the maximum num- ber of hyperedges which appear i n t h e r i g h t - hand s i d e of t h e product ion r u l e s i n P . We assume without l o s s of g e n e r a l i t y t h a t D i s simple, monotone and reduced CFHG by Theorem 4.5. such t h a t IHI 2 l + ( l - l)k, t h e l e n g t h of

Then, f o r every hypergraph H E C ( D )

d e r i v a t i o n s t o d e r i v e H is longe r than o r equal t o k. Because D i s s imple, a l l t h e nonterminal hyperedges i n the semihyper- graphs de r ived from S are simple. t he fol lowing d e r i v a t i o n :

We have

S *b Ao[Xol{h)

3

*; H = Ao[Xo]Bo[XlIA1

Ao [Xo] BO [ X i I {h'}

where h and h' are nonterminal hyperedges such t h a t h h', labef(A;) T , and label(Bj)

T. Because t h e product ion r u l e s used f o r de r iv ing & 1 [ X 1 ] { h ' } from { h } can a l s o be app l i ed t o { h ' } , w e have

S +b Ao[Xo]Bo[Xi]Bi[X~]...[XjIBj[XJ+lIA:

EL (D) for all j I 1

i 0' where each B i s isomorphic t o B and

( X i 1 6 n

Corol lary 5.2. For any CFHG D with rank n , t h e r e e x i s t s an i n t e g e r c such t h a t f o r every H E L(D), i f [HI 2 c, then H can be divided i n t o H and H such t h a t H = 1 2 H1[X1H2, where 1fli1 5 (2/3)IHI, lH2l 5 (2/3)lHl, and 1x1 5 n.

Coro l l a ry 5.3. The class of languages generated by CFHGs i s a proper subse t of t h e the c l a s s of languages generated by LHGs.

Proof. L e t C denote t h e complete

graphs with n v e r t i c e s . {C,l n I 1) i s generated by t h e LHG i n Exam- p l e 3.1. CFHG. By Theorem 5.1, t h e r e e x i s t s an i n t e - ge r m such t h a t i f lH,l 2 rn, t hen H =

A O [ X O ] & [ X ~ ] A I , and f o r every p o s i t i v e i n t e - ger k , t h e r e e x i s t s a complete graph such t h a t lH;l = n(n + 1)/2 + kl, where I&( 2 1. Hence, w e have c o n t r a d i c t i o n .

n The language C =

Suppose t h a t C i s generated by a

n

I n t h e fol lowing theorem, w e show a h i e ra rchy on subc la s ses of con tex t - f r ee hypergraph languages with r e s p e c t t o t h e i r ranks.

D e f i n i t i o n 5.4. L e t G(n) denote t h e c l a s s of CFHGs wi th rank k such t h a t k s n , and L ( n ) denote t h e class of languages of t h e LHGs i n G(n).

Theorem 5.5. For any nz > n1 _> 0 , L (n1) s L: (nz ) .

Proof. Since i t i s obvious t h a t C ( n l ) C C (n l ) , i t i s s u f f i c i e n t t o show t h a t t h e r e exist CFHGs D o , D1, D2, ..., such t h a t

7

succeeds i f and only i f an i n s t a n c e of t h e hypergraph i n C ( D ) i s a subse t of H .

Proof. The proof i s s t r a igh t fo rward s i n c e computation of t h e program i s similar t o d e r i v a t i o n of t h e hypergraph.

Fig. 6. A sample graph i n L ( 4 ) .

For proper pa r s ing , t h e computation of t he l o g i c program H U P f o r t h e query ?-S. should succeed i f and only i f H is iso- morphic t o a hypergraph der ived by D. Therefore , w e should s o l v e the following problems.

(1) The computation succeeds even i f a hypergraph of &(D) is a proper subse t of i npu t hypergraphs.

(2) The computation a l s o succeeds even i f t h e input hypergraph i s an i n s t a n c e o f , but n o t isomorphic t o , a hypergraph i n t (D).

( 3 ) The computation by Prolog may f a l l L e t i n t o i n f i n i t e loops i f t h e LHG con ta ins

6. A Parsing Method of LHGs

Here, w e desc r ibe a top-down parsing method of LHGs i n Prolog. We consider pars- ing of an LHG as Computation of a l o g i c pro- gram constructed from D, such t h a t f o r any hypergraph H, H i s isomorphic t o an element of C ( D ) , i f and only i f computation of t h e l o g i c program succeeds f o r t h e query con- s t r u c t e d from H . Our method i s an ex tens ion of Kowalski's method [8]. However, h i s mthod cannot be app l i ed d i r e c t l y t o LHGs. The following lemma suggests some problems i f Kowalski's method is used d i r e c t l y f o r LHGs.

Lemma 6.1. L e t D = ( N , T , P , { S } ) be an LHG. For a hypergraph H , t h e computation of t h e l o g i c program H U P and t h e query ?-S.

some l e f t r e c u r s i v e r u l e s .

To s o l v e t h e problem ( l ) , w e r ep resen t t h e se t H of hyperedges by t h e list of t h e hyperedges, and remove a hyperedge from t h e l i s t of H when a terminal hyperedge is recognized u n t i l t h e l i s t comes t o an empty l ist . To s o l v e t h e problem ( 2 ) , w e add two extra arguments f o r each atomic formula of Horn c l auses : one i s a list rep resen t ing t h e se t of v e r t i c e s of t h e hypergraph de- r ived by D; and t h e o t h e r t h e set of ver- t ices of t h e hypergraph t o be parsed. A t t h e end of computation w e check t h a t t h e two sets have one-to-one correspondence.

A Prolog program f o r an LHG D c o n s i s t s of t h e fol lowing t h r e e groups of d e f i n i t e c l auses . A s i n s tandard Prolog, names be- ginning with c a p i t a l l e t te rs are v a r i a b l e s .

...

where every v a r i a b l e i n any term t is re- named so t h a t t h e v a r i a b l e s i n t ' do no t appear i n t. I f qi i s a terminal l a b e l ,

t h e atom with q is replaced by i

8

Each atom p ( P i, P j , t l , ..., tn, ... ) r ep re -

s e n t s t h a t t h e d i f f e r e n c e of l i s ts P . and P

is t h e hyperedge p (t 2 j . . . , tn).

1’

( 2 ) A Prolog program t o d e f i n e sub:

sub([X I A], X, A ) . sub([/! 1 B ] , X, [A I Y I ) :-sub(B, x, Y )

The atom sub(A, B , C) means t h a t C i s t h e l i s t ob ta ined by removing a l l t h e e lements of B from A.

(3) A P ro log program t o d e f i n e t h e p r e d i c a t e check i s shown i n t h e Appendix. An atom check(A, B, C, D) means t h a t A , B, C and D are l i s t s r e p r e s e n t i n g sets of ver - t i c e s , and t h e l i s t ob ta ined by removing t h e e lements i n C from those i n A h a s one- to-one cor respondence t o t h e l i s t ob ta ined by removing t h e e l emen t s i n D from t h o s e i n B.

We r e p r e s e n t a hypergraph H = { e 1 s ..., e k l by t h e l i s t [ e 1 , ..., e,].

semihypergraph { s ( t

of p a r s i n g f o r H i s

For an i n i t i a l

t ) 1 , t h e query 1’ ...’ n

? -s([el, ..*, e J [ I , 11, ..., t n , 1 1 ’ ~ ..., tn’, [ I , V , [ 1, W ) , check( V , W , [ I , [ I )

1’ . . * ’ where t ..., t ’ a r e v a r i a n t s of t 1 ’ n

r e s p e c t i v e l y , such t h a t t l , ..., tn and

t l f J ..., t ’ have no common v a r i a b l e s . n

Example 6.1. The Pro log program f o r t h e LHG i n Example 3.1 c o n s i s t s of t h e f o l - lowing d e f i n i t e c l a u s e s :

d P O , P1, [X, Y], [ X l , Y 11, vo, v1, wo, W1) :- s (P0 , P1, x, Y, x1, Y1, vo, v1, wo, W1).

q(P0, P2, [x I Y], [ X l I Y 11, vo, v2, wo, W 2 ) :- Y(P0, P1, x, Y , x1, Y1, vo, v 1 , wo, W l ) , Q(P1, P2, Y , Y1, v1, v2, w1, W 2 ) .

Y(PO,Pl,X, [ Y ] , X l , [ Y l ] , vo, v1, wo, W1):- S ( P 0 , P1 , x, Y , x 1 , Y1, vo, v1, wo, W1).

Y(P0, P2, x, [ Y 123, x1, [ Y l l 213, vo, v2, wo, W 2 ) : -

s (P0, PI, x, Y, x1, Y1, vo, v1, wo, W l ) , Y(P1, P2, x, 2, x1, 21, v1, v2, w1, W2).

S ( P 0 , P1, x, Y, x1, Y1, vo, [x, Y I vol, wo, [ X l , Y 1 I WOI) :-

sub(P0, f (X, Y ), P1)

d P 0 , P1, x, Y , x1, Y1, vo, [ Y , x I vo], wo, [ Y 1, X I I WO]) :-

sub(P0, t ( Y , X), P1)

The query f o r t h e comple te graph i n F ig . 2 (b) is:

7. Conclus ions

I n t h i s p a p e r , w e d e s c r i b e d two types of ex tended g raph grammars, c a l l e d l o g i c hypergraph grammars (LHGs) and c o n t e x t - f r e e hypergraph grammars (CFHGs), and d i scussed t h e i r c a p a b i l i t i e s and a p a r s i n g method based on l o g i c programming. The t ransforma- t i o n methods of CFHG i n t o s e v e r a l normal forms would be a l s o a p p l i e d t o l o g i c pro- grams wi thou t f u n c t i o n symbols o r l i s ts . We need f u r t h e r r e s e a r c h e s on t h e fo l lowing s u b j e c t s :

(1) P a r s i n g method i n P ro log such t h a t t h e computation does n o t f a l l i n t o i n f i n i t e l oops , even i f t h e program c o n t a i n s l e f t r e c u r s i v e r u l e s ;

( 2 ) e f f i c i e n t p a r s i n g methods f o r LHGs i n Pro log; and

(3) comparisons of LHG and CFHG w i t h d i f f e r e n t t y p e s of graph grammars.

It would b e p o s s i b l e t o r e a l i z e e f f i - c i e n t p a r s i n g wi th s e a r c h comple teness by employing a bottom-up computa t ion of l o g i c programs. S ince w e can r e p r e s e n t many k i n d s of g e n e r a l s t r u c t u r e s such as flow- c h a r t and e l e c t r o n i c c i r c u i t s by hyper- graphs , w e are working on app ly ing ou r gram- mar and t h e p a r s i n g method f o r s y n t a c t i c p a t t e r n r e c o g n i t i o n by l o g i c programming.

REFERENCES

1. C. Berge. Graphs and Hypergraphs. North-Holland (1976).

2. V. C laus , H. E h r i g , and G. Rozenberg ( e d i t o r s ) . Graph-grammars and t h e i r a p p l i c a t i o n t o computer s c i e n c e and b io logy . L e c t u r e Notes i n Computer Sc ience , 73, Spr inger -Ver lag (1979).

3. H. Eh r ig , M. Nagl, and G. Rozenberg ( e d i t o r s ) . Graph-grammars and t h e i r a p p l i c a t i o n t o computer s c i e n c e . Lec- t u r e Notes i n Computer Sc ience , 153, Spr inger -Ver lag (1983).

9

4 . H. Ehrig, M. Nagl, and A. Ronfeld (edi- tors). Graph-grammars and their appli- cation to computer science. Lecture Notes in Computer Science, 291, Springer- Verlag (1987).

5. K. S. Fu. Syntactic Pattern Recognition and Applications. Prentice-Hall (1982).

6. A. Habel and H. Kreowski. On context- free graph languages generated by edge replacement. Lecture Notes in Computer Science, 153, Springer-Verlag, pp. 143- 158 (1983) .

7. A. Habel and H. Kreowski. May we intro- duce to you: Hyperedge replacement. Lecture Notes in Computer Science, 291, Springer-Verlag, pp. 15-26 (1987).

North-Holland (1983).

gramming. Springer-Verlag (1984).

8. R. Kowalski. Logic for Problem Solving.

9. J. W. Lloyd. Foundations of Logic Pro-

10. E. Sopena. Combinatorial hypermap re- writing. Lecture Notes in Computer Science, 256, Springer-Verlag, pp. 62- 73 (1987).

free graph grammars. Inf. & Control,

12. K. J. Peng, K. Onda, T. Yamamoto, and

11. P. D. Vigna and C. Chezzi. Context-

- 37, pp. 207-233 (1978) .

Y. Aoki. Plex grammars for the predi- cate logic programming and its applica- tion to the structural analysis of electronic circuits. Trans. I. E. I.C. E., Japan, J70-D, 10, pp. 1831-1842 (1987) .

13. T. Tanaka. Structural analysis of electronic circuits using definite clause grammars. Ibid., J69-D, 3, pp. 443-450 (1986).

14. N. Honda. Automaton and Language Theory. Corona Publ. (1972) .

APPENDIX A Prolog Program to Define check check([X 1 Xl], [Y I Y 11, 2, 21) :-atom( Y ),

! , check(X1, Y1, [X 121, [ Y 1211).

checkl(A, Y, [ 1, [ 1) :- ! . chcckl(A, Y, [I3 I I,], [Ill I I l l ] ) : - A \ = = B ,

checkl(A, Y , [B I L], [Bl I L11) :- Y = =B1,

This program is used in Sect. 6.

check( [ I, [ 1, -, -) :- ! . check([X I Xl], [ Y I Y 11, 2 , Z l ) :-

var( Y) , ! , checkl(X, Y, X1, Y l ) , checkl(A, Y , L. Ll I. checkl(X, Y, 2, Zl) , check(X1, Y 1, [ X I 21, [ Y I 211) checkl(A, Y, L, L1)

10

AUTHORS (from left to right)

Isamu Shioya received an M.E. in 1978 from Tokyo Denki University, Tokyo. He is present- ly with the Department of System Engineering, School of Science Engineering, Tokyo Denki Uni- versity. He is a member of the ACM; the Information Processing Society of Japan (IPSJ); and the IEICE. He is currently engaged in research on logic programming, deductive databases and graph grammars.

Katsuhiko Nakamura obtained a Dr. of Eng. degree in 1977 from Tokyo Denki University, Tokyo, where he is presently a Professor in the Department of System Engineering. He is a member of ACM; IEEE; the Information Processing Society of Japan (IPSJ); and IEICE. He is presently engaged in research on logic programming and artificial intelligence.

11